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

Riccardo Tacconi rtacconi at gmail.com
Tue Jul 27 06:43:21 PDT 2010


On 27 July 2010 13:21, Murray Steele <murray.steele at gmail.com> wrote:

> On 27 July 2010 10:17, Riccardo Tacconi <rtacconi at gmail.com> wrote:
>
>> I do not get any output with this code
>>
>>
>>   context "should destroy participation" do
>>     setup do
>>       @configuration = Factory.create :configuration, :status => 'LIVE'
>>       @p = Factory.create :participation, :configuration => @configuration
>>       @admin = Factory.create :participant, :admin => true
>>       login_as @admin
>>     end
>>
>>     should "delete :destroy participations" do
>>       assert_difference('Participation.count', -1) do
>>         delete :destroy, :id => @p.to_param
>>       end
>>     end
>>
>>     app = ApplicationController.new
>>     puts app.response.body
>>
>>     should_redirect_to("redirect to edit configuration") {
>> edit_configuration_path @configuration }
>>     # should_set_the_flash_to "The host has been unassociated."
>>   end
>>
>> I think the problem is the shoulda context. I am realizing that Shoulda is
>> not so magic and it is complicating my tests instead of helping. Probably I
>> should try Rspec
>>
>>
> You've got that puts in the wrong place.  You need to put it inside a
> should block, for example:
>
>     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*


> In terms of complicating your tests or magic, I'd say that Shoulda and
> Rspec are about equivalent, so switching from one to the other probably
> won't help.
>
> It may clear things up to know that, basically, those should blocks are
> defining a test method and setup blocks are defining a setup method and
> everything not in a should block or setup block is at class-scope for your
> test case.
>


*Thank you*



>
> Murray
>
>
> On 27 July 2010 09:14, Glenn Gillen <glenn at rubypond.com> wrote:
>>
>>> Just a "puts response.body" or the equivalent for webrat should be
>>> sufficient in your test (before the assertion).
>>>
>>> I suspect Matthews diagnosis is correct, I've been caught by it myself in
>>> the past.
>>>
>>> Glenn
>>>
>>> - Mistyped in a rush on my mobile
>>>
>>> On 27 Jul 2010, at 10:09, Riccardo Tacconi <rtacconi at gmail.com> wrote:
>>>
>>> Matthew,
>>>
>>> I have not used a debugger with Ruby yet.
>>>
>>> On 26 July 2010 18:21, Matthew Rudy Jacobs <<matthewrudyjacobs at gmail.com>
>>> matthewrudyjacobs at gmail.com> wrote:
>>>
>>>> have you used debugger?
>>>> I suggest you see what the content actually looks like
>>>>
>>>> in particular response.body
>>>>
>>>> perhaps its actually some error page that is being displayed
>>>> and erroneously returning a 200
>>>>
>>>
>>> I think that is the case
>>>
>>>>
>>>> ie.
>>>> check what your output is exactly
>>>> before saying the assertion is broken.
>>>>
>>>>
>>> Yes, I am wondering how to intercept the output to have more info
>>>
>>>
>>>> most likely its the code thats broken.
>>>>
>>>>
>>>> On 26 July 2010 18:17, Riccardo Tacconi < <rtacconi at gmail.com>
>>>> rtacconi at gmail.com> wrote:
>>>>
>>>>> I do not know if the test sends Accept text/html but I removed
>>>>> respond_to .html and left only the redirect, so it should redirect for every
>>>>> type of content, but I get the same message.
>>>>>
>>>>> Thanks,
>>>>>
>>>>> Riccardo
>>>>>
>>>>>
>>>>> On 26 July 2010 18:08, Tim Cowlishaw < <tim at timcowlishaw.co.uk>
>>>>> tim at timcowlishaw.co.uk> wrote:
>>>>>
>>>>>>
>>>>>> On 26 Jul 2010, at 18:05, Riccardo Tacconi wrote:
>>>>>>
>>>>>> >
>>>>>> > Expected response to be a <:redirect>, but was <200>
>>>>>> >
>>>>>> > But why? That method really return a 302 (redirrect) method. Do I
>>>>>> miss something?
>>>>>>
>>>>>> does the request that your test sends have an Accepts header of
>>>>>> text/html? Since the redirect is within the respond_to html block, I think
>>>>>> it would return 200 for any other content types.
>>>>>>
>>>>>> 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
>>>>>>
>>>>>
>>>>>
>>>>>
>>>>> --
>>>>> 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
>>>
>>>
>>> _______________________________________________
>>> 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
>>
>> _______________________________________________
>> Chat mailing list
>> Chat at lists.lrug.org
>> http://lists.lrug.org/listinfo.cgi/chat-lrug.org
>>
>>
>
> _______________________________________________
> 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
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.lrug.org/pipermail/chat-lrug.org/attachments/20100727/9863d1a3/attachment.html>


More information about the Chat mailing list