shared examples share the let
scope let
scope, so you could further dry up your code (assuming you use do_action
for every action) to this:
shared_examples :empty_success_response do
before do
do_action
end
...
end
Also, if you are using do_action, I also like to add to my scopes:
describe '#destroy' do
let(:do_action) do
delete :destroy, id: subject.id.to_s
end
after do
do_action
end
...
end
This way, you don't have to call do_action
if all you do in the test is set expectations.
it 'makes the call' do
expect(controller).to receive(:destroy_item).once.times.with(subject.id.to_s)
end
If in some tests you want do_action
to run before the end of the test - that's no problem, since let
runs the code only once - so it won't run again at the end of that specific test!
shared examples share the let
scope, so you could further dry up your code (assuming you use do_action
for every action) to this:
shared_examples :empty_success_response do
before do
do_action
end
...
end
Also, if you are using do_action, I also like to add to my scopes:
describe '#destroy' do
let(:do_action) do
delete :destroy, id: subject.id.to_s
end
after do
do_action
end
...
end
This way, you don't have to call do_action
if all you do in the test is set expectations.
it 'makes the call' do
expect(controller).to receive(:destroy_item).once.times.with(subject.id.to_s)
end
If in some tests you want do_action
to run before the end of the test - that's no problem, since let
runs the code only once - so it won't run again at the end of that specific test!
shared examples share the let
scope, so you could further dry up your code (assuming you use do_action
for every action) to this:
shared_examples :empty_success_response do
before do
do_action
end
...
end
Also, if you are using do_action, I also like to add to my scopes:
describe '#destroy' do
let(:do_action) do
delete :destroy, id: subject.id.to_s
end
after do
do_action
end
...
end
This way, you don't have to call do_action
if all you do in the test is set expectations.
it 'makes the call' do
expect(controller).to receive(:destroy_item).once.times.with(subject.id.to_s)
end
If in some tests you want do_action
to run before the end of the test - that's no problem, since let
runs the code only once - so it won't run again at the end of that specific test!
shared examples share the let
scope, so you could further dry up your code (assuming you use do_action
for every action) to this:
shared_examples :empty_success_response do
before do
do_action
end
...
end
Also, if you are using do_action, I also like to add to my scopes:
describe '#destroy' do
let(:do_action) do
delete :destroy, id: subject.id.to_s
end
after do
do_action
end
...
end
This way, you don't have to call do_action
if all you do in the test is set expectations.
it 'makes the call' do
expect(controller).to receive(:destroy_item).once.times.with(subject.id.to_s)
end
If in some tests you want do_action
to run before the end of the test - that's no problem, since let
runs the code only once - so it won't run again at the end of that specific test!