simplecov 0.4.2 → 0.5.2

Sign up to get free protection for your applications and to get access to all the features.
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
@@ -0,0 +1,31 @@
1
+ @rspec
2
+ Feature:
3
+
4
+ Simply adding the basic simplecov lines to a project should get
5
+ the user a coverage report after running `rspec`
6
+
7
+ Scenario:
8
+ Given SimpleCov for RSpec is configured with:
9
+ """
10
+ require 'simplecov'
11
+ SimpleCov.start
12
+ """
13
+
14
+ When I open the coverage report generated with `bundle exec rspec spec`
15
+ Then I should see the groups:
16
+ | name | coverage | files |
17
+ | All Files | 90.91% | 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
+ | spec/meta_magic_spec.rb | 100.0 % |
26
+ | spec/some_class_spec.rb | 100.0 % |
27
+
28
+ # Note: faked_spec.rb is not appearing here since that's the first unit test file
29
+ # loaded by Rake, and only there test_helper is required, which then loads simplecov
30
+ # and triggers tracking of all other loaded files! Solution for this would be to
31
+ # configure simplecov in this first test instead of test_helper.
@@ -0,0 +1,29 @@
1
+ @rspec
2
+ Feature:
3
+
4
+ Defining some groups and filters should give a corresponding
5
+ coverage report that respects those settings after running rspec
6
+
7
+ Scenario:
8
+ Given SimpleCov for RSpec is configured with:
9
+ """
10
+ require 'simplecov'
11
+ SimpleCov.start do
12
+ add_group 'Libs', 'lib/faked_project/'
13
+ add_filter '/spec/'
14
+ end
15
+ """
16
+
17
+ When I open the coverage report generated with `bundle exec rspec spec`
18
+ And I should see the groups:
19
+ | name | coverage | files |
20
+ | All Files | 88.37% | 4 |
21
+ | Libs | 86.11% | 3 |
22
+ | Ungrouped | 100.0% | 1 |
23
+
24
+ And I should see the source files:
25
+ | name | coverage |
26
+ | lib/faked_project.rb | 100.0 % |
27
+ | lib/faked_project/some_class.rb | 80.0 % |
28
+ | lib/faked_project/framework_specific.rb | 75.0 % |
29
+ | lib/faked_project/meta_magic.rb | 100.0 % |
@@ -0,0 +1,35 @@
1
+ @rspec
2
+ Feature: Sophisticated grouping and filtering on RSpec
3
+
4
+ Defining groups and filters can be done by passing blocks or strings.
5
+ Blocks get each SimpleCov::SourceFile instance passed an can use arbitrary
6
+ and potentially weird conditions to remove files from the report or add them
7
+ to specific groups.
8
+
9
+ Scenario:
10
+ Given SimpleCov for RSpec is configured with:
11
+ """
12
+ require 'simplecov'
13
+ SimpleCov.start do
14
+ add_group 'By block' do |src_file|
15
+ src_file.filename =~ /MaGiC/i
16
+ end
17
+ add_group 'By string', 'project/meta_magic'
18
+
19
+ add_filter 'faked_project.rb'
20
+ # Remove all files that include "describe" in their source
21
+ add_filter {|src_file| src_file.lines.any? {|line| line.src =~ /describe/ } }
22
+ add_filter {|src_file| src_file.covered_percent < 100 }
23
+ end
24
+ """
25
+
26
+ When I open the coverage report generated with `bundle exec rspec spec`
27
+ Then I should see the groups:
28
+ | name | coverage | files |
29
+ | All Files | 100.0% | 1 |
30
+ | By block | 100.0% | 1 |
31
+ | By string | 100.0% | 1 |
32
+
33
+ And I should see the source files:
34
+ | name | coverage |
35
+ | lib/faked_project/meta_magic.rb | 100.0 % |
@@ -0,0 +1,20 @@
1
+ @rspec
2
+ Feature:
3
+
4
+ Running specs without simplecov configuration
5
+
6
+ Scenario: No config at all
7
+ When I successfully run `bundle exec rspec spec`
8
+ Then no coverage report should have been generated
9
+
10
+ Scenario: Configured, but not started
11
+ Given SimpleCov for RSpec is configured with:
12
+ """
13
+ require 'simplecov'
14
+ SimpleCov.configure do
15
+ add_filter 'somefilter'
16
+ end
17
+ """
18
+
19
+ When I successfully run `bundle exec rspec spec`
20
+ Then no coverage report should have been generated
@@ -0,0 +1,42 @@
1
+ module GroupHelpers
2
+ def available_groups
3
+ all('#content .file_list_container')
4
+ end
5
+
6
+ def available_source_files
7
+ all('.source_files .source_table')
8
+ end
9
+ end
10
+ World(GroupHelpers)
11
+
12
+
13
+ Then /^I should see the groups:$/ do |table|
14
+ expected_groups = table.hashes
15
+ # Given group names should be the same number than those rendered in report
16
+ expected_groups.count.should == available_groups.count
17
+
18
+ # Verify each of the expected groups has a file list container and corresponding title and coverage number
19
+ # as well as the correct number of links to files.
20
+ expected_groups.each do |group|
21
+ with_scope "#content ##{group["name"].gsub(/[^a-z]/i, '')}.file_list_container" do
22
+ file_count_in_group = page.all('a.src_link').count
23
+ file_count_in_group.should == group["files"].to_i
24
+
25
+ with_scope "h2" do
26
+ page.should have_content(group["name"])
27
+ page.should have_content(group["coverage"])
28
+ end
29
+ end
30
+ end
31
+ end
32
+
33
+ Then /^I should see the source files:$/ do |table|
34
+ expected_files = table.hashes
35
+ expected_files.length.should == available_source_files.count
36
+
37
+ # Find all filenames and their coverage present in coverage report
38
+ files = available_source_files.map {|f| {"name" => f.find('h3').text, "coverage" => f.find('.header span').text} }
39
+
40
+ files.sort_by {|hsh| hsh["name"] }.should == expected_files.sort_by {|hsh| hsh["name"] }
41
+ end
42
+
@@ -0,0 +1,61 @@
1
+ # Just a shortcut to make framework setup more readable
2
+ # The test project is using separate config files to avoid specifying all of
3
+ # test/spec_helper in the features every time.
4
+ Given /^SimpleCov for (.*) is configured with:$/ do |framework, config_body|
5
+ framework_dir = case framework
6
+ when /RSpec/i
7
+ "spec"
8
+ when /Test\/Unit/i
9
+ "test"
10
+ when /Cucumber/i
11
+ "features/support"
12
+ else
13
+ raise ArgumentError, "Could not identify test framework #{framework}!"
14
+ end
15
+
16
+ steps %Q{
17
+ Given a file named "#{framework_dir}/simplecov_config.rb" with:
18
+ """
19
+ #{config_body}
20
+ """
21
+ }
22
+ end
23
+
24
+ When /^I open the coverage report generated with `([^`]+)`$/ do |command|
25
+ steps %Q{
26
+ When I successfully run `#{command}`
27
+ Then a coverage report should have been generated
28
+ When I open the coverage report
29
+ }
30
+ end
31
+
32
+ Then /^a coverage report should have been generated(?: in "([^"]*)")?$/ do |coverage_dir|
33
+ coverage_dir ||= 'coverage'
34
+ steps %Q{
35
+ Then the output should contain "Coverage report generated"
36
+ And a directory named "#{coverage_dir}" should exist
37
+ And the following files should exist:
38
+ | #{coverage_dir}/index.html |
39
+ | #{coverage_dir}/.resultset.json |
40
+ }
41
+ end
42
+
43
+ Then /^no coverage report should have been generated(?: in "([^"]*)")?$/ do |coverage_dir|
44
+ coverage_dir ||= 'coverage'
45
+ steps %Q{
46
+ Then the output should not contain "Coverage report generated"
47
+ And a directory named "#{coverage_dir}" should not exist
48
+ And the following files should not exist:
49
+ | #{coverage_dir}/index.html |
50
+ | #{coverage_dir}/.resultset.json |
51
+ }
52
+ end
53
+
54
+ Then /^the report should be based upon:$/ do |table|
55
+ frameworks = table.raw.flatten
56
+ steps %Q{
57
+ Then the output should contain "Coverage report generated for #{frameworks.join(", ")}"
58
+ And I should see "using #{frameworks.join(", ")}" within "#footer"
59
+ }
60
+ end
61
+
@@ -0,0 +1,13 @@
1
+ #
2
+ # Enforce the alphabetical execution of specs because rspec 2+ executes them
3
+ # randomly with `rspec spec` while we need them in an accurate order for coverage
4
+ # reports that include the spec files.
5
+ #
6
+ # This is due to the fact that coverage will not include the first loaded spec/test file.
7
+ # To get predictable coverage results, we need to know which one that is...
8
+ #
9
+ Transform "bundle exec rspec spec" do |t|
10
+ files = nil # Avoid shadowing
11
+ in_current_dir { files = Dir['spec/**/*_spec.rb'] }
12
+ "bundle exec rspec #{files.sort.join(' ')}"
13
+ end
@@ -0,0 +1,64 @@
1
+ module WithinHelpers
2
+ def with_scope(locator)
3
+ locator ? within(locator) { yield } : yield
4
+ end
5
+ end
6
+ World(WithinHelpers)
7
+
8
+ When /^I open the coverage report$/ do
9
+ visit '/'
10
+ end
11
+
12
+ Given /^(?:|I )am on (.+)$/ do |path|
13
+ visit path
14
+ end
15
+
16
+ When /^(?:|I )go to (.+)$/ do |path|
17
+ visit path
18
+ end
19
+
20
+ When /^(?:|I )press "([^"]*)"(?: within "([^"]*)")?$/ do |button, selector|
21
+ with_scope(selector) do
22
+ click_button(button)
23
+ end
24
+ end
25
+
26
+ When /^(?:|I )follow "([^"]*)"(?: within "([^"]*)")?$/ do |link, selector|
27
+ with_scope(selector) do
28
+ click_link(link)
29
+ end
30
+ end
31
+
32
+ Then /^(?:|I )should see "([^"]*)"(?: within "([^"]*)")?$/ do |text, selector|
33
+ with_scope(selector) do
34
+ page.should have_content(text)
35
+ end
36
+ end
37
+
38
+ Then /^(?:|I )should see \/([^\/]*)\/(?: within "([^"]*)")?$/ do |regexp, selector|
39
+ regexp = Regexp.new(regexp)
40
+ with_scope(selector) do
41
+ page.should have_xpath('//*', :text => regexp)
42
+ end
43
+ end
44
+
45
+ Then /^(?:|I )should not see "([^"]*)"(?: within "([^"]*)")?$/ do |text, selector|
46
+ with_scope(selector) do
47
+ page.should have_no_content(text)
48
+ end
49
+ end
50
+
51
+ Then /^(?:|I )should not see \/([^\/]*)\/(?: within "([^"]*)")?$/ do |regexp, selector|
52
+ regexp = Regexp.new(regexp)
53
+ with_scope(selector) do
54
+ page.should have_no_xpath('//*', :text => regexp)
55
+ end
56
+ end
57
+
58
+ Then /^show me the page$/ do
59
+ save_and_open_page
60
+ end
61
+
62
+ Then /^print the page$/ do
63
+ puts page.body
64
+ end
@@ -0,0 +1,26 @@
1
+ unless RUBY_VERSION =~ /1\.9/
2
+ $stderr.puts "Sorry, Cucumber features are only meant to run on Ruby 1.9 for now :("
3
+ exit 0
4
+ end
5
+
6
+ require 'bundler'
7
+ Bundler.setup
8
+ require 'aruba/cucumber'
9
+ require 'capybara/cucumber'
10
+
11
+ # Fake rack app for capybara that just returns the latest coverage report from aruba temp project dir
12
+ Capybara.app = lambda {|env|
13
+ [200, {'Content-Type' => 'text/html'},
14
+ [File.read(File.join(File.dirname(__FILE__), '../../tmp/aruba/project', 'coverage/index.html'))]]
15
+ }
16
+
17
+ Before do
18
+ @aruba_timeout_seconds = 20
19
+ this_dir = File.dirname(__FILE__)
20
+ # Clean up and create blank state for fake project
21
+ in_current_dir do
22
+ FileUtils.rm_rf 'project'
23
+ FileUtils.cp_r File.join(this_dir, '../../test/faked_project/'), 'project'
24
+ end
25
+ Given 'I cd to "project"'
26
+ end
@@ -0,0 +1,34 @@
1
+ @test_unit
2
+ Feature:
3
+
4
+ Simply adding the basic simplecov lines to a project should get
5
+ the user a coverage report after running `rake test`
6
+
7
+ Scenario:
8
+ Given SimpleCov for Test/Unit is configured with:
9
+ """
10
+ require 'simplecov'
11
+ SimpleCov.start
12
+ """
13
+
14
+ When I open the coverage report generated with `bundle exec rake test`
15
+ Then I should see the groups:
16
+ | name | coverage | files |
17
+ | All Files | 91.53% | 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
+ | test/meta_magic_test.rb | 100.0 % |
26
+ | test/some_class_test.rb | 100.0 % |
27
+
28
+ # Note: faked_test.rb is not appearing here since that's the first unit test file
29
+ # loaded by Rake, and only there test_helper is required, which then loads simplecov
30
+ # and triggers tracking of all other loaded files! Solution for this would be to
31
+ # configure simplecov in this first test instead of test_helper.
32
+
33
+ And the report should be based upon:
34
+ | Unit Tests |
@@ -0,0 +1,29 @@
1
+ @test_unit
2
+ Feature:
3
+
4
+ Defining some groups and filters should give a corresponding
5
+ coverage report that respects those settings after running tests
6
+
7
+ Scenario:
8
+ Given SimpleCov for Test/Unit is configured with:
9
+ """
10
+ require 'simplecov'
11
+ SimpleCov.start do
12
+ add_group 'Libs', 'lib/faked_project/'
13
+ add_filter '/test/'
14
+ end
15
+ """
16
+
17
+ When I open the coverage report generated with `bundle exec rake test`
18
+ Then I should see the groups:
19
+ | name | coverage | files |
20
+ | All Files | 88.37% | 4 |
21
+ | Libs | 86.11% | 3 |
22
+ | Ungrouped | 100.0% | 1 |
23
+
24
+ And I should see the source files:
25
+ | name | coverage |
26
+ | lib/faked_project.rb | 100.0 % |
27
+ | lib/faked_project/some_class.rb | 80.0 % |
28
+ | lib/faked_project/framework_specific.rb | 75.0 % |
29
+ | lib/faked_project/meta_magic.rb | 100.0 % |
@@ -0,0 +1,35 @@
1
+ @test_unit
2
+ Feature: Sophisticated grouping and filtering on Test/Unit
3
+
4
+ Defining groups and filters can be done by passing blocks or strings.
5
+ Blocks get each SimpleCov::SourceFile instance passed an can use arbitrary
6
+ and potentially weird conditions to remove files from the report or add them
7
+ to specific groups.
8
+
9
+ Scenario:
10
+ Given SimpleCov for Test/Unit is configured with:
11
+ """
12
+ require 'simplecov'
13
+ SimpleCov.start do
14
+ add_group 'By block' do |src_file|
15
+ src_file.filename =~ /MaGiC/i
16
+ end
17
+ add_group 'By string', 'project/meta_magic'
18
+
19
+ add_filter 'faked_project.rb'
20
+ # Remove all files that include "describe" in their source
21
+ add_filter {|src_file| src_file.lines.any? {|line| line.src =~ /TestCase/ } }
22
+ add_filter {|src_file| src_file.covered_percent < 100 }
23
+ end
24
+ """
25
+
26
+ When I open the coverage report generated with `bundle exec rake test`
27
+ Then I should see the groups:
28
+ | name | coverage | files |
29
+ | All Files | 100.0% | 1 |
30
+ | By block | 100.0% | 1 |
31
+ | By string | 100.0% | 1 |
32
+
33
+ And I should see the source files:
34
+ | name | coverage |
35
+ | lib/faked_project/meta_magic.rb | 100.0 % |
@@ -0,0 +1,20 @@
1
+ @test_unit
2
+ Feature:
3
+
4
+ Running unit tests without simplecov configuration
5
+
6
+ Scenario: No config at all
7
+ When I successfully run `bundle exec rake test`
8
+ Then no coverage report should have been generated
9
+
10
+ Scenario: Configured, but not started
11
+ Given SimpleCov for Test/Unit is configured with:
12
+ """
13
+ require 'simplecov'
14
+ SimpleCov.configure do
15
+ add_filter 'somefilter'
16
+ end
17
+ """
18
+
19
+ When I successfully run `bundle exec rake test`
20
+ Then no coverage report should have been generated