Skip to content

Instantly share code, notes, and snippets.

@zben
Created March 4, 2020 18:24
Show Gist options
  • Save zben/bb04d7900114cd84da5027cc33431bb2 to your computer and use it in GitHub Desktop.
Save zben/bb04d7900114cd84da5027cc33431bb2 to your computer and use it in GitHub Desktop.
describe ExampleController, type: :controller do
describe '#show' do
context 'third party API returns 404' do
before do
stub_request(:get, "www.example.com").
to_return(body: {error: "record not found"}.to_json, status: 404)
get :show
end
it 'returns 200' do
expect(response.status).to eq(200)
end
it 'returns correct error message' do
expect(JSON.parse(response.body)).to eq({"error" => "record_not_found"})
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment