[rspec-users] How To Spec Controllers with Finders

Courtenay court3nay at gmail.com
Fri Jan 5 17:14:09 EST 2007


try this:


@line_item = mock("line_item")
LineItem.should_receive(:find_by_id).with(3).and_return(@line_item)
@line_item.should_receive(:update_attribute).with(:quantity, 1)

get :change_quantity, :id => 3, :quantity => 1


On 1/5/07, s.ross <cwdinfo at gmail.com> wrote:
> Given this code (which renders rjs), I'm faced with the fixture-
> driven way of spec-ing or mocking. How the heck to you mock this so
> the code at line (2) and (4) work right? I'm still struggling with
> mocks but it seems like this can be done. Forgive the naivety of this
> question.
>
> 1.  def change_quantity
> 2.    @line_item = LineItem.find_by_id(params[:id])
> 3.    unless @line_item.nil?
> 4.      @line_item.update_attribute(:quantity, params[:quantity])
> 5.      @extension_id = "extension#{params[:id]}"
> 6.    end
> 7.  end
>
> Thanks
> _______________________________________________
> rspec-users mailing list
> rspec-users at rubyforge.org
> http://rubyforge.org/mailman/listinfo/rspec-users
>


More information about the rspec-users mailing list