module RSpec::Rails::ChannelExampleGroup

def have_rejected_connection

expect { connect }.to have_rejected_connection
@example

Checks that the connection attempt has been rejected.
def have_rejected_connection
  raise_error(::ActionCable::Connection::Authorization::UnauthorizedError)
end

def have_stream_for(object)

expect(subscription).to have_stream_for(user)
@example

Checks that the channel has been subscribed to a stream for the given model
def have_stream_for(object)
  check_subscribed!
  RSpec::Rails::Matchers::ActionCable::HaveStream.new(broadcasting_for(object))
end

def have_stream_from(stream)

expect(subscription).to have_stream_from("chat_1")
@example

Checks that the channel has been subscribed to the given stream
def have_stream_from(stream)
  check_subscribed!
  RSpec::Rails::Matchers::ActionCable::HaveStream.new(stream)
end

def have_streams

expect(subscription).to have_streams
@example

Checks that the subscription is subscribed to at least one stream.
def have_streams
  check_subscribed!
  RSpec::Rails::Matchers::ActionCable::HaveStream.new
end