Class: Crspec::Mock::InstanceDouble
- Defined in:
- lib/crspec/mock/double.rb
Overview
A verifying double: only methods that exist on the doubled class's instance interface may be stubbed or expected.
Instance Attribute Summary
Attributes inherited from Double
Instance Method Summary collapse
- #__crspec_verify_stub!(method_name) ⇒ Object
-
#initialize(doubled_class, name = nil, stubs = {}) ⇒ InstanceDouble
constructor
A new instance of InstanceDouble.
- #inspect ⇒ Object
Methods inherited from Double
Constructor Details
#initialize(doubled_class, name = nil, stubs = {}) ⇒ InstanceDouble
Returns a new instance of InstanceDouble.
38 39 40 41 42 |
# File 'lib/crspec/mock/double.rb', line 38 def initialize(doubled_class, name = nil, stubs = {}) @doubled_class = doubled_class.is_a?(Module) ? doubled_class : nil @doubled_class_name = doubled_class.is_a?(Module) ? doubled_class.name : doubled_class.to_s super(name || @doubled_class_name, stubs) end |
Instance Method Details
#__crspec_verify_stub!(method_name) ⇒ Object
44 45 46 47 48 49 50 51 52 53 |
# File 'lib/crspec/mock/double.rb', line 44 def __crspec_verify_stub!(method_name) return unless @doubled_class method_sym = method_name.to_sym return if @doubled_class.method_defined?(method_sym) || @doubled_class.private_method_defined?(method_sym) raise MockError, "the #{@doubled_class_name} class does not implement the instance method: #{method_sym}" end |
#inspect ⇒ Object
55 56 57 |
# File 'lib/crspec/mock/double.rb', line 55 def inspect "#<InstanceDouble(#{@doubled_class_name}) #{@name.inspect}>" end |