matchi-fix
A matcher of matchi that tests a value against a specification of Fix.
Matchi::Fix tests a value against a specification of fix, registered under a name or written in a block: match? is true when the value meets every expectation. It brings the specifications of Fix wherever a matcher of matchi goes: to spectus, and to any test framework that takes one.
- Version
- 4.0.0
- Ruby
- 3.3 or later, with
fork - Dependencies
- fix
- License
- MIT
Install
Add gem "matchi-fix" to your Gemfile, or run gem install matchi-fix, then require "matchi/fix", which requires fix.
Usage
Matchi::Fix.new(:Name) finds the specification registered by Fix :Name do … end, and raises KeyError when there is none; Matchi::Fix.new { … } builds one from the block. match? calls its block once, and the value is the subject of every expectation, each context running in a child process, as Fix does it; to_s names the specification.
require "matchi/fix"
Fix :Duck do
on :walk do
it MUST eq "Klop klop!"
end
end
class Duck
def walk = "Klop klop!"
end
matcher = Matchi::Fix.new(:Duck)
matcher.match? { Duck.new } # => true
matcher.match? { "a decoy" } # => false
matcher.to_s # => "fix Duck"
Matchi::Fix.new { it MUST be_a_kind_of Numeric }.match? { 42 } # => true
Spectus.must(matcher).call { "a decoy" }.to_s # => "Failure: expected \"a decoy\" to fix Duck"
match? answers true when every expectation passes, a warning or an info included, and false when one fails or errors, without saying which: Fix[:Name].test { … } says which. Since the value is given once, a specification meant for a matcher is written without with. A Fix::Spec is a matcher already, and inside a specification of Fix the word fix(:Duck) is that matcher: the class is the word of matchi for it, for the other frameworks.