Sha256: 07fe75db12c959ea519b2e64061cfc4b66aa4cc5583c982d9e2b3ad247c774ef

Contents?: true

Size: 1020 Bytes

Versions: 6

Compression:

Stored size: 1020 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

6 entries across 6 versions & 4 rubygems

Version Path
brycethornton-integrity-0.1.7.1 test/helpers/expectations/predicates.rb
foca-integrity-0.1.6 test/helpers/expectations/predicates.rb
foca-integrity-0.1.7 test/helpers/expectations/predicates.rb
foca-integrity-0.1.8 test/helpers/expectations/predicates.rb
myronmarston-integrity-0.1.7.1 test/helpers/expectations/predicates.rb
integrity-0.1.8 test/helpers/expectations/predicates.rb