Skip to content

Instantly share code, notes, and snippets.

@jgaskins
Created April 10, 2012 13:43
Show Gist options
  • Save jgaskins/2351463 to your computer and use it in GitHub Desktop.
Save jgaskins/2351463 to your computer and use it in GitHub Desktop.
Keep your specs from needlessly hitting the database
describe ThingsController do
describe '#create' do
let(:thing_data) { { name: 'Name' } }
it 'creates a new Thing and hits the DB 3x' do
expect { post :create, thing: thing_data }.to change { Thing.count }.by 1
# other response-related expectations here
end
it 'creates a new Thing and hits the DB once' do
post :create, thing: thing_data
assigns(:thing).should be_persisted
# other response-related expectations here
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment