coverband 2.0.2.alpha → 2.0.2.alpha2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: d86abf13125588b12cb567afcf59f8289cb4bd1c
4
- data.tar.gz: bda957a57268f3d5a74ea6ffe8502146edf2c4bb
3
+ metadata.gz: 02246eb05ef94f9b83510eba25d096e582f2d2ed
4
+ data.tar.gz: a8af15031477e50a6e395b54b9a4cc726f31ef31
5
5
  SHA512:
6
- metadata.gz: 599dbb24f2292684fe9418352e1564ffa13cebcb5c3ff5831f90d0ad86496b00ec4f1e16c33f1f38c2f96a098553422bb2e44af263bd4c7379ab4ecee045dcd0
7
- data.tar.gz: 013454ba197354052f8fa8ce933a7a669761b685299e7e3657895b370201b166837961dc92c81fb4068c2dc5333abad89625e080fbf6454001621992ee05e9ed
6
+ metadata.gz: d28669d70bc0b5786c08d8a612f8f7d1d0aaf69e75c258e544cc6f3aa8862833bde6cb38ba42b6a97c78ff77c865928f4889507aeb50c46c6c89df2c369251b5
7
+ data.tar.gz: 49a1bd4d91fbb131d673277a7c7f2d1fd4590282e13f9c5099b31564f5f698805c9be97370ed8f3df7f3be0dbe9c10689f7e44d0b486beeed65bfe1518fa40c2
data/README.md CHANGED
@@ -9,7 +9,8 @@ Build Status: [![Build Status](https://travis-ci.org/danmayer/coverband.svg?bran
9
9
  <a href="#installation">Installation</a> •
10
10
  <a href="#configuration">Configuration</a> •
11
11
  <a href="#usage">Usage</a> •
12
- <a href="#license">License</a>
12
+ <a href="#license">License</a>
13
+ <a href="/changes.md">Change Log / Roadmap</a>
13
14
  </p>
14
15
 
15
16
  A gem to measure production code usage, showing each line of code that is executed. Coverband allows easy configuration to collect and report on production code usage. It can be used as Rack middleware, wrapping a block with sampling, or manually configured to meet any need (like usage during background jobs).
@@ -631,8 +632,7 @@ Similar format to redis store, but array with integer values
631
632
 
632
633
  ### Todo
633
634
 
634
- * rackup / how to run webapp via rake
635
- * move off sinatra to pure rack
635
+ * add articles / podcasts like prontos readme https://github.com/prontolabs/pronto
636
636
  * graphite adapters (it would allow passing in date ranges on usage)
637
637
  * perf test for array vs hash
638
638
  * redis pipeline around hash (or batch get then push)
@@ -9,16 +9,18 @@ module Coverband
9
9
  class MemoryCacheStore < Base
10
10
  attr_accessor :store
11
11
 
12
+ @@files_cache = {}
13
+
12
14
  def initialize(store)
13
15
  @store = store
14
16
  end
15
17
 
16
- def self.reset!
17
- files_cache.clear
18
+ def self.clear!
19
+ @@files_cache.clear
18
20
  end
19
21
 
20
22
  def clear!
21
- self.class.reset!
23
+ self.class.clear!
22
24
  end
23
25
 
24
26
  def save_report(files)
@@ -26,28 +28,26 @@ module Coverband
26
28
  store.save_report(filtered_files) if filtered_files.any?
27
29
  end
28
30
 
29
- # rubocop:disable Lint/IneffectiveAccessModifier
30
31
  private
31
32
 
32
- def self.files_cache
33
- @files_cache ||= {}
34
- end
35
-
36
33
  def files_cache
37
- self.class.files_cache
34
+ @@files_cache
38
35
  end
39
36
 
40
37
  def filter(files)
41
- files.each_with_object({}) do |(file, lines), filtered_file_hash|
42
- # first time we see a file, we pre-init the in memory cache to whatever is in store(redis)
43
- line_cache = files_cache[file] ||= Set.new(store.covered_lines_for_file(file))
44
- lines.reject! do |line|
45
- line_cache.include?(line) ? true : (line_cache << line && false)
38
+ files.each_with_object({}) do |(file, covered_lines), filtered_file_hash|
39
+ if covered_lines != cached_file(file)
40
+ files_cache[file] = covered_lines
41
+ filtered_file_hash[file] = covered_lines
46
42
  end
47
- filtered_file_hash[file] = lines if lines.any?
48
43
  end
49
44
  end
50
- # rubocop:enable Lint/IneffectiveAccessModifier
45
+
46
+ def cached_file(file)
47
+ files_cache[file] ||= store.covered_lines_for_file(file).each_with_object({}) do |(line_number, value), hash|
48
+ hash[line_number.to_i] = value.to_i
49
+ end
50
+ end
51
51
  end
52
52
  end
53
53
  end
@@ -71,7 +71,7 @@ module Coverband
71
71
  @store = Coverband::Adapters::RedisStore.new(redis, ttl: Coverband.configuration.redis_ttl,
72
72
  redis_namespace: Coverband.configuration.redis_namespace)
73
73
  elsif store.is_a?(String)
74
- @store = Coverband::Adapters::FileStore.new(coverage_file)
74
+ @store = Coverband::Adapters::FileStore.new(store)
75
75
  end
76
76
  end
77
77
  end
@@ -20,6 +20,8 @@ module Coverband
20
20
 
21
21
  if request.post?
22
22
  case request.path_info
23
+ when /\/collect_update_and_view/
24
+ collect_update_and_view
23
25
  when /\/clear/
24
26
  clear
25
27
  when /\/update_report/
@@ -51,6 +53,7 @@ module Coverband
51
53
  html += "<strong>Notice:</strong> #{Rack::Utils.escape_html(request.params['notice'])}<br/>" if request.params['notice']
52
54
  html += "<ul>"
53
55
  html += "<li><a href='#{base_path}'>Coverband Web Admin Index</a></li>"
56
+ html += "<li>#{button("#{base_path}collect_update_and_view",'collect data, update report, & view')}</li>"
54
57
  html += "<li><a href='#{base_path}show'>view coverage report</a></li>"
55
58
  html += "<li>#{button("#{base_path}collect_coverage",'update coverage data (collect coverage)')}</li>"
56
59
  html += "<li>#{button("#{base_path}update_report",'update coverage report (rebuild report)')}</li>"
@@ -74,6 +77,12 @@ module Coverband
74
77
  html
75
78
  end
76
79
 
80
+ def collect_update_and_view
81
+ collect_coverage
82
+ update_report
83
+ [301, { 'Location' => "#{base_path}show" }, []]
84
+ end
85
+
77
86
  def update_report
78
87
  Coverband::Reporters::SimpleCovReport.report(Coverband.configuration.store, open_report: false)
79
88
  notice = 'coverband coverage updated'
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Coverband
4
- VERSION = '2.0.2.alpha'
4
+ VERSION = '2.0.2.alpha2'
5
5
  end
@@ -5,52 +5,62 @@ require File.expand_path('../test_helper', File.dirname(__FILE__))
5
5
  module Coverband
6
6
  class MemoryCacheStoreTest < Test::Unit::TestCase
7
7
  def setup
8
- Adapters::MemoryCacheStore.reset!
9
- @store = mock('store')
8
+ Adapters::MemoryCacheStore.clear!
9
+ @redis = Redis.new
10
+ @store = Coverband::Adapters::RedisStore.new(@redis)
11
+ @store.clear!
10
12
  @memory_store = Adapters::MemoryCacheStore.new(@store)
11
13
  end
12
14
 
13
- def data
14
- {
15
- 'file1' => { 3 => 1, 5 => 2 },
16
- 'file2' => { 1 => 1, 2 => 1 }
17
- }
18
- end
19
-
20
15
  test 'it passes data into store' do
16
+ data = {
17
+ 'file1' => { 1 => 0, 2 => 1, 3 => 0 },
18
+ 'file2' => { 1 => 5, 2 => 2 }
19
+ }
21
20
  @store.expects(:save_report).with data
22
- @store.expects(:covered_lines_for_file).with('file1').returns []
23
- @store.expects(:covered_lines_for_file).with('file2').returns []
24
21
  @memory_store.save_report data
25
22
  end
26
23
 
27
- test 'it passes data into store only once' do
24
+
25
+ test 'it filters coverage with same exact data' do
26
+ data = {
27
+ 'file1' => { 1 => 0, 2 => 1, 3 => 0 },
28
+ 'file2' => { 1 => 5, 2 => 2 }
29
+ }
28
30
  @store.expects(:save_report).once.with data
29
- @store.expects(:covered_lines_for_file).with('file1').returns []
30
- @store.expects(:covered_lines_for_file).with('file2').returns []
31
31
  2.times { @memory_store.save_report data }
32
32
  end
33
+
34
+ test 'it filters coverage for files with same exact data' do
35
+
36
+ report_first_request = {
37
+ 'file1' => { 1 => 0, 2 => 1, 3 => 0 },
38
+ 'file2' => { 1 => 5, 2 => 2 }
39
+ }
33
40
 
34
- test 'it only passes files and lines we have not hit yet' do
35
- second_data = {
36
- 'file1' => { 3 => 1, 5 => 1, 10 => 1 },
37
- 'file2' => { 1 => 1, 2 => 1 }
41
+ report_second_request = {
42
+ 'file1' => { 1 => 0, 2 => 1, 3 => 0 },
43
+ 'file2' => { 1 => 5, 2 => 3 }
38
44
  }
39
- @store.expects(:covered_lines_for_file).with('file1').returns []
40
- @store.expects(:covered_lines_for_file).with('file2').returns []
41
- @store.expects(:save_report).once.with data
42
- @store.expects(:save_report).once.with(
43
- 'file1' => { 10 => 1 }
44
- )
45
- @memory_store.save_report data
46
- @memory_store.save_report second_data
45
+ @store.expects(:save_report).with({
46
+ 'file1' => { 1 => 0, 2 => 1, 3 => 0 },
47
+ 'file2' => { 1 => 5, 2 => 2 }
48
+ })
49
+ @store.expects(:save_report).with({
50
+ 'file2' => { 1 => 5, 2 => 3 }
51
+ })
52
+ @memory_store.save_report(report_first_request)
53
+ @memory_store.save_report(report_second_request)
47
54
  end
48
55
 
49
56
  test 'it initializes cache with what is in store' do
50
- @store.expects(:covered_lines_for_file).with('file1').returns [3, 5]
51
- @store.expects(:covered_lines_for_file).with('file2').returns [2]
52
- @store.expects(:save_report).with('file2' => { 1 => 1 })
53
- @memory_store.save_report data
57
+ data = {
58
+ 'file1' => { 1 => 0, 2 => 1, 3 => 0 },
59
+ 'file2' => { 1 => 5, 2 => 2 }
60
+ }
61
+ Coverband::Adapters::RedisStore.new(@redis).save_report(data)
62
+ @store.expects(:save_report).never
63
+ @memory_store.save_report(data)
54
64
  end
55
65
  end
56
66
  end
@@ -7,29 +7,31 @@ require 'rack/test'
7
7
 
8
8
  ENV['RACK_ENV'] = 'test'
9
9
 
10
- module Coverband
11
- class S3WebTest < Test::Unit::TestCase
12
- include Rack::Test::Methods
10
+ if Gem::Version.new(RUBY_VERSION) >= Gem::Version.new('2.2.0')
11
+ module Coverband
12
+ class S3WebTest < Test::Unit::TestCase
13
+ include Rack::Test::Methods
13
14
 
14
- def app
15
- Coverband::Reporters::Web.new
16
- end
15
+ def app
16
+ Coverband::Reporters::Web.new
17
+ end
17
18
 
18
- # TODO add tests for all endpoints
19
- test 'renders index content' do
20
- get '/'
21
- assert last_response.ok?
22
- assert_match 'Coverband Web Admin Index', last_response.body
23
- end
19
+ # TODO add tests for all endpoints
20
+ test 'renders index content' do
21
+ get '/'
22
+ assert last_response.ok?
23
+ assert_match 'Coverband Web Admin Index', last_response.body
24
+ end
24
25
 
25
- test 'renders show content' do
26
- Coverband.configuration.s3_bucket = 'coverage-bucket'
27
- s3 = mock('s3')
28
- Aws::S3::Client.expects(:new).returns(s3)
29
- s3.expects(:get_object).with(bucket: 'coverage-bucket', key: 'coverband/index.html').returns mock('response', body: mock('body', read: 'content'))
30
- get '/show'
31
- assert last_response.ok?
32
- assert_equal 'content', last_response.body
26
+ test 'renders show content' do
27
+ Coverband.configuration.s3_bucket = 'coverage-bucket'
28
+ s3 = mock('s3')
29
+ Aws::S3::Client.expects(:new).returns(s3)
30
+ s3.expects(:get_object).with(bucket: 'coverage-bucket', key: 'coverband/index.html').returns mock('response', body: mock('body', read: 'content'))
31
+ get '/show'
32
+ assert last_response.ok?
33
+ assert_equal 'content', last_response.body
34
+ end
33
35
  end
34
36
  end
35
37
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: coverband
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.0.2.alpha
4
+ version: 2.0.2.alpha2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Dan Mayer
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2018-09-05 00:00:00.000000000 Z
11
+ date: 2018-09-15 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: aws-sdk