RspecMatcherNumTimes
This gem provides some rspec matchers to simplify asserting that something is included or matched N times.
Installation
Current Gem Version (for rspec-3)
Add this line to your application's Gemfile:
gem 'rspec-matcher-num-times'
And then execute:
$ bundle
Or install it yourself as:
$ gem install rspec-matcher-num-times
For rspec-2
Add this line to your application's Gemfile:
gem 'rspec-matcher-num-times', git: "https://github.com/jantman/rspec-matcher-num-times.git", branch: 'rspec2'
And then execute:
$ bundle
Usage
In your spec_helper, add a line like:
require 'rspec_matcher_num_times'
Matchers
include_num_times
This matcher tests that a given item occurs N times in an array, or a given substring occurs N times in a string.
expect('foo bar foo').to include_num_times(2, 'foo')
expect(['foo', 'bar', 'foo']).to include_num_times(2, 'foo')
match_num_times
This matcher tests that a given regex is matched N times in a string, or that an array has N elements matching the regex.
expect('ffooo bar foo').to match_num_times(2, /foo/)
expect(['ffooo', 'bar', 'foo foo foo']).to include_num_times(2, /foo/)
Contributing
- Fork it ( https://github.com/jantman/rspec-matcher-num-times/fork )
- Create your feature branch (
git checkout -b my-new-feature
) - Commit your changes (
git commit -am 'Add some feature'
) - Push to the branch (
git push origin my-new-feature
) - Create a new Pull Request
Testing
Spec tests are done automatically via Travis CI. They're run using Bundler and rspec.
For manual testing:
bundle install
bundle exec rake spec
Releasing
- Ensure all tests are passing, coverage is acceptable, etc.
- Increment the version number in
lib/rspec_matcher_num_times/version.rb
- Update CHANGES.md
- Push those changes to origin.
bundle exec rake build
bundle exec rake release