matchi-fix 2.1.1 → 3.0.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/LICENSE.md +1 -1
- data/README.md +45 -27
- data/lib/matchi/fix.rb +97 -59
- metadata +26 -128
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 3b42bc77b68d62f4c3bed7bf25c7a78dbc48968db05bcdfb234f96ec0e903310
|
4
|
+
data.tar.gz: f508566e09920d7a88aabc3588350a4679eac62f4e605c35c00db29334fa63bb
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: b019c450b570dd51b99e0202b3d44a26943f743e0c676fc044a7125cfbc68a1c43b23d540971dec16456d2acf05b0685c9c0e1186f8a455a5e31fa05e34647e4
|
7
|
+
data.tar.gz: 7b0dcaaa92f49aff5eba4604b112b57c18fe038098d477dbac459b4065c1a400f758f18d2e5078d70aef2d464558ec80a7d0f18c926533e6d9b82f6fef15744b
|
data/LICENSE.md
CHANGED
data/README.md
CHANGED
@@ -2,11 +2,9 @@
|
|
2
2
|
|
3
3
|
[](https://github.com/fixrb/matchi-fix/releases)
|
4
4
|
[](https://rubydoc.info/github/fixrb/matchi-fix/main)
|
5
|
-
[](https://github.com/fixrb/matchi-fix/actions?query=workflow%3Aci+branch%3Amain)
|
6
|
-
[](https://github.com/fixrb/matchi-fix/actions?query=workflow%3Arubocop+branch%3Amain)
|
7
5
|
[](https://github.com/fixrb/matchi-fix/raw/main/LICENSE.md)
|
8
6
|
|
9
|
-
|
7
|
+
[Matchi](https://github.com/fixrb/matchi)-compatible matcher for testing implementations against [Fix](https://github.com/fixrb/fix) specifications.
|
10
8
|
|
11
9
|
## Installation
|
12
10
|
|
@@ -18,16 +16,24 @@ gem "matchi-fix"
|
|
18
16
|
|
19
17
|
And then execute:
|
20
18
|
|
21
|
-
```
|
22
|
-
bundle
|
19
|
+
```shell
|
20
|
+
bundle install
|
23
21
|
```
|
24
22
|
|
25
|
-
Or install it yourself
|
23
|
+
Or install it yourself:
|
26
24
|
|
27
|
-
```
|
25
|
+
```shell
|
28
26
|
gem install matchi-fix
|
29
27
|
```
|
30
28
|
|
29
|
+
## Description
|
30
|
+
|
31
|
+
A Matchi-compatible matcher that allows testing objects against Fix specifications.
|
32
|
+
Enables verification of implementation conformance to Fix test specifications
|
33
|
+
across different testing frameworks like Minitest and RSpec. Integrates seamlessly
|
34
|
+
with the Fix testing framework's powerful specification system while maintaining
|
35
|
+
Matchi's clean matcher interface.
|
36
|
+
|
31
37
|
## Usage
|
32
38
|
|
33
39
|
To make __Matchi::Fix__ available:
|
@@ -36,30 +42,47 @@ To make __Matchi::Fix__ available:
|
|
36
42
|
require "matchi/fix"
|
37
43
|
```
|
38
44
|
|
39
|
-
|
45
|
+
The Fix matcher allows testing values against Fix specifications. After requiring `matchi-fix`, you can use the `Fix` matcher in your tests through anonymous specification:
|
46
|
+
|
47
|
+
```ruby
|
48
|
+
Matchi::Fix.new { it MUST be 42 }.match? { 42 } # => true
|
49
|
+
```
|
40
50
|
|
41
|
-
|
51
|
+
or through registered specification by name:
|
42
52
|
|
43
53
|
```ruby
|
44
|
-
|
54
|
+
# First, define a Fix specification
|
55
|
+
Fix :Calculator do
|
56
|
+
on(:add, 2, 3) do
|
57
|
+
it MUST eq 5
|
58
|
+
end
|
59
|
+
|
60
|
+
on(:multiply, 2, 3) do
|
61
|
+
it MUST eq 6
|
62
|
+
end
|
63
|
+
end
|
64
|
+
|
65
|
+
# Then use the matcher to test implementations
|
66
|
+
calculator = MyCalculator.new
|
45
67
|
|
46
|
-
|
47
|
-
|
68
|
+
# Using direct matcher syntax
|
69
|
+
Matchi::Fix.new(:Calculator).matches?(calculator) #=> true/false
|
48
70
|
```
|
49
71
|
|
50
|
-
###
|
72
|
+
### Error Handling
|
51
73
|
|
52
|
-
|
74
|
+
On missing specifications:
|
53
75
|
|
54
76
|
```ruby
|
55
|
-
Fix
|
56
|
-
|
57
|
-
|
77
|
+
Matchi::Fix.new(:NonExistent)
|
78
|
+
# => KeyError
|
79
|
+
```
|
58
80
|
|
59
|
-
|
81
|
+
On passing both specification name and specification code:
|
60
82
|
|
61
|
-
|
62
|
-
|
83
|
+
```ruby
|
84
|
+
Matchi::Fix.new(:SpecName) { "Spec block" }
|
85
|
+
# => ArgumentError
|
63
86
|
```
|
64
87
|
|
65
88
|
## Contact
|
@@ -74,11 +97,6 @@ __Matchi::Fix__ follows [Semantic Versioning 2.0](https://semver.org/).
|
|
74
97
|
|
75
98
|
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).
|
76
99
|
|
77
|
-
|
100
|
+
## Sponsors
|
78
101
|
|
79
|
-
|
80
|
-
This project is sponsored by:<br />
|
81
|
-
<a href="https://sashite.com/"><img
|
82
|
-
src="https://github.com/fixrb/matchi-fix/raw/main/img/sashite.png"
|
83
|
-
alt="Sashite" /></a>
|
84
|
-
</p>
|
102
|
+
This project is sponsored by [Sashité](https://sashite.com/)
|
data/lib/matchi/fix.rb
CHANGED
@@ -2,89 +2,127 @@
|
|
2
2
|
|
3
3
|
require "fix"
|
4
4
|
|
5
|
-
# Namespace for the Matchi library.
|
6
5
|
module Matchi
|
7
|
-
#
|
6
|
+
# Specification conformance matcher that verifies objects against Fix test specifications.
|
7
|
+
#
|
8
|
+
# This matcher allows testing objects against Fix specifications, enabling verification
|
9
|
+
# of implementation conformance across different testing frameworks. It supports both
|
10
|
+
# anonymous specifications defined inline and named specifications registered with Fix.
|
11
|
+
# The matcher provides a bridge between Matchi's matcher interface and Fix's powerful
|
12
|
+
# specification system.
|
13
|
+
#
|
14
|
+
# @example Basic usage with anonymous specification
|
15
|
+
# matcher = Matchi::Fix.new { it MUST be 42 }
|
16
|
+
# matcher.match? { 42 } # => true
|
17
|
+
# matcher.match? { 41 } # => false
|
18
|
+
#
|
19
|
+
# @example Using named specifications
|
20
|
+
# # Define a Fix specification
|
21
|
+
# Fix :Calculator do
|
22
|
+
# on(:add, 2, 3) do
|
23
|
+
# it MUST eq 5
|
24
|
+
# end
|
25
|
+
#
|
26
|
+
# on(:multiply, 2, 3) do
|
27
|
+
# it MUST eq 6
|
28
|
+
# end
|
29
|
+
# end
|
30
|
+
#
|
31
|
+
# # Test implementations
|
32
|
+
# calculator = Calculator.new
|
33
|
+
# matcher = Matchi::Fix.new(:Calculator)
|
34
|
+
# matcher.match? { calculator } # => true if calculator meets spec
|
35
|
+
#
|
36
|
+
# @example Complex specifications
|
37
|
+
# Fix :UserValidator do
|
38
|
+
# on(:validate, name: "Alice", age: 30) do
|
39
|
+
# it MUST be true
|
40
|
+
# end
|
41
|
+
#
|
42
|
+
# on(:validate, name: "", age: -1) do
|
43
|
+
# it MUST be false
|
44
|
+
# end
|
45
|
+
# end
|
46
|
+
#
|
47
|
+
# validator = UserValidator.new
|
48
|
+
# matcher = Matchi::Fix.new(:UserValidator)
|
49
|
+
# matcher.match? { validator } # => true if validation logic is correct
|
50
|
+
#
|
51
|
+
# @see https://github.com/fixrb/fix
|
52
|
+
# @see https://github.com/fixrb/matchi
|
8
53
|
class Fix
|
9
|
-
#
|
10
|
-
attr_reader :expected
|
11
|
-
|
12
|
-
# Initialize the matcher with a behavioral definition.
|
54
|
+
# Initialize the matcher with either a name or a specification block.
|
13
55
|
#
|
14
|
-
# @
|
15
|
-
# require "matchi/fix"
|
56
|
+
# @api public
|
16
57
|
#
|
17
|
-
#
|
58
|
+
# @param name [Symbol, nil] The name of a registered Fix specification
|
59
|
+
# @param block [Proc, nil] A block containing the specification
|
18
60
|
#
|
19
|
-
# @
|
20
|
-
#
|
61
|
+
# @raise [ArgumentError] if neither name nor block is provided
|
62
|
+
# @raise [ArgumentError] if both name and block are provided
|
63
|
+
# @raise [KeyError] if the named specification doesn't exist
|
21
64
|
#
|
22
|
-
#
|
23
|
-
# it MUST be 42
|
24
|
-
# end
|
65
|
+
# @return [Fix] a new instance of the matcher
|
25
66
|
#
|
26
|
-
#
|
67
|
+
# @example With anonymous specification
|
68
|
+
# Fix.new { it MUST be_positive }
|
27
69
|
#
|
28
|
-
# @
|
29
|
-
#
|
70
|
+
# @example With named specification
|
71
|
+
# Fix.new(:Calculator)
|
30
72
|
def initialize(name = nil, &block)
|
31
|
-
|
32
|
-
|
73
|
+
raise ::ArgumentError, "a name or a block must be provided" if name.nil? && block.nil?
|
74
|
+
raise ::ArgumentError, "a name or a block must be provided" if !name.nil? && !block.nil?
|
33
75
|
|
34
|
-
|
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
|
76
|
+
@expected = name.nil? ? ::Fix.spec(&block) : ::Fix[name]
|
41
77
|
end
|
42
78
|
|
43
|
-
#
|
79
|
+
# Checks if the yielded object satisfies the Fix specification.
|
44
80
|
#
|
45
|
-
#
|
46
|
-
#
|
81
|
+
# This method executes the Fix specification against the provided object,
|
82
|
+
# verifying that all specified behaviors and conditions are met. It works
|
83
|
+
# with both anonymous and named specifications.
|
47
84
|
#
|
48
|
-
#
|
85
|
+
# @api public
|
49
86
|
#
|
50
|
-
#
|
51
|
-
#
|
87
|
+
# @yield [] Block that returns the object to verify
|
88
|
+
# @yieldreturn [Object] The object to check against the specification
|
52
89
|
#
|
53
|
-
# @
|
54
|
-
# require "matchi/fix"
|
90
|
+
# @return [Boolean] true if the object satisfies the specification
|
55
91
|
#
|
56
|
-
#
|
57
|
-
# it MUST be 42
|
58
|
-
# end
|
92
|
+
# @raise [ArgumentError] if no block is provided
|
59
93
|
#
|
60
|
-
#
|
94
|
+
# @example With anonymous specification
|
95
|
+
# matcher = Fix.new { it MUST be_zero }
|
96
|
+
# matcher.match? { 0 } # => true
|
97
|
+
# matcher.match? { 1 } # => false
|
61
98
|
#
|
62
|
-
#
|
63
|
-
#
|
64
|
-
#
|
65
|
-
#
|
99
|
+
# @example With named specification
|
100
|
+
# Fix :Sortable do
|
101
|
+
# on(:sort) do
|
102
|
+
# it MUST be_kind_of(Array)
|
103
|
+
# it MUST be_sorted
|
104
|
+
# end
|
105
|
+
# end
|
66
106
|
#
|
67
|
-
#
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
e.success?
|
72
|
-
end
|
107
|
+
# matcher = Fix.new(:Sortable)
|
108
|
+
# matcher.match? { [1, 2, 3] } # => true if array meets spec
|
109
|
+
def match?
|
110
|
+
raise ::ArgumentError, "a block must be provided" unless block_given?
|
73
111
|
|
74
|
-
|
75
|
-
def inspect
|
76
|
-
"#{self.class}(#{parameter})"
|
112
|
+
@expected.match?(yield)
|
77
113
|
end
|
78
114
|
|
79
|
-
# Returns a
|
115
|
+
# Returns a human-readable description of the matcher.
|
116
|
+
#
|
117
|
+
# @api public
|
118
|
+
#
|
119
|
+
# @return [String] A string describing what this matcher verifies
|
120
|
+
#
|
121
|
+
# @example
|
122
|
+
# Fix.new(:Calculator).to_s # => "fix Calculator"
|
123
|
+
# Fix.new { it MUST be 42 }.to_s # => "fix #<Fix::Spec:...>"
|
80
124
|
def to_s
|
81
|
-
"fix #{
|
82
|
-
end
|
83
|
-
|
84
|
-
private
|
85
|
-
|
86
|
-
def parameter
|
87
|
-
@name.nil? ? "&specs" : ":#{@name}"
|
125
|
+
"fix #{@expected.inspect}"
|
88
126
|
end
|
89
127
|
end
|
90
128
|
end
|
metadata
CHANGED
@@ -1,156 +1,50 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: matchi-fix
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version:
|
4
|
+
version: 3.0.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Cyril Kato
|
8
|
-
autorequire:
|
8
|
+
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2025-01-05 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: fix
|
15
15
|
requirement: !ruby/object:Gem::Requirement
|
16
16
|
requirements:
|
17
|
-
- -
|
17
|
+
- - "~>"
|
18
18
|
- !ruby/object:Gem::Version
|
19
|
-
version:
|
19
|
+
version: '0.21'
|
20
20
|
type: :runtime
|
21
21
|
prerelease: false
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
23
23
|
requirements:
|
24
|
-
- -
|
24
|
+
- - "~>"
|
25
25
|
- !ruby/object:Gem::Version
|
26
|
-
version:
|
26
|
+
version: '0.21'
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
28
|
name: matchi
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
30
30
|
requirements:
|
31
31
|
- - "~>"
|
32
32
|
- !ruby/object:Gem::Version
|
33
|
-
version: '
|
33
|
+
version: '4.1'
|
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: '
|
41
|
-
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
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: rake
|
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: rubocop-md
|
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
|
-
- !ruby/object:Gem::Dependency
|
84
|
-
name: rubocop-performance
|
85
|
-
requirement: !ruby/object:Gem::Requirement
|
86
|
-
requirements:
|
87
|
-
- - ">="
|
88
|
-
- !ruby/object:Gem::Version
|
89
|
-
version: '0'
|
90
|
-
type: :development
|
91
|
-
prerelease: false
|
92
|
-
version_requirements: !ruby/object:Gem::Requirement
|
93
|
-
requirements:
|
94
|
-
- - ">="
|
95
|
-
- !ruby/object:Gem::Version
|
96
|
-
version: '0'
|
97
|
-
- !ruby/object:Gem::Dependency
|
98
|
-
name: rubocop-rake
|
99
|
-
requirement: !ruby/object:Gem::Requirement
|
100
|
-
requirements:
|
101
|
-
- - ">="
|
102
|
-
- !ruby/object:Gem::Version
|
103
|
-
version: '0'
|
104
|
-
type: :development
|
105
|
-
prerelease: false
|
106
|
-
version_requirements: !ruby/object:Gem::Requirement
|
107
|
-
requirements:
|
108
|
-
- - ">="
|
109
|
-
- !ruby/object:Gem::Version
|
110
|
-
version: '0'
|
111
|
-
- !ruby/object:Gem::Dependency
|
112
|
-
name: rubocop-thread_safety
|
113
|
-
requirement: !ruby/object:Gem::Requirement
|
114
|
-
requirements:
|
115
|
-
- - ">="
|
116
|
-
- !ruby/object:Gem::Version
|
117
|
-
version: '0'
|
118
|
-
type: :development
|
119
|
-
prerelease: false
|
120
|
-
version_requirements: !ruby/object:Gem::Requirement
|
121
|
-
requirements:
|
122
|
-
- - ">="
|
123
|
-
- !ruby/object:Gem::Version
|
124
|
-
version: '0'
|
125
|
-
- !ruby/object:Gem::Dependency
|
126
|
-
name: simplecov
|
127
|
-
requirement: !ruby/object:Gem::Requirement
|
128
|
-
requirements:
|
129
|
-
- - ">="
|
130
|
-
- !ruby/object:Gem::Version
|
131
|
-
version: '0'
|
132
|
-
type: :development
|
133
|
-
prerelease: false
|
134
|
-
version_requirements: !ruby/object:Gem::Requirement
|
135
|
-
requirements:
|
136
|
-
- - ">="
|
137
|
-
- !ruby/object:Gem::Version
|
138
|
-
version: '0'
|
139
|
-
- !ruby/object:Gem::Dependency
|
140
|
-
name: yard
|
141
|
-
requirement: !ruby/object:Gem::Requirement
|
142
|
-
requirements:
|
143
|
-
- - ">="
|
144
|
-
- !ruby/object:Gem::Version
|
145
|
-
version: '0'
|
146
|
-
type: :development
|
147
|
-
prerelease: false
|
148
|
-
version_requirements: !ruby/object:Gem::Requirement
|
149
|
-
requirements:
|
150
|
-
- - ">="
|
151
|
-
- !ruby/object:Gem::Version
|
152
|
-
version: '0'
|
153
|
-
description: A Fix specifications matcher compatible with Matchi.
|
40
|
+
version: '4.1'
|
41
|
+
description: 'A Matchi-compatible matcher that allows testing objects against Fix
|
42
|
+
specifications. Enables verification of implementation conformance to Fix test specifications
|
43
|
+
across different testing frameworks like Minitest and RSpec. Integrates seamlessly
|
44
|
+
with the Fix testing framework''s powerful specification system while maintaining
|
45
|
+
Matchi''s clean matcher interface.
|
46
|
+
|
47
|
+
'
|
154
48
|
email: contact@cyril.email
|
155
49
|
executables: []
|
156
50
|
extensions: []
|
@@ -162,8 +56,12 @@ files:
|
|
162
56
|
homepage: https://github.com/fixrb/matchi-fix
|
163
57
|
licenses:
|
164
58
|
- MIT
|
165
|
-
metadata:
|
166
|
-
|
59
|
+
metadata:
|
60
|
+
bug_tracker_uri: https://github.com/fixrb/matchi-fix/issues
|
61
|
+
documentation_uri: https://rubydoc.info/gems/matchi-fix
|
62
|
+
source_code_uri: https://github.com/fixrb/matchi-fix
|
63
|
+
rubygems_mfa_required: 'true'
|
64
|
+
post_install_message:
|
167
65
|
rdoc_options: []
|
168
66
|
require_paths:
|
169
67
|
- lib
|
@@ -171,15 +69,15 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
171
69
|
requirements:
|
172
70
|
- - ">="
|
173
71
|
- !ruby/object:Gem::Version
|
174
|
-
version:
|
72
|
+
version: 3.1.0
|
175
73
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
176
74
|
requirements:
|
177
75
|
- - ">="
|
178
76
|
- !ruby/object:Gem::Version
|
179
77
|
version: '0'
|
180
78
|
requirements: []
|
181
|
-
rubygems_version: 3.
|
182
|
-
signing_key:
|
79
|
+
rubygems_version: 3.3.27
|
80
|
+
signing_key:
|
183
81
|
specification_version: 4
|
184
|
-
summary: Fix specifications
|
82
|
+
summary: Matcher for testing implementations against Fix specifications.
|
185
83
|
test_files: []
|