Skip to content

Watch body elements and wait for changes in Capybara integration tests. It does not matter which framework you are using.

License

Notifications You must be signed in to change notification settings

ricvillagrana/capybara_watcher

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

21 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Capybara Watcher

Watch body elements and wait for changes in Capybara integration tests.

Build with Ruby Powered by Vim

Getting Started

To use capybara watcher you only have to add wait_for_changes on any integration test.

How does it work

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:

Approach 1

fill_in 'Name', with 'My name'
click_on 'Submit'

wait_for_changes

# Perform any action
expect(body).to have_content(/Name was saved!/i)

Approach 2

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)

Approach 3

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' }

Prerequisites

  • Rails
  • RSpec

Installing

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
...

Configuring

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.

Built With

  • Ruby - A PROGRAMMER'S BEST FRIEND

Contributing

Please read CONTRIBUTING.md for details on our code of conduct, and the process for submitting pull requests to us.

Versioning

We use SemVer for versioning. For the versions available, see the tags on this repository.

Authors

License

This project is licensed under the MIT License - see the LICENSE.md file for details

About

Watch body elements and wait for changes in Capybara integration tests. It does not matter which framework you are using.

Topics

Resources

License

Stars

Watchers

Forks

Languages