Francis Hwang
2008-Jul-09 22:36 UTC
[rspec-users] setting request.raw_post with rspec-rails
... is there a way to do this? We have some REST-ish POSTs we''d like to spec out. In the controller this gets accessed with request.raw_post.to_s, is there a way to set this with rspec? Thanks as always, Francis
David Chelimsky
2008-Jul-10 01:53 UTC
[rspec-users] setting request.raw_post with rspec-rails
On Jul 9, 2008, at 5:36 PM, Francis Hwang wrote:> ... is there a way to do this? We have some REST-ish POSTs we''d like > to spec out. In the controller this gets accessed with > request.raw_post.to_s, is there a way to set this with rspec?If you mean you want to set it in an example before the post, you can do this: request.stub!(:raw_post).and_return(''this string'') post :whatever Or, if you want to be really detailed about it (I wouldn''t, but it''s up to you), you could say: raw_post = mock(''raw_post'') raw_post.should_receive(:to_s).and_return(''this string'') request.stub!(:raw_post).and_return(:raw_post) etc That what you''re looking for? Cheers, David> > > Thanks as always, > Francis > > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users
Francis Hwang
2008-Jul-11 02:43 UTC
[rspec-users] setting request.raw_post with rspec-rails
Yup, that''s exactly what I needed -- thanks, Francis Hwang http://fhwang.net/ On Jul 9, 2008, at 9:53 PM, David Chelimsky wrote:> On Jul 9, 2008, at 5:36 PM, Francis Hwang wrote: > >> ... is there a way to do this? We have some REST-ish POSTs we''d >> like to spec out. In the controller this gets accessed with >> request.raw_post.to_s, is there a way to set this with rspec? > > If you mean you want to set it in an example before the post, you > can do this: > > request.stub!(:raw_post).and_return(''this string'') > post :whatever > > Or, if you want to be really detailed about it (I wouldn''t, but it''s > up to you), you could say: > > raw_post = mock(''raw_post'') > raw_post.should_receive(:to_s).and_return(''this string'') > request.stub!(:raw_post).and_return(:raw_post) > > etc > > That what you''re looking for? > > Cheers, > David > > >> >> >> Thanks as always, >> Francis >> >> _______________________________________________ >> rspec-users mailing list >> rspec-users at rubyforge.org >> http://rubyforge.org/mailman/listinfo/rspec-users > > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users