Search code examples
ruby-on-railsrubyrspeccapybaracapybara-webkit

Capybara config for a single test


I'm trying to

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

to replace the capybara config that i have in spec_helper just for a single test, but i'm getting the error "All configuration must take place before the driver starts".

This is my 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

Is there a way to do it?


Solution

  • for a single test you can just call allow_unknown_urls on the driver, and use the Capybara.using_wait_time to override the default wait time for the block

    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