Class: ObjectProtocol::MessageExpectation

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(protocol:, sender:, message:) ⇒ MessageExpectation

Returns a new instance of MessageExpectation.



7
8
9
10
11
12
13
# File 'lib/object_protocol/message_expectation.rb', line 7

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

  @arguments_specified = false
end

Instance Attribute Details

#argumentsObject (readonly)

Returns the value of attribute arguments.



5
6
7
# File 'lib/object_protocol/message_expectation.rb', line 5

def arguments
  @arguments
end

#messageObject (readonly)

Returns the value of attribute message.



5
6
7
# File 'lib/object_protocol/message_expectation.rb', line 5

def message
  @message
end

#receiverObject (readonly)

Returns the value of attribute receiver.



5
6
7
# File 'lib/object_protocol/message_expectation.rb', line 5

def receiver
  @receiver
end

#senderObject (readonly)

Returns the value of attribute sender.



5
6
7
# File 'lib/object_protocol/message_expectation.rb', line 5

def sender
  @sender
end

Instance Method Details

#==(other) ⇒ Object



47
48
49
50
51
52
53
54
55
56
# File 'lib/object_protocol/message_expectation.rb', line 47

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)


58
59
60
# File 'lib/object_protocol/message_expectation.rb', line 58

def arguments_specified?
  @arguments_specified
end

#inspectObject



33
34
35
# File 'lib/object_protocol/message_expectation.rb', line 33

def inspect
  "<#{self.class.name.split('::').last}[#{sender.name}, :#{message}, #{receiver.name}]>"
end

#to(receiver) ⇒ Object



15
16
17
18
19
# File 'lib/object_protocol/message_expectation.rb', line 15

def to(receiver)
  @receiver = receiver

  self
end

#to_rspec_matcher_failure_message_linesObject



37
38
39
40
41
42
43
44
45
# File 'lib/object_protocol/message_expectation.rb', line 37

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

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

#to_satisfiableObject



29
30
31
# File 'lib/object_protocol/message_expectation.rb', line 29

def to_satisfiable
  SatisfiableMessageExpectation.new(protocol: protocol, message_expectation: self)
end

#with(*arguments) ⇒ Object



21
22
23
24
25
26
27
# File 'lib/object_protocol/message_expectation.rb', line 21

def with(*arguments)
  @arguments = arguments

  @arguments_specified = true

  self
end