simplecov 0.4.2 → 0.5.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (87) hide show
  1. data/.gitignore +4 -1
  2. data/.rvmrc +1 -1
  3. data/.travis.yml +9 -0
  4. data/CHANGELOG.md +64 -0
  5. data/Gemfile +7 -0
  6. data/README.rdoc +83 -66
  7. data/Rakefile +3 -7
  8. data/cucumber.yml +13 -0
  9. data/features/config_adapters.feature +44 -0
  10. data/features/config_autoload.feature +46 -0
  11. data/features/config_command_name.feature +33 -0
  12. data/features/config_coverage_dir.feature +20 -0
  13. data/features/config_deactivate_merging.feature +42 -0
  14. data/features/config_merge_timeout.feature +38 -0
  15. data/features/config_project_name.feature +27 -0
  16. data/features/config_styles.feature +93 -0
  17. data/features/cucumber_basic.feature +29 -0
  18. data/features/merging_test_unit_and_rspec.feature +44 -0
  19. data/features/rspec_basic.feature +31 -0
  20. data/features/rspec_groups_and_filters_basic.feature +29 -0
  21. data/features/rspec_groups_and_filters_complex.feature +35 -0
  22. data/features/rspec_without_simplecov.feature +20 -0
  23. data/features/step_definitions/html_steps.rb +42 -0
  24. data/features/step_definitions/simplecov_steps.rb +61 -0
  25. data/features/step_definitions/transformers.rb +13 -0
  26. data/features/step_definitions/web_steps.rb +64 -0
  27. data/features/support/env.rb +26 -0
  28. data/features/test_unit_basic.feature +34 -0
  29. data/features/test_unit_groups_and_filters_basic.feature +29 -0
  30. data/features/test_unit_groups_and_filters_complex.feature +35 -0
  31. data/features/test_unit_without_simplecov.feature +20 -0
  32. data/lib/simplecov.rb +15 -30
  33. data/lib/simplecov/adapters.rb +3 -26
  34. data/lib/simplecov/command_guesser.rb +2 -2
  35. data/lib/simplecov/configuration.rb +21 -21
  36. data/lib/simplecov/defaults.rb +48 -0
  37. data/lib/simplecov/file_list.rb +44 -0
  38. data/lib/simplecov/filter.rb +5 -5
  39. data/lib/simplecov/formatter.rb +1 -1
  40. data/lib/simplecov/formatter/simple_formatter.rb +1 -1
  41. data/lib/simplecov/jruby_float_fix.rb +1 -1
  42. data/lib/simplecov/merge_helpers.rb +4 -4
  43. data/lib/simplecov/result.rb +33 -30
  44. data/lib/simplecov/result_merger.rb +30 -13
  45. data/lib/simplecov/source_file.rb +78 -21
  46. data/lib/simplecov/version.rb +1 -1
  47. data/simplecov.gemspec +25 -22
  48. data/test/faked_project/Gemfile +6 -0
  49. data/test/faked_project/Rakefile +8 -0
  50. data/test/faked_project/cucumber.yml +13 -0
  51. data/test/faked_project/features/step_definitions/my_steps.rb +23 -0
  52. data/test/faked_project/features/support/env.rb +12 -0
  53. data/test/faked_project/features/test_stuff.feature +6 -0
  54. data/test/faked_project/lib/faked_project.rb +11 -0
  55. data/test/faked_project/lib/faked_project/framework_specific.rb +18 -0
  56. data/test/faked_project/lib/faked_project/meta_magic.rb +24 -0
  57. data/test/faked_project/lib/faked_project/some_class.rb +29 -0
  58. data/test/faked_project/spec/faked_spec.rb +11 -0
  59. data/test/faked_project/spec/meta_magic_spec.rb +10 -0
  60. data/test/faked_project/spec/some_class_spec.rb +10 -0
  61. data/test/faked_project/spec/spec_helper.rb +15 -0
  62. data/test/faked_project/test/faked_test.rb +11 -0
  63. data/test/faked_project/test/meta_magic_test.rb +13 -0
  64. data/test/faked_project/test/some_class_test.rb +15 -0
  65. data/test/faked_project/test/test_helper.rb +16 -0
  66. data/test/fixtures/app/controllers/sample_controller.rb +2 -2
  67. data/test/fixtures/app/models/user.rb +2 -2
  68. data/test/fixtures/frameworks/rspec_bad.rb +1 -1
  69. data/test/fixtures/frameworks/rspec_good.rb +1 -1
  70. data/test/fixtures/frameworks/testunit_bad.rb +1 -1
  71. data/test/fixtures/frameworks/testunit_good.rb +1 -1
  72. data/test/fixtures/resultset1.rb +1 -1
  73. data/test/fixtures/resultset2.rb +1 -1
  74. data/test/fixtures/sample.rb +8 -2
  75. data/test/helper.rb +17 -4
  76. data/test/shoulda_macros.rb +2 -2
  77. data/test/test_1_8_fallbacks.rb +3 -3
  78. data/test/test_command_guesser.rb +3 -3
  79. data/test/test_file_list.rb +24 -0
  80. data/test/test_filters.rb +18 -13
  81. data/test/test_merge_helpers.rb +23 -23
  82. data/test/test_result.rb +40 -31
  83. data/test/test_return_codes.rb +5 -5
  84. data/test/test_source_file.rb +39 -15
  85. data/test/test_source_file_line.rb +22 -22
  86. metadata +191 -53
  87. data/.document +0 -5
data/cucumber.yml ADDED
@@ -0,0 +1,13 @@
1
+ <%
2
+ rerun = File.file?('rerun.txt') ? IO.read('rerun.txt') : ""
3
+ rerun_opts = rerun.to_s.strip.empty? ? "--format #{ENV['CUCUMBER_FORMAT'] || 'progress'} features" : "--format #{ENV['CUCUMBER_FORMAT'] || 'pretty'} #{rerun}"
4
+ std_opts = "--format #{ENV['CUCUMBER_FORMAT'] || 'progress'} --strict --tags ~@wip"
5
+ interp_opts = if defined?(RUBY_ENGINE)
6
+ " --tags ~@exclude-#{RUBY_ENGINE}"
7
+ else
8
+ ''
9
+ end
10
+ %>
11
+ default: <%= std_opts %><%= interp_opts %> features
12
+ wip: --tags @wip:30 --wip features<%= interp_opts %>
13
+ rerun: <%= rerun_opts %> --format rerun --out rerun.txt --strict --tags ~@wip<%= interp_opts %>
@@ -0,0 +1,44 @@
1
+ @test_unit @config @adapters
2
+ Feature:
3
+
4
+ In order to re-use SimpleCov settings across projects,
5
+ adapters can be defined that hold configuration settings
6
+ that can be loaded at once.
7
+
8
+ Background:
9
+ Given SimpleCov for Test/Unit is configured with:
10
+ """
11
+ require 'simplecov'
12
+ """
13
+
14
+ Scenario: Defining and using a custom adapter
15
+ Given a file named ".simplecov" with:
16
+ """
17
+ SimpleCov.adapters.define 'custom_command' do
18
+ command_name "Adapter Command"
19
+ end
20
+
21
+ SimpleCov.start do
22
+ load_adapter 'test_frameworks'
23
+ load_adapter 'custom_command'
24
+ end
25
+ """
26
+
27
+ When I open the coverage report generated with `bundle exec rake test`
28
+ Then I should see "4 files in total."
29
+ And I should see "using Adapter Command" within "#footer"
30
+
31
+ Scenario: Using existing adapter in custom adapter and supplying adapter to start command
32
+ Given a file named ".simplecov" with:
33
+ """
34
+ SimpleCov.adapters.define 'my_adapter' do
35
+ load_adapter 'test_frameworks'
36
+ command_name "My Adapter"
37
+ end
38
+
39
+ SimpleCov.start 'my_adapter'
40
+ """
41
+
42
+ When I open the coverage report generated with `bundle exec rake test`
43
+ Then I should see "4 files in total."
44
+ And I should see "using My Adapter" within "#footer"
@@ -0,0 +1,46 @@
1
+ @test_unit @rspec @config
2
+ Feature:
3
+
4
+ If you have multiple test suites, it can be a bit cumbersome
5
+ to keep the configuration across them in sync. SimpleCov
6
+ is able to find a config file called '.simplecov' that resides
7
+ in your project's root and will automatically use it when
8
+ loaded.
9
+
10
+ This gives you the ability to configure SimpleCov just once
11
+ and then use the same configuration on all test suites simply
12
+ by doing a 'require "simplecov"'
13
+
14
+ Scenario:
15
+ Given a file named ".simplecov" with:
16
+ """
17
+ SimpleCov.start do
18
+ add_filter 'test.rb'
19
+ add_filter 'spec.rb'
20
+ end
21
+ """
22
+ Given SimpleCov for Test/Unit is configured with:
23
+ """
24
+ require 'simplecov'
25
+ """
26
+ Given SimpleCov for RSpec is configured with:
27
+ """
28
+ require 'simplecov'
29
+ """
30
+
31
+ When I successfully run `bundle exec rake test`
32
+ And I open the coverage report generated with `bundle exec rspec spec`
33
+ Then the report should be based upon:
34
+ | RSpec |
35
+ | Unit Tests |
36
+
37
+ And I should see the groups:
38
+ | name | coverage | files |
39
+ | All Files | 90.7% | 4 |
40
+
41
+ And I should see the source files:
42
+ | name | coverage |
43
+ | lib/faked_project.rb | 100.0 % |
44
+ | lib/faked_project/some_class.rb | 80.0 % |
45
+ | lib/faked_project/framework_specific.rb | 87.5 % |
46
+ | lib/faked_project/meta_magic.rb | 100.0 % |
@@ -0,0 +1,33 @@
1
+ @test_unit @rspec @merging @config
2
+ Feature: Custom names for individual test suites
3
+
4
+ Each test suite needs a name it can be identified by. SimpleCov tries
5
+ best to detect Rails' Unit, Functional, Integration tests as well as regular
6
+ Test/Unit, RSpec and Cucumber, but if that is insufficient, each test suite
7
+ config can be given a custom command name using SimpleCov.command_name.
8
+
9
+ Scenario:
10
+ Given SimpleCov for Test/Unit is configured with:
11
+ """
12
+ require 'simplecov'
13
+ SimpleCov.start do
14
+ command_name "I'm in UR Unitz"
15
+ end
16
+ """
17
+ Given SimpleCov for RSpec is configured with:
18
+ """
19
+ require 'simplecov'
20
+ SimpleCov.start do
21
+ command_name "Dreck macht Speck"
22
+ end
23
+ """
24
+
25
+ When I open the coverage report generated with `bundle exec rake test`
26
+ Then the report should be based upon:
27
+ | I'm in UR Unitz |
28
+
29
+ When I open the coverage report generated with `bundle exec rspec spec`
30
+ Then the report should be based upon:
31
+ | Dreck macht Speck |
32
+ | I'm in UR Unitz |
33
+
@@ -0,0 +1,20 @@
1
+ @test_unit @config
2
+ Feature:
3
+
4
+ The output directory for test coverage can be customized
5
+ with the SimpleCov.coverage_dir setting. All coverage reports
6
+ will be put there instead of the default 'coverage' directory
7
+ in your project's root.
8
+
9
+ Scenario:
10
+ Given SimpleCov for Test/Unit is configured with:
11
+ """
12
+ require 'simplecov'
13
+ SimpleCov.start do
14
+ coverage_dir 'test/simplecov'
15
+ end
16
+ """
17
+
18
+ When I successfully run `bundle exec rake test`
19
+ Then a coverage report should have been generated in "test/simplecov"
20
+ And a directory named "coverage" should not exist
@@ -0,0 +1,42 @@
1
+ @test_unit @rspec @merging @config
2
+ Feature:
3
+
4
+ If merging of test suite results is not desired, it can be deactivated,
5
+ thus leading to the coverage report being overwritten with the latest results
6
+ of a single test suite on each run of any suite.
7
+
8
+ It's probably preferrable to generate the individual suite results into separate
9
+ output directories instead (see SimpleCov.coverage_dir), but it is possible :)
10
+
11
+ Scenario:
12
+ Given SimpleCov for Test/Unit is configured with:
13
+ """
14
+ require 'simplecov'
15
+ SimpleCov.start do
16
+ use_merging false
17
+ end
18
+ """
19
+ Given SimpleCov for RSpec is configured with:
20
+ """
21
+ require 'simplecov'
22
+ SimpleCov.start do
23
+ use_merging false
24
+ end
25
+ """
26
+
27
+ When I successfully run `bundle exec rake test`
28
+ Then a file named "coverage/index.html" should exist
29
+ But a file named "coverage/.resultset.json" should not exist
30
+
31
+ Given I open the coverage report
32
+ Then the report should be based upon:
33
+ | Unit Tests |
34
+
35
+ When I successfully run `bundle exec rspec spec`
36
+ Then a file named "coverage/index.html" should exist
37
+ But a file named "coverage/.resultset.json" should not exist
38
+
39
+ Given I open the coverage report
40
+ Then the report should be based upon:
41
+ | RSpec |
42
+
@@ -0,0 +1,38 @@
1
+ @test_unit @rspec @merging @config
2
+ Feature:
3
+
4
+ The maximum time between resultset merges can be customized
5
+ using SimpleCov.merge_timeout SECONDS. This can be helpful for
6
+ long-running test-suites that fail to merge because of the time
7
+ between individual suite finishes is more then the default timeout
8
+ of 10 minutes.
9
+
10
+ Here, for the sake of testing the opposite case is shown, choosing
11
+ a merge timeout so short that the first test suite's results actually
12
+ are out of date when the second suite finishes and thus does not end up
13
+ in the report.
14
+
15
+ Scenario:
16
+ Given SimpleCov for Test/Unit is configured with:
17
+ """
18
+ require 'simplecov'
19
+ SimpleCov.start do
20
+ merge_timeout 1
21
+ end
22
+ """
23
+ Given SimpleCov for RSpec is configured with:
24
+ """
25
+ require 'simplecov'
26
+ SimpleCov.start do
27
+ merge_timeout 1
28
+ end
29
+ """
30
+
31
+ When I open the coverage report generated with `bundle exec rake test`
32
+ Then the report should be based upon:
33
+ | Unit Tests |
34
+
35
+ When I open the coverage report generated with `bundle exec rspec spec`
36
+ Then the report should be based upon:
37
+ | RSpec |
38
+
@@ -0,0 +1,27 @@
1
+ @test_unit @config
2
+ Feature:
3
+
4
+ SimpleCov guesses the project name from the project root dir's name.
5
+ If this is not sufficient for you, you can specify a custom name using
6
+ SimpleCov.project_name('xyz')
7
+
8
+
9
+ Scenario: Guessed name
10
+ Given SimpleCov for Test/Unit is configured with:
11
+ """
12
+ require 'simplecov'
13
+ SimpleCov.start
14
+ """
15
+
16
+ When I open the coverage report generated with `bundle exec rake test`
17
+ Then I should see "Code coverage for Project"
18
+
19
+ Scenario: Custom name
20
+ Given SimpleCov for Test/Unit is configured with:
21
+ """
22
+ require 'simplecov'
23
+ SimpleCov.start { project_name "Superfancy 2.0" }
24
+ """
25
+
26
+ When I open the coverage report generated with `bundle exec rake test`
27
+ Then I should see "Code coverage for Superfancy 2.0"
@@ -0,0 +1,93 @@
1
+ @test_unit @config
2
+ Feature:
3
+
4
+ There's several ways to configure SimpleCov. All of those
5
+ config schemes below are equivalent and can be chosen by personal
6
+ preference or project requirements.
7
+
8
+ Background:
9
+ Given SimpleCov for Test/Unit is configured with:
10
+ """
11
+ require 'simplecov'
12
+ """
13
+
14
+ Scenario: Inside start block
15
+ Given a file named ".simplecov" with:
16
+ """
17
+ SimpleCov.start do
18
+ add_filter 'test'
19
+ command_name 'Config Test Runner'
20
+ end
21
+ """
22
+
23
+ When I open the coverage report generated with `bundle exec rake test`
24
+ Then I should see "4 files in total."
25
+ And I should see "using Config Test Runner" within "#footer"
26
+
27
+ Scenario: Explicitly before start block
28
+ Given a file named ".simplecov" with:
29
+ """
30
+ SimpleCov.add_filter 'test'
31
+ SimpleCov.command_name 'Config Test Runner'
32
+ SimpleCov.start
33
+ """
34
+
35
+ When I open the coverage report generated with `bundle exec rake test`
36
+ Then I should see "4 files in total."
37
+ And I should see "using Config Test Runner" within "#footer"
38
+
39
+ Scenario: Explicitly after start block
40
+ Given a file named ".simplecov" with:
41
+ """
42
+ SimpleCov.start
43
+ SimpleCov.add_filter 'test'
44
+ SimpleCov.command_name 'Config Test Runner'
45
+ """
46
+
47
+ When I open the coverage report generated with `bundle exec rake test`
48
+ Then I should see "4 files in total."
49
+ And I should see "using Config Test Runner" within "#footer"
50
+
51
+ Scenario: Using configure block after start
52
+ Given a file named ".simplecov" with:
53
+ """
54
+ SimpleCov.start
55
+ SimpleCov.configure do
56
+ add_filter 'test'
57
+ command_name 'Config Test Runner'
58
+ end
59
+ """
60
+
61
+ When I open the coverage report generated with `bundle exec rake test`
62
+ Then I should see "4 files in total."
63
+ And I should see "using Config Test Runner" within "#footer"
64
+
65
+ Scenario: Using configure block before start
66
+ Given a file named ".simplecov" with:
67
+ """
68
+ SimpleCov.configure do
69
+ add_filter 'test'
70
+ command_name 'Config Test Runner'
71
+ end
72
+ SimpleCov.start
73
+ """
74
+
75
+ When I open the coverage report generated with `bundle exec rake test`
76
+ Then I should see "4 files in total."
77
+ And I should see "using Config Test Runner" within "#footer"
78
+
79
+ Scenario: Mixing configure and start block config
80
+ Given a file named ".simplecov" with:
81
+ """
82
+ SimpleCov.configure do
83
+ command_name 'Config Test Runner'
84
+ end
85
+ SimpleCov.start do
86
+ add_filter 'test'
87
+ end
88
+ """
89
+
90
+ When I open the coverage report generated with `bundle exec rake test`
91
+ Then I should see "4 files in total."
92
+ And I should see "using Config Test Runner" within "#footer"
93
+
@@ -0,0 +1,29 @@
1
+ @cucumber
2
+ Feature:
3
+
4
+ Simply adding the basic simplecov lines to a project should get
5
+ the user a coverage report after running `cucumber features`
6
+
7
+ Scenario:
8
+ Given SimpleCov for Cucumber is configured with:
9
+ """
10
+ require 'simplecov'
11
+ SimpleCov.start
12
+ """
13
+
14
+ When I open the coverage report generated with `bundle exec cucumber features`
15
+ Then I should see the groups:
16
+ | name | coverage | files |
17
+ | All Files | 91.38% | 6 |
18
+
19
+ And I should see the source files:
20
+ | name | coverage |
21
+ | lib/faked_project.rb | 100.0 % |
22
+ | lib/faked_project/some_class.rb | 80.0 % |
23
+ | lib/faked_project/framework_specific.rb | 75.0 % |
24
+ | lib/faked_project/meta_magic.rb | 100.0 % |
25
+ | features/step_definitions/my_steps.rb | 100.0 % |
26
+ | features/support/simplecov_config.rb | 100.0 % |
27
+
28
+ And the report should be based upon:
29
+ | Cucumber Features |
@@ -0,0 +1,44 @@
1
+ @test_unit @rspec @merging
2
+ Feature:
3
+
4
+ Test suites like RSpec and Test/Unit should be merged automatically
5
+ when both have been run recently. The coverage report will feature
6
+ the joined results of all test suites that are using SimpleCov.
7
+
8
+ Scenario:
9
+ Given SimpleCov for Test/Unit is configured with:
10
+ """
11
+ require 'simplecov'
12
+ SimpleCov.start do
13
+ add_filter 'test.rb'
14
+ add_filter 'spec.rb'
15
+ end
16
+ """
17
+ And SimpleCov for RSpec is configured with:
18
+ """
19
+ require 'simplecov'
20
+ SimpleCov.start do
21
+ add_filter 'test.rb'
22
+ add_filter 'spec.rb'
23
+ end
24
+ """
25
+
26
+ When I open the coverage report generated with `bundle exec rake test`
27
+ Then the report should be based upon:
28
+ | Unit Tests |
29
+
30
+ When I open the coverage report generated with `bundle exec rspec spec`
31
+ Then the report should be based upon:
32
+ | RSpec |
33
+ | Unit Tests |
34
+
35
+ And I should see the groups:
36
+ | name | coverage | files |
37
+ | All Files | 90.7% | 4 |
38
+
39
+ And I should see the source files:
40
+ | name | coverage |
41
+ | lib/faked_project.rb | 100.0 % |
42
+ | lib/faked_project/some_class.rb | 80.0 % |
43
+ | lib/faked_project/framework_specific.rb | 87.5 % |
44
+ | lib/faked_project/meta_magic.rb | 100.0 % |