Integration tests with Javascript via Test :: Unit and Capybara in Ruby on Rails
With RSpec and Capybara, I used to write the following code to test capabilities on pages where javascript was run:
feature "Some Feature" do
scenario "testing some scenario", js: true do
# code
end
end
Now using Test :: Unit with Capybara, how do I achieve the same result? Because when I do test 'checks some feature on some scenario', js: true
it doesn't work.
EDIT
So, I was able to get by with the following:
setup do
Capybara.current_driver = Capybara.javascript_driver
end
teardown do
Capybara.current_driver = Capybara.default_driver
end
test 'checks some feature on some scenario with javascript goin on' do
# code
end
Is there any other solution without this boilerplate code?
+3
source to share
1 answer
Ok, I resolve this by defining a method in test_helper.rb
which terminates the test in the capybara driver by assigning:
def js
Capybara.current_driver = Capybara.javascript_driver
yield
Capybara.current_driver = Capybara.default_driver
end
And using it like:
test 'checks some feature on some scenario with javascript goin on' do
js do
# code
end
end
I read that minitest-data might be useful here, but I haven't dug anymore.
+1
source to share