Thanks for help and sorry for insistance but I don't understand aspects on rspec ( I think not understand how we use mocks and stubs): The behavior of my controller is... Before Filter: check_administrator_role load_user
So, in this case I want run my before filter methods in before block on rspec, like below: describe PropertiesController do def mock_property(stubs={}) @mock_property ||= mock_model(Property, stubs) end before do @current_user = mock_model(User, :id => 1) <== define a current_user with id 1 controller.stub!(:check_administrator_role).and_return(true) <== and current_user is administrator @params = {:user_id=>1} <== define params User.stub!(:find).with(@params[:user_id]).and_return(@user) <== and now try fetch the user with id 1 end This line will define @user variable, right? User.stub!(:find).with(@params[:user_id]).and_return(@user) But I don't need mock the @user variable to fill it with valid values ( like user_id, name, email and etc ) ? I think @user content is nil and get errors from will_paginate find method for this reason. describe "responding to GET index" do it "should expose all properties of given user as @properties" do @user.should_receive(:properties).and_return([mock_property]) get :index assigns[:properties].should == [mock_property] end end thanks. Atenciosamente, Daniel Lopes Area Criações Design, Websites e Sistemas Web Visite: http://www.areacriacoes.com.br/projects http://blog.areacriacoes.com.br/ * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * 55 (31) 3077-4560 / 55 (31) 8808-8748 / 55 (31) 8737-7501 On Fri, Dec 5, 2008 at 12:16 PM, David Chelimsky <[EMAIL PROTECTED]>wrote: > On Fri, Dec 5, 2008 at 8:07 AM, Daniel Lopes <[EMAIL PROTECTED]> > wrote: > > Thanks Newman, I already try this but get strange error: > > before do > > @current_user = mock_model(User, :id => 1) > > controller.stub!(:check_administrator_role).and_return(true) > > User.stub(:find).with(1).and_return(@user) # <=<=<=<=<=<= > > It's stub!, not stub :) > > Cheers, > David > > > end > > The error: > > undefined method `stub' for #<Class:0x23a5f3c> > > > > Atenciosamente, > > > > Daniel Lopes Area Criações > > Design, Websites e Sistemas Web > > > > Visite: http://www.areacriacoes.com.br/projects > > http://blog.areacriacoes.com.br/ > > > > * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * > * > > * > > 55 (31) 3077-4560 / 55 (31) 8808-8748 / 55 (31) 8737-7501 > > > > > > On Fri, Dec 5, 2008 at 11:58 AM, Newman Huang <[EMAIL PROTECTED]> > wrote: > >> > >> try: > >> > >> [EMAIL PROTECTED] = User.find(params[:user_id]) > >> User.stub(:find).with(xx).and_return(@user) > >> -- > >> 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 > > > _______________________________________________ > 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