# Redirect\_to() says "undefined local variable or method \`request'"

**URL:** <https://www.ruby-forum.com/t/redirect-to-says-undefined-local-variable-or-method-request/145266>\
**Category:** Rails\
**Created:** [August 7, 2008, 10:56am UTC](https://www.ruby-forum.com/t/redirect-to-says-undefined-local-variable-or-method-request/145266 "2008-08-07T10:56:03Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![snitko](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/c0e974/32.png) [@snitko](https://www.ruby-forum.com/u/snitko)\
**Post date:** [August 7, 2008, 10:56am UTC](https://www.ruby-forum.com/t/redirect-to-says-undefined-local-variable-or-method-request/145266/1 "2008-08-07T10:56:03Z")

</div>

I’ve been doing my plugin and testing it with rspec. Let me show the  
spec code first: [http://pastie.org/249050](http://pastie.org/249050)

So, this spec lies in vendor/plugins/myplugin/spec/lib  
The reason I set @controller, @request and @response in before(:all)  
is because rspec complains they are not set (probably because I run  
this test from plugin dir). Anyway, the error pops up on str 21, when  
it tries to execute redirect\_to(): undefined local variable or method  
`request’. I’ve checked redirect\_to source and I have no idea how to  
pass it the ‘request’ variable.

Probably, the whole thing happens because I forgot to require/include  
something (that’s why I have to set @controllers and others manually).  
I wish it could just work as when it’s run from RAILS\_ROOT/spec.

Any help or ideas, please?

---

<div class="post-metadata">

**Author:** ![snitko](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/c0e974/32.png) [@snitko](https://www.ruby-forum.com/u/snitko)\
**Post date:** [August 7, 2008, 11:01am UTC](https://www.ruby-forum.com/t/redirect-to-says-undefined-local-variable-or-method-request/145266/2 "2008-08-07T11:01:55Z")

</div>

Being more specific, the error message is:  
undefined local variable or method `request’ for  
#\<Spec::Rails::Example::RailsExampleGroup::Subclass\_1:0x7f9d7ffc98f0

It both appears if I run ‘spec spec/lib’ from plugin folder or rake  
task ‘rake spec:plugins:myplugin’

---

<div class="post-metadata">

**Author:** ![snitko](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/c0e974/32.png) [@snitko](https://www.ruby-forum.com/u/snitko)\
**Post date:** [August 7, 2008, 2:25pm UTC](https://www.ruby-forum.com/t/redirect-to-says-undefined-local-variable-or-method-request/145266/3 "2008-08-07T14:25:52Z")

</div>

Okay, solution found: never put specs that test controllers anywhere  
but in ‘spec/controllers’ dir. Unless you know how to include  
everything it needs to work.
