Class: RuboCop::Cop::Committee::UnspecifiedExpectedStatus

Inherits:
Base
  • Object
show all
Extended by:
AutoCorrector
Includes:
RangeHelp
Defined in:
lib/rubocop/cop/committee/unspecified_expected_status.rb

Overview

Check if the status code is specified as an argument to the method of the Committee where the expected response status code is required.

Examples:

# bad
it 'something' do
  subject
  expect(response).to have_http_status 400
  assert_schema_conform
end

# good
it 'something' do
  subject
  assert_schema_conform(400)
end

Constant Summary collapse

MSG =
"Specify the HTTP status code of the expected response as an argument."
RESTRICT_ON_SEND =
%i[assert_schema_conform assert_response_schema_confirm].freeze

Instance Method Summary collapse

Instance Method Details

#have_http_status(node) ⇒ Object



31
32
33
# File 'lib/rubocop/cop/committee/unspecified_expected_status.rb', line 31

def_node_search :have_http_status, <<~PATTERN
  (send nil? :have_http_status (:int $_))
PATTERN

#on_send(node) ⇒ Object



35
36
37
38
39
40
41
42
43
# File 'lib/rubocop/cop/committee/unspecified_expected_status.rb', line 35

def on_send(node)
  return if node.arguments?

  have_http_status(node.parent) do |status|
    return autocorrect(node, status)
  end

  add_offense(node)
end