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.



13
14
15
16
17
18
# File 'lib/rspec/rails/matchers/action_cable/have_broadcasted_to.rb', line 13

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.



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

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.



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

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.



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

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.



58
59
60
61
62
63
64
65
66
67
# File 'lib/rspec/rails/matchers/action_cable/have_broadcasted_to.rb', line 58

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.



69
70
71
# File 'lib/rspec/rails/matchers/action_cable/have_broadcasted_to.rb', line 69

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.



95
96
97
98
# File 'lib/rspec/rails/matchers/action_cable/have_broadcasted_to.rb', line 95

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)


85
86
87
88
89
90
91
92
93
# File '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

  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.



73
74
75
76
77
78
79
# File 'lib/rspec/rails/matchers/action_cable/have_broadcasted_to.rb', line 73

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.



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

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)


81
82
83
# File 'lib/rspec/rails/matchers/action_cable/have_broadcasted_to.rb', line 81

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.



54
55
56
# File 'lib/rspec/rails/matchers/action_cable/have_broadcasted_to.rb', line 54

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.



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

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.



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

def twice
  exactly(:twice)
end

#with(data = nil, &block) ⇒ 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.



20
21
22
23
24
25
# File 'lib/rspec/rails/matchers/action_cable/have_broadcasted_to.rb', line 20

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