[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.ruby

Testing for warnings

Alex Gutteridge

7/2/2007 7:10:00 AM

Is there a way of asserting that a warning is raised in a unit test?
So I could write something like:

assert_warns "Blah blah" do function_that_warns(foo) end

I can't seem to find anything in the test/unit docs, but it seems
like something that would be relatively common to test for...

Alex Gutteridge

Bioinformatics Center
Kyoto University



14 Answers

Jano Svitok

7/2/2007 9:24:00 PM

0

On 7/2/07, Alex Gutteridge <alexg@kuicr.kyoto-u.ac.jp> wrote:
> Is there a way of asserting that a warning is raised in a unit test?
> So I could write something like:
>
> assert_warns "Blah blah" do function_that_warns(foo) end
>
> I can't seem to find anything in the test/unit docs, but it seems
> like something that would be relatively common to test for...

You may try to write that yourself by replacing Kernel#warn, though
this way you cannot check warnings from C code. Alternatively you
could replace/capture $stderr/STDERR and look for warnings there.

Alex Gutteridge

7/2/2007 11:46:00 PM

0

On 3 Jul 2007, at 06:23, Jano Svitok wrote:

> On 7/2/07, Alex Gutteridge <alexg@kuicr.kyoto-u.ac.jp> wrote:
>> Is there a way of asserting that a warning is raised in a unit test?
>> So I could write something like:
>>
>> assert_warns "Blah blah" do function_that_warns(foo) end
>>
>> I can't seem to find anything in the test/unit docs, but it seems
>> like something that would be relatively common to test for...
>
> You may try to write that yourself by replacing Kernel#warn, though
> this way you cannot check warnings from C code. Alternatively you
> could replace/capture $stderr/STDERR and look for warnings there.

I specifically need to check for warnings from C code so replacing
Kernel#warn won't work. I will try hooking into STDERR though -
thanks for the idea.

Alex Gutteridge

Bioinformatics Center
Kyoto University



Gregory Brown

7/2/2007 11:53:00 PM

0

On 7/2/07, Alex Gutteridge <alexg@kuicr.kyoto-u.ac.jp> wrote:

> I specifically need to check for warnings from C code so replacing
> Kernel#warn won't work. I will try hooking into STDERR though -
> thanks for the idea.

Possibly make use of Mocha or another mocking framework?

class Foo
def bar
warn "baz"
end
end

require "test/unit"
require "rubygems"
require "mocha"

class TestFoo < Test::Unit::TestCase

def test_bar_should_warn
a = Foo.new
a.expects(:warn).with("baz")
a.bar
end

end

Phlip

12/7/2010 6:57:00 AM

0

On Dec 6, 10:40 pm, "DogDiesel" <nos...@nospam.none> wrote:
> "George Plimpton" <geo...@si.not> wrote in message
>
> news:Y8-dnSb7lfUV2mDRnZ2dnUVZ_u6dnZ2d@earthlink.com...
>
> > "Gary", convicted child molester, town drunk, and the Shame of Chico,
> > lied:
>
> >> No one should be stuck eating cat food this holiday season - or ever, for
> >> that matter.
>
> > No one is.  No one in America has to eat cat food.
>
> But plenty of peope have pimpleton.

DogDiesel, sober up and recognize "Plimpton" is on your "side". (If
you can tell...)

George Plimpton

12/7/2010 7:04:00 AM

0

On 12/6/2010 10:40 PM, DogDiesel wrote:
> "George Plimpton"<george@si.not> wrote in message
> news:Y8-dnSb7lfUV2mDRnZ2dnUVZ_u6dnZ2d@earthlink.com...
>> "Gary", convicted child molester, town drunk, and the Shame of Chico,
>> lied:
>>
>>> No one should be stuck eating cat food this holiday season - or ever, for
>>> that matter.
>>
>> No one is. No one in America has to eat cat food.
>
>
> But plenty of peope

Learn English, fuckwit.

No one in America has to eat cat food. Cut the shit, pal.

--
....and that's just how it is.

None4U

12/7/2010 7:52:00 AM

0


"Phlip" <phlip2005@gmail.com> wrote in message
news:d87a77d1-7119-4242-82b0-470d29250ce9@y19g2000prb.googlegroups.com...
On Dec 6, 10:40 pm, "DogDiesel" <nos...@nospam.none> wrote:
> "George Plimpton" <geo...@si.not> wrote in message
>
> news:Y8-dnSb7lfUV2mDRnZ2dnUVZ_u6dnZ2d@earthlink.com...
>
> > "Gary", convicted child molester, town drunk, and the Shame of Chico,
> > lied:
>
> >> No one should be stuck eating cat food this holiday season - or ever,
> >> for
> >> that matter.
>
> > No one is. No one in America has to eat cat food.
>
> But plenty of peope have pimpleton.

DogDiesel, sober up and recognize "Plimpton" is on your "side". (If
you can tell...)



I dont take sides. Im pounding anyone. Who spends , or taxes, or pisses
me off.


None4U

12/7/2010 7:53:00 AM

0


"George Plimpton" <george@si.not> wrote in message
news:JMadncE7SKT_QWDRnZ2dnUVZ_jGdnZ2d@earthlink.com...
> On 12/6/2010 10:40 PM, DogDiesel wrote:
>> "George Plimpton"<george@si.not> wrote in message
>> news:Y8-dnSb7lfUV2mDRnZ2dnUVZ_u6dnZ2d@earthlink.com...
>>> "Gary", convicted child molester, town drunk, and the Shame of Chico,
>>> lied:
>>>
>>>> No one should be stuck eating cat food this holiday season - or ever,
>>>> for
>>>> that matter.
>>>
>>> No one is. No one in America has to eat cat food.
>>
>>
>> But plenty of peope
>
> Learn English, fuckwit.
>
> No one in America has to eat cat food. Cut the shit, pal.
>
> --
> ...and that's just how it is.


plenty have. And thats how it is.


George Plimpton

12/7/2010 2:54:00 PM

0

On 12/6/2010 11:52 PM, DogDiesel wrote:
> "George Plimpton"<george@si.not> wrote in message
> news:JMadncE7SKT_QWDRnZ2dnUVZ_jGdnZ2d@earthlink.com...
>> On 12/6/2010 10:40 PM, DogDiesel wrote:
>>> "George Plimpton"<george@si.not> wrote in message
>>> news:Y8-dnSb7lfUV2mDRnZ2dnUVZ_u6dnZ2d@earthlink.com...
>>>> "Gary", convicted child molester, town drunk, and the Shame of Chico,
>>>> lied:
>>>>
>>>>> No one should be stuck eating cat food this holiday season - or ever,
>>>>> for
>>>>> that matter.
>>>>
>>>> No one is. No one in America has to eat cat food.
>>>
>>>
>>> But plenty of peope
>>
>> Learn English, fuckwit.
>>
>> No one in America has to eat cat food. Cut the shit, pal.
>>
>> --
>> ...and that's just how it is.
>
>
> plenty have.

No. No one in America has to eat cat food. This is nothing but an
urban legend, and you've bought it because you don't have any ability
for critical thinking.


--
....and that's just how it is.

Phlip

12/7/2010 3:27:00 PM

0

On Dec 7, 6:53 am, George Plimpton <geo...@si.not> wrote:

> No.  No one in America has to eat cat food.

"Are there no prisons? Are there no workhouses?" asked Scrooge.

Phlip

12/7/2010 3:28:00 PM

0

On Dec 6, 11:52 pm, "DogDiesel" <nos...@nospam.none> wrote:

> I dont take sides.  Im pounding anyone.  Who spends , or taxes,  or pisses
> me off.

That sure includes yourself.