[rspec-users] Help with controllers specs

Elza Di Sirio elza.morelli at tagview.com.br
Mon Oct 19 09:24:39 EDT 2009


I had some doubts while specing the action edit for User Model

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)
       end
       ##############################################################
       it "should find user and return object" do
         User.should_receive(:find_by_id_and_role).with(1,  
"SJ").and_return(@user)
         get :edit, :id => 1, :role => 'SJ'
       end
      end
   end
**************************************

The method is_admin in Application Controller

   def is_admin?
     logged_in? && current_user.role == Role.find(Role::ADMINISTRATOR)
   end
***************************************************
The error I have is

Spec::Mocks::MockExpectationError in 'UsersController GET edit  
authenticated user should find user and return object'
Mock 'User_1015' received unexpected message :role with (no args)

How should I verify the method is_admin?

Thank you

EM


  
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://rubyforge.org/pipermail/rspec-users/attachments/20091019/69c9fd8f/attachment.html>


More information about the rspec-users mailing list