Class: VerifiedDouble::RecordingDouble
- Inherits:
-
SimpleDelegator
- Object
- SimpleDelegator
- VerifiedDouble::RecordingDouble
- Defined in:
- lib/verified_double/recording_double.rb
Instance Method Summary collapse
- #and_return(return_value) ⇒ Object
- #class_double? ⇒ Boolean
- #class_name ⇒ Object
- #double ⇒ Object
-
#initialize(double) ⇒ RecordingDouble
constructor
A new instance of RecordingDouble.
- #inspect ⇒ Object
- #method_operator ⇒ Object
- #method_signatures ⇒ Object
- #should_receive(method) ⇒ Object
- #to_s ⇒ Object
- #with(*args) ⇒ Object
Constructor Details
#initialize(double) ⇒ RecordingDouble
Returns a new instance of RecordingDouble.
5 6 7 8 |
# File 'lib/verified_double/recording_double.rb', line 5 def initialize(double) @double = double super(@double) end |
Instance Method Details
#and_return(return_value) ⇒ Object
10 11 12 13 14 |
# File 'lib/verified_double/recording_double.rb', line 10 def and_return(return_value) self.method_signatures.last.return_value = return_value @double_call.and_return(return_value) self end |
#class_double? ⇒ Boolean
16 17 18 |
# File 'lib/verified_double/recording_double.rb', line 16 def class_double? ! double.is_a?(RSpec::Fire::FireObjectDouble) end |
#class_name ⇒ Object
20 21 22 |
# File 'lib/verified_double/recording_double.rb', line 20 def class_name double.instance_variable_get('@name') end |
#double ⇒ Object
24 25 26 |
# File 'lib/verified_double/recording_double.rb', line 24 def double __getobj__ end |
#inspect ⇒ Object
28 29 30 |
# File 'lib/verified_double/recording_double.rb', line 28 def inspect to_s end |
#method_operator ⇒ Object
32 33 34 |
# File 'lib/verified_double/recording_double.rb', line 32 def method_operator class_double? ? '.' : '#' end |
#method_signatures ⇒ Object
36 37 38 |
# File 'lib/verified_double/recording_double.rb', line 36 def method_signatures @method_signatures ||= [] end |
#should_receive(method) ⇒ Object
40 41 42 43 44 45 46 |
# File 'lib/verified_double/recording_double.rb', line 40 def should_receive(method) method_signature = MethodSignature.new(self) method_signature.method = method self.method_signatures << method_signature @double_call = super(method) self end |
#to_s ⇒ Object
48 49 50 |
# File 'lib/verified_double/recording_double.rb', line 48 def to_s "#{VerifiedDouble}.of_#{class_double? ? 'class' : 'instance' }('#{class_name}')" end |
#with(*args) ⇒ Object
52 53 54 55 56 |
# File 'lib/verified_double/recording_double.rb', line 52 def with(*args) self.method_signatures.last.args = args @double_call.with(*args) self end |