diff options
Diffstat (limited to 'test/minitest/test_minitest_spec.rb')
-rw-r--r-- | test/minitest/test_minitest_spec.rb | 60 |
1 files changed, 53 insertions, 7 deletions
diff --git a/test/minitest/test_minitest_spec.rb b/test/minitest/test_minitest_spec.rb index 942156abdb..26dd4ec46a 100644 --- a/test/minitest/test_minitest_spec.rb +++ b/test/minitest/test_minitest_spec.rb @@ -4,11 +4,9 @@ # File a patch instead and assign it to Ryan Davis. ###################################################################### -require 'minitest/spec' +require 'minitest/autorun' require 'stringio' -MiniTest::Unit.autorun - describe MiniTest::Spec do before do @assertion_count = 4 @@ -202,6 +200,53 @@ describe MiniTest::Spec do end end +describe MiniTest::Spec, :let do + i_suck_and_my_tests_are_order_dependent! + + def _count + $let_count ||= 0 + end + + let :count do + $let_count += 1 + $let_count + end + + it "is evaluated once per example" do + _count.must_equal 0 + + count.must_equal 1 + count.must_equal 1 + + _count.must_equal 1 + end + + it "is REALLY evaluated once per example" do + _count.must_equal 1 + + count.must_equal 2 + count.must_equal 2 + + _count.must_equal 2 + end +end + +describe MiniTest::Spec, :subject do + attr_reader :subject_evaluation_count + + subject do + @subject_evaluation_count ||= 0 + @subject_evaluation_count += 1 + @subject_evaluation_count + end + + it "is evaluated once per example" do + subject.must_equal 1 + subject.must_equal 1 + subject_evaluation_count.must_equal 1 + end +end + class TestMeta < MiniTest::Unit::TestCase def test_setup srand 42 @@ -245,8 +290,8 @@ class TestMeta < MiniTest::Unit::TestCase assert_equal "inner thingy", y.desc assert_equal "very inner thingy", z.desc - top_methods = %w(setup teardown test_0001_top_level_it) - inner_methods = %w(setup teardown test_0001_inner_it) + top_methods = %w(test_0001_top_level_it) + inner_methods = %w(test_0001_inner_it) assert_equal top_methods, x.instance_methods(false).sort.map {|o| o.to_s } assert_equal inner_methods, y.instance_methods(false).sort.map {|o| o.to_s } @@ -257,8 +302,9 @@ class TestMeta < MiniTest::Unit::TestCase _, _, z, before_list, after_list = util_structure tc = z.new(nil) - tc.setup - tc.teardown + + tc.run_setup_hooks + tc.run_teardown_hooks assert_equal [1, 2, 3], before_list assert_equal [3, 2, 1], after_list |