Class: RuboCop::Cop::TurboRspec::UseHaveTurboStream

Inherits:
Base
  • Object
show all
Defined in:
lib/rubocop/cop/turbo_rspec/use_have_turbo_stream.rb

Overview

Flags request specs that assert turbo stream content by matching against response.body as a raw string. Use have_turbo_stream instead.

Examples:

Bad — string matching on response.body

expect(response.body).to include("<turbo-stream")
expect(response.body).to match(/turbo-stream/)

Good

expect(response).to have_turbo_stream
expect(response).to have_turbo_stream.with_action(:append).targeting("list")

Constant Summary collapse

MSG =
"Use `expect(response).to have_turbo_stream` instead of " \
"asserting on `response.body` directly."
RESTRICT_ON_SEND =
%i[to not_to].freeze

Instance Method Summary collapse

Instance Method Details

#on_send(node) ⇒ Object



31
32
33
34
35
36
# File 'lib/rubocop/cop/turbo_rspec/use_have_turbo_stream.rb', line 31

def on_send(node)
  return unless response_body_expectation?(node)
  return unless turbo_stream_related?(node)

  add_offense(node)
end