matchi-fix 2.1.2 → 3.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 +45 -27
- data/lib/matchi/fix.rb +97 -64
- metadata +22 -138
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: b7fb48f06e3e6e908cd3bd62f18a1813b33cfee44c10f42c7b6dc217b8be2127
|
4
|
+
data.tar.gz: f7e74dab912262624625e5edec68939aa2218604df28bf7688a19d60b4c18fef
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: f873e0eacdfe88f0607f215f45c1267d865017facd15ded5b890b72b543487b041a742d8b43128d7688207036ec9d40e3dc5c2a0e06418fc27e5f96903dbd026
|
7
|
+
data.tar.gz: 6fba06dbd66e390080c9687f8ec77816f8ad5d070d13a989676eea1aca595edd3aeb48abf2ad30fbe00ce4c611bf7d45f35005452cad305d1c173d8559b71eb8
|
data/LICENSE.md
CHANGED
data/README.md
CHANGED
@@ -2,11 +2,9 @@
|
|
2
2
|
|
3
3
|
[![Version](https://img.shields.io/github/v/tag/fixrb/matchi-fix?label=Version&logo=github)](https://github.com/fixrb/matchi-fix/releases)
|
4
4
|
[![Yard documentation](https://img.shields.io/badge/Yard-documentation-blue.svg?logo=github)](https://rubydoc.info/github/fixrb/matchi-fix/main)
|
5
|
-
[![CI](https://github.com/fixrb/matchi-fix/workflows/CI/badge.svg?branch=main)](https://github.com/fixrb/matchi-fix/actions?query=workflow%3Aci+branch%3Amain)
|
6
|
-
[![RuboCop](https://github.com/fixrb/matchi-fix/workflows/RuboCop/badge.svg?branch=main)](https://github.com/fixrb/matchi-fix/actions?query=workflow%3Arubocop+branch%3Amain)
|
7
5
|
[![License](https://img.shields.io/github/license/fixrb/matchi-fix?label=License&logo=github)](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,94 +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
|
-
|
33
|
-
@expected = if unnamed?
|
34
|
-
raise ::ArgumentError, "Pass either an argument or a block" unless block
|
35
|
-
|
36
|
-
Fix(&block)
|
37
|
-
else
|
38
|
-
raise ::ArgumentError, "Can't pass both an argument and a block" if block
|
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?
|
39
75
|
|
40
|
-
|
41
|
-
end
|
76
|
+
@expected = name.nil? ? ::Fix.spec(&block) : ::Fix[name]
|
42
77
|
end
|
43
78
|
|
44
|
-
#
|
79
|
+
# Checks if the yielded object satisfies the Fix specification.
|
45
80
|
#
|
46
|
-
#
|
47
|
-
#
|
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.
|
48
84
|
#
|
49
|
-
#
|
85
|
+
# @api public
|
50
86
|
#
|
51
|
-
#
|
52
|
-
#
|
87
|
+
# @yield [] Block that returns the object to verify
|
88
|
+
# @yieldreturn [Object] The object to check against the specification
|
53
89
|
#
|
54
|
-
# @
|
55
|
-
# require "matchi/fix"
|
90
|
+
# @return [Boolean] true if the object satisfies the specification
|
56
91
|
#
|
57
|
-
#
|
58
|
-
# it MUST be 42
|
59
|
-
# end
|
60
|
-
#
|
61
|
-
# matcher = Matchi::Fix.new(:Answer)
|
92
|
+
# @raise [ArgumentError] if no block is provided
|
62
93
|
#
|
63
|
-
#
|
64
|
-
# matcher.
|
94
|
+
# @example With anonymous specification
|
95
|
+
# matcher = Fix.new { it MUST be_zero }
|
96
|
+
# matcher.match? { 0 } # => true
|
97
|
+
# matcher.match? { 1 } # => false
|
65
98
|
#
|
66
|
-
# @
|
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
|
67
106
|
#
|
68
|
-
#
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
e.success?
|
73
|
-
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?
|
74
111
|
|
75
|
-
|
76
|
-
def inspect
|
77
|
-
"#{self.class}(#{parameter})"
|
112
|
+
@expected.match?(yield)
|
78
113
|
end
|
79
114
|
|
80
|
-
# 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:...>"
|
81
124
|
def to_s
|
82
|
-
"fix #{
|
83
|
-
end
|
84
|
-
|
85
|
-
private
|
86
|
-
|
87
|
-
def unnamed?
|
88
|
-
@name.nil?
|
89
|
-
end
|
90
|
-
|
91
|
-
def parameter
|
92
|
-
unnamed? ? "&specs" : ":#{@name}"
|
125
|
+
"fix #{@expected.inspect}"
|
93
126
|
end
|
94
127
|
end
|
95
128
|
end
|
metadata
CHANGED
@@ -1,156 +1,36 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: matchi-fix
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version:
|
4
|
+
version: 3.0.1
|
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
|
-
requirement: !ruby/object:Gem::Requirement
|
16
|
-
requirements:
|
17
|
-
- - '='
|
18
|
-
- !ruby/object:Gem::Version
|
19
|
-
version: 1.0.0.beta8
|
20
|
-
type: :runtime
|
21
|
-
prerelease: false
|
22
|
-
version_requirements: !ruby/object:Gem::Requirement
|
23
|
-
requirements:
|
24
|
-
- - '='
|
25
|
-
- !ruby/object:Gem::Version
|
26
|
-
version: 1.0.0.beta8
|
27
|
-
- !ruby/object:Gem::Dependency
|
28
|
-
name: matchi
|
29
15
|
requirement: !ruby/object:Gem::Requirement
|
30
16
|
requirements:
|
31
17
|
- - "~>"
|
32
18
|
- !ruby/object:Gem::Version
|
33
|
-
version: '
|
19
|
+
version: '0.21'
|
34
20
|
type: :runtime
|
35
21
|
prerelease: false
|
36
22
|
version_requirements: !ruby/object:Gem::Requirement
|
37
23
|
requirements:
|
38
24
|
- - "~>"
|
39
25
|
- !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 specing matcher compatible with Matchi.
|
26
|
+
version: '0.21'
|
27
|
+
description: 'A Matchi-compatible matcher that allows testing objects against Fix
|
28
|
+
specifications. Enables verification of implementation conformance to Fix test specifications
|
29
|
+
across different testing frameworks like Minitest and RSpec. Integrates seamlessly
|
30
|
+
with the Fix testing framework''s powerful specification system while maintaining
|
31
|
+
Matchi''s clean matcher interface.
|
32
|
+
|
33
|
+
'
|
154
34
|
email: contact@cyril.email
|
155
35
|
executables: []
|
156
36
|
extensions: []
|
@@ -162,8 +42,12 @@ files:
|
|
162
42
|
homepage: https://github.com/fixrb/matchi-fix
|
163
43
|
licenses:
|
164
44
|
- MIT
|
165
|
-
metadata:
|
166
|
-
|
45
|
+
metadata:
|
46
|
+
bug_tracker_uri: https://github.com/fixrb/matchi-fix/issues
|
47
|
+
documentation_uri: https://rubydoc.info/gems/matchi-fix
|
48
|
+
source_code_uri: https://github.com/fixrb/matchi-fix
|
49
|
+
rubygems_mfa_required: 'true'
|
50
|
+
post_install_message:
|
167
51
|
rdoc_options: []
|
168
52
|
require_paths:
|
169
53
|
- lib
|
@@ -171,15 +55,15 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
171
55
|
requirements:
|
172
56
|
- - ">="
|
173
57
|
- !ruby/object:Gem::Version
|
174
|
-
version:
|
58
|
+
version: 3.1.0
|
175
59
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
176
60
|
requirements:
|
177
61
|
- - ">="
|
178
62
|
- !ruby/object:Gem::Version
|
179
63
|
version: '0'
|
180
64
|
requirements: []
|
181
|
-
rubygems_version: 3.
|
182
|
-
signing_key:
|
65
|
+
rubygems_version: 3.3.27
|
66
|
+
signing_key:
|
183
67
|
specification_version: 4
|
184
|
-
summary: Fix
|
68
|
+
summary: Matcher for testing implementations against Fix specifications.
|
185
69
|
test_files: []
|