Class: Matchi::Fix
- Inherits:
-
Object
- Object
- Matchi::Fix
- Defined in:
- lib/matchi/fix.rb
Overview
Specification conformance matcher that verifies objects against Fix test specifications.
This matcher allows testing objects against Fix specifications, enabling verification of implementation conformance across different testing frameworks. It supports both anonymous specifications defined inline and named specifications registered with Fix. The matcher provides a bridge between Matchi’s matcher interface and Fix’s powerful specification system.
Instance Method Summary collapse
-
#initialize(name = nil, &block) ⇒ Fix
constructor
Initialize the matcher with either a name or a specification block.
-
#match? { ... } ⇒ Boolean
Checks if the yielded object satisfies the Fix specification.
-
#to_s ⇒ String
Returns a human-readable description of the matcher.
Constructor Details
#initialize(name = nil, &block) ⇒ Fix
Initialize the matcher with either a name or a specification block.
72 73 74 75 76 77 |
# File 'lib/matchi/fix.rb', line 72 def initialize(name = nil, &block) raise ::ArgumentError, "a name or a block must be provided" if name.nil? && block.nil? raise ::ArgumentError, "a name or a block must be provided" if !name.nil? && !block.nil? @expected = name.nil? ? ::Fix.spec(&block) : ::Fix[name] end |
Instance Method Details
#match? { ... } ⇒ Boolean
Checks if the yielded object satisfies the Fix specification.
This method executes the Fix specification against the provided object, verifying that all specified behaviors and conditions are met. It works with both anonymous and named specifications.
109 110 111 112 113 |
# File 'lib/matchi/fix.rb', line 109 def match? raise ::ArgumentError, "a block must be provided" unless block_given? @expected.match?(yield) end |
#to_s ⇒ String
Returns a human-readable description of the matcher.
124 125 126 |
# File 'lib/matchi/fix.rb', line 124 def to_s "fix #{@expected.inspect}" end |