7

这是我的设置,基于此建议:How to get Cucumber/Capybara/Mechanize to work against external non-rails site

在我将参数添加到 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 <top (required)>'

  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 <top (required)>'
4

3 回答 3

18

您只能设置app和之一app_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
于 2013-07-19T17:57:27.820 回答
4

如果您指定 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'
于 2014-02-21T04:31:40.960 回答
0

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

于 2013-07-16T03:11:11.413 回答