Class: RSpec::Notifications::Matcher
- Inherits:
-
Object
- Object
- RSpec::Notifications::Matcher
- Includes:
- Matchers::Composable
- Defined in:
- lib/rspec/notifications/matcher.rb
Overview
RSpec matcher asserting that a block emits an ActiveSupport::Notifications event. See RSpec::Matchers#emit_notification for the public entry point.
Instance Method Summary collapse
- #at_least(count) ⇒ Object
- #at_most(count) ⇒ Object
- #description ⇒ Object
- #does_not_match?(block) ⇒ Boolean
- #exactly(count) ⇒ Object
- #failure_message ⇒ Object
- #failure_message_when_negated ⇒ Object
-
#initialize(pattern) ⇒ Matcher
constructor
A new instance of Matcher.
-
#matches?(block) ⇒ Boolean
— matcher protocol ———————————————-.
- #once ⇒ Object
- #supports_block_expectations? ⇒ Boolean
-
#times ⇒ Object
syntactic sugar: exactly(n).times.
- #twice ⇒ Object
-
#with(payload) ⇒ Object
— chained expectations ——————————————.
Constructor Details
#initialize(pattern) ⇒ Matcher
Returns a new instance of Matcher.
8 9 10 11 12 13 |
# File 'lib/rspec/notifications/matcher.rb', line 8 def initialize(pattern) @pattern = pattern @expected_payload = nil @count_type = nil @count = nil end |
Instance Method Details
#at_least(count) ⇒ Object
34 35 36 |
# File 'lib/rspec/notifications/matcher.rb', line 34 def at_least(count) set_count(:at_least, count) end |
#at_most(count) ⇒ Object
38 39 40 |
# File 'lib/rspec/notifications/matcher.rb', line 38 def at_most(count) set_count(:at_most, count) end |
#description ⇒ Object
66 67 68 69 70 71 |
# File 'lib/rspec/notifications/matcher.rb', line 66 def description desc = "emit #{@pattern.inspect} notification" desc += " with payload #{description_of(@expected_payload)}" if @expected_payload desc += " #{count_description}" if @count_type desc end |
#does_not_match?(block) ⇒ Boolean
58 59 60 |
# File 'lib/rspec/notifications/matcher.rb', line 58 def does_not_match?(block) !matches?(block) end |
#exactly(count) ⇒ Object
30 31 32 |
# File 'lib/rspec/notifications/matcher.rb', line 30 def exactly(count) set_count(:exactly, count) end |
#failure_message ⇒ Object
73 74 75 |
# File 'lib/rspec/notifications/matcher.rb', line 73 def "expected block to #{description}, but #{observed_summary}#{emitted_breakdown}" end |
#failure_message_when_negated ⇒ Object
77 78 79 |
# File 'lib/rspec/notifications/matcher.rb', line 77 def "expected block not to #{description}, but #{observed_summary}#{emitted_breakdown}" end |
#matches?(block) ⇒ Boolean
— matcher protocol ———————————————-
49 50 51 52 53 54 55 56 |
# File 'lib/rspec/notifications/matcher.rb', line 49 def matches?(block) @events = Subscriber.capture(subscribe_pattern, &block) @matching_events = @events.select do |event| PayloadMatcher.matches?(@expected_payload, event.payload) end count_satisfied?(@matching_events.size) end |
#once ⇒ Object
22 23 24 |
# File 'lib/rspec/notifications/matcher.rb', line 22 def once exactly(1) end |
#supports_block_expectations? ⇒ Boolean
62 63 64 |
# File 'lib/rspec/notifications/matcher.rb', line 62 def supports_block_expectations? true end |
#times ⇒ Object
syntactic sugar: exactly(n).times
43 44 45 |
# File 'lib/rspec/notifications/matcher.rb', line 43 def times self end |
#twice ⇒ Object
26 27 28 |
# File 'lib/rspec/notifications/matcher.rb', line 26 def twice exactly(2) end |
#with(payload) ⇒ Object
— chained expectations ——————————————
17 18 19 20 |
# File 'lib/rspec/notifications/matcher.rb', line 17 def with(payload) @expected_payload = payload self end |