matchi-fix 2.0.0 → 2.1.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 +25 -2
- data/lib/matchi/fix.rb +49 -13
- metadata +6 -6
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 8dda03096cb67cd0a3552246a0e0ae676a346e3483cbfd5fd88eaded3ed9020e
|
4
|
+
data.tar.gz: 01b9f0fa9e7dfe4b07c279209f7dfdc36085d1652bf5167b67e6c890d7ff7653
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: d96d65f1086745d2f8a71aeb007911c93b2f14b7943762c5068f31090185b54af4d1bd96c469762cff956ce13bdcfd99593e0c192e3265515be8d2d9100ceec8
|
7
|
+
data.tar.gz: cd08c56a584d6c460d621d4e29de1c9f4ddb1bbc783ef23e04cc56e41bf9cc04ca2e6b0a612933ed067ac2a5981435436057719b1bd0a81b31e31139eb6a1cb3
|
data/README.md
CHANGED
@@ -6,7 +6,7 @@
|
|
6
6
|
[](https://github.com/fixrb/matchi-fix/actions?query=workflow%3Arubocop+branch%3Amain)
|
7
7
|
[](https://github.com/fixrb/matchi-fix/raw/main/LICENSE.md)
|
8
8
|
|
9
|
-
> A [Fix](https://github.com/fixrb/fix)
|
9
|
+
> A [Fix](https://github.com/fixrb/fix) specifications matcher compatible with [Matchi](https://github.com/fixrb/matchi).
|
10
10
|
|
11
11
|
## Installation
|
12
12
|
|
@@ -30,15 +30,38 @@ gem install matchi-fix
|
|
30
30
|
|
31
31
|
## Usage
|
32
32
|
|
33
|
+
To make __Matchi::Fix__ available:
|
34
|
+
|
33
35
|
```ruby
|
34
36
|
require "matchi/fix"
|
37
|
+
```
|
38
|
+
|
39
|
+
All examples here assume that this has been done.
|
40
|
+
|
41
|
+
### With a block of specifications
|
35
42
|
|
43
|
+
```ruby
|
36
44
|
matcher = Matchi::Fix.new { it MUST be 42 }
|
37
45
|
|
38
46
|
matcher.expected # => #<Fix::Set:0x00007fd96915dc28 ...>
|
39
47
|
matcher.matches? { 42 } # => true
|
40
48
|
```
|
41
49
|
|
50
|
+
### With the constant name of the specifications
|
51
|
+
|
52
|
+
If specifications have been defined and named, they can be mentioned:
|
53
|
+
|
54
|
+
```ruby
|
55
|
+
Fix :Answer do
|
56
|
+
it MUST be 42
|
57
|
+
end
|
58
|
+
|
59
|
+
matcher = Matchi::Fix.new(:Answer)
|
60
|
+
|
61
|
+
matcher.expected # => #<Fix::Set:0x00007fd96915dc28 ...>
|
62
|
+
matcher.matches? { 42 } # => true
|
63
|
+
```
|
64
|
+
|
42
65
|
## Contact
|
43
66
|
|
44
67
|
* Source code: https://github.com/fixrb/matchi-fix
|
@@ -49,7 +72,7 @@ __Matchi::Fix__ follows [Semantic Versioning 2.0](https://semver.org/).
|
|
49
72
|
|
50
73
|
## License
|
51
74
|
|
52
|
-
The [gem](https://rubygems.org/gems/matchi-fix) is available as open source under the terms of the [MIT License](https://
|
75
|
+
The [gem](https://rubygems.org/gems/matchi-fix) is available as open source under the terms of the [MIT License](https://github.com/fixrb/matchi-fix/raw/main/LICENSE.md).
|
53
76
|
|
54
77
|
***
|
55
78
|
|
data/lib/matchi/fix.rb
CHANGED
@@ -6,24 +6,43 @@ require "fix"
|
|
6
6
|
module Matchi
|
7
7
|
# **Fix** matcher.
|
8
8
|
class Fix
|
9
|
-
# @return [
|
9
|
+
# @return [#test] A set of specifications.
|
10
10
|
attr_reader :expected
|
11
11
|
|
12
|
-
# Initialize the matcher with a
|
12
|
+
# Initialize the matcher with a behavioral definition.
|
13
13
|
#
|
14
|
-
# @example
|
14
|
+
# @example With a block of specifications
|
15
15
|
# require "matchi/fix"
|
16
16
|
#
|
17
17
|
# Matchi::Fix.new { it MUST be 42 }
|
18
18
|
#
|
19
|
-
# @
|
20
|
-
|
21
|
-
|
19
|
+
# @example With the constant name of the specifications
|
20
|
+
# require "matchi/fix"
|
21
|
+
#
|
22
|
+
# Fix :Answer do
|
23
|
+
# it MUST be 42
|
24
|
+
# end
|
25
|
+
#
|
26
|
+
# Matchi::Fix.new(:Answer)
|
27
|
+
#
|
28
|
+
# @param name [String, Symbol] The constant name of the specifications.
|
29
|
+
# @param block [Proc] A block of specifications.
|
30
|
+
def initialize(name = nil, &block)
|
31
|
+
@expected = if name.nil?
|
32
|
+
raise ::ArgumentError, "Pass either an argument or a block" unless block
|
33
|
+
|
34
|
+
Fix(&block)
|
35
|
+
else
|
36
|
+
raise ::ArgumentError, "Can't pass both an argument and a block" if block
|
37
|
+
|
38
|
+
@name = name
|
39
|
+
::Fix[name]
|
40
|
+
end
|
22
41
|
end
|
23
42
|
|
24
|
-
# Boolean comparison between
|
43
|
+
# Boolean comparison between an actual value and the expected specs.
|
25
44
|
#
|
26
|
-
# @example
|
45
|
+
# @example With a block of specifications
|
27
46
|
# require "matchi/fix"
|
28
47
|
#
|
29
48
|
# matcher = Matchi::Fix.new { it MUST be 42 }
|
@@ -31,10 +50,21 @@ module Matchi
|
|
31
50
|
# matcher.expected # => #<Fix::Set:0x00007fd96915dc28 ...>
|
32
51
|
# matcher.matches? { 42 } # => true
|
33
52
|
#
|
34
|
-
# @
|
35
|
-
#
|
53
|
+
# @example With the constant name of the specifications
|
54
|
+
# require "matchi/fix"
|
55
|
+
#
|
56
|
+
# Fix :Answer do
|
57
|
+
# it MUST be 42
|
58
|
+
# end
|
59
|
+
#
|
60
|
+
# matcher = Matchi::Fix.new(:Answer)
|
61
|
+
#
|
62
|
+
# matcher.expected # => #<Fix::Set:0x00007fd96915dc28 ...>
|
63
|
+
# matcher.matches? { 42 } # => true
|
64
|
+
#
|
65
|
+
# @yieldreturn [#object_id] The value to be compared to the specifications.
|
36
66
|
#
|
37
|
-
# @return [Boolean]
|
67
|
+
# @return [Boolean] Actual value test on specifications.
|
38
68
|
def matches?(&block)
|
39
69
|
expected.test(log_level: 0, &block)
|
40
70
|
rescue ::SystemExit => e
|
@@ -43,12 +73,18 @@ module Matchi
|
|
43
73
|
|
44
74
|
# A string containing a human-readable representation of the matcher.
|
45
75
|
def inspect
|
46
|
-
"#{self.class}(
|
76
|
+
"#{self.class}(#{parameter})"
|
47
77
|
end
|
48
78
|
|
49
79
|
# Returns a string representing the matcher.
|
50
80
|
def to_s
|
51
|
-
"fix
|
81
|
+
"fix #{parameter}"
|
82
|
+
end
|
83
|
+
|
84
|
+
private
|
85
|
+
|
86
|
+
def parameter
|
87
|
+
@name.nil? ? "&specs" : ":#{@name}"
|
52
88
|
end
|
53
89
|
end
|
54
90
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: matchi-fix
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 2.
|
4
|
+
version: 2.1.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Cyril Kato
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2021-07-
|
11
|
+
date: 2021-07-28 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: fix
|
@@ -30,14 +30,14 @@ dependencies:
|
|
30
30
|
requirements:
|
31
31
|
- - "~>"
|
32
32
|
- !ruby/object:Gem::Version
|
33
|
-
version: 3.2
|
33
|
+
version: '3.2'
|
34
34
|
type: :runtime
|
35
35
|
prerelease: false
|
36
36
|
version_requirements: !ruby/object:Gem::Requirement
|
37
37
|
requirements:
|
38
38
|
- - "~>"
|
39
39
|
- !ruby/object:Gem::Version
|
40
|
-
version: 3.2
|
40
|
+
version: '3.2'
|
41
41
|
- !ruby/object:Gem::Dependency
|
42
42
|
name: bundler
|
43
43
|
requirement: !ruby/object:Gem::Requirement
|
@@ -150,7 +150,7 @@ dependencies:
|
|
150
150
|
- - ">="
|
151
151
|
- !ruby/object:Gem::Version
|
152
152
|
version: '0'
|
153
|
-
description: A Fix
|
153
|
+
description: A Fix specifications matcher compatible with Matchi.
|
154
154
|
email: contact@cyril.email
|
155
155
|
executables: []
|
156
156
|
extensions: []
|
@@ -181,5 +181,5 @@ requirements: []
|
|
181
181
|
rubygems_version: 3.1.6
|
182
182
|
signing_key:
|
183
183
|
specification_version: 4
|
184
|
-
summary: Fix
|
184
|
+
summary: Fix specifications matcher.
|
185
185
|
test_files: []
|