matchi 2.2.1 → 2.3.0
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 +4 -4
- data/README.md +7 -0
- data/lib/matchi/matcher/satisfy.rb +45 -0
- metadata +2 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 96a52462a574281d4d485558a112fec5cef2e00f1fb90c13987407c18302887c
|
4
|
+
data.tar.gz: 00511b2878ebc9bbe2deb07f888944c9b2e2f2cebf9d8a78d1fe40e1a2b923c7
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: d368cf94df8ebbfe50b7d5ffd521653853096cd7c36c1c23093916899d0f2524ccf3f3526495cc37e043af571b0df68652c406e7effb033c8d2e92c661dd2b4a
|
7
|
+
data.tar.gz: 5646d8c021cc964041af44412aefab04cc27ebbaa51ddf381b81b43577f233be8f4621735000f1ef7b63e759d80cf51e67c8c802ace3634e2174f72ee8b4ab9f
|
data/README.md
CHANGED
@@ -102,6 +102,13 @@ be_an_instance_of = Matchi::Matcher::BeAnInstanceOf.new(:String)
|
|
102
102
|
be_an_instance_of.matches? { "foo" } # => true
|
103
103
|
```
|
104
104
|
|
105
|
+
**Satisfy** matcher:
|
106
|
+
|
107
|
+
```ruby
|
108
|
+
satisfy = Matchi::Matcher::Satisfy.new { |value| value == 42 }
|
109
|
+
satisfy.matches? { 42 } # => true
|
110
|
+
```
|
111
|
+
|
105
112
|
### Custom matchers
|
106
113
|
|
107
114
|
Custom matchers can easily be defined for expressing expectations.
|
@@ -0,0 +1,45 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require_relative "base"
|
4
|
+
|
5
|
+
module Matchi
|
6
|
+
module Matcher
|
7
|
+
# *Satisfy* matcher.
|
8
|
+
class Satisfy < ::Matchi::Matcher::Base
|
9
|
+
# Initialize the matcher with a block.
|
10
|
+
#
|
11
|
+
# @example The number 42 matcher.
|
12
|
+
# Matchi::Matcher::Satisfy.new { |value| value == 42 }
|
13
|
+
#
|
14
|
+
# @param block [Proc] A block of code.
|
15
|
+
def initialize(&block)
|
16
|
+
super()
|
17
|
+
@expected = block
|
18
|
+
end
|
19
|
+
|
20
|
+
# (see Base#inspect)
|
21
|
+
def inspect
|
22
|
+
"#{self.class}(&block)"
|
23
|
+
end
|
24
|
+
|
25
|
+
# Boolean comparison between the actual value and the expected value.
|
26
|
+
#
|
27
|
+
# @example Is it equal to 42
|
28
|
+
# equal = Matchi::Matcher::Satisfy.new { |value| value == 42 }
|
29
|
+
# equal.matches? { 42 } # => true
|
30
|
+
#
|
31
|
+
# @yieldreturn [#object_id] The actual value to compare to the expected
|
32
|
+
# one.
|
33
|
+
#
|
34
|
+
# @return [Boolean] Comparison between actual and expected values.
|
35
|
+
def matches?(*, **)
|
36
|
+
expected.call(yield)
|
37
|
+
end
|
38
|
+
|
39
|
+
# (see Base#to_s)
|
40
|
+
def to_s
|
41
|
+
"#{self.class.to_sym} &block"
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end
|
45
|
+
end
|
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: 2.
|
4
|
+
version: 2.3.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Cyril Kato
|
@@ -142,6 +142,7 @@ files:
|
|
142
142
|
- lib/matchi/matcher/equal.rb
|
143
143
|
- lib/matchi/matcher/match.rb
|
144
144
|
- lib/matchi/matcher/raise_exception.rb
|
145
|
+
- lib/matchi/matcher/satisfy.rb
|
145
146
|
homepage: https://github.com/fixrb/matchi
|
146
147
|
licenses:
|
147
148
|
- MIT
|