RSpec HTTP get simulation

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 :slight_smile:

Thanks in advance for your help.

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.

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.