Module: Anyt::TestHelpers
- Defined in:
- lib/anyt/ext/minitest.rb
Overview
Common tests helpers
Class Method Summary collapse
Instance Method Summary collapse
- #assert_includes_message(collection, expected) ⇒ Object
-
#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).
- #build_client(**args) ⇒ Object
- #remote_client ⇒ Object
- #restart_server! ⇒ Object
Class Method Details
.included(base) ⇒ Object
10 11 12 13 |
# File 'lib/anyt/ext/minitest.rb', line 10 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
40 41 42 43 44 45 46 |
# File 'lib/anyt/ext/minitest.rb', line 40 def (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)
36 37 38 |
# File 'lib/anyt/ext/minitest.rb', line 36 def (expected, actual) assert_equal expected, actual.slice(*expected.keys) end |
#build_client(**args) ⇒ Object
15 16 17 18 19 20 |
# File 'lib/anyt/ext/minitest.rb', line 15 def build_client(**args) @clients ||= [] Anyt::Client.new(**args).tap do |client| @clients << client end end |
#remote_client ⇒ Object
30 31 32 |
# File 'lib/anyt/ext/minitest.rb', line 30 def remote_client @remote_client ||= RemoteControl::Client.connect(Anyt.config.remote_control_port) end |
#restart_server! ⇒ Object
22 23 24 25 26 27 28 |
# File 'lib/anyt/ext/minitest.rb', line 22 def restart_server! if Anyt.config.use_action_cable remote_client.restart_action_cable else Command.restart end end |