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

标签 ruby rspec capybara

这是我的设置,基于此建议: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)>'

最佳答案

您只能设置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

关于ruby - 在没有机架的情况下运行 Capybara 在使用 url 参数时会产生错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17666623/

相关文章:

javascript - 让 capybara 在 Rails 中与 Vue.js 一起工作

ruby-on-rails - 标记要在模块中使用的特定 Rails 模型的最佳方法

javascript - 限制 javascript 数据表中允许选择的复选框数量 (Ruby on Rails)

ruby-on-rails - Spork 无法启动,因为没有要加载的此类文件 -- spork (LoadError)

ruby-on-rails - 为什么这个 Rspec 测试返回 "email already taken"

ruby-on-rails - 从助手规范中获取 'action_name' 或 'controller'

ruby-on-rails - 通过 Post 在 Rails 中发送 JSON 对象

javascript - 防止实例变量在js文件中编码为html

ruby-on-rails - 西类牙语中的 cucumber 步骤定义 : Ambiguous match of "..."

ruby-on-rails-3 - NOOB capybara Rspec 警告 : regexp match/. ../n 针对 UTF-8 字符串