I'm writing integration tests with Capybara at the moment for our Rails 4 application. To make this as light-weight as possible, I have written a capybara_helper.rb file that is located inside the spec folder to be used with RSpec.
However, this file is loaded every time when the RSpec tests are running, destroying the configuration for existing Capybara tests that originally were present inside the test suite.
Is there a way to tell/configure RSpec to not load this file when starting up the "normal" unit tests?
My Integration tests are loaded with the command RAILS_ENV=test bundle exec rspec --tag @type:capybara. Our normal tests are just ran using rake parallel:spec[4]
If you place your capybara_helper code into a module, then you can include the module in your rails helper ONLY for feature tests (i.e capybara tests):
spec/support/capybara_helper.rb:
module CapybaraHelper
# Your code
end
In your rails_helper.rb, only include the module for feature tests:
Dir[Rails.root.join('spec', 'support', '**', '*.rb')].each { |f| require f }
RSpec.configure do |config|
config.include CapybaraHelper, type: :feature
end
The above approach will also work with tagged example groups. So in your case, I think the following should work (for tests that are tagged with metadata of type: :capybara).
RSpec.configure do |config|
config.include CapybaraHelper, type: :capybara
end
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With