Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/abotalov/waiting_rspec_matchers
become_* RSpec matchers that do the same as * matchers but also wait
https://github.com/abotalov/waiting_rspec_matchers
rspec
Last synced: 3 months ago
JSON representation
become_* RSpec matchers that do the same as * matchers but also wait
- Host: GitHub
- URL: https://github.com/abotalov/waiting_rspec_matchers
- Owner: abotalov
- License: mit
- Created: 2014-06-22T14:52:48.000Z (over 10 years ago)
- Default Branch: master
- Last Pushed: 2019-07-05T19:12:34.000Z (over 5 years ago)
- Last Synced: 2024-03-15T01:03:48.902Z (11 months ago)
- Topics: rspec
- Language: Ruby
- Homepage:
- Size: 14.6 KB
- Stars: 9
- Watchers: 2
- Forks: 1
- Open Issues: 2
-
Metadata Files:
- Readme: README.md
- License: LICENSE.txt
Awesome Lists containing this project
README
# Waiting RSpec Matchers
[![Gem Version](https://badge.fury.io/rb/waiting_rspec_matchers.svg)](https://rubygems.org/gems/waiting_rspec_matchers)
[![Build Status](https://travis-ci.org/abotalov/waiting_rspec_matchers.svg?branch=master)](https://travis-ci.org/abotalov/waiting_rspec_matchers)When writing end-to-end tests there is often a necessity to wait for something to happen. Libraries like Capybara, Watir-Webdriver provide some functionality to ease it but this functionality doesn't cover all needed cases. Sometimes you need to wait for a more specific condition.
This is where this gem aims to help.
If `some_name` rspec matcher exists, WaitingRspecMatchers provides you `become_some_name` matcher that does the same as `some_name` matcher but also waits for that matcher to succeed.
The benefit of using this gem over solutions like [wait_until](https://gist.github.com/jnicklas/d8da686061f0a59ffdf7), [retryable](https://github.com/carlo/retryable), [tries](https://github.com/krautcomputing/tries) is that those solutions don't integrate with RSpec and thus don't provide useful enough error messages.
## Setup
To install, add this line to your Gemfile and run bundle install:
```ruby
gem 'waiting_rspec_matchers'
```Then you should include it in e.g. `spec_helper.rb`:
```ruby
RSpec.configure do |config|
config.include WaitingRspecMatchers
end
```## Usage examples (inspiration)
* reload page until some element/text appears:
```ruby
# setup Capybara
expect do
visit 'path'
page
end.to become_have_css('#id', wait: 0) # `expect(page).to have_css('#id', wait: 0)` is internally invoked by this gem
```* check that page url is "some_string" or will become "some_string":
```ruby
# setup Capybara
expect { page.current_url }.to become_eq('http://www.google.com/')
```* wait for element attribute to include a specific string:
```ruby
# setup Capybara
el = find('#id')
expect { el[:class] }.to become_include('some_class')
```* assert that 3 requests url of which contains `/path` pass through proxy
```ruby
# setup proxy
expect { proxy.har.entries.count { |e| e.request.url[/\/path/]} }.to become_eq(3)
```## Changing wait time
You can specify a wait time (amount of time that gem will retry supplied block of code) and delay (period between retries).
You can either change default values (it will take effect for all matchers):
```ruby
WaitingRspecMatchers.configure do |config|
config.default_wait_time = 2
config.default_delay = 0.05
end
```or set it on per-matcher basis:
```ruby
expect { some_code }.to become_eq(3).during(2).delay(0.05)
expect { some_code }.to become_eq(3).during(2)
expect { some_code }.to become_eq(3).delay(0.05)
```