Sha256: ace41ddae4261cfd75b9ad2823d6eead8db2aa8b0199e9ac7d1a01b6f1845ee4

Contents?: true

Size: 1.01 KB

Versions: 1

Compression:

Stored size: 1.01 KB

Contents

# frozen_string_literal: true

# Generate contexts to use specific Action Cable adapter:
# - "action_cable:async" (action_cable: :async)
# - "action_cable:inline" (action_cable: :inline)
# - "action_cable:test" (action_cabke: :test)
%w[async inline test].each do |adapter|
  RSpec.shared_context "action_cable:#{adapter}" do
    require "action_cable/subscription_adapter/#{adapter}"

    adapter_class = ActionCable::SubscriptionAdapter.const_get(adapter.capitalize)

    before do
      next if ActionCable.server.pubsub.is_a?(adapter_class)

      @__was_pubsub_adapter__ = ActionCable.server.pubsub

      adapter = adapter_class.new(ActionCable.server)
      ActionCable.server.instance_variable_set(:@pubsub, adapter)
    end

    after do
      next unless instance_variable_defined?(:@__was_pubsub_adapter__)
      ActionCable.server.instance_variable_set(:@pubsub, @__was_pubsub_adapter__)
    end
  end

  RSpec.configure do |config|
    config.include_context "action_cable:#{adapter}", action_cable: adapter.to_sym
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
action-cable-testing-0.1.2 lib/rspec/rails/shared_contexts/action_cable.rb