Sha256: b5f1c12af7e4fa8a7cf00cac299be40e73242324d2b50815f8da9d6a2b4d1a13

Contents?: true

Size: 1.48 KB

Versions: 22

Compression:

Stored size: 1.48 KB

Contents

class FlexMock

  # A composite expectation allows several expectations to be grouped into a
  # single composite and then apply the same constraints to  all expectations
  # in the group.
  class CompositeExpectation

    # Initialize the composite expectation.
    def initialize
      @expectations = []
    end

    # Add an expectation to the composite.
    def add(expectation)
      @expectations << expectation
    end

    # Apply the constraint method to all expectations in the composite.
    def method_missing(sym, *args, &block)
      @expectations.each do |expectation|
        expectation.send(sym, *args, &block)
      end
      self
    end

    # The following methods return a value, so we make an arbitrary choice
    # and return the value for the first expectation in the composite.

    # Return the order number of the first expectation in the list.
    def order_number
      @expectations.first.order_number
    end

    # Return the associated mock object.
    def mock
      @expectations.first.mock
    end

    # Start a new method expectation.  The following constraints will be
    # applied to the new expectation.
    def should_receive(*args, &block)
      @expectations.first.mock.
        flexmock_define_expectation(caller, *args, &block)
    end

    # Return a string representations
    def to_s
      if @expectations.size > 1
        "[" + @expectations.collect { |e| e.to_s }.join(', ') + "]"
      else
        @expectations.first.to_s
      end
    end
  end

end

Version data entries

22 entries across 22 versions & 1 rubygems

Version Path
flexmock-2.4.2 lib/flexmock/composite_expectation.rb
flexmock-2.4.1 lib/flexmock/composite_expectation.rb
flexmock-2.4.0 lib/flexmock/composite_expectation.rb
flexmock-2.3.8 lib/flexmock/composite_expectation.rb
flexmock-2.3.6 lib/flexmock/composite_expectation.rb
flexmock-2.3.5 lib/flexmock/composite_expectation.rb
flexmock-2.3.4 lib/flexmock/composite_expectation.rb
flexmock-2.3.3 lib/flexmock/composite_expectation.rb
flexmock-2.3.2 lib/flexmock/composite_expectation.rb
flexmock-2.3.1 lib/flexmock/composite_expectation.rb
flexmock-2.3.0 lib/flexmock/composite_expectation.rb
flexmock-2.2.1 lib/flexmock/composite_expectation.rb
flexmock-2.2.0 lib/flexmock/composite_expectation.rb
flexmock-2.1.0 lib/flexmock/composite_expectation.rb
flexmock-2.0.6 lib/flexmock/composite_expectation.rb
flexmock-2.0.5 lib/flexmock/composite_expectation.rb
flexmock-2.0.4 lib/flexmock/composite_expectation.rb
flexmock-2.0.3 lib/flexmock/composite_expectation.rb
flexmock-2.0.2 lib/flexmock/composite_expectation.rb
flexmock-2.0.1 lib/flexmock/composite_expectation.rb