matchi 1.0.5 → 2.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/LICENSE.md +1 -1
- data/README.md +50 -97
- data/lib/matchi.rb +1 -1
- data/lib/matchi/helper.rb +28 -0
- data/lib/matchi/matcher.rb +11 -0
- data/lib/matchi/matcher/base.rb +45 -0
- data/lib/matchi/matcher/be_false.rb +24 -0
- data/lib/matchi/matcher/be_nil.rb +24 -0
- data/lib/matchi/matcher/be_true.rb +24 -0
- data/lib/matchi/matcher/eql.rb +35 -0
- data/lib/matchi/matcher/equal.rb +35 -0
- data/lib/matchi/matcher/match.rb +35 -0
- data/lib/matchi/matcher/raise_exception.rb +39 -0
- metadata +61 -63
- data/.gitignore +0 -10
- data/.rubocop.yml +0 -1
- data/.rubocop_todo.yml +0 -7
- data/.travis.yml +0 -28
- data/.yardopts +0 -1
- data/CODE_OF_CONDUCT.md +0 -13
- data/Gemfile +0 -5
- data/Rakefile +0 -22
- data/VERSION.semver +0 -1
- data/bin/console +0 -8
- data/bin/setup +0 -6
- data/checksum/matchi-0.0.1.gem.sha512 +0 -1
- data/checksum/matchi-0.0.2.gem.sha512 +0 -1
- data/checksum/matchi-0.0.3.gem.sha512 +0 -1
- data/checksum/matchi-0.0.4.gem.sha512 +0 -1
- data/checksum/matchi-0.0.5.gem.sha512 +0 -1
- data/checksum/matchi-0.0.6.gem.sha512 +0 -1
- data/checksum/matchi-0.0.7.gem.sha512 +0 -1
- data/checksum/matchi-0.0.8.gem.sha512 +0 -1
- data/checksum/matchi-0.0.9.gem.sha512 +0 -1
- data/checksum/matchi-0.1.0.gem.sha512 +0 -1
- data/checksum/matchi-0.1.1.gem.sha512 +0 -1
- data/checksum/matchi-0.1.2.gem.sha512 +0 -1
- data/checksum/matchi-1.0.0.gem.sha512 +0 -1
- data/checksum/matchi-1.0.1.gem.sha512 +0 -1
- data/checksum/matchi-1.0.2.gem.sha512 +0 -1
- data/checksum/matchi-1.0.3.gem.sha512 +0 -1
- data/checksum/matchi-1.0.4.gem.sha512 +0 -1
- data/lib/matchi/matchers.rb +0 -11
- data/lib/matchi/matchers/be_false.rb +0 -30
- data/lib/matchi/matchers/be_nil.rb +0 -30
- data/lib/matchi/matchers/be_true.rb +0 -30
- data/lib/matchi/matchers/eql.rb +0 -40
- data/lib/matchi/matchers/equal.rb +0 -40
- data/lib/matchi/matchers/match.rb +0 -40
- data/lib/matchi/matchers/raise_exception.rb +0 -44
- data/lib/matchi/matchers_base.rb +0 -51
- data/matchi.gemspec +0 -24
- data/pkg_checksum +0 -12
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: a9afc0e3e02c4150637f3d1080cf6eacd470ad7dec335417bda0e79ee60ecdea
|
4
|
+
data.tar.gz: d62e283556fc4f9d4a6d93bde1efb518861d482dba734786f00b57a166f4ade6
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 50d45962387971730773221e8756fa543457ebd1375f7205538040d2fb115eb1fae0784c1e9949794e9c990efc7788fda49ce03f8096918005eae384ed460a13
|
7
|
+
data.tar.gz: 12071d2d5462243d42eac25ca3d70fc5a236cd79b8cbdd20a608e4d2ceeacdbdddbaeeba06f30218c30d1cbf0c6f16279be655eead7a42dcf6b9cecdf1c645cf
|
data/LICENSE.md
CHANGED
data/README.md
CHANGED
@@ -1,30 +1,19 @@
|
|
1
1
|
# Matchi
|
2
2
|
|
3
|
-
[![Build Status](https://api.travis-ci.org/fixrb/matchi.svg?branch=
|
3
|
+
[![Build Status](https://api.travis-ci.org/fixrb/matchi.svg?branch=main)][travis]
|
4
4
|
[![Code Climate](https://codeclimate.com/github/fixrb/matchi/badges/gpa.svg)][codeclimate]
|
5
5
|
[![Gem Version](https://badge.fury.io/rb/matchi.svg)][gem]
|
6
|
-
[![Inline docs](https://inch-ci.org/github/fixrb/matchi.svg?branch=
|
6
|
+
[![Inline docs](https://inch-ci.org/github/fixrb/matchi.svg?branch=main)][inchpages]
|
7
7
|
[![Documentation](https://img.shields.io/:yard-docs-38c800.svg)][rubydoc]
|
8
8
|
|
9
9
|
> Collection of expectation matchers for Ruby.
|
10
10
|
|
11
|
-
## Contact
|
12
|
-
|
13
|
-
* Home page: https://github.com/fixrb/matchi
|
14
|
-
* Bugs/issues: https://github.com/fixrb/matchi/issues
|
15
|
-
|
16
|
-
## Rubies
|
17
|
-
|
18
|
-
* [MRI](https://www.ruby-lang.org/)
|
19
|
-
* [Rubinius](https://rubinius.com/)
|
20
|
-
* [JRuby](https://www.jruby.org/)
|
21
|
-
|
22
11
|
## Installation
|
23
12
|
|
24
13
|
Add this line to your application's Gemfile:
|
25
14
|
|
26
15
|
```ruby
|
27
|
-
gem
|
16
|
+
gem "matchi"
|
28
17
|
```
|
29
18
|
|
30
19
|
And then execute:
|
@@ -42,49 +31,49 @@ Or install it yourself as:
|
|
42
31
|
**Equivalence** matcher:
|
43
32
|
|
44
33
|
```ruby
|
45
|
-
eql = Matchi::
|
46
|
-
eql.matches? {
|
34
|
+
eql = Matchi::Matcher::Eql.new("foo")
|
35
|
+
eql.matches? { "foo" } # => true
|
47
36
|
```
|
48
37
|
|
49
38
|
**Identity** matcher:
|
50
39
|
|
51
40
|
```ruby
|
52
|
-
equal = Matchi::
|
41
|
+
equal = Matchi::Matcher::Equal.new(:foo)
|
53
42
|
equal.matches? { :foo } # => true
|
54
43
|
```
|
55
44
|
|
56
45
|
**Regular expressions** matcher:
|
57
46
|
|
58
47
|
```ruby
|
59
|
-
match = Matchi::
|
60
|
-
match.matches? {
|
48
|
+
match = Matchi::Matcher::Match.new(/^foo$/)
|
49
|
+
match.matches? { "foo" } # => true
|
61
50
|
```
|
62
51
|
|
63
52
|
**Expecting errors** matcher:
|
64
53
|
|
65
54
|
```ruby
|
66
|
-
raise_exception = Matchi::
|
55
|
+
raise_exception = Matchi::Matcher::RaiseException.new(NameError)
|
67
56
|
raise_exception.matches? { Boom } # => true
|
68
57
|
```
|
69
58
|
|
70
59
|
**Truth** matcher:
|
71
60
|
|
72
61
|
```ruby
|
73
|
-
be_true = Matchi::
|
62
|
+
be_true = Matchi::Matcher::BeTrue.new
|
74
63
|
be_true.matches? { true } # => true
|
75
64
|
```
|
76
65
|
|
77
66
|
**Untruth** matcher:
|
78
67
|
|
79
68
|
```ruby
|
80
|
-
be_false = Matchi::
|
69
|
+
be_false = Matchi::Matcher::BeFalse.new
|
81
70
|
be_false.matches? { false } # => true
|
82
71
|
```
|
83
72
|
|
84
73
|
**Nil** matcher:
|
85
74
|
|
86
75
|
```ruby
|
87
|
-
be_nil = Matchi::
|
76
|
+
be_nil = Matchi::Matcher::BeNil.new
|
88
77
|
be_nil.matches? { nil } # => true
|
89
78
|
```
|
90
79
|
|
@@ -96,55 +85,35 @@ A **Be the answer** matcher:
|
|
96
85
|
|
97
86
|
```ruby
|
98
87
|
module Matchi
|
99
|
-
module
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
42.equal? yield
|
104
|
-
end
|
105
|
-
|
106
|
-
def to_s
|
107
|
-
'be_the_answer'
|
108
|
-
end
|
109
|
-
|
110
|
-
def to_h
|
111
|
-
{ BeTheAnswer: [] }
|
112
|
-
end
|
88
|
+
module Matcher
|
89
|
+
class BeTheAnswer < ::Matchi::Matcher::Base
|
90
|
+
def matches?
|
91
|
+
42.equal? yield
|
113
92
|
end
|
114
93
|
end
|
115
94
|
end
|
116
95
|
end
|
117
96
|
|
118
|
-
be_the_answer = Matchi::
|
97
|
+
be_the_answer = Matchi::Matcher::BeTheAnswer.new
|
119
98
|
be_the_answer.matches? { 42 } # => true
|
120
99
|
```
|
121
100
|
|
122
101
|
A **Be prime** matcher:
|
123
102
|
|
124
103
|
```ruby
|
125
|
-
require
|
104
|
+
require "prime"
|
126
105
|
|
127
106
|
module Matchi
|
128
|
-
module
|
129
|
-
|
130
|
-
|
131
|
-
|
132
|
-
Prime.prime? yield
|
133
|
-
end
|
134
|
-
|
135
|
-
def to_s
|
136
|
-
'be_prime'
|
137
|
-
end
|
138
|
-
|
139
|
-
def to_h
|
140
|
-
{ BePrime: [] }
|
141
|
-
end
|
107
|
+
module Matcher
|
108
|
+
class BePrime < ::Matchi::Matcher::Base
|
109
|
+
def matches?
|
110
|
+
Prime.prime? yield
|
142
111
|
end
|
143
112
|
end
|
144
113
|
end
|
145
114
|
end
|
146
115
|
|
147
|
-
be_prime = Matchi::
|
116
|
+
be_prime = Matchi::Matcher::BePrime.new
|
148
117
|
be_prime.matches? { 42 } # => false
|
149
118
|
```
|
150
119
|
|
@@ -152,70 +121,54 @@ A **Start with** matcher:
|
|
152
121
|
|
153
122
|
```ruby
|
154
123
|
module Matchi
|
155
|
-
module
|
156
|
-
|
157
|
-
|
158
|
-
|
159
|
-
|
160
|
-
|
161
|
-
|
162
|
-
|
163
|
-
|
164
|
-
end
|
165
|
-
|
166
|
-
def to_s
|
167
|
-
'start_with'
|
168
|
-
end
|
169
|
-
|
170
|
-
def to_h
|
171
|
-
{ StartWith: [@expected] }
|
172
|
-
end
|
124
|
+
module Matcher
|
125
|
+
class StartWith < ::Matchi::Matcher::Base
|
126
|
+
def initialize(expected)
|
127
|
+
super()
|
128
|
+
@expected = expected
|
129
|
+
end
|
130
|
+
|
131
|
+
def matches?
|
132
|
+
!Regexp.new("^#{expected}").match(yield).nil?
|
173
133
|
end
|
174
134
|
end
|
175
135
|
end
|
176
136
|
end
|
177
137
|
|
178
|
-
start_with = Matchi::
|
179
|
-
start_with.matches? {
|
138
|
+
start_with = Matchi::Matcher::StartWith.new("foo")
|
139
|
+
start_with.matches? { "foobar" } # => true
|
180
140
|
```
|
181
141
|
|
182
|
-
##
|
142
|
+
## Contact
|
183
143
|
|
184
|
-
|
185
|
-
|
186
|
-
Although these checksums do not prevent malicious users from tampering with a
|
187
|
-
built Gem they can be used for basic integrity verification purposes.
|
144
|
+
* Home page: https://github.com/fixrb/matchi
|
145
|
+
* Bugs/issues: https://github.com/fixrb/matchi/issues
|
188
146
|
|
189
|
-
|
190
|
-
example:
|
147
|
+
## Rubies
|
191
148
|
|
192
|
-
|
193
|
-
|
149
|
+
* [MRI](https://www.ruby-lang.org/)
|
150
|
+
* [Rubinius](https://rubinius.com/)
|
151
|
+
* [JRuby](https://www.jruby.org/)
|
194
152
|
|
195
153
|
## Versioning
|
196
154
|
|
197
155
|
__Matchi__ follows [Semantic Versioning 2.0](https://semver.org/).
|
198
156
|
|
199
|
-
##
|
157
|
+
## License
|
200
158
|
|
201
|
-
|
202
|
-
2. Create your feature branch (`git checkout -b my-new-feature`)
|
203
|
-
3. Commit your changes (`git commit -am 'Add some feature'`)
|
204
|
-
4. Push to the branch (`git push origin my-new-feature`)
|
205
|
-
5. Create a new Pull Request
|
159
|
+
The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
|
206
160
|
|
207
|
-
|
161
|
+
***
|
208
162
|
|
209
|
-
|
163
|
+
<p>
|
164
|
+
This project is sponsored by:<br />
|
165
|
+
<a href="https://sashite.com/"><img
|
166
|
+
src="https://github.com/fixrb/matchi/raw/main/img/sashite.png"
|
167
|
+
alt="Sashite" /></a>
|
168
|
+
</p>
|
210
169
|
|
211
170
|
[gem]: https://rubygems.org/gems/matchi
|
212
171
|
[travis]: https://travis-ci.org/fixrb/matchi
|
213
172
|
[codeclimate]: https://codeclimate.com/github/fixrb/matchi
|
214
173
|
[inchpages]: https://inch-ci.org/github/fixrb/matchi
|
215
174
|
[rubydoc]: https://rubydoc.info/gems/matchi/frames
|
216
|
-
|
217
|
-
***
|
218
|
-
|
219
|
-
This project is sponsored by:
|
220
|
-
|
221
|
-
[![Sashite](https://pbs.twimg.com/profile_images/618485028322975744/PZ9qPuI__400x400.png)](https://sashite.com/)
|
data/lib/matchi.rb
CHANGED
@@ -0,0 +1,28 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require_relative "matcher"
|
4
|
+
|
5
|
+
module Matchi
|
6
|
+
# Collection of helper methods.
|
7
|
+
module Helper
|
8
|
+
::Matchi::Matcher.constants.each do |matcher_const|
|
9
|
+
next if matcher_const.equal?(:Base)
|
10
|
+
|
11
|
+
matcher_klass = ::Matchi::Matcher.const_get(matcher_const)
|
12
|
+
|
13
|
+
# Define a method for the given matcher.
|
14
|
+
#
|
15
|
+
# @example Given the `Matchi::Matchers::Equal::Matcher` matcher, its
|
16
|
+
# method would be:
|
17
|
+
#
|
18
|
+
# def equal(expected)
|
19
|
+
# Matchi::Matchers::Equal::Matcher.new(expected)
|
20
|
+
# end
|
21
|
+
#
|
22
|
+
# @return [#matches?] The matcher.
|
23
|
+
define_method(matcher_klass.to_sym) do |*args|
|
24
|
+
matcher_klass.new(*args)
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
@@ -0,0 +1,45 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Matchi
|
4
|
+
module Matcher
|
5
|
+
# Abstract matcher class.
|
6
|
+
class Base
|
7
|
+
# @return [Symbol] A symbol identifying the matcher.
|
8
|
+
def self.to_sym
|
9
|
+
name.delete_prefix("Matchi::Matcher::")
|
10
|
+
.gsub(/([A-Z]+)([A-Z][a-z])/, '\1_\2')
|
11
|
+
.gsub(/([a-z\d])([A-Z])/, '\1_\2')
|
12
|
+
.downcase
|
13
|
+
.to_sym
|
14
|
+
end
|
15
|
+
|
16
|
+
# @return [#object_id] Any value to give to the matcher.
|
17
|
+
attr_reader :expected
|
18
|
+
|
19
|
+
# A string containing a human-readable representation of the matcher.
|
20
|
+
#
|
21
|
+
# @return [String] The human-readable representation of the matcher.
|
22
|
+
def inspect
|
23
|
+
"#{self.class}(#{expected&.inspect})"
|
24
|
+
end
|
25
|
+
|
26
|
+
# Abstract matcher class.
|
27
|
+
#
|
28
|
+
# @raise [NotImplementedError] Override me inside a matcher.
|
29
|
+
def matches?
|
30
|
+
raise ::NotImplementedError, "matcher MUST respond to this method."
|
31
|
+
end
|
32
|
+
|
33
|
+
# Returns a string representing the matcher.
|
34
|
+
#
|
35
|
+
# @example The readable definition of a FooBar matcher.
|
36
|
+
# matcher = Matchi::Matcher::FooBar.new(42)
|
37
|
+
# matcher.to_s # => "foo_bar 42"
|
38
|
+
#
|
39
|
+
# @return [String] A string representing the matcher.
|
40
|
+
def to_s
|
41
|
+
[self.class.to_sym, expected&.inspect].compact.join(" ")
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end
|
45
|
+
end
|
@@ -0,0 +1,24 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require_relative "base"
|
4
|
+
|
5
|
+
module Matchi
|
6
|
+
module Matcher
|
7
|
+
# **Untruth** matcher.
|
8
|
+
class BeFalse < ::Matchi::Matcher::Base
|
9
|
+
# Boolean comparison between the actual value and the expected value.
|
10
|
+
#
|
11
|
+
# @example Is it false?
|
12
|
+
# be_false = Matchi::Matcher::BeFalse.new
|
13
|
+
# be_false.matches? { false } # => true
|
14
|
+
#
|
15
|
+
# @yieldreturn [#object_id] The actual value to compare to the expected
|
16
|
+
# one.
|
17
|
+
#
|
18
|
+
# @return [Boolean] Comparison between actual and expected values.
|
19
|
+
def matches?(*, **)
|
20
|
+
false.equal?(yield)
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
@@ -0,0 +1,24 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require_relative "base"
|
4
|
+
|
5
|
+
module Matchi
|
6
|
+
module Matcher
|
7
|
+
# **Nil** matcher.
|
8
|
+
class BeNil < ::Matchi::Matcher::Base
|
9
|
+
# Boolean comparison between the actual value and the expected value.
|
10
|
+
#
|
11
|
+
# @example Is it nil?
|
12
|
+
# be_nil = Matchi::Matcher::BeNil.new
|
13
|
+
# be_nil.matches? { nil } # => true
|
14
|
+
#
|
15
|
+
# @yieldreturn [#object_id] The actual value to compare to the expected
|
16
|
+
# one.
|
17
|
+
#
|
18
|
+
# @return [Boolean] Comparison between actual and expected values.
|
19
|
+
def matches?(*, **)
|
20
|
+
nil.equal?(yield)
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
@@ -0,0 +1,24 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require_relative "base"
|
4
|
+
|
5
|
+
module Matchi
|
6
|
+
module Matcher
|
7
|
+
# **Truth** matcher.
|
8
|
+
class BeTrue < ::Matchi::Matcher::Base
|
9
|
+
# Boolean comparison between the actual value and the expected value.
|
10
|
+
#
|
11
|
+
# @example Is it true?
|
12
|
+
# be_true = Matchi::Matcher::BeTrue.new
|
13
|
+
# be_true.matches? { true } # => true
|
14
|
+
#
|
15
|
+
# @yieldreturn [#object_id] The actual value to compare to the expected
|
16
|
+
# one.
|
17
|
+
#
|
18
|
+
# @return [Boolean] Comparison between actual and expected values.
|
19
|
+
def matches?(*, **)
|
20
|
+
true.equal?(yield)
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|