@ticket.should_receive(:new).with(@params).and_return(@ticket) is like saying:
@ticket = @ticket.new(params) And that, of course, doesn't make much sense. I'll give you a chance to find the solution yourself ;-) Aslak On 8/21/07, Andrew WC Brown <[EMAIL PROTECTED]> wrote: > I'm using restful_authentication in my app and I have the before filters in > my application rhtml: > > before_filter :login_required > around_filter :set_timezone > around_filter :catch_errors > > Currently I have them commented out while rspec'in but I'll need to add them > in my specs. > > > def create > @ticket = Ticket.new(params[:ticket]) > @ticket.user = current_user > if @ticket.save > redirect_to tickets_path > else > render new_ticket_path(params[:user_id]) > end > end > > describe TicketsController, "handling POST /tickets" do > before do > @ticket = mock_model(Ticket, :save => true) > @current_user = mock_model(User) > @params = {} > end > def do_post > post :create, :ticket => @params > end > it "should create a new ticket and assign current user as ticket's user" > do > > @ticket.should_receive(:new).with(@params).and_return(@ticket) > assigns[:ticket].user.should equal(@current_user) > do_post > end > end > > 1) > NoMethodError in 'TicketsController handling POST /tickets should create a > new ticket and assign current user as ticket's user' > You have a nil object when you didn't expect it! > You might have expected an instance of Array. > The error occurred while evaluating nil.include? > /Volumes/EXTERNAL/web/yellowticket/vendor/plugins/rspec_on_rails/lib/spec/rails/dsl/assigns_hash_proxy.rb:10:in > `[]' > ./spec/controllers/tickets_controller_spec.rb:14: > > > My guess is that I'm not allow to do this: assigns[:ticket].user > How do I apple the assignment with current_user? > > _______________________________________________ > 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