Hello, I have a rhtml file that goes through the request.params. One of my test generates that file, but rspec pops an error saying : undefined method ''params'' for ... I''m not sure what to do with this, since request.params actually works with rails. Any idea? Thank you Olivier Dupuis -------------- next part -------------- An HTML attachment was scrubbed... URL: http://rubyforge.org/pipermail/rspec-users/attachments/20080411/e61f03cf/attachment.html
Please post spec, code and error message. On Apr 11, 2008, at 3:21 PM, Olivier Dupuis wrote:> Hello, > > I have a rhtml file that goes through the request.params. One of my > test generates that file, but rspec pops an error saying : > > undefined method ''params'' for ... > > I''m not sure what to do with this, since request.params actually > works with rails. > > Any idea? > > Thank you > > Olivier Dupuis > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users
Sorry about that. Here goes... Spec: *describe "/search/index" do it "should have option to login" do render "/search/index" response.should have_text(/Login/) end end* Code for index.rhtml *<body> <div id="container"> <div id="main_footer" align="center"> <%= render_component :controller => "components", :action => "footer", :params => { :lang => @language } %> </div> </div> </body>* Code for footer.rhtml *<% listOfParameters = "" %> <% request.params.each do |param| %> <% if param[0].to_s != "lang" %> <% listOfParameters = listOfParameters + "&" + param[0].to_s + "=" + param[1].to_s %> <% end %> <% end %> ...* Now the error message: *ActionView::TemplateError in ''/search/index should have option to login'' undefined method ''params'' for #<ActionController::TestRequest:0x46a044c> On line #7 of app/views/components/footer.rhtml **6: <% listOfParameters = "" %> 7: <% request.params.each do |param| %> 8: <% if param[0].to_s != "lang" %> 9: <% listOfParameters = listOfParameters + "&" + param[0].to_s + "=" + param[1].to_s %> 10: <% end %> 11: <% end %> *Thanks again Olivier Dupuis On Fri, Apr 11, 2008 at 3:26 PM, David Chelimsky <dchelimsky at gmail.com> wrote:> Please post spec, code and error message. > > On Apr 11, 2008, at 3:21 PM, Olivier Dupuis wrote: > > > Hello, > > > > I have a rhtml file that goes through the request.params. One of my > > test generates that file, but rspec pops an error saying : > > > > undefined method ''params'' for ... > > > > I''m not sure what to do with this, since request.params actually > > works with rails. > > > > Any idea? > > > > Thank you > > > > Olivier Dupuis > > _______________________________________________ > > 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 >-------------- next part -------------- An HTML attachment was scrubbed... URL: http://rubyforge.org/pipermail/rspec-users/attachments/20080411/a109433b/attachment.html
On Apr 11, 2008, at 3:53 PM, Olivier Dupuis wrote:> Sorry about that. Here goes... > > Spec: > > describe "/search/index" do > it "should have option to login" do > render "/search/index" > response.should have_text(/Login/) > end > end > > Code for index.rhtml > > <body> > <div id="container"> > <div id="main_footer" align="center"> > <%= render_component :controller => > "components", :action => "footer", :params => { :lang => @language } > %> > </div> > </div> > </body> > > Code for footer.rhtml > > <% listOfParameters = "" %> > <% request.params.each do |param| %> > <% if param[0].to_s != "lang" %> > <% listOfParameters = listOfParameters + "&" + param[0].to_s > + "=" + param[1].to_s %> > <% end %> > <% end %> > > ... > > Now the error message: > > ActionView::TemplateError in ''/search/index should have option to > login'' > undefined method ''params'' for #<ActionController::TestRequest: > 0x46a044c> > On line #7 of app/views/components/footer.rhtml > > 6: <% listOfParameters = "" %> > 7: <% request.params.each do |param| %>Try just params (not request.params) - does that work?> > 8: <% if param[0].to_s != "lang" %> > 9: <% listOfParameters = listOfParameters + "&" + > param[0].to_s + "=" + param[1].to_s %> > 10: <% end %> > 11: <% end %> > > > Thanks again > > Olivier Dupuis > > > On Fri, Apr 11, 2008 at 3:26 PM, David Chelimsky > <dchelimsky at gmail.com> wrote: > Please post spec, code and error message. > > On Apr 11, 2008, at 3:21 PM, Olivier Dupuis wrote: > > > Hello, > > > > I have a rhtml file that goes through the request.params. One of my > > test generates that file, but rspec pops an error saying : > > > > undefined method ''params'' for ... > > > > I''m not sure what to do with this, since request.params actually > > works with rails. > > > > Any idea? > > > > Thank you > > > > Olivier Dupuis > > _______________________________________________ > > 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 > > _______________________________________________ > 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/20080411/d9bd0c09/attachment-0001.html
It unfortunately access the wrong parameters. Instead of accessing the parameters from my url request, it access the parameters from my render_component. For example, my request is * http://localhost:4000/search/results?author=&keyword=&page=1&publisher=&title=agile * In that results view, I render this component *<%= render_component :controller => "components", :action => "footer", :params => { :lang => @language } %>* So in the footer component, when I execute *<% request.params.each do |param| %>* it goes through the params from * http://localhost:4000/search/results?author=&keyword=&page=1&publisher=&title=agile *But if I execute *<% params.each do |param| %> *it goes through the params from *<%= render_component :controller => "components", :action => "footer", :params => { :lang => @language } %> *My test passes when I use only *params.each* but not when I use * request.params.each *Thanks again Olivier Dupuis On Fri, Apr 11, 2008 at 4:05 PM, David Chelimsky <dchelimsky at gmail.com> wrote:> On Apr 11, 2008, at 3:53 PM, Olivier Dupuis wrote: > > Sorry about that. Here goes... > > Spec: > > *describe "/search/index" do > it "should have option to login" do > render "/search/index" > response.should have_text(/Login/) > end > end* > > Code for index.rhtml > > *<body> > <div id="container"> > <div id="main_footer" align="center"> > <%= render_component :controller => "components", > :action => "footer", :params => { :lang => @language } %> > </div> > </div> > </body>* > > Code for footer.rhtml > > *<% listOfParameters = "" %> > <% request.params.each do |param| %> > <% if param[0].to_s != "lang" %> > <% listOfParameters = listOfParameters + "&" + param[0].to_s + "=" > + param[1].to_s %> > <% end %> > <% end %> > > ...* > > Now the error message: > > *ActionView::TemplateError in ''/search/index should have option to login'' > undefined method ''params'' for #<ActionController::TestRequest:0x46a044c> > On line #7 of app/views/components/footer.rhtml > > **6: <% listOfParameters = "" %> > 7: <% request.params.each do |param| %>* > > > Try just params (not request.params) - does that work? > > * > 8: <% if param[0].to_s != "lang" %> > 9: <% listOfParameters = listOfParameters + "&" + param[0].to_s + > "=" + param[1].to_s %> > 10: <% end %> > 11: <% end %> > > > *Thanks again > > Olivier Dupuis > > > On Fri, Apr 11, 2008 at 3:26 PM, David Chelimsky <dchelimsky at gmail.com> > wrote: > > > Please post spec, code and error message. > > > > On Apr 11, 2008, at 3:21 PM, Olivier Dupuis wrote: > > > > > Hello, > > > > > > I have a rhtml file that goes through the request.params. One of my > > > test generates that file, but rspec pops an error saying : > > > > > > undefined method ''params'' for ... > > > > > > I''m not sure what to do with this, since request.params actually > > > works with rails. > > > > > > Any idea? > > > > > > Thank you > > > > > > Olivier Dupuis > > > _______________________________________________ > > > 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 > > > > _______________________________________________ > 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 >-------------- next part -------------- An HTML attachment was scrubbed... URL: http://rubyforge.org/pipermail/rspec-users/attachments/20080412/b91f9533/attachment.html
Reasonably Related Threads
- Is it still possible to use should_have_rjs
- response.should have_text leads to undefined method `has_text?'
- rspecing rjs - form.reset(''form'')
- spec''ing view render partial collection, local variable not found
- have_text matcher does not support should_not.