Sha256: 9842974e33f1099ea88973ddf91e5397f127509d268503237f1a94e207af9fb0

Contents?: true

Size: 1.28 KB

Versions: 13

Compression:

Stored size: 1.28 KB

Contents

module Mocha

  class ExpectationList

    def initialize(expectations = [])
      @expectations = expectations
    end

    def add(expectation)
      @expectations.unshift(expectation)
      expectation
    end

    def remove_all_matching_method(method_name)
      @expectations.reject! { |expectation| expectation.matches_method?(method_name) }
    end

    def matches_method?(method_name)
      @expectations.any? { |expectation| expectation.matches_method?(method_name) }
    end

    def match(method_name, *arguments)
      matching_expectations(method_name, *arguments).first
    end

    def match_allowing_invocation(method_name, *arguments)
      matching_expectations(method_name, *arguments).detect { |e| e.invocations_allowed? }
    end

    def verified?(assertion_counter = nil)
      @expectations.all? { |expectation| expectation.verified?(assertion_counter) }
    end

    def to_a
      @expectations
    end

    def to_set
      @expectations.to_set
    end

    def length
      @expectations.length
    end

    def any?
      @expectations.any?
    end

    def +(other)
      self.class.new(self.to_a + other.to_a)
    end

    private

    def matching_expectations(method_name, *arguments)
      @expectations.select { |e| e.match?(method_name, *arguments) }
    end

  end

end

Version data entries

13 entries across 10 versions & 2 rubygems

Version Path
mocha-1.6.0 lib/mocha/expectation_list.rb
mocha-1.5.0 lib/mocha/expectation_list.rb
mocha-1.4.0 lib/mocha/expectation_list.rb
mocha-1.3.0 lib/mocha/expectation_list.rb
mocha-1.2.1 lib/mocha/expectation_list.rb
mocha-1.2.0 lib/mocha/expectation_list.rb
apl-library-0.0.90 vendor/bundle/ruby/2.1.0/gems/mocha-1.0.0/lib/mocha/expectation_list.rb
apl-library-0.0.90 vendor/bundle/ruby/1.9.1/gems/mocha-1.0.0/lib/mocha/expectation_list.rb
apl-library-0.0.90 vendor/bundle/ruby/2.1.0/gems/apl-library-0.0.90/vendor/bundle/ruby/1.9.1/gems/mocha-1.0.0/lib/mocha/expectation_list.rb
apl-library-0.0.90 vendor/bundle/ruby/2.1.0/gems/apl-library-0.0.90/vendor/bundle/ruby/2.1.0/gems/mocha-1.0.0/lib/mocha/expectation_list.rb
mocha-1.1.0 lib/mocha/expectation_list.rb
mocha-1.0.0 lib/mocha/expectation_list.rb
mocha-1.0.0.alpha lib/mocha/expectation_list.rb