我刚开始玩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)
这导致我的困惑.
在某些情况下,我查看了几个类似的线程,在某些情况下,错误是关于在spec_helper.rb或测试不正确的位置丢失config.include 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
思考?
解决方法
>更新
根据报告不再需要此解决方法(请参阅注释),但我还没有检查.
找到解决方法
我必须指定应用程序主机网址和默认驱动程序..
#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
更新1
为了修正错误:
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 url不再需要,它可以从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)
发生,因为宝石’jquery-rails’在我的Gemfile的测试范围不可用,它只有在:开发& :生产环境.我把宝石’jquery-rails’移到全球范围.完整版的Gemfile:http://pastebin.com/dt4KrHGG