Class: RuboCop::Cop::RSpec::Rails::HttpStatus

Inherits:
Cop
  • Object
show all
Includes:
ConfigurableEnforcedStyle
Defined in:
lib/rubocop/cop/rspec/rails/http_status.rb

Overview

Enforces use of symbolic or numeric value to describe HTTP status.

Examples:

‘EnforcedStyle: symbolic` (default)

# bad
it { is_expected.to have_http_status 200 }
it { is_expected.to have_http_status 404 }

# good
it { is_expected.to have_http_status :ok }
it { is_expected.to have_http_status :not_found }
it { is_expected.to have_http_status :success }
it { is_expected.to have_http_status :error }

‘EnforcedStyle: numeric`

# bad
it { is_expected.to have_http_status :ok }
it { is_expected.to have_http_status :not_found }

# good
it { is_expected.to have_http_status 200 }
it { is_expected.to have_http_status 404 }
it { is_expected.to have_http_status :success }
it { is_expected.to have_http_status :error }

Defined Under Namespace

Classes: NumericStyleChecker, SymbolicStyleChecker

Constant Summary

Constants inherited from Cop

Cop::DEFAULT_CONFIGURATION, Cop::DEFAULT_PATTERN_RE

Constants included from RSpec::Language

RSpec::Language::ALL

Instance Method Summary collapse

Methods inherited from Cop

inherited, #relevant_file?

Instance Method Details

#autocorrect(node) ⇒ Object



48
49
50
51
52
53
# File 'lib/rubocop/cop/rspec/rails/http_status.rb', line 48

def autocorrect(node)
  lambda do |corrector|
    checker = checker_class.new(node)
    corrector.replace(node.loc.expression, checker.preferred_style)
  end
end

#on_send(node) ⇒ Object



40
41
42
43
44
45
46
# File 'lib/rubocop/cop/rspec/rails/http_status.rb', line 40

def on_send(node)
  http_status(node) do |ast_node|
    checker = checker_class.new(ast_node)
    return unless checker.offensive?
    add_offense(checker.node, message: checker.message)
  end
end