5

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?

fabdurso
  • 2,366
  • 5
  • 29
  • 55

2 Answers2

3

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
Thomas Walpole
  • 48,548
  • 5
  • 64
  • 78
  • Thanks for the answer! The test passes but I get this: "[DEPRECATION] allow_unknown_urls is deprecated. Please use Capybara::Webkit.configure instead" – fabdurso Nov 11 '15 at 17:15
  • 1
    Yes - I should have mentioned that - I don't think there really is an easy replacement yet - other than register a second driver instance with different options – Thomas Walpole Nov 11 '15 at 17:17
  • 3
    @fabersky You can follow part of the discussion about why there is/is not an easy way to modify the options per test at https://github.com/thoughtbot/capybara-webkit/issues/814 . – Thomas Walpole Nov 11 '15 at 17:30
0

You should put it in spec/spec_helper.rb, you can use rspec --init to generate these files and then add capybara's configs here. Your approach is wrong, it is not a good idea to store this information in this spec file.

Edit:

Below is my 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
MC2DX
  • 562
  • 1
  • 7
  • 19
  • 2
    Hey! Thanks for the answer! As i told you, I have the spec_helper with my capybara config, but i'd like to change it just for a SINGLE test – fabdurso Nov 11 '15 at 15:40
  • Try to move capybara configs above `describe` section, frankly speaking, I had never tried this but it could help a little bit. – MC2DX Nov 11 '15 at 15:49