Reputation: 592
We are writing tests to a Rails application and we need to test a controller where we pass a header for almost every request, but not all.
You pass a header setting @request.headers['my-header'] = 'my-header-content'
, but we only want to do this in some tests, not all, so having this line in setup
is not an option, but we consider incorrect to have it repeated 20 or 30 times for every request made.
How could we achieve that?
Upvotes: 0
Views: 304
Reputation: 3847
If you're using rspec
, you can separate them into two different context and then do a before
for that context:
describe MyController do
context 'with specific header' do
before :all do
@request.headers['my-header'] = 'my-header-content'
end
end
context 'other context' do
#Tests without context
end
end
If you're using minitest
you can always separate your tests into classes. Then make one class to the specific header and another one to the other tests.
Upvotes: 1