Module: Turbo::SystemTestHelper
- Defined in:
- lib/turbo/system_test_helper.rb
Defined Under Namespace
Classes: SignedStreamNameConditions
Instance Method Summary collapse
-
#assert_no_turbo_cable_stream_source(*args, &block) ⇒ Object
Asserts that a ‘<turbo-cable-stream-source>` element is absent from the document.
-
#assert_turbo_cable_stream_source(*args, &block) ⇒ Object
Asserts that a ‘<turbo-cable-stream-source>` element is present in the document.
-
#connect_turbo_cable_stream_sources(**options, &block) ⇒ Object
Delay until every ‘<turbo-cable-stream-source>` element present in the page is ready to receive broadcasts.
Instance Method Details
#assert_no_turbo_cable_stream_source(*args, &block) ⇒ Object
Asserts that a ‘<turbo-cable-stream-source>` element is absent from the document
Arguments
-
locator
optional locator to determine the element’s ‘[signed-stream-name]` attribute. Can be of any type that is a valid argument toTurbo::Streams::StreamName#signed_stream_name
.
Options
-
:connected
matches the ‘[connected]` attribute -
:channel
matches the ‘[channel]` attribute. Can be a Class, String, Symbol, or Regexp -
:signed_stream_name
matches the element’s ‘[signed-stream-name]` attribute. Can be of any type that is a valid argument toTurbo::Streams::StreamName#signed_stream_name
.
In addition to the filters listed above, accepts any valid Capybara global filter option.
78 79 80 |
# File 'lib/turbo/system_test_helper.rb', line 78 def assert_no_turbo_cable_stream_source(*args, &block) assert_no_selector(:turbo_cable_stream_source, *args, &block) end |
#assert_turbo_cable_stream_source(*args, &block) ⇒ Object
Asserts that a ‘<turbo-cable-stream-source>` element is present in the document
Arguments
-
locator
optional locator to determine the element’s ‘[signed-stream-name]` attribute. Can be of any type that is a valid argument toTurbo::Streams::StreamName#signed_stream_name
.
Options
-
:connected
matches the ‘[connected]` attribute -
:channel
matches the ‘[channel]` attribute. Can be a Class, String, Symbol, or Regexp -
:signed_stream_name
matches the element’s ‘[signed-stream-name]` attribute. Can be of any type that is a valid argument toTurbo::Streams::StreamName#signed_stream_name
.
In addition to the filters listed above, accepts any valid Capybara global filter option.
54 55 56 |
# File 'lib/turbo/system_test_helper.rb', line 54 def assert_turbo_cable_stream_source(*args, &block) assert_selector(:turbo_cable_stream_source, *args, &block) end |
#connect_turbo_cable_stream_sources(**options, &block) ⇒ Object
Delay until every ‘<turbo-cable-stream-source>` element present in the page is ready to receive broadcasts
test "renders broadcasted Messages" do
= Message.new content: "Hello, from Action Cable"
visit "/"
click_link "All Messages"
.save! # execute server-side code to broadcast a Message
assert_text .content
end
By default, calls to ‘#visit` will wait for all `<turbo-cable-stream-source>` elements to connect. You can control this by modifying the `config.turbo.test_connect_after_actions`. For example, to wait after calls to `#click_link`, add the following to `config/environments/test.rb`:
# config/environments/test.rb
config.turbo.test_connect_after_actions << :click_link
To disable automatic connecting, set the configuration to ‘[]`:
# config/environments/test.rb
config.turbo.test_connect_after_actions = []
28 29 30 31 32 |
# File 'lib/turbo/system_test_helper.rb', line 28 def connect_turbo_cable_stream_sources(**, &block) all(:turbo_cable_stream_source, **, connected: false, wait: 0).each do |element| element.assert_matches_selector(:turbo_cable_stream_source, **, connected: true, &block) end end |