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
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 (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 (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_client ⇒ Object
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 |