Sha256: 207a0e6beaf6a150041d00021a5020eb4974459d61dcc8496cff0e394bc18dd1

Contents?: true

Size: 754 Bytes

Versions: 2

Compression:

Stored size: 754 Bytes

Contents

require 'matchi'

module Expect
  # This module provides matchers to define expectations.
  module Matcher
    # Evaluate the expectation with the passed block.
    #
    # @param [Hash] definition
    #
    # @return [Boolean] Report if the expectation is true or false.
    def self.pass?(definition, &actual)
      params        = Array(definition).flatten 1
      name          = params.first
      expected_args = params[1..-1]
      matcher       = get(name).new(*expected_args)

      matcher.matches?(&actual)
    end

    # Get the class of a matcher from its symbol.
    #
    # @example
    #
    #   Matcher.get(:eql) # => Eql
    def self.get(name)
      Matchi.const_get name.to_s.split('_').map(&:capitalize).join.to_sym
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
expect-0.0.5 lib/expect/matcher.rb
expect-0.0.4 lib/expect/matcher.rb