[rspec-users] Stubbing Time.now in trunk

aslak hellesoy aslak.hellesoy at gmail.com
Fri Nov 10 16:20:17 EST 2006


On 11/10/06, Jay Levitt <lists-rspec at shopwatch.org> wrote:
> I'm a big fan of stubbing Time.now so it returns a known value.  I used
> to be able to use stubba and say:
>
> @time_now = Time.parse("Jan 1 2001")
> Time.stubs(:now).returns(lambda{@time_now})
>
> However, something in trunk broke that.  Fine, rspec's got its own
> stubbing lib now, so I tried switching to that:
>
> @time_now = Time.parse("Jan 1 2001")
> Time.stub!(:now).and_return(lambda{@time_now})
>
> This gives me some VERY odd errors.  For instance, if this is in a
> controller spec, and the next line is
>   get 'index'
>
> I get:
>
> wrong number of arguments (1 for 0)
> ./spec/controllers/one_spec.rb:9:in `should render the index page'
>
> Line 9 is the get 'index' line. If I delete that, so there is no next
> line, I get:
>
> NoMethodError in 'the test app should render the index page'
> undefined method `to_i' for
> #<Proc:0x04a0374c at ./spec/controllers/one_spec.rb:8>
>
> Am I doing something wrong, or is this a bug in trunk?
>

Could be a bug. Please submit a complete failing spec so we can
reproduce it faithfully.
http://rspec.rubyforge.org/contribute.html

Aslak

> Jay
>
> _______________________________________________
> rspec-users mailing list
> rspec-users at rubyforge.org
> http://rubyforge.org/mailman/listinfo/rspec-users
>


More information about the rspec-users mailing list