My controller
def edit
@user = User.find(get_param(:id, :integer))
@user = current_user if !is_admin?
end
My spec
describe “GET edit” do
##############################################################
should_require_login :get, :edit
##############################################################
describe "authenticated user" do
##############################################################
before(:each) do
login_as_user
@user = mock_model(User)
User.stub!(:find).and_return(@user)
controller.stub!(:is_admin?).and_return(false)
end
##############################################################
def do_get
get :edit, :id => 1
end
##############################################################
it "should find user and return object" do
User.should_receive(:find).with(1).and_return(@user)
get :edit, :id => 1
assigns[:user].should == @user
end
end
end
The error
‘UsersController GET edit authenticated user should find user and return
object’ FAILED
expected: #<User:0x10cbaec @name=“User_1016”>,
got: #<User:0x10cf228 @name=“User_1015”> (using ==)
I know I am stubbing the is_admin? method in a wrong way.
Can anyone help me?
Thank you
EM
View this message in context:
http://www.nabble.com/Help-in-Stubing-is_admin--method-tp25965314p25965314.html
Sent from the rspec-users mailing list archive at Nabble.com.