Class: RuboCop::Cop::RSpecRails::HttpStatusNameConsistency

Inherits:
Base
  • Object
show all
Extended by:
AutoCorrector
Defined in:
lib/rubocop/cop/rspec_rails/http_status_name_consistency.rb

Overview

Enforces consistency by using the current HTTP status names.

Examples:


# bad
it { is_expected.to have_http_status :unprocessable_entity }

# good
it { is_expected.to have_http_status :unprocessable_content }

Constant Summary collapse

MSG =
'Use `Prefer `:%<preferred>s` over `:%<current>s`.'
RESTRICT_ON_SEND =
i[have_http_status].freeze
PREFERRED_STATUSES =
{
  unprocessable_entity: :unprocessable_content,
  payload_too_large: :content_too_large
}.freeze

Instance Method Summary collapse

Instance Method Details

#http_status(node) ⇒ Object



31
32
33
# File 'lib/rubocop/cop/rspec_rails/http_status_name_consistency.rb', line 31

def_node_matcher :http_status, "(send nil? :have_http_status ${sym})\n"

#on_send(node) ⇒ Object Also known as: on_csend



35
36
37
38
39
# File 'lib/rubocop/cop/rspec_rails/http_status_name_consistency.rb', line 35

def on_send(node)
  http_status(node) do |arg|
    check_status_name_consistency(arg)
  end
end