Class: ObjectProtocol::SatisfactionAttempt

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

Instance Method Summary collapse

Constructor Details

#initialize(protocol, &blk) ⇒ SatisfactionAttempt

Returns a new instance of SatisfactionAttempt.



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

def initialize(protocol, &blk)
  @protocol = protocol
  @blk      = blk
end

Instance Method Details

#to_boolObject



10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
# File 'lib/object_protocol/satisfaction_attempt.rb', line 10

def to_bool
  execution.call(protocol)

  satisfiable_expectations = protocol.expectations.map(&:to_satisfiable)

  execution.messages.each do |sent_message|
    next_expectation = satisfiable_expectations.first

    next_expectation.attempt_to_apply_sent_message(sent_message)

    if next_expectation.satisfied?
      satisfiable_expectations.shift
    end
  end

  satisfiable_expectations.empty?
end

#to_rspec_matcher_failure_message_linesObject



28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
# File 'lib/object_protocol/satisfaction_attempt.rb', line 28

def to_rspec_matcher_failure_message_lines
  return ["<empty execution>"] if execution.messages.empty?

  execution.messages.map do |sent_message|
    fragment_base = "#{protocol.name_of_participant(sent_message.sender)}"\
      ".sent(:#{sent_message.name})"\
      ".to(#{protocol.name_of_participant(sent_message.receiver)})"

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