Sha256: f3c75495b9fa170148553e96176488b459d5e5ba12c83231f215b704ecbb5fb0

Contents?: true

Size: 1.19 KB

Versions: 24

Compression:

Stored size: 1.19 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(invocation)
      matching_expectations(invocation).first
    end

    def match_allowing_invocation(invocation)
      matching_expectations(invocation).detect(&: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(to_a + other.to_a)
    end

    private

    def matching_expectations(invocation)
      @expectations.select { |e| e.match?(invocation) }
    end
  end
end

Version data entries

24 entries across 24 versions & 2 rubygems

Version Path
mocha-2.1.0 lib/mocha/expectation_list.rb
mocha-2.0.4 lib/mocha/expectation_list.rb
mocha-2.0.3 lib/mocha/expectation_list.rb
fluent-plugin-google-cloud-logging-on-prem-0.1.0 vendor/ruby/3.1.0/gems/mocha-2.0.2/lib/mocha/expectation_list.rb
mocha-2.0.2 lib/mocha/expectation_list.rb
mocha-1.16.1 lib/mocha/expectation_list.rb
mocha-1.15.1 lib/mocha/expectation_list.rb
mocha-2.0.1 lib/mocha/expectation_list.rb
mocha-2.0.0 lib/mocha/expectation_list.rb
mocha-1.16.0 lib/mocha/expectation_list.rb
mocha-2.0.0.alpha.1 lib/mocha/expectation_list.rb
mocha-2.0.0.alpha lib/mocha/expectation_list.rb
mocha-1.15.0 lib/mocha/expectation_list.rb
mocha-1.14.0 lib/mocha/expectation_list.rb
mocha-1.13.0 lib/mocha/expectation_list.rb
mocha-1.12.0 lib/mocha/expectation_list.rb
mocha-1.11.2 lib/mocha/expectation_list.rb
mocha-1.11.1 lib/mocha/expectation_list.rb
mocha-1.11.0 lib/mocha/expectation_list.rb
mocha-1.10.2 lib/mocha/expectation_list.rb