Module: Anyt::TestHelpers

Defined in:
lib/anyt/ext/minitest.rb

Overview

Common tests helpers

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.included(base) ⇒ Object



11
12
13
14
# File 'lib/anyt/ext/minitest.rb', line 11

def self.included(base)
  base.let(:client) { build_client(ignore: %w[ping welcome]) }
  base.after { @clients&.each { |client| client.close(allow_messages: true) } }
end

Instance Method Details

#assert_includes_message(collection, expected) ⇒ Object



41
42
43
44
45
46
47
# File 'lib/anyt/ext/minitest.rb', line 41

def assert_includes_message(collection, expected)
  found = collection.find do |el|
    el.slice(*expected.keys) == expected
  end

  assert found, "Expecte #{collection} to include a message matching #{expected}"
end

#assert_message(expected, actual) ⇒ Object

Verifies that the actual message Hash is a subset of the expected one (so we can ignore some irrelevant fields)



37
38
39
# File 'lib/anyt/ext/minitest.rb', line 37

def assert_message(expected, actual)
  assert_equal expected, actual.slice(*expected.keys)
end

#build_client(**args) ⇒ Object



16
17
18
19
20
21
# File 'lib/anyt/ext/minitest.rb', line 16

def build_client(**args)
  @clients ||= []
  Anyt::Client.new(**args).tap do |client|
    @clients << client
  end
end

#remote_clientObject



31
32
33
# File 'lib/anyt/ext/minitest.rb', line 31

def remote_client
  @remote_client ||= RemoteControl::Client.connect(Anyt.config.remote_control_port)
end

#restart_server!Object



23
24
25
26
27
28
29
# File 'lib/anyt/ext/minitest.rb', line 23

def restart_server!
  if Anyt.config.use_action_cable
    remote_client.restart_action_cable
  else
    Command.restart
  end
end