使用url参数时,在没有机架的情况下运行Capybara会产生错误

这是我的设置,基于这个建议: 如何让Cucumber / Capybara / Mechanize对抗外部非铁轨站点

它一直有效,直到我向URL添加参数。 有关解决这个问题的建议吗?

require 'rspec' require 'capybara/rspec' require 'capybara/dsl' @test_url = "test" RSpec.configure do |config| config.include Capybara::DSL end Capybara.configure do |config| config.run_server = false config.current_driver = :selenium config.app = "fake app name" config.app_host = "http://site.com/#{@test_url}" end 

这很好用:

 describe "the page, without URL parameters" do it "shows the regular form" do visit "/registration.aspx" page.should have_content "YES" end end 

但是这个:

 describe "the page, when not fully pre-filled" do it "shows the regular form if only passed the attendance" do visit "/registration.aspx?r=y" page.should have_content "YES" end it "shows the regular form if only passed the attendance" do visit "/registration.aspx?f=Jim" page.should have_content "YES" end end 

结果是

 ....FF Failures: 1) the page, when not fully pre-filled shows the regular form if only passed the attendance Failure/Error: visit "/registration.aspx?r=y" NoMethodError: undefined method `call' for "fake app name":String # ./conf_spec.rb:39:in `block (2 levels) in ' 2) the page, when not fully pre-filled shows the regular form if only passed the attendance Failure/Error: visit "/registration.aspx?f=Jim" NoMethodError: undefined method `call' for "fake app name":String # ./conf_spec.rb:44:in `block (2 levels) in ' 

您只能设置appapp_host 。 所以你应该从配置中删除config.app

你也应该设置default_driver而不是current_driver

正如我在链接问题的答案中所示,工作配置是:

 Capybara.configure do |config| config.run_server = false config.default_driver = :selenium config.app_host = 'https://www.google.com' # change url end 

如果您要指定app_host而不是使用rack,则需要指定default_driver而不是current_driver 。 例如:

 Capybara.run_server = false Capybara.default_driver = :selenium Capybara.app_host = 'https://www.google.com' instead of Capybara.run_server = false Capybara.current_driver = :selenium Capybara.app_host = 'https://www.google.com' 

假设你有一个非机架应用程序,并按照第二个答案中的说明参考https://groups.google.com/forum/#!msg/ruby-capybara/9UFnfrc1S-s/TfQO5uBv7gMJ ,在我看来hack / workaround仅对最简单的用例有效,即当您没有尝试将参数传递给应用程序时。 我假设Rack或Capybara试图调用你的应用来传递参数而它失败了,因为你的app只是一个String而不是一个可call对象。