Sha256: 8c7f4c422e4e47a008a4e4ffeab4c6eeffa646bf2d3220bd8803cfcdb426c38b

Contents?: true

Size: 1.67 KB

Versions: 43

Compression:

Stored size: 1.67 KB

Contents

module RSpec
  module Rails
    module Matchers
      module ActionCable
        # @api private
        # Provides the implementation for `have_stream`, `have_stream_for`, and `have_stream_from`.
        # Not intended to be instantiated directly.
        class HaveStream < RSpec::Matchers::BuiltIn::BaseMatcher
          # @api private
          # @return [String]
          def failure_message
            "expected to have #{base_message}"
          end

          # @api private
          # @return [String]
          def failure_message_when_negated
            "expected not to have #{base_message}"
          end

          # @api private
          # @return [Boolean]
          def matches?(subscription)
            raise(ArgumentError, "have_streams is used for negated expectations only") if no_expected?

            match(subscription)
          end

          # @api private
          # @return [Boolean]
          def does_not_match?(subscription)
            !match(subscription)
          end

        private

          def match(subscription)
            case subscription
            when ::ActionCable::Channel::Base
              @actual = subscription.streams
              no_expected? ? actual.any? : actual.any? { |i| expected === i }
            else
              raise ArgumentError, "have_stream, have_stream_from and have_stream_from support expectations on subscription only"
            end
          end

          def base_message
            no_expected? ? "any stream started" : "stream #{expected_formatted} started, but have #{actual_formatted}"
          end

          def no_expected?
            !defined?(@expected)
          end
        end
      end
    end
  end
end

Version data entries

43 entries across 40 versions & 7 rubygems

Version Path
trusty-cms-7.0.9.1 vendor/bundle/ruby/3.3.0/gems/rspec-rails-7.1.0/lib/rspec/rails/matchers/action_cable/have_streams.rb
trusty-cms-7.0.9.1 vendor/bundle/ruby/3.1.0/gems/rspec-rails-7.1.0/lib/rspec/rails/matchers/action_cable/have_streams.rb
rspec-rails-7.1.0 lib/rspec/rails/matchers/action_cable/have_streams.rb
rspec-rails-7.0.2 lib/rspec/rails/matchers/action_cable/have_streams.rb
rspec-rails-7.0.1 lib/rspec/rails/matchers/action_cable/have_streams.rb
rspec-rails-7.0.0 lib/rspec/rails/matchers/action_cable/have_streams.rb
rspec-rails-6.1.5 lib/rspec/rails/matchers/action_cable/have_streams.rb
rspec-rails-6.1.4 lib/rspec/rails/matchers/action_cable/have_streams.rb
blacklight-spotlight-3.6.0.beta8 vendor/bundle/ruby/3.2.0/gems/rspec-rails-6.1.3/lib/rspec/rails/matchers/action_cable/have_streams.rb
rspec-rails-6.1.3 lib/rspec/rails/matchers/action_cable/have_streams.rb
tinymce-rails-7.1.2 vendor/bundle/ruby/3.3.0/gems/rspec-rails-6.0.4/lib/rspec/rails/matchers/action_cable/have_streams.rb
rspec-rails-6.1.2 lib/rspec/rails/matchers/action_cable/have_streams.rb
rspec-rails-6.1.1 lib/rspec/rails/matchers/action_cable/have_streams.rb
scrapbook-0.3.2 vendor/ruby/2.7.0/gems/rspec-rails-5.1.2/lib/rspec/rails/matchers/action_cable/have_streams.rb
scrapbook-0.3.2 vendor/ruby/2.7.0/gems/rspec-rails-5.1.1/lib/rspec/rails/matchers/action_cable/have_streams.rb
rspec-rails-6.1.0 lib/rspec/rails/matchers/action_cable/have_streams.rb
rspec-rails-6.0.4 lib/rspec/rails/matchers/action_cable/have_streams.rb
scrapbook-0.3.1 vendor/ruby/2.7.0/gems/rspec-rails-5.1.1/lib/rspec/rails/matchers/action_cable/have_streams.rb
scrapbook-0.3.1 vendor/ruby/2.7.0/gems/rspec-rails-5.1.2/lib/rspec/rails/matchers/action_cable/have_streams.rb
rspec-rails-6.0.3 lib/rspec/rails/matchers/action_cable/have_streams.rb