[mocha-developer] Returning different values with stubs

Kevin Clark kevin.clark at gmail.com
Sun Sep 3 16:27:19 EDT 2006


Right now I'm working on adding tests to a method that looks like this:

      def get_via_redirect(path, args={})
        get path, args
        follow_redirect! while redirect?
        status
      end

So, I want to confirm that get is called and that status is returned
but I also want to see that when the value of redirect? effects how
many times follow_redirect is called. Is there already a built in way
to do this or should I go hacking?

My test looks a bit like this at the moment:

  # This needs redirect? to change what it returns...
  # def test_get_via_redirect
  #   path = "/somepath"
  #   args = {:id => '1'}
  #   @session.expects(:get).with(path,args)
  #   @session.stubs(:redirect?).returns() <-- returns different values
  #   @session.expects(:follow_redirect!). <-- expects it a certain
amount of times
  #   @session.get_via_redirect(pth, args)
  # end


-- 
Kevin Clark
http://glu.ttono.us


More information about the mocha-developer mailing list