Class: Hivent::Spec::Matchers::Emit
- Inherits:
-
Object
- Object
- Hivent::Spec::Matchers::Emit
- Defined in:
- lib/hivent/spec/matchers/emit.rb
Instance Method Summary collapse
- #emitted? ⇒ Boolean
- #emitted_with_payload?(payload) ⇒ Boolean
-
#initialize(name, meta) ⇒ Emit
constructor
A new instance of Emit.
- #signals ⇒ Object
- #signals_with_payload(payload) ⇒ Object
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, ) @name = name @meta = end |
Instance Method Details
#emitted? ⇒ 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
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 |
#signals ⇒ Object
31 32 33 34 35 36 37 38 39 40 41 42 |
# File 'lib/hivent/spec/matchers/emit.rb', line 31 def signals .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 |