When upgrading a project to the Rails 5.2 pre-release we started to see some deprecation warnings in our RSpec runs. The warnings were as follows, and occurred wherever have_http_status(:success) or have_success_status and the like were used in tests.

.DEPRECATION WARNING: The success? predicate is deprecated and will be removed
in Rails 6.0. Please use successful? as provided by Rack::Response::Helpers.
(called from matches? at rspec/rails/matchers/have_http_status.rb:263)

This was annoying because many controller tests use the have_success_status matcher.

What changed

Rails, with this commit decided, in very reasonable fashion, to standardize the response status checking methods in ActionDispatch::TestResponse.

The team simply deprecated the success?, missing? and error? methods with the suggestion to use the successful?, not_found?, and server_error? methods pre-existing in Rack::Response::Helpers. (ActionDispatch::TestResponse inherits from ActionDispatch::Response which includes Rack::Response::Helpers.)

In rspec-rails, the have_http_status matcher called these methods in a meta-sense, by mapping the :success, :missing, and :error symbols to corresponding methods invoked on the response.

How to repair?

One way to repair this would have been to support the replacement methods, e.g. successful? and require any extant tests using, for example, have_http_status(:success) to make the change to have_http_status(:successful).

This would possibly be defensible as a “follow closely as a thin wrapper on Rails” strategy. Unfortunately, it would break a mountain of tests!

However the successful?, server_error?, and not_found? methods have been available to ActionDispatch::TestResponse via Rack::Response::Helpers for many many years.

The method provided introduces the new status codes, :successful, :not_found, and :server_error while maintaining support for the Rails deprecated ones. It does so by mapping, for example, :success to the successful? method.

Thus the world of rspec-rails turns in accordance with the heavens, that is, Rails.