Sha256: 8c7f4c422e4e47a008a4e4ffeab4c6eeffa646bf2d3220bd8803cfcdb426c38b

Contents?: true

Size: 1.67 KB

Versions: 44

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

44 entries across 41 versions & 7 rubygems

Version Path
rspec-rails-6.0.3 lib/rspec/rails/matchers/action_cable/have_streams.rb
rspec-rails-6.0.2 lib/rspec/rails/matchers/action_cable/have_streams.rb
rspec-rails-6.0.1 lib/rspec/rails/matchers/action_cable/have_streams.rb
rspec-rails-6.0.0 lib/rspec/rails/matchers/action_cable/have_streams.rb
rspec-rails-5.1.2 lib/rspec/rails/matchers/action_cable/have_streams.rb
rspec-rails-6.0.0.rc1 lib/rspec/rails/matchers/action_cable/have_streams.rb
rspec-rails-5.1.1 lib/rspec/rails/matchers/action_cable/have_streams.rb
rspec-rails-5.1.0 lib/rspec/rails/matchers/action_cable/have_streams.rb
rspec-rails-5.0.3 lib/rspec/rails/matchers/action_cable/have_streams.rb
date_n_time_picker_activeadmin-0.1.2 vendor/bundle/ruby/2.6.0/gems/rspec-rails-5.0.2/lib/rspec/rails/matchers/action_cable/have_streams.rb
date_n_time_picker_activeadmin-0.1.1 vendor/bundle/ruby/2.6.0/gems/rspec-rails-5.0.2/lib/rspec/rails/matchers/action_cable/have_streams.rb
rspec-rails-5.0.2 lib/rspec/rails/matchers/action_cable/have_streams.rb
rails_mini_profiler-0.2.0 vendor/bundle/ruby/3.0.0/gems/rspec-rails-4.1.2/lib/rspec/rails/matchers/action_cable/have_streams.rb
rspec-rails-5.0.1 lib/rspec/rails/matchers/action_cable/have_streams.rb
rspec-rails-4.1.2 lib/rspec/rails/matchers/action_cable/have_streams.rb
rspec-rails-5.0.0 lib/rspec/rails/matchers/action_cable/have_streams.rb
rspec-rails-4.1.1 lib/rspec/rails/matchers/action_cable/have_streams.rb
rspec-rails-4.1.0 lib/rspec/rails/matchers/action_cable/have_streams.rb
rspec-rails-4.0.2 lib/rspec/rails/matchers/action_cable/have_streams.rb
rspec-rails-4.0.1 lib/rspec/rails/matchers/action_cable/have_streams.rb