Class: Spec::Mocks::Mock
- Includes:
- Methods
- Defined in:
- lib/spec/mocks/mock.rb
Instance Method Summary collapse
-
#initialize(name, options = {}) ⇒ Mock
constructor
Creates a new mock with a
name
(that will be used in error messages only) == Options: *:null_object
- if true, the mock object acts as a forgiving null object allowing any message to be sent to it. - #method_missing(sym, *args, &block) ⇒ Object
Methods included from Methods
#__reset_mock, #__verify, #received_message?, #should_not_receive, #should_receive, #stub!
Constructor Details
#initialize(name, options = {}) ⇒ Mock
Creates a new mock with a name
(that will be used in error messages only)
Options:
-
:null_object
- if true, the mock object acts as a forgiving null object allowing any message to be sent to it.
9 10 11 12 |
# File 'lib/spec/mocks/mock.rb', line 9 def initialize(name, ={}) @name = name @options = end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(sym, *args, &block) ⇒ Object
14 15 16 17 18 19 20 21 22 |
# File 'lib/spec/mocks/mock.rb', line 14 def method_missing(sym, *args, &block) __mock_handler.instance_eval {@messages_received << [sym, args, block]} begin return self if __mock_handler.null_object? super(sym, *args, &block) rescue NoMethodError __mock_handler. sym, *args end end |