class RuboCop::Cop::RSpec::Rails::HaveHttpStatus


expect(last_response).to have_http_status(200)
expect(response).to have_http_status(200)
# also good
expect(foo_response).to have_http_status(200)
# good
expect(foo_response.status).to be(200)
# bad
@example ResponseMethods: [‘foo_response’]
expect(last_response).to have_http_status(200)
expect(response).to have_http_status(200)
# good
expect(last_response.code).to eq(“200”)
expect(response.status).to be(200)
# bad
@example ResponseMethods: [‘response’, ‘last_response’] (default)
Checks that tests use ‘have_http_status` instead of equality matchers.

def on_send(node) # rubocop:disable Metrics/MethodLength

rubocop:disable Metrics/MethodLength
def on_send(node) # rubocop:disable Metrics/MethodLength
  match_status(node) do
    |response_status, response_method, to, match, status|
    return unless status.to_s.match?(/\A\d+\z/)
    message = format(MSG, response: response_method.method_name,
                          to: to, status: status,
                          bad_code: node.source)
    add_offense(node, message: message) do |corrector|
      corrector.replace(response_status, response_method.method_name)
      corrector.replace(match.loc.selector, 'have_http_status')
      corrector.replace(match.first_argument, status.to_s)
    end
  end
end

def response_methods

def response_methods
  cop_config.fetch('ResponseMethods', [])
end

def response_methods?(name)

def response_methods?(name)
  response_methods.include?(name.to_s)
end