Class: RuboCop::Cop::Ezcater::RspecRequireHttpStatusMatcher

Inherits:
RuboCop::Cop
  • Object
show all
Defined in:
lib/rubocop/cop/ezcater/rspec_require_http_status_matcher.rb

Overview

Enforce use of HTTP status code matchers rather than asserting on on random numbers.

Examples:


# good
expect(response).to have_http_status :created
expect(response).to have_http_status :bad_request

# bad
expect(response.code).to eq 201
expect(response.code).to eq 400

Constant Summary collapse

MSG =
"Use the `have_http_status` matcher, like `expect(response).to have_http_status :bad_request`, "\
"rather than `%<node_source>s`"

Instance Method Summary collapse

Instance Method Details

#on_send(node) ⇒ Object



29
30
31
32
33
34
35
# File 'lib/rubocop/cop/ezcater/rspec_require_http_status_matcher.rb', line 29

def on_send(node)
  return if !response_status_assertion(node) && !response_code_assertion(node)

  add_offense(node,
              location: :expression,
              message: format(MSG, node_source: node.source))
end