# RSpec HTTP get simulation

**URL:** <https://www.ruby-forum.com/t/rspec-http-get-simulation/140534>\
**Category:** Rails\
**Created:** [June 15, 2008, 10:39pm UTC](https://www.ruby-forum.com/t/rspec-http-get-simulation/140534 "2008-06-15T22:39:25Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![reis](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/f1d935/32.png) [@reis](https://www.ruby-forum.com/u/reis)\
**Post date:** [June 15, 2008, 10:39pm UTC](https://www.ruby-forum.com/t/rspec-http-get-simulation/140534/1 "2008-06-15T22: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  
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](http://weblog.jamisbuck.org/2006/3/9/integration-testing-in-rails-1-1)

---

<div class="post-metadata">

**Author:** ![reis](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/f1d935/32.png) [@reis](https://www.ruby-forum.com/u/reis)\
**Post date:** [June 16, 2008, 1:47am UTC](https://www.ruby-forum.com/t/rspec-http-get-simulation/140534/2 "2008-06-16T01:47:09Z")

</div>

On Sun, Jun 15, 2008 at 4:39 PM, Andrea R. \<  
removed\_email\_address@domain.invalid\> wrote:

> 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/](http://talklikeaduck.denhaven2.com/)

---

<div class="post-metadata">

**Author:** ![reis](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/f1d935/32.png) [@reis](https://www.ruby-forum.com/u/reis)\
**Post date:** [June 17, 2008, 11:59am UTC](https://www.ruby-forum.com/t/rspec-http-get-simulation/140534/3 "2008-06-17T11:59:47Z")

</div>

> 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/](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 R.
