[rspec-users] another noob question about stubs

Patrick Aljord patcito at gmail.com
Wed Apr 30 12:26:08 EDT 2008


>  You'd need to paste more of your spec and controller action that you're
> stubbing for anyone to be of further help.
>

I think I posted it on my first post, here it is:

 def open_id_authentication(openid_url)
   authenticate_with_open_id(openid_url, :required => [:nickname,
:email], :optional => [:fullname]) do |result, identity_url,
registration|
     if result.successful?
       @user = User.find_or_initialize_by_identity_url(identity_url)
       if @user.new_record?
         @user.login = registration['nickname']
         @user.fullname = registration['fullname']
         @user.email = registration['email']
         @user.save!
         @user.activate
       end
       self.current_user = @user
       successful_login
     else
       failed_login result.message, 'openid'
     end
   end
end

My spec looks like this:
  it "should login with openid and redirect" do
    openid_url = "patcito.myopenid.com"
    controller.stub!(:using_open_id?).and_return(true)
    controller.stub!(:authenticate_with_open_id).and_yield(result,openid_url,registration={"nickname"=>"patcito","email"=>"bob at gmail.com","fullname"=>'bobby
bob'})
    post :create, :openid_url => openid_url
    session[:user_id].should_not be(nil)
    response.should be_redirect
  end


I tried to do something similar to this
http://pastie.textmate.org/102377 but it complains that
OpenID::Consumer::SUCCESS is not recognized. I guess I'd have to
include my open_id_authentication plugin lib in my spec to get it
recognized no? is there another way to include a lib in my spec to
make it work?

thanks in advance

Pat


More information about the rspec-users mailing list