Sha256: 6c6dc61c87f67b3ebc325be43357a1deb3bdf02d522de4d1ecbe79960b557c51

Contents?: true

Size: 1011 Bytes

Versions: 28

Compression:

Stored size: 1011 Bytes

Contents

module Matchy::Expectations
  class PredicateExpectation < Base
    def initialize(predicate, *arguments)
      @test_case = arguments.pop
      @predicate = predicate
      @arguments = arguments
    end

    def matches?(receiver)
      @receiver = receiver
      @receiver.send("#{@predicate}?", *@arguments)
    end

    def failure_message
      message = "Expected #{@receiver.inspect} to be #{@predicate}"
      message << " with #{@arguments.map {|e| e.inspect }.join(", ")}" unless @arguments.empty?
      message
    end

    def negative_failure_message
      message = "Expected #{@receiver.inspect} not to be #{@predicate}"
      message << " with #{@arguments.map {|e| e.inspect }.join(", ")}" unless @arguments.empty?
      message
    end
  end

  module TestCaseExtensions
    def method_missing(method, *args, &block)
      if method.to_s =~ /^be_(.*)/
        args << self
        Matchy::Expectations::PredicateExpectation.new($1, *args)
      else
        super
      end
    end
  end
end

Version data entries

28 entries across 28 versions & 8 rubygems

Version Path
alphasights-integrity-0.1.10 test/helpers/expectations/predicates.rb
alphasights-integrity-0.1.9.3 test/helpers/expectations/predicates.rb
alphasights-integrity-0.1.9.4 test/helpers/expectations/predicates.rb
alphasights-integrity-0.1.9.5 test/helpers/expectations/predicates.rb
alphasights-integrity-0.1.9.6 test/helpers/expectations/predicates.rb
alphasights-integrity-0.1.9.7 test/helpers/expectations/predicates.rb
alphasights-integrity-0.1.9.8 test/helpers/expectations/predicates.rb
foca-integrity-0.1.9.0 test/helpers/expectations/predicates.rb
foca-integrity-0.1.9.1 test/helpers/expectations/predicates.rb
foca-integrity-0.1.9.2 test/helpers/expectations/predicates.rb
foca-integrity-0.1.9.3 test/helpers/expectations/predicates.rb
gforces-integrity-0.1.9.3 test/helpers/expectations/predicates.rb
gforces-integrity-0.1.9.4 test/helpers/expectations/predicates.rb
imbriaco-integrity-0.1.9.2.1 test/helpers/expectations/predicates.rb
imbriaco-integrity-0.1.9.2 test/helpers/expectations/predicates.rb
integrity-integrity-0.1.10 test/helpers/expectations/predicates.rb
integrity-integrity-0.1.9.3 test/helpers/expectations/predicates.rb
oliyoung-integrity-0.1.9.0 test/helpers/expectations/predicates.rb
sr-integrity-0.1.8.1 test/helpers/expectations/predicates.rb
sr-integrity-0.1.9.1 test/helpers/expectations/predicates.rb