Class: TurboRspec::Matchers::HaveBroadcastedTurboStreamTo

Inherits:
Object
  • Object
show all
Defined in:
lib/turbo_rspec/matchers/have_broadcasted_turbo_stream_to.rb

Instance Method Summary collapse

Constructor Details

#initialize(stream_or_object) ⇒ HaveBroadcastedTurboStreamTo

Returns a new instance of HaveBroadcastedTurboStreamTo.



8
9
10
11
12
13
14
15
16
17
# File 'lib/turbo_rspec/matchers/have_broadcasted_turbo_stream_to.rb', line 8

def initialize(stream_or_object)
  @stream_or_object = stream_or_object
  @action = nil
  @target = nil
  @target_all = nil
  @content = nil
  @partial = nil
  @expected_count = nil
  @count_type = :at_least
end

Instance Method Details

#at_least(n) ⇒ Object



62
63
64
65
66
# File 'lib/turbo_rspec/matchers/have_broadcasted_turbo_stream_to.rb', line 62

def at_least(n)
  @expected_count = n
  @count_type = :at_least
  self
end

#at_most(n) ⇒ Object



68
69
70
71
72
# File 'lib/turbo_rspec/matchers/have_broadcasted_turbo_stream_to.rb', line 68

def at_most(n)
  @expected_count = n
  @count_type = :at_most
  self
end

#descriptionObject



101
102
103
# File 'lib/turbo_rspec/matchers/have_broadcasted_turbo_stream_to.rb', line 101

def description
  "broadcast a turbo stream to #{stream_name.inspect}#{constraint_description}"
end

#does_not_match?(block) ⇒ Boolean

Returns:

  • (Boolean)


89
90
91
# File 'lib/turbo_rspec/matchers/have_broadcasted_turbo_stream_to.rb', line 89

def does_not_match?(block)
  !matches?(block)
end

#exactly(n) ⇒ Object



56
57
58
59
60
# File 'lib/turbo_rspec/matchers/have_broadcasted_turbo_stream_to.rb', line 56

def exactly(n)
  @expected_count = n
  @count_type = :exactly
  self
end

#failure_messageObject



93
94
95
# File 'lib/turbo_rspec/matchers/have_broadcasted_turbo_stream_to.rb', line 93

def failure_message
  "expected block to broadcast a turbo stream to #{stream_name.inspect}#{constraint_description}#{count_description}\n#{found_message}"
end

#failure_message_when_negatedObject



97
98
99
# File 'lib/turbo_rspec/matchers/have_broadcasted_turbo_stream_to.rb', line 97

def failure_message_when_negated
  "expected block not to broadcast a turbo stream to #{stream_name.inspect}#{constraint_description}"
end

#matches?(block) ⇒ Boolean

Returns:

  • (Boolean)


82
83
84
85
86
87
# File 'lib/turbo_rspec/matchers/have_broadcasted_turbo_stream_to.rb', line 82

def matches?(block)
  before = snapshot
  block.call
  @matching = (snapshot - before).select { |msg| message_matches?(msg) }
  count_matches?(@matching.size)
end

#onceObject

Count qualifiers



48
49
50
# File 'lib/turbo_rspec/matchers/have_broadcasted_turbo_stream_to.rb', line 48

def once
  exactly(1)
end

#rendering(partial) ⇒ Object



41
42
43
44
# File 'lib/turbo_rspec/matchers/have_broadcasted_turbo_stream_to.rb', line 41

def rendering(partial)
  @partial = partial.to_s
  self
end

#supports_block_expectations?Boolean

Returns:

  • (Boolean)


78
79
80
# File 'lib/turbo_rspec/matchers/have_broadcasted_turbo_stream_to.rb', line 78

def supports_block_expectations?
  true
end

#targeting(dom_id) ⇒ Object



26
27
28
29
# File 'lib/turbo_rspec/matchers/have_broadcasted_turbo_stream_to.rb', line 26

def targeting(dom_id)
  @target = dom_id.to_s
  self
end

#targeting_all(selector) ⇒ Object



31
32
33
34
# File 'lib/turbo_rspec/matchers/have_broadcasted_turbo_stream_to.rb', line 31

def targeting_all(selector)
  @target_all = selector.to_s
  self
end

#timesObject



74
75
76
# File 'lib/turbo_rspec/matchers/have_broadcasted_turbo_stream_to.rb', line 74

def times
  self
end

#twiceObject



52
53
54
# File 'lib/turbo_rspec/matchers/have_broadcasted_turbo_stream_to.rb', line 52

def twice
  exactly(2)
end

#with_action(action) ⇒ Object

Stream constraints (mirrors HaveTurboStream)



21
22
23
24
# File 'lib/turbo_rspec/matchers/have_broadcasted_turbo_stream_to.rb', line 21

def with_action(action)
  @action = action.to_s
  self
end

#with_content(text) ⇒ Object



36
37
38
39
# File 'lib/turbo_rspec/matchers/have_broadcasted_turbo_stream_to.rb', line 36

def with_content(text)
  @content = text.to_s
  self
end