If your controller action looks like this:
respond_to do |format|
format.html { raise \'Unsupported\' }
format.js # index.js.erb
end
and yo
RSpec 3.7 and Rails 5.x solution:
A few of these answers were a little outdated in my case so I decided to provide an answer for those running Rails 5 and RSpec 3.7:
it "should render js" do
get :index, xhr: true
expect(response.content_type).to eq('text/javascript')
end
Very similar to Steve's answer with a few adjustments. The first being xhr
is passed as a boolean key/pair. Second is I now use expect
due to should
receiving deprecation warnings if used. Comparing the content_type
of the response to be equal to text/javascript
worked for me.