Class: Wisper::RSpec::BroadcastMatcher::Matcher

Inherits:
Object
  • Object
show all
Defined in:
lib/wisper/rspec/matchers.rb

Instance Method Summary collapse

Constructor Details

#initialize(event, *args) ⇒ Matcher

Returns a new instance of Matcher.



29
30
31
32
# File 'lib/wisper/rspec/matchers.rb', line 29

def initialize(event, *args)
  @event = event
  @args = args
end

Instance Method Details

#failure_messageObject



48
49
50
51
52
# File 'lib/wisper/rspec/matchers.rb', line 48

def failure_message
  msg = "expected publisher to broadcast #{@event} event"
  msg += " with args: #{@args.inspect}" if @args.size > 0
  msg
end

#failure_message_when_negatedObject



54
55
56
57
58
# File 'lib/wisper/rspec/matchers.rb', line 54

def failure_message_when_negated
  msg = "expected publisher not to broadcast #{@event} event"
  msg += " with args: #{@args.inspect}" if @args.size > 0
  msg
end

#matches?(block) ⇒ Boolean

Returns:

  • (Boolean)


38
39
40
41
42
43
44
45
46
# File 'lib/wisper/rspec/matchers.rb', line 38

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

Returns:

  • (Boolean)


34
35
36
# File 'lib/wisper/rspec/matchers.rb', line 34

def supports_block_expectations?
  true
end