minitest_rollbar 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 43e3d57fdf20bb35de28a5b50e0d84ca93a85ec0
4
+ data.tar.gz: 37796aefddaf154f091fa07662167ed5787a7016
5
+ SHA512:
6
+ metadata.gz: e2c96013fc8d7201bc0fc51fe74a4aafa247c3f4a3ac3d888c040fc8f8e7f64e44a66f77070d74556e1c23217d95ec9f129cd44d8273252287cc9314d2ae4372
7
+ data.tar.gz: d64d19ce2d1d4ba3d7ee7750b6b29cf79cc760fbc4a25e55f15e21c3c46dfa4a810a0960d6481d016c3f7e9190bedc2914a903efef39212edb9740c811c581d7
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2016, AppFolio, Inc.
2
+ All rights reserved.
3
+
4
+ Redistribution and use in source and binary forms, with or without
5
+ modification, are permitted provided that the following conditions are met:
6
+
7
+ 1. Redistributions of source code must retain the above copyright notice, this
8
+ list of conditions and the following disclaimer.
9
+ 2. Redistributions in binary form must reproduce the above copyright notice,
10
+ this list of conditions and the following disclaimer in the documentation
11
+ and/or other materials provided with the distribution.
12
+
13
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
14
+ ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
15
+ WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
16
+ DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
17
+ FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
18
+ DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
19
+ SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
20
+ CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
21
+ OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
22
+ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
data/README.md ADDED
@@ -0,0 +1,37 @@
1
+ # Minitest-rollbar
2
+
3
+ Minitest-rollbar is a gem to log test exceptions to rollbar. This is useful in
4
+ a CI environment to gather statistics on common exceptions that could indicate
5
+ infrastructer related issues.
6
+
7
+ ## Installation
8
+
9
+ Add this line to your application's Gemfile:
10
+
11
+ ```ruby
12
+ gem 'minitest_rollbar'
13
+ ```
14
+
15
+ And then execute:
16
+
17
+ $ bundle
18
+
19
+ Or install it yourself as:
20
+
21
+ $ gem install minitest_rollbar
22
+
23
+ ## Usage
24
+
25
+ Require necessary files on test_helper:
26
+
27
+ require 'minitest_rollbar'
28
+
29
+ Set up authentication token by:
30
+
31
+ MinitestRollbar.access_token = {YOUR_TOKEN}
32
+
33
+ ## License
34
+
35
+ This gem is available under the Simplified BSD License.
36
+
37
+ * Copyright (c), 2016, AppFolio, Inc.
@@ -0,0 +1,8 @@
1
+ require 'rollbar'
2
+ require 'minitest_rollbar'
3
+
4
+ module Minitest
5
+ def self.plugin_rollbar_reporter_init(options)
6
+ reporter << MinitestRollbar.ollbarReporter.new(options[:io], options)
7
+ end
8
+ end
@@ -0,0 +1,88 @@
1
+ require 'minitest'
2
+ require 'rollbar'
3
+
4
+ module MinitestRollbar
5
+ class << self
6
+ attr_accessor :access_token
7
+ end
8
+
9
+ class RollbarReporter < Minitest::StatisticsReporter
10
+ def initialize(io = $stdout, options = {})
11
+ super
12
+ @sequential_exception_count = 0
13
+ # Inspect will return ExceptionType + Message.
14
+ # E.g #<Selenium::WebDriver::Error::NoSuchWindowError: Window not found. The browser window may have been closed.>
15
+ # Use this as a criteria of grouping
16
+ @previous_exception_inspect_result = nil
17
+ @previous_exception = nil
18
+
19
+ raise 'Must set rollbar access token' if MinitestRollbar.access_token.nil?
20
+ Rollbar.configure do |config|
21
+ config.access_token = MinitestRollbar.access_token
22
+ end
23
+ end
24
+
25
+ def record(result)
26
+ super
27
+ if result.error?
28
+ current_exception = result.failure.exception
29
+ current_exception_inspect_result = current_exception.inspect
30
+
31
+ # If there is no previous exception, start a fresh counter
32
+ if @previous_exception_inspect_result.nil?
33
+ record_new_error(current_exception)
34
+ # Report or increment the count the previous errors if a new error occurs
35
+ elsif current_exception_inspect_result == @previous_exception_inspect_result
36
+ # Same error, increment counter
37
+ increment_error_counting
38
+ else
39
+ # Different error, report previous errors and record new error
40
+ report_error_to_rollbar
41
+ record_new_error current_exception
42
+ end
43
+ else
44
+ # Report previous errors if there is any
45
+ unless @previous_exception.nil?
46
+ report_error_to_rollbar
47
+ reset_error_counting
48
+ end
49
+ end
50
+ end
51
+
52
+ def report
53
+ super
54
+ if @sequential_exception_count > 0
55
+ notifier = Rollbar.scope(count: @sequential_exception_count)
56
+ notifier.error(@previous_exception)
57
+
58
+ @previous_exception_inspect_result = nil
59
+ @previous_exception = nil
60
+ @sequential_exception_count = 0
61
+
62
+ end
63
+ end
64
+
65
+ private
66
+
67
+ def report_error_to_rollbar
68
+ notifier = Rollbar.scope(count: @sequential_exception_count)
69
+ notifier.error(@previous_exception)
70
+ end
71
+
72
+ def reset_error_counting
73
+ @previous_exception_inspect_result = nil
74
+ @previous_exception = nil
75
+ @sequential_exception_count = 0
76
+ end
77
+
78
+ def increment_error_counting
79
+ @sequential_exception_count += 1
80
+ end
81
+
82
+ def record_new_error(error)
83
+ @previous_exception_inspect_result = error.inspect
84
+ @previous_exception = error
85
+ @sequential_exception_count = 1
86
+ end
87
+ end
88
+ end
@@ -0,0 +1,3 @@
1
+ module MinitestRollbar
2
+ VERSION = '0.1.0'.freeze
3
+ end
@@ -0,0 +1,2 @@
1
+ require 'minitest_rollbar/reporters'
2
+ require 'minitest_rollbar/version'
metadata ADDED
@@ -0,0 +1,106 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: minitest_rollbar
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Yuesong Wang
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2016-07-01 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1.12'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.12'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '10.0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '10.0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rollbar
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '2.0'
48
+ type: :runtime
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '2.0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: minitest
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '5.0'
62
+ type: :runtime
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '5.0'
69
+ description:
70
+ email:
71
+ - wangyuesong0@qq.com
72
+ executables: []
73
+ extensions: []
74
+ extra_rdoc_files: []
75
+ files:
76
+ - LICENSE.txt
77
+ - README.md
78
+ - lib/minitest/rollbar_reporter_plugin.rb
79
+ - lib/minitest_rollbar.rb
80
+ - lib/minitest_rollbar/reporters.rb
81
+ - lib/minitest_rollbar/version.rb
82
+ homepage: https://github.com/appfolio/minitest-rollbar
83
+ licenses:
84
+ - BSD-2-Clause
85
+ metadata: {}
86
+ post_install_message:
87
+ rdoc_options: []
88
+ require_paths:
89
+ - lib
90
+ required_ruby_version: !ruby/object:Gem::Requirement
91
+ requirements:
92
+ - - ">="
93
+ - !ruby/object:Gem::Version
94
+ version: '0'
95
+ required_rubygems_version: !ruby/object:Gem::Requirement
96
+ requirements:
97
+ - - ">="
98
+ - !ruby/object:Gem::Version
99
+ version: '0'
100
+ requirements: []
101
+ rubyforge_project:
102
+ rubygems_version: 2.5.1
103
+ signing_key:
104
+ specification_version: 4
105
+ summary: A minitest reporter that logs testexceptions to Rollbar.
106
+ test_files: []