[LRUG] Expected response to be a <:redirect>, but was <200> when using should_redirect_to

Murray Steele murray.steele at gmail.com
Wed Jul 28 03:43:13 PDT 2010


Urrr.  My fault, I should have looked at the code itself rather than simply
caring about the scoping.

    should "delete :destroy participations" do
>       app = ApplicationController.new
>       puts app.response.body
>       assert_difference('Participation.count', -1) do
>         delete :destroy, :id => @p.to_param
>       end
>     end
>
Probably needs to be closer to:

    should "delete :destroy participations" do
>       assert_difference('Participation.count', -1) do
>         delete :destroy, :id => @p.to_param
>
        puts response.body
>
      end
>
    end
>

I think you should be able to refer to just response instead of @response,
but I could be wrong, so try both.

Matthew's (Rudy Jacobs) advice is good though, install the ruby-debug gem
and stick a breakpoint in there, instead of the puts line.  That will drop
you into an irb session (if it's not an irb session by default, just type
irb at the debugger prompt when you drop into it) in the middle of your test
and you can see what variables are available and what they contain much more
easily than littering puts statements around.

I'm sorry this is taking so much effort to work out.  It really shouldn't be
this hard, I'm sure it's something simple and obvious, but we just can't
quite put our finger on it.  The fact that it works outside of the tests is
a good sign that it's something in the testing stack.  It be worth checking
if there are any known bugs with your version of shoulda, and to upgrade if
there's a fix, or downgrade if they know when the bug was introduced.

Hope some of this helps,

Murray

On 27 July 2010 18:02, Matthew Krom <matthew.krom at gmail.com> wrote:

> Hi all  (I replied off-list and Riccardo replied directly to me, but I
> believe Riccardo's intention was to email the whole list, so I am
> forwarding).
>
> Riccardo, are you using Rails 2.3.6, .7, or .8?  Try it with 2.3.5.  (I've
> stayed on 2.3.5 because I saw redirects not happening correctly in the newer
> versions).
>
> Matt
>
>
> On Tue, Jul 27, 2010 at 11:49 AM, Riccardo Tacconi <rtacconi at gmail.com>wrote:
>
>> Thanks to all,
>>
>> I cleaned the code and used @response and I get the out put:
>>
>> <html><body>You are being <a href="
>> http://test.host/configurations/25/edit">redirected</a>.</body></html>
>>
>> So the response is 200 insted of redirecting to
>> http://test.host/configurations/25/edit with a 302 status. The strange
>> thing is that without Shoulda I get a 302.
>>
>> On 27 July 2010 16:36, Matthew Krom <matthew.krom at gmail.com> wrote:
>>
>>> Try response instead of @response (no @ )
>>>
>>> (off list, because I have not taken the time to read the whole thread)
>>>
>>> Matthew Krom, principal
>>> MW Krom LLC
>>> Cambridge, MA
>>> +1 617 852 5130
>>>
>>> On Jul 27, 2010, at 11:33 AM, Riccardo Tacconi <rtacconi at gmail.com>
>>> wrote:
>>>
>>> Yes,
>>>
>>> That is the order I use. But @response is still nil. I implemented the
>>> same test inside a standard Unit::Test and it worked without any error.
>>>
>>> On 27 July 2010 15:25, Mr Jaba < <the.jaba at gmail.com>the.jaba at gmail.com>wrote:
>>>
>>>> So it should look something like:
>>>>
>>>> <http://gist.github.com/492284>http://gist.github.com/492284
>>>>
>>>>
>>>> On 27 July 2010 15:22, Riccardo Tacconi < <rtacconi at gmail.com>
>>>> rtacconi at gmail.com> wrote:
>>>>
>>>>> I already tried that and I get
>>>>>
>>>>> NoMethodError: undefined method `body' for nil:NilClass
>>>>>
>>>>> Two days trying to solve this :-(
>>>>>
>>>>>
>>>>> On 27 July 2010 14:58, Mr Jaba < <the.jaba at gmail.com>
>>>>> the.jaba at gmail.com> wrote:
>>>>>
>>>>>> Tim has hit the nail on the head there, there will be no response.body
>>>>>> either @response or app.response until you have made the request (the delete
>>>>>> line).
>>>>>> Move the put down after the delete and try again.
>>>>>>
>>>>>>
>>>>>>
>>>>>> On 27 July 2010 14:56, Tim Cowlishaw < <tim at timcowlishaw.co.uk>
>>>>>> tim at timcowlishaw.co.uk> wrote:
>>>>>>
>>>>>>>
>>>>>>> On 27 Jul 2010, at 14:43, Riccardo Tacconi wrote:
>>>>>>>
>>>>>>> On 27 July 2010 13:21, Murray Steele < <murray.steele at gmail.com>
>>>>>>> murray.steele at gmail.com> wrote:
>>>>>>>
>>>>>>>>     should "delete :destroy participations" do
>>>>>>>>        app = ApplicationController.new
>>>>>>>>       puts app.response.body
>>>>>>>>       assert_difference('Participation.count', -1) do
>>>>>>>>         delete :destroy, :id => @p.to_param
>>>>>>>>       end
>>>>>>>>     end
>>>>>>>>
>>>>>>>>
>>>>>>> *Ok, but it does not print anything*
>>>>>>>
>>>>>>>
>>>>>>>
>>>>>>> To caveat, I'm not massively familiar with either Test::Unit or
>>>>>>> Shoulda, but I can't quite see what this ApplicationController instance
>>>>>>> you're creating has to do with the request that your test is making. if you
>>>>>>> look in the testing guide: <http://guides.rubyonrails.org/testing.html#functional-tests-for-your-controllers>
>>>>>>> http://guides.rubyonrails.org/testing.html#functional-tests-for-your-controllers,
>>>>>>> you'll see that the request methods (like delete in your code) populate an
>>>>>>> instance variable called @response with the response of the request. try
>>>>>>> inspecting the body of this object in order to see what the response of your
>>>>>>> request was.
>>>>>>>
>>>>>>> Cheers,
>>>>>>>
>>>>>>> Tim
>>>>>>>
>>>>>>>
>>>>>>>
>>>>>>> _______________________________________________
>>>>>>> Chat mailing list
>>>>>>>  <Chat at lists.lrug.org>Chat at lists.lrug.org
>>>>>>>  <http://lists.lrug.org/listinfo.cgi/chat-lrug.org>
>>>>>>> http://lists.lrug.org/listinfo.cgi/chat-lrug.org
>>>>>>>
>>>>>>>
>>>>>>
>>>>>> _______________________________________________
>>>>>> Chat mailing list
>>>>>>  <Chat at lists.lrug.org>Chat at lists.lrug.org
>>>>>>  <http://lists.lrug.org/listinfo.cgi/chat-lrug.org>
>>>>>> http://lists.lrug.org/listinfo.cgi/chat-lrug.org
>>>>>>
>>>>>>
>>>>>
>>>>>
>>>>> --
>>>>> Riccardo Tacconi
>>>>> Web developer at Wolseley UK
>>>>>
>>>>> <http://www.linkedin.com/in/riccardotacconi>
>>>>> http://www.linkedin.com/in/riccardotacconi
>>>>>  <http://riccardotacconi.blogspot.com/>
>>>>> http://riccardotacconi.blogspot.com/
>>>>>  <http://twitter.com/rtacconi>http://twitter.com/rtacconi
>>>>> Linux user: #400461
>>>>>
>>>>> _______________________________________________
>>>>> Chat mailing list
>>>>>  <Chat at lists.lrug.org>Chat at lists.lrug.org
>>>>>  <http://lists.lrug.org/listinfo.cgi/chat-lrug.org>
>>>>> http://lists.lrug.org/listinfo.cgi/chat-lrug.org
>>>>>
>>>>>
>>>>
>>>> _______________________________________________
>>>> Chat mailing list
>>>>  <Chat at lists.lrug.org>Chat at lists.lrug.org
>>>>  <http://lists.lrug.org/listinfo.cgi/chat-lrug.org>
>>>> http://lists.lrug.org/listinfo.cgi/chat-lrug.org
>>>>
>>>>
>>>
>>>
>>> --
>>> Riccardo Tacconi
>>> Web developer at Wolseley UK
>>>
>>> <http://www.linkedin.com/in/riccardotacconi>
>>> http://www.linkedin.com/in/riccardotacconi
>>>  <http://riccardotacconi.blogspot.com/>
>>> http://riccardotacconi.blogspot.com/
>>>  <http://twitter.com/rtacconi>http://twitter.com/rtacconi
>>> Linux user: #400461
>>>
>>> _______________________________________________
>>> Chat mailing list
>>> Chat at lists.lrug.org
>>> http://lists.lrug.org/listinfo.cgi/chat-lrug.org
>>>
>>>
>>
>>
>> --
>> Riccardo Tacconi
>> Web developer at Wolseley UK
>>
>> http://www.linkedin.com/in/riccardotacconi
>> http://riccardotacconi.blogspot.com/
>> http://twitter.com/rtacconi
>> Linux user: #400461
>>
>
>
>
> --
> matthew.krom at gmail.com
> MW Krom LLC
> Cambridge, MA
> 617 852 5130
>
> _______________________________________________
> Chat mailing list
> Chat at lists.lrug.org
> http://lists.lrug.org/listinfo.cgi/chat-lrug.org
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.lrug.org/pipermail/chat-lrug.org/attachments/20100728/e295267b/attachment.html>


More information about the Chat mailing list