Sha256: 877a3aa36c8cffd63397ac12eb7c3e1bc48a13a88cfdae5cc7397e4c02e23678
Contents?: true
Size: 1.47 KB
Versions: 45
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
45 entries across 45 versions & 3 rubygems