Sha256: d2287e6bb272bb20fa6c2d0c8070ee30e7ab121a4094f8560465b167417d4789

Contents?: true

Size: 1.02 KB

Versions: 3

Compression:

Stored size: 1.02 KB

Contents

# frozen_string_literal: true

require 'matchi/matchers_base'
require 'fix'

# Namespace for the Matchi library.
module Matchi
  # Collection of matchers.
  module Matchers
    # **Fix** matcher.
    module Fix
      # The matcher.
      class Matcher
        include MatchersBase

        # Initialize the matcher with a spec.
        #
        # @example It MUST be equal to 42 matcher.
        #   new(proc { it { MUST equal 42 } })
        #
        # @param expected [Proc] A spec.
        def initialize(expected)
          @expected = expected
        end

        # @example Is 42 matching 6 * 7?
        #   fix = new(proc { it { MUST equal 42 } })
        #   fix.matches? { 6 * 7 } # => true
        #
        # @yieldreturn [#object_id] A front object to compare against the spec.
        #
        # @return [Boolean] The result of the test: _pass_ or _fail_.
        def matches?
          ::Fix.describe(yield, verbose: false, &@expected)
        rescue SystemExit => e
          e.success?
        end
      end
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
matchi-fix-1.0.4 lib/matchi/fix.rb
matchi-fix-1.0.3 lib/matchi/fix.rb
matchi-fix-1.0.2 lib/matchi/fix.rb