Watch body elements and wait for changes in Capybara integration tests.
To use capybara watcher you only have to add wait_for_changes
on any integration test.
Capybara Watcher gets the current body content and then watch for changes on it, a change trigger your lines of code that lies bellow the watch line.
Example:
fill_in 'Name', with 'My name'
click_on 'Submit'
wait_for_changes
# Perform any action
expect(body).to have_content(/Name was saved!/i)
fill_in 'Name', with 'My name'
before_wait do
click_on 'Submit'
end
# Perform any action
expect(body).to have_content(/Name was saved!/i)
fill_in 'Name', with 'My name'
click_on 'Submit'
# Perform any action
wait_until_content_has('Name was saved!') do |text|
expect(body).to have_content(text)
end
You can even wait for many changes, i.e. "A modal closes and then a notification is triggered". This can be done with:
wait_for_changes(2)
before_wait(2) { click_on 'Submit' }
- Rails
- RSpec
Install capybara_watcher
gem install capybara_watcher
Or in Gemfile
gem 'capybara_watcher'
On your rails_helper.rb
...
config.include CapybaraWatcher, type: :feature
# or
config.include CapybaraWatcher, type: :view
...
On your rails_helper.rb
CapybaraWatcher.configure do |options|
options[:timeout] = 5 # Time in seconds
end
The timeout option has a default value of 2 (seconds), and this means that a when CapybaraWatcher wait more than this time, it automatically continue with the program.
- Ruby - A PROGRAMMER'S BEST FRIEND
Please read CONTRIBUTING.md for details on our code of conduct, and the process for submitting pull requests to us.
We use SemVer for versioning. For the versions available, see the tags on this repository.
- Ricardo Villagrana - ricvillagrana
This project is licensed under the MIT License - see the LICENSE.md file for details