# What is this failure trying to tell me?

**URL:** <https://www.ruby-forum.com/t/what-is-this-failure-trying-to-tell-me/63693>\
**Category:** Rails\
**Created:** [June 17, 2006, 7:09pm UTC](https://www.ruby-forum.com/t/what-is-this-failure-trying-to-tell-me/63693 "2006-06-17T19:09:49Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![charlie](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/d6d6ee/32.png) [@charlie](https://www.ruby-forum.com/u/charlie)\
**Post date:** [June 17, 2006, 7:09pm UTC](https://www.ruby-forum.com/t/what-is-this-failure-trying-to-tell-me/63693/1 "2006-06-17T19:09:49Z")

</div>

Here is my unit test code.

```
post :login, :user=>{ :login => "bob", :password => "test"}
assert_response :redirect
assert_session_has :user
assert_redirected_to :action => 'welcome'

```

Here is the failure I’m getting when I run my tests.

1. Failure:  
test\_login\_required(UserControllerTest)  
[test/functional/user\_controller\_test.rb:122]:  
response is not a redirection to all of the options supplied  
(redirection is \<“[http://test.host/user/welcome](http://test.host/user/welcome)”\>), difference:  
\<{:controller=\>“user”}\>

assert\_redirected\_to :action =\> ‘welcome’ should mean :controller is set  
to the current controller (i.e. user). If I try asserting the following  
it doesn’t work either:

assert\_redirected\_to :controller =\> ‘user’, :action =\> ‘welcome’

WTF! Please help.

Charlie

---

<div class="post-metadata">

**Author:** ![charlie](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/d6d6ee/32.png) [@charlie](https://www.ruby-forum.com/u/charlie)\
**Post date:** [June 17, 2006, 8:10pm UTC](https://www.ruby-forum.com/t/what-is-this-failure-trying-to-tell-me/63693/2 "2006-06-17T20:10:08Z")

</div>

Charlie wrote:

> Here is my unit test code.
> 
> ```
> post :login, :user=>{ :login => "bob", :password => "test"}
> assert_response :redirect
> assert_session_has :user
> assert_redirected_to :action => 'welcome'
> 
> ```
> 
> Here is the failure I’m getting when I run my tests.
> 
> 1. Failure:  
> test\_login\_required(UserControllerTest)  
> [test/functional/user\_controller\_test.rb:122]:  
> response is not a redirection to all of the options supplied  
> (redirection is \<“[http://test.host/user/welcome](http://test.host/user/welcome)”\>), difference:  
> \<{:controller=\>“user”}\>
> 
> assert\_redirected\_to :action =\> ‘welcome’ should mean :controller is set  
> to the current controller (i.e. user). If I try asserting the following  
> it doesn’t work either:
> 
> assert\_redirected\_to :controller =\> ‘user’, :action =\> ‘welcome’
> 
> WTF! Please help.
> 
> Charlie

I remember butting heads with that about a week ago. I think I remember  
it having something to do with differences between calling redirect\_to  
and assert\_redirected\_to with pre-built urls versus hash arguments  
lists, etc. Perhaps trying changing your assertion to  
“assert\_redirected\_to url\_for(:action=\>‘welcome’)”

I think that’s how I fixed it in the past, but its awfully brittle and  
is probably a bug in the assertion code.

---

<div class="post-metadata">

**Author:** ![charlie](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/d6d6ee/32.png) [@charlie](https://www.ruby-forum.com/u/charlie)\
**Post date:** [June 17, 2006, 11:15pm UTC](https://www.ruby-forum.com/t/what-is-this-failure-trying-to-tell-me/63693/3 "2006-06-17T23:15:15Z")

</div>

Eric,

Thanks that worked! I changed my code from

assert\_redirected\_to :action =\> ‘login’

to

assert\_redirected\_to @controller.url\_for( :action =\> ‘login’ )

and it worked.

I found similar brittleness with follow\_redirect method. The functional  
test support is not very robust, breaks often, and fails to work as  
advertised.

Charlie

Eric D. Nielsen wrote:

> Charlie wrote:
> 
> > Here is my unit test code.
> > 
> > ```
> > post :login, :user=>{ :login => "bob", :password => "test"}
> > assert_response :redirect
> > assert_session_has :user
> > assert_redirected_to :action => 'welcome'
> > 
> > ```
> > 
> > Here is the failure I’m getting when I run my tests.
> > 
> > 1. Failure:  
> > test\_login\_required(UserControllerTest)  
> > [test/functional/user\_controller\_test.rb:122]:  
> > response is not a redirection to all of the options supplied  
> > (redirection is \<“[http://test.host/user/welcome](http://test.host/user/welcome)”\>), difference:  
> > \<{:controller=\>“user”}\>
> > 
> > assert\_redirected\_to :action =\> ‘welcome’ should mean :controller is set  
> > to the current controller (i.e. user). If I try asserting the following  
> > it doesn’t work either:
> > 
> > assert\_redirected\_to :controller =\> ‘user’, :action =\> ‘welcome’
> > 
> > WTF! Please help.
> > 
> > Charlie
> 
> I remember butting heads with that about a week ago. I think I remember  
> it having something to do with differences between calling redirect\_to  
> and assert\_redirected\_to with pre-built urls versus hash arguments  
> lists, etc. Perhaps trying changing your assertion to  
> “assert\_redirected\_to url\_for(:action=\>‘welcome’)”
> 
> I think that’s how I fixed it in the past, but its awfully brittle and  
> is probably a bug in the assertion code.

---

<div class="post-metadata">

**Author:** ![charlie](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/d6d6ee/32.png) [@charlie](https://www.ruby-forum.com/u/charlie)\
**Post date:** [June 18, 2006, 12:19am UTC](https://www.ruby-forum.com/t/what-is-this-failure-trying-to-tell-me/63693/4 "2006-06-18T00:19:27Z")

</div>

Charlie wrote:

> Eric,
> 
> Thanks that worked! I changed my code from
> 
> assert\_redirected\_to :action =\> ‘login’
> 
> to
> 
> assert\_redirected\_to @controller.url\_for( :action =\> ‘login’ )
> 
> and it worked.
> 
> Charlie
> 
> Eric D. Nielsen wrote:
> 
> > Charlie wrote:
> > 
> > > Here is my unit test code.
> > > 
> > > ```
> > > post :login, :user=>{ :login => "bob", :password => "test"}
> > > assert_response :redirect
> > > assert_session_has :user
> > > assert_redirected_to :action => 'welcome'
> > > 
> > > ```
> > > 
> > > Here is the failure I’m getting when I run my tests.
> > > 
> > > 1. Failure:  
> > > test\_login\_required(UserControllerTest)  
> > > [test/functional/user\_controller\_test.rb:122]:  
> > > response is not a redirection to all of the options supplied  
> > > (redirection is \<“[http://test.host/user/welcome](http://test.host/user/welcome)”\>), difference:  
> > > \<{:controller=\>“user”}\>
> > > 
> > > assert\_redirected\_to :action =\> ‘welcome’ should mean :controller is set  
> > > to the current controller (i.e. user). If I try asserting the following
> > 
> > I remember butting heads with that about a week ago. I think I remember  
> > it having something to do with differences between calling redirect\_to  
> > and assert\_redirected\_to with pre-built urls versus hash arguments  
> > lists, etc. Perhaps trying changing your assertion to  
> > “assert\_redirected\_to url\_for(:action=\>‘welcome’)”

OK I’ve filled a defect report; I’m trying to work on a patch, but its a  
little bit beyond my comfort level. If anyone is up for a little bit of  
“Remote Pairing” via IM or or something, please let me know.

Eric
