Hi all,

On a basic negative test case, we want to ensure that when we PATCH to the 
wrong URL, we get a 404 error. The test looks like this (slightly modified 
to improve clarity):
    it 'fails if using a bad id' do 
      patch our_endpoint(bad_id), params: form_params, as: :json 
      expect(response).to have_http_status(:not_found) 
    end 

when we run this, we get an exception, ActiveRecord::RecordNotFound

It is thrown by #find not finding anything:
    def update 
      post = Post.find(params[:id]) 
      post.update(description: params[:description]) 
    end 

My question is: if we're doing RSPec testing, shouldn't the default 
configuration be to return a 404 HTTP response instead of a Ruby exception? 
Is my understanding of the paradigm broken? All the examples showing RSpec 
testing API's work fine - return an HTTP response - for a success (200 
response), but if it fails, it throws an exception (and doesn't return an 
HTTP response)

By the way, I know how to correct this: as a workaround, we change the 
configuration in config > environments > test.rb as follows:
    # Raise exceptions instead of rendering exception templates.
    config.action_dispatch.show_exceptions = true

or alternately, we can put that setting in the before method of the RSpec 
file, or in the rails_helper.rb under the spec directory, and again it 
works fine, but why wouldn't that be already set as default, given the 
paradigm I'm assuming of how RSpec is meant to work - that is, as much as 
possible with a outward-facing mentality?

Thanks,

Byron

-- 
You received this message because you are subscribed to the Google Groups 
"rspec" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to rspec+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/rspec/e216b303-0061-4e16-bf17-2f36894b77can%40googlegroups.com.

Reply via email to