Class: RSpec::Rails::Matchers::ActionCable::HaveBroadcastedTo Private
Relationships & Source Files | |
Super Chains via Extension / Inclusion / Inheritance | |
Class Chain:
|
|
Instance Chain:
|
|
Inherits: |
RSpec::Matchers::BuiltIn::BaseMatcher
|
Defined in: | rspec-rails/lib/rspec/rails/matchers/action_cable/have_broadcasted_to.rb |
Overview
rubocop: disable Metrics/ClassLength
Constant Summary
::RSpec::Matchers::BuiltIn::BaseMatcher
- Inherited
Class Method Summary
- .new(target, channel:) ⇒ HaveBroadcastedTo constructor Internal use only
::RSpec::Matchers::BuiltIn::BaseMatcher
- Inherited
.matcher_name, .new, | |
.underscore | Borrowed from ActiveSupport. |
Instance Attribute Summary
- #supports_block_expectations? ⇒ Boolean readonly Internal use only
::RSpec::Matchers::BuiltIn::BaseMatcher
- Inherited
#actual, | |
#diffable? |
|
#expected, #expects_call_stack_jump?, #matcher_name, #matcher_name=, #rescued_exception, | |
#supports_block_expectations? | Most matchers are value matchers (i.e. meant to work with ‘expect(value)`) rather than block matchers (i.e. meant to work with `expect { }`), so this defaults to false. |
#supports_value_expectations? |
::RSpec::Matchers::BuiltIn::BaseMatcher::StringEncodingFormatting
- Included
#string_encoding_differs? | :nocov: |
Instance Method Summary
- #at_least(count) Internal use only
- #at_most(count) Internal use only
- #description Internal use only
- #exactly(count) Internal use only
- #failure_message Internal use only
- #failure_message_when_negated Internal use only
- #from_channel(channel) Internal use only
- #matches?(proc) ⇒ Boolean Internal use only
- #message_expectation_modifier Internal use only
- #once Internal use only
- #thrice Internal use only
- #times Internal use only
- #twice Internal use only
- #with(data = nil, &block) Internal use only
- #base_description private Internal use only
- #base_message private Internal use only
- #check(messages) private Internal use only
- #check_channel_presence private Internal use only
- #data_description(data) private Internal use only
- #pubsub_adapter private Internal use only
- #set_expected_number(relativity, count) private Internal use only
- #stream private Internal use only
::RSpec::Matchers::BuiltIn::BaseMatcher
- Inherited
#actual_formatted, | |
#description | Generates a description using |
#expected_formatted, | |
#match_unless_raises | Used to wrap a block of code that will indicate failure by raising one of the named exceptions. |
#matches? | Indicates if the match is successful. |
::RSpec::Matchers::BuiltIn::BaseMatcher::DefaultFailureMessages
- Included
#failure_message | Provides a good generic failure message. |
#failure_message_when_negated | Provides a good generic negative failure message. |
::RSpec::Matchers::BuiltIn::BaseMatcher::StringEncodingFormatting
- Included
#format_encoding | Formats a String’s encoding as a human readable string :nocov: |
::RSpec::Matchers::BuiltIn::BaseMatcher::HashFormatting
- Included
#improve_hash_formatting | ‘{ |
::RSpec::Matchers::Composable
- Included
#& | Alias for Matchers::Composable#and. |
#=== | Delegates to #matches?. |
#and | Creates a compound |
#description_of | Returns the description of the given object in a way that is aware of composed matchers. |
#or | Creates a compound |
#values_match? | This provides a generic way to fuzzy-match an expected value against an actual value. |
#| | Alias for Matchers::Composable#or. |
#should_enumerate? | We should enumerate arrays as long as they are not recursive. |
#surface_descriptions_in | Transforms the given data structure (typically a hash or array) into a new data structure that, when |
#unreadable_io?, | |
#with_matchers_cloned | Historically, a single matcher instance was only checked against a single value. |
Instance Attribute Details
#supports_block_expectations? ⇒ Boolean
(readonly)
# File 'rspec-rails/lib/rspec/rails/matchers/action_cable/have_broadcasted_to.rb', line 81
def supports_block_expectations? true end
Instance Method Details
#at_least(count)
[ GitHub ]# File 'rspec-rails/lib/rspec/rails/matchers/action_cable/have_broadcasted_to.rb', line 28
def at_least(count) set_expected_number(:at_least, count) self end
#at_most(count)
[ GitHub ]# File 'rspec-rails/lib/rspec/rails/matchers/action_cable/have_broadcasted_to.rb', line 33
def at_most(count) set_expected_number(:at_most, count) self end
#base_description (private)
[ GitHub ]# File 'rspec-rails/lib/rspec/rails/matchers/action_cable/have_broadcasted_to.rb', line 147
def base_description "#{} #{@expected_number} messages to #{stream}".tap do |msg| msg << " with #{data_description(@data)}" unless @data.nil? end end
#base_message (private)
[ GitHub ]# File 'rspec-rails/lib/rspec/rails/matchers/action_cable/have_broadcasted_to.rb', line 153
def "#{base_description}, but broadcast #{@matching_msgs_count}" end
#check(messages) (private)
[ GitHub ]# File 'rspec-rails/lib/rspec/rails/matchers/action_cable/have_broadcasted_to.rb', line 114
def check( ) @matching_msgs, @unmatching_msgs = .partition do |msg| decoded = ActiveSupport::JSON.decode(msg) decoded = decoded.with_indifferent_access if decoded.is_a?(Hash) if @data.nil? || values_match?(@data, decoded) @block.call(decoded) true else false end end @matching_msgs_count = @matching_msgs.size case @expectation_type when :exactly then @expected_number == @matching_msgs_count when :at_most then @expected_number >= @matching_msgs_count when :at_least then @expected_number <= @matching_msgs_count end end
#check_channel_presence (private)
# File 'rspec-rails/lib/rspec/rails/matchers/action_cable/have_broadcasted_to.rb', line 169
def check_channel_presence return if @channel.present? && @channel.respond_to?(:channel_name) error_msg = "Broadcasting channel can't be inferred. Please, specify it with `from_channel`" raise ArgumentError, error_msg end
#data_description(data) (private)
[ GitHub ]# File 'rspec-rails/lib/rspec/rails/matchers/action_cable/have_broadcasted_to.rb', line 157
def data_description(data) if data.is_a?(RSpec::Matchers::Composable) data.description else data.inspect end end
#description
[ GitHub ]# File 'rspec-rails/lib/rspec/rails/matchers/action_cable/have_broadcasted_to.rb', line 54
def description "have broadcasted #{base_description}" end
#exactly(count)
[ GitHub ]# File 'rspec-rails/lib/rspec/rails/matchers/action_cable/have_broadcasted_to.rb', line 23
def exactly(count) set_expected_number(:exactly, count) self end
#failure_message
[ GitHub ]# File 'rspec-rails/lib/rspec/rails/matchers/action_cable/have_broadcasted_to.rb', line 58
def "expected to broadcast #{}".tap do |msg| if @unmatching_msgs.any? msg << "\nBroadcasted messages to #{stream}:" @unmatching_msgs.each do |data| msg << "\n #{data}" end end end end
#failure_message_when_negated
[ GitHub ]# File 'rspec-rails/lib/rspec/rails/matchers/action_cable/have_broadcasted_to.rb', line 69
def "expected not to broadcast #{}" end
#from_channel(channel)
[ GitHub ]# File 'rspec-rails/lib/rspec/rails/matchers/action_cable/have_broadcasted_to.rb', line 95
def from_channel(channel) @channel = channel self end
#matches?(proc) ⇒ Boolean
# File 'rspec-rails/lib/rspec/rails/matchers/action_cable/have_broadcasted_to.rb', line 85
def matches?(proc) raise ArgumentError, "have_broadcasted_to and broadcast_to only support block expectations" unless Proc === proc = pubsub_adapter.broadcasts(stream).size proc.call = pubsub_adapter.broadcasts(stream).drop( ) check( ) end
#message_expectation_modifier
[ GitHub ]#once
[ GitHub ]# File 'rspec-rails/lib/rspec/rails/matchers/action_cable/have_broadcasted_to.rb', line 42
def once exactly(:once) end
#pubsub_adapter (private)
[ GitHub ]# File 'rspec-rails/lib/rspec/rails/matchers/action_cable/have_broadcasted_to.rb', line 165
def pubsub_adapter ::ActionCable.server.pubsub end
#set_expected_number(relativity, count) (private)
[ GitHub ]#stream (private)
[ GitHub ]# File 'rspec-rails/lib/rspec/rails/matchers/action_cable/have_broadcasted_to.rb', line 102
def stream @stream ||= case @target when String @target when Symbol @target.to_s else check_channel_presence @channel.broadcasting_for(@target) end end
#thrice
[ GitHub ]# File 'rspec-rails/lib/rspec/rails/matchers/action_cable/have_broadcasted_to.rb', line 50
def thrice exactly(:thrice) end
#times
[ GitHub ]# File 'rspec-rails/lib/rspec/rails/matchers/action_cable/have_broadcasted_to.rb', line 38
def times self end
#twice
[ GitHub ]# File 'rspec-rails/lib/rspec/rails/matchers/action_cable/have_broadcasted_to.rb', line 46
def twice exactly(:twice) end
#with(data = nil, &block)
[ GitHub ]# File 'rspec-rails/lib/rspec/rails/matchers/action_cable/have_broadcasted_to.rb', line 16
def with(data = nil, &block) @data = data @data = @data.with_indifferent_access if @data.is_a?(Hash) @block = block if block self end