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`.
Defined Under Namespace
Classes: BeStatusStyleChecker, NumericStyleChecker, StyleCheckerBase, SymbolicStyleChecker
Constant Summary collapse
- RESTRICT_ON_SEND =
%i[have_http_status].freeze
Instance Method Summary collapse
Instance Method Details
#http_status(node) ⇒ Object
66 67 68 |
# File 'lib/rubocop/cop/rspec_rails/http_status.rb', line 66 def_node_matcher :http_status, <<~PATTERN (send nil? :have_http_status ${int sym str}) PATTERN |
#on_send(node) ⇒ Object
70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 |
# File 'lib/rubocop/cop/rspec_rails/http_status.rb', line 70 def on_send(node) 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| corrector.replace(checker.offense_range, checker.prefer) end end end |