I just found it bothersome to use stubs when testing rails controllers. A far easier way to do this is to define what @food is in a before(:each) block and then use it in your tests:
describe "GET edit" do it "should assign the requested food to @food" do Food.should_receive(:find).with("1").and_return(@food) get :edit, :id => "1" assigns(:food).should be(@food) end end This is still very fast, and it has the added benefit that you can use "render_views" at the top of the spec to test your routes, erb code, etc. -> which is REALLY valuable. Ken On Fri, May 27, 2011 at 12:39 PM, Chris Habgood <chabg...@gmail.com> wrote: > Never seen the error above before, code: > > describe "edit action" do > it "edit action should render edit template" do > food = Food.create(:name=>'mooo') # > Food.any_instance.stubs(:valid?).returns(true) > get :edit, :id => food.id > response.should render_template(:edit) > end > end > > _______________________________________________ > rspec-users mailing list > rspec-users@rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users >
_______________________________________________ rspec-users mailing list rspec-users@rubyforge.org http://rubyforge.org/mailman/listinfo/rspec-users