From c666776dafbbcb7b1c3485d5e48622bb1eb56c04 Mon Sep 17 00:00:00 2001 From: Hugo Peixoto Date: Sat, 7 Mar 2015 23:30:00 +0000 Subject: [PATCH] Fixes order dependencies in unit tests Some tests were changing global configuration settings without restoring them afterwards. Fixes #362 --- test/test_filters.rb | 6 +++++- test/test_result.rb | 13 ++++++++++--- 2 files changed, 15 insertions(+), 4 deletions(-) diff --git a/test/test_filters.rb b/test/test_filters.rb index da44e071..8d363066 100644 --- a/test/test_filters.rb +++ b/test/test_filters.rb @@ -37,10 +37,14 @@ class TestFilters < Minitest::Test context "with no filters set up and a basic source file in an array" do setup do - SimpleCov.filters = [] + @prev_filters, SimpleCov.filters = SimpleCov.filters, [] @files = [SimpleCov::SourceFile.new(source_fixture('sample.rb'), [nil, 1, 1, 1, nil, nil, 1, 0, nil, nil])] end + teardown do + SimpleCov.filters = @prev_filters + end + should "return 0 items after executing SimpleCov.filtered on files when using a 'sample' string filter" do SimpleCov.add_filter "sample" assert_equal 0, SimpleCov.filtered(@files).count diff --git a/test/test_result.rb b/test/test_result.rb index 83105d29..5535ce69 100644 --- a/test/test_result.rb +++ b/test/test_result.rb @@ -3,14 +3,21 @@ class TestResult < Minitest::Test context "With a (mocked) Coverage.result" do setup do - SimpleCov.filters = [] - SimpleCov.groups = {} - SimpleCov.formatter = nil + @prev_filters, SimpleCov.filters = SimpleCov.filters, [] + @prev_groups, SimpleCov.groups = SimpleCov.groups, {} + @prev_formatter, SimpleCov.formatter = SimpleCov.formatter, nil + @original_result = {source_fixture('sample.rb') => [nil, 1, 1, 1, nil, nil, 1, 1, nil, nil], source_fixture('app/models/user.rb') => [nil, 1, 1, 1, nil, nil, 1, 0, nil, nil], source_fixture('app/controllers/sample_controller.rb') => [nil, 1, 1, 1, nil, nil, 1, 0, nil, nil]} end + teardown do + SimpleCov.filters = @prev_filters + SimpleCov.groups = @prev_groups + SimpleCov.formatter = @prev_formatter + end + context "a simple cov result initialized from that" do setup { @result = SimpleCov::Result.new(@original_result) }