Class: RuboCop::Cop::Workit::ComitteeAssertSchemaConfirm

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

Overview

Check for not pass expected response status code to check it against the corresponding schema explicitly.

Examples:

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

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

Constant Summary collapse

MSG =
"Pass expected response status code to check it against the corresponding schema explicitly."
RESTRICT_ON_SEND =
%i[assert_schema_conform assert_response_schema_confirm].freeze

Instance Method Summary collapse

Instance Method Details

#have_http_status(node) ⇒ Object



32
33
34
# File 'lib/rubocop/cop/workit/comittee_assert_schema_confirm.rb', line 32

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

#on_send(node) ⇒ Object



36
37
38
39
40
41
42
43
44
45
# File 'lib/rubocop/cop/workit/comittee_assert_schema_confirm.rb', line 36

def on_send(node)
  return if node.arguments?

  have_http_status(node.parent) do |child_node, value|
    add_offense(node) do |corrector|
      corrector.remove(range_by_whole_lines(child_node.parent.loc.expression, include_final_newline: true))
      corrector.insert_after(node, "(#{value})")
    end
  end
end