Sha256: 3c75ea0df476fe7edbe90227b136eebdf2eb86c32b2bc691fb251d4bfb94508f
Contents?: true
Size: 1.53 KB
Versions: 5
Compression:
Stored size: 1.53 KB
Contents
module Spec module Matchers class BaseOperatorMatcher def initialize(target) @target = target end def ==(expected) @expected = expected __delegate_method_missing_to_target("==", expected) end def ===(expected) @expected = expected __delegate_method_missing_to_target("===", expected) end def =~(expected) @expected = expected __delegate_method_missing_to_target("=~", expected) end def fail_with_message(message) Spec::Expectations.fail_with(message, @expected, @target) end end class PositiveOperatorMatcher < BaseOperatorMatcher #:nodoc: def __delegate_method_missing_to_target(operator, expected) ::Spec::Matchers.generated_description = "should #{operator} #{expected.inspect}" return if @target.send(operator, expected) return fail_with_message("expected #{expected.inspect}, got #{@target.inspect} (using #{operator})") if ['==','==='].include?(operator) return fail_with_message("expected =~ #{expected.inspect}, got #{@target.inspect}") end end class NegativeOperatorMatcher < BaseOperatorMatcher #:nodoc: def __delegate_method_missing_to_target(operator, expected) ::Spec::Matchers.generated_description = "should not #{operator} #{expected.inspect}" return unless @target.send(operator, expected) return fail_with_message("expected not #{operator} #{expected.inspect}, got #{@target.inspect}") end end end end
Version data entries
5 entries across 5 versions & 1 rubygems