On Thu, Jan 1, 2009 at 5:31 AM, Jesse Crockett <li...@ruby-forum.com> wrote: > Jesse Crockett wrote: >> I hope to be on my feet after a few more basic questions.. > > I'm sorry, but this is beginning to feel like kicking myself in the > head. > > === here is what I'm working with > http://github.com/fudgestudios/bort/tree/master > > === Errors > FF > > 1) > NoMethodError in 'bidding on an item should be allowed with a credit' > You have a nil object when you didn't expect it! > You might have expected an instance of ActiveRecord::Base. > The error occurred while evaluating nil.new_record? > spec/controllers/auction_controller_spec.rb:23: > spec/controllers/auction_controller_spec.rb:6: > > 2) > NoMethodError in 'bidding on an item should require a credit' > You have a nil object when you didn't expect it! > You might have expected an instance of ActiveRecord::Base. > The error occurred while evaluating nil.new_record? > spec/controllers/auction_controller_spec.rb:17: > spec/controllers/auction_controller_spec.rb:6: > > Finished in 0.074996 seconds > > 2 examples, 2 failures > > > === here is my controller action > > def bid > > @bid = Bid.new(params[:bid]) > @bid.save > > end > > === here is my test > > require File.dirname(__FILE__) + '/../spec_helper' > include ApplicationHelper > include UsersHelper > include AuthenticatedTestHelper > > describe "bidding on an item" do > controller_name :items > > before(:each) do > @user = mock_user > stub!(:current_user).and_return(@user)
Calling stub! with no receiver means it's being called on the example itself. Assuming you're using RestfulAuth, you'll want this to be on the controller itself: controller.stub!(:current_user).and_return(@user) Although, looking at the 'bid' action, it doesn't appear to be doing anything with the user yet, so I'm not sure why this is here at this point. > end > > it "should require a credit" do > @user.stub!(:credits).and_return(0) > post 'bid', :bid => { :auction_id => 1, :user_id => @user.id, :point > => 1 } If you're using the mock_user, which uses mock_model (I'm assuming here, since you're not posting complete files), > assigns[:bid].should_not be_new_record I'm guessing this is line 17 and the "assigns[:bid] line below is 23. What this means is that assigns[:bid] is nil, which means that somehow the action is failing to generate the bit object. I'm at a bit of a loss as to why that might be, but that's what is indicated. HTH, David > end > > it "should be allowed with a credit" do > @user.stub!(:credits).and_return(1) > post 'bid', :bid => { :auction_id => 1, :user_id => @user.id, :point > => 1 } > assigns[:bid].should be_new_record > end > > end > > === spec_helper > http://github.com/fudgestudios/bort/tree/master/spec/spec_helper.rb > > It's very disheartening to wake for work at 3 a.m. and accomplish > nothing for the day. Please understand. > -- > Posted via http://www.ruby-forum.com/. > _______________________________________________ > 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