class Hivent::Spec::Matchers::Emit

Public Class Methods

new(name, meta) click to toggle source
# File lib/hivent/spec/matchers/emit.rb, line 10
def initialize(name, meta)
  @name = name
  @meta = meta
end

Public Instance Methods

emitted?() { || ... } click to toggle source
# File lib/hivent/spec/matchers/emit.rb, line 15
def emitted?
  before = signals.length

  yield

  signals.length > before
end
emitted_with_payload?(payload) { || ... } click to toggle source
# 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() click to toggle source
# 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) click to toggle source
# File lib/hivent/spec/matchers/emit.rb, line 44
def signals_with_payload(payload)
  signals.select { |signal| deep_include?(signal[:message][:payload], payload) }
end

Private Instance Methods

deep_include?(hash, sub_hash) click to toggle source
# File lib/hivent/spec/matchers/emit.rb, line 54
def deep_include?(hash, sub_hash)
  sub_hash.keys.all? do |key|
    if hash.has_key?(key) && sub_hash[key].is_a?(Hash) && hash[key].is_a?(Hash)
      deep_include?(hash[key], sub_hash[key])
    else
      hash[key] == sub_hash[key]
    end
  end
end
messages() click to toggle source
# File lib/hivent/spec/matchers/emit.rb, line 50
def messages
  Signal.messages
end