Skip to content

Commit

Permalink
- Make Spec::DSL.describe_stack thread local to avoid failing on my o…
Browse files Browse the repository at this point in the history
…wn tests.

- Make a fake Time.now local to the tests so they won't interfere with real reporter timings.

[git-p4: depot-paths = "//src/minitest/dev/": change = 8677]
  • Loading branch information
zenspider committed Jun 12, 2013
1 parent 46ed331 commit 53d233c
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 16 deletions.
3 changes: 1 addition & 2 deletions lib/minitest/spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -143,9 +143,8 @@ def spec_type desc
}.last
end

@@describe_stack = []
def describe_stack # :nodoc:
@@describe_stack
Thread.current[:describe_stack] ||= []
end

##
Expand Down
30 changes: 16 additions & 14 deletions test/minitest/test_minitest_mock.rb
Original file line number Diff line number Diff line change
Expand Up @@ -286,18 +286,22 @@ def teardown
assert_equal @assertion_count, @tc.assertions
end

class Time
def self.now
24
end
end

def assert_stub val_or_callable
@assertion_count += 1

Minitest::Test.synchronize do
t = Time.now.to_i

Time.stub :now, val_or_callable do
@tc.assert_equal 42, Time.now
end
t = Time.now.to_i

@tc.assert_operator Time.now.to_i, :>=, t
Time.stub :now, val_or_callable do
@tc.assert_equal 42, Time.now
end

@tc.assert_operator Time.now.to_i, :>=, t
end

def test_stub_private_module_method
Expand Down Expand Up @@ -345,15 +349,13 @@ def test_stub_block
def test_stub_block_args
@assertion_count += 1

Minitest::Test.synchronize do
t = Time.now.to_i

Time.stub :now, lambda { |n| n * 2 } do
@tc.assert_equal 42, Time.now(21)
end
t = Time.now.to_i

@tc.assert_operator Time.now.to_i, :>=, t
Time.stub :now, lambda { |n| n * 2 } do
@tc.assert_equal 42, Time.now(21)
end

@tc.assert_operator Time.now.to_i, :>=, t
end

def test_stub_callable
Expand Down

0 comments on commit 53d233c

Please sign in to comment.