If your controller action looks like this:
respond_to do |format|
format.html { raise \'Unsupported\' }
format.js # index.js.erb
end
and yo
Many of the above answers are outdated.
The correct way to do it in RSpec 3+ is post some_path, xhr: true
.
Deprecation warning straight from RSpec itself, when attempting to use xhr :post, "some_path"
:
DEPRECATION WARNING: `xhr` and `xml_http_request` are deprecated and will be removed in Rails 5.1.
Switch to e.g. `post comments_path, params: { comment: { body: 'Honey bunny' } }, xhr: true`.
Also, xhr :post, "some_path"
results in some funky errors that doesn't happen with post some_path, xhr: true
.