Skip to content

Instantly share code, notes, and snippets.

@marksiemers
Created March 24, 2018 01:23
Show Gist options
  • Save marksiemers/da361eced265e2a2ff50138fa7746d97 to your computer and use it in GitHub Desktop.
Save marksiemers/da361eced265e2a2ff50138fa7746d97 to your computer and use it in GitHub Desktop.
Sample request spec for 404s in RSpec/Rails
describe 'API Request', type: :request do
let!(:request) do
-> { rails_respond_without_detailed_exceptions { get '/bad/path' } }
end
context 'first context, perhaps when a user is signed in' do
before { request.call }
it 'returns http not found (404)' do
expect(response).to have_http_status(:not_found)
end
end
context "second context, perhaps when an admin user is signed in" do
before { request.call }
it 'returns http not found (404)' do
expect(response).to have_http_status(:not_found)
end
end
context "third context, perhaps when no one is signed in" do
before { request.call }
it 'returns http redirect (302)' do
expect(response).to have_http_status(302)
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment