Is it possible globally configure RSpec to use Capybara's (default or custom) JavaScript driver for all request specs? We sometimes forget to manually add js: true
to every request spec and it's kind of annoying.
Capybara helps you test web applications by simulating how a real user would interact with your app. It is agnostic about the driver running your tests and comes with Rack::Test and Selenium support built in.
Capybara is an integration testing tool for rack based web applications. It simulates how a user would interact with a website.
Capybara is a web-based test automation software that simulates scenarios for user stories and automates web application testing for behavior-driven software development. It is written in the Ruby programming language.
In spec_helper.rb, set the following:
config.before(:each) do
if example.metadata[:type] == :request
Capybara.current_driver = :selenium # or equivalent javascript driver you are using
else
Capybara.use_default_driver # presumed to be :rack_test
end
end
For later versions of capybara and rspec, it's important to check for type being "feature"
config.before(:each) do
if [:request, :feature].include? example.metadata[:type]
Capybara.current_driver = :poltergeist # or equivalent javascript driver you are using
else
Capybara.use_default_driver # presumed to be :rack_test
end
end
or for RSpec 3 (pass example
into the block)
config.before(:each) do |example|
if [:request, :feature].include? example.metadata[:type]
Capybara.current_driver = :poltergeist # or equivalent javascript driver you are using
else
Capybara.use_default_driver # presumed to be :rack_test
end
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