-
Notifications
You must be signed in to change notification settings - Fork 17
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
have_broadcasted_to does not seem to work in Rails 5.2 #86
Comments
Could you please provide an example of the failing test as long as the exact versions of |
Versions:
Controller:
Spec File:
Results:
Most of the specs code were reference from the readme. |
Could you please do the following modification and show the output: it do
expect { subject; puts ActionCable.server.pubsub.send(:channels_data) }.to have_broadcasted_to(room).from_channel(RoomChannel)
end |
This is what i get:
I notice that if i do have_broadcasted_to(model), it does not seem to be on the right broadcast channel. As shown in the output it only shows the ref id without the model name prepended. Is this intended? I guessing thats why its not recognising the broadcast. |
Yep, without Let's do one more experiment: check the value of |
But... i'm using from_channel as shown in the code which is suppose to provide the channel prefix am i right? Yes both gid are the same after doing a binding.pry to check. is there a way i can fix this? |
Ok, I think, I know the reason. Could you spot the difference between https://github.com/palkan/action-cable-testing/blob/master/lib/rspec/rails/matchers/action_cable/have_broadcasted_to.rb and https://github.com/rspec/rspec-rails/blob/v4.0.0/lib/rspec/rails/matchers/action_cable/have_broadcasted_to.rb ? RSpec version of the matcher doesn't support Rails <6: In the gem, we use a refinement to backport this behavior and be compatible with both Rails 5 and Rails 6. Thus, I'd suggest either:
# have_broadcasted_to_patch.rb
require "action_cable/testing/rails_six"
using ActionCable::Testing::Rails6
class RSpec::Rails::Matchers::ActionCable::HaveBroadcastedTo
def stream
@stream ||= if @target.is_a?(String)
@target
else
check_channel_presence
@channel.broadcasting_for(@target)
end
end
end And load it after |
Thanks for the super prompt clarification! This made alot of sense now. I also notice from the relish documentation here to do something like this which actually works.
I decided to go with your patch instead as alot cleaner then the one recommended in relish and its also impossible for me to downgrade rspec now. Thank you so much for helping. I think this is worthy to be in the readme for legacy rails users like me. :D |
Currently I am on RSpec 4 with Rails 5.2. In order to get action cable test to work, I used the monkey patch as referenced from #76.
Channel testing works fine, however I cant seem to get have_broadcasted_to to work successfully. I have checked the logs and its shows that ActionCable is broadcasting to its respective channel with its respective message but the test sees that the broadcast is still 0.
Any idea on this or is this gem simply not compatible with my current setup?
The text was updated successfully, but these errors were encountered: