Sha256: 2748996253120f7f2e6eafe794d9b7519d559a4c3f417d9f52f6da7aa36223f2

Contents?: true

Size: 1.02 KB

Versions: 25

Compression:

Stored size: 1.02 KB

Contents

module RR
module TimesCalledMatchers
  class TimesCalledMatcher
    class << self
      def create(value)
        return value if value.is_a?(TimesCalledMatcher)
        return IntegerMatcher.new(value) if value.is_a?(Integer)
        return RangeMatcher.new(value) if value.is_a?(Range )
        return ProcMatcher.new(value) if value.is_a?(Proc)
        raise ArgumentError, "There is no TimesCalledMatcher for #{value.inspect}."
      end
    end

    attr_reader :times
    
    def initialize(times)
      @times = times
    end

    def matches?(times_called)
    end

    def attempt?(times_called)
    end

    def error_message(times_called)
      "Called #{times_called.inspect} #{pluralized_time(times_called)}.\n#{expected_message_part}"
    end

    def ==(other)
      self.class == other.class && self.times == other.times
    end

    protected
    def expected_message_part
      "Expected #{@times.inspect} times."
    end

    def pluralized_time(times_called)
      (times_called == 1) ? "time" : "times"
    end
  end
end
end

Version data entries

25 entries across 25 versions & 1 rubygems

Version Path
rr-0.1.8 lib/rr/times_called_matchers/times_called_matcher.rb
rr-0.1.14 lib/rr/times_called_matchers/times_called_matcher.rb
rr-0.1.13 lib/rr/times_called_matchers/times_called_matcher.rb
rr-0.1.12 lib/rr/times_called_matchers/times_called_matcher.rb
rr-0.1.11 lib/rr/times_called_matchers/times_called_matcher.rb
rr-0.1.15 lib/rr/times_called_matchers/times_called_matcher.rb
rr-0.1.10 lib/rr/times_called_matchers/times_called_matcher.rb
rr-0.3.10 lib/rr/times_called_matchers/times_called_matcher.rb
rr-0.2.1 lib/rr/times_called_matchers/times_called_matcher.rb
rr-0.3.11 lib/rr/times_called_matchers/times_called_matcher.rb
rr-0.3.3 lib/rr/times_called_matchers/times_called_matcher.rb
rr-0.3.1 lib/rr/times_called_matchers/times_called_matcher.rb
rr-0.3.4 lib/rr/times_called_matchers/times_called_matcher.rb
rr-0.3.2 lib/rr/times_called_matchers/times_called_matcher.rb
rr-0.2.4 lib/rr/times_called_matchers/times_called_matcher.rb
rr-0.2.3 lib/rr/times_called_matchers/times_called_matcher.rb
rr-0.2.5 lib/rr/times_called_matchers/times_called_matcher.rb
rr-0.2.2 lib/rr/times_called_matchers/times_called_matcher.rb
rr-0.1.9 lib/rr/times_called_matchers/times_called_matcher.rb
rr-0.3.0 lib/rr/times_called_matchers/times_called_matcher.rb