ruby-on-railsrspecruby-on-rails-5actioncable

How can I test ActionCable channels using RSpec?


I am wondering how to test ActionCable channels.

Let's say I have the following chat channel:

class ChatChannel < ApplicationCable::Channel
  def subscribed
    current_user.increment!(:num_of_chats)

    stream_from "chat_#{params[:chat_id]}"
    stream_from "chat_stats_#{params[:chat_id]}"
  end
end

The subscribed method updates the db and defines two streams to be broadcasted across the channel, but the details are not very important since my question is a more general one:

RSpec provides a lot of helper methods and various utilities when testing similar interactions like controller actions, but I couldn't find anything regarding RSpec and ActionCable.


Solution

  • Look like it was merged to Rails 6. Checkout the release note Action cable testing and the pr AC testing PR