class RuboCop::Cop::RSpec::Rails::HttpStatus
it { is_expected.to have_http_status :error }
it { is_expected.to have_http_status :success }
it { is_expected.to be_not_found }
it { is_expected.to be_ok }
# good
it { is_expected.to have_http_status 404 }
it { is_expected.to have_http_status 200 }
it { is_expected.to have_http_status :not_found }
it { is_expected.to have_http_status :ok }
# bad
@example ‘EnforcedStyle: be_status`
it { is_expected.to have_http_status :error }
it { is_expected.to have_http_status :success }
it { is_expected.to have_http_status 404 }
it { is_expected.to have_http_status 200 }
# good
it { is_expected.to have_http_status :not_found }
it { is_expected.to have_http_status :ok }
# bad
@example `EnforcedStyle: numeric`
it { is_expected.to have_http_status :error }
it { is_expected.to have_http_status :success }
it { is_expected.to have_http_status :not_found }
it { is_expected.to have_http_status :ok }
# good
it { is_expected.to have_http_status 404 }
it { is_expected.to have_http_status 200 }
# bad
@example `EnforcedStyle: symbolic` (default)
`EnforcedStyle: numeric`.
when setting for `EnforcedStyle: symbolic` or
So, this cop does not check if a method starting with `be_*` is used
This cop inspects only `have_http_status` calls.
Enforces use of symbolic or numeric value to describe HTTP status.
def checker_class
def checker_class case style when :symbolic SymbolicStyleChecker when :numeric NumericStyleChecker when :be_status BeStatusStyleChecker end end
def on_send(node)
def on_send(node) http_status(node) do |arg| checker = checker_class.new(arg) return unless checker.offensive? add_offense(checker.offense_range, message: checker.message) do |corrector| corrector.replace(checker.offense_range, checker.prefer) end end end