class Matchi::Fix

Fix specing matcher.

Attributes

expected[R]

@return [#against] A set of specifications.

Public Class Methods

new(name = nil, &block) click to toggle source

Initialize the matcher with a behavioral definition.

@example With a block of specifications

require "matchi/fix"

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

@example With the constant name of the specifications

require "matchi/fix"

Fix :Answer do
  it MUST be 42
end

Matchi::Fix.new(:Answer)

@param name [String, Symbol] The constant name of the specifications. @param block [Proc] A block of specifications.

# File lib/matchi/fix.rb, line 30
def initialize(name = nil, &block)
  @name = name

  @expected = if unnamed?
                raise ::ArgumentError, "Pass either an argument or a block" unless block

                Fix(&block)
              else
                raise ::ArgumentError, "Can't pass both an argument and a block" if block

                ::Fix[name]
              end
end

Public Instance Methods

inspect() click to toggle source

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

# File lib/matchi/fix.rb, line 76
def inspect
  "#{self.class}(#{parameter})"
end
matches?(&block) click to toggle source

Boolean comparison between an actual value and the expected specs.

@example With a block of specifications

require "matchi/fix"

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

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

@example With the constant name of the specifications

require "matchi/fix"

Fix :Answer do
  it MUST be 42
end

matcher = Matchi::Fix.new(:Answer)

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

@yieldreturn [#object_id] The value to be compared to the specifications.

@return [Boolean] Determines whether the test has passed or failed.

# File lib/matchi/fix.rb, line 69
def matches?(&block)
  expected.against(log_level: 0, &block)
rescue ::SystemExit => e
  e.success?
end
to_s() click to toggle source

Returns a string representing the matcher.

# File lib/matchi/fix.rb, line 81
def to_s
  "fix #{parameter}"
end

Private Instance Methods

parameter() click to toggle source
# File lib/matchi/fix.rb, line 91
def parameter
  unnamed? ? "&specs" : ":#{@name}"
end
unnamed?() click to toggle source
# File lib/matchi/fix.rb, line 87
def unnamed?
  @name.nil?
end