rspec-matcher-num-times 0.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml ADDED
@@ -0,0 +1,15 @@
1
+ ---
2
+ !binary "U0hBMQ==":
3
+ metadata.gz: !binary |-
4
+ NjUyZTMwOTAyOTY2NTc3MGU4MmNiNTQ4NmU2MWQ3MWJkNjc3YmJkYg==
5
+ data.tar.gz: !binary |-
6
+ NDQ0N2M4ZDVhNTAwN2IwZTc3OWM3MDU5NmY2ZDYwODljNzg3MDFmZA==
7
+ SHA512:
8
+ metadata.gz: !binary |-
9
+ YWExOWQ3ZTgzM2MwZDY4ZDYxODRiNjlhMTg3YmQ5ZDk2MTA1NzdiNzYwNGI0
10
+ NzM4MmZjMDU0YmJkYjhmYzhkMjgzN2UxZDc0Y2EzMzdjZjg5OGI4MThjZjNm
11
+ NjVmMzY2YWM3YzllMGJiMDc4NGM4NDc5ODE0NWI5ZjhhZDUyYTE=
12
+ data.tar.gz: !binary |-
13
+ Yjg2ODAxZmY5NTlhNTA5MDYxYjkzNDE1MTIwZWU1NGRmNmE3YTI2Zjc5Mjlj
14
+ NDBmOGVhYmNhZmE5YTU4N2ViYTA0ZTJiNTNlZjcyNTFlMDEwMjk2ODFhMTll
15
+ MjMxMDA0ZGU5ZThkZmQ0NDE3MDQ3YjEwODAxZmUxY2EyYTIyNzA=
data/.gitignore ADDED
@@ -0,0 +1,22 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
18
+ *.bundle
19
+ *.so
20
+ *.o
21
+ *.a
22
+ mkmf.log
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --color
2
+ --format documentation
data/.travis.yml ADDED
@@ -0,0 +1,13 @@
1
+ ---
2
+ language: ruby
3
+ before_install:
4
+ - gem install bundler
5
+ install: bundle install
6
+ script: bundle exec rspec --color --format documentation
7
+ notifications:
8
+ email: true
9
+ rvm:
10
+ - 2.0.0
11
+ env:
12
+ global:
13
+ - NOKOGIRI_USE_SYSTEM_LIBRARIES=true
data/CHANGES.md ADDED
@@ -0,0 +1,5 @@
1
+ # rspec-matcher-num-times, changelog
2
+
3
+ ## 0.0.1 2015-06-01 Jason Antman <jason@jasonantman.com>
4
+
5
+ * Initial release
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in rspec-matcher-num-times.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2015 Jason Antman
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,77 @@
1
+ # RspecMatcherNumTimes
2
+
3
+ [![Build Status](https://travis-ci.org/jantman/rspec-matcher-num-times.svg?branch=master)](https://travis-ci.org/jantman/rspec-matcher-num-times)
4
+ [![Code Coverage](https://codecov.io/github/jantman/rspec-matcher-num-times/coverage.svg?branch=master)](https://codecov.io/github/jantman/rspec-matcher-num-times?branch=master)
5
+ [![Code Climate](https://codeclimate.com/github/jantman/rspec-matcher-num-times/badges/gpa.svg)](https://codeclimate.com/github/jantman/rspec-matcher-num-times)
6
+ [![Gem Version](https://img.shields.io/gem/v/rspec-matcher-num-times.svg)](https://rubygems.org/gems/rspec-matcher-num-times)
7
+ [![Total Downloads](https://img.shields.io/gem/dt/rspec-matcher-num-times.svg)](https://rubygems.org/gems/rspec-matcher-num-times)
8
+ [![Github Issues](https://img.shields.io/github/issues/jantman/rspec-matcher-num-times.svg)](https://github.com/jantman/rspec-matcher-num-times/issues)
9
+ [![Project Status: Abandoned - Initial development has started, but there has not yet been a stable, usable release; the project has been abandoned and the author(s) do not intend on continuing development.](http://www.repostatus.org/badges/0.1.0/abandoned.svg)](http://www.repostatus.org/#abandoned)
10
+
11
+ This gem provides some rspec matchers to simplify asserting that something is included or matched N times.
12
+
13
+ ## Installation
14
+
15
+ Add this line to your application's Gemfile:
16
+
17
+ gem 'rspec-matcher-num-times'
18
+
19
+ And then execute:
20
+
21
+ $ bundle
22
+
23
+ Or install it yourself as:
24
+
25
+ $ gem install rspec-matcher-num-times
26
+
27
+ ## Usage
28
+
29
+ In your spec_helper, add a line like:
30
+
31
+ require 'rspec_matcher_num_times'
32
+
33
+ ### Matchers
34
+
35
+ #### include_num_times
36
+
37
+ This matcher tests that a given item occurs N times in an array, or a given
38
+ substring occurs N times in a string.
39
+
40
+ expect('foo bar foo').to include_num_times(2, 'foo')
41
+
42
+ expect(['foo', 'bar', 'foo']).to include_num_times(2, 'foo')
43
+
44
+ #### match_num_times
45
+
46
+ This matcher tests that a given regex is matched N times in a string, or
47
+ that an array has N elements matching the regex.
48
+
49
+ expect('ffooo bar foo').to match_num_times(2, /foo/)
50
+
51
+ expect(['ffooo', 'bar', 'foo foo foo']).to include_num_times(2, /foo/)
52
+
53
+ ## Contributing
54
+
55
+ 1. Fork it ( https://github.com/jantman/rspec-matcher-num-times/fork )
56
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
57
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
58
+ 4. Push to the branch (`git push origin my-new-feature`)
59
+ 5. Create a new Pull Request
60
+
61
+ ## Testing
62
+
63
+ Spec tests are done automatically via Travis CI. They're run using Bundler and rspec.
64
+
65
+ For manual testing:
66
+
67
+ bundle install
68
+ bundle exec rake spec
69
+
70
+ ## Releasing
71
+
72
+ 1. Ensure all tests are passing, coverage is acceptable, etc.
73
+ 2. Increment the version number in ``lib/rspec_matcher_num_times/version.rb``
74
+ 3. Update CHANGES.md
75
+ 4. Push those changes to origin.
76
+ 5. ``bundle exec rake build``
77
+ 6. ``bundle exec rake release``
data/Rakefile ADDED
@@ -0,0 +1,16 @@
1
+ require 'bundler/gem_tasks'
2
+ require 'rubygems'
3
+ require 'bundler/setup'
4
+ require 'rspec/core/rake_task'
5
+ Bundler::GemHelper.install_tasks
6
+
7
+ RSpec::Core::RakeTask.new(:spec) do |t|
8
+ t.pattern = 'spec/**/*_spec.rb'
9
+ end
10
+
11
+ task :default => [:help]
12
+
13
+ desc "Display the list of available rake tasks"
14
+ task :help do
15
+ system("rake -T")
16
+ end
@@ -0,0 +1,55 @@
1
+ require "rspec_matcher_num_times"
2
+
3
+ RSpec::Matchers.define :include_num_times do |num_times, incl_item|
4
+ match do |actual|
5
+ if actual.is_a? String
6
+ actual.scan(incl_item).length == num_times ? true : false
7
+ else
8
+ # we assume an array...
9
+ actual.count(incl_item) == num_times ? true : false
10
+ end
11
+ end
12
+
13
+ match_when_negated do |actual|
14
+ if actual.is_a? String
15
+ actual.scan(incl_item).length == num_times ? false : true
16
+ else
17
+ # we assume an array...
18
+ actual.count(incl_item) == num_times ? false : true
19
+ end
20
+ end
21
+
22
+ failure_message do |actual|
23
+ if actual.is_a? String
24
+ res = actual.scan(incl_item).length
25
+ else
26
+ # we assume an array...
27
+ res = actual.count(incl_item)
28
+ end
29
+ ns = num_str(num_times)
30
+ ns_actual = num_str(res)
31
+ "expected that value would include '#{incl_item}' #{ns}, but it is included #{ns_actual}"
32
+ end
33
+
34
+ failure_message_when_negated do |actual|
35
+ if actual.is_a? String
36
+ res = actual.scan(incl_item).length
37
+ else
38
+ # we assume an array...
39
+ res = actual.count(incl_item)
40
+ end
41
+ ns = num_str(num_times)
42
+ ns_actual = num_str(res)
43
+ "expected that value would not include '#{incl_item}' #{ns}"
44
+ end
45
+
46
+ description do
47
+ ns = num_str(num_times)
48
+ "includes '#{incl_item}' #{ns}"
49
+ end
50
+
51
+ def num_str(n)
52
+ return 'once' if n == 1
53
+ return "#{n} times"
54
+ end
55
+ end
@@ -0,0 +1,55 @@
1
+ require "rspec_matcher_num_times"
2
+
3
+ RSpec::Matchers.define :match_num_times do |num_times, val_regex|
4
+ match do |actual|
5
+ if actual.is_a? String
6
+ actual.scan(val_regex).length == num_times ? true : false
7
+ else
8
+ # we assume an array...
9
+ actual.select{ |x| x[val_regex] }.length == num_times ? true : false
10
+ end
11
+ end
12
+
13
+ match_when_negated do |actual|
14
+ if actual.is_a? String
15
+ actual.scan(val_regex).length == num_times ? false : true
16
+ else
17
+ # we assume an array...
18
+ actual.select{ |x| x[val_regex] }.length == num_times ? false : true
19
+ end
20
+ end
21
+
22
+ failure_message do |actual|
23
+ if actual.is_a? String
24
+ res = actual.scan(val_regex).length
25
+ else
26
+ # we assume an array...
27
+ res = actual.select{ |x| x[val_regex] }.length
28
+ end
29
+ ns = num_str(num_times)
30
+ ns_actual = num_str(res)
31
+ "expected that value would match '#{val_regex.source}' #{ns}, but it is matched #{ns_actual}"
32
+ end
33
+
34
+ failure_message_when_negated do |actual|
35
+ if actual.is_a? String
36
+ res = actual.scan(val_regex).length
37
+ else
38
+ # we assume an array...
39
+ res = actual.select{ |x| x[val_regex] }.length
40
+ end
41
+ ns = num_str(num_times)
42
+ ns_actual = num_str(res)
43
+ "expected that value would not match '#{val_regex.source}' #{ns}"
44
+ end
45
+
46
+ description do
47
+ ns = num_str(num_times)
48
+ "matches '#{val_regex.source}' #{ns}"
49
+ end
50
+
51
+ def num_str(n)
52
+ return 'once' if n == 1
53
+ return "#{n} times"
54
+ end
55
+ end
@@ -0,0 +1,3 @@
1
+ module RspecMatcherNumTimes
2
+ VERSION = "0.0.1"
3
+ end
@@ -0,0 +1,5 @@
1
+ require 'rspec_matcher_num_times/version'
2
+ require 'rspec/expectations'
3
+
4
+ require 'rspec_matcher_num_times/include_num_times'
5
+ require 'rspec_matcher_num_times/match_num_times'
@@ -0,0 +1,25 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'rspec_matcher_num_times/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "rspec-matcher-num-times"
8
+ spec.version = RspecMatcherNumTimes::VERSION
9
+ spec.authors = ["Jason Antman"]
10
+ spec.email = ["jason@jasonantman.com"]
11
+ spec.summary = %q{Rspec matchers for dealing with include and match a given number of times}
12
+ spec.homepage = "https://github.com/jantman/rspec-matcher-num-times"
13
+ spec.license = "MIT"
14
+
15
+ spec.files = `git ls-files -z`.split("\x0")
16
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
17
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
18
+ spec.require_paths = ["lib"]
19
+ spec.add_dependency 'rspec', '>= 3.0'
20
+
21
+ spec.add_development_dependency "bundler", "~> 1.6"
22
+ spec.add_development_dependency "rake"
23
+ spec.add_development_dependency 'simplecov'
24
+ spec.add_development_dependency 'codecov'
25
+ end
@@ -0,0 +1,150 @@
1
+ require 'spec_helper'
2
+ require 'rspec_matcher_num_times'
3
+
4
+ describe '#include_num_times' do
5
+ context 'overall' do
6
+ it "has the correct description for once" do
7
+ matcher = include_num_times(1, 'foo')
8
+ matcher.matches?('foobarbaz')
9
+ expect(matcher.description).to eq "includes 'foo' once"
10
+ end
11
+ it "has the correct description" do
12
+ matcher = include_num_times(3, 'foo')
13
+ matcher.matches?('foobarbaz')
14
+ expect(matcher.description).to eq "includes 'foo' 3 times"
15
+ end
16
+ it "has the correct description for 0" do
17
+ matcher = include_num_times(0, 'foo')
18
+ matcher.matches?('foobarbaz')
19
+ expect(matcher.description).to eq "includes 'foo' 0 times"
20
+ end
21
+ end
22
+ context '.should' do
23
+ context 'string' do
24
+ context 'when not contained' do
25
+ it 'fails' do
26
+ matcher = include_num_times(1, 'foo')
27
+ expect(matcher.matches?('bar baz')).to eq false
28
+ end
29
+ it "has the correct failure message" do
30
+ matcher = include_num_times(1, 'foo')
31
+ matcher.matches?('bar baz')
32
+ expect(matcher.failure_message).to eq "expected that value would include 'foo' once, but it is included 0 times"
33
+ end
34
+ it "fails with correct error" do
35
+ expected_fail = /expected that value would include 'foo' once, but it is included 0 times/m
36
+ expect {
37
+ expect('bar baz').to include_num_times(1, 'foo')
38
+ }.to raise_error(RSpec::Expectations::ExpectationNotMetError).with_message(expected_fail)
39
+ end
40
+ end
41
+ context 'when number of times is wrong' do
42
+ it 'fails' do
43
+ matcher = include_num_times(2, 'foo')
44
+ expect(matcher.matches?('foo bar baz')).to eq false
45
+ end
46
+ it "has the correct failure message" do
47
+ matcher = include_num_times(2, 'foo')
48
+ matcher.matches?('foo bar baz')
49
+ expect(matcher.failure_message).to eq "expected that value would include 'foo' 2 times, but it is included once"
50
+ end
51
+ it "fails with correct error" do
52
+ expected_fail = /expected that value would include 'foo' 2 times, but it is included once/m
53
+ expect {
54
+ expect('foo bar baz').to include_num_times(2, 'foo')
55
+ }.to raise_error(RSpec::Expectations::ExpectationNotMetError).with_message(expected_fail)
56
+ end
57
+ end
58
+ context 'when value matches' do
59
+ it 'succeeds' do
60
+ matcher = include_num_times(3, 'foo')
61
+ expect(matcher.matches?('fooBARfooBAZfoo')).to eq true
62
+ end
63
+ end
64
+ end
65
+ context 'array' do
66
+ context 'when not contained' do
67
+ it 'fails' do
68
+ matcher = include_num_times(1, 'foo')
69
+ expect(matcher.matches?(['bar', 'baz'])).to eq false
70
+ end
71
+ it "has the correct failure message" do
72
+ matcher = include_num_times(1, 'foo')
73
+ matcher.matches?(['bar', 'baz'])
74
+ expect(matcher.failure_message).to eq "expected that value would include 'foo' once, but it is included 0 times"
75
+ end
76
+ it "fails with correct error" do
77
+ expected_fail = /expected that value would include 'foo' once, but it is included 0 times/m
78
+ expect {
79
+ expect(['bar', 'baz']).to include_num_times(1, 'foo')
80
+ }.to raise_error(RSpec::Expectations::ExpectationNotMetError).with_message(expected_fail)
81
+ end
82
+ end
83
+ context 'when number of times is wrong' do
84
+ it 'fails' do
85
+ matcher = include_num_times(2, 'foo')
86
+ expect(matcher.matches?(['foo', 'bar', 'baz'])).to eq false
87
+ end
88
+ it "has the correct failure message" do
89
+ matcher = include_num_times(2, 'foo')
90
+ matcher.matches?(['foo', 'bar', 'baz'])
91
+ expect(matcher.failure_message).to eq "expected that value would include 'foo' 2 times, but it is included once"
92
+ end
93
+ it "fails with correct error" do
94
+ expected_fail = /expected that value would include 'foo' 2 times, but it is included once/m
95
+ expect {
96
+ expect(['foo', 'bar', 'baz']).to include_num_times(2, 'foo')
97
+ }.to raise_error(RSpec::Expectations::ExpectationNotMetError).with_message(expected_fail)
98
+ end
99
+ end
100
+ context 'when value matches' do
101
+ it 'succeeds' do
102
+ matcher = include_num_times(3, 'foo')
103
+ expect(matcher.matches?(['foo', 'BAR', 'foo', 'BAZ', 'foo'])).to eq true
104
+ end
105
+ end
106
+ end
107
+ end
108
+ context '.should_not' do
109
+ context 'string' do
110
+ context 'when number of times is wrong' do
111
+ it 'fails' do
112
+ matcher = include_num_times(1, 'foo')
113
+ expect(matcher.does_not_match?('barfoobaz')).to eq false
114
+ end
115
+ it "fails with correct error" do
116
+ expected_fail = /expected that value would not include 'foo' once/m
117
+ expect {
118
+ expect('barfoobaz').not_to include_num_times(1, 'foo')
119
+ }.to raise_error(RSpec::Expectations::ExpectationNotMetError).with_message(expected_fail)
120
+ end
121
+ end
122
+ context 'when correct' do
123
+ it 'succeeds' do
124
+ matcher = include_num_times(2, 'foo')
125
+ expect(matcher.does_not_match?('fooBARfooBAZfoo')).to eq true
126
+ end
127
+ end
128
+ end
129
+ context 'array' do
130
+ context 'when number of times is wrong' do
131
+ it 'fails' do
132
+ matcher = include_num_times(1, 'foo')
133
+ expect(matcher.does_not_match?(['bar', 'foo', 'baz'])).to eq false
134
+ end
135
+ it "fails with correct error" do
136
+ expected_fail = /expected that value would not include 'foo' once/m
137
+ expect {
138
+ expect(['bar', 'foo', 'baz']).not_to include_num_times(1, 'foo')
139
+ }.to raise_error(RSpec::Expectations::ExpectationNotMetError).with_message(expected_fail)
140
+ end
141
+ end
142
+ context 'when correct' do
143
+ it 'succeeds' do
144
+ matcher = include_num_times(2, 'foo')
145
+ expect(matcher.does_not_match?(['foo', 'BAR', 'foo', 'BAZ', 'foo'])).to eq true
146
+ end
147
+ end
148
+ end
149
+ end
150
+ end
@@ -0,0 +1,156 @@
1
+ require 'spec_helper'
2
+ require 'rspec_matcher_num_times'
3
+
4
+ describe '#match_num_times' do
5
+ context 'overall' do
6
+ it "has the correct description for once" do
7
+ matcher = match_num_times(1, /foo/)
8
+ matcher.matches?('foobarbaz')
9
+ expect(matcher.description).to eq "matches 'foo' once"
10
+ end
11
+ it "has the correct description" do
12
+ matcher = match_num_times(3, /foo/)
13
+ matcher.matches?('foobarbaz')
14
+ expect(matcher.description).to eq "matches 'foo' 3 times"
15
+ end
16
+ it "has the correct description for 0" do
17
+ matcher = match_num_times(0, /foo/)
18
+ matcher.matches?('foobarbaz')
19
+ expect(matcher.description).to eq "matches 'foo' 0 times"
20
+ end
21
+ end
22
+ context '.should' do
23
+ context 'string' do
24
+ context 'when not contained' do
25
+ it 'fails' do
26
+ matcher = match_num_times(1, /foo/)
27
+ expect(matcher.matches?('bar baz')).to eq false
28
+ end
29
+ it "has the correct failure message" do
30
+ matcher = match_num_times(1, /foo/)
31
+ matcher.matches?('bar baz')
32
+ expect(matcher.failure_message).to eq "expected that value would match 'foo' once, but it is matched 0 times"
33
+ end
34
+ it "fails with correct error" do
35
+ expected_fail = /expected that value would match 'foo' once, but it is matched 0 times/m
36
+ expect {
37
+ expect('bar baz').to match_num_times(1, /foo/)
38
+ }.to raise_error(RSpec::Expectations::ExpectationNotMetError).with_message(expected_fail)
39
+ end
40
+ end
41
+ context 'when number of times is wrong' do
42
+ it 'fails' do
43
+ matcher = match_num_times(2, /foo/)
44
+ expect(matcher.matches?('foo bar baz')).to eq false
45
+ end
46
+ it "has the correct failure message" do
47
+ matcher = match_num_times(2, /foo/)
48
+ matcher.matches?('foo bar baz')
49
+ expect(matcher.failure_message).to eq "expected that value would match 'foo' 2 times, but it is matched once"
50
+ end
51
+ it "fails with correct error" do
52
+ expected_fail = /expected that value would match 'foo' 2 times, but it is matched once/m
53
+ expect {
54
+ expect('foo bar baz').to match_num_times(2, /foo/)
55
+ }.to raise_error(RSpec::Expectations::ExpectationNotMetError).with_message(expected_fail)
56
+ end
57
+ it "fails with correct error for multiple matches in sequence" do
58
+ expected_fail = /expected that value would match 'foo' 2 times, but it is matched 3 times/m
59
+ expect {
60
+ expect('foofoofoo bar baz').to match_num_times(2, /foo/)
61
+ }.to raise_error(RSpec::Expectations::ExpectationNotMetError).with_message(expected_fail)
62
+ end
63
+ end
64
+ context 'when value matches' do
65
+ it 'succeeds' do
66
+ matcher = match_num_times(3, /foo/)
67
+ expect(matcher.matches?('fooBARfooBAZfoo')).to eq true
68
+ end
69
+ end
70
+ end
71
+ context 'array' do
72
+ context 'when not contained' do
73
+ it 'fails' do
74
+ matcher = match_num_times(1, /foo/)
75
+ expect(matcher.matches?(['bar', 'baz'])).to eq false
76
+ end
77
+ it "has the correct failure message" do
78
+ matcher = match_num_times(1, /foo/)
79
+ matcher.matches?(['bar', 'baz'])
80
+ expect(matcher.failure_message).to eq "expected that value would match 'foo' once, but it is matched 0 times"
81
+ end
82
+ it "fails with correct error" do
83
+ expected_fail = /expected that value would match 'foo' once, but it is matched 0 times/m
84
+ expect {
85
+ expect(['bar', 'baz']).to match_num_times(1, /foo/)
86
+ }.to raise_error(RSpec::Expectations::ExpectationNotMetError).with_message(expected_fail)
87
+ end
88
+ end
89
+ context 'when number of times is wrong' do
90
+ it 'fails' do
91
+ matcher = match_num_times(2, /foo/)
92
+ expect(matcher.matches?(['foo', 'bar', 'baz'])).to eq false
93
+ end
94
+ it "has the correct failure message" do
95
+ matcher = match_num_times(2, /foo/)
96
+ matcher.matches?(['foo', 'bar', 'baz'])
97
+ expect(matcher.failure_message).to eq "expected that value would match 'foo' 2 times, but it is matched once"
98
+ end
99
+ it "fails with correct error" do
100
+ expected_fail = /expected that value would match 'foo' 2 times, but it is matched once/m
101
+ expect {
102
+ expect(['foo', 'bar', 'baz']).to match_num_times(2, /foo/)
103
+ }.to raise_error(RSpec::Expectations::ExpectationNotMetError).with_message(expected_fail)
104
+ end
105
+ end
106
+ context 'when value matches' do
107
+ it 'succeeds' do
108
+ matcher = match_num_times(3, /foo/)
109
+ expect(matcher.matches?(['foo', 'BAR', 'foo', 'BAZ', 'foo'])).to eq true
110
+ end
111
+ end
112
+ end
113
+ end
114
+ context '.should_not' do
115
+ context 'string' do
116
+ context 'when number of times is wrong' do
117
+ it 'fails' do
118
+ matcher = match_num_times(1, /foo/)
119
+ expect(matcher.does_not_match?('barfoobaz')).to eq false
120
+ end
121
+ it "fails with correct error" do
122
+ expected_fail = /expected that value would not match 'foo' once/m
123
+ expect {
124
+ expect('barfoobaz').not_to match_num_times(1, /foo/)
125
+ }.to raise_error(RSpec::Expectations::ExpectationNotMetError).with_message(expected_fail)
126
+ end
127
+ end
128
+ context 'when correct' do
129
+ it 'succeeds' do
130
+ matcher = match_num_times(2, /foo/)
131
+ expect(matcher.does_not_match?('fooBARfooBAZfoo')).to eq true
132
+ end
133
+ end
134
+ end
135
+ context 'array' do
136
+ context 'when number of times is wrong' do
137
+ it 'fails' do
138
+ matcher = match_num_times(1, /foo/)
139
+ expect(matcher.does_not_match?(['bar', 'foo', 'baz'])).to eq false
140
+ end
141
+ it "fails with correct error" do
142
+ expected_fail = /expected that value would not match 'foo' once/m
143
+ expect {
144
+ expect(['bar', 'foo', 'baz']).not_to match_num_times(1, /foo/)
145
+ }.to raise_error(RSpec::Expectations::ExpectationNotMetError).with_message(expected_fail)
146
+ end
147
+ end
148
+ context 'when correct' do
149
+ it 'succeeds' do
150
+ matcher = match_num_times(2, /foo/)
151
+ expect(matcher.does_not_match?(['foo', 'BAR', 'foo', 'BAZ', 'foo'])).to eq true
152
+ end
153
+ end
154
+ end
155
+ end
156
+ end
@@ -0,0 +1,13 @@
1
+ $LOAD_PATH.unshift File.expand_path('../../lib', __FILE__)
2
+
3
+ require 'simplecov'
4
+ SimpleCov.start do
5
+ add_filter "/vendor/"
6
+ end
7
+
8
+ require 'codecov'
9
+ if ENV['CI']=='true'
10
+ SimpleCov.formatter = SimpleCov::Formatter::Codecov
11
+ end
12
+
13
+ require 'rspec_matcher_num_times'
metadata ADDED
@@ -0,0 +1,133 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: rspec-matcher-num-times
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Jason Antman
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2015-06-02 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: rspec
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ! '>='
18
+ - !ruby/object:Gem::Version
19
+ version: '3.0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ! '>='
25
+ - !ruby/object:Gem::Version
26
+ version: '3.0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: bundler
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ~>
32
+ - !ruby/object:Gem::Version
33
+ version: '1.6'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ~>
39
+ - !ruby/object:Gem::Version
40
+ version: '1.6'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rake
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ! '>='
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ! '>='
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: simplecov
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ! '>='
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ! '>='
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: codecov
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ! '>='
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - ! '>='
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
83
+ description:
84
+ email:
85
+ - jason@jasonantman.com
86
+ executables: []
87
+ extensions: []
88
+ extra_rdoc_files: []
89
+ files:
90
+ - .gitignore
91
+ - .rspec
92
+ - .travis.yml
93
+ - CHANGES.md
94
+ - Gemfile
95
+ - LICENSE.txt
96
+ - README.md
97
+ - Rakefile
98
+ - lib/rspec_matcher_num_times.rb
99
+ - lib/rspec_matcher_num_times/include_num_times.rb
100
+ - lib/rspec_matcher_num_times/match_num_times.rb
101
+ - lib/rspec_matcher_num_times/version.rb
102
+ - rspec-matcher-num-times.gemspec
103
+ - spec/rspec_matcher_num_times/include_num_times_spec.rb
104
+ - spec/rspec_matcher_num_times/match_num_times_spec.rb
105
+ - spec/spec_helper.rb
106
+ homepage: https://github.com/jantman/rspec-matcher-num-times
107
+ licenses:
108
+ - MIT
109
+ metadata: {}
110
+ post_install_message:
111
+ rdoc_options: []
112
+ require_paths:
113
+ - lib
114
+ required_ruby_version: !ruby/object:Gem::Requirement
115
+ requirements:
116
+ - - ! '>='
117
+ - !ruby/object:Gem::Version
118
+ version: '0'
119
+ required_rubygems_version: !ruby/object:Gem::Requirement
120
+ requirements:
121
+ - - ! '>='
122
+ - !ruby/object:Gem::Version
123
+ version: '0'
124
+ requirements: []
125
+ rubyforge_project:
126
+ rubygems_version: 2.2.2
127
+ signing_key:
128
+ specification_version: 4
129
+ summary: Rspec matchers for dealing with include and match a given number of times
130
+ test_files:
131
+ - spec/rspec_matcher_num_times/include_num_times_spec.rb
132
+ - spec/rspec_matcher_num_times/match_num_times_spec.rb
133
+ - spec/spec_helper.rb