Sha256: 1f96e943a9773883847f332c3871cbe7bc8a2e408f232438d17c451a0408a8cf

Contents?: true

Size: 952 Bytes

Versions: 2

Compression:

Stored size: 952 Bytes

Contents

# frozen_string_literal: true

require 'matchi/matcher/base'

# Namespace for the Matchi library.
module Matchi
  # Collection of matcher classes.
  module Matcher
    # **Fix** matcher.
    class Fix < ::Matchi::Matcher::Base
      # 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, &expected)
        true
      rescue ::SystemExit => e
        e.success?
      end
    end
  end
end

require 'fix'

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
matchi-fix-1.1.1 lib/matchi/matcher/fix.rb
matchi-fix-1.1.0 lib/matchi/matcher/fix.rb