MaurĂcio Linhares
2010-Aug-26 13:12 UTC
[rspec-users] Default format for all requests in a spec
Hi guys, Is there a way to define a default parameter for all requests made in a spec? I have a spec where I want all requests to be made with the "js" format but I find it rather annoying to type a ":format => ''js''" on every get/post/put/delete. Is there any other way to do this? - Maur?cio Linhares http://codeshooter.wordpress.com/ | http://twitter.com/mauriciojr
David Chelimsky
2010-Aug-26 13:16 UTC
[rspec-users] Default format for all requests in a spec
On Aug 26, 2010, at 8:12 AM, Maur?cio Linhares wrote:> Hi guys, > > Is there a way to define a default parameter for all requests made in a spec? > > I have a spec where I want all requests to be made with the "js" > format but I find it rather annoying to type a ":format => ''js''" on > every get/post/put/delete. Is there any other way to do this?Nope. I''d recommend making a feature request in rails for this: https://rails.lighthouseapp.com/projects/8994.
Well, you could setup a default parameter hash:
describe MyController do
let(:params) { {:format => ''js''} }
describe ''#show'' do
it ''...'' do
get :show, params.merge(:id => 1)
end
end
end
You could also take it another level:
describe MyController do
let(:params) { {:format => ''js''} }
describe ''#show'' do
before { params.merge(:id => 1) }
it ''...'' do
get :show, params.merge(:another_param => ''yep'')
end
end
end
On Aug 26, 9:12?am, Maur?cio Linhares <mauricio.linha... at gmail.com>
wrote:> Hi guys,
>
> Is there a way to define a default parameter for all requests made in a
spec?
>
> I have a spec where I want all requests to be made with the "js"
> format but I find it rather annoying to type a ":format =>
''js''" on
> every get/post/put/delete. Is there any other way to do this?
>
> -
> Maur?cio
Linhareshttp://codeshooter.wordpress.com/|http://twitter.com/mauriciojr
> _______________________________________________
> rspec-users mailing list
> rspec-us... at
rubyforge.orghttp://rubyforge.org/mailman/listinfo/rspec-users
Or you could override the #get/post/put/delete methods in your ExampleGroup
describe MyController do
def get(path, params)
super(path, params.merge({:format => ''js''})
end
it ''...'' do
get :show, :id => 1
end
end
On 27 Aug 2010, at 08:00, Justin Ko wrote:
> Well, you could setup a default parameter hash:
>
> describe MyController do
> let(:params) { {:format => ''js''} }
>
> describe ''#show'' do
> it ''...'' do
> get :show, params.merge(:id => 1)
> end
> end
> end
>
> You could also take it another level:
>
> describe MyController do
> let(:params) { {:format => ''js''} }
>
> describe ''#show'' do
> before { params.merge(:id => 1) }
>
> it ''...'' do
> get :show, params.merge(:another_param => ''yep'')
> end
> end
> end
>
> On Aug 26, 9:12 am, Maur?cio Linhares <mauricio.linha... at
gmail.com>
> wrote:
>> Hi guys,
>>
>> Is there a way to define a default parameter for all requests made in a
spec?
>>
>> I have a spec where I want all requests to be made with the
"js"
>> format but I find it rather annoying to type a ":format =>
''js''" on
>> every get/post/put/delete. Is there any other way to do this?
>>
>> -
>> Maur?cio
Linhareshttp://codeshooter.wordpress.com/|http://twitter.com/mauriciojr
>> _______________________________________________
>> rspec-users mailing list
>> rspec-us... at
rubyforge.orghttp://rubyforge.org/mailman/listinfo/rspec-users
> _______________________________________________
> rspec-users mailing list
> rspec-users at rubyforge.org
> http://rubyforge.org/mailman/listinfo/rspec-users
cheers,
Matt
http://blog.mattwynne.net
+44(0)7974 430184