coverband 5.1.0.rcmailer.2 → 5.2.0.rc.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (41) hide show
  1. checksums.yaml +4 -4
  2. data/.github/workflows/diagram.yml +16 -0
  3. data/.github/workflows/main.yml +5 -5
  4. data/Gemfile +2 -5
  5. data/README.md +33 -1
  6. data/changes.md +19 -66
  7. data/coverband.gemspec +16 -4
  8. data/diagram.svg +1 -0
  9. data/lib/coverband/adapters/base.rb +8 -7
  10. data/lib/coverband/adapters/file_store.rb +1 -1
  11. data/lib/coverband/adapters/hash_redis_store.rb +1 -1
  12. data/lib/coverband/adapters/null_store.rb +42 -0
  13. data/lib/coverband/adapters/redis_store.rb +1 -1
  14. data/lib/coverband/collectors/coverage.rb +19 -1
  15. data/lib/coverband/collectors/view_tracker.rb +27 -20
  16. data/lib/coverband/collectors/view_tracker_service.rb +3 -3
  17. data/lib/coverband/configuration.rb +11 -2
  18. data/lib/coverband/integrations/background.rb +6 -3
  19. data/lib/coverband/reporters/base.rb +1 -1
  20. data/lib/coverband/reporters/web.rb +4 -4
  21. data/lib/coverband/utils/dead_methods.rb +63 -0
  22. data/lib/coverband/utils/method_definition_scanner.rb +96 -0
  23. data/lib/coverband/utils/railtie.rb +3 -2
  24. data/lib/coverband/utils/result.rb +1 -1
  25. data/lib/coverband/utils/source_file.rb +2 -2
  26. data/lib/coverband/utils/tasks.rb +17 -3
  27. data/lib/coverband/version.rb +2 -2
  28. data/lib/coverband.rb +1 -0
  29. data/public/dependencies.js +4 -4
  30. data/roadmap.md +56 -0
  31. data/test/coverband/adapters/null_store_test.rb +39 -0
  32. data/test/coverband/configuration_test.rb +5 -5
  33. data/test/coverband/utils/dead_methods_test.rb +53 -0
  34. data/test/coverband/utils/method_definition_scanner_test.rb +85 -0
  35. data/test/fixtures/casting_invitor.rb +60 -0
  36. data/test/forked/rails_full_stack_test.rb +1 -1
  37. data/test/integration/full_stack_deferred_eager_test.rb +51 -0
  38. data/test/test_helper.rb +1 -0
  39. data/test/unique_files.rb +3 -3
  40. data/views/file_list.erb +2 -2
  41. metadata +25 -4
@@ -0,0 +1,85 @@
1
+ # frozen_string_literal: true
2
+
3
+ require File.expand_path("../../test_helper", File.dirname(__FILE__))
4
+
5
+ if defined?(RubyVM::AbstractSyntaxTree)
6
+ require "coverband/utils/method_definition_scanner"
7
+ module Coverband
8
+ module Utils
9
+ class MethodBodyTest < Minitest::Test
10
+ def test_no_method_body_coverage
11
+ method_body =
12
+ MethodDefinitionScanner::MethodBody.new(
13
+ MethodDefinitionScanner::MethodDefinition.new(
14
+ first_line_number: 4,
15
+ last_line_number: 6,
16
+ name: :bark,
17
+ class_name: :Dog,
18
+ file_path: "./test/dog.rb"
19
+ )
20
+ )
21
+ refute(method_body.coverage?([nil, nil, 1, 1, 0, nil, 1]))
22
+ end
23
+
24
+ def test_method_body_coverage
25
+ method_body =
26
+ MethodDefinitionScanner::MethodBody.new(
27
+ MethodDefinitionScanner::MethodDefinition.new(
28
+ first_line_number: 4,
29
+ last_line_number: 6,
30
+ name: :bark,
31
+ class_name: :Dog,
32
+ file_path: "./test/dog.rb"
33
+ )
34
+ )
35
+ assert(method_body.coverage?([nil, nil, 1, 1, 1, nil, 1]))
36
+ end
37
+ end
38
+
39
+ class MethodDefinitionScannerTest < Minitest::Test
40
+ def test_scan
41
+ method_definitions = MethodDefinitionScanner.scan("./test/dog.rb")
42
+ assert(method_definitions)
43
+ assert_equal(1, method_definitions.length)
44
+ method_definition = method_definitions.first # assert_equal(4, method.first_line)
45
+ assert_equal(4, method_definition.first_line_number)
46
+ assert_equal(6, method_definition.last_line_number)
47
+ assert_equal(:bark, method_definition.name)
48
+ assert_equal(:Dog, method_definition.class_name)
49
+ end
50
+
51
+ def test_scan_large_class
52
+ method_definitions =
53
+ MethodDefinitionScanner.scan("./test/fixtures/casting_invitor.rb")
54
+ method_first_line_numbers =
55
+ method_definitions.map(&:first_line_number)
56
+ assert_equal(
57
+ [6, 13, 17, 35, 40, 44, 48, 52],
58
+ method_first_line_numbers
59
+ )
60
+ method_last_line_numbers = method_definitions.map(&:last_line_number)
61
+ assert_equal(
62
+ [11, 15, 31, 38, 42, 46, 50, 59],
63
+ method_last_line_numbers
64
+ )
65
+ method_names = method_definitions.map(&:name)
66
+ assert_equal(
67
+ %i[
68
+ initialize
69
+ valid?
70
+ deliver
71
+ invalid_invitees
72
+ invitee_list
73
+ valid_message?
74
+ valid_invitees?
75
+ create_invitation
76
+ ],
77
+ method_names
78
+ )
79
+ class_names = method_definitions.map(&:class_name)
80
+ assert_equal(8.times.map { :CastingInviter }, class_names)
81
+ end
82
+ end
83
+ end
84
+ end
85
+ end
@@ -0,0 +1,60 @@
1
+ class CastingInviter
2
+ EMAIL_REGEX = /\A([^@\s]+)@((?:[-a-z0-9]+\.)+[a-z]{2,})\z/
3
+
4
+ attr_reader :message, :invitees, :casting
5
+
6
+ def initialize(attributes = {})
7
+ @message = attributes[:message] || ""
8
+ @invitees = attributes[:invitees] || ""
9
+ @sender = attributes[:sender]
10
+ @casting = attributes[:casting]
11
+ end
12
+
13
+ def valid?
14
+ valid_message? && valid_invitees?
15
+ end
16
+
17
+ def deliver
18
+ if valid?
19
+ invitee_list.each do |email|
20
+ invitation = create_invitation(email)
21
+ Mailer.invitation_notification(invitation, @message)
22
+ end
23
+ else
24
+ failure_message =
25
+ "Your #{
26
+ @casting
27
+ } message couldn’t be sent. Invitees emails or message are invalid"
28
+ invitation = create_invitation(@sender)
29
+ Mailer.invitation_notification(invitation, failure_message)
30
+ end
31
+ end
32
+
33
+ private
34
+
35
+ def invalid_invitees
36
+ @invalid_invitees ||=
37
+ invitee_list.map { |item| item unless item.match(EMAIL_REGEX) }.compact
38
+ end
39
+
40
+ def invitee_list
41
+ @invitee_list ||= @invitees.gsub(/\s+/, "").split(/[\n,;]+/)
42
+ end
43
+
44
+ def valid_message?
45
+ @message.present?
46
+ end
47
+
48
+ def valid_invitees?
49
+ invalid_invitees.empty?
50
+ end
51
+
52
+ def create_invitation(email)
53
+ Invitation.create(
54
+ casting: @casting,
55
+ sender: @sender,
56
+ invitee_email: email,
57
+ status: "pending"
58
+ )
59
+ end
60
+ end
@@ -58,7 +58,7 @@ class RailsFullStackTest < Minitest::Test
58
58
 
59
59
  # we don't want this to run during our standard test suite
60
60
  # as the below profiler changes the runtime
61
- # and shold only be included for isolated processes
61
+ # and should only be included for isolated processes
62
62
  begin
63
63
  require "memory_profiler"
64
64
 
@@ -0,0 +1,51 @@
1
+ # frozen_string_literal: true
2
+
3
+ require File.expand_path("../test_helper", File.dirname(__FILE__))
4
+ require "rack"
5
+
6
+ class FullStackDeferredEagerTest < Minitest::Test
7
+ REDIS_STORAGE_FORMAT_VERSION = Coverband::Adapters::RedisStore::REDIS_STORAGE_FORMAT_VERSION
8
+ TEST_RACK_APP = "../fake_app/basic_rack.rb"
9
+
10
+ def setup
11
+ super
12
+ Coverband::Collectors::Coverage.instance.reset_instance
13
+ Coverband.configure do |config|
14
+ config.background_reporting_enabled = false
15
+ config.track_gems = true
16
+ config.defer_eager_loading_data = true
17
+ end
18
+ Coverband.start
19
+ Coverband::Collectors::Coverage.instance.eager_loading!
20
+ @rack_file = require_unique_file "fake_app/basic_rack.rb"
21
+ Coverband.report_coverage
22
+ Coverband::Collectors::Coverage.instance.runtime!
23
+ end
24
+
25
+ test "call app" do
26
+ # eager loaded class coverage starts empty
27
+ Coverband.eager_loading_coverage!
28
+ expected = {}
29
+ assert_equal expected, Coverband.configuration.store.coverage
30
+
31
+ Coverband::Collectors::Coverage.instance.runtime!
32
+ request = Rack::MockRequest.env_for("/anything.json")
33
+ middleware = Coverband::BackgroundMiddleware.new(fake_app_with_lines)
34
+ results = middleware.call(request)
35
+ assert_equal "Hello Rack!", results.last
36
+ Coverband.report_coverage
37
+ expected = [nil, nil, 0, nil, 0, 0, 1, nil, nil]
38
+ assert_equal expected, Coverband.configuration.store.coverage[@rack_file]["data"]
39
+
40
+ # eager loaded class coverage is saved at first normal coverage report
41
+ Coverband.eager_loading_coverage!
42
+ expected = [nil, nil, 1, nil, 1, 1, 0, nil, nil]
43
+ assert_equal expected, Coverband.configuration.store.coverage[@rack_file]["data"]
44
+ end
45
+
46
+ private
47
+
48
+ def fake_app_with_lines
49
+ @fake_app_with_lines ||= ::HelloWorld.new
50
+ end
51
+ end
data/test/test_helper.rb CHANGED
@@ -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"
data/test/unique_files.rb CHANGED
@@ -20,10 +20,10 @@ def require_unique_file(file = "dog.rb", variables = {})
20
20
  Coverband::Utils::RelativeFileConverter.convert(File.expand_path(temp_file))
21
21
  end
22
22
 
23
- @@dogs = 0
24
23
  def require_class_unique_file
25
- @@dogs += 1
26
- require_unique_file("dog.rb.erb", dog_number: @@dogs)
24
+ @dogs ||= 0
25
+ @dogs += 1
26
+ require_unique_file("dog.rb.erb", dog_number: @dogs)
27
27
  end
28
28
 
29
29
  def remove_unique_files
data/views/file_list.erb CHANGED
@@ -22,8 +22,8 @@
22
22
  <thead>
23
23
  <tr>
24
24
  <th title="The source file name">File</th>
25
- <th title="Percentage of relavent lines covered (load & runtime)">% covered</th>
26
- <th title="Runtime Percentage of relavent lines covered">% runtime</th>
25
+ <th title="Percentage of relevant lines covered (load & runtime)">% covered</th>
26
+ <th title="Runtime Percentage of relevant lines covered">% runtime</th>
27
27
  <th title="The total line number count for the file">Lines</th>
28
28
  <th title="Line number count excluding comments, whitespace, etc...">Relevant Lines</th>
29
29
  <th title="The number of lines covered (load & runtime)">Lines covered</th>
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.1.0.rcmailer.2
4
+ version: 5.2.0.rc.2
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-12-30 00:00:00.000000000 Z
12
+ date: 2022-01-04 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: benchmark-ips
@@ -272,6 +272,7 @@ extra_rdoc_files: []
272
272
  files:
273
273
  - ".github/ISSUE_TEMPLATE/bug_report.md"
274
274
  - ".github/ISSUE_TEMPLATE/feature_request.md"
275
+ - ".github/workflows/diagram.yml"
275
276
  - ".github/workflows/main.yml"
276
277
  - ".gitignore"
277
278
  - ".jrubyrc"
@@ -288,11 +289,13 @@ files:
288
289
  - changes.md
289
290
  - config.ru
290
291
  - coverband.gemspec
292
+ - diagram.svg
291
293
  - lib/alternative_coverband_patch.rb
292
294
  - lib/coverband.rb
293
295
  - lib/coverband/adapters/base.rb
294
296
  - lib/coverband/adapters/file_store.rb
295
297
  - lib/coverband/adapters/hash_redis_store.rb
298
+ - lib/coverband/adapters/null_store.rb
296
299
  - lib/coverband/adapters/redis_store.rb
297
300
  - lib/coverband/adapters/stdout_store.rb
298
301
  - lib/coverband/adapters/web_service_store.rb
@@ -312,11 +315,13 @@ files:
312
315
  - lib/coverband/reporters/html_report.rb
313
316
  - lib/coverband/reporters/web.rb
314
317
  - lib/coverband/utils/absolute_file_converter.rb
318
+ - lib/coverband/utils/dead_methods.rb
315
319
  - lib/coverband/utils/file_hasher.rb
316
320
  - lib/coverband/utils/file_list.rb
317
321
  - lib/coverband/utils/html_formatter.rb
318
322
  - lib/coverband/utils/jruby_ext.rb
319
323
  - lib/coverband/utils/lines_classifier.rb
324
+ - lib/coverband/utils/method_definition_scanner.rb
320
325
  - lib/coverband/utils/railtie.rb
321
326
  - lib/coverband/utils/relative_file_converter.rb
322
327
  - lib/coverband/utils/result.rb
@@ -356,6 +361,7 @@ files:
356
361
  - public/images/ui-icons_cd0a0a_256x240.png
357
362
  - public/loading.gif
358
363
  - public/magnify.png
364
+ - roadmap.md
359
365
  - test/benchmarks/.gitignore
360
366
  - test/benchmarks/benchmark.rake
361
367
  - test/benchmarks/coverage_fork.sh
@@ -366,6 +372,7 @@ files:
366
372
  - test/coverband/adapters/base_test.rb
367
373
  - test/coverband/adapters/file_store_test.rb
368
374
  - test/coverband/adapters/hash_redis_store_test.rb
375
+ - test/coverband/adapters/null_store_test.rb
369
376
  - test/coverband/adapters/redis_store_test.rb
370
377
  - test/coverband/adapters/web_service_store_test.rb
371
378
  - test/coverband/at_exit_test.rb
@@ -385,10 +392,12 @@ files:
385
392
  - test/coverband/reporters/html_test.rb
386
393
  - test/coverband/reporters/web_test.rb
387
394
  - test/coverband/utils/absolute_file_converter_test.rb
395
+ - test/coverband/utils/dead_methods_test.rb
388
396
  - test/coverband/utils/file_hasher_test.rb
389
397
  - test/coverband/utils/file_list_test.rb
390
398
  - test/coverband/utils/html_formatter_test.rb
391
399
  - test/coverband/utils/lines_classifier_test.rb
400
+ - test/coverband/utils/method_definition_scanner_test.rb
392
401
  - test/coverband/utils/relative_file_converter_test.rb
393
402
  - test/coverband/utils/result_test.rb
394
403
  - test/coverband/utils/results_test.rb
@@ -399,6 +408,7 @@ files:
399
408
  - test/fake_app/basic_rack.rb
400
409
  - test/fixtures/app/controllers/sample_controller.rb
401
410
  - test/fixtures/app/models/user.rb
411
+ - test/fixtures/casting_invitor.rb
402
412
  - test/fixtures/never.rb
403
413
  - test/fixtures/sample.rb
404
414
  - test/fixtures/skipped.rb
@@ -408,6 +418,7 @@ files:
408
418
  - test/forked/rails_full_stack_views_test.rb
409
419
  - test/forked/rails_rake_full_stack_test.rb
410
420
  - test/forked/rails_view_tracker_stack_test.rb
421
+ - test/integration/full_stack_deferred_eager_test.rb
411
422
  - test/integration/full_stack_test.rb
412
423
  - test/jruby_check.rb
413
424
  - test/rails4_dummy/Rakefile
@@ -467,7 +478,12 @@ files:
467
478
  homepage: https://github.com/danmayer/coverband
468
479
  licenses:
469
480
  - MIT
470
- metadata: {}
481
+ metadata:
482
+ homepage_uri: https://github.com/danmayer/coverband
483
+ bug_tracker_uri: https://github.com/danmayer/coverband/issues
484
+ documentation_uri: https://github.com/danmayer/coverband
485
+ changelog_uri: https://github.com/danmayer/coverband/blob/main/changes.md
486
+ source_code_uri: https://github.com/danmayer/coverband
471
487
  post_install_message:
472
488
  rdoc_options: []
473
489
  require_paths:
@@ -476,7 +492,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
476
492
  requirements:
477
493
  - - ">="
478
494
  - !ruby/object:Gem::Version
479
- version: '0'
495
+ version: '2.3'
480
496
  required_rubygems_version: !ruby/object:Gem::Requirement
481
497
  requirements:
482
498
  - - ">"
@@ -498,6 +514,7 @@ test_files:
498
514
  - test/coverband/adapters/base_test.rb
499
515
  - test/coverband/adapters/file_store_test.rb
500
516
  - test/coverband/adapters/hash_redis_store_test.rb
517
+ - test/coverband/adapters/null_store_test.rb
501
518
  - test/coverband/adapters/redis_store_test.rb
502
519
  - test/coverband/adapters/web_service_store_test.rb
503
520
  - test/coverband/at_exit_test.rb
@@ -517,10 +534,12 @@ test_files:
517
534
  - test/coverband/reporters/html_test.rb
518
535
  - test/coverband/reporters/web_test.rb
519
536
  - test/coverband/utils/absolute_file_converter_test.rb
537
+ - test/coverband/utils/dead_methods_test.rb
520
538
  - test/coverband/utils/file_hasher_test.rb
521
539
  - test/coverband/utils/file_list_test.rb
522
540
  - test/coverband/utils/html_formatter_test.rb
523
541
  - test/coverband/utils/lines_classifier_test.rb
542
+ - test/coverband/utils/method_definition_scanner_test.rb
524
543
  - test/coverband/utils/relative_file_converter_test.rb
525
544
  - test/coverband/utils/result_test.rb
526
545
  - test/coverband/utils/results_test.rb
@@ -531,6 +550,7 @@ test_files:
531
550
  - test/fake_app/basic_rack.rb
532
551
  - test/fixtures/app/controllers/sample_controller.rb
533
552
  - test/fixtures/app/models/user.rb
553
+ - test/fixtures/casting_invitor.rb
534
554
  - test/fixtures/never.rb
535
555
  - test/fixtures/sample.rb
536
556
  - test/fixtures/skipped.rb
@@ -540,6 +560,7 @@ test_files:
540
560
  - test/forked/rails_full_stack_views_test.rb
541
561
  - test/forked/rails_rake_full_stack_test.rb
542
562
  - test/forked/rails_view_tracker_stack_test.rb
563
+ - test/integration/full_stack_deferred_eager_test.rb
543
564
  - test/integration/full_stack_test.rb
544
565
  - test/jruby_check.rb
545
566
  - test/rails4_dummy/Rakefile