class RuboCop::Cop::RSpec::Rails::HttpStatus
Enforces use of symbolic or numeric value to describe HTTP status.
@example `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 }
@example `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 }
Public Instance Methods
autocorrect(node)
click to toggle source
# File lib/rubocop/cop/rspec/rails/http_status.rb, line 49 def autocorrect(node) lambda do |corrector| checker = checker_class.new(node) corrector.replace(node.loc.expression, checker.preferred_style) end end
on_send(node)
click to toggle source
# 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
Private Instance Methods
checker_class()
click to toggle source
# File lib/rubocop/cop/rspec/rails/http_status.rb, line 58 def checker_class case style when :symbolic SymbolicStyleChecker when :numeric NumericStyleChecker end end