[Testing] Counting Records in Array from Query

I can’t seem to figure out how to assert in my test that my method which
finds 5 records is in fact returning five records.

In my model:

app/models/widget.rb


def self.recent_widgets
find(:all,
:conditions => “created_at <= now()”,
:limit => 5,
:order => “created_at desc”)
end

I created a widgets.yml fixture with five records in it.

In my test_widget.rb unit test I want to assert that there are in fact
five
records being returned with the recent_widgets method

I’ve gone as far as:

tests/unit/test_widget.rb


fixtures :widgets

def test_find_recent_widgets
w = widget.recent_widgets
assert_not_nil w
end

Any clues. Thanks!

David Andrew T.
http://www.davidandrewthompson.com

On 7/11/07, David Andrew T. [email protected] wrote:

     :conditions => "created_at <= now()",


David Andrew T.
http://www.davidandrewthompson.com

If you want to assert that it has 5 exactly, use the asset_equal
assertion
on the array’s size.

def test_find_recent_widgets
assert_equal 5, widget.recent_widgets.size
end

HTH
Daniel