Class: Impersonator::Method
- Inherits:
-
Struct
- Object
- Struct
- Impersonator::Method
- Defined in:
- lib/impersonator/method.rb
Overview
A method instance
Instance Attribute Summary collapse
-
#arguments ⇒ Object
Arguments passed to the method invocation.
-
#block ⇒ Object
Returns the value of attribute block.
-
#matching_configuration ⇒ Object
The configuration that will be used to match the method invocation at replay mode.
-
#name ⇒ Object
Method name.
Instance Method Summary collapse
- #==(other_method) ⇒ Object
-
#block_spy ⇒ BlockSpy
The spy used to spy the block yield invocations.
- #encode_with(coder) ⇒ Object
- #init_with(coder) ⇒ Object
- #to_s ⇒ Object
Instance Attribute Details
#arguments ⇒ Object
Arguments passed to the method invocation
3 4 5 |
# File 'lib/impersonator/method.rb', line 3 def arguments @arguments end |
#block ⇒ Object
Returns the value of attribute block
3 4 5 |
# File 'lib/impersonator/method.rb', line 3 def block @block end |
#matching_configuration ⇒ Object
The configuration that will be used to match the method invocation at replay mode
3 4 5 |
# File 'lib/impersonator/method.rb', line 3 def matching_configuration @matching_configuration end |
#name ⇒ Object
Method name
3 4 5 |
# File 'lib/impersonator/method.rb', line 3 def name @name end |
Instance Method Details
#==(other_method) ⇒ Object
43 44 45 46 47 48 49 50 51 52 53 |
# File 'lib/impersonator/method.rb', line 43 def ==(other_method) my_arguments = arguments.dup other_arguments = other_method.arguments.dup matching_configuration&.ignored_positions&.each do |ignored_position| my_arguments.delete_at(ignored_position) other_arguments.delete_at(ignored_position) end name == other_method.name && my_arguments == other_arguments && !block_spy == !other_method.block_spy end |
#block_spy ⇒ BlockSpy
The spy used to spy the block yield invocations
23 24 25 26 27 |
# File 'lib/impersonator/method.rb', line 23 def block_spy return nil if !@block_spy && !block @block_spy ||= BlockSpy.new(actual_block: block) end |
#encode_with(coder) ⇒ Object
36 37 38 39 40 41 |
# File 'lib/impersonator/method.rb', line 36 def encode_with(coder) coder['name'] = name coder['arguments'] = arguments coder['block_spy'] = block_spy coder['matching_configuration'] = matching_configuration end |
#init_with(coder) ⇒ Object
29 30 31 32 33 34 |
# File 'lib/impersonator/method.rb', line 29 def init_with(coder) self.name = coder['name'] self.arguments = coder['arguments'] self.matching_configuration = coder['matching_configuration'] @block_spy = coder['block_spy'] end |
#to_s ⇒ Object
10 11 12 13 14 15 16 17 18 |
# File 'lib/impersonator/method.rb', line 10 def to_s string = name.to_s arguments_string = arguments&.collect(&:to_s)&.join(', ') string << "(#{arguments_string})" string << ' {with block}' if block string end |