Class: RSpec::Rails::Matchers::ActionCable::HaveBroadcastedTo Private

Inherits:
Matchers::BuiltIn::BaseMatcher
  • Object
show all
Defined in:
lib/rspec/rails/matchers/action_cable/have_broadcasted_to.rb

Overview

This class is part of a private API. You should avoid using this class if possible, as it may be removed or be changed in the future.

rubocop: disable Metrics/ClassLength

Instance Method Summary collapse

Constructor Details

#initialize(target, channel:) ⇒ HaveBroadcastedTo

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns a new instance of HaveBroadcastedTo.



10
11
12
13
14
15
# File 'lib/rspec/rails/matchers/action_cable/have_broadcasted_to.rb', line 10

def initialize(target, channel:)
  @target = target
  @channel = channel
  @block = Proc.new {}
  set_expected_number(:exactly, 1)
end

Instance Method Details

#at_least(count) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



29
30
31
32
# File 'lib/rspec/rails/matchers/action_cable/have_broadcasted_to.rb', line 29

def at_least(count)
  set_expected_number(:at_least, count)
  self
end

#at_most(count) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



34
35
36
37
# File 'lib/rspec/rails/matchers/action_cable/have_broadcasted_to.rb', line 34

def at_most(count)
  set_expected_number(:at_most, count)
  self
end

#exactly(count) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



24
25
26
27
# File 'lib/rspec/rails/matchers/action_cable/have_broadcasted_to.rb', line 24

def exactly(count)
  set_expected_number(:exactly, count)
  self
end

#failure_messageObject

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



55
56
57
58
59
60
61
62
63
64
# File 'lib/rspec/rails/matchers/action_cable/have_broadcasted_to.rb', line 55

def failure_message
  "expected to broadcast #{base_message}".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_negatedObject

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



66
67
68
# File 'lib/rspec/rails/matchers/action_cable/have_broadcasted_to.rb', line 66

def failure_message_when_negated
  "expected not to broadcast #{base_message}"
end

#from_channel(channel) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



92
93
94
95
# File 'lib/rspec/rails/matchers/action_cable/have_broadcasted_to.rb', line 92

def from_channel(channel)
  @channel = channel
  self
end

#matches?(proc) ⇒ Boolean

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns:

  • (Boolean)

Raises:

  • (ArgumentError)


82
83
84
85
86
87
88
89
90
# File 'lib/rspec/rails/matchers/action_cable/have_broadcasted_to.rb', line 82

def matches?(proc)
  raise ArgumentError, "have_broadcasted_to and broadcast_to only support block expectations" unless Proc === proc

  original_sent_messages_count = pubsub_adapter.broadcasts(stream).size
  proc.call
  in_block_messages = pubsub_adapter.broadcasts(stream).drop(original_sent_messages_count)

  check(in_block_messages)
end

#message_expectation_modifierObject

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



70
71
72
73
74
75
76
# File 'lib/rspec/rails/matchers/action_cable/have_broadcasted_to.rb', line 70

def message_expectation_modifier
  case @expectation_type
  when :exactly then "exactly"
  when :at_most then "at most"
  when :at_least then "at least"
  end
end

#onceObject

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



43
44
45
# File 'lib/rspec/rails/matchers/action_cable/have_broadcasted_to.rb', line 43

def once
  exactly(:once)
end

#supports_block_expectations?Boolean

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns:

  • (Boolean)


78
79
80
# File 'lib/rspec/rails/matchers/action_cable/have_broadcasted_to.rb', line 78

def supports_block_expectations?
  true
end

#thriceObject

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



51
52
53
# File 'lib/rspec/rails/matchers/action_cable/have_broadcasted_to.rb', line 51

def thrice
  exactly(:thrice)
end

#timesObject

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



39
40
41
# File 'lib/rspec/rails/matchers/action_cable/have_broadcasted_to.rb', line 39

def times
  self
end

#twiceObject

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



47
48
49
# File 'lib/rspec/rails/matchers/action_cable/have_broadcasted_to.rb', line 47

def twice
  exactly(:twice)
end

#with(data = nil) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



17
18
19
20
21
22
# File 'lib/rspec/rails/matchers/action_cable/have_broadcasted_to.rb', line 17

def with(data = nil)
  @data = data
  @data = @data.with_indifferent_access if @data.is_a?(Hash)
  @block = Proc.new if block_given?
  self
end