Displaying 1 result from an estimated 1 matches for "test_lambda".
Did you mean:
  best_lambda
  
2006 Sep 22
2
I''m misunderstanding how stubs works
...e.now
    t += 20
    Time.stubs(:now).returns(t)
    end_time = Time.now
    assert_equal end_time - start_time, 20
  end
But it fails with:
  1) Failure:
test_two_stubs(MochaTest) [mochatest.rb:19]:
<0.0> expected but was
<20>.
I can create a test which works as I intend:
  def test_lambda
    t = Time.now - 60
    Time.stubs(:now).returns(lambda { t })
    start_time = Time.now
    t += 20
    end_time = Time.now
    assert_equal end_time - start_time, 20
  end
But I''d be interested to understand why the first version doesn''t.
Thanks in advance for any help y...