I have several routes like these:
get '/test1' => 'test#index1', defaults: {common: '123'}
get '/test2' => 'test#index2', defaults: {common: '123'}
And specs for them like these:
specify do
get('/test1').should route_to controller: 'test', action: 'index1', common: '123'
end
specify do
get('/test2').should route_to controller: 'test', action: 'index2', common: '123'
end
How to DRY up the usage of defaults?
I've tried using with_options
like this:
with_options defaults: {common: '123'} do |o|
o.get '/test1' => 'test#index1'
o.get '/test2' => 'test#index2'
end
But it breaks the first test with message:
Failure/Error: get('/test1').should route_to controller: 'test', action: 'index1', common: '123'
The recognized options <{"common"=>"123", "controller"=>"test", "action"=>"index2"}> did not match <{"controller"=>"test", "action"=>"index1", "common"=>"123"}>, difference: <{"action"=>"index1"}>.
<{"controller"=>"test", "action"=>"index1", "common"=>"123"}> expected but was
<{"common"=>"123", "controller"=>"test", "action"=>"index2"}>.
Am I doing something wrong? Or is there another way?