# RSpec HTTP get simulation

**URL:** <https://discuss.rubyonrails.org/t/rspec-http-get-simulation/30661>\
**Category:** rubyonrails-talk\
**Created:** [June 15, 2008, 8:39pm UTC](https://discuss.rubyonrails.org/t/rspec-http-get-simulation/30661 "2008-06-15T20:39:25Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![11175](https://avatars.discourse-cdn.com/v4/letter/1/8edcca/32.png) [@11175](https://discuss.rubyonrails.org/u/11175)\
**Post date:** [June 15, 2008, 8:39pm UTC](https://discuss.rubyonrails.org/t/rspec-http-get-simulation/30661/1 "2008-06-15T20:39:25Z")

</div>

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 &nbsp;&nbsp;get :index end

but I would like to put the named url, with something like

def do\_get &nbsp;&nbsp;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.

---

<div class="post-metadata">

**Author:** ![Rick\_DeNatale](https://avatars.discourse-cdn.com/v4/letter/r/a587f6/32.png) [@Rick\_DeNatale](https://discuss.rubyonrails.org/u/Rick_DeNatale)\
**Post date:** [June 15, 2008, 11:46pm UTC](https://discuss.rubyonrails.org/t/rspec-http-get-simulation/30661/2 "2008-06-15T23:46:30Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![11175](https://avatars.discourse-cdn.com/v4/letter/1/8edcca/32.png) [@11175](https://discuss.rubyonrails.org/u/11175)\
**Post date:** [June 17, 2008, 9:59am UTC](https://discuss.rubyonrails.org/t/rspec-http-get-simulation/30661/3 "2008-06-17T09:59:47Z")

</div>

> Now you say you have multiple routes to your controller, lets say you have a named route
> 
> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;map.televisions :controller =\> "x\_controller", :action =\> :tv\_list
> 
> then you can certainly write
> 
> &nbsp;&nbsp;&nbsp;&nbsp;def do\_get\_televisions &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;get :tv\_list &nbsp;&nbsp;&nbsp;&nbsp;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/](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

&nbsp;&nbsp;def map.resource\_routing(resources) &nbsp;&nbsp;&nbsp;&nbsp;resources.each do |resource| &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;self.send( "resources", resource, :path\_prefix =\> "resources", &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;:controller =\> "resources") &nbsp;&nbsp;&nbsp;&nbsp;end &nbsp;&nbsp;end

&nbsp;&nbsp;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

&nbsp;&nbsp;/resources/lights &nbsp;&nbsp;/resources/lights/:id &nbsp;&nbsp;... &nbsp;&nbsp;/resources/televisions &nbsp;&nbsp;/resources/televisions/:id &nbsp;&nbsp;..

In this case if I use the get method, rightly I'll get back an HTTP call to /resources.

&nbsp;&nbsp;def do\_get\_televisions &nbsp;&nbsp;&nbsp;&nbsp;get :index &nbsp;&nbsp;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.
