Class: TurboRspec::Matchers::HaveTurboStream

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

Instance Method Summary collapse

Constructor Details

#initializeHaveTurboStream

Returns a new instance of HaveTurboStream.



8
9
10
11
12
13
14
# File 'lib/turbo_rspec/matchers/have_turbo_stream.rb', line 8

def initialize
  @action = nil
  @target = nil
  @target_all = nil
  @content = nil
  @partial = nil
end

Instance Method Details

#descriptionObject



59
60
61
# File 'lib/turbo_rspec/matchers/have_turbo_stream.rb', line 59

def description
  "have turbo stream#{constraint_description}"
end

#does_not_match?(response_or_body) ⇒ Boolean

Returns:

  • (Boolean)


47
48
49
# File 'lib/turbo_rspec/matchers/have_turbo_stream.rb', line 47

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

#failure_messageObject



51
52
53
# File 'lib/turbo_rspec/matchers/have_turbo_stream.rb', line 51

def failure_message
  "expected response to contain a turbo stream#{constraint_description}\n#{found_streams_message}"
end

#failure_message_when_negatedObject



55
56
57
# File 'lib/turbo_rspec/matchers/have_turbo_stream.rb', line 55

def failure_message_when_negated
  "expected response not to contain a turbo stream#{constraint_description}"
end

#matches?(response_or_body) ⇒ Boolean

Returns:

  • (Boolean)


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

def matches?(response_or_body)
  @body = extract_body(response_or_body)
  @streams = parse_streams(@body)
  @streams.any? { |stream| stream_matches?(stream) }
end

#rendering(partial) ⇒ Object



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

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

#targeting(dom_id) ⇒ Object



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

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

#targeting_all(selector) ⇒ Object



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

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

#with_action(action) ⇒ Object



16
17
18
19
# File 'lib/turbo_rspec/matchers/have_turbo_stream.rb', line 16

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

#with_content(text) ⇒ Object



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

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