Sha256: 9cbc502785e295da15e73c381dc70221869b78454dbf091e88f84850c3bfaf2b

Contents?: true

Size: 1.26 KB

Versions: 1

Compression:

Stored size: 1.26 KB

Contents

# frozen_string_literal: true

require "fix"

# Namespace for the Matchi library.
module Matchi
  # **Fix** matcher.
  class Fix
    # @return [Proc] A set of specifications.
    attr_reader :expected

    # Initialize the matcher with a block of specs.
    #
    # @example
    #   require "matchi/fix"
    #
    #   Matchi::Fix.new { it MUST be 42 }
    #
    # @param block [Proc] A block of code.
    def initialize(&block)
      @expected = Fix(&block)
    end

    # Boolean comparison between the actual value and the expected specs.
    #
    # @example
    #   require "matchi/fix"
    #
    #   matcher = Matchi::Fix.new { it MUST be 42 }
    #
    #   matcher.expected        # => #<Fix::Set:0x00007fd96915dc28 ...>
    #   matcher.matches? { 42 } # => true
    #
    # @yieldreturn [#object_id] The actual value to compare to the expected
    #   one.
    #
    # @return [Boolean] Comparison between actual and expected values.
    def matches?(&block)
      expected.test(log_level: 0, &block)
    rescue ::SystemExit => e
      e.success?
    end

    # A string containing a human-readable representation of the matcher.
    def inspect
      "#{self.class}(&specs)"
    end

    # Returns a string representing the matcher.
    def to_s
      "fix &specs"
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
matchi-fix-2.0.0 lib/matchi/fix.rb