coverband 5.0.0 → 5.1.0.rcmailer.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (46) 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 +2 -0
  7. data/Gemfile.rails4 +2 -0
  8. data/Gemfile.rails6 +2 -0
  9. data/LICENSE.txt +1 -1
  10. data/README.md +18 -8
  11. data/changes.md +24 -5
  12. data/lib/coverband/adapters/base.rb +5 -1
  13. data/lib/coverband/adapters/file_store.rb +1 -1
  14. data/lib/coverband/adapters/redis_store.rb +1 -1
  15. data/lib/coverband/collectors/view_tracker.rb +16 -7
  16. data/lib/coverband/reporters/web.rb +2 -1
  17. data/lib/coverband/utils/railtie.rb +14 -9
  18. data/lib/coverband/utils/tasks.rb +1 -1
  19. data/lib/coverband/version.rb +1 -1
  20. data/test/coverband/collectors/view_tracker_test.rb +10 -0
  21. data/test/coverband/reporters/web_test.rb +34 -0
  22. data/test/forked/rails_full_stack_test.rb +1 -1
  23. data/test/forked/rails_full_stack_views_test.rb +51 -0
  24. data/test/forked/rails_view_tracker_stack_test.rb +44 -0
  25. data/test/rails4_dummy/app/controllers/dummy_view_controller.rb +16 -0
  26. data/test/rails4_dummy/app/views/dummy_view/show.html.erb +5 -0
  27. data/test/rails4_dummy/app/views/dummy_view/show_haml.html.haml +4 -0
  28. data/test/rails4_dummy/app/views/dummy_view/show_slim.html.slim +4 -0
  29. data/test/rails4_dummy/config/application.rb +1 -0
  30. data/test/rails4_dummy/config/routes.rb +3 -0
  31. data/test/rails5_dummy/app/controllers/dummy_view_controller.rb +16 -0
  32. data/test/rails5_dummy/app/views/dummy_view/show.html.erb +5 -0
  33. data/test/rails5_dummy/app/views/dummy_view/show_haml.html.haml +4 -0
  34. data/test/rails5_dummy/app/views/dummy_view/show_slim.html.slim +4 -0
  35. data/test/rails5_dummy/config/application.rb +2 -0
  36. data/test/rails5_dummy/config/coverband.rb +3 -1
  37. data/test/rails5_dummy/config/routes.rb +3 -0
  38. data/test/rails6_dummy/app/controllers/dummy_view_controller.rb +16 -0
  39. data/test/rails6_dummy/app/views/dummy_view/show.html.erb +5 -0
  40. data/test/rails6_dummy/app/views/dummy_view/show_haml.html.haml +4 -0
  41. data/test/rails6_dummy/app/views/dummy_view/show_slim.html.slim +4 -0
  42. data/test/rails6_dummy/config/application.rb +1 -0
  43. data/test/rails6_dummy/config/routes.rb +3 -0
  44. data/views/view_tracker.erb +2 -2
  45. metadata +40 -9
  46. data/.travis.yml +0 -48
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: f73e90b7f1451c8f7a47355b680b361fa96e7ab665c1b135282e1cf2f87db8ac
4
- data.tar.gz: e0bd9b0e10bd500dcb814091a048902e4123fa09a3532e8bffb7108cf69bea53
3
+ metadata.gz: ec5d51bc8a16c6d59cb6a04ae43ffd0f242677038851c7f44fe0f2720d1686c8
4
+ data.tar.gz: 608b0442f7993d8e18c686c49037521dbe96325f2f240bb11a542229e3a0bbb8
5
5
  SHA512:
6
- metadata.gz: 67e8d3f7f1c925f030b828eb4a4b37a1b35e887341da8cc6956d4c84ec71cb2a31395f656d48ad3d1782e81404624ae95604a4d0198af4cef2e2c43fc7e08578
7
- data.tar.gz: 3d4a7456beb6adfa1e6eeec4bacb35ef4f3b3a25049b9540b603e5f9bcd65aba1d370c1cbf446c7835106d8ccc536209fbdc74f77949847e91262cdffa0c715c
6
+ metadata.gz: 9d88524814527a2df8c30d7e15005d3cbab174612fdc841035e46bef0847bd352450357c64a64945e8ed72935c0f288746e1f90773397836ed74fdce5c7f0f83
7
+ data.tar.gz: d56b0c8f50e6d985b5eecac8051e2516359698c41b70f230d21256b73faab0392097ad5b1ece4cfad685251e5a816fa52db0bdcdbc5fbc71640c94686f6ef141
@@ -0,0 +1,38 @@
1
+ ---
2
+ name: Bug report
3
+ about: Create a report to help us improve
4
+ title: ''
5
+ labels: ''
6
+ assignees: ''
7
+
8
+ ---
9
+
10
+ **Describe the bug**
11
+ A clear and concise description of what the bug is.
12
+
13
+ **To Reproduce**
14
+ Steps to reproduce the behavior:
15
+ 1. Go to '...'
16
+ 2. Click on '....'
17
+ 3. Scroll down to '....'
18
+ 4. See error
19
+
20
+ **Expected behavior**
21
+ A clear and concise description of what you expected to happen.
22
+
23
+ **Screenshots**
24
+ If applicable, add screenshots to help explain your problem.
25
+
26
+ **Desktop (please complete the following information):**
27
+ - OS: [e.g. iOS]
28
+ - Browser [e.g. chrome, safari]
29
+ - Version [e.g. 22]
30
+
31
+ **Smartphone (please complete the following information):**
32
+ - Device: [e.g. iPhone6]
33
+ - OS: [e.g. iOS8.1]
34
+ - Browser [e.g. stock browser, safari]
35
+ - Version [e.g. 22]
36
+
37
+ **Additional context**
38
+ Add any other context about the problem here.
@@ -0,0 +1,20 @@
1
+ ---
2
+ name: Feature request
3
+ about: Suggest an idea for this project
4
+ title: ''
5
+ labels: ''
6
+ assignees: ''
7
+
8
+ ---
9
+
10
+ **Is your feature request related to a problem? Please describe.**
11
+ A clear and concise description of what the problem is. Ex. I'm always frustrated when [...]
12
+
13
+ **Describe the solution you'd like**
14
+ A clear and concise description of what you want to happen.
15
+
16
+ **Describe alternatives you've considered**
17
+ A clear and concise description of any alternative solutions or features you've considered.
18
+
19
+ **Additional context**
20
+ Add any other context or screenshots about the feature request here.
@@ -0,0 +1,30 @@
1
+ name: CI
2
+ # Controls when the action will run.
3
+ on:
4
+ # Triggers the workflow on push or pull request events but only for the master branch
5
+ push:
6
+ branches: [master]
7
+ pull_request:
8
+ branches: [master]
9
+ jobs:
10
+ test:
11
+ strategy:
12
+ fail-fast: false
13
+ matrix:
14
+ # need to figure out how to use redis on macos github actions
15
+ # os: [ubuntu, macos]
16
+ os: [ubuntu]
17
+ # remove until I sort out CI issues for truffle
18
+ # truffleruby,
19
+ # truffleruby-head,
20
+ ruby: [2.3, 2.4, 2.5, 2.6, 2.7, jruby, jruby-head]
21
+ redis-version: [5]
22
+ runs-on: ${{ matrix.os }}-latest
23
+ steps:
24
+ - uses: actions/checkout@v2
25
+ - uses: supercharge/redis-github-action@1.1.0
26
+ - uses: ruby/setup-ruby@v1
27
+ with:
28
+ ruby-version: ${{ matrix.ruby }}
29
+ bundler-cache: true # runs 'bundle install' and caches installed gems automatically
30
+ - run: bundle exec rake
@@ -0,0 +1 @@
1
+ See our [code of conduct](https://github.com/danmayer/coverband/blob/master/CODE_OF_CONDUCT.md)
data/Gemfile CHANGED
@@ -15,5 +15,7 @@ else
15
15
  end
16
16
 
17
17
  gem "rails", "~>5"
18
+ gem "haml"
19
+ gem "slim"
18
20
  # these gems are used for testing gem tracking
19
21
  gem "irb", require: false
@@ -5,3 +5,5 @@ source 'https://rubygems.org'
5
5
  # Specify your gem's dependencies in coverband.gemspec
6
6
  gemspec
7
7
  gem 'rails', '~>4'
8
+ gem "haml"
9
+ gem "slim"
@@ -5,3 +5,5 @@ source 'https://rubygems.org'
5
5
  # Specify your gem's dependencies in coverband.gemspec
6
6
  gemspec
7
7
  gem 'rails', '~>6'
8
+ gem "haml"
9
+ gem "slim"
@@ -1,4 +1,4 @@
1
- Copyright (c) 2010-2018 Dan Mayer
1
+ Copyright (c) 2010-2020 Dan Mayer
2
2
 
3
3
  MIT License
4
4
 
data/README.md CHANGED
@@ -2,7 +2,7 @@
2
2
 
3
3
  # Coverband
4
4
 
5
- [![Build Status](https://travis-ci.org/danmayer/coverband.svg?branch=master)](https://travis-ci.org/danmayer/coverband)
5
+ [![GithubCI](https://github.com/danmayer/coverband/workflows/CI/badge.svg)](https://github.com/danmayer/coverband/actions)
6
6
  [![Coverage Status](https://coveralls.io/repos/github/danmayer/coverband/badge.svg?branch=master)](https://coveralls.io/github/danmayer/coverband?branch=master)
7
7
  [![Maintainability](https://api.codeclimate.com/v1/badges/1e6682f9540d75f26da7/maintainability)](https://codeclimate.com/github/danmayer/coverband/maintainability)
8
8
  [![Discord Shield](https://img.shields.io/discord/609509533999562753)](https://discord.gg/KAH38EV)
@@ -65,7 +65,7 @@ The Railtie integration means you shouldn't need to do anything else other than
65
65
 
66
66
  ## Sinatra
67
67
 
68
- For the best coverage you want this loaded as early as possible. We recommend requiring cover band directly in the `config.ru`. Requiring coverband within an initializer could also work, but you may end up missing some boot up coverage. To start collection require Coverband as early as possible.
68
+ For the best coverage you want this loaded as early as possible. We recommend requiring cover band directly in the `config.ru`. Requiring coverband within an initializer could also work, but you may end up missing some boot up coverage. To start collection require Coverband as early as possible.
69
69
 
70
70
  ```ruby
71
71
  require 'coverband'
@@ -91,7 +91,7 @@ run ActionController::Dispatcher.new
91
91
 
92
92
  - Clear coverage report
93
93
 
94
- This will clear the coverage data. This wipes out all collected data.
94
+ This will clear the coverage data. This wipes out all collected data.
95
95
 
96
96
  - Clear individual file coverage
97
97
 
@@ -128,10 +128,16 @@ or you can enable basic auth by setting `ENV['COVERBAND_PASSWORD']` or via your
128
128
  The coverage server can also be started standalone with a rake task:
129
129
 
130
130
  ```
131
- bundle exec rake coverband:coverage_server
131
+ bundle exec rake coverband:coverage_server
132
132
  ```
133
133
 
134
- The web UI should then be available here: http://localhost:1022/
134
+ The web UI should then be available here: http://localhost:9022/
135
+
136
+ If you want to run on an alternative port:
137
+
138
+ ```
139
+ COVERBAND_COVERAGE_PORT=8086 bundle exec rake coverband:coverage_server
140
+ ```
135
141
 
136
142
  This is especially useful for projects that are api only and cannot support the mounted rack app. To get production coverage, point coverband at your production redis server and ensure to checkout the production version of your project code locally.
137
143
 
@@ -298,6 +304,8 @@ rake coverband:coverage # report runtime coverband code coverage
298
304
 
299
305
  Coverband starts on require of the the library which is usually done within the Gemfile. This can be disabled by setting the `COVERBAND_DISABLE_AUTO_START` environment variable. This environment variable can be useful to toggle coverband on and off in certain environments.
300
306
 
307
+ **NOTE:** That any value set for `COVERBAND_DISABLE_AUTO_START` is considered true, it does not match the string content but only checks the presence of the ENV variable.
308
+
301
309
  In order to start coverband manually yourself when this flag is enabled, call `Coverband.configure` followed by `Coverband.start`.
302
310
 
303
311
  ```ruby
@@ -307,7 +315,7 @@ Coverband.start
307
315
 
308
316
  ### Verbose Debug / Development Mode
309
317
 
310
- Note: To debug issues getting Coverband working. I recommend running in development mode, by turning verbose logging on `config.verbose = true` and passing in the Rails.logger `config.logger = Rails.logger` to the Coverband config. We respect the log level, and I would recommend log level info generally, but if you are investigating a prolbem Coverband logs additional data at the `debug` level. This makes it easy to follow in development mode. Be careful to not leave these on in production as they will affect performance.
318
+ Note: To debug issues getting Coverband working. I recommend running in development mode, by turning verbose logging on `config.verbose = true` and passing in the Rails.logger `config.logger = Rails.logger` to the Coverband config. We respect the log level, and I would recommend log level info generally, but if you are investigating a problem Coverband logs additional data at the `debug` level. This makes it easy to follow in development mode. Be careful to not leave these on in production as they will affect performance.
311
319
 
312
320
  ---
313
321
 
@@ -327,7 +335,7 @@ If you currently have require: false, remove the 'coverband' string from the req
327
335
  gem 'coverband', require: ['alternative_coverband_patch']
328
336
  ```
329
337
 
330
- This conflict happens when a ruby method is patched twice, once using module prepend, and once using method aliasing. See this ruby issue for details. The fix is to apply all patches the same way. Coverband by default will apply its patch using prepend, but you can change that to method aliasing by adding require: ['alternative_coverband_patch'] to the gem line as shown above.
338
+ This conflict happens when a ruby method is patched twice, once using module prepend, and once using method aliasing. See this ruby issue for details. The fix is to apply all patches the same way. Coverband by default will apply its patch using prepend, but you can change that to method aliasing by adding require: ['alternative_coverband_patch'] to the gem line as shown above.
331
339
 
332
340
  # Prerequisites
333
341
 
@@ -379,7 +387,9 @@ If you submit a change please make sure the tests and benchmarks are passing.
379
387
  - **total fail** on front end code, for line for line coverage, because of the precompiled template step basically coverage doesn't work well for `erb`, `slim`, and the like.
380
388
  - related it will try to report something, but the line numbers reported for `ERB` files are often off and aren't considered useful. I recommend filtering out .erb using the `config.ignore` option. The default configuration excludes these files
381
389
  - **NOTE:** We now have file level coverage for view files, but don't support line level detail
382
- - The view file detection doesn't workf or mailers at the moment only for web related views / JSON templates. This is due to how Rails active mailer notifications work.
390
+ - **Coverage does NOT work when used alongside Scout APM Auto Instrumentation**
391
+ - In an environment that uses Scout's `AUTO_INSTRUMENT=true` (usually production or staging) it stops reporting any coverage, it will show one or two files that have been loaded at the start but everything else will show up as having 0% coverage
392
+ - Bug tracked here: https://github.com/scoutapp/scout_apm_ruby/issues/343
383
393
 
384
394
  ### Debugging Redis Store
385
395
 
data/changes.md CHANGED
@@ -53,6 +53,27 @@ Will be the fully modern release that drops maintenance legacy support in favor
53
53
 
54
54
  # Alpha / Beta / Release Candidates
55
55
 
56
+ ### Coverband 5.0.4
57
+
58
+ - ?
59
+
60
+ # Released
61
+
62
+ ### Coverband 5.0.3
63
+
64
+ - fix for non standard root paths for view_tracker thx @markshawtoronto
65
+ - support basic auth for Rack prior to 2.0 thx @kadru
66
+
67
+ ### Coverband 5.0.2
68
+
69
+ - change default port of local server
70
+ - update on readme about issue with scout app, thanks @mrbongiolo
71
+ - fix on configuration page not loading when redis can't load
72
+
73
+ ### Coverband 5.0.1
74
+
75
+ - fix for race condition on view tracker redis configuration setting ensuring it is set after it is configured... bug only impacted apps that have multiple redis connections for the same system and have Coverband not on the default REDIS_URL
76
+
56
77
  ### Coverband 5.0.0
57
78
 
58
79
  - Full JRuby support
@@ -77,14 +98,12 @@ Will be the fully modern release that drops maintenance legacy support in favor
77
98
  - reduce logs / errors / alerts on bad startup configurations
78
99
  - fix: #301 runtime vs eagerload should always remain correct
79
100
 
80
- # Released
81
-
82
- ###Coverband 4.2.7
101
+ ### Coverband 4.2.7
83
102
 
84
103
  - Ignore patterns too aggressive #382, thanks @thijsnado
85
104
  - Stack level too deep error when running certain activejob jobs #367, thanks @kejordan and @hanslauwers
86
105
 
87
- ###Coverband 4.2.6
106
+ ### Coverband 4.2.6
88
107
 
89
108
  - Address Redis exists deprecation warning by baffers
90
109
 
@@ -267,7 +286,7 @@ Will be a stable and fast release that drops maintenance legacy support in favor
267
286
  - implemented for Redis and File store
268
287
  - improved mountable web interface
269
288
 
270
- # 2.0.3
289
+ ### 2.0.3
271
290
 
272
291
  - don''t include docs in the gemfile thanks @bquorning
273
292
  - pipeline_redis to reduce network overhead thanks @Kallin
@@ -40,7 +40,11 @@ module Coverband
40
40
  end
41
41
 
42
42
  def size_in_mib
43
- format("%<size>.2f", size: (size.to_f / 2**20))
43
+ if size
44
+ format("%<size>.2f", size: (size.to_f / 2**20))
45
+ else
46
+ "N/A"
47
+ end
44
48
  end
45
49
 
46
50
  def save_report(_report)
@@ -20,7 +20,7 @@ module Coverband
20
20
  # files matching the path pattern, in this case `log/coverage.log.*`
21
21
  #
22
22
  # run: `bundle exec rake coverband:coverage_server`
23
- # open http://localhost:1022/
23
+ # open http://localhost:9022/
24
24
  #
25
25
  # one could also build a report via code, the output is suitable to feed into SimpleCov
26
26
  #
@@ -44,7 +44,7 @@ module Coverband
44
44
  end
45
45
 
46
46
  def size
47
- @redis.get(base_key).bytesize
47
+ @redis.get(base_key) ? @redis.get(base_key).bytesize : "N/A"
48
48
  end
49
49
 
50
50
  ###
@@ -10,22 +10,20 @@ module Coverband
10
10
  # This is a port of Flatfoot, a project I open sourced years ago,
11
11
  # but am now rolling into Coverband
12
12
  # https://github.com/livingsocial/flatfoot
13
- #
14
- # TODO: test and ensure slim, haml, and other support
15
13
  ###
16
14
  class ViewTracker
17
- DEFAULT_TARGET = Dir.glob("app/views/**/*.html.erb").reject { |file| file.match(/(_mailer)/) }
18
15
  attr_accessor :target, :logged_views, :views_to_record
19
16
  attr_reader :logger, :roots, :store, :ignore_patterns
20
17
 
21
18
  def initialize(options = {})
22
19
  raise NotImplementedError, "View Tracker requires Rails 4 or greater" unless self.class.supported_version?
20
+ raise "Coverband: view tracker initialized before configuration!" if !Coverband.configured? && ENV["COVERBAND_TEST"] == "test"
23
21
 
24
22
  @project_directory = File.expand_path(Coverband.configuration.root)
25
23
  @ignore_patterns = Coverband.configuration.ignore
26
24
  @store = options.fetch(:store) { Coverband.configuration.store }
27
25
  @logger = options.fetch(:logger) { Coverband.configuration.logger }
28
- @target = options.fetch(:target) { DEFAULT_TARGET }
26
+ @target = options.fetch(:target) { Dir.glob("#{@project_directory}/app/views/**/*.html.{erb,haml,slim}") }
29
27
 
30
28
  @roots = options.fetch(:roots) { Coverband.configuration.all_root_patterns }
31
29
  @roots = @roots.split(",") if @roots.is_a?(String)
@@ -65,18 +63,29 @@ module Coverband
65
63
  normalized_views = {}
66
64
  views.each_pair do |view, time|
67
65
  roots.each do |root|
68
- view = view.gsub(/#{root}/, "")
66
+ view = view.gsub(root, "")
69
67
  end
70
68
  normalized_views[view] = time
71
69
  end
72
70
  normalized_views
73
71
  end
74
72
 
73
+ def all_views
74
+ all_views = []
75
+ target.each do |view|
76
+ roots.each do |root|
77
+ view = view.gsub(root, "")
78
+ end
79
+ all_views << view
80
+ end
81
+ all_views.uniq
82
+ end
83
+
75
84
  def unused_views
76
85
  recently_used_views = used_views.keys
77
- all_views = target.reject { |view| recently_used_views.include?(view) }
86
+ unused_views = all_views.reject { |view| recently_used_views.include?(view) }
78
87
  # since layouts don't include format we count them used if they match with ANY formats
79
- all_views.reject { |view| view.match(/\/layouts\//) && recently_used_views.any? { |used_view| view.include?(used_view) } }
88
+ unused_views.reject { |view| view.match(/\/layouts\//) && recently_used_views.any? { |used_view| view.include?(used_view) } }
80
89
  end
81
90
 
82
91
  def as_json
@@ -23,7 +23,8 @@ module Coverband
23
23
  def check_auth
24
24
  return true unless Coverband.configuration.password
25
25
 
26
- auth_header = request.get_header("HTTP_AUTHORIZATION")
26
+ # support rack 1.6.x and rack 2.0 (get_header)
27
+ auth_header = request.respond_to?(:get_header) ? request.get_header("HTTP_AUTHORIZATION") : request.env["HTTP_AUTHORIZATION"]
27
28
  return unless auth_header
28
29
 
29
30
  Coverband.configuration.password == Base64.decode64(auth_header.split[1]).split(":")[1]
@@ -13,7 +13,21 @@ module Coverband
13
13
  initializer "coverband.configure" do |app|
14
14
  begin
15
15
  app.middleware.use Coverband::BackgroundMiddleware
16
+ rescue Redis::CannotConnectError => error
17
+ Coverband.configuration.logger.info "Redis is not available (#{error}), Coverband not configured"
18
+ Coverband.configuration.logger.info "If this is a setup task like assets:precompile feel free to ignore"
19
+ end
20
+ end
16
21
 
22
+ config.after_initialize do
23
+ unless Coverband.tasks_to_ignore?
24
+ Coverband.configure
25
+ Coverband.eager_loading_coverage!
26
+ Coverband.report_coverage
27
+ Coverband.runtime_coverage!
28
+ end
29
+
30
+ begin
17
31
  if Coverband.configuration.track_views
18
32
  COVERBAND_VIEW_TRACKER = if Coverband.coverband_service?
19
33
  Coverband::Collectors::ViewTrackerService.new
@@ -33,15 +47,6 @@ module Coverband
33
47
  end
34
48
  end
35
49
 
36
- config.after_initialize do
37
- unless Coverband.tasks_to_ignore?
38
- Coverband.configure
39
- Coverband.eager_loading_coverage!
40
- Coverband.report_coverage
41
- Coverband.runtime_coverage!
42
- end
43
- end
44
-
45
50
  config.before_configuration do
46
51
  unless ENV["COVERBAND_DISABLE_AUTO_START"]
47
52
  begin
@@ -13,7 +13,7 @@ namespace :coverband do
13
13
  task :coverage_server do
14
14
  Rake.application["environment"].invoke if Rake::Task.task_defined?("environment")
15
15
  Coverband.configuration.store.merge_mode = true if Coverband.configuration.store.is_a?(Coverband::Adapters::FileStore)
16
- Rack::Server.start app: Coverband::Reporters::Web.new, Port: ENV.fetch("COVERBAND_COVERAGE_PORT", 1022).to_i
16
+ Rack::Server.start app: Coverband::Reporters::Web.new, Port: ENV.fetch("COVERBAND_COVERAGE_PORT", 9022).to_i
17
17
  end
18
18
 
19
19
  ###
@@ -5,5 +5,5 @@
5
5
  # use format '4.2.1.rc.1' ~> 4.2.1.rc to prerelease versions like v4.2.1.rc.2 and v4.2.1.rc.3
6
6
  ###
7
7
  module Coverband
8
- VERSION = "5.0.0"
8
+ VERSION = "5.1.0.rcmailer.1"
9
9
  end
@@ -42,6 +42,16 @@ class ReporterTest < Minitest::Test
42
42
  assert_equal [file_path], tracker.used_views.keys
43
43
  end
44
44
 
45
+ test "track partials that include the word _mailer in the path" do
46
+ Coverband::Collectors::ViewTracker.expects(:supported_version?).returns(true)
47
+ store = fake_store
48
+ file_path = "#{File.expand_path(Coverband.configuration.root)}/_mailer/file"
49
+ tracker = Coverband::Collectors::ViewTracker.new(store: store, roots: "dir")
50
+ tracker.track_views("name", "start", "finish", "id", identifier: file_path)
51
+ tracker.report_views_tracked
52
+ assert_equal [file_path], tracker.used_views.keys
53
+ end
54
+
45
55
  test "ignore partials that include the folder vendor in the path" do
46
56
  Coverband::Collectors::ViewTracker.expects(:supported_version?).returns(true)
47
57
  store = fake_store
@@ -43,4 +43,38 @@ if Gem::Version.new(RUBY_VERSION) >= Gem::Version.new("2.2.0")
43
43
  end
44
44
  end
45
45
  end
46
+
47
+ module Coverband
48
+ class AuthWebTest < Minitest::Test
49
+ include Rack::Test::Methods
50
+
51
+ def setup
52
+ super
53
+ @store = Coverband.configuration.store
54
+ Coverband.configure do |config|
55
+ config.password = "test_pass"
56
+ end
57
+ end
58
+
59
+ def app
60
+ Coverband::Reporters::Web.new
61
+ end
62
+
63
+ def teardown
64
+ super
65
+ end
66
+
67
+ test "renders index with basic auth" do
68
+ basic_authorize "anything", "test_pass"
69
+ get "/"
70
+ assert last_response.ok?
71
+ assert_match "Coverband Home", last_response.body
72
+ end
73
+
74
+ test "renders 401 auth error when not provided" do
75
+ get "/"
76
+ assert_equal 401, last_response.status
77
+ end
78
+ end
79
+ end
46
80
  end
@@ -35,7 +35,7 @@ class RailsFullStackTest < Minitest::Test
35
35
  end
36
36
 
37
37
  # Test eager load data stored separately
38
- dummy_controller = "./test/rails#{Rails::VERSION::MAJOR}_dummy/app/controllers/dummy_controller.rb"
38
+ dummy_controller = "./app/controllers/dummy_controller.rb"
39
39
  store.type = :eager_loading
40
40
  eager_expected = [1, 1, 0, nil, nil]
41
41
  results = store.coverage[dummy_controller]["data"]
@@ -0,0 +1,51 @@
1
+ # frozen_string_literal: true
2
+
3
+ require File.expand_path("../rails_test_helper", File.dirname(__FILE__))
4
+
5
+ class RailsFullStackTest < Minitest::Test
6
+ include Capybara::DSL
7
+ include Capybara::Minitest::Assertions
8
+
9
+ def setup
10
+ super
11
+ rails_setup
12
+ Coverband.report_coverage
13
+ end
14
+
15
+ def teardown
16
+ super
17
+ Capybara.reset_sessions!
18
+ Capybara.use_default_driver
19
+ end
20
+
21
+ test "verify erb haml slim support" do
22
+ visit "/dummy_view/show"
23
+ assert_content("I am no dummy view tracker text")
24
+ Coverband.report_coverage
25
+ Coverband.configuration.view_tracker&.report_views_tracked
26
+ visit "/coverage/view_tracker"
27
+ assert_content("Used Views: (1)")
28
+ assert_content("Unused Views: (2)")
29
+ assert_selector("li.used-views", text: "dummy_view/show.html.erb")
30
+ assert_selector("li.unused-views", text: "dummy_view/show_haml.html.haml")
31
+ assert_selector("li.unused-views", text: "dummy_view/show_slim.html.slim")
32
+
33
+ visit "/dummy_view/show_haml"
34
+ assert_content("I am haml text")
35
+ Coverband.report_coverage
36
+ Coverband.configuration.view_tracker&.report_views_tracked
37
+ visit "/coverage/view_tracker"
38
+ assert_content("Used Views: (2)")
39
+ assert_content("Unused Views: (1)")
40
+ assert_selector("li.used-views", text: "dummy_view/show_haml.html.haml")
41
+
42
+ visit "/dummy_view/show_slim"
43
+ assert_content("I am slim text")
44
+ Coverband.report_coverage
45
+ Coverband.configuration.view_tracker&.report_views_tracked
46
+ visit "/coverage/view_tracker"
47
+ assert_content("Used Views: (3)")
48
+ assert_content("Unused Views: (0)")
49
+ assert_selector("li.used-views", text: "dummy_view/show_slim.html.slim")
50
+ end
51
+ end
@@ -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
@@ -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,15 +1,15 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: coverband
3
3
  version: !ruby/object:Gem::Version
4
- version: 5.0.0
4
+ version: 5.1.0.rcmailer.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Dan Mayer
8
8
  - Karl Baum
9
- autorequire:
9
+ autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2020-08-30 00:00:00.000000000 Z
12
+ date: 2020-12-30 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
@@ -402,11 +405,17 @@ files:
402
405
  - test/fixtures/skipped_and_executed.rb
403
406
  - test/fixtures/utf-8.rb
404
407
  - test/forked/rails_full_stack_test.rb
408
+ - test/forked/rails_full_stack_views_test.rb
405
409
  - test/forked/rails_rake_full_stack_test.rb
410
+ - test/forked/rails_view_tracker_stack_test.rb
406
411
  - test/integration/full_stack_test.rb
407
412
  - test/jruby_check.rb
408
413
  - test/rails4_dummy/Rakefile
409
414
  - test/rails4_dummy/app/controllers/dummy_controller.rb
415
+ - test/rails4_dummy/app/controllers/dummy_view_controller.rb
416
+ - test/rails4_dummy/app/views/dummy_view/show.html.erb
417
+ - test/rails4_dummy/app/views/dummy_view/show_haml.html.haml
418
+ - test/rails4_dummy/app/views/dummy_view/show_slim.html.slim
410
419
  - test/rails4_dummy/config.ru
411
420
  - test/rails4_dummy/config/application.rb
412
421
  - test/rails4_dummy/config/boot.rb
@@ -418,6 +427,10 @@ files:
418
427
  - test/rails4_dummy/tmp/.keep
419
428
  - test/rails5_dummy/Rakefile
420
429
  - test/rails5_dummy/app/controllers/dummy_controller.rb
430
+ - test/rails5_dummy/app/controllers/dummy_view_controller.rb
431
+ - test/rails5_dummy/app/views/dummy_view/show.html.erb
432
+ - test/rails5_dummy/app/views/dummy_view/show_haml.html.haml
433
+ - test/rails5_dummy/app/views/dummy_view/show_slim.html.slim
421
434
  - test/rails5_dummy/config.ru
422
435
  - test/rails5_dummy/config/application.rb
423
436
  - test/rails5_dummy/config/coverband.rb
@@ -427,6 +440,10 @@ files:
427
440
  - test/rails5_dummy/tmp/.keep
428
441
  - test/rails6_dummy/Rakefile
429
442
  - test/rails6_dummy/app/controllers/dummy_controller.rb
443
+ - test/rails6_dummy/app/controllers/dummy_view_controller.rb
444
+ - test/rails6_dummy/app/views/dummy_view/show.html.erb
445
+ - test/rails6_dummy/app/views/dummy_view/show_haml.html.haml
446
+ - test/rails6_dummy/app/views/dummy_view/show_slim.html.slim
430
447
  - test/rails6_dummy/config.ru
431
448
  - test/rails6_dummy/config/application.rb
432
449
  - test/rails6_dummy/config/boot.rb
@@ -451,7 +468,7 @@ homepage: https://github.com/danmayer/coverband
451
468
  licenses:
452
469
  - MIT
453
470
  metadata: {}
454
- post_install_message:
471
+ post_install_message:
455
472
  rdoc_options: []
456
473
  require_paths:
457
474
  - lib
@@ -462,12 +479,12 @@ required_ruby_version: !ruby/object:Gem::Requirement
462
479
  version: '0'
463
480
  required_rubygems_version: !ruby/object:Gem::Requirement
464
481
  requirements:
465
- - - ">="
482
+ - - ">"
466
483
  - !ruby/object:Gem::Version
467
- version: '0'
484
+ version: 1.3.1
468
485
  requirements: []
469
- rubygems_version: 3.1.2
470
- signing_key:
486
+ rubygems_version: 3.0.3
487
+ signing_key:
471
488
  specification_version: 4
472
489
  summary: Rack middleware to measure production code usage (LOC runtime usage)
473
490
  test_files:
@@ -520,11 +537,17 @@ test_files:
520
537
  - test/fixtures/skipped_and_executed.rb
521
538
  - test/fixtures/utf-8.rb
522
539
  - test/forked/rails_full_stack_test.rb
540
+ - test/forked/rails_full_stack_views_test.rb
523
541
  - test/forked/rails_rake_full_stack_test.rb
542
+ - test/forked/rails_view_tracker_stack_test.rb
524
543
  - test/integration/full_stack_test.rb
525
544
  - test/jruby_check.rb
526
545
  - test/rails4_dummy/Rakefile
527
546
  - test/rails4_dummy/app/controllers/dummy_controller.rb
547
+ - test/rails4_dummy/app/controllers/dummy_view_controller.rb
548
+ - test/rails4_dummy/app/views/dummy_view/show.html.erb
549
+ - test/rails4_dummy/app/views/dummy_view/show_haml.html.haml
550
+ - test/rails4_dummy/app/views/dummy_view/show_slim.html.slim
528
551
  - test/rails4_dummy/config.ru
529
552
  - test/rails4_dummy/config/application.rb
530
553
  - test/rails4_dummy/config/boot.rb
@@ -536,6 +559,10 @@ test_files:
536
559
  - test/rails4_dummy/tmp/.keep
537
560
  - test/rails5_dummy/Rakefile
538
561
  - test/rails5_dummy/app/controllers/dummy_controller.rb
562
+ - test/rails5_dummy/app/controllers/dummy_view_controller.rb
563
+ - test/rails5_dummy/app/views/dummy_view/show.html.erb
564
+ - test/rails5_dummy/app/views/dummy_view/show_haml.html.haml
565
+ - test/rails5_dummy/app/views/dummy_view/show_slim.html.slim
539
566
  - test/rails5_dummy/config.ru
540
567
  - test/rails5_dummy/config/application.rb
541
568
  - test/rails5_dummy/config/coverband.rb
@@ -545,6 +572,10 @@ test_files:
545
572
  - test/rails5_dummy/tmp/.keep
546
573
  - test/rails6_dummy/Rakefile
547
574
  - test/rails6_dummy/app/controllers/dummy_controller.rb
575
+ - test/rails6_dummy/app/controllers/dummy_view_controller.rb
576
+ - test/rails6_dummy/app/views/dummy_view/show.html.erb
577
+ - test/rails6_dummy/app/views/dummy_view/show_haml.html.haml
578
+ - test/rails6_dummy/app/views/dummy_view/show_slim.html.slim
548
579
  - test/rails6_dummy/config.ru
549
580
  - test/rails6_dummy/config/application.rb
550
581
  - 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