class FlexMock::CompositeExpectation

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.

Public Class Methods

new() click to toggle source

Initialize the composite expectation.

# File lib/flexmock/composite_expectation.rb, line 9
def initialize
  @expectations = []
end

Public Instance Methods

add(expectation) click to toggle source

Add an expectation to the composite.

# File lib/flexmock/composite_expectation.rb, line 14
def add(expectation)
  @expectations << expectation
end
method_missing(sym, *args, **kw, &block) click to toggle source

Apply the constraint method to all expectations in the composite.

# File lib/flexmock/composite_expectation.rb, line 19
def method_missing(sym, *args, **kw, &block)
  @expectations.each do |expectation|
    expectation.send(sym, *args, **kw, &block)
  end
  self
end
mock() click to toggle source

Return the associated mock object.

# File lib/flexmock/composite_expectation.rb, line 35
def mock
  @expectations.first.mock
end
order_number() click to toggle source

Return the order number of the first expectation in the list.

# File lib/flexmock/composite_expectation.rb, line 30
def order_number
  @expectations.first.order_number
end
should_receive(*args, **kw, &block) click to toggle source

Start a new method expectation. The following constraints will be applied to the new expectation.

# File lib/flexmock/composite_expectation.rb, line 41
def should_receive(*args, **kw, &block)
  @expectations.first.mock.
    flexmock_define_expectation(caller, *args, **kw, &block)
end
to_s() click to toggle source

Return a string representations

# File lib/flexmock/composite_expectation.rb, line 47
def to_s
  if @expectations.size > 1
    "[" + @expectations.collect { |e| e.to_s }.join(', ') + "]"
  else
    @expectations.first.to_s
  end
end