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
@@ -0,0 +1,6 @@
1
+ source :rubygems
2
+
3
+ gem 'simplecov', :path => '../../../'
4
+ gem 'rake'
5
+ gem 'rspec', '>= 2.6.0'
6
+ gem 'cucumber'
@@ -0,0 +1,8 @@
1
+ require 'bundler'
2
+
3
+ require 'rake/testtask'
4
+ Rake::TestTask.new(:test) do |test|
5
+ test.libs << 'lib' << 'test'
6
+ test.test_files = FileList['test/**/*_test.rb'].sort
7
+ test.verbose = true
8
+ end
@@ -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,23 @@
1
+ Given /^I want to keep stuff simple$/ do
2
+ 1.should == 1
3
+ end
4
+
5
+ When /^I write my cukes for the fake project$/ do
6
+ 1.should == 1
7
+ end
8
+
9
+ Then /^I make all neccessary tests in a single step$/ do
10
+ FakedProject.foo.should == 'bar'
11
+
12
+ FrameworkSpecific.cucumber.should == "Only tested in Cucumber"
13
+
14
+ FakedProject.a_class_method.should == "this is a mixed-in class method"
15
+
16
+ FakedProject.new.an_instance_method.should == "this is a mixed-in instance method"
17
+ FakedProject.new.dynamic.should == "A dynamically defined instance method"
18
+
19
+ something = SomeClass.new("foo")
20
+ something.reverse.should == 'oof'
21
+ something.compare_with('foo').should be_true
22
+ end
23
+
@@ -0,0 +1,12 @@
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
+ $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '/../../lib'))
12
+ require 'faked_project'
@@ -0,0 +1,6 @@
1
+ Feature: Foo
2
+
3
+ Scenario: Test stuff
4
+ Given I want to keep stuff simple
5
+ When I write my cukes for the fake project
6
+ Then I make all neccessary tests in a single step
@@ -0,0 +1,11 @@
1
+ class FakedProject
2
+ def self.foo
3
+ "bar"
4
+ end
5
+ end
6
+
7
+ require 'faked_project/some_class'
8
+ require 'faked_project/meta_magic'
9
+ require 'faked_project/framework_specific'
10
+
11
+ FakedProject.send :include, MetaMagic
@@ -0,0 +1,18 @@
1
+ # A pile of methods that only get tested in their frameworks
2
+ # and thus make this file only 100% covered when all framework test
3
+ # results are merged
4
+ module FrameworkSpecific
5
+ class << self
6
+ def cucumber
7
+ "Only tested in Cucumber"
8
+ end
9
+
10
+ def rspec
11
+ "Only tested in RSpec"
12
+ end
13
+
14
+ def test_unit
15
+ "Only tested in Test/Unit"
16
+ end
17
+ end
18
+ end
@@ -0,0 +1,24 @@
1
+ module MetaMagic
2
+ module ClassMethods
3
+ def a_class_method
4
+ "this is a mixed-in class method"
5
+ end
6
+ end
7
+
8
+ module InstanceMethods
9
+ def an_instance_method
10
+ "this is a mixed-in instance method"
11
+ end
12
+ end
13
+
14
+ def self.included(base)
15
+ base.send :extend, ClassMethods
16
+ base.send :include, InstanceMethods
17
+
18
+ base.class_eval do
19
+ define_method :dynamic do
20
+ "A dynamically defined instance method"
21
+ end
22
+ end
23
+ end
24
+ end
@@ -0,0 +1,29 @@
1
+ class SomeClass
2
+ attr_reader :label
3
+ attr_accessor :some_attr
4
+
5
+ def initialize(label)
6
+ @label = label
7
+ end
8
+
9
+ def reverse
10
+ label.reverse
11
+ end
12
+
13
+ def compare_with(item)
14
+ if item == label
15
+ return true
16
+ else
17
+ raise "Item does not match label"
18
+ end
19
+
20
+ rescue => err
21
+ false
22
+ end
23
+
24
+ private
25
+
26
+ def uncovered
27
+ "private method"
28
+ end
29
+ end
@@ -0,0 +1,11 @@
1
+ require 'spec_helper'
2
+
3
+ describe FakedProject do
4
+ it "should return proper foo" do
5
+ FakedProject.foo.should == 'bar'
6
+ end
7
+
8
+ it "should test it's framework specific method" do
9
+ FrameworkSpecific.rspec.should == "Only tested in RSpec"
10
+ end
11
+ end
@@ -0,0 +1,10 @@
1
+ require 'spec_helper'
2
+
3
+ describe FakedProject do
4
+ it "should have added a class method to FakedProject" do
5
+ FakedProject.a_class_method.should == "this is a mixed-in class method"
6
+ end
7
+
8
+ its(:an_instance_method) { should == "this is a mixed-in instance method" }
9
+ its(:dynamic) { should == "A dynamically defined instance method" }
10
+ end
@@ -0,0 +1,10 @@
1
+ require 'spec_helper'
2
+
3
+ describe SomeClass do
4
+ subject { SomeClass.new("foo") }
5
+
6
+ its(:reverse) { should == 'oof' }
7
+ it "should compare with 'foo'" do
8
+ subject.compare_with('foo').should be_true
9
+ end
10
+ end
@@ -0,0 +1,15 @@
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
+ RSpec.configure do |config|
14
+ # some (optional) config here
15
+ end
@@ -0,0 +1,11 @@
1
+ require 'test_helper'
2
+
3
+ class FakedTest < Test::Unit::TestCase
4
+ def test_something
5
+ assert_equal 'bar', FakedProject.foo
6
+ end
7
+
8
+ def test_framework_specific
9
+ assert_equal "Only tested in Test/Unit", FrameworkSpecific.test_unit
10
+ end
11
+ end
@@ -0,0 +1,13 @@
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
@@ -0,0 +1,15 @@
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
@@ -0,0 +1,16 @@
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
@@ -3,8 +3,8 @@ class Foo
3
3
  def initialize
4
4
  @foo = 'baz'
5
5
  end
6
-
6
+
7
7
  def bar
8
8
  @foo
9
9
  end
10
- end
10
+ end
@@ -3,8 +3,8 @@ class Foo
3
3
  def initialize
4
4
  @foo = 'baz'
5
5
  end
6
-
6
+
7
7
  def bar
8
8
  @foo
9
9
  end
10
- end
10
+ end
@@ -6,4 +6,4 @@ describe 'exit status' do
6
6
  it "should exit with a non-zero exit status when assertion fails" do
7
7
  1.should == 2
8
8
  end
9
- end
9
+ end
@@ -6,4 +6,4 @@ describe 'exit status' do
6
6
  it "should exit with a zero exit status when assertion fails" do
7
7
  1.should == 1
8
8
  end
9
- end
9
+ end
@@ -6,4 +6,4 @@ class FooTest < Test::Unit::TestCase
6
6
  def test_foo
7
7
  assert false
8
8
  end
9
- end
9
+ end
@@ -6,4 +6,4 @@ class FooTest < Test::Unit::TestCase
6
6
  def test_foo
7
7
  assert true
8
8
  end
9
- end
9
+ end
@@ -1,4 +1,4 @@
1
1
  puts "foo"
2
2
  puts "foo"
3
3
  puts "foo"
4
- puts "foo"
4
+ puts "foo"
@@ -2,4 +2,4 @@
2
2
  class Resultset
3
3
  VERSION = 2
4
4
  end
5
-
5
+
@@ -3,8 +3,14 @@ class Foo
3
3
  def initialize
4
4
  @foo = 'baz'
5
5
  end
6
-
6
+
7
7
  def bar
8
8
  @foo
9
9
  end
10
- end
10
+
11
+ #:nocov:
12
+ def skipped
13
+ @foo * 2
14
+ end
15
+ #:nocov:
16
+ end
data/test/helper.rb CHANGED
@@ -1,7 +1,5 @@
1
- require 'rubygems'
2
1
  require 'bundler/setup'
3
2
  require 'simplecov'
4
-
5
3
  require 'test/unit'
6
4
  require 'shoulda'
7
5
 
@@ -11,11 +9,26 @@ class Test::Unit::TestCase
11
9
  def source_fixture(filename)
12
10
  File.expand_path(File.join(File.dirname(__FILE__), 'fixtures', filename))
13
11
  end
14
-
12
+
15
13
  # Keep 1.8-rubies from complaining about missing tests in each file that covers only 1.9 functionality
16
14
  def default_test
17
15
  end
18
16
  end
19
17
 
20
18
  require 'shoulda_macros'
21
- Test::Unit::TestCase.send :extend, ShouldaMacros
19
+ Test::Unit::TestCase.send :extend, ShouldaMacros
20
+
21
+ # Taken from http://stackoverflow.com/questions/4459330/how-do-i-temporarily-redirect-stderr-in-ruby
22
+ require "stringio"
23
+
24
+ def capture_stderr
25
+ # The output stream must be an IO-like object. In this case we capture it in
26
+ # an in-memory IO object so we can return the string value. You can assign any
27
+ # IO object here.
28
+ previous_stderr, $stderr = $stderr, StringIO.new
29
+ yield
30
+ $stderr.string
31
+ ensure
32
+ # Restore the previous value of stderr (typically equal to STDERR).
33
+ $stderr = previous_stderr
34
+ end
@@ -2,10 +2,10 @@ module ShouldaMacros
2
2
  #
3
3
  # Simple block helper for running certain tests only on specific ruby versions.
4
4
  # The given strings will be regexp-matched against RUBY_VERSION
5
- #
5
+ #
6
6
  def on_ruby(*ruby_versions)
7
7
  context "On Ruby #{RUBY_VERSION}" do
8
8
  yield
9
9
  end if ruby_versions.any? {|v| RUBY_VERSION =~ /#{v}/ }
10
10
  end
11
- end
11
+ end
@@ -11,15 +11,15 @@ class Test18FallBacks < Test::Unit::TestCase
11
11
  should "return false when calling SimpleCov.start" do
12
12
  assert_equal false, SimpleCov.start
13
13
  end
14
-
14
+
15
15
  should "return false when calling SimpleCov.start with a block" do
16
16
  assert_equal false, SimpleCov.start { raise "Shouldn't reach this!?" }
17
17
  end
18
-
18
+
19
19
  should "return false when calling SimpleCov.configure with a block" do
20
20
  assert_equal false, SimpleCov.configure { raise "Shouldn't reach this!?" }
21
21
  end
22
-
22
+
23
23
  should "allow to define an adapter" do
24
24
  begin
25
25
  SimpleCov.adapters.define 'testadapter' do