Sha256: 21d878c520c0a734e116fe29faf43d5632624970f1855a7ab0ad11f44c86e01c

Contents?: true

Size: 1.18 KB

Versions: 48

Compression:

Stored size: 1.18 KB

Contents

module Mocha

  class ExpectationList

    def initialize
      @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

    private

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

  end

end

Version data entries

48 entries across 40 versions & 4 rubygems

Version Path
tnargav-1.3.3 vendor/bundle/ruby/1.9.1/gems/mocha-0.14.0/lib/mocha/expectation_list.rb
challah-1.0.0 vendor/bundle/gems/mocha-0.14.0/lib/mocha/expectation_list.rb
tnargav-1.2.3 vendor/bundle/ruby/1.9.1/gems/mocha-0.14.0/lib/mocha/expectation_list.rb
mocha-0.14.0 lib/mocha/expectation_list.rb
challah-1.0.0.beta3 vendor/bundle/gems/mocha-0.13.3/lib/mocha/expectation_list.rb
mocha-0.14.0.alpha lib/mocha/expectation_list.rb
challah-1.0.0.beta2 vendor/bundle/gems/mocha-0.13.3/lib/mocha/expectation_list.rb
challah-1.0.0.beta vendor/bundle/gems/mocha-0.13.3/lib/mocha/expectation_list.rb
mocha-0.13.3 lib/mocha/expectation_list.rb
mocha-0.12.10 lib/mocha/expectation_list.rb
mocha-0.12.9 lib/mocha/expectation_list.rb
mocha-0.13.2 lib/mocha/expectation_list.rb
mocha-0.12.8 lib/mocha/expectation_list.rb
mocha-0.13.1 lib/mocha/expectation_list.rb
challah-rolls-0.2.0 vendor/bundle/gems/challah-0.8.3/vendor/bundle/gems/mocha-0.12.3/lib/mocha/expectation_list.rb
challah-rolls-0.2.0 vendor/bundle/gems/challah-0.8.3/vendor/bundle/gems/mocha-0.13.0/lib/mocha/expectation_list.rb
challah-rolls-0.2.0 vendor/bundle/gems/mocha-0.12.3/lib/mocha/expectation_list.rb
challah-rolls-0.2.0 vendor/bundle/gems/challah-0.8.0.pre/vendor/bundle/gems/mocha-0.12.2/lib/mocha/expectation_list.rb
challah-rolls-0.2.0 vendor/bundle/gems/mocha-0.12.2/lib/mocha/expectation_list.rb
challah-rolls-0.2.0 vendor/bundle/gems/mocha-0.13.0/lib/mocha/expectation_list.rb