matchi 0.1.2 → 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: bf3ff8d046c12b8859a24a5c777cd0f3546f73b1
4
- data.tar.gz: c75ed231f342591b9fb61e7e204eb7ca617e6c4a
3
+ metadata.gz: 4a9dac2b12567695a9191ab629a8ccdaab8a646f
4
+ data.tar.gz: ba2560c4a1f9cdff593d09e32a60a23cdb7da9b1
5
5
  SHA512:
6
- metadata.gz: ec2c6160e00dd0c8f657cc241875051c006e6317c3226f195cc6a8f81a893ae67bf2d3ce2da422171de353f201c9c5b3dadcfeefadd4d8a58f18a5e2d47043d9
7
- data.tar.gz: d5882ffb24781166aa7a72b3848dd08e1d33c8acf6b6f00ee0f8eebed103b886963369d0b643d2bc3fdbafc2d7a6baf174af1ccc463c2dd0ae70d701ba19195c
6
+ metadata.gz: 7fc866f6d5896aa2994e95ce5871c10550af70244bda79d7a31351b5c518609d55944260d513f72e5a426d10c55c927b8b9e6b36cb78c6a6b513f3e78ddc664e
7
+ data.tar.gz: 355636b846a23088be8b3af819fd4e5994bb2d72feba117133f35a3135904bd6010693454d10ef20c58e766bf9a8056407060d9c3c7c2b7df023b45d89543045
checksums.yaml.gz.sig CHANGED
Binary file
data/README.md CHANGED
@@ -49,49 +49,49 @@ And then execute:
49
49
  **Equivalence** matcher:
50
50
 
51
51
  ```ruby
52
- eql = Matchi::Eql.new('foo')
52
+ eql = Matchi::Matchers::Eql::Matcher.new('foo')
53
53
  eql.matches? { 'foo' } # => true
54
54
  ```
55
55
 
56
56
  **Identity** matcher:
57
57
 
58
58
  ```ruby
59
- equal = Matchi::Equal.new(:foo)
59
+ equal = Matchi::Matchers::Equal::Matcher.new(:foo)
60
60
  equal.matches? { :foo } # => true
61
61
  ```
62
62
 
63
63
  **Regular expressions** matcher:
64
64
 
65
65
  ```ruby
66
- match = Matchi::Match.new(/^foo$/)
66
+ match = Matchi::Matchers::Match::Matcher.new(/^foo$/)
67
67
  match.matches? { 'foo' } # => true
68
68
  ```
69
69
 
70
70
  **Expecting errors** matcher:
71
71
 
72
72
  ```ruby
73
- raise_exception = Matchi::RaiseException.new(NameError)
73
+ raise_exception = Matchi::Matchers::RaiseException::Matcher.new(NameError)
74
74
  raise_exception.matches? { Boom } # => true
75
75
  ```
76
76
 
77
77
  **Truth** matcher:
78
78
 
79
79
  ```ruby
80
- be_true = Matchi::BeTrue.new
80
+ be_true = Matchi::Matchers::BeTrue::Matcher.new
81
81
  be_true.matches? { true } # => true
82
82
  ```
83
83
 
84
84
  **Untruth** matcher:
85
85
 
86
86
  ```ruby
87
- be_false = Matchi::BeFalse.new
87
+ be_false = Matchi::Matchers::BeFalse::Matcher.new
88
88
  be_false.matches? { false } # => true
89
89
  ```
90
90
 
91
91
  **Nil** matcher:
92
92
 
93
93
  ```ruby
94
- be_nil = Matchi::BeNil.new
94
+ be_nil = Matchi::Matchers::BeNil::Matcher.new
95
95
  be_nil.matches? { nil } # => true
96
96
  ```
97
97
 
@@ -99,78 +99,90 @@ be_nil.matches? { nil } # => true
99
99
 
100
100
  Custom matchers can easily be defined for expressing expectations. They can be any Ruby class that responds to `matches?`, `to_s` and `to_h` instance methods.
101
101
 
102
- **Be the answer** matcher:
102
+ A **Be the answer** matcher:
103
103
 
104
104
  ```ruby
105
105
  module Matchi
106
- class BeTheAnswer
107
- def matches?
108
- 42.equal? yield
109
- end
110
-
111
- def to_s
112
- 'be_the_answer'
113
- end
114
-
115
- def to_h
116
- { BeTheAnswer: [] }
106
+ module Matchers
107
+ module BeTheAnswer
108
+ class Matcher
109
+ def matches?
110
+ 42.equal? yield
111
+ end
112
+
113
+ def to_s
114
+ 'be_the_answer'
115
+ end
116
+
117
+ def to_h
118
+ { BeTheAnswer: [] }
119
+ end
120
+ end
117
121
  end
118
122
  end
119
123
  end
120
124
 
121
- be_the_answer = Matchi::BeTheAnswer.new
125
+ be_the_answer = Matchi::Matchers::BeTheAnswer::Matcher.new
122
126
  be_the_answer.matches? { 42 } # => true
123
127
  ```
124
128
 
125
- **Be prime** matcher:
129
+ A **Be prime** matcher:
126
130
 
127
131
  ```ruby
128
132
  require 'prime'
129
133
 
130
134
  module Matchi
131
- class BePrime
132
- def matches?
133
- Prime.prime? yield
134
- end
135
-
136
- def to_s
137
- 'be_prime'
138
- end
139
-
140
- def to_h
141
- { BePrime: [] }
135
+ module Matchers
136
+ module BePrime
137
+ class Matcher
138
+ def matches?
139
+ Prime.prime? yield
140
+ end
141
+
142
+ def to_s
143
+ 'be_prime'
144
+ end
145
+
146
+ def to_h
147
+ { BePrime: [] }
148
+ end
149
+ end
142
150
  end
143
151
  end
144
152
  end
145
153
 
146
- be_prime = Matchi::BePrime.new
154
+ be_prime = Matchi::Matchers::BePrime::Matcher.new
147
155
  be_prime.matches? { 42 } # => false
148
156
  ```
149
157
 
150
- **Start with** matcher:
158
+ A **Start with** matcher:
151
159
 
152
160
  ```ruby
153
161
  module Matchi
154
- class StartWith
155
- def initialize(expected)
156
- @expected = expected
157
- end
158
-
159
- def matches?
160
- !Regexp.new("^#{@expected}").match(yield).nil?
161
- end
162
-
163
- def to_s
164
- 'start_with'
165
- end
166
-
167
- def to_h
168
- { StartWith: [@expected] }
162
+ module Matchers
163
+ module StartWith
164
+ class Matcher
165
+ def initialize(expected)
166
+ @expected = expected
167
+ end
168
+
169
+ def matches?
170
+ !Regexp.new("^#{@expected}").match(yield).nil?
171
+ end
172
+
173
+ def to_s
174
+ 'start_with'
175
+ end
176
+
177
+ def to_h
178
+ { StartWith: [@expected] }
179
+ end
180
+ end
169
181
  end
170
182
  end
171
183
  end
172
184
 
173
- start_with = Matchi::StartWith.new('foo')
185
+ start_with = Matchi::Matchers::StartWith::Matcher.new('foo')
174
186
  start_with.matches? { 'foobar' } # => true
175
187
  ```
176
188
 
@@ -207,3 +219,9 @@ See `LICENSE.md` file.
207
219
  [travis]: https://travis-ci.org/fixrb/matchi
208
220
  [inchpages]: http://inch-ci.org/github/fixrb/matchi/
209
221
  [rubydoc]: http://rubydoc.info/gems/matchi/frames
222
+
223
+ ***
224
+
225
+ This project is sponsored by:
226
+
227
+ [![Sashite](http://www.sashite.com/assets/img/sashite.png)](http://www.sashite.com/)
data/VERSION.semver CHANGED
@@ -1 +1 @@
1
- 0.1.2
1
+ 1.0.0
@@ -0,0 +1 @@
1
+ ddc127123b3b59b5edaa5532d60521c7bec45d1889d84ac282d461928066ef0646ae3cfe312adba700d21da17f33be17efca258533e512f2f63a9eae7085831c
@@ -0,0 +1,28 @@
1
+ require_relative File.join('..', 'matchers_base') unless
2
+ defined?(::Matchi::MatchersBase)
3
+
4
+ module Matchi
5
+ module Matchers
6
+ # **Untruth** matcher.
7
+ module BeFalse
8
+ # The matcher.
9
+ class Matcher
10
+ include MatchersBase
11
+
12
+ # Boolean comparison between the actual value and the expected value.
13
+ #
14
+ # @example Is it false?
15
+ # be_false = Matchi::Matchers::BeFalse::Matcher.new
16
+ # be_false.matches? { false } # => true
17
+ #
18
+ # @yieldreturn [#object_id] the actual value to compare to the expected
19
+ # one.
20
+ #
21
+ # @return [Boolean] Comparison between actual and expected values.
22
+ def matches?
23
+ false.equal?(yield)
24
+ end
25
+ end
26
+ end
27
+ end
28
+ end
@@ -0,0 +1,28 @@
1
+ require_relative File.join('..', 'matchers_base') unless
2
+ defined?(::Matchi::MatchersBase)
3
+
4
+ module Matchi
5
+ module Matchers
6
+ # **Nil** matcher.
7
+ module BeNil
8
+ # The matcher.
9
+ class Matcher
10
+ include MatchersBase
11
+
12
+ # Boolean comparison between the actual value and the expected value.
13
+ #
14
+ # @example Is it nil?
15
+ # be_nil = Matchi::Matchers::BeNil::Matcher.new
16
+ # be_nil.matches? { nil } # => true
17
+ #
18
+ # @yieldreturn [#object_id] the actual value to compare to the expected
19
+ # one.
20
+ #
21
+ # @return [Boolean] Comparison between actual and expected values.
22
+ def matches?
23
+ nil.equal?(yield)
24
+ end
25
+ end
26
+ end
27
+ end
28
+ end
@@ -0,0 +1,28 @@
1
+ require_relative File.join('..', 'matchers_base') unless
2
+ defined?(::Matchi::MatchersBase)
3
+
4
+ module Matchi
5
+ module Matchers
6
+ # **Truth** matcher.
7
+ module BeTrue
8
+ # The matcher.
9
+ class Matcher
10
+ include MatchersBase
11
+
12
+ # Boolean comparison between the actual value and the expected value.
13
+ #
14
+ # @example Is it true?
15
+ # be_true = Matchi::Matchers::BeTrue::Matcher.new
16
+ # be_true.matches? { true } # => true
17
+ #
18
+ # @yieldreturn [#object_id] the actual value to compare to the expected
19
+ # one.
20
+ #
21
+ # @return [Boolean] Comparison between actual and expected values.
22
+ def matches?
23
+ true.equal?(yield)
24
+ end
25
+ end
26
+ end
27
+ end
28
+ end
@@ -0,0 +1,38 @@
1
+ require_relative File.join('..', 'matchers_base') unless
2
+ defined?(::Matchi::MatchersBase)
3
+
4
+ module Matchi
5
+ module Matchers
6
+ # **Equivalence** matcher.
7
+ module Eql
8
+ # The matcher.
9
+ class Matcher
10
+ include MatchersBase
11
+
12
+ # Initialize the matcher with an object.
13
+ #
14
+ # @example The string 'foo' matcher.
15
+ # Matchi::Matchers::Eql::Matcher.new('foo')
16
+ #
17
+ # @param expected [#eql?] An expected equivalent object.
18
+ def initialize(expected)
19
+ @expected = expected
20
+ end
21
+
22
+ # Boolean comparison between the actual value and the expected value.
23
+ #
24
+ # @example Is it equivalent to 'foo'?
25
+ # eql = Matchi::Matchers::Eql::Matcher.new('foo')
26
+ # eql.matches? { 'foo' } # => true
27
+ #
28
+ # @yieldreturn [#object_id] the actual value to compare to the expected
29
+ # one.
30
+ #
31
+ # @return [Boolean] Comparison between actual and expected values.
32
+ def matches?
33
+ @expected.eql?(yield)
34
+ end
35
+ end
36
+ end
37
+ end
38
+ end
@@ -0,0 +1,38 @@
1
+ require_relative File.join('..', 'matchers_base') unless
2
+ defined?(::Matchi::MatchersBase)
3
+
4
+ module Matchi
5
+ module Matchers
6
+ # **Identity** matcher.
7
+ module Equal
8
+ # The matcher.
9
+ class Matcher
10
+ include MatchersBase
11
+
12
+ # Initialize the matcher with an object.
13
+ #
14
+ # @example The number 42 matcher.
15
+ # Matchi::Matchers::Equal::Matcher.new(42)
16
+ #
17
+ # @param expected [#equal?] An expected object.
18
+ def initialize(expected)
19
+ @expected = expected
20
+ end
21
+
22
+ # Boolean comparison between the actual value and the expected value.
23
+ #
24
+ # @example Is it equal to :foo?
25
+ # equal = Matchi::Matchers::Equal::Matcher.new(:foo)
26
+ # equal.matches? { :foo } # => true
27
+ #
28
+ # @yieldreturn [#object_id] the actual value to compare to the expected
29
+ # one.
30
+ #
31
+ # @return [Boolean] Comparison between actual and expected values.
32
+ def matches?
33
+ @expected.equal?(yield)
34
+ end
35
+ end
36
+ end
37
+ end
38
+ end
@@ -0,0 +1,38 @@
1
+ require_relative File.join('..', 'matchers_base') unless
2
+ defined?(::Matchi::MatchersBase)
3
+
4
+ module Matchi
5
+ module Matchers
6
+ # **Regular expressions** matcher.
7
+ module Match
8
+ # The matcher.
9
+ class Matcher
10
+ include MatchersBase
11
+
12
+ # Initialize the matcher with an instance of Regexp.
13
+ #
14
+ # @example Username matcher.
15
+ # Matchi::Matchers::Match::Matcher.new(/^[a-z0-9_-]{3,16}$/)
16
+ #
17
+ # @param expected [#match] A regular expression.
18
+ def initialize(expected)
19
+ @expected = expected
20
+ end
21
+
22
+ # Boolean comparison between the actual value and the expected value.
23
+ #
24
+ # @example Is it matching /^foo$/ regex?
25
+ # match = Matchi::Matchers::Match::Matcher.new(/^foo$/)
26
+ # match.matches? { 'foo' } # => true
27
+ #
28
+ # @yieldreturn [#object_id] the actual value to compare to the expected
29
+ # one.
30
+ #
31
+ # @return [Boolean] Comparison between actual and expected values.
32
+ def matches?
33
+ @expected.match(yield).nil?.equal?(false)
34
+ end
35
+ end
36
+ end
37
+ end
38
+ end
@@ -0,0 +1,42 @@
1
+ require_relative File.join('..', 'matchers_base') unless
2
+ defined?(::Matchi::MatchersBase)
3
+
4
+ module Matchi
5
+ module Matchers
6
+ # **Expecting errors** matcher.
7
+ module RaiseException
8
+ # The matcher.
9
+ class Matcher
10
+ include MatchersBase
11
+
12
+ # Initialize the matcher with a descendant of class Exception.
13
+ #
14
+ # @example Divided by 0 matcher.
15
+ # Matchi::Matchers::RaiseException::Matcher.new(ZeroDivisionError)
16
+ #
17
+ # @param expected [.exception] The class of the expected exception.
18
+ def initialize(expected)
19
+ @expected = expected
20
+ end
21
+
22
+ # Boolean comparison between the actual value and the expected value.
23
+ #
24
+ # @example Is it raising NameError?
25
+ # matcher = Matchi::Matchers::RaiseException::Matcher.new(NameError)
26
+ # matcher.matches? { Boom } # => true
27
+ #
28
+ # @yieldreturn [#object_id] the actual value to compare to the expected
29
+ # one.
30
+ #
31
+ # @return [Boolean] Comparison between actual and expected values.
32
+ def matches?
33
+ yield
34
+ rescue @expected
35
+ true
36
+ else
37
+ false
38
+ end
39
+ end
40
+ end
41
+ end
42
+ end
@@ -0,0 +1,9 @@
1
+ module Matchi
2
+ # Collection of matchers.
3
+ module Matchers
4
+ end
5
+ end
6
+
7
+ Dir[File.join File.dirname(__FILE__), 'matchers', '*.rb'].each do |fname|
8
+ require_relative fname
9
+ end
@@ -0,0 +1,49 @@
1
+ module Matchi
2
+ # Common matcher methods.
3
+ module MatchersBase
4
+ # Abstract matcher class.
5
+ #
6
+ # @raise [NotImplementedError] Override me inside a Matcher subclass please.
7
+ def matches?
8
+ fail NotImplementedError, 'The matcher MUST respond to matches? method.'
9
+ end
10
+
11
+ # Returns a string representing the matcher.
12
+ #
13
+ # @example The readable definition of a FooBar matcher.
14
+ # matcher = Matchi::Matchers::FooBar::Matcher.new(42)
15
+ # matcher.to_s # => "foo_bar 42"
16
+ #
17
+ # @return [String] A string representing the matcher.
18
+ def to_s
19
+ s = matcher_name
20
+ .gsub(/([A-Z]+)([A-Z][a-z])/, '\1_\2')
21
+ .gsub(/([a-z\d])([A-Z])/, '\1_\2')
22
+ .downcase
23
+
24
+ defined?(@expected) ? [s, @expected.inspect].join(' ') : s
25
+ end
26
+
27
+ # Returns a hash of one key-value pair with a key corresponding to the
28
+ # matcher and a value corresponding to its initialize parameters.
29
+ #
30
+ # @example A FooBar matcher serialized into a hash.
31
+ # matcher = Matchi::Matchers::FooBar::Matcher.new(42)
32
+ # matcher.to_h # => { FooBar: 42 }
33
+ #
34
+ # @return [Hash] A hash of one key-value pair.
35
+ def to_h
36
+ { matcher_name.to_sym => (defined?(@expected) ? Array(@expected) : []) }
37
+ end
38
+
39
+ private
40
+
41
+ def matcher_name
42
+ self
43
+ .class
44
+ .name
45
+ .gsub(/^Matchi::Matchers::/, '')
46
+ .gsub(/::Matcher$/, '')
47
+ end
48
+ end
49
+ end
data/lib/matchi.rb CHANGED
@@ -2,6 +2,4 @@
2
2
  module Matchi
3
3
  end
4
4
 
5
- Dir[File.join File.dirname(__FILE__), 'matchi', '*.rb'].each do |fname|
6
- require_relative fname
7
- end
5
+ require_relative File.join('matchi', 'matchers')
data/matchi.gemspec CHANGED
@@ -18,7 +18,8 @@ Gem::Specification.new do |spec|
18
18
  spec.add_development_dependency 'rake', '~> 10.4'
19
19
  spec.add_development_dependency 'yard', '~> 0.8'
20
20
  spec.add_development_dependency 'simplecov', '~> 0.10'
21
- spec.add_development_dependency 'rubocop', '~> 0.34'
21
+ spec.add_development_dependency 'rubocop', '~> 0.35'
22
+ spec.add_development_dependency 'byebug'
22
23
 
23
24
  spec.cert_chain = ['certs/gem-fixrb-public_cert.pem']
24
25
  private_key = File.expand_path('~/.ssh/gem-fixrb-private_key.pem')
data.tar.gz.sig CHANGED
Binary file
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: matchi
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.2
4
+ version: 1.0.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Cyril Wack
@@ -30,7 +30,7 @@ cert_chain:
30
30
  dzJvWzQ1+dJU6WQv75E9ddSkaQrK3nhdgQVu+/wgvGSrsMvOGNz+LXaSDxQqZuwX
31
31
  0KNQFuIukfrdk8URwRnHoAnvx4U93iUw
32
32
  -----END CERTIFICATE-----
33
- date: 2015-10-31 00:00:00.000000000 Z
33
+ date: 2015-11-26 00:00:00.000000000 Z
34
34
  dependencies:
35
35
  - !ruby/object:Gem::Dependency
36
36
  name: bundler
@@ -94,14 +94,28 @@ dependencies:
94
94
  requirements:
95
95
  - - "~>"
96
96
  - !ruby/object:Gem::Version
97
- version: '0.34'
97
+ version: '0.35'
98
98
  type: :development
99
99
  prerelease: false
100
100
  version_requirements: !ruby/object:Gem::Requirement
101
101
  requirements:
102
102
  - - "~>"
103
103
  - !ruby/object:Gem::Version
104
- version: '0.34'
104
+ version: '0.35'
105
+ - !ruby/object:Gem::Dependency
106
+ name: byebug
107
+ requirement: !ruby/object:Gem::Requirement
108
+ requirements:
109
+ - - ">="
110
+ - !ruby/object:Gem::Version
111
+ version: '0'
112
+ type: :development
113
+ prerelease: false
114
+ version_requirements: !ruby/object:Gem::Requirement
115
+ requirements:
116
+ - - ">="
117
+ - !ruby/object:Gem::Version
118
+ version: '0'
105
119
  description: Collection of expectation matchers for Ruby.
106
120
  email:
107
121
  - contact@cyril.email
@@ -132,14 +146,17 @@ files:
132
146
  - checksum/matchi-0.0.9.gem.sha512
133
147
  - checksum/matchi-0.1.0.gem.sha512
134
148
  - checksum/matchi-0.1.1.gem.sha512
149
+ - checksum/matchi-0.1.2.gem.sha512
135
150
  - lib/matchi.rb
136
- - lib/matchi/be_false.rb
137
- - lib/matchi/be_nil.rb
138
- - lib/matchi/be_true.rb
139
- - lib/matchi/eql.rb
140
- - lib/matchi/equal.rb
141
- - lib/matchi/match.rb
142
- - lib/matchi/raise_exception.rb
151
+ - lib/matchi/matchers.rb
152
+ - lib/matchi/matchers/be_false.rb
153
+ - lib/matchi/matchers/be_nil.rb
154
+ - lib/matchi/matchers/be_true.rb
155
+ - lib/matchi/matchers/eql.rb
156
+ - lib/matchi/matchers/equal.rb
157
+ - lib/matchi/matchers/match.rb
158
+ - lib/matchi/matchers/raise_exception.rb
159
+ - lib/matchi/matchers_base.rb
143
160
  - matchi.gemspec
144
161
  - pkg_checksum
145
162
  homepage: https://github.com/fixrb/matchi
@@ -162,7 +179,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
162
179
  version: '0'
163
180
  requirements: []
164
181
  rubyforge_project:
165
- rubygems_version: 2.4.5
182
+ rubygems_version: 2.4.5.1
166
183
  signing_key:
167
184
  specification_version: 4
168
185
  summary: Collection of matchers.
metadata.gz.sig CHANGED
@@ -1 +1 @@
1
- �����E�d��*~���K�f���Z��8UL�����3��N�SbKfU�̃�A�������Q�� KEE";R�t<��wWKݰ���{=֚�L���|@��`�]"���Y0��A=+�ϥb��~eIa1-}���0,���|�6Xe�!���Z�� sdxL"���G{��lc6��qQ�=����w'p��f�*r��ڨ>��g1Ӹ�vΨ(�Uz�ʝ�+����T�Pb��u'���
1
+ ����ע4&��@[B�!*4������=f�\A��9eU�-+��c��[EhZ}���<[ۜ�4"sOXO3�9S��D�LɈUۢm��N=�sRo3�/��.����zVY������p⣉=�s6i����#�y&`Mn�K��r�5�������{n\^L�Jv ���M:4:h0��<�,g_ou�gs'SnKxgvCvaVԠ�>�+y�ʅ�V�>���=ɏ�ϛ=�y��SMI ��t
@@ -1,40 +0,0 @@
1
- module Matchi
2
- # **Untruth** matcher.
3
- class BeFalse
4
- # Boolean comparison between the actual value and the expected value.
5
- #
6
- # @example Is it false?
7
- # be_false = Matchi::BeFalse.new
8
- # be_false.matches? { false } # => true
9
- #
10
- # @yieldreturn [#object_id] the actual value to compare to the expected one.
11
- #
12
- # @return [Boolean] Comparison between actual and expected values.
13
- def matches?
14
- false.equal?(yield)
15
- end
16
-
17
- # Returns a string representing the matcher.
18
- #
19
- # @example The readable definition of a FooBar matcher.
20
- # matcher = Matchi::FooBar.new(42)
21
- # matcher.to_s # => "foo_bar 42"
22
- #
23
- # @return [String] A string representing the matcher.
24
- def to_s
25
- 'be_false'
26
- end
27
-
28
- # Returns a hash of one key-value pair with a key corresponding to the
29
- # matcher and a value corresponding to its initialize parameters.
30
- #
31
- # @example A FooBar matcher serialized into a hash.
32
- # matcher = Matchi::FooBar.new(42)
33
- # matcher.to_h # => { FooBar: 42 }
34
- #
35
- # @return [Hash] A hash of one key-value pair.
36
- def to_h
37
- { BeFalse: [] }
38
- end
39
- end
40
- end
data/lib/matchi/be_nil.rb DELETED
@@ -1,40 +0,0 @@
1
- module Matchi
2
- # **Nil** matcher.
3
- class BeNil
4
- # Boolean comparison between the actual value and the expected value.
5
- #
6
- # @example Is it nil?
7
- # be_nil = Matchi::BeNil.new
8
- # be_nil.matches? { nil } # => true
9
- #
10
- # @yieldreturn [#object_id] the actual value to compare to the expected one.
11
- #
12
- # @return [Boolean] Comparison between actual and expected values.
13
- def matches?
14
- nil.equal?(yield)
15
- end
16
-
17
- # Returns a string representing the matcher.
18
- #
19
- # @example The readable definition of a FooBar matcher.
20
- # matcher = Matchi::FooBar.new(42)
21
- # matcher.to_s # => "foo_bar 42"
22
- #
23
- # @return [String] A string representing the matcher.
24
- def to_s
25
- 'be_nil'
26
- end
27
-
28
- # Returns a hash of one key-value pair with a key corresponding to the
29
- # matcher and a value corresponding to its initialize parameters.
30
- #
31
- # @example A FooBar matcher serialized into a hash.
32
- # matcher = Matchi::FooBar.new(42)
33
- # matcher.to_h # => { FooBar: 42 }
34
- #
35
- # @return [Hash] A hash of one key-value pair.
36
- def to_h
37
- { BeNil: [] }
38
- end
39
- end
40
- end
@@ -1,40 +0,0 @@
1
- module Matchi
2
- # **Truth** matcher.
3
- class BeTrue
4
- # Boolean comparison between the actual value and the expected value.
5
- #
6
- # @example Is it true?
7
- # be_true = Matchi::BeTrue.new
8
- # be_true.matches? { true } # => true
9
- #
10
- # @yieldreturn [#object_id] the actual value to compare to the expected one.
11
- #
12
- # @return [Boolean] Comparison between actual and expected values.
13
- def matches?
14
- true.equal?(yield)
15
- end
16
-
17
- # Returns a string representing the matcher.
18
- #
19
- # @example The readable definition of a FooBar matcher.
20
- # matcher = Matchi::FooBar.new(42)
21
- # matcher.to_s # => "foo_bar 42"
22
- #
23
- # @return [String] A string representing the matcher.
24
- def to_s
25
- 'be_true'
26
- end
27
-
28
- # Returns a hash of one key-value pair with a key corresponding to the
29
- # matcher and a value corresponding to its initialize parameters.
30
- #
31
- # @example A FooBar matcher serialized into a hash.
32
- # matcher = Matchi::FooBar.new(42)
33
- # matcher.to_h # => { FooBar: 42 }
34
- #
35
- # @return [Hash] A hash of one key-value pair.
36
- def to_h
37
- { BeTrue: [] }
38
- end
39
- end
40
- end
data/lib/matchi/eql.rb DELETED
@@ -1,50 +0,0 @@
1
- module Matchi
2
- # **Equivalence** matcher.
3
- class Eql
4
- # Initialize the matcher with an object.
5
- #
6
- # @example The string 'foo' matcher.
7
- # Matchi::Eql.new('foo')
8
- #
9
- # @param expected [#eql?] An expected equivalent object.
10
- def initialize(expected)
11
- @expected = expected
12
- end
13
-
14
- # Boolean comparison between the actual value and the expected value.
15
- #
16
- # @example Is it equivalent to 'foo'?
17
- # eql = Matchi::Eql.new('foo')
18
- # eql.matches? { 'foo' } # => true
19
- #
20
- # @yieldreturn [#object_id] the actual value to compare to the expected one.
21
- #
22
- # @return [Boolean] Comparison between actual and expected values.
23
- def matches?
24
- @expected.eql?(yield)
25
- end
26
-
27
- # Returns a string representing the matcher.
28
- #
29
- # @example The readable definition of a FooBar matcher.
30
- # matcher = Matchi::FooBar.new(42)
31
- # matcher.to_s # => "foo_bar 42"
32
- #
33
- # @return [String] A string representing the matcher.
34
- def to_s
35
- "eql #{@expected.inspect}"
36
- end
37
-
38
- # Returns a hash of one key-value pair with a key corresponding to the
39
- # matcher and a value corresponding to its initialize parameters.
40
- #
41
- # @example A FooBar matcher serialized into a hash.
42
- # matcher = Matchi::FooBar.new(42)
43
- # matcher.to_h # => { FooBar: 42 }
44
- #
45
- # @return [Hash] A hash of one key-value pair.
46
- def to_h
47
- { Eql: [@expected] }
48
- end
49
- end
50
- end
data/lib/matchi/equal.rb DELETED
@@ -1,50 +0,0 @@
1
- module Matchi
2
- # **Identity** matcher.
3
- class Equal
4
- # Initialize the matcher with an object.
5
- #
6
- # @example The number 42 matcher.
7
- # Matchi::Equal.new(42)
8
- #
9
- # @param expected [#equal?] An expected object.
10
- def initialize(expected)
11
- @expected = expected
12
- end
13
-
14
- # Boolean comparison between the actual value and the expected value.
15
- #
16
- # @example Is it equal to :foo?
17
- # equal = Matchi::Equal.new(:foo)
18
- # equal.matches? { :foo } # => true
19
- #
20
- # @yieldreturn [#object_id] the actual value to compare to the expected one.
21
- #
22
- # @return [Boolean] Comparison between actual and expected values.
23
- def matches?
24
- @expected.equal?(yield)
25
- end
26
-
27
- # Returns a string representing the matcher.
28
- #
29
- # @example The readable definition of a FooBar matcher.
30
- # matcher = Matchi::FooBar.new(42)
31
- # matcher.to_s # => "foo_bar 42"
32
- #
33
- # @return [String] A string representing the matcher.
34
- def to_s
35
- "equal #{@expected.inspect}"
36
- end
37
-
38
- # Returns a hash of one key-value pair with a key corresponding to the
39
- # matcher and a value corresponding to its initialize parameters.
40
- #
41
- # @example A FooBar matcher serialized into a hash.
42
- # matcher = Matchi::FooBar.new(42)
43
- # matcher.to_h # => { FooBar: 42 }
44
- #
45
- # @return [Hash] A hash of one key-value pair.
46
- def to_h
47
- { Equal: [@expected] }
48
- end
49
- end
50
- end
data/lib/matchi/match.rb DELETED
@@ -1,50 +0,0 @@
1
- module Matchi
2
- # **Regular expressions** matcher.
3
- class Match
4
- # Initialize the matcher with an instance of Regexp.
5
- #
6
- # @example Username matcher.
7
- # Matchi::Match.new(/^[a-z0-9_-]{3,16}$/)
8
- #
9
- # @param expected [#match] A regular expression.
10
- def initialize(expected)
11
- @expected = expected
12
- end
13
-
14
- # Boolean comparison between the actual value and the expected value.
15
- #
16
- # @example Is it matching /^foo$/ regex?
17
- # match = Matchi::Match.new(/^foo$/)
18
- # match.matches? { 'foo' } # => true
19
- #
20
- # @yieldreturn [#object_id] the actual value to compare to the expected one.
21
- #
22
- # @return [Boolean] Comparison between actual and expected values.
23
- def matches?
24
- @expected.match(yield).nil?.equal?(false)
25
- end
26
-
27
- # Returns a string representing the matcher.
28
- #
29
- # @example The readable definition of a FooBar matcher.
30
- # matcher = Matchi::FooBar.new(42)
31
- # matcher.to_s # => "foo_bar 42"
32
- #
33
- # @return [String] A string representing the matcher.
34
- def to_s
35
- "match #{@expected.inspect}"
36
- end
37
-
38
- # Returns a hash of one key-value pair with a key corresponding to the
39
- # matcher and a value corresponding to its initialize parameters.
40
- #
41
- # @example A FooBar matcher serialized into a hash.
42
- # matcher = Matchi::FooBar.new(42)
43
- # matcher.to_h # => { FooBar: 42 }
44
- #
45
- # @return [Hash] A hash of one key-value pair.
46
- def to_h
47
- { Match: [@expected] }
48
- end
49
- end
50
- end
@@ -1,54 +0,0 @@
1
- module Matchi
2
- # **Expecting errors** matcher.
3
- class RaiseException
4
- # Initialize the matcher with a descendant of class Exception.
5
- #
6
- # @example Divided by 0 matcher.
7
- # Matchi::RaiseException.new(ZeroDivisionError)
8
- #
9
- # @param expected [.exception] The class of the expected exception.
10
- def initialize(expected)
11
- @expected = expected
12
- end
13
-
14
- # Boolean comparison between the actual value and the expected value.
15
- #
16
- # @example Is it raising NameError?
17
- # raise_exception = Matchi::RaiseException.new(NameError)
18
- # raise_exception.matches? { Boom } # => true
19
- #
20
- # @yieldreturn [#object_id] the actual value to compare to the expected one.
21
- #
22
- # @return [Boolean] Comparison between actual and expected values.
23
- def matches?
24
- yield
25
- rescue @expected
26
- true
27
- else
28
- false
29
- end
30
-
31
- # Returns a string representing the matcher.
32
- #
33
- # @example The readable definition of a FooBar matcher.
34
- # matcher = Matchi::FooBar.new(42)
35
- # matcher.to_s # => "foo_bar 42"
36
- #
37
- # @return [String] A string representing the matcher.
38
- def to_s
39
- "raise_exception #{@expected.inspect}"
40
- end
41
-
42
- # Returns a hash of one key-value pair with a key corresponding to the
43
- # matcher and a value corresponding to its initialize parameters.
44
- #
45
- # @example A FooBar matcher serialized into a hash.
46
- # matcher = Matchi::FooBar.new(42)
47
- # matcher.to_h # => { FooBar: 42 }
48
- #
49
- # @return [Hash] A hash of one key-value pair.
50
- def to_h
51
- { RaiseException: [@expected] }
52
- end
53
- end
54
- end