Class: Matchi::Fix

Inherits:
Object
  • Object
show all
Defined in:
lib/matchi/fix.rb

Overview

Fix matcher.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(&block) ⇒ Fix

Initialize the matcher with a block of specs.

Examples:

require "matchi/fix"

Matchi::Fix.new { it MUST be 42 }

Parameters:

  • block (Proc)

    A block of code.



20
21
22
# File 'lib/matchi/fix.rb', line 20

def initialize(&block)
  @expected = Fix(&block)
end

Instance Attribute Details

#expectedProc (readonly)

Returns A set of specifications.

Returns:

  • (Proc)

    A set of specifications.



10
11
12
# File 'lib/matchi/fix.rb', line 10

def expected
  @expected
end

Instance Method Details

#inspectObject

A string containing a human-readable representation of the matcher.



45
46
47
# File 'lib/matchi/fix.rb', line 45

def inspect
  "#{self.class}(&specs)"
end

#matches?(&block) ⇒ Boolean

Boolean comparison between the actual value and the expected specs.

Examples:

require "matchi/fix"

matcher = Matchi::Fix.new { it MUST be 42 }

matcher.expected        # => #<Fix::Set:0x00007fd96915dc28 ...>
matcher.matches? { 42 } # => true

Yield Returns:

  • (#object_id)

    The actual value to compare to the expected one.

Returns:

  • (Boolean)

    Comparison between actual and expected values.



38
39
40
41
42
# File 'lib/matchi/fix.rb', line 38

def matches?(&block)
  expected.test(log_level: 0, &block)
rescue ::SystemExit => e
  e.success?
end

#to_sObject

Returns a string representing the matcher.



50
51
52
# File 'lib/matchi/fix.rb', line 50

def to_s
  "fix &specs"
end