How can I test ActionCable channels using RSpec?

后端 未结 4 1521
刺人心
刺人心 2021-01-01 19:25

I am wondering how to test ActionCable channels.

Let\'s say I have the following chat channel:

class ChatChannel < ApplicationCable::Channel
  def s         


        
4条回答
  •  陌清茗
    陌清茗 (楼主)
    2021-01-01 20:02

    I would install and configure TCR gem for recording sockets interaction ('its like VCR for websockets')

    A spec for this in your case might look something like this...

    describe ChatChannel do
      context ".subscribed" do
        it "updates db and defines opens 2 streams for one channel" do
          TCR.use_cassette("subscribed_action") do |cassette|
            # ...
            ChatChannel.subscribed
            expect(cassette).to include "something ..."
          end
        end
      end
    end
    

提交回复
热议问题