def test_ferret false positive?

0 views
Skip to first unread message

akkdio

unread,
Oct 1, 2008, 10:10:31 PM10/1/08
to Beginning Ruby on Rails E-Commerce
I am getting a false positive on the book test for test_ferret. When
I change the books assert method:

assert Book.find_by_contents("Pride and Prejudice") to
assert Book.find_by_contents("rrrrr")

it still passes. Any hints to why this is.

everything works fine for ferret but I like to break things to
understand how they are working and this did not break.

Thanks,

Akkdio

Jarkko Laine

unread,
Oct 2, 2008, 1:41:39 AM10/2/08
to railsec...@googlegroups.com

puts Book.find_by_contents("rrrrr").inspect

will tell you what the method returned. Or if you want to go fancy,
use Rails.logger.debug instead of plain puts and the output will go to
your test.log.

//jarkko

>
>
> Thanks,
>
> Akkdio
> >

--
Jarkko Laine
http://jlaine.net
http://dotherightthing.com
http://www.railsecommerce.com
http://odesign.fi


akkdio

unread,
Oct 3, 2008, 12:19:28 AM10/3/08
to Beginning Ruby on Rails E-Commerce
Thanks,

This is the return:

..#<ActsAsFerret::SearchResults:0x25a36f4 @total_pages=0, @results=[],
@per_page=0, @current_page=nil, @total_hits=0>

I guess the reason the test does not fail is because we are asserting
ferret worked but do not require it to return the book. It does its
job by not finding the book because the book does not exists. Why is
this test, assert Book.find_by_contents("Pride and Prejudice"), used.
Is it just to see if it works - doesn't the test: assert_equal 1,
Book.find_by_contents("Open Source").size, play this role too?

Jarkko Laine

unread,
Oct 3, 2008, 1:14:56 AM10/3/08
to railsec...@googlegroups.com

On 3.10.2008, at 7.19, akkdio wrote:

>
> Thanks,
>
> This is the return:
>
> ..#<ActsAsFerret::SearchResults:0x25a36f4 @total_pages=0, @results=[],
> @per_page=0, @current_page=nil, @total_hits=0>
>
> I guess the reason the test does not fail is because we are asserting
> ferret worked but do not require it to return the book. It does its
> job by not finding the book because the book does not exists. Why is
> this test, assert Book.find_by_contents("Pride and Prejudice"), used.
> Is it just to see if it works - doesn't the test: assert_equal 1,
> Book.find_by_contents("Open Source").size, play this role too?

I think the behaviour of acts_as_ferret has changed since the writing
of the book. It used to just return nil when there were no hits.
Checking the size is definitely the way to go now.

//jarkko

>
>
>
> On Oct 2, 1:41 am, Jarkko Laine <jar...@jlaine.net> wrote:
>> On 2.10.2008, at 5.10, akkdio wrote:
>>
>>
>>
>>> I am getting a false positive on the book test for test_ferret.
>>> When
>>> I change the books assert method:
>>
>>> assert Book.find_by_contents("Pride and Prejudice") to
>>> assert Book.find_by_contents("rrrrr")
>>
>>> it still passes. Any hints to why this is.
>>
>>> everything works fine for ferret but I like to break things to
>>> understand how they are working and this did not break.
>>
>> puts Book.find_by_contents("rrrrr").inspect
>>
>> will tell you what the method returned. Or if you want to go fancy,
>> use Rails.logger.debug instead of plain puts and the output will go
>> to
>> your test.log.
>>
>> //jarkko
>>
>>
>>
>>> Thanks,
>>
>>> Akkdio
>>
>> --
>> Jarkko Lainehttp://jlaine.nethttp://dotherightthing.comhttp://www.railsecommerce.comhttp
>> ://odesign.fi
> >

--

Reply all
Reply to author
Forward
0 new messages