From: Jay Levitt Date: 2006-09-06T06:25:16+09:00 Subject: Stubbing Time.now with Mocha Mocha seems a great way to stub Time.now for testing expiration dates, etc. with rspec. I can get it to stub a single time easily: Time.stubs(:now).returns(Time.at(1)) but what I'd really like to do is do that multiple times during a test: specify "with an expired cookie should return nil" Time.stubs(:now).returns(Time.parse("Jan 1 2001")) louie.login cookie = louie.remember_me Time.stubs(:now).returns(Time.parse("Oct 1 2001")) louie.login_with_cookie(cookie).should_be_nil end However, only the first stubs call has any effect. I've tried stubbing it to a FakeTime object: Time.stubs(:now).returns(FakeTime.now) but it only looks at the value of FakeTime.now when the stub is created. Is there a way using Mocha/Stubba to stub a routine and have it call another for the return value? I've tried creating procs/lambdas, but I must be doing something wrong - I get an infinite recursion. Jay Levitt