# ActsAsFerret - what's the class of the results?

**URL:** <https://www.ruby-forum.com/t/actsasferret-whats-the-class-of-the-results/159617>\
**Category:** Ferret\
**Created:** [February 6, 2009, 12:13pm UTC](https://www.ruby-forum.com/t/actsasferret-whats-the-class-of-the-results/159617 "2009-02-06T12:13:43Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![cmaxvv](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/85f322/32.png) [@cmaxvv](https://www.ruby-forum.com/u/cmaxvv)\
**Post date:** [February 6, 2009, 12:13pm UTC](https://www.ruby-forum.com/t/actsasferret-whats-the-class-of-the-results/159617/1 "2009-02-06T12:13:43Z")

</div>

I’m trying to write a test for a method that uses a ferret search, but  
can’t validate that the results are a\_a\_f results because my class test  
doesn’t work. Can anyone set me straight? Here’s some console  
experimentation that shows the root of the problem.

> > users = User.find\_with\_ferret(“max”, :per\_page =\> 2)  
> > =\> [#\<User …  
> > …  
> > ]
> 
> > users.size  
> > =\> 2
> 
> > users.next\_page #call a ferret-results-specific method  
> > =\> 2
> 
> > users.kind\_of?(ActsAsFerret::SearchResults)  
> > =\> false

What class should i be testing against, if it’s not  
ActsAsFerret::SearchResults? If i do type on the results i just get  
Array.

---

<div class="post-metadata">

**Author:** ![cmaxvv](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/85f322/32.png) [@cmaxvv](https://www.ruby-forum.com/u/cmaxvv)\
**Post date:** [February 10, 2009, 10:14am UTC](https://www.ruby-forum.com/t/actsasferret-whats-the-class-of-the-results/159617/2 "2009-02-10T10:14:58Z")

</div>

Hi,

SearchResults is a _really_ thin wrapper around a standard Ruby Array  
instance. If you really want to check it’s a SearchResults instance  
and not something else, check for Array and whether it behaves like it  
should by looking at the ‘special’ methods the SearchResults class  
adds, maybe like this:

assert\_equal Array, results.class  
%w(total\_hits current\_page per\_page total\_pages).each {|m| assert  
results.respond\_to?(m.to\_sym) }

cheers,  
Jens

On 06.02.2009, at 12:13, Max W. wrote:

> > > users.size  
> > > Posted via [http://www.ruby-forum.com/](http://www.ruby-forum.com/).
> 
> * * *
> 
> Ferret-talk mailing list  
> removed\_email\_address@domain.invalid  
> [http://rubyforge.org/mailman/listinfo/ferret-talk](http://rubyforge.org/mailman/listinfo/ferret-talk)

–  
Jens KrÃ¤mer  
Finkenlust 14, 06449 Aschersleben, Germany  
VAT Id DE251962952  
[http://www.jkraemer.net/](http://www.jkraemer.net/) - Blog  
[http://www.omdb.org/](http://www.omdb.org/) - The new free film database

---

<div class="post-metadata">

**Author:** ![cmaxvv](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/85f322/32.png) [@cmaxvv](https://www.ruby-forum.com/u/cmaxvv)\
**Post date:** [February 10, 2009, 11:24am UTC](https://www.ruby-forum.com/t/actsasferret-whats-the-class-of-the-results/159617/3 "2009-02-10T11:24:06Z")

</div>

ah ok. i should have thought to just put that same method that i  
referred to into a ‘responds\_to’ call in my test, like you suggest 🙂

Thanks Jens  
max
