coverband 4.2.1.rc3 → 4.2.1.rc4

Sign up to get free protection for your applications and to get access to all the features.
Files changed (37) hide show
  1. checksums.yaml +4 -4
  2. data/.travis.yml +4 -0
  3. data/Gemfile +1 -0
  4. data/README.md +6 -4
  5. data/Rakefile +5 -2
  6. data/changes.md +32 -13
  7. data/lib/coverband.rb +3 -4
  8. data/lib/coverband/adapters/base.rb +59 -30
  9. data/lib/coverband/adapters/file_store.rb +8 -8
  10. data/lib/coverband/adapters/redis_store.rb +18 -10
  11. data/lib/coverband/collectors/coverage.rb +3 -4
  12. data/lib/coverband/collectors/delta.rb +18 -8
  13. data/lib/coverband/configuration.rb +25 -9
  14. data/lib/coverband/integrations/background.rb +3 -1
  15. data/lib/coverband/reporters/base.rb +6 -3
  16. data/lib/coverband/reporters/web.rb +11 -0
  17. data/lib/coverband/utils/file_path_helper.rb +12 -3
  18. data/lib/coverband/utils/source_file.rb +2 -1
  19. data/lib/coverband/utils/tasks.rb +1 -11
  20. data/lib/coverband/version.rb +1 -1
  21. data/test/benchmarks/benchmark.rake +135 -10
  22. data/test/coverband/adapters/base_test.rb +73 -42
  23. data/test/coverband/adapters/file_store_test.rb +48 -37
  24. data/test/coverband/adapters/redis_store_test.rb +35 -5
  25. data/test/coverband/collectors/coverage_test.rb +1 -1
  26. data/test/coverband/collectors/delta_test.rb +10 -1
  27. data/test/coverband/coverband_test.rb +14 -1
  28. data/test/coverband/utils/html_formatter_test.rb +0 -2
  29. data/test/dog.rb.erb +12 -0
  30. data/test/forked/rails_full_stack_test.rb +35 -25
  31. data/test/forked/rails_rake_full_stack_test.rb +12 -4
  32. data/test/rails4_dummy/config/coverband.rb +2 -0
  33. data/test/rails5_dummy/config/coverband.rb +2 -0
  34. data/test/rails_test_helper.rb +2 -1
  35. data/test/test_helper.rb +19 -6
  36. data/test/unique_files.rb +12 -5
  37. metadata +5 -4
@@ -4,6 +4,8 @@ require 'rails'
4
4
  class RailsRakeFullStackTest < Minitest::Test
5
5
 
6
6
  test 'rake tasks shows coverage properly within eager_loading' do
7
+ store.instance_variable_set(:@redis_namespace, 'coverband_test')
8
+ store.clear!
7
9
  system("COVERBAND_CONFIG=./test/rails#{Rails::VERSION::MAJOR}_dummy/config/coverband.rb bundle exec rake -f test/rails#{Rails::VERSION::MAJOR}_dummy/Rakefile middleware")
8
10
  store.instance_variable_set(:@redis_namespace, 'coverband_test')
9
11
  store.type = :eager_loading
@@ -13,19 +15,25 @@ class RailsRakeFullStackTest < Minitest::Test
13
15
  refute_nil pundit_coverage
14
16
  assert_includes pundit_coverage['data'], 1
15
17
 
16
- store.type = nil
17
- pundit_coverage = store.coverage[pundit_file]
18
- assert_nil pundit_coverage
18
+ store.type = Coverband::RUNTIME_TYPE
19
+ if ENV['SIMULATE_ONESHOT']
20
+ pundit_coverage = store.get_coverage_report[Coverband::RUNTIME_TYPE][pundit_file]
21
+ assert pundit_coverage['data'].compact.all? { |el| el == 0}
22
+ else
23
+ pundit_coverage = store.coverage[pundit_file]
24
+ assert_nil pundit_coverage
25
+ end
19
26
  end
20
27
 
21
28
  test "ignored rake tasks don't add coverage" do
29
+ store.clear!
22
30
  store.instance_variable_set(:@redis_namespace, 'coverband_test')
23
31
  store.send(:save_report, basic_coverage_full_path)
24
32
  output = `COVERBAND_CONFIG=./test/rails#{Rails::VERSION::MAJOR}_dummy/config/coverband.rb bundle exec rake -f test/rails#{Rails::VERSION::MAJOR}_dummy/Rakefile coverband:clear`
25
33
  assert_nil output.match(/Coverband: Reported coverage via thread/)
26
34
  coverage_report = store.get_coverage_report
27
35
  empty_hash = {}
28
- assert_equal empty_hash, coverage_report[nil]
36
+ assert_equal empty_hash, coverage_report[Coverband::RUNTIME_TYPE]
29
37
  assert_equal empty_hash, coverage_report[:eager_loading]
30
38
  assert_equal empty_hash, coverage_report[:merged]
31
39
  end
@@ -8,4 +8,6 @@ Coverband.configure do |config|
8
8
  config.background_reporting_enabled = true
9
9
  config.track_gems = true
10
10
  config.gem_details = true
11
+ config.use_oneshot_lines_coverage = true if ENV['ONESHOT']
12
+ config.simulate_oneshot_lines_coverage = true if ENV['SIMULATE_ONESHOT']
11
13
  end
@@ -8,4 +8,6 @@ Coverband.configure do |config|
8
8
  config.background_reporting_enabled = true
9
9
  config.track_gems = true
10
10
  config.gem_details = true
11
+ config.use_oneshot_lines_coverage = true if ENV['ONESHOT']
12
+ config.simulate_oneshot_lines_coverage = true if ENV['SIMULATE_ONESHOT']
11
13
  end
@@ -22,8 +22,9 @@ def rails_setup
22
22
  ENV['RAILS_ENV'] = 'test'
23
23
  require 'rails'
24
24
  # coverband must be required after rails
25
- load 'coverband/utils/railtie.rb'
26
25
  Coverband.configure("./test/rails#{Rails::VERSION::MAJOR}_dummy/config/coverband.rb")
26
+ load 'coverband/utils/railtie.rb'
27
+
27
28
  require_relative "../test/rails#{Rails::VERSION::MAJOR}_dummy/config/environment"
28
29
  require 'capybara/rails'
29
30
  # Our coverage report is wrapped in display:none as of now
@@ -19,19 +19,23 @@ require 'pry-byebug'
19
19
  require_relative 'unique_files'
20
20
  $VERBOSE = original_verbosity
21
21
 
22
- SimpleCov.formatter = Coveralls::SimpleCov::Formatter
23
- SimpleCov.start do
24
- add_filter 'test/forked'
22
+ unless ENV['ONESHOT'] || ENV['SIMULATE_ONESHOT']
23
+ SimpleCov.formatter = Coveralls::SimpleCov::Formatter
24
+ SimpleCov.start do
25
+ add_filter 'test/forked'
26
+ end
27
+
28
+ Coveralls.wear!
25
29
  end
26
30
 
27
- Coveralls.wear!
28
31
 
29
32
  module Coverband
30
33
  module Test
31
34
  def self.reset
32
35
  Coverband.configuration.redis_namespace = 'coverband_test'
33
36
  Coverband.configuration.store.instance_variable_set(:@redis_namespace, 'coverband_test')
34
- [:eager_loading, nil].each do |type|
37
+ Coverband.configuration.store.class.class_variable_set(:@@path_cache, {})
38
+ [:eager_loading, :runtime].each do |type|
35
39
  Coverband.configuration.store.type = type
36
40
  Coverband.configuration.store.clear!
37
41
  end
@@ -116,8 +120,17 @@ def test_root
116
120
  File.expand_path(File.join(File.dirname(__FILE__)))
117
121
  end
118
122
 
123
+ ###
124
+ # This handles an issue where the store is setup in tests prior to being able to set the namespace
125
+ ###
119
126
  def store
120
- Coverband.configuration.store
127
+ if Coverband.configuration.store.redis_namespace=='coverband_test'
128
+ Coverband.configuration.store
129
+ else
130
+ Coverband.configuration.redis_namespace = 'coverband_test'
131
+ Coverband.configuration.instance_variable_set(:@store, nil)
132
+ Coverband.configuration.store
133
+ end
121
134
  end
122
135
 
123
136
  # Taken from http://stackoverflow.com/questions/4459330/how-do-i-temporarily-redirect-stderr-in-ruby
@@ -2,15 +2,20 @@
2
2
 
3
3
  require 'securerandom'
4
4
  require 'fileutils'
5
+ require 'erb'
6
+ require 'ostruct'
5
7
 
6
8
  UNIQUE_FILES_DIR = './test/unique_files'
7
9
 
8
- def require_unique_file(file = 'dog.rb')
10
+ def require_unique_file(file = 'dog.rb', variables = {})
9
11
  uuid = SecureRandom.uuid
10
12
  dir = "#{UNIQUE_FILES_DIR}/#{uuid}"
11
- temp_file = "#{dir}/#{file}"
13
+ file_name = file.sub('.erb', '')
14
+ temp_file = "#{dir}/#{file_name}"
12
15
  FileUtils.mkdir_p(Pathname.new(temp_file).dirname.to_s)
13
- File.open(temp_file, 'w') { |w| w.write(File.read("./test/#{file}")) }
16
+ file_contents = File.read("./test/#{file}")
17
+ file_contents = ERB.new(file_contents).result(OpenStruct.new(variables).instance_eval { binding }) if variables.any?
18
+ File.open(temp_file, 'w') { |w| w.write(file_contents) }
14
19
  require temp_file
15
20
  Coverband::Utils::FilePathHelper.full_path_to_relative(File.expand_path(temp_file))
16
21
  end
@@ -19,6 +24,8 @@ def remove_unique_files
19
24
  FileUtils.rm_r(UNIQUE_FILES_DIR) if File.exist?(UNIQUE_FILES_DIR)
20
25
  end
21
26
 
22
- Minitest.after_run do
23
- remove_unique_files
27
+ if defined?(Minitest)
28
+ Minitest.after_run do
29
+ remove_unique_files
30
+ end
24
31
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: coverband
3
3
  version: !ruby/object:Gem::Version
4
- version: 4.2.1.rc3
4
+ version: 4.2.1.rc4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Dan Mayer
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2019-05-30 00:00:00.000000000 Z
12
+ date: 2019-06-26 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: aws-sdk-s3
@@ -387,6 +387,7 @@ files:
387
387
  - test/coverband/utils/source_file_line_test.rb
388
388
  - test/coverband/utils/source_file_test.rb
389
389
  - test/dog.rb
390
+ - test/dog.rb.erb
390
391
  - test/fake_app/basic_rack.rb
391
392
  - test/fixtures/app/controllers/sample_controller.rb
392
393
  - test/fixtures/app/models/user.rb
@@ -444,8 +445,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
444
445
  - !ruby/object:Gem::Version
445
446
  version: 1.3.1
446
447
  requirements: []
447
- rubyforge_project:
448
- rubygems_version: 2.7.8
448
+ rubygems_version: 3.0.3
449
449
  signing_key:
450
450
  specification_version: 4
451
451
  summary: Rack middleware to help measure production code usage (LOC runtime usage)
@@ -484,6 +484,7 @@ test_files:
484
484
  - test/coverband/utils/source_file_line_test.rb
485
485
  - test/coverband/utils/source_file_test.rb
486
486
  - test/dog.rb
487
+ - test/dog.rb.erb
487
488
  - test/fake_app/basic_rack.rb
488
489
  - test/fixtures/app/controllers/sample_controller.rb
489
490
  - test/fixtures/app/models/user.rb