I’m trying to improve the tests for my ActionCable system but I’m having a hard time. In test, it seems like my stream_from("something") { ... }
handlers aren’t actually called. I was trying to debug and I made a minimal test case in a new Rails 7.2.1 app.
First, I made an empty ActionCable channel:
# app/channels/test_channel.rb
class TestChannel < ApplicationCable::Channel
end
Then, I wrote a test just to see if I could make it work:
require "test_helper"
class TestChannelTest < ActionCable::Channel::TestCase
test "it works at all" do
subscribe
assert subscription.confirmed?
last_message = nil
subscription.stream_from("something") do |message|
last_message = message
end
ActionCable.server.broadcast("something", 100)
assert_equal(100, last_message)
end
end
But this test fails:
# Running:
F
Failure:
TestChannelTest#test_it_works_at_all [test/channels/test_channel_test.rb:14]:
Expected: 100
Actual: nil
As far as I can tell, the stream_from
block is never called at all.
What am I missing? How can I make this test pass?