lib/rubocop/cop/rspec/rails/have_http_status.rb in rubocop-rspec-2.20.0 vs lib/rubocop/cop/rspec/rails/have_http_status.rb in rubocop-rspec-2.21.0
- old
+ new
@@ -16,11 +16,11 @@
#
class HaveHttpStatus < ::RuboCop::Cop::Base
extend AutoCorrector
MSG =
- 'Prefer `expect(response).%<to>s have_http_status(%<status>i)` ' \
+ 'Prefer `expect(response).%<to>s have_http_status(%<status>s)` ' \
'over `%<bad_code>s`.'
RUNNERS = %i[to to_not not_to].to_set
RESTRICT_ON_SEND = RUNNERS
@@ -35,15 +35,17 @@
)
PATTERN
def on_send(node)
match_status(node) do |response_status, to, match, status|
+ return unless status.to_s.match?(/\A\d+\z/)
+
message = format(MSG, to: to, status: status,
bad_code: node.source)
add_offense(node, message: message) do |corrector|
corrector.replace(response_status, 'response')
corrector.replace(match.loc.selector, 'have_http_status')
- corrector.replace(match.first_argument, status.to_i.to_s)
+ corrector.replace(match.first_argument, status.to_s)
end
end
end
end
end