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

Version Path
rsanheim-micronaut-0.1.3.2 lib/micronaut/matchers/operator_matcher.rb
rsanheim-micronaut-0.1.4.1 lib/micronaut/matchers/operator_matcher.rb
spicycode-micronaut-0.1.3 lib/micronaut/matchers/operator_matcher.rb
spicycode-micronaut-0.1.4.1 lib/micronaut/matchers/operator_matcher.rb
spicycode-micronaut-0.1.4.2 lib/micronaut/matchers/operator_matcher.rb
spicycode-micronaut-0.1.4.3 lib/micronaut/matchers/operator_matcher.rb
spicycode-micronaut-0.1.4.4 lib/micronaut/matchers/operator_matcher.rb
spicycode-micronaut-0.1.4 lib/micronaut/matchers/operator_matcher.rb
spicycode-micronaut-0.1.5.2 lib/micronaut/matchers/operator_matcher.rb
spicycode-micronaut-0.1.5 lib/micronaut/matchers/operator_matcher.rb
spicycode-micronaut-0.1.6.1 lib/micronaut/matchers/operator_matcher.rb
spicycode-micronaut-0.1.6.8 lib/micronaut/matchers/operator_matcher.rb
spicycode-micronaut-0.1.6.9.1 lib/micronaut/matchers/operator_matcher.rb
spicycode-micronaut-0.1.6.9 lib/micronaut/matchers/operator_matcher.rb
spicycode-micronaut-0.1.6 lib/micronaut/matchers/operator_matcher.rb
spicycode-micronaut-0.1.7.1 lib/micronaut/matchers/operator_matcher.rb
spicycode-micronaut-0.1.7.2 lib/micronaut/matchers/operator_matcher.rb
spicycode-micronaut-0.1.7.3 lib/micronaut/matchers/operator_matcher.rb
spicycode-micronaut-0.1.7.4 lib/micronaut/matchers/operator_matcher.rb
spicycode-micronaut-0.1.7 lib/micronaut/matchers/operator_matcher.rb