Typically in my controller specs I'll do something like this:
describe MyController do
describe 'POST #create' do
let!(:my_model) { initialize_something_here }
before :each do
post :create, my_model: my_model
end
it 'should be successful' do
response.should be_successful
end
... more tests ...
end
end
My question is, when I do assertions that use an expect block such as checking that the count of items in the database is incremented after a create, I have to remove the post call from the before :each block, like this and repeat it for each it statement:
describe MyController do
describe 'POST #create' do
let!(:my_model) { initialize_something_here }
it 'should insert into database' do
expect { post :create, my_model: my_model }.to change(MyModel, :count).by(1)
end
it 'should be successful' do
post :create, my_model: my_model
response.should be_successful
end
... more tests ...
end
end
Is there a DRY-er way to do the post call?