Re: [rspec-users] [rails] undefined method `model_name' for NilClass:Class

2011-05-31 Thread Ken Egervari
> On 2011-05-31 1:57 PM, Chris Habgood wrote: > >> The program works when I run it on the server. >> >> describe FoodsController do >> render_views >> >> before(:each) do >> Food.delete_all >> login_as_admin >> Food.stubs(:find).with("1").returns(@food = mock_model(Food, >> :save=>fa

Re: [rspec-users] [rails] undefined method `model_name' for NilClass:Class

2011-05-31 Thread Phillip Koebbe
On 2011-05-31 1:57 PM, Chris Habgood wrote: The program works when I run it on the server. describe FoodsController do render_views before(:each) do Food.delete_all login_as_admin Food.stubs(:find).with("1").returns(@food = mock_model(Food, :save=>false)) end #des

Re: [rspec-users] [rails] undefined method `model_name' for NilClass:Class

2011-05-31 Thread Ken Egervari
Can you give me the whole test code, with no comments? Just the stuff you are running. Thanks Ken On Tue, May 31, 2011 at 4:59 PM, Chris Habgood wrote: > yes > > > On Tue, May 31, 2011 at 15:33, Ken Egervari wrote: > >> Dumb question, do you have required "spec_helper" at the top of the file?

Re: [rspec-users] [rails] undefined method `model_name' for NilClass:Class

2011-05-31 Thread Chris Habgood
yes On Tue, May 31, 2011 at 15:33, Ken Egervari wrote: > Dumb question, do you have required "spec_helper" at the top of the file? > > Ken > > > > On Tue, May 31, 2011 at 4:03 PM, Chris Habgood wrote: > >> Ya, that is not working. The code I gave you I was trying different >> things out. >> Ra

Re: [rspec-users] [rails] undefined method `model_name' for NilClass:Class

2011-05-31 Thread Ken Egervari
Dumb question, do you have required "spec_helper" at the top of the file? Ken On Tue, May 31, 2011 at 4:03 PM, Chris Habgood wrote: > Ya, that is not working. The code I gave you I was trying different things > out. > Rails 3.0 > Rspec rspec (2.6.0.rc6) > > On Tue, May 31, 2011 at 14:35, Ken

Re: [rspec-users] [rails] undefined method `model_name' for NilClass:Class

2011-05-31 Thread Chris Habgood
Ya, that is not working. The code I gave you I was trying different things out. Rails 3.0 Rspec rspec (2.6.0.rc6) On Tue, May 31, 2011 at 14:35, Ken Egervari wrote: > Oh, don't forget the :id in the call to edit > > > before(:each) do > @food = Food.new > @food.id = 1 > end > > d

Re: [rspec-users] [rails] undefined method `model_name' for NilClass:Class

2011-05-31 Thread Ken Egervari
Oh, don't forget the :id in the call to edit before(:each) do @food = Food.new @food.id = 1 end describe "GET 'edit'" do it "should be successful" do Food.stub(:find).with("1").and_return(@food) get :edit, :id => "1" assigns(:food).should == @food end e

Re: [rspec-users] [rails] undefined method `model_name' for NilClass:Class

2011-05-31 Thread Ken Egervari
On Tue, May 31, 2011 at 2:57 PM, Chris Habgood wrote: > The program works when I run it on the server. > > describe FoodsController do > render_views > >before(:each) do > Food.delete_all > login_as_admin > Food.stubs(:find).with("1").returns(@food = mock_model(Food, > :save=

Re: [rspec-users] [rails] undefined method `model_name' for NilClass:Class

2011-05-31 Thread Chris Habgood
The program works when I run it on the server. describe FoodsController do render_views before(:each) do Food.delete_all login_as_admin Food.stubs(:find).with("1").returns(@food = mock_model(Food, :save=>false)) end #describe "stub_model(Food) with a hash of stubs" do

Re: [rspec-users] [rails] undefined method `model_name' for NilClass:Class

2011-05-31 Thread Chris Habgood
Full Error: Failures: 1) FoodsController should assign the requested food to @food Failure/Error: get :edit, :id => @food.id ActionView::Template::Error: undefined method `model_name' for NilClass:Class # ./app/views/foods/_form.html.erb:1:in `_app_views_foods__form_html_e

Re: [rspec-users] [rails] undefined method `model_name' for NilClass:Class

2011-05-31 Thread Ken Egervari
On Tue, May 31, 2011 at 2:38 PM, Chris Habgood wrote: > Still getting the same error. ugggh. Truly, you have to give us some more code to help you. ___ rspec-users mailing list rspec-users@rubyforge.org http://rubyforge.org/mailman/listinfo/rspec-use

Re: [rspec-users] [rails] undefined method `model_name' for NilClass:Class

2011-05-31 Thread Chris Habgood
Still getting the same error. ugggh. On Sat, May 28, 2011 at 10:50, Ken Egervari wrote: > You also want to make sure that @food has an id of some kind, or Rails > complains. For the 'new' action, you want to set @food.id to nil to make > sure the form works for the new action. > > You might not

Re: [rspec-users] [rails] undefined method `model_name' for NilClass:Class

2011-05-28 Thread Ken Egervari
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).wi

Re: [rspec-users] [rails] undefined method `model_name' for NilClass:Class

2011-05-28 Thread Ken Egervari
You also want to make sure that @food has an id of some kind, or Rails complains. For the 'new' action, you want to set @food.id to nil to make sure the form works for the new action. You might not think this is important, but it is. If you decide to move this controller into a namespace for examp

[rspec-users] [rails] undefined method `model_name' for NilClass:Class

2011-05-28 Thread Chris Habgood
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)