Gi guis, I''m using the RSpec testing plugin to make my tests, but I''ve encountered a problem. In my application I''ve different named routes that go to the same controller, so to simulate a session HTTP request I can''t use def do_get get :index end but I would like to put the named url, with something like def do_get get televisions_url end The solution is not working, since the get method put the generated url into the action option, and in this way it doesn''t work. I read here [1] an example which confirm that my idea is correct, but it''s not working on my system. I use Rails 2.1 on a *nix platform. I also looked for the documentation of the method and into the source code, but I wasn''t able to solve the problem :) Thanks in advance for your help. -- Andrea [1] http://weblog.jamisbuck.org/2006/3/9/integration-testing-in-rails-1-1 -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
On Sun, Jun 15, 2008 at 4:39 PM, Andrea Reginato < rails-mailing-list-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org> wrote:> > Gi guis, I''m using the RSpec testing plugin to make my tests, but I''ve > encountered a problem. > In my application I''ve different named routes that go to the same > controller, so to simulate a session HTTP request I can''t use > > def do_get > get :index > end > > but I would like to put the named url, with something like > > def do_get > get televisions_url > end > > The solution is not working, since the get method put the generated url > into the action option, and in this way it doesn''t work. I read here [1] > an example which confirm that my idea is correct, but it''s not working > on my system.Jamis'' article is talking about rails integration testing which is not the same as functional testing. RSpec controller specs use the Rails functional testing framework. The get, post, update, and delete methods in the functional tests/controller specs don''t go through routing, they only call the controller action methods after setting up the environment. Now you say you have multiple routes to your controller, lets say you have a named route map.televisions :controller => "x_controller", :action => :tv_list then you can certainly write def do_get_televisions get :tv_list end The equivalent to Rails integration tests in RSpec are stories with the RailsStory option set. This uses the Rails integration test framework, but it''s quite different from writing RSpec examples. -- Rick DeNatale My blog on Ruby http://talklikeaduck.denhaven2.com/ --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
> Now you say you have multiple routes to your controller, lets say you > have a > named route > > map.televisions :controller => "x_controller", :action => :tv_list > > then you can certainly write > > def do_get_televisions > get :tv_list > end > > The equivalent to Rails integration tests in RSpec are stories with the > RailsStory option set. This uses the Rails integration test framework, > but > it''s quite different from writing RSpec examples. > > -- > Rick DeNatale > > My blog on Ruby > http://talklikeaduck.denhaven2.com/Thanks a lot for the answer. I got the fact that the article I of Jamis wasn''t related to Rspec, but your example is not working with me. I''ll explain with an example. A sample route configuration I''m working with, is similar at this def map.resource_routing(resources) resources.each do |resource| self.send( "resources", resource, :path_prefix => "resources", :controller => "resources") end end map.resource_routing %w(televisions sensors lights) In this way I can dynamicaly generate all the restful routes I need in an easy way. They will looks similar at these /resources/lights /resources/lights/:id ... /resources/televisions /resources/televisions/:id .. In this case if I use the get method, rightly I''ll get back an HTTP call to /resources. def do_get_televisions get :index end I don''t wanna give complexity (if I can of course) just because of making test working. Maybe I''m wrong on the idea that there is under my modeling system, but it works well for me. Thanks again for the help. -- Andrea Reginato -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---