Sha256: 470cd3662c5b9505b69e1f43ebaf7ee26468fdf43e5b58d3e9265da29a75c834
Contents?: true
Size: 1.47 KB
Versions: 9
Compression:
Stored size: 1.47 KB
Contents
module Micronaut module Matchers class OperatorMatcher def initialize(actual) @actual = actual end ['==','===','<','<=','>=','>','=~'].each do |operator| define_method operator do |expected| ::Micronaut::Matchers.last_matcher = self @operator, @expected = operator, expected __delegate_operator(@actual, operator, expected) end end def fail_with_message(message) Micronaut::Expectations.fail_with(message, @expected, @actual) end def description "#{@operator} #{@expected.inspect}" end end class PositiveOperatorMatcher < OperatorMatcher #:nodoc: def __delegate_operator(actual, operator, expected) return true if actual.__send__(operator, expected) if ['==','===', '=~'].include?(operator) fail_with_message("expected: #{expected.inspect},\n got: #{actual.inspect} (using #{operator})") else fail_with_message("expected: #{operator} #{expected.inspect},\n got: #{operator.gsub(/./, ' ')} #{actual.inspect}") end end end class NegativeOperatorMatcher < OperatorMatcher #:nodoc: def __delegate_operator(actual, operator, expected) return true unless actual.__send__(operator, expected) return fail_with_message("expected not: #{operator} #{expected.inspect},\n got: #{operator.gsub(/./, ' ')} #{actual.inspect}") end end end end
Version data entries
9 entries across 9 versions & 1 rubygems