Low commit activity in last 3 years
A long-lived project that still receives updates
RSpec matcher to check that an expression changed its result in arbitrary seconds. Useful for expecting value which changes asynchronously.
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
 Dependencies

Development

Runtime

 Project Readme

Rspec::BecomeMatcher Build Status

RSpec matcher to check that an expression changed its result within arbitrary seconds.

async_task.start!
expect { async_task.finished? }.to become(true)

Installation

Add this line to your application's Gemfile:

gem 'rspec-become-matcher'

And then execute:

$ bundle

Or install it yourself as:

$ gem install rspec-become-matcher

Usage

Require and include matcher first:

require 'rspec/become_matcher'

RSpec.configure do |config|
  config.include RSpec::BecomeMatcher
end

Then, asynchronous behaviour can be tested like this:

# Start some asynchronous task
async_task.start!

# `become` matcher checks the task is `finished?` periodically
expect { async_task.finished? }.to become(true) # => PASS

# Start long asynchronous task
long_task.start!

# By default, `become` matcher waits 3 seconds
expect { long_task.finished? }.to become(true) # => FAIL

# Start long asynchronous task, which finishes in 5 seconds
another_long_task.start!

# Timeout seconds can be specified with `in`
expect { another_long_task.finished? }.to become(true).in(10) # => PASS

# Expectation can be specified with block
yet_another_long_task.start!
expect { yet_another_long_task }.to become { |task| task.finished? } # => PASS

Contributing

Bug reports and pull requests are welcome on GitHub at https://github.com/fujimura/rspec-become-matcher. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the Contributor Covenant code of conduct.

License

The gem is available as open source under the terms of the MIT License.

Code of Conduct

Everyone interacting in the Rspec::Become::Matcher project’s codebases, issue trackers, chat rooms and mailing lists is expected to follow the code of conduct.