Class: TestBench::Telemetry::Substitute::Sink
Constant Summary
collapse
- MatchError =
Class.new(RuntimeError)
TestBench::Telemetry::Sink::ReceiveError
Instance Method Summary
collapse
Instance Method Details
#any_event? ⇒ Boolean
Also known as:
event?
36
37
38
|
# File 'lib/test_bench/telemetry/substitute/sink.rb', line 36
def any_event?(...)
events(...).any?
end
|
#events(event_class, **attributes) ⇒ Object
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
|
# File 'lib/test_bench/telemetry/substitute/sink.rb', line 41
def events(event_class, **attributes)
event_type = event_class.event_type
events = []
received_events.each do |event_data|
event_types_correspond = event_data.type == event_type
if event_types_correspond
event = Event::Import.(event_data, event_class)
attributes_correspond = attributes.all? do |attribute, compare_value|
value = event.public_send(attribute)
value == compare_value
end
if attributes_correspond
events << event
end
end
end
events
end
|
#one_event ⇒ Object
25
26
27
28
29
30
31
32
33
34
|
# File 'lib/test_bench/telemetry/substitute/sink.rb', line 25
def one_event(...)
events = events(...)
if events.count > 1
event_type = events.first.event_type
raise MatchError, "More than one event matches (Type: #{event_type.inspect}, Matching Events: #{events.count})"
end
events.first
end
|
#one_event? ⇒ Boolean
21
22
23
|
# File 'lib/test_bench/telemetry/substitute/sink.rb', line 21
def one_event?(...)
!one_event(...).nil?
end
|
#receive(event_data) ⇒ Object
13
14
15
|
# File 'lib/test_bench/telemetry/substitute/sink.rb', line 13
def receive(event_data)
received_events << event_data
end
|
#received?(event_data) ⇒ Boolean
17
18
19
|
# File 'lib/test_bench/telemetry/substitute/sink.rb', line 17
def received?(event_data)
received_events.include?(event_data)
end
|
#received_events ⇒ Object
9
10
11
|
# File 'lib/test_bench/telemetry/substitute/sink.rb', line 9
def received_events
@received_events ||= []
end
|