Class: Hardmock::Trapper
- Includes:
- MethodCleanout
- Defined in:
- lib/hardmock/trapper.rb
Overview
:nodoc:
Constant Summary
Constants included from MethodCleanout
MethodCleanout::SACRED_METHODS
Instance Method Summary collapse
-
#initialize(mock, mock_control, expectation_builder) ⇒ Trapper
constructor
A new instance of Trapper.
- #method_missing(mname, *args) ⇒ Object
Methods included from MethodCleanout
Constructor Details
#initialize(mock, mock_control, expectation_builder) ⇒ Trapper
Returns a new instance of Trapper.
8 9 10 11 12 |
# File 'lib/hardmock/trapper.rb', line 8 def initialize(mock,mock_control,expectation_builder) @mock = mock @mock_control = mock_control @expectation_builder = expectation_builder end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(mname, *args) ⇒ Object
14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 |
# File 'lib/hardmock/trapper.rb', line 14 def method_missing(mname, *args) if block_given? raise ExpectationError.new("Don't pass blocks when using 'trap' (setting exepectations for '#{mname}')") end the_block = lambda { |target_block| target_block } expectation = @expectation_builder.build_expectation( :mock => @mock, :method => mname, :arguments => args, :suppress_arguments_to_block => true, :block => the_block) @mock_control.add_expectation expectation expectation end |