0

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?

4

1 に答える 1

1

with_optionsここでは必要ありませんdefaults。ブロックも受け入れます。

defaults common: '123' do
  get '/test1' => 'test#index1'
  get '/test2' => 'test#index2'
end
于 2012-08-06T12:32:47.630 に答える