Class: Mocha::Mock
Instance Attribute Summary collapse
-
#mocked ⇒ Object
readonly
Returns the value of attribute mocked.
Instance Method Summary collapse
- #always_responds ⇒ Object
- #expects(symbol) ⇒ Object
-
#initialize(*arguments) ⇒ Mock
constructor
A new instance of Mock.
Methods included from MockMethods
#expectations, #expectations_matching, #matching_expectation, #method_missing, #stubs, #super_method_missing, #unexpected_method_called, #verify
Constructor Details
#initialize(*arguments) ⇒ Mock
Returns a new instance of Mock.
11 12 13 14 15 16 17 18 |
# File 'lib/mocha/mock.rb', line 11 def initialize(*arguments) @mocked = arguments.shift unless arguments.first.is_a?(Hash) @mocked ||= always_responds expectations = arguments.shift || {} expectations.each do |method_name, result| expects(method_name).returns(result) end end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method in the class Mocha::MockMethods
Instance Attribute Details
#mocked ⇒ Object (readonly)
Returns the value of attribute mocked.
9 10 11 |
# File 'lib/mocha/mock.rb', line 9 def mocked @mocked end |
Instance Method Details
#always_responds ⇒ Object
25 26 27 |
# File 'lib/mocha/mock.rb', line 25 def always_responds Class.new { def respond_to?(symbol); true; end }.new end |
#expects(symbol) ⇒ Object
20 21 22 23 |
# File 'lib/mocha/mock.rb', line 20 def expects(symbol) raise Test::Unit::AssertionFailedError, "Cannot replace #{symbol} as #{@mocked} does not respond to it." unless @mocked.respond_to?(symbol) super end |