Class: FlexMock::CompositeExpectation
- Defined in:
- lib/gems/flexmock-0.8.3/lib/flexmock/expectation.rb
Overview
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.
Instance Method Summary collapse
-
#add(expectation) ⇒ Object
Add an expectation to the composite.
-
#initialize ⇒ CompositeExpectation
constructor
Initialize the composite expectation.
-
#method_missing(sym, *args, &block) ⇒ Object
Apply the constraint method to all expectations in the composite.
-
#mock ⇒ Object
Return the associated mock object.
-
#order_number ⇒ Object
Return the order number of the first expectation in the list.
-
#should_receive(*args, &block) ⇒ Object
Start a new method expectation.
-
#to_s ⇒ Object
Return a string representations.
Constructor Details
#initialize ⇒ CompositeExpectation
Initialize the composite expectation.
402 403 404 |
# File 'lib/gems/flexmock-0.8.3/lib/flexmock/expectation.rb', line 402 def initialize @expectations = [] end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(sym, *args, &block) ⇒ Object
Apply the constraint method to all expectations in the composite.
412 413 414 415 416 417 |
# File 'lib/gems/flexmock-0.8.3/lib/flexmock/expectation.rb', line 412 def method_missing(sym, *args, &block) @expectations.each do |expectation| expectation.send(sym, *args, &block) end self end |
Instance Method Details
#add(expectation) ⇒ Object
Add an expectation to the composite.
407 408 409 |
# File 'lib/gems/flexmock-0.8.3/lib/flexmock/expectation.rb', line 407 def add(expectation) @expectations << expectation end |
#mock ⇒ Object
Return the associated mock object.
428 429 430 |
# File 'lib/gems/flexmock-0.8.3/lib/flexmock/expectation.rb', line 428 def mock @expectations.first.mock end |
#order_number ⇒ Object
Return the order number of the first expectation in the list.
423 424 425 |
# File 'lib/gems/flexmock-0.8.3/lib/flexmock/expectation.rb', line 423 def order_number @expectations.first.order_number end |
#should_receive(*args, &block) ⇒ Object
Start a new method expectation. The following constraints will be applied to the new expectation.
434 435 436 |
# File 'lib/gems/flexmock-0.8.3/lib/flexmock/expectation.rb', line 434 def should_receive(*args, &block) @expectations.first.mock.should_receive(*args, &block) end |
#to_s ⇒ Object
Return a string representations
439 440 441 442 443 444 445 |
# File 'lib/gems/flexmock-0.8.3/lib/flexmock/expectation.rb', line 439 def to_s if @expectations.size > 1 "[" + @expectations.collect { |e| e.to_s }.join(', ') + "]" else @expectations.first.to_s end end |