Module: RSpec::Rails::ChannelExampleGroup

Extended by:
ActiveSupport::Concern
Includes:
ActionCable::Channel::TestCase::Behavior, ActionCable::Connection::TestCase::Behavior, RailsExampleGroup
Defined in:
lib/rspec/rails/example/channel_example_group.rb,
lib/rspec/rails/example/channel_example_group.rb

Overview

Container module for channel spec functionality.

Defined Under Namespace

Modules: ClassMethods

Instance Method Summary collapse

Instance Method Details

#have_rejected_connectionObject

Checks that the connection attempt has been rejected.

Examples:

expect { connect }.to have_rejected_connection


58
59
60
# File 'lib/rspec/rails/example/channel_example_group.rb', line 58

def have_rejected_connection
  raise_error(::ActionCable::Connection::Authorization::UnauthorizedError)
end

#have_stream_for(object) ⇒ Object

Checks that the channel has been subscribed to a stream for the given model

Examples:

expect(subscription).to have_stream_for(user)


86
87
88
89
# File 'lib/rspec/rails/example/channel_example_group.rb', line 86

def have_stream_for(object)
  check_subscribed!
  RSpec::Rails::Matchers::ActionCable::HaveStream.new(broadcasting_for(object))
end

#have_stream_from(stream) ⇒ Object

Checks that the channel has been subscribed to the given stream

Examples:

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


76
77
78
79
80
# File 'lib/rspec/rails/example/channel_example_group.rb', line 76

def have_stream_from(stream)
  check_subscribed!

  RSpec::Rails::Matchers::ActionCable::HaveStream.new(stream)
end

#have_streamsObject

Checks that the subscription is subscribed to at least one stream.

Examples:

expect(subscription).to have_streams


66
67
68
69
70
# File 'lib/rspec/rails/example/channel_example_group.rb', line 66

def have_streams
  check_subscribed!

  RSpec::Rails::Matchers::ActionCable::HaveStream.new
end