I wanted to keep my controller tests DRY, readable, and make writing new tests very simple so that it encourages good practices like one assertion per test (if you have to redo a lot of work over and over, chances are you're just gonna shove more assertions into the same test to avoid the extra work).
Here's the strategy I'm using:
RSpec.describe FireController do
let(:do_request) { post :create, request_body }
let(:request_body) { {} }
describe '#create' do
context 'when we have firewood' do
let(:request_body) { { firewood: true } }
it 'creates fire' do
do_request
expect(response.body).to eql('fire!!!')
end
end
end
end
I would like some opinions on potential downsides to a strategy like this.
do_request
seems like unnecessary indirection. I'd rather readpost :create, request_body
. Other than that this seems fine. I'm unclear what the question is. \$\endgroup\$