find_all_by returning nil with rspec

Discussion in 'Ruby' started by John Mark, Aug 8, 2008.

  1. John Mark

    John Mark Guest

    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(category_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(anything()).and_return([product])
    Product.should_receive:)find_all_meeting_some_criteria_for_category).with(product.category_id)
    end
    --
    Posted via http://www.ruby-forum.com/.
    John Mark, Aug 8, 2008
    #1
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Brian Candler

    puts nil generates "nil\n"

    Brian Candler, Nov 6, 2004, in forum: Ruby
    Replies:
    1
    Views:
    104
  2. Christoffer Sawicki
    Replies:
    5
    Views:
    241
    Christoffer Sawicki
    Sep 2, 2006
  3. David Chelimsky
    Replies:
    0
    Views:
    105
    David Chelimsky
    Sep 15, 2009
  4. David Chelimsky
    Replies:
    0
    Views:
    107
    David Chelimsky
    Oct 3, 2010
  5. David Chelimsky
    Replies:
    0
    Views:
    102
    David Chelimsky
    Oct 10, 2010
Loading...

Share This Page