Capybara 单次测试配置

Capybara config for a single test

我正在尝试

describe "test", :js => true do
 it "test" do

  Capybara.default_max_wait_time = 3
  Capybara::Webkit.configure do |config|
   config.allow_unknown_urls
  end

  my test
 end
 it "test2" do
  ...
 end
end

替换我在 spec_helper 中的水豚配置只是为了一次测试,但我收到错误 "All configuration must take place before the driver starts"。

这是我的spec_helper

   Capybara.run_server = false
   Capybara.default_max_wait_time = 1
   Capybara.javascript_driver = :webkit_with_qt_plugin_messages_suppressed

   Capybara::Webkit.configure do |config|
    config.block_unknown_urls
   end

   RSpec.configure do |config|
    config.include Capybara::DSL
   end

有办法吗?

你应该把它放在spec/spec_helper.rb,你可以使用rspec --init生成这些文件,然后在这里添加水豚的配置。您的方法是错误的,将此信息存储在此规范文件中不是一个好主意。

编辑:

下面是我的spec/spec_helper.rb

$ cat spec/spec_helper.rb
require 'vcr'

RSpec.configure do |config|
  config.expect_with :rspec do |expectations|
    expectations.include_chain_clauses_in_custom_matcher_descriptions = true
  end

  config.mock_with :rspec do |mocks|
    mocks.verify_partial_doubles = true
  end
end

VCR.configure do |config|
  config.cassette_library_dir = "spec/fixtures/vcr_cassettes"
  config.hook_into :webmock
  config.ignore_localhost = true
end

对于单个测试,您只需在驱动程序上调用 allow_unknown_urls,并使用 Capybara.using_wait_time 覆盖块的默认等待时间

describe "test", :js => true do
  it "test" do
    page.driver.allow_unknown_urls
    using_wait_time(3) do
      my test
    end
 end
 it "test2" do
   ...
 end
end