Class: ObjectProtocol

Inherits:
Object
  • Object
show all
Defined in:
lib/object_protocol.rb,
lib/object_protocol/step.rb,
lib/object_protocol/version.rb,
lib/object_protocol/stand_in.rb,
lib/object_protocol/execution.rb,
lib/object_protocol/sent_message.rb,
lib/object_protocol/satisfiable_step.rb,
lib/object_protocol/satisfaction_attempt.rb

Defined Under Namespace

Modules: RSpecMatchers Classes: Execution, SatisfactionAttempt, SatisfiableStep, SentMessage, StandIn, Step

Constant Summary collapse

VERSION =
"0.1.0"

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(*participant_names, &protocol) ⇒ ObjectProtocol

Returns a new instance of ObjectProtocol.



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

def initialize(*participant_names, &protocol)
  participant_names.each(&method(:define_stand_in))
  instance_exec(&protocol)
  participant_names.each(&method(:undefine_stand_in))
end

Instance Attribute Details

#participants_by_nameObject (readonly)

Returns the value of attribute participants_by_name.



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

def participants_by_name
  @participants_by_name
end

Instance Method Details

#bind(**participants_by_name) ⇒ Object



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

def bind(**participants_by_name)
  @participants_by_name = participants_by_name

  @participants_by_name.each(&method(:define_participant))

  self
end

#name_of_participant(participant) ⇒ Object



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

def name_of_participant(participant)
  participants_by_name.invert[participant]
end

#participant_by_name(name) ⇒ Object



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

def participant_by_name(name)
  participants_by_name[name]
end

#participantsObject



38
39
40
# File 'lib/object_protocol.rb', line 38

def participants
  participants_by_name.values
end

#satisfied_by?(&blk) ⇒ Boolean

Returns:

  • (Boolean)


22
23
24
# File 'lib/object_protocol.rb', line 22

def satisfied_by?(&blk)
  SatisfactionAttempt.new(self, &blk).to_bool
end

#stepsObject



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

def steps
  @steps ||= []
end

#to_rspec_matcher_failure_message_linesObject



42
43
44
# File 'lib/object_protocol.rb', line 42

def to_rspec_matcher_failure_message_lines
  steps.map(&:to_rspec_matcher_failure_message_line)
end