Class: RuboCop::Cop::RSpecRails::HttpStatus
- Inherits:
-
Base
- Object
- Base
- RuboCop::Cop::RSpecRails::HttpStatus
- Extended by:
- AutoCorrector
- Includes:
- ConfigurableEnforcedStyle
- Defined in:
- lib/rubocop/cop/rspec_rails/http_status.rb
Overview
Enforces use of symbolic or numeric value to describe HTTP status.
This cop inspects only ‘have_http_status` calls. So, this cop does not check if a method starting with `be_*` is used when setting for `EnforcedStyle: symbolic` or `EnforcedStyle: numeric`. This cop is also capable of detecting unknown HTTP status codes.
Defined Under Namespace
Classes: BeStatusStyleChecker, NumericStyleChecker, StyleCheckerBase, SymbolicStyleChecker
Constant Summary collapse
- RESTRICT_ON_SEND =
i[have_http_status].freeze
Instance Method Summary collapse
- #http_status(node) ⇒ Object
-
#on_send(node) ⇒ Object
rubocop:disable Metrics/MethodLength.
Instance Method Details
#http_status(node) ⇒ Object
73 74 75 |
# File 'lib/rubocop/cop/rspec_rails/http_status.rb', line 73 def_node_matcher :http_status, "(send nil? :have_http_status ${int sym str})\n" |
#on_send(node) ⇒ Object
rubocop:disable Metrics/MethodLength
77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 |
# File 'lib/rubocop/cop/rspec_rails/http_status.rb', line 77 def on_send(node) # rubocop:disable Metrics/MethodLength return unless defined?(::Rack::Utils::SYMBOL_TO_STATUS_CODE) http_status(node) do |arg| return if arg.str_type? && arg.heredoc? checker = checker_class.new(arg) return unless checker.offensive? add_offense(checker.offense_range, message: checker.) do |corrector| next unless checker.autocorrectable? corrector.replace(checker.offense_range, checker.prefer) end end end |