# Request.path\_info doesn't work in tests

**URL:** <https://www.ruby-forum.com/t/request-path-info-doesnt-work-in-tests/139983>\
**Category:** Rails\
**Created:** [June 9, 2008, 8:06pm UTC](https://www.ruby-forum.com/t/request-path-info-doesnt-work-in-tests/139983 "2008-06-09T20:06:46Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![bcm](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/977dab/32.png) [@bcm](https://www.ruby-forum.com/u/bcm)\
**Post date:** [June 9, 2008, 8:06pm UTC](https://www.ruby-forum.com/t/request-path-info-doesnt-work-in-tests/139983/1 "2008-06-09T20:06:46Z")

</div>

Hi all,

I’m having a problem with my tests. In my application.rb, I’ve got the  
following:

before\_filter :record\_current\_page  
def record\_current\_page  
unless request.path\_info == session[:current\_page]  
session[:previous\_page] = session[:current\_page]  
session[:current\_page] = request.path\_info  
end  
@previous\_page = session[:previous\_page] || ‘/’  
end

This always lets me generate a “Back” link for my users that points to  
the previous URL they were looking at, ignoring any  
refreshes/reloads/validation error pages etc. that might be happening.

It works fine, until I test:

def test\_should\_get\_index  
get :index  
assert\_response :success  
end

When I run this test, or any other test on my controller, I get:

test\_should\_get\_new(PersonControllerTest):  
NoMethodError: undefined method `path\_info’ for  
#ActionController::TestRequest:0x1fceb0c

It seems to me that the TestRequest object should have a path\_info  
method, right? If not, how do I code my app to do what I want, but have  
the tests pass? Or, how do I rejigger my tests to get them to pass,  
since I know the behavior of the app is correct?

Any help would be appreciated.

Thanks!

---

<div class="post-metadata">

**Author:** ![bcm](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/977dab/32.png) [@bcm](https://www.ruby-forum.com/u/bcm)\
**Post date:** [June 9, 2008, 8:41pm UTC](https://www.ruby-forum.com/t/request-path-info-doesnt-work-in-tests/139983/2 "2008-06-09T20:41:00Z")

</div>

On 9 Jun 2008, at 19:06, Brent M. wrote:

> have  
> the tests pass? Or, how do I rejigger my tests to get them to pass,  
> since I know the behavior of the app is correct?

well the functional tests operate a layer below routing, so it doesn’t  
actually know what is the current path (although I suppose it could  
make it up).  
This is ruby though, so you could define path\_info as a single method  
on @request or use mocha to stub/expect a call to path\_info.

Fred

---

<div class="post-metadata">

**Author:** ![bcm](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/977dab/32.png) [@bcm](https://www.ruby-forum.com/u/bcm)\
**Post date:** [June 10, 2008, 10:19pm UTC](https://www.ruby-forum.com/t/request-path-info-doesnt-work-in-tests/139983/3 "2008-06-10T22:19:10Z")

</div>

I was afraid it would be something like that. Mocha to the rescue…

Thanks, Fred!
