Class: Wisper::RSpec::BroadcastMatcher::Matcher
- Inherits:
-
Object
- Object
- Wisper::RSpec::BroadcastMatcher::Matcher
- Includes:
- RSpec::Matchers::Composable
- Defined in:
- lib/wisper/rspec/matchers.rb
Instance Method Summary collapse
- #actual ⇒ Object
- #broadcast_events_args ⇒ Object
- #diffable? ⇒ Boolean
- #expected ⇒ Object
- #failure_message ⇒ Object
- #failure_message_when_negated ⇒ Object
-
#initialize(event, *args) ⇒ Matcher
constructor
A new instance of Matcher.
- #matches?(block) ⇒ Boolean
- #supports_block_expectations? ⇒ Boolean
Constructor Details
#initialize(event, *args) ⇒ Matcher
39 40 41 42 |
# File 'lib/wisper/rspec/matchers.rb', line 39 def initialize(event, *args) @event = event @args = args end |
Instance Method Details
#actual ⇒ Object
69 70 71 |
# File 'lib/wisper/rspec/matchers.rb', line 69 def actual broadcast_events_args end |
#broadcast_events_args ⇒ Object
83 84 85 |
# File 'lib/wisper/rspec/matchers.rb', line 83 def broadcast_events_args @event_recorder.broadcast_events.map {|event| event.size == 1 ? [] : event[1..-1] } end |
#diffable? ⇒ Boolean
73 74 75 |
# File 'lib/wisper/rspec/matchers.rb', line 73 def diffable? true end |
#expected ⇒ Object
65 66 67 |
# File 'lib/wisper/rspec/matchers.rb', line 65 def expected [] << @args end |
#failure_message ⇒ Object
58 59 60 61 62 63 |
# File 'lib/wisper/rspec/matchers.rb', line 58 def msg = "expected publisher to broadcast #{@event} event" msg += " with args: #{@args.inspect}" if @args.size > 0 msg << broadcast_events_list msg end |
#failure_message_when_negated ⇒ Object
77 78 79 80 81 |
# File 'lib/wisper/rspec/matchers.rb', line 77 def msg = "expected publisher not to broadcast #{@event} event" msg += " with args: #{@args.inspect}" if @args.size > 0 msg end |
#matches?(block) ⇒ Boolean
48 49 50 51 52 53 54 55 56 |
# File 'lib/wisper/rspec/matchers.rb', line 48 def matches?(block) @event_recorder = EventRecorder.new Wisper.subscribe(@event_recorder) do block.call end @event_recorder.broadcast?(@event, *@args) end |
#supports_block_expectations? ⇒ Boolean
44 45 46 |
# File 'lib/wisper/rspec/matchers.rb', line 44 def supports_block_expectations? true end |