Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Ruby > find_all_by returning nil with rspec

Reply
Thread Tools

find_all_by returning nil with rspec

 
 
John Mark
Guest
Posts: n/a
 
      08-08-2008
The statement
products = find_all_by_category_id(category_id)
in the Product model is returning nil with rspec.
I am expecting it to to return the stub that I provided it with. It does
not also work with fixtures.


Product model

def self.find_all_meeting_some_criteria_for_category(c ategory_id)
products = find_all_by_category_id(category_id)
products.each do |product|
....
end
end

Product spec

it "should find products given a category" do
product = mock_model(Product, :id => 1, :category_id => 1)
Product.stub(!find_all_by_category_id).with(anythi ng()).and_return([product])
Product.should_receive(:find_all_meeting_some_crit eria_for_category).with(product.category_id)
end
--
Posted via http://www.ruby-forum.com/.

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
rspec-1.3.1 and rspec-rails-1.3.3 are released! David Chelimsky Ruby 0 10-10-2010 02:51 AM
rspec-1.3.1.rc and rspec-rails-1.3.3.rc are released! David Chelimsky Ruby 0 10-03-2010 10:42 PM
[ANN] rspec and rspec-rails 1.2.9.rc1 Released David Chelimsky Ruby 0 09-15-2009 12:53 AM
Integer(nil) versus Float(nil) versus String(nil) Christoffer Sawicki Ruby 5 09-02-2006 06:28 PM
puts nil generates "nil\n" Brian Candler Ruby 1 11-06-2004 01:59 PM



Advertisments