Matt Kolenda
2010-Apr-02 17:16 UTC
[rspec-users] Passing get request parameters in an rspec test
Hello
Please forgive my noobness to rspec. I have a controller method that
inspects the params[:id] object and renders a view that depends on the
existence of that :id.
I want to ensure that the view is rendered in the controller rspec test.
The rspec code is:
describe "GET ''enrollments''" do
it "should be successful" do
get ''enrollments''
response.should be_success
end
end
The ''enrollments'' controller method inspects the params
object, pulls out
the :id and uses it in a few queries to populate a couple of instance
variables.
My question is "How do I pass in the params[:id] parameter to the get
''enrollments'' line?"
Thanks in advance
Matt
-------------- next part --------------
An HTML attachment was scrubbed...
URL:
<http://rubyforge.org/pipermail/rspec-users/attachments/20100402/6da5abf6/attachment.html>
Phillip Koebbe
2010-Apr-02 17:51 UTC
[rspec-users] Passing get request parameters in an rspec test
On 2010-04-02 12:16 PM, Matt Kolenda wrote:> Hello > > Please forgive my noobness to rspec.We''re all noobs at some point in regard to something. No forgiveness necessary. :)> I have a controller method that inspects the params[:id] object and > renders a view that depends on the existence of that :id. > > I want to ensure that the view is rendered in the controller rspec > test. The rspec code is: > > describe "GET ''enrollments''" do > it "should be successful" do > get ''enrollments'' > response.should be_success > end > end > > The ''enrollments'' controller method inspects the params object, pulls > out the :id and uses it in a few queries to populate a couple of > instance variables. > > My question is "How do I pass in the params[:id] parameter to the get > ''enrollments'' line?" >get ''enrollments'', {:id => ''1'') One thing I''ve learned is to pay attention to the data type you use in the params hash when you use get|post|put|delete. The params hash in a real application is filled with strings, so yours should be too.> Thanks in advance > > MattPeace, Phillip
Phillip Koebbe
2010-Apr-02 17:53 UTC
[rspec-users] Passing get request parameters in an rspec test
> get ''enrollments'', {:id => ''1'')And, of course, that should be a curly at the end! get ''enrollments'', {:id => ''1''} Phillip
Matt Kolenda
2010-Apr-07 03:56 UTC
[rspec-users] Passing get request parameters in an rspec test
Phillip - Yes, that worked, thanks a million! Matt On Fri, Apr 2, 2010 at 10:53 AM, Phillip Koebbe <phillipkoebbe at gmail.com>wrote:> > get ''enrollments'', {:id => ''1'') >> > > And, of course, that should be a curly at the end! > > get ''enrollments'', {:id => ''1''} > > > Phillip > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users >-------------- next part -------------- An HTML attachment was scrubbed... URL: <http://rubyforge.org/pipermail/rspec-users/attachments/20100406/fbdbe97f/attachment.html>