Class: ObjectProtocol::Step

Inherits:
Object
  • Object
show all
Defined in:
lib/object_protocol/step.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(sender:, message:) ⇒ Step

Returns a new instance of Step.



5
6
7
8
9
10
# File 'lib/object_protocol/step.rb', line 5

def initialize(sender:, message:)
  @sender  = sender
  @message = message

  @arguments_specified = false
end

Instance Attribute Details

#argumentsObject (readonly)

Returns the value of attribute arguments.



3
4
5
# File 'lib/object_protocol/step.rb', line 3

def arguments
  @arguments
end

#messageObject (readonly)

Returns the value of attribute message.



3
4
5
# File 'lib/object_protocol/step.rb', line 3

def message
  @message
end

#receiverObject (readonly)

Returns the value of attribute receiver.



3
4
5
# File 'lib/object_protocol/step.rb', line 3

def receiver
  @receiver
end

#senderObject (readonly)

Returns the value of attribute sender.



3
4
5
# File 'lib/object_protocol/step.rb', line 3

def sender
  @sender
end

Instance Method Details

#==(other) ⇒ Object



40
41
42
43
44
45
46
47
48
49
# File 'lib/object_protocol/step.rb', line 40

def ==(other)
  other.respond_to?(:sender) &&
    sender == other.sender &&
    other.respond_to?(:receiver) &&
    receiver == other.receiver &&
    other.respond_to?(:message) &&
    message == other.message &&
    other.respond_to?(:arguments) &&
    arguments == other.arguments
end

#arguments_specified?Boolean

Returns:

  • (Boolean)


51
52
53
# File 'lib/object_protocol/step.rb', line 51

def arguments_specified?
  @arguments_specified
end

#inspectObject



26
27
28
# File 'lib/object_protocol/step.rb', line 26

def inspect
  "<Step[#{sender.name}, :#{message}, #{receiver.name}]>"
end

#to(receiver) ⇒ Object



12
13
14
15
16
# File 'lib/object_protocol/step.rb', line 12

def to(receiver)
  @receiver = receiver

  self
end

#to_rspec_matcher_failure_message_lineObject



30
31
32
33
34
35
36
37
38
# File 'lib/object_protocol/step.rb', line 30

def to_rspec_matcher_failure_message_line
  fragment_base = "#{sender.name}.sends(:#{message}).to(#{receiver.name})"

  if arguments_specified?
    "#{fragment_base}.with(#{arguments})"
  else
    fragment_base
  end
end

#with(*arguments) ⇒ Object



18
19
20
21
22
23
24
# File 'lib/object_protocol/step.rb', line 18

def with(*arguments)
  @arguments = arguments

  @arguments_specified = true

  self
end