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 }

Constants

RESTRICT_ON_SEND

Public Instance Methods

on_send(node) click to toggle source
# File lib/rubocop/cop/rspec/rails/http_status.rb, line 43
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) do |corrector|
      corrector.replace(checker.node, checker.preferred_style)
    end
  end
end

Private Instance Methods

checker_class() click to toggle source
# File lib/rubocop/cop/rspec/rails/http_status.rb, line 56
def checker_class
  case style
  when :symbolic
    SymbolicStyleChecker
  when :numeric
    NumericStyleChecker
  end
end