coverband 5.0.1 → 5.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (53) hide show
  1. checksums.yaml +4 -4
  2. data/.github/ISSUE_TEMPLATE/bug_report.md +38 -0
  3. data/.github/ISSUE_TEMPLATE/feature_request.md +20 -0
  4. data/.github/workflows/main.yml +30 -0
  5. data/CONTRIBUTING.md +1 -0
  6. data/Gemfile +4 -5
  7. data/Gemfile.rails4 +2 -0
  8. data/Gemfile.rails6 +2 -0
  9. data/LICENSE.txt +1 -1
  10. data/README.md +43 -7
  11. data/changes.md +14 -9
  12. data/coverband.gemspec +6 -4
  13. data/lib/coverband/adapters/base.rb +5 -1
  14. data/lib/coverband/adapters/file_store.rb +1 -1
  15. data/lib/coverband/adapters/redis_store.rb +1 -1
  16. data/lib/coverband/at_exit.rb +3 -0
  17. data/lib/coverband/collectors/view_tracker.rb +16 -7
  18. data/lib/coverband/reporters/web.rb +2 -1
  19. data/lib/coverband/utils/dead_methods.rb +63 -0
  20. data/lib/coverband/utils/method_definition_scanner.rb +96 -0
  21. data/lib/coverband/utils/tasks.rb +17 -3
  22. data/lib/coverband/version.rb +1 -1
  23. data/test/coverband/collectors/view_tracker_test.rb +10 -0
  24. data/test/coverband/reporters/web_test.rb +34 -0
  25. data/test/coverband/utils/dead_methods_test.rb +53 -0
  26. data/test/coverband/utils/method_definition_scanner_test.rb +85 -0
  27. data/test/fixtures/casting_invitor.rb +60 -0
  28. data/test/forked/rails_full_stack_test.rb +1 -1
  29. data/test/forked/rails_full_stack_views_test.rb +51 -0
  30. data/test/forked/rails_view_tracker_stack_test.rb +44 -0
  31. data/test/rails4_dummy/app/controllers/dummy_view_controller.rb +16 -0
  32. data/test/rails4_dummy/app/views/dummy_view/show.html.erb +5 -0
  33. data/test/rails4_dummy/app/views/dummy_view/show_haml.html.haml +4 -0
  34. data/test/rails4_dummy/app/views/dummy_view/show_slim.html.slim +4 -0
  35. data/test/rails4_dummy/config/application.rb +1 -0
  36. data/test/rails4_dummy/config/routes.rb +3 -0
  37. data/test/rails5_dummy/app/controllers/dummy_view_controller.rb +16 -0
  38. data/test/rails5_dummy/app/views/dummy_view/show.html.erb +5 -0
  39. data/test/rails5_dummy/app/views/dummy_view/show_haml.html.haml +4 -0
  40. data/test/rails5_dummy/app/views/dummy_view/show_slim.html.slim +4 -0
  41. data/test/rails5_dummy/config/application.rb +2 -0
  42. data/test/rails5_dummy/config/coverband.rb +3 -1
  43. data/test/rails5_dummy/config/routes.rb +3 -0
  44. data/test/rails6_dummy/app/controllers/dummy_view_controller.rb +16 -0
  45. data/test/rails6_dummy/app/views/dummy_view/show.html.erb +5 -0
  46. data/test/rails6_dummy/app/views/dummy_view/show_haml.html.haml +4 -0
  47. data/test/rails6_dummy/app/views/dummy_view/show_slim.html.slim +4 -0
  48. data/test/rails6_dummy/config/application.rb +1 -0
  49. data/test/rails6_dummy/config/routes.rb +3 -0
  50. data/test/test_helper.rb +1 -0
  51. data/views/view_tracker.erb +2 -2
  52. metadata +42 -3
  53. data/.travis.yml +0 -48
@@ -0,0 +1,44 @@
1
+ # frozen_string_literal: true
2
+
3
+ require File.expand_path("../rails_test_helper", File.dirname(__FILE__))
4
+
5
+ class RailsWithoutConfigStackTest < Minitest::Test
6
+ def setup
7
+ super
8
+ setup_server
9
+ end
10
+
11
+ def teardown
12
+ super
13
+ shutdown_server
14
+ end
15
+
16
+ test "check view tracker" do
17
+ output = `sleep 7 && curl http://localhost:9999/dummy_view/show`
18
+ assert output.match(/rendered view/)
19
+ assert output.match(/I am no dummy view tracker text/)
20
+ output = `sleep 1 && curl http://localhost:9999/coverage/view_tracker`
21
+ assert output.match(/Used Views: \(1\)/)
22
+ assert output.match(/dummy_view\/show/)
23
+ end
24
+
25
+ private
26
+
27
+ # NOTE: We aren't leveraging Capybara because it loads all of our other test helpers and such,
28
+ # which in turn Configures coverband making it impossible to test the configuration error
29
+ def setup_server
30
+ ENV["RAILS_ENV"] = "test"
31
+ require "rails"
32
+ fork do
33
+ exec "cd test/rails#{Rails::VERSION::MAJOR}_dummy && COVERBAND_TEST=test bundle exec rackup config.ru -p 9999 --pid /tmp/testrack.pid"
34
+ end
35
+ end
36
+
37
+ def shutdown_server
38
+ if File.exist?("/tmp/testrack.pid")
39
+ pid = `cat /tmp/testrack.pid`&.strip&.to_i
40
+ Process.kill("HUP", pid)
41
+ sleep 1
42
+ end
43
+ end
44
+ end
@@ -0,0 +1,16 @@
1
+ class DummyViewController < ActionController::Base
2
+ def show
3
+ @text = "I am no dummy view tracker text"
4
+ render layout: false
5
+ end
6
+
7
+ def show_haml
8
+ @text = "I am haml text"
9
+ render layout: false
10
+ end
11
+
12
+ def show_slim
13
+ @text = "I am slim text"
14
+ render layout: false
15
+ end
16
+ end
@@ -0,0 +1,5 @@
1
+ rendered view
2
+
3
+ <div>
4
+ <%= @text %>
5
+ </div>
@@ -0,0 +1,4 @@
1
+ rendered haml view
2
+
3
+ #foo
4
+ = @text
@@ -0,0 +1,4 @@
1
+ rendered slim view
2
+
3
+ #content
4
+ = @text
@@ -10,5 +10,6 @@ Bundler.require(*Rails.groups)
10
10
  module Rails4Dummy
11
11
  class Application < Rails::Application
12
12
  config.eager_load = true
13
+ config.consider_all_requests_local = true
13
14
  end
14
15
  end
@@ -1,4 +1,7 @@
1
1
  Rails.application.routes.draw do
2
2
  get "dummy/show"
3
+ get "dummy_view/show", to: "dummy_view#show"
4
+ get "dummy_view/show_haml", to: "dummy_view#show_haml"
5
+ get "dummy_view/show_slim", to: "dummy_view#show_slim"
3
6
  mount Coverband::Reporters::Web.new, at: "/coverage"
4
7
  end
@@ -0,0 +1,16 @@
1
+ class DummyViewController < ActionController::Base
2
+ def show
3
+ @text = "I am no dummy view tracker text"
4
+ render layout: false
5
+ end
6
+
7
+ def show_haml
8
+ @text = "I am haml text"
9
+ render layout: false
10
+ end
11
+
12
+ def show_slim
13
+ @text = "I am slim text"
14
+ render layout: false
15
+ end
16
+ end
@@ -0,0 +1,5 @@
1
+ rendered view
2
+
3
+ <div>
4
+ <%= @text %>
5
+ </div>
@@ -0,0 +1,4 @@
1
+ rendered haml view
2
+
3
+ #foo
4
+ = @text
@@ -0,0 +1,4 @@
1
+ rendered slim view
2
+
3
+ #content
4
+ = @text
@@ -2,11 +2,13 @@
2
2
 
3
3
  require "rails"
4
4
  require "action_controller/railtie"
5
+ require "action_view/railtie"
5
6
  require "coverband"
6
7
  Bundler.require(*Rails.groups)
7
8
 
8
9
  module Rails5Dummy
9
10
  class Application < Rails::Application
10
11
  config.eager_load = true
12
+ config.consider_all_requests_local = true
11
13
  end
12
14
  end
@@ -1,7 +1,9 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  Coverband.configure do |config|
4
- config.root = Dir.pwd
4
+ # NOTE: we reuse this config in each of the fake rails projects
5
+ # the below ensures the root is set to the correct fake project
6
+ config.root = ::File.expand_path("../../../", __FILE__).to_s + "/rails#{Rails::VERSION::MAJOR}_dummy"
5
7
  config.store = Coverband::Adapters::RedisStore.new(Redis.new(db: 2, url: ENV["REDIS_URL"]), redis_namespace: "coverband_test") if defined? Redis
6
8
  config.ignore = %w[.erb$ .slim$]
7
9
  config.root_paths = []
@@ -1,4 +1,7 @@
1
1
  Rails.application.routes.draw do
2
2
  get "dummy/show"
3
+ get "dummy_view/show", to: "dummy_view#show"
4
+ get "dummy_view/show_haml", to: "dummy_view#show_haml"
5
+ get "dummy_view/show_slim", to: "dummy_view#show_slim"
3
6
  mount Coverband::Reporters::Web.new, at: "/coverage"
4
7
  end
@@ -0,0 +1,16 @@
1
+ class DummyViewController < ActionController::Base
2
+ def show
3
+ @text = "I am no dummy view tracker text"
4
+ render layout: false
5
+ end
6
+
7
+ def show_haml
8
+ @text = "I am haml text"
9
+ render layout: false
10
+ end
11
+
12
+ def show_slim
13
+ @text = "I am slim text"
14
+ render layout: false
15
+ end
16
+ end
@@ -0,0 +1,5 @@
1
+ rendered view
2
+
3
+ <div>
4
+ <%= @text %>
5
+ </div>
@@ -0,0 +1,4 @@
1
+ rendered haml view
2
+
3
+ #foo
4
+ = @text
@@ -0,0 +1,4 @@
1
+ rendered slim view
2
+
3
+ #content
4
+ = @text
@@ -10,5 +10,6 @@ Bundler.require(*Rails.groups)
10
10
  module Rails6Dummy
11
11
  class Application < Rails::Application
12
12
  config.eager_load = true
13
+ config.consider_all_requests_local = true
13
14
  end
14
15
  end
@@ -1,4 +1,7 @@
1
1
  Rails.application.routes.draw do
2
2
  get "dummy/show"
3
+ get "dummy_view/show", to: "dummy_view#show"
4
+ get "dummy_view/show_haml", to: "dummy_view#show_haml"
5
+ get "dummy_view/show_slim", to: "dummy_view#show_slim"
3
6
  mount Coverband::Reporters::Web.new, at: "/coverage"
4
7
  end
@@ -3,6 +3,7 @@
3
3
  original_verbosity = $VERBOSE
4
4
  $VERBOSE = nil
5
5
  require "rubygems"
6
+ require "pry-byebug" unless ENV["CI"]
6
7
  require "simplecov"
7
8
  require "coveralls"
8
9
  require "minitest/autorun"
@@ -26,7 +26,7 @@
26
26
  <p>These views have not been rendered since recording started at <%= tracker.tracking_since %></p>
27
27
  <ul>
28
28
  <% tracker.unused_views.each do |view_file| %>
29
- <li><%= view_file %></li>
29
+ <li class="unused-views"><%= view_file %></li>
30
30
  <% end %>
31
31
  </ul>
32
32
 
@@ -34,7 +34,7 @@
34
34
  <p>These views have been rendered at least once</p>
35
35
  <ul>
36
36
  <% tracker.used_views.each_pair do |view_file, time_at| %>
37
- <li>
37
+ <li class="used-views">
38
38
  <%= view_file %>
39
39
  <span class="last_seen_at">last activity recorded <%= Time.at(time_at.to_i)%></span>
40
40
  <% if Coverband.configuration.web_enable_clear %>
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: 5.0.1
4
+ version: 5.1.0
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: 2020-09-07 00:00:00.000000000 Z
12
+ date: 2020-12-31 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: benchmark-ips
@@ -270,11 +270,14 @@ executables: []
270
270
  extensions: []
271
271
  extra_rdoc_files: []
272
272
  files:
273
+ - ".github/ISSUE_TEMPLATE/bug_report.md"
274
+ - ".github/ISSUE_TEMPLATE/feature_request.md"
275
+ - ".github/workflows/main.yml"
273
276
  - ".gitignore"
274
277
  - ".jrubyrc"
275
278
  - ".standard.yml"
276
- - ".travis.yml"
277
279
  - CODE_OF_CONDUCT.md
280
+ - CONTRIBUTING.md
278
281
  - Gemfile
279
282
  - Gemfile.rails4
280
283
  - Gemfile.rails6
@@ -309,11 +312,13 @@ files:
309
312
  - lib/coverband/reporters/html_report.rb
310
313
  - lib/coverband/reporters/web.rb
311
314
  - lib/coverband/utils/absolute_file_converter.rb
315
+ - lib/coverband/utils/dead_methods.rb
312
316
  - lib/coverband/utils/file_hasher.rb
313
317
  - lib/coverband/utils/file_list.rb
314
318
  - lib/coverband/utils/html_formatter.rb
315
319
  - lib/coverband/utils/jruby_ext.rb
316
320
  - lib/coverband/utils/lines_classifier.rb
321
+ - lib/coverband/utils/method_definition_scanner.rb
317
322
  - lib/coverband/utils/railtie.rb
318
323
  - lib/coverband/utils/relative_file_converter.rb
319
324
  - lib/coverband/utils/result.rb
@@ -382,10 +387,12 @@ files:
382
387
  - test/coverband/reporters/html_test.rb
383
388
  - test/coverband/reporters/web_test.rb
384
389
  - test/coverband/utils/absolute_file_converter_test.rb
390
+ - test/coverband/utils/dead_methods_test.rb
385
391
  - test/coverband/utils/file_hasher_test.rb
386
392
  - test/coverband/utils/file_list_test.rb
387
393
  - test/coverband/utils/html_formatter_test.rb
388
394
  - test/coverband/utils/lines_classifier_test.rb
395
+ - test/coverband/utils/method_definition_scanner_test.rb
389
396
  - test/coverband/utils/relative_file_converter_test.rb
390
397
  - test/coverband/utils/result_test.rb
391
398
  - test/coverband/utils/results_test.rb
@@ -396,17 +403,24 @@ files:
396
403
  - test/fake_app/basic_rack.rb
397
404
  - test/fixtures/app/controllers/sample_controller.rb
398
405
  - test/fixtures/app/models/user.rb
406
+ - test/fixtures/casting_invitor.rb
399
407
  - test/fixtures/never.rb
400
408
  - test/fixtures/sample.rb
401
409
  - test/fixtures/skipped.rb
402
410
  - test/fixtures/skipped_and_executed.rb
403
411
  - test/fixtures/utf-8.rb
404
412
  - test/forked/rails_full_stack_test.rb
413
+ - test/forked/rails_full_stack_views_test.rb
405
414
  - test/forked/rails_rake_full_stack_test.rb
415
+ - test/forked/rails_view_tracker_stack_test.rb
406
416
  - test/integration/full_stack_test.rb
407
417
  - test/jruby_check.rb
408
418
  - test/rails4_dummy/Rakefile
409
419
  - test/rails4_dummy/app/controllers/dummy_controller.rb
420
+ - test/rails4_dummy/app/controllers/dummy_view_controller.rb
421
+ - test/rails4_dummy/app/views/dummy_view/show.html.erb
422
+ - test/rails4_dummy/app/views/dummy_view/show_haml.html.haml
423
+ - test/rails4_dummy/app/views/dummy_view/show_slim.html.slim
410
424
  - test/rails4_dummy/config.ru
411
425
  - test/rails4_dummy/config/application.rb
412
426
  - test/rails4_dummy/config/boot.rb
@@ -418,6 +432,10 @@ files:
418
432
  - test/rails4_dummy/tmp/.keep
419
433
  - test/rails5_dummy/Rakefile
420
434
  - test/rails5_dummy/app/controllers/dummy_controller.rb
435
+ - test/rails5_dummy/app/controllers/dummy_view_controller.rb
436
+ - test/rails5_dummy/app/views/dummy_view/show.html.erb
437
+ - test/rails5_dummy/app/views/dummy_view/show_haml.html.haml
438
+ - test/rails5_dummy/app/views/dummy_view/show_slim.html.slim
421
439
  - test/rails5_dummy/config.ru
422
440
  - test/rails5_dummy/config/application.rb
423
441
  - test/rails5_dummy/config/coverband.rb
@@ -427,6 +445,10 @@ files:
427
445
  - test/rails5_dummy/tmp/.keep
428
446
  - test/rails6_dummy/Rakefile
429
447
  - test/rails6_dummy/app/controllers/dummy_controller.rb
448
+ - test/rails6_dummy/app/controllers/dummy_view_controller.rb
449
+ - test/rails6_dummy/app/views/dummy_view/show.html.erb
450
+ - test/rails6_dummy/app/views/dummy_view/show_haml.html.haml
451
+ - test/rails6_dummy/app/views/dummy_view/show_slim.html.slim
430
452
  - test/rails6_dummy/config.ru
431
453
  - test/rails6_dummy/config/application.rb
432
454
  - test/rails6_dummy/config/boot.rb
@@ -500,10 +522,12 @@ test_files:
500
522
  - test/coverband/reporters/html_test.rb
501
523
  - test/coverband/reporters/web_test.rb
502
524
  - test/coverband/utils/absolute_file_converter_test.rb
525
+ - test/coverband/utils/dead_methods_test.rb
503
526
  - test/coverband/utils/file_hasher_test.rb
504
527
  - test/coverband/utils/file_list_test.rb
505
528
  - test/coverband/utils/html_formatter_test.rb
506
529
  - test/coverband/utils/lines_classifier_test.rb
530
+ - test/coverband/utils/method_definition_scanner_test.rb
507
531
  - test/coverband/utils/relative_file_converter_test.rb
508
532
  - test/coverband/utils/result_test.rb
509
533
  - test/coverband/utils/results_test.rb
@@ -514,17 +538,24 @@ test_files:
514
538
  - test/fake_app/basic_rack.rb
515
539
  - test/fixtures/app/controllers/sample_controller.rb
516
540
  - test/fixtures/app/models/user.rb
541
+ - test/fixtures/casting_invitor.rb
517
542
  - test/fixtures/never.rb
518
543
  - test/fixtures/sample.rb
519
544
  - test/fixtures/skipped.rb
520
545
  - test/fixtures/skipped_and_executed.rb
521
546
  - test/fixtures/utf-8.rb
522
547
  - test/forked/rails_full_stack_test.rb
548
+ - test/forked/rails_full_stack_views_test.rb
523
549
  - test/forked/rails_rake_full_stack_test.rb
550
+ - test/forked/rails_view_tracker_stack_test.rb
524
551
  - test/integration/full_stack_test.rb
525
552
  - test/jruby_check.rb
526
553
  - test/rails4_dummy/Rakefile
527
554
  - test/rails4_dummy/app/controllers/dummy_controller.rb
555
+ - test/rails4_dummy/app/controllers/dummy_view_controller.rb
556
+ - test/rails4_dummy/app/views/dummy_view/show.html.erb
557
+ - test/rails4_dummy/app/views/dummy_view/show_haml.html.haml
558
+ - test/rails4_dummy/app/views/dummy_view/show_slim.html.slim
528
559
  - test/rails4_dummy/config.ru
529
560
  - test/rails4_dummy/config/application.rb
530
561
  - test/rails4_dummy/config/boot.rb
@@ -536,6 +567,10 @@ test_files:
536
567
  - test/rails4_dummy/tmp/.keep
537
568
  - test/rails5_dummy/Rakefile
538
569
  - test/rails5_dummy/app/controllers/dummy_controller.rb
570
+ - test/rails5_dummy/app/controllers/dummy_view_controller.rb
571
+ - test/rails5_dummy/app/views/dummy_view/show.html.erb
572
+ - test/rails5_dummy/app/views/dummy_view/show_haml.html.haml
573
+ - test/rails5_dummy/app/views/dummy_view/show_slim.html.slim
539
574
  - test/rails5_dummy/config.ru
540
575
  - test/rails5_dummy/config/application.rb
541
576
  - test/rails5_dummy/config/coverband.rb
@@ -545,6 +580,10 @@ test_files:
545
580
  - test/rails5_dummy/tmp/.keep
546
581
  - test/rails6_dummy/Rakefile
547
582
  - test/rails6_dummy/app/controllers/dummy_controller.rb
583
+ - test/rails6_dummy/app/controllers/dummy_view_controller.rb
584
+ - test/rails6_dummy/app/views/dummy_view/show.html.erb
585
+ - test/rails6_dummy/app/views/dummy_view/show_haml.html.haml
586
+ - test/rails6_dummy/app/views/dummy_view/show_slim.html.slim
548
587
  - test/rails6_dummy/config.ru
549
588
  - test/rails6_dummy/config/application.rb
550
589
  - test/rails6_dummy/config/boot.rb
@@ -1,48 +0,0 @@
1
- language: ruby
2
- rvm:
3
- - "2.3"
4
- - "2.4"
5
- - "2.5"
6
- - "2.6.1"
7
- - "2.7"
8
- - jruby-9.2.6.0
9
- gemfile:
10
- - Gemfile
11
- - Gemfile.rails4
12
- - Gemfile.rails6
13
- env:
14
- global:
15
- # --dev improves JRuby startup time
16
- # See https://github.com/jruby/jruby/wiki/Improving-startup-time
17
- - JRUBY_OPTS="--dev"
18
- - JAVA_OPTS="--add-opens java.base/{java.security.cert=ALL-UNNAMED --add-opens java.base/java.security=ALL-UNNAMED --add-opens java.base/java.util.zip=ALL-UNNAMED"
19
-
20
- jobs:
21
- exclude:
22
- - rvm: "2.3"
23
- gemfile: Gemfile.rails6
24
- - rvm: "2.4"
25
- gemfile: Gemfile.rails6
26
- - rvm: "2.7"
27
- gemfile: Gemfile.rails4
28
- - rvm: jruby-9.2.6.0
29
- gemfile: Gemfile.rails4
30
-
31
- cache:
32
- bundler: true
33
- directories:
34
- - $HOME/lua51
35
- services:
36
- - redis-server
37
- script:
38
- - sudo ./lua/install.sh
39
- - $HOME/lua51/bin/busted lua/test/*
40
- - bundle exec standardrb
41
- - COVERBAND_HASH_REDIS_STORE=t bundle exec rake
42
- - COVERBAND_HASH_REDIS_STORE=t bundle exec rake forked_tests
43
- - bundle exec rake
44
- - bundle exec rake forked_tests
45
- # remove this for now as it is flaky
46
- # passes locally on 2.3.5 on travis passes sometimes on 2.4 and always on 2.6.1
47
- #- bundle exec rake benchmarks:memory
48
- - bundle exec rake benchmarks