我刚开始玩Capycabra + poltergeist并执行了我的Capy测试rspec ./spec/features/test_spec.rb
我收到以下错误:
Failure/Error: visit '/item/new'
ArgumentError: rack-test requires a rack application, but none was given
此外,我还有一些标准的rspec测试,每当我尝试执行所有测试时,都会成功通过rspec测试,但只有capy测试失败且出现奇怪的错误
ActionView::Template::Error: couldn't find file 'jquery.min' (in app/assets/javascripts/application.js:13)
这让我感到困惑。
我在stackoverflow上查看了几个类似的线程,在某些情况下,错误是缺少 config.include在spec_helper.rb中的Capybara :: DSL 或测试位置不正确。我做了相应的更改,但它不起作用,错误仍然是相同的。
我的spec_helper.rb文件
require 'capybara'
require 'capybara/dsl'
require 'capybara/poltergeist'
Capybara.javascript_driver = :poltergeist
RSpec.configure do |config|
config.include Capybara::DSL
end
完整版spec_helper:http://pastebin.com/qkANfu39
测试文件:
#spec/features/test_spec.rb
require 'spec_helper'
describe 'accessibility of webpage' do
it 'should access web page' do
visit '/item/new'
expect(page).to have_content("Something")
end
end
思想?
答案 0 :(得分:13)
根据报告不再需要此解决方法(请参阅评论中),但我尚未检查过。
找到解决方法..
我必须指定应用主机网址和默认驱动程序..
#spec/spec_helper.rb
require 'capybara'
require 'database_cleaner'
require 'capybara/dsl'
require 'capybara/poltergeist'
Capybara.configure do |c|
c.javascript_driver = :poltergeist
c.default_driver = :poltergeist
c.app_host = "http://localhost:3000"
end
为了修正错误:
Failure/Error: visit '/item/new'
ArgumentError: rack-test requires a rack application, but none was given
我将 rails_helper 文件包含在我的Capy测试中。测试的最终版本:
require 'rails_helper'
require 'spec_helper'
describe 'accessibility of webpage' do
it 'should access web page' do
visit '/item/new'
expect(page).to have_content I18n.t("form_input.item.item_s")
end
end
之后出于某种原因,指定的app_host网址不再需要,可以从 spec_helper 帮助文件中删除。最终版本:
Capybara.configure do |c|
c.javascript_driver = :poltergeist
c.default_driver = :poltergeist
end
spec_helper.rb http://pastebin.com/DKgF1uQA
的完整版本ActionView::Template::Error: couldn't find file 'jquery.min' (in app/assets/javascripts/application.js:13)
发生因为gem'jquery-rails'在我的Gemfile中的测试范围中不可用,它仅在以下版本中可用:development& :生产环境。我将gem'jquery-rails'移到了全局范围。 Gemfile的完整版本:http://pastebin.com/dt4KrHGG