Class: RuboCop::Cop::Sevencop::RSpecDescribeHttpEndpoint

Inherits:
Base
  • Object
show all
Defined in:
lib/rubocop/cop/sevencop/rspec_describe_http_endpoint.rb

Overview

Pass HTTP endpoint identifier (e.g. GET /users) to top-level describe on request-specs.

In request-specs, one should be aware that it is a test type for endpoints at HTTP layer. Therefore it is good practice to put the HTTP method and path in the top-level description and to separate examples groups by each endpoint.

Examples:

# bad
RSpec.describe 'Users'

# good
RSpec.describe 'GET /users'

See Also:

Constant Summary collapse

MSG =
'Pass HTTP endpoint identifier (e.g. `GET /users`) to top-level `describe` on request-specs.'
RESTRICT_ON_SEND =
i[
  describe
].freeze
SUPPORTED_HTTP_METHODS =
%w[
  DELETE
  GET
  HEAD
  PATCH
  POST
  PUT
].freeze
DESCRIPTION_PATTERN =
%r{\A#{::Regexp.union(SUPPORTED_HTTP_METHODS)} /}.freeze

Instance Method Summary collapse

Instance Method Details

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

This method returns an undefined value.

Parameters:

  • node (RuboCop::AST::SendNode)


40
41
42
43
44
# File 'lib/rubocop/cop/sevencop/rspec_describe_http_endpoint.rb', line 40

def on_send(node)
  return unless bad?(node)

  add_offense(node.first_argument)
end