simplecov 0.6.0 → 0.22.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/CHANGELOG.md +163 -80
- data/LICENSE +1 -1
- data/README.md +776 -277
- data/doc/alternate-formatters.md +71 -0
- data/doc/commercial-services.md +25 -0
- data/doc/editor-integration.md +18 -0
- data/lib/minitest/simplecov_plugin.rb +15 -0
- data/lib/simplecov/combine/branches_combiner.rb +32 -0
- data/lib/simplecov/combine/files_combiner.rb +24 -0
- data/lib/simplecov/combine/lines_combiner.rb +43 -0
- data/lib/simplecov/combine/results_combiner.rb +60 -0
- data/lib/simplecov/combine.rb +30 -0
- data/lib/simplecov/command_guesser.rb +53 -38
- data/lib/simplecov/configuration.rb +478 -193
- data/lib/simplecov/coverage_statistics.rb +56 -0
- data/lib/simplecov/default_formatter.rb +20 -0
- data/lib/simplecov/defaults.rb +40 -44
- data/lib/simplecov/exit_codes/exit_code_handling.rb +29 -0
- data/lib/simplecov/exit_codes/maximum_coverage_drop_check.rb +83 -0
- data/lib/simplecov/exit_codes/minimum_coverage_by_file_check.rb +54 -0
- data/lib/simplecov/exit_codes/minimum_overall_coverage_check.rb +53 -0
- data/lib/simplecov/exit_codes.rb +15 -0
- data/lib/simplecov/file_list.rb +112 -36
- data/lib/simplecov/filter.rb +54 -4
- data/lib/simplecov/formatter/multi_formatter.rb +32 -0
- data/lib/simplecov/formatter/simple_formatter.rb +21 -15
- data/lib/simplecov/formatter.rb +4 -1
- data/lib/simplecov/last_run.rb +28 -0
- data/lib/simplecov/lines_classifier.rb +48 -0
- data/lib/simplecov/load_global_config.rb +8 -0
- data/lib/simplecov/no_defaults.rb +4 -0
- data/lib/simplecov/process.rb +19 -0
- data/lib/simplecov/profiles/bundler_filter.rb +5 -0
- data/lib/simplecov/profiles/hidden_filter.rb +5 -0
- data/lib/simplecov/profiles/rails.rb +18 -0
- data/lib/simplecov/profiles/root_filter.rb +10 -0
- data/lib/simplecov/profiles/test_frameworks.rb +8 -0
- data/lib/simplecov/profiles.rb +35 -0
- data/lib/simplecov/result.rb +33 -64
- data/lib/simplecov/result_adapter.rb +30 -0
- data/lib/simplecov/result_merger.rb +178 -64
- data/lib/simplecov/simulate_coverage.rb +29 -0
- data/lib/simplecov/source_file/branch.rb +84 -0
- data/lib/simplecov/source_file/line.rb +72 -0
- data/lib/simplecov/source_file.rb +304 -123
- data/lib/simplecov/useless_results_remover.rb +18 -0
- data/lib/simplecov/version.rb +4 -2
- data/lib/simplecov.rb +396 -49
- metadata +81 -242
- data/.gitignore +0 -30
- data/.rvmrc +0 -1
- data/.travis.yml +0 -13
- data/Gemfile +0 -9
- data/Rakefile +0 -16
- data/cucumber.yml +0 -13
- data/features/config_adapters.feature +0 -44
- data/features/config_autoload.feature +0 -46
- data/features/config_command_name.feature +0 -33
- data/features/config_coverage_dir.feature +0 -20
- data/features/config_deactivate_merging.feature +0 -42
- data/features/config_merge_timeout.feature +0 -38
- data/features/config_nocov_token.feature +0 -79
- data/features/config_project_name.feature +0 -27
- data/features/config_styles.feature +0 -93
- data/features/cucumber_basic.feature +0 -29
- data/features/merging_test_unit_and_rspec.feature +0 -44
- data/features/rspec_basic.feature +0 -31
- data/features/rspec_fails_on_initialization.feature +0 -14
- data/features/rspec_groups_and_filters_basic.feature +0 -29
- data/features/rspec_groups_and_filters_complex.feature +0 -35
- data/features/rspec_groups_using_filter_class.feature +0 -40
- data/features/rspec_without_simplecov.feature +0 -20
- data/features/skipping_code_blocks_manually.feature +0 -70
- data/features/step_definitions/html_steps.rb +0 -45
- data/features/step_definitions/simplecov_steps.rb +0 -61
- data/features/step_definitions/transformers.rb +0 -13
- data/features/step_definitions/web_steps.rb +0 -64
- data/features/support/env.rb +0 -26
- data/features/test_unit_basic.feature +0 -34
- data/features/test_unit_groups_and_filters_basic.feature +0 -29
- data/features/test_unit_groups_and_filters_complex.feature +0 -35
- data/features/test_unit_groups_using_filter_class.feature +0 -40
- data/features/test_unit_without_simplecov.feature +0 -20
- data/features/unicode_compatiblity.feature +0 -67
- data/lib/simplecov/adapters.rb +0 -29
- data/lib/simplecov/merge_helpers.rb +0 -39
- data/lib/simplecov/railtie.rb +0 -7
- data/lib/simplecov/railties/tasks.rake +0 -11
- data/simplecov.gemspec +0 -28
- data/test/faked_project/Gemfile +0 -6
- data/test/faked_project/Rakefile +0 -8
- data/test/faked_project/cucumber.yml +0 -13
- data/test/faked_project/features/step_definitions/my_steps.rb +0 -23
- data/test/faked_project/features/support/env.rb +0 -12
- data/test/faked_project/features/test_stuff.feature +0 -6
- data/test/faked_project/lib/faked_project/framework_specific.rb +0 -18
- data/test/faked_project/lib/faked_project/meta_magic.rb +0 -24
- data/test/faked_project/lib/faked_project/some_class.rb +0 -29
- data/test/faked_project/lib/faked_project.rb +0 -11
- data/test/faked_project/spec/faked_spec.rb +0 -11
- data/test/faked_project/spec/meta_magic_spec.rb +0 -10
- data/test/faked_project/spec/some_class_spec.rb +0 -10
- data/test/faked_project/spec/spec_helper.rb +0 -15
- data/test/faked_project/test/faked_test.rb +0 -11
- data/test/faked_project/test/meta_magic_test.rb +0 -13
- data/test/faked_project/test/some_class_test.rb +0 -15
- data/test/faked_project/test/test_helper.rb +0 -16
- data/test/fixtures/app/controllers/sample_controller.rb +0 -10
- data/test/fixtures/app/models/user.rb +0 -10
- data/test/fixtures/deleted_source_sample.rb +0 -15
- data/test/fixtures/frameworks/rspec_bad.rb +0 -9
- data/test/fixtures/frameworks/rspec_good.rb +0 -9
- data/test/fixtures/frameworks/testunit_bad.rb +0 -9
- data/test/fixtures/frameworks/testunit_good.rb +0 -9
- data/test/fixtures/resultset1.rb +0 -4
- data/test/fixtures/resultset2.rb +0 -5
- data/test/fixtures/sample.rb +0 -16
- data/test/fixtures/utf-8.rb +0 -3
- data/test/helper.rb +0 -35
- data/test/shoulda_macros.rb +0 -29
- data/test/test_1_8_fallbacks.rb +0 -33
- data/test/test_command_guesser.rb +0 -21
- data/test/test_deleted_source.rb +0 -16
- data/test/test_file_list.rb +0 -24
- data/test/test_filters.rb +0 -80
- data/test/test_merge_helpers.rb +0 -107
- data/test/test_result.rb +0 -147
- data/test/test_return_codes.rb +0 -39
- data/test/test_source_file.rb +0 -86
- data/test/test_source_file_line.rb +0 -110
@@ -1,13 +0,0 @@
|
|
1
|
-
require 'test_helper'
|
2
|
-
|
3
|
-
class MetaMagicTest < Test::Unit::TestCase
|
4
|
-
def test_class_methods
|
5
|
-
assert_equal "this is a mixed-in class method", FakedProject.a_class_method
|
6
|
-
end
|
7
|
-
|
8
|
-
def test_instance_methods
|
9
|
-
p = FakedProject.new
|
10
|
-
assert_equal "this is a mixed-in instance method", p.an_instance_method
|
11
|
-
assert_equal "A dynamically defined instance method", p.dynamic
|
12
|
-
end
|
13
|
-
end
|
@@ -1,15 +0,0 @@
|
|
1
|
-
require 'test_helper'
|
2
|
-
|
3
|
-
class SomeClassTest < Test::Unit::TestCase
|
4
|
-
def setup
|
5
|
-
@instance = SomeClass.new("foo")
|
6
|
-
end
|
7
|
-
|
8
|
-
def test_reverse
|
9
|
-
assert_equal 'oof', @instance.reverse
|
10
|
-
end
|
11
|
-
|
12
|
-
def test_comparison
|
13
|
-
assert @instance.compare_with('foo')
|
14
|
-
end
|
15
|
-
end
|
@@ -1,16 +0,0 @@
|
|
1
|
-
require 'bundler/setup'
|
2
|
-
|
3
|
-
# We're injecting simplecov_config via aruba in cucumber here
|
4
|
-
# depending on what the test case is...
|
5
|
-
begin
|
6
|
-
require File.join(File.dirname(__FILE__), 'simplecov_config')
|
7
|
-
rescue LoadError => err
|
8
|
-
$stderr.puts "No SimpleCov config file found!"
|
9
|
-
end
|
10
|
-
|
11
|
-
require 'faked_project'
|
12
|
-
|
13
|
-
require 'test/unit'
|
14
|
-
|
15
|
-
class Test::Unit::TestCase
|
16
|
-
end
|
@@ -1,15 +0,0 @@
|
|
1
|
-
$LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', '..'))
|
2
|
-
require 'lib/simplecov'
|
3
|
-
SimpleCov.start { command_name "Test" }
|
4
|
-
|
5
|
-
dir = File.expand_path(File.dirname(__FILE__))
|
6
|
-
file = File.join(dir, "generated_buddha.rb")
|
7
|
-
code = %{
|
8
|
-
def kill_the_buddha(z)
|
9
|
-
z**z
|
10
|
-
end
|
11
|
-
}
|
12
|
-
File.open(file, "w") { |f| f.print code }
|
13
|
-
load file
|
14
|
-
File.unlink file
|
15
|
-
raise unless kill_the_buddha(3) == 27
|
data/test/fixtures/resultset1.rb
DELETED
data/test/fixtures/resultset2.rb
DELETED
data/test/fixtures/sample.rb
DELETED
data/test/fixtures/utf-8.rb
DELETED
data/test/helper.rb
DELETED
@@ -1,35 +0,0 @@
|
|
1
|
-
require 'bundler/setup'
|
2
|
-
require 'simplecov'
|
3
|
-
require 'test/unit'
|
4
|
-
require 'shoulda'
|
5
|
-
|
6
|
-
SimpleCov.coverage_dir('tmp/coverage')
|
7
|
-
|
8
|
-
class Test::Unit::TestCase
|
9
|
-
def source_fixture(filename)
|
10
|
-
File.expand_path(File.join(File.dirname(__FILE__), 'fixtures', filename))
|
11
|
-
end
|
12
|
-
|
13
|
-
# Keep 1.8-rubies from complaining about missing tests in each file that covers only 1.9 functionality
|
14
|
-
def default_test
|
15
|
-
end
|
16
|
-
|
17
|
-
end
|
18
|
-
|
19
|
-
require 'shoulda_macros'
|
20
|
-
Test::Unit::TestCase.send :extend, ShouldaMacros
|
21
|
-
|
22
|
-
# Taken from http://stackoverflow.com/questions/4459330/how-do-i-temporarily-redirect-stderr-in-ruby
|
23
|
-
require "stringio"
|
24
|
-
|
25
|
-
def capture_stderr
|
26
|
-
# The output stream must be an IO-like object. In this case we capture it in
|
27
|
-
# an in-memory IO object so we can return the string value. You can assign any
|
28
|
-
# IO object here.
|
29
|
-
previous_stderr, $stderr = $stderr, StringIO.new
|
30
|
-
yield
|
31
|
-
$stderr.string
|
32
|
-
ensure
|
33
|
-
# Restore the previous value of stderr (typically equal to STDERR).
|
34
|
-
$stderr = previous_stderr
|
35
|
-
end
|
data/test/shoulda_macros.rb
DELETED
@@ -1,29 +0,0 @@
|
|
1
|
-
module ShouldaMacros
|
2
|
-
#
|
3
|
-
# Simple block helper for running certain tests only on specific ruby versions.
|
4
|
-
# The given strings will be regexp-matched against RUBY_VERSION
|
5
|
-
#
|
6
|
-
def on_ruby(*ruby_versions)
|
7
|
-
context "On Ruby #{RUBY_VERSION}" do
|
8
|
-
yield
|
9
|
-
end if ruby_versions.any? {|v| RUBY_VERSION =~ /#{v}/ }
|
10
|
-
end
|
11
|
-
|
12
|
-
def should_be(boolean_flag)
|
13
|
-
should "be #{boolean_flag}" do
|
14
|
-
assert_equal true, subject.send(boolean_flag)
|
15
|
-
end
|
16
|
-
end
|
17
|
-
|
18
|
-
def should_not_be(boolean_flag)
|
19
|
-
should "not be #{boolean_flag}" do
|
20
|
-
assert_equal false, subject.send(boolean_flag)
|
21
|
-
end
|
22
|
-
end
|
23
|
-
|
24
|
-
def should_have(attr_name, expectation)
|
25
|
-
should "have #{attr_name} == #{expectation.inspect}" do
|
26
|
-
assert_equal expectation, subject.send(attr_name)
|
27
|
-
end
|
28
|
-
end
|
29
|
-
end
|
data/test/test_1_8_fallbacks.rb
DELETED
@@ -1,33 +0,0 @@
|
|
1
|
-
require 'helper'
|
2
|
-
|
3
|
-
# Tests that verify that on 1.8 versions of ruby, simplecov simply
|
4
|
-
# does not launch and does not cause errors on the way
|
5
|
-
#
|
6
|
-
# TODO: This should be expanded upon all methods that could potentially
|
7
|
-
# be called in a test/spec-helper simplecov config block
|
8
|
-
#
|
9
|
-
class Test18FallBacks < Test::Unit::TestCase
|
10
|
-
on_ruby '1.8' do
|
11
|
-
should "return false when calling SimpleCov.start" do
|
12
|
-
assert_equal false, SimpleCov.start
|
13
|
-
end
|
14
|
-
|
15
|
-
should "return false when calling SimpleCov.start with a block" do
|
16
|
-
assert_equal false, SimpleCov.start { raise "Shouldn't reach this!?" }
|
17
|
-
end
|
18
|
-
|
19
|
-
should "return false when calling SimpleCov.configure with a block" do
|
20
|
-
assert_equal false, SimpleCov.configure { raise "Shouldn't reach this!?" }
|
21
|
-
end
|
22
|
-
|
23
|
-
should "allow to define an adapter" do
|
24
|
-
begin
|
25
|
-
SimpleCov.adapters.define 'testadapter' do
|
26
|
-
add_filter '/config/'
|
27
|
-
end
|
28
|
-
rescue => err
|
29
|
-
assert false, "Adapter definition should have been fine, but raised #{err}"
|
30
|
-
end
|
31
|
-
end
|
32
|
-
end
|
33
|
-
end
|
@@ -1,21 +0,0 @@
|
|
1
|
-
require 'helper'
|
2
|
-
|
3
|
-
class TestCommandGuesser < Test::Unit::TestCase
|
4
|
-
on_ruby '1.9' do
|
5
|
-
def self.should_guess_command_name(expectation, *argv)
|
6
|
-
argv.each do |args|
|
7
|
-
should "return '#{expectation}' for '#{args}'" do
|
8
|
-
SimpleCov::CommandGuesser.original_run_command = args
|
9
|
-
assert_equal expectation, SimpleCov::CommandGuesser.guess
|
10
|
-
end
|
11
|
-
end
|
12
|
-
end
|
13
|
-
|
14
|
-
should_guess_command_name "Unit Tests", '/some/path/test/units/foo_bar_test.rb', 'test/units/foo.rb', 'test/foo.rb'
|
15
|
-
should_guess_command_name "Functional Tests", '/some/path/test/functional/foo_bar_controller_test.rb'
|
16
|
-
should_guess_command_name "Integration Tests", '/some/path/test/integration/foo_bar_controller_test.rb'
|
17
|
-
should_guess_command_name "Cucumber Features", 'features', 'cucumber', 'cucumber features'
|
18
|
-
should_guess_command_name "RSpec", '/some/path/spec/foo.rb'
|
19
|
-
should_guess_command_name "Unit Tests", 'some_arbitrary_command with arguments' # Because Test::Unit const is defined!
|
20
|
-
end
|
21
|
-
end
|
data/test/test_deleted_source.rb
DELETED
@@ -1,16 +0,0 @@
|
|
1
|
-
require 'helper'
|
2
|
-
|
3
|
-
# Test to verify correct handling of deleted files,
|
4
|
-
# see issue #9 on github
|
5
|
-
class TestDeletedSource < Test::Unit::TestCase
|
6
|
-
on_ruby '1.8', '1.9' do
|
7
|
-
context "A source file which is subsequently deleted" do
|
8
|
-
should "not cause an error" do
|
9
|
-
Dir.chdir(File.join(File.dirname(__FILE__), 'fixtures')) do
|
10
|
-
`ruby deleted_source_sample.rb`
|
11
|
-
assert_equal 0, $?.exitstatus
|
12
|
-
end
|
13
|
-
end
|
14
|
-
end
|
15
|
-
end
|
16
|
-
end
|
data/test/test_file_list.rb
DELETED
@@ -1,24 +0,0 @@
|
|
1
|
-
require 'helper'
|
2
|
-
|
3
|
-
class TestFileList < Test::Unit::TestCase
|
4
|
-
on_ruby "1.9" do
|
5
|
-
context "With a file list from a result" do
|
6
|
-
setup do
|
7
|
-
original_result = {source_fixture('sample.rb') => [nil, 1, 1, 1, nil, nil, 1, 1, nil, nil],
|
8
|
-
source_fixture('app/models/user.rb') => [nil, 1, 1, 1, nil, nil, 1, 0, nil, nil],
|
9
|
-
source_fixture('app/controllers/sample_controller.rb') => [nil, 1, 1, 1, nil, nil, 1, 0, nil, nil]}
|
10
|
-
@file_list = SimpleCov::Result.new(original_result).files
|
11
|
-
end
|
12
|
-
|
13
|
-
should("have 13 covered_lines") { assert_equal 13, @file_list.covered_lines }
|
14
|
-
should("have 2 missed_lines") { assert_equal 2, @file_list.missed_lines }
|
15
|
-
should("have 18 never_lines") { assert_equal 18, @file_list.never_lines }
|
16
|
-
should("have 15 lines_of_code") { assert_equal 15, @file_list.lines_of_code }
|
17
|
-
should("have 3 skipped_lines") { assert_equal 3, @file_list.skipped_lines }
|
18
|
-
|
19
|
-
should "have correct covered_percent" do
|
20
|
-
assert_equal 100.0*13/15, @file_list.covered_percent
|
21
|
-
end
|
22
|
-
end
|
23
|
-
end
|
24
|
-
end
|
data/test/test_filters.rb
DELETED
@@ -1,80 +0,0 @@
|
|
1
|
-
require 'helper'
|
2
|
-
|
3
|
-
class TestFilters < Test::Unit::TestCase
|
4
|
-
on_ruby '1.9' do
|
5
|
-
context "A source file initialized with some coverage data" do
|
6
|
-
setup do
|
7
|
-
@source_file = SimpleCov::SourceFile.new(source_fixture('sample.rb'), [nil, 1, 1, 1, nil, nil, 1, 0, nil, nil])
|
8
|
-
end
|
9
|
-
|
10
|
-
should "not match a new SimpleCov::StringFilter 'foobar'" do
|
11
|
-
assert !SimpleCov::StringFilter.new('foobar').matches?(@source_file)
|
12
|
-
end
|
13
|
-
|
14
|
-
should "not match a new SimpleCov::StringFilter 'some/path'" do
|
15
|
-
assert !SimpleCov::StringFilter.new('some/path').matches?(@source_file)
|
16
|
-
end
|
17
|
-
|
18
|
-
should "match a new SimpleCov::StringFilter 'test/fixtures'" do
|
19
|
-
assert SimpleCov::StringFilter.new('test/fixtures').matches?(@source_file)
|
20
|
-
end
|
21
|
-
|
22
|
-
should "match a new SimpleCov::StringFilter 'test/fixtures/sample.rb'" do
|
23
|
-
assert SimpleCov::StringFilter.new('test/fixtures/sample.rb').matches?(@source_file)
|
24
|
-
end
|
25
|
-
|
26
|
-
should "match a new SimpleCov::StringFilter 'sample.rb'" do
|
27
|
-
assert SimpleCov::StringFilter.new('sample.rb').matches?(@source_file)
|
28
|
-
end
|
29
|
-
|
30
|
-
should "not match a new SimpleCov::BlockFilter that is not applicable" do
|
31
|
-
assert !SimpleCov::BlockFilter.new(Proc.new {|s| File.basename(s.filename) == 'foo.rb'}).matches?(@source_file)
|
32
|
-
end
|
33
|
-
|
34
|
-
should "match a new SimpleCov::BlockFilter that is applicable" do
|
35
|
-
assert SimpleCov::BlockFilter.new(Proc.new {|s| File.basename(s.filename) == 'sample.rb'}).matches?(@source_file)
|
36
|
-
end
|
37
|
-
end
|
38
|
-
|
39
|
-
context "with no filters set up and a basic source file in an array" do
|
40
|
-
setup do
|
41
|
-
SimpleCov.filters = []
|
42
|
-
@files = [SimpleCov::SourceFile.new(source_fixture('sample.rb'), [nil, 1, 1, 1, nil, nil, 1, 0, nil, nil])]
|
43
|
-
end
|
44
|
-
|
45
|
-
should "return 0 items after executing SimpleCov.filtered on files when using a 'sample' string filter" do
|
46
|
-
SimpleCov.add_filter "sample"
|
47
|
-
assert_equal 0, SimpleCov.filtered(@files).count
|
48
|
-
end
|
49
|
-
|
50
|
-
should "return 0 items after executing SimpleCov.filtered on files when using a 'test/fixtures/' string filter" do
|
51
|
-
SimpleCov.add_filter "test/fixtures"
|
52
|
-
assert_equal 0, SimpleCov.filtered(@files).count
|
53
|
-
end
|
54
|
-
|
55
|
-
should "return 1 item after executing SimpleCov.filtered on files when using a 'fooo' string filter" do
|
56
|
-
SimpleCov.add_filter "fooo"
|
57
|
-
assert_equal 1, SimpleCov.filtered(@files).count
|
58
|
-
end
|
59
|
-
|
60
|
-
should "return 0 items after executing SimpleCov.filtered on files when using a block filter that returns true" do
|
61
|
-
SimpleCov.add_filter do |src_file|
|
62
|
-
true
|
63
|
-
end
|
64
|
-
assert_equal 0, SimpleCov.filtered(@files).count
|
65
|
-
end
|
66
|
-
|
67
|
-
should "return 1 item after executing SimpleCov.filtered on files when using an always-false block filter" do
|
68
|
-
SimpleCov.add_filter do |src_file|
|
69
|
-
false
|
70
|
-
end
|
71
|
-
assert_equal 1, SimpleCov.filtered(@files).count
|
72
|
-
end
|
73
|
-
|
74
|
-
should "return a FileList after filtering" do
|
75
|
-
SimpleCov.add_filter "fooo"
|
76
|
-
assert_equal SimpleCov::FileList, SimpleCov.filtered(@files).class
|
77
|
-
end
|
78
|
-
end
|
79
|
-
end
|
80
|
-
end
|
data/test/test_merge_helpers.rb
DELETED
@@ -1,107 +0,0 @@
|
|
1
|
-
require 'helper'
|
2
|
-
|
3
|
-
class TestMergeHelpers < Test::Unit::TestCase
|
4
|
-
on_ruby '1.9' do
|
5
|
-
context "With two faked coverage resultsets" do
|
6
|
-
setup do
|
7
|
-
SimpleCov.use_merging true
|
8
|
-
@resultset1 = {source_fixture('sample.rb') => [nil, 1, 1, 1, nil, nil, 1, 1, nil, nil],
|
9
|
-
source_fixture('app/models/user.rb') => [nil, 1, 1, 1, nil, nil, 1, 0, nil, nil],
|
10
|
-
source_fixture('app/controllers/sample_controller.rb') => [nil, 1, 1, 1, nil, nil, 1, 0, nil, nil],
|
11
|
-
source_fixture('resultset1.rb') => [1, 1, 1, 1]}
|
12
|
-
|
13
|
-
@resultset2 = {source_fixture('sample.rb') => [1, nil, 1, 1, nil, nil, 1, 1, nil, nil],
|
14
|
-
source_fixture('app/models/user.rb') => [nil, 1, 5, 1, nil, nil, 1, 0, nil, nil],
|
15
|
-
source_fixture('app/controllers/sample_controller.rb') => [nil, 3, 1, nil, nil, nil, 1, 0, nil, nil],
|
16
|
-
source_fixture('resultset2.rb') => [nil, 1, 1, nil]}
|
17
|
-
end
|
18
|
-
|
19
|
-
context "a merge" do
|
20
|
-
setup do
|
21
|
-
assert @merged = @resultset1.merge_resultset(@resultset2)
|
22
|
-
end
|
23
|
-
|
24
|
-
should "have proper results for sample.rb" do
|
25
|
-
assert_equal [1, 1, 2, 2, nil, nil, 2, 2, nil, nil], @merged[source_fixture('sample.rb')]
|
26
|
-
end
|
27
|
-
|
28
|
-
should "have proper results for user.rb" do
|
29
|
-
assert_equal [nil, 2, 6, 2, nil, nil, 2, 0, nil, nil], @merged[source_fixture('app/models/user.rb')]
|
30
|
-
end
|
31
|
-
|
32
|
-
should "have proper results for sample_controller.rb" do
|
33
|
-
assert_equal [nil, 4, 2, 1, nil, nil, 2, 0, nil, nil], @merged[source_fixture('app/controllers/sample_controller.rb')]
|
34
|
-
end
|
35
|
-
|
36
|
-
should "have proper results for resultset1.rb" do
|
37
|
-
assert_equal [1, 1, 1, 1], @merged[source_fixture('resultset1.rb')]
|
38
|
-
end
|
39
|
-
|
40
|
-
should "have proper results for resultset2.rb" do
|
41
|
-
assert_equal [nil, 1, 1, nil], @merged[source_fixture('resultset2.rb')]
|
42
|
-
end
|
43
|
-
end
|
44
|
-
|
45
|
-
# See Github issue #6
|
46
|
-
should "return an empty hash when the resultset cache file is empty" do
|
47
|
-
File.open(SimpleCov::ResultMerger.resultset_path, "w+") {|f| f.puts ""}
|
48
|
-
assert_equal Hash.new, SimpleCov::ResultMerger.resultset
|
49
|
-
end
|
50
|
-
|
51
|
-
# See Github issue #6
|
52
|
-
should "return an empty hash when the resultset cache file is not present" do
|
53
|
-
system "rm #{SimpleCov::ResultMerger.resultset_path}" if File.exist?(SimpleCov::ResultMerger.resultset_path)
|
54
|
-
assert_equal Hash.new, SimpleCov::ResultMerger.resultset
|
55
|
-
end
|
56
|
-
|
57
|
-
context "and results generated from those" do
|
58
|
-
setup do
|
59
|
-
system "rm #{SimpleCov::ResultMerger.resultset_path}" if File.exist?(SimpleCov::ResultMerger.resultset_path)
|
60
|
-
@result1 = SimpleCov::Result.new(@resultset1)
|
61
|
-
@result1.command_name = "result1"
|
62
|
-
@result2 = SimpleCov::Result.new(@resultset2)
|
63
|
-
@result2.command_name = "result2"
|
64
|
-
end
|
65
|
-
|
66
|
-
context "with stored results" do
|
67
|
-
setup do
|
68
|
-
assert SimpleCov::ResultMerger.store_result(@result1)
|
69
|
-
assert SimpleCov::ResultMerger.store_result(@result2)
|
70
|
-
end
|
71
|
-
|
72
|
-
should "have stored data in resultset_path yaml file" do
|
73
|
-
assert File.readlines(SimpleCov::ResultMerger.resultset_path).length > 50
|
74
|
-
end
|
75
|
-
|
76
|
-
should "return a hash containing keys ['result1' and 'result2'] for resultset" do
|
77
|
-
assert_equal ['result1', 'result2'], SimpleCov::ResultMerger.resultset.keys.sort
|
78
|
-
end
|
79
|
-
|
80
|
-
should "return proper values for merged_result" do
|
81
|
-
assert_equal [nil, 2, 6, 2, nil, nil, 2, 0, nil, nil], SimpleCov::ResultMerger.merged_result.source_files.find {|s| s.filename =~ /user/}.lines.map(&:coverage)
|
82
|
-
end
|
83
|
-
|
84
|
-
context "with second result way above the merge_timeout" do
|
85
|
-
setup do
|
86
|
-
@result2.created_at = Time.now - 172800 # two days ago
|
87
|
-
assert SimpleCov::ResultMerger.store_result(@result2)
|
88
|
-
end
|
89
|
-
|
90
|
-
should "have only one result in SimpleCov::ResultMerger.results" do
|
91
|
-
assert_equal 1, SimpleCov::ResultMerger.results.length
|
92
|
-
end
|
93
|
-
end
|
94
|
-
|
95
|
-
context "with merging disabled" do
|
96
|
-
setup { SimpleCov.use_merging false }
|
97
|
-
|
98
|
-
should "return nil for SimpleCov.result" do
|
99
|
-
assert_nil SimpleCov.result
|
100
|
-
end
|
101
|
-
end
|
102
|
-
end
|
103
|
-
|
104
|
-
end
|
105
|
-
end
|
106
|
-
end
|
107
|
-
end
|
data/test/test_result.rb
DELETED
@@ -1,147 +0,0 @@
|
|
1
|
-
require 'helper'
|
2
|
-
|
3
|
-
class TestResult < Test::Unit::TestCase
|
4
|
-
on_ruby "1.9" do
|
5
|
-
context "With a (mocked) Coverage.result" do
|
6
|
-
setup do
|
7
|
-
SimpleCov.filters = []
|
8
|
-
SimpleCov.groups = {}
|
9
|
-
SimpleCov.formatter = nil
|
10
|
-
@original_result = {source_fixture('sample.rb') => [nil, 1, 1, 1, nil, nil, 1, 1, nil, nil],
|
11
|
-
source_fixture('app/models/user.rb') => [nil, 1, 1, 1, nil, nil, 1, 0, nil, nil],
|
12
|
-
source_fixture('app/controllers/sample_controller.rb') => [nil, 1, 1, 1, nil, nil, 1, 0, nil, nil]}
|
13
|
-
end
|
14
|
-
|
15
|
-
context "a simple cov result initialized from that" do
|
16
|
-
setup { @result = SimpleCov::Result.new(@original_result) }
|
17
|
-
|
18
|
-
should "have 3 filenames" do
|
19
|
-
assert_equal 3, @result.filenames.count
|
20
|
-
end
|
21
|
-
|
22
|
-
should "have 3 source files" do
|
23
|
-
assert_equal 3, @result.source_files.count
|
24
|
-
assert @result.source_files.all? {|s| s.instance_of?(SimpleCov::SourceFile)}, "Not alL instances are of SimpleCov::SourceFile type"
|
25
|
-
end
|
26
|
-
|
27
|
-
should "return an instance of SimpleCov::FileList for source_files and files" do
|
28
|
-
assert_equal SimpleCov::FileList, @result.source_files.class
|
29
|
-
assert_equal SimpleCov::FileList, @result.files.class
|
30
|
-
end
|
31
|
-
|
32
|
-
should "have files equal to source_files" do
|
33
|
-
assert_equal @result.files, @result.source_files
|
34
|
-
end
|
35
|
-
|
36
|
-
should "have accurate covered percent" do
|
37
|
-
# in our fixture, there are 13 covered line (result in 1) in all 15 relevant line (result in non-nil)
|
38
|
-
assert_equal 100.0*13/15, @result.covered_percent
|
39
|
-
end
|
40
|
-
|
41
|
-
context "dumped with to_hash" do
|
42
|
-
setup { @hash = @result.to_hash }
|
43
|
-
should("be a hash") { assert_equal Hash, @hash.class }
|
44
|
-
|
45
|
-
context "loaded back with from_yaml" do
|
46
|
-
setup { @dumped_result = SimpleCov::Result.from_hash(@hash) }
|
47
|
-
|
48
|
-
should "have 3 source files" do
|
49
|
-
assert_equal @result.source_files.count, @dumped_result.source_files.count
|
50
|
-
end
|
51
|
-
|
52
|
-
should "have the same covered_percent" do
|
53
|
-
assert_equal @result.covered_percent, @dumped_result.covered_percent
|
54
|
-
end
|
55
|
-
|
56
|
-
should "have the same timestamp" do
|
57
|
-
assert_equal @result.created_at.to_i, @dumped_result.created_at.to_i
|
58
|
-
end
|
59
|
-
|
60
|
-
should "have the same command_name" do
|
61
|
-
assert_equal @result.command_name, @dumped_result.command_name
|
62
|
-
end
|
63
|
-
|
64
|
-
should "have the same original_result" do
|
65
|
-
assert_equal @result.original_result, @dumped_result.original_result
|
66
|
-
end
|
67
|
-
end
|
68
|
-
end
|
69
|
-
end
|
70
|
-
|
71
|
-
context "with some filters set up" do
|
72
|
-
setup do
|
73
|
-
SimpleCov.add_filter 'sample.rb'
|
74
|
-
end
|
75
|
-
|
76
|
-
should "have 2 files in a new simple cov result" do
|
77
|
-
assert_equal 2, SimpleCov::Result.new(@original_result).source_files.length
|
78
|
-
end
|
79
|
-
|
80
|
-
should "have 80 covered percent" do
|
81
|
-
assert_equal 80, SimpleCov::Result.new(@original_result).covered_percent
|
82
|
-
end
|
83
|
-
end
|
84
|
-
|
85
|
-
context "with groups set up for all files" do
|
86
|
-
setup do
|
87
|
-
SimpleCov.add_group 'Models', 'app/models'
|
88
|
-
SimpleCov.add_group 'Controllers', 'app/controllers'
|
89
|
-
SimpleCov.add_group 'Other' do |src_file|
|
90
|
-
File.basename(src_file.filename) == 'sample.rb'
|
91
|
-
end
|
92
|
-
@result = SimpleCov::Result.new(@original_result)
|
93
|
-
end
|
94
|
-
|
95
|
-
should "have 3 groups" do
|
96
|
-
assert_equal 3, @result.groups.length
|
97
|
-
end
|
98
|
-
|
99
|
-
should "have user.rb in 'Models' group" do
|
100
|
-
assert_equal 'user.rb', File.basename(@result.groups['Models'].first.filename)
|
101
|
-
end
|
102
|
-
|
103
|
-
should "have sample_controller.rb in 'Controllers' group" do
|
104
|
-
assert_equal 'sample_controller.rb', File.basename(@result.groups['Controllers'].first.filename)
|
105
|
-
end
|
106
|
-
|
107
|
-
context "and simple formatter being used" do
|
108
|
-
setup {SimpleCov.formatter = SimpleCov::Formatter::SimpleFormatter}
|
109
|
-
|
110
|
-
should "return a formatted string with result.format!" do
|
111
|
-
assert_equal String, @result.format!.class
|
112
|
-
end
|
113
|
-
end
|
114
|
-
end
|
115
|
-
|
116
|
-
context "with groups set up that do not match all files" do
|
117
|
-
setup do
|
118
|
-
SimpleCov.configure do
|
119
|
-
add_group 'Models', 'app/models'
|
120
|
-
add_group 'Controllers', 'app/controllers'
|
121
|
-
end
|
122
|
-
@result = SimpleCov::Result.new(@original_result)
|
123
|
-
end
|
124
|
-
|
125
|
-
should "have 3 groups" do
|
126
|
-
assert_equal 3, @result.groups.length
|
127
|
-
end
|
128
|
-
|
129
|
-
should "have 1 item per group" do
|
130
|
-
@result.groups.each do |name, files|
|
131
|
-
assert_equal 1, files.length, "Group #{name} should have 1 file"
|
132
|
-
end
|
133
|
-
end
|
134
|
-
|
135
|
-
should "have sample.rb in 'Ungrouped' group" do
|
136
|
-
assert_equal 'sample.rb', File.basename(@result.groups['Ungrouped'].first.filename)
|
137
|
-
end
|
138
|
-
|
139
|
-
should "return all groups as instances of SimpleCov::FileList" do
|
140
|
-
@result.groups.each do |name, files|
|
141
|
-
assert_equal SimpleCov::FileList, files.class
|
142
|
-
end
|
143
|
-
end
|
144
|
-
end
|
145
|
-
end
|
146
|
-
end
|
147
|
-
end
|