coverband 4.2.6 → 5.0.0.rc.5
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.standard.yml +26 -0
- data/.travis.yml +2 -1
- data/Gemfile +5 -7
- data/Gemfile.rails4 +0 -3
- data/Gemfile.rails6 +0 -3
- data/README.md +24 -77
- data/Rakefile +17 -17
- data/changes.md +30 -28
- data/config.ru +1 -1
- data/coverband.gemspec +31 -34
- data/lib/alternative_coverband_patch.rb +5 -0
- data/lib/coverband.rb +68 -44
- data/lib/coverband/adapters/base.rb +17 -18
- data/lib/coverband/adapters/file_store.rb +38 -6
- data/lib/coverband/adapters/hash_redis_store.rb +24 -21
- data/lib/coverband/adapters/redis_store.rb +12 -12
- data/lib/coverband/adapters/stdout_store.rb +41 -0
- data/lib/coverband/adapters/web_service_store.rb +155 -0
- data/lib/coverband/at_exit.rb +1 -1
- data/lib/coverband/collectors/coverage.rb +15 -27
- data/lib/coverband/collectors/delta.rb +29 -9
- data/lib/coverband/collectors/view_tracker.rb +10 -10
- data/lib/coverband/collectors/view_tracker_service.rb +59 -0
- data/lib/coverband/configuration.rb +150 -113
- data/lib/coverband/integrations/background.rb +6 -6
- data/lib/coverband/integrations/rack_server_check.rb +3 -3
- data/lib/coverband/integrations/resque.rb +13 -1
- data/lib/coverband/reporters/base.rb +11 -12
- data/lib/coverband/reporters/console_report.rb +1 -1
- data/lib/coverband/reporters/html_report.rb +10 -30
- data/lib/coverband/reporters/web.rb +55 -50
- data/lib/coverband/utils/absolute_file_converter.rb +6 -6
- data/lib/coverband/utils/html_formatter.rb +32 -61
- data/lib/coverband/utils/railtie.rb +23 -6
- data/lib/coverband/utils/relative_file_converter.rb +2 -2
- data/lib/coverband/utils/result.rb +6 -11
- data/lib/coverband/utils/results.rb +0 -10
- data/lib/coverband/utils/source_file.rb +21 -30
- data/lib/coverband/utils/tasks.rb +8 -11
- data/lib/coverband/version.rb +1 -1
- data/public/application.js +0 -30
- data/test/benchmarks/benchmark.rake +97 -92
- data/test/benchmarks/dog.rb +1 -1
- data/test/benchmarks/init_rails.rake +4 -4
- data/test/coverband/adapters/base_test.rb +29 -30
- data/test/coverband/adapters/file_store_test.rb +19 -20
- data/test/coverband/adapters/hash_redis_store_test.rb +57 -57
- data/test/coverband/adapters/redis_store_test.rb +26 -26
- data/test/coverband/adapters/web_service_store_test.rb +56 -0
- data/test/coverband/at_exit_test.rb +2 -2
- data/test/coverband/collectors/coverage_test.rb +33 -47
- data/test/coverband/collectors/delta_test.rb +52 -23
- data/test/coverband/collectors/view_tracker_test.rb +35 -35
- data/test/coverband/configuration_test.rb +61 -48
- data/test/coverband/coverband_test.rb +11 -11
- data/test/coverband/integrations/background_middleware_test.rb +10 -10
- data/test/coverband/integrations/background_test.rb +17 -5
- data/test/coverband/integrations/rack_server_check_test.rb +7 -7
- data/test/coverband/integrations/report_middleware_test.rb +9 -9
- data/test/coverband/integrations/resque_worker_test.rb +9 -9
- data/test/coverband/integrations/test_resque_job.rb +1 -1
- data/test/coverband/reporters/base_test.rb +9 -9
- data/test/coverband/reporters/console_test.rb +6 -6
- data/test/coverband/reporters/html_test.rb +36 -48
- data/test/coverband/reporters/web_test.rb +16 -18
- data/test/coverband/utils/absolute_file_converter_test.rb +22 -22
- data/test/coverband/utils/file_hasher_test.rb +6 -12
- data/test/coverband/utils/file_list_test.rb +13 -13
- data/test/coverband/utils/html_formatter_test.rb +9 -23
- data/test/coverband/utils/lines_classifier_test.rb +29 -29
- data/test/coverband/utils/relative_file_converter_test.rb +13 -13
- data/test/coverband/utils/result_test.rb +18 -18
- data/test/coverband/utils/results_test.rb +17 -17
- data/test/coverband/utils/source_file_line_test.rb +46 -46
- data/test/coverband/utils/source_file_test.rb +38 -88
- data/test/dog.rb +1 -1
- data/test/fake_app/basic_rack.rb +2 -2
- data/test/fixtures/app/controllers/sample_controller.rb +1 -1
- data/test/fixtures/app/models/user.rb +1 -1
- data/test/fixtures/sample.rb +1 -1
- data/test/fixtures/utf-8.rb +0 -2
- data/test/forked/rails_full_stack_test.rb +24 -27
- data/test/forked/rails_rake_full_stack_test.rb +7 -26
- data/test/integration/full_stack_test.rb +11 -22
- data/test/jruby_check.rb +2 -3
- data/test/rails4_dummy/Rakefile +1 -1
- data/test/rails4_dummy/config.ru +1 -1
- data/test/rails4_dummy/config/application.rb +4 -4
- data/test/rails4_dummy/config/boot.rb +2 -2
- data/test/rails4_dummy/config/coverband.rb +1 -1
- data/test/rails4_dummy/config/coverband_missing_redis.rb +1 -1
- data/test/rails4_dummy/config/environment.rb +1 -1
- data/test/rails4_dummy/config/routes.rb +2 -2
- data/test/rails5_dummy/Rakefile +1 -1
- data/test/rails5_dummy/config.ru +1 -1
- data/test/rails5_dummy/config/application.rb +3 -3
- data/test/rails5_dummy/config/coverband.rb +8 -8
- data/test/rails5_dummy/config/coverband_missing_redis.rb +8 -8
- data/test/rails5_dummy/config/environment.rb +1 -1
- data/test/rails5_dummy/config/routes.rb +2 -2
- data/test/rails6_dummy/Rakefile +1 -1
- data/test/rails6_dummy/config.ru +1 -1
- data/test/rails6_dummy/config/application.rb +4 -4
- data/test/rails6_dummy/config/boot.rb +2 -2
- data/test/rails6_dummy/config/coverband.rb +1 -1
- data/test/rails6_dummy/config/coverband_missing_redis.rb +1 -1
- data/test/rails6_dummy/config/environment.rb +1 -1
- data/test/rails6_dummy/config/routes.rb +2 -2
- data/test/rails_test_helper.rb +11 -11
- data/test/test_helper.rb +44 -34
- data/test/unique_files.rb +10 -10
- data/views/layout.erb +2 -12
- metadata +29 -34
- data/.rubocop.yml +0 -84
- data/lib/coverband/integrations/bundler.rb +0 -8
- data/lib/coverband/utils/file_groups.rb +0 -53
- data/lib/coverband/utils/gem_list.rb +0 -31
- data/lib/coverband/utils/s3_report.rb +0 -105
- data/test/coverband/utils/file_groups_test.rb +0 -61
- data/test/coverband/utils/gem_list_test.rb +0 -48
- data/test/coverband/utils/s3_report_test.rb +0 -44
- data/views/gem_list.erb +0 -63
@@ -1,60 +1,49 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
require File.expand_path(
|
3
|
+
require File.expand_path("../test_helper", File.dirname(__FILE__))
|
4
4
|
|
5
5
|
class BaseTest < Minitest::Test
|
6
6
|
def setup
|
7
|
+
Coverband.configuration.reset
|
7
8
|
super
|
8
9
|
Coverband.configuration.reset
|
9
10
|
Coverband.configure do |config|
|
10
|
-
config.root
|
11
|
-
config.
|
12
|
-
config.
|
13
|
-
config.
|
14
|
-
config.
|
15
|
-
config.store = Coverband::Adapters::RedisStore.new(Coverband::Test.redis, redis_namespace: 'coverband_test')
|
11
|
+
config.root = Dir.pwd
|
12
|
+
config.root_paths = ["/app_path/"]
|
13
|
+
config.ignore = ["config/envionments"]
|
14
|
+
config.reporter = "std_out"
|
15
|
+
config.store = Coverband::Adapters::RedisStore.new(Coverband::Test.redis, redis_namespace: "coverband_test")
|
16
16
|
end
|
17
17
|
end
|
18
18
|
|
19
|
-
test
|
20
|
-
|
21
|
-
expected = [
|
19
|
+
test "ignore works with equal" do
|
20
|
+
Coverband::Collectors::Coverage.instance.reset_instance
|
21
|
+
expected = ["vendor/", ".erb$", ".slim$", "/tmp", "internal:prelude", "db/schema.rb", "config/envionments"]
|
22
22
|
assert_equal expected, Coverband.configuration.ignore
|
23
23
|
end
|
24
24
|
|
25
|
-
test
|
25
|
+
test "ignore works with plus equal" do
|
26
26
|
Coverband.configure do |config|
|
27
|
-
config.ignore += [
|
27
|
+
config.ignore += ["config/initializers"]
|
28
28
|
end
|
29
|
-
coverband = Coverband::Collectors::Coverage.instance.reset_instance
|
30
|
-
expected = ['vendor/',
|
31
|
-
'.erb$',
|
32
|
-
'.slim$',
|
33
|
-
'/tmp',
|
34
|
-
'internal:prelude',
|
35
|
-
'schema.rb',
|
36
|
-
'config/envionments',
|
37
|
-
'config/initializers']
|
38
|
-
assert_equal expected, Coverband.configuration.ignore
|
39
|
-
end
|
40
|
-
|
41
|
-
test 'ignore' do
|
42
|
-
Coverband::Collectors::Coverage.instance.reset_instance
|
43
|
-
assert !Coverband.configuration.gem_paths.first.nil?
|
44
|
-
end
|
45
|
-
|
46
|
-
test 'gem_paths' do
|
47
29
|
Coverband::Collectors::Coverage.instance.reset_instance
|
48
|
-
|
30
|
+
expected = ["vendor/",
|
31
|
+
".erb$",
|
32
|
+
".slim$",
|
33
|
+
"/tmp",
|
34
|
+
"internal:prelude",
|
35
|
+
"db/schema.rb",
|
36
|
+
"config/envionments",
|
37
|
+
"config/initializers"]
|
38
|
+
assert_equal expected, Coverband.configuration.ignore
|
49
39
|
end
|
50
40
|
|
51
|
-
test
|
41
|
+
test "ignore" do
|
52
42
|
Coverband::Collectors::Coverage.instance.reset_instance
|
53
|
-
Coverband.configuration.
|
54
|
-
assert_equal %w[App Gems], Coverband.configuration.groups.keys
|
43
|
+
assert !Coverband.configuration.ignore.first.nil?
|
55
44
|
end
|
56
45
|
|
57
|
-
test
|
46
|
+
test "all_root_paths" do
|
58
47
|
Coverband::Collectors::Coverage.instance.reset_instance
|
59
48
|
current_paths = Coverband.configuration.root_paths.dup
|
60
49
|
# verify previous bug fix
|
@@ -64,30 +53,54 @@ class BaseTest < Minitest::Test
|
|
64
53
|
assert_equal current_paths, Coverband.configuration.root_paths
|
65
54
|
end
|
66
55
|
|
67
|
-
test
|
56
|
+
test "store raises when not set to supported adapter" do
|
68
57
|
Coverband::Collectors::Coverage.instance.reset_instance
|
58
|
+
assert_raises RuntimeError do
|
59
|
+
Coverband.configure do |config|
|
60
|
+
config.store = "fake"
|
61
|
+
end
|
62
|
+
end
|
63
|
+
end
|
64
|
+
|
65
|
+
test "store defaults to redis store" do
|
66
|
+
Coverband::Collectors::Coverage.instance.reset_instance
|
67
|
+
assert_equal Coverband.configuration.store.class, Coverband::Adapters::RedisStore
|
68
|
+
end
|
69
|
+
|
70
|
+
test "store is a service store when api_key is set" do
|
71
|
+
Coverband::Collectors::Coverage.instance.reset_instance
|
72
|
+
Coverband.configuration.reset
|
69
73
|
Coverband.configure do |config|
|
70
|
-
config.
|
71
|
-
config.
|
72
|
-
|
73
|
-
|
74
|
+
config.redis_url = nil
|
75
|
+
config.api_key = "test-key"
|
76
|
+
end
|
77
|
+
assert_equal Coverband.configuration.store.class.to_s, "Coverband::Adapters::WebServiceStore"
|
78
|
+
end
|
79
|
+
|
80
|
+
test "store raises when api key set but not set to service" do
|
81
|
+
Coverband::Collectors::Coverage.instance.reset_instance
|
82
|
+
Coverband.configuration.reset
|
83
|
+
assert_raises RuntimeError do
|
84
|
+
Coverband.configure do |config|
|
85
|
+
config.api_key = "test-key"
|
86
|
+
config.redis_url = "redis://localhost:3333"
|
87
|
+
config.store = Coverband::Adapters::RedisStore.new(Coverband::Test.redis, redis_namespace: "coverband_test")
|
88
|
+
end
|
74
89
|
end
|
75
|
-
assert_equal 'bucket', Coverband.configuration.s3_bucket
|
76
|
-
assert_equal 'region', Coverband.configuration.s3_region
|
77
|
-
assert_equal 'key_id', Coverband.configuration.s3_access_key_id
|
78
|
-
assert_equal 'secret', Coverband.configuration.s3_secret_access_key
|
79
90
|
end
|
80
91
|
|
81
|
-
test
|
92
|
+
test "store raises when api key and redis_url" do
|
82
93
|
Coverband::Collectors::Coverage.instance.reset_instance
|
94
|
+
Coverband.configuration.reset
|
83
95
|
assert_raises RuntimeError do
|
84
96
|
Coverband.configure do |config|
|
85
|
-
config.
|
97
|
+
config.api_key = "test-key"
|
98
|
+
config.redis_url = "redis://localhost:3333"
|
86
99
|
end
|
87
100
|
end
|
88
101
|
end
|
89
102
|
|
90
|
-
test
|
103
|
+
test "use_oneshot_lines_coverage" do
|
91
104
|
refute Coverband.configuration.use_oneshot_lines_coverage
|
92
105
|
|
93
106
|
Coverband.configuration.stubs(:one_shot_coverage_implemented_in_ruby_version?).returns(true)
|
@@ -101,7 +114,7 @@ class BaseTest < Minitest::Test
|
|
101
114
|
exception = assert_raises Exception do
|
102
115
|
Coverband.configuration.use_oneshot_lines_coverage = true
|
103
116
|
end
|
104
|
-
assert_equal
|
117
|
+
assert_equal "One shot line coverage is only available in ruby >= 2.6", exception.message
|
105
118
|
refute Coverband.configuration.use_oneshot_lines_coverage
|
106
119
|
end
|
107
120
|
end
|
@@ -1,42 +1,42 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
require File.expand_path(
|
3
|
+
require File.expand_path("../test_helper", File.dirname(__FILE__))
|
4
4
|
|
5
5
|
class CoverbandTest < Minitest::Test
|
6
|
-
test
|
7
|
-
Coverband.configuration.stubs(:background_reporting_enabled).returns(
|
6
|
+
test "Coverband#start kicks off background reporting if enabled and not in rack server" do
|
7
|
+
Coverband.configuration.stubs(:background_reporting_enabled).returns(true)
|
8
8
|
Coverband::RackServerCheck.expects(:running?).returns(false)
|
9
9
|
Coverband::Background.expects(:start)
|
10
10
|
Coverband.start
|
11
11
|
end
|
12
12
|
|
13
|
-
test
|
13
|
+
test "Coverband#start delays background reporting if enabled and running in a rack server" do
|
14
14
|
Coverband.configuration.stubs(:background_reporting_enabled).returns(true)
|
15
15
|
Coverband::RackServerCheck.expects(:running?).returns(true)
|
16
16
|
Coverband::Background.expects(:start).never
|
17
17
|
Coverband.start
|
18
18
|
end
|
19
19
|
|
20
|
-
test
|
20
|
+
test "Coverband#start does not kick off background reporting if not enabled" do
|
21
21
|
Coverband.configuration.stubs(:background_reporting_enabled).returns(false)
|
22
22
|
Coverband::Background.expects(:start).never
|
23
23
|
::Coverband.start
|
24
24
|
end
|
25
25
|
|
26
|
-
test
|
26
|
+
test "Coverband#configured? works" do
|
27
27
|
Coverband.configure
|
28
28
|
assert Coverband.configured?
|
29
29
|
end
|
30
30
|
|
31
|
-
test
|
32
|
-
Coverband.eager_loading_coverage
|
33
|
-
#some code
|
31
|
+
test "Eager load coverage block" do
|
32
|
+
Coverband.eager_loading_coverage do
|
33
|
+
# some code
|
34
34
|
1 + 1
|
35
|
-
|
35
|
+
end
|
36
36
|
assert_equal :runtime, Coverband.configuration.store.type
|
37
37
|
end
|
38
38
|
|
39
|
-
test
|
39
|
+
test "Eager load coverage" do
|
40
40
|
Coverband.eager_loading_coverage!
|
41
41
|
assert_equal :eager_loading, Coverband.configuration.store.type
|
42
42
|
Coverband.runtime_coverage!
|
@@ -1,7 +1,7 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
require File.expand_path(
|
4
|
-
require
|
3
|
+
require File.expand_path("../../test_helper", File.dirname(__FILE__))
|
4
|
+
require "rack"
|
5
5
|
|
6
6
|
class BackgroundMiddlewareTest < Minitest::Test
|
7
7
|
def setup
|
@@ -11,23 +11,23 @@ class BackgroundMiddlewareTest < Minitest::Test
|
|
11
11
|
end
|
12
12
|
end
|
13
13
|
|
14
|
-
test
|
15
|
-
request = Rack::MockRequest.env_for(
|
14
|
+
test "call app" do
|
15
|
+
request = Rack::MockRequest.env_for("/anything.json")
|
16
16
|
Coverband::Collectors::Coverage.instance.reset_instance
|
17
17
|
middleware = Coverband::BackgroundMiddleware.new(fake_app)
|
18
18
|
results = middleware.call(request)
|
19
|
-
assert_equal
|
19
|
+
assert_equal "/anything.json", results.last
|
20
20
|
end
|
21
21
|
|
22
|
-
test
|
22
|
+
test "pass all rack lint checks" do
|
23
23
|
Coverband::Collectors::Coverage.instance.reset_instance
|
24
24
|
app = Rack::Lint.new(Coverband::BackgroundMiddleware.new(fake_app))
|
25
|
-
env = Rack::MockRequest.env_for(
|
25
|
+
env = Rack::MockRequest.env_for("/hello")
|
26
26
|
app.call(env)
|
27
27
|
end
|
28
28
|
|
29
|
-
test
|
30
|
-
request = Rack::MockRequest.env_for(
|
29
|
+
test "starts background reporter when configured" do
|
30
|
+
request = Rack::MockRequest.env_for("/anything.json")
|
31
31
|
Coverband.configuration.stubs(:background_reporting_enabled).returns(true)
|
32
32
|
Coverband::Background.expects(:start)
|
33
33
|
middleware = Coverband::BackgroundMiddleware.new(fake_app)
|
@@ -38,7 +38,7 @@ class BackgroundMiddlewareTest < Minitest::Test
|
|
38
38
|
|
39
39
|
def fake_app
|
40
40
|
@fake_app ||= lambda do |env|
|
41
|
-
[200, {
|
41
|
+
[200, {"Content-Type" => "text/plain"}, env["PATH_INFO"]]
|
42
42
|
end
|
43
43
|
end
|
44
44
|
end
|
@@ -1,28 +1,40 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
require File.expand_path(
|
3
|
+
require File.expand_path("../../test_helper", File.dirname(__FILE__))
|
4
4
|
|
5
5
|
class BackgroundTest < Minitest::Test
|
6
6
|
class ThreadDouble < Struct.new(:alive)
|
7
|
-
def exit
|
7
|
+
def exit
|
8
|
+
end
|
8
9
|
|
9
10
|
def alive?
|
10
11
|
alive
|
11
12
|
end
|
12
13
|
end
|
13
14
|
|
15
|
+
def setup
|
16
|
+
Coverband.configuration.reset
|
17
|
+
super
|
18
|
+
Coverband.configure do |config|
|
19
|
+
config.background_reporting_sleep_seconds = 60
|
20
|
+
Coverband.configuration.reporting_wiggle = 0
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
14
24
|
def test_start
|
25
|
+
sleep_seconds = Coverband.configuration.background_reporting_sleep_seconds.to_i
|
15
26
|
Thread.expects(:new).yields.returns(ThreadDouble.new(true))
|
16
27
|
Coverband::Background.expects(:loop).yields
|
17
|
-
Coverband::Background.expects(:sleep).with(
|
28
|
+
Coverband::Background.expects(:sleep).with(sleep_seconds)
|
18
29
|
Coverband::Collectors::Coverage.instance.expects(:report_coverage).once
|
19
30
|
2.times { Coverband::Background.start }
|
20
31
|
end
|
21
32
|
|
22
33
|
def test_start_with_wiggle
|
34
|
+
sleep_seconds = Coverband.configuration.background_reporting_sleep_seconds.to_i
|
23
35
|
Thread.expects(:new).yields.returns(ThreadDouble.new(true))
|
24
36
|
Coverband::Background.expects(:loop).yields
|
25
|
-
Coverband::Background.expects(:sleep).with(
|
37
|
+
Coverband::Background.expects(:sleep).with(sleep_seconds + 5)
|
26
38
|
Coverband::Background.expects(:rand).with(10).returns(5)
|
27
39
|
Coverband.configuration.reporting_wiggle = 10
|
28
40
|
Coverband::Collectors::Coverage.instance.expects(:report_coverage).once
|
@@ -32,7 +44,7 @@ class BackgroundTest < Minitest::Test
|
|
32
44
|
def test_start_dead_thread
|
33
45
|
Thread.expects(:new).yields.returns(ThreadDouble.new(false)).twice
|
34
46
|
Coverband::Background.expects(:loop).yields.twice
|
35
|
-
Coverband::Background.expects(:sleep).with(
|
47
|
+
Coverband::Background.expects(:sleep).with(60).twice
|
36
48
|
Coverband::Collectors::Coverage.instance.expects(:report_coverage).twice
|
37
49
|
2.times { Coverband::Background.start }
|
38
50
|
end
|
@@ -1,22 +1,22 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
require File.expand_path(
|
3
|
+
require File.expand_path("../../test_helper", File.dirname(__FILE__))
|
4
4
|
|
5
5
|
class RackServerCheckTest < Minitest::Test
|
6
|
-
test
|
7
|
-
caller_locations = [
|
6
|
+
test "returns true when running in rack server" do
|
7
|
+
caller_locations = ["blah/lib/rack/server.rb"].map { |path| OpenStruct.new(path: path, label: "foo") }
|
8
8
|
Kernel.expects(:caller_locations).returns(caller_locations)
|
9
9
|
assert(Coverband::RackServerCheck.running?)
|
10
10
|
end
|
11
11
|
|
12
|
-
test
|
13
|
-
caller_locations = [
|
12
|
+
test "returns false when not running in rack server" do
|
13
|
+
caller_locations = ["blah/lib/sidekiq/worker.rb"].map { |path| OpenStruct.new(path: path, label: "foo") }
|
14
14
|
Kernel.expects(:caller_locations).returns(caller_locations)
|
15
15
|
refute(Coverband::RackServerCheck.running?)
|
16
16
|
end
|
17
17
|
|
18
|
-
test
|
19
|
-
caller_locations = [OpenStruct.new(path:
|
18
|
+
test "returns true if running within a rails server" do
|
19
|
+
caller_locations = [OpenStruct.new(path: "/lib/rails/commands/commands_tasks.rb", label: "server")]
|
20
20
|
Kernel.expects(:caller_locations).returns(caller_locations)
|
21
21
|
assert(Coverband::RackServerCheck.running?)
|
22
22
|
end
|
@@ -1,7 +1,7 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
require File.expand_path(
|
4
|
-
require
|
3
|
+
require File.expand_path("../../test_helper", File.dirname(__FILE__))
|
4
|
+
require "coverband/integrations/report_middleware"
|
5
5
|
|
6
6
|
class ReportMiddlewareTest < Minitest::Test
|
7
7
|
def setup
|
@@ -11,21 +11,21 @@ class ReportMiddlewareTest < Minitest::Test
|
|
11
11
|
end
|
12
12
|
end
|
13
13
|
|
14
|
-
test
|
15
|
-
request = Rack::MockRequest.env_for(
|
14
|
+
test "reports coverage" do
|
15
|
+
request = Rack::MockRequest.env_for("/anything.json")
|
16
16
|
Coverband::Collectors::Coverage.instance.expects(:report_coverage)
|
17
17
|
middleware = Coverband::ReportMiddleware.new(fake_app)
|
18
18
|
middleware.call(request)
|
19
19
|
end
|
20
20
|
|
21
|
-
test
|
22
|
-
request = Rack::MockRequest.env_for(
|
21
|
+
test "reports coverage when an error is raised" do
|
22
|
+
request = Rack::MockRequest.env_for("/anything.json")
|
23
23
|
Coverband::Collectors::Coverage.instance.reset_instance
|
24
24
|
Coverband::Collectors::Coverage.instance.expects(:report_coverage).once
|
25
25
|
middleware = Coverband::ReportMiddleware.new(fake_app_raise_error)
|
26
26
|
begin
|
27
27
|
middleware.call(request)
|
28
|
-
rescue
|
28
|
+
rescue
|
29
29
|
nil
|
30
30
|
end
|
31
31
|
end
|
@@ -34,11 +34,11 @@ class ReportMiddlewareTest < Minitest::Test
|
|
34
34
|
|
35
35
|
def fake_app
|
36
36
|
@fake_app ||= lambda do |env|
|
37
|
-
[200, {
|
37
|
+
[200, {"Content-Type" => "text/plain"}, env["PATH_INFO"]]
|
38
38
|
end
|
39
39
|
end
|
40
40
|
|
41
41
|
def fake_app_raise_error
|
42
|
-
@fake_app_raise_error ||= -> { raise
|
42
|
+
@fake_app_raise_error ||= -> { raise "hell" }
|
43
43
|
end
|
44
44
|
end
|
@@ -1,11 +1,11 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
require File.expand_path(
|
3
|
+
require File.expand_path("../../test_helper", File.dirname(__FILE__))
|
4
4
|
|
5
5
|
class ResqueWorkerTest < Minitest::Test
|
6
6
|
def enqueue_and_run_job
|
7
7
|
Resque.enqueue(TestResqueJob)
|
8
|
-
|
8
|
+
ENV["QUEUE"] = "resque_coverband"
|
9
9
|
worker = Resque::Worker.new
|
10
10
|
worker.startup
|
11
11
|
worker.work_one_job
|
@@ -21,9 +21,9 @@ class ResqueWorkerTest < Minitest::Test
|
|
21
21
|
Resque.redis = redis
|
22
22
|
end
|
23
23
|
|
24
|
-
test
|
25
|
-
relative_job_file =
|
26
|
-
resque_job_file = File.expand_path(
|
24
|
+
test "resque job coverage" do
|
25
|
+
relative_job_file = "./test/coverband/integrations/test_resque_job.rb"
|
26
|
+
resque_job_file = File.expand_path("./test_resque_job.rb", File.dirname(__FILE__))
|
27
27
|
require resque_job_file
|
28
28
|
|
29
29
|
enqueue_and_run_job
|
@@ -35,13 +35,13 @@ class ResqueWorkerTest < Minitest::Test
|
|
35
35
|
Coverband.runtime_coverage!
|
36
36
|
report = Coverband.configuration.store.get_coverage_report
|
37
37
|
|
38
|
-
if RUBY_PLATFORM ==
|
38
|
+
if RUBY_PLATFORM == "java"
|
39
39
|
# NOTE: the todo test only issue seems to be slightly different in JRuby
|
40
40
|
# were nothing is showing up as runtime Coverage... This appears to be a test only issue
|
41
|
-
assert_equal 1, report[Coverband::EAGER_TYPE][relative_job_file][
|
41
|
+
assert_equal 1, report[Coverband::EAGER_TYPE][relative_job_file]["data"][6]
|
42
42
|
else
|
43
|
-
assert_equal 0, report[Coverband::EAGER_TYPE][relative_job_file][
|
44
|
-
assert_equal 1, report[Coverband::RUNTIME_TYPE][relative_job_file][
|
43
|
+
assert_equal 0, report[Coverband::EAGER_TYPE][relative_job_file]["data"][6]
|
44
|
+
assert_equal 1, report[Coverband::RUNTIME_TYPE][relative_job_file]["data"][6]
|
45
45
|
end
|
46
46
|
end
|
47
47
|
end
|