Class: Hivent::Spec::Matchers::Emit

Inherits:
Object
  • Object
show all
Defined in:
lib/hivent/spec/matchers/emit.rb

Instance Method Summary collapse

Constructor Details

#initialize(name, meta) ⇒ Emit

Returns a new instance of Emit.



10
11
12
13
# File 'lib/hivent/spec/matchers/emit.rb', line 10

def initialize(name, meta)
  @name = name
  @meta = meta
end

Instance Method Details

#emitted?Boolean

Returns:

  • (Boolean)


15
16
17
18
19
20
21
# File 'lib/hivent/spec/matchers/emit.rb', line 15

def emitted?
  before = signals.length

  yield

  signals.length > before
end

#emitted_with_payload?(payload) ⇒ Boolean

Returns:

  • (Boolean)


23
24
25
26
27
28
29
# File 'lib/hivent/spec/matchers/emit.rb', line 23

def emitted_with_payload?(payload)
  before = signals_with_payload(payload).length

  yield

  signals_with_payload(payload).length > before
end

#signalsObject



31
32
33
34
35
36
37
38
39
40
41
42
# File 'lib/hivent/spec/matchers/emit.rb', line 31

def signals
  messages
    .lazy
    .select { |signal| signal[:name] == @name }
    .select do |signal|
      @meta.all? do |key, value|
        !value.present? ||
        value == signal[:message][:meta][key]
      end
    end
    .to_a
end

#signals_with_payload(payload) ⇒ Object



44
45
46
# File 'lib/hivent/spec/matchers/emit.rb', line 44

def signals_with_payload(payload)
  signals.select { |signal| deep_include?(signal[:message][:payload], payload) }
end