Class: Message::Recorder::BranchingMock
- Defined in:
- lib/message-recorder/branching_mock.rb
Overview
Copyright © 2008 Simon Menke
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the “Software”), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
Instance Method Summary collapse
- #__branch__(&block) ⇒ Object
-
#initialize(recorder, collector) ⇒ BranchingMock
constructor
A new instance of BranchingMock.
- #method_missing(m, *args, &block) ⇒ Object
Constructor Details
#initialize(recorder, collector) ⇒ BranchingMock
Returns a new instance of BranchingMock.
26 27 28 29 30 31 |
# File 'lib/message-recorder/branching_mock.rb', line 26 def initialize(recorder, collector) @recorder = recorder @branched_collectors = [] @collector_prototype = collector.deep_copy @collector = collector.clear end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(m, *args, &block) ⇒ Object
39 40 41 42 43 44 45 46 47 48 49 50 51 52 |
# File 'lib/message-recorder/branching_mock.rb', line 39 def method_missing(m, *args, &block) @recorder.filter_before_branch(@collector_prototype) branched_collector = @collector_prototype.branch @branched_collectors << branched_collector @recorder.filter_after_branch(@collector_prototype, branched_collector) = ::Message::Recorder::Message.new(m, args, block) @recorder.filter_before_chain() branched_collector.record() @recorder.filter_after_chain() Message::Recorder::ChainingMock.new(@recorder, branched_collector) end |
Instance Method Details
#__branch__(&block) ⇒ Object
33 34 35 36 37 |
# File 'lib/message-recorder/branching_mock.rb', line 33 def __branch__(&block) __instance_eval__(&block) unless block.nil? @branched_collectors.each { |branched_collector| @collector.concat branched_collector } Message::Recorder::ChainingMock.new(@recorder, @collector) end |