whoops_notifier 0.0.0
Sign up to get free protection for your applications and to get access to all the features.
- data/.document +5 -0
- data/.rspec +1 -0
- data/Gemfile +15 -0
- data/Gemfile.lock +38 -0
- data/LICENSE.txt +20 -0
- data/README.rdoc +19 -0
- data/Rakefile +50 -0
- data/VERSION +1 -0
- data/lib/whoops_notifier.rb +30 -0
- data/lib/whoops_notifier/configuration.rb +96 -0
- data/lib/whoops_notifier/investigator.rb +27 -0
- data/lib/whoops_notifier/report.rb +20 -0
- data/lib/whoops_notifier/sender.rb +82 -0
- data/lib/whoops_notifier/strategies/basic.rb +11 -0
- data/lib/whoops_notifier/strategy.rb +50 -0
- data/spec/investigator_spec.rb +35 -0
- data/spec/spec_helper.rb +12 -0
- data/spec/strategy_spec.rb +69 -0
- data/spec/whoops_notifier_spec.rb +12 -0
- data/whoops_notifier.gemspec +81 -0
- metadata +179 -0
data/.document
ADDED
data/.rspec
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
--color
|
data/Gemfile
ADDED
@@ -0,0 +1,15 @@
|
|
1
|
+
source "http://rubygems.org"
|
2
|
+
gem "json"
|
3
|
+
# Add dependencies required to use your gem here.
|
4
|
+
# Example:
|
5
|
+
# gem "activesupport", ">= 2.3.5"
|
6
|
+
|
7
|
+
# Add dependencies to develop your gem here.
|
8
|
+
# Include everything needed to run rake, tests, features, etc.
|
9
|
+
group :development do
|
10
|
+
gem "rspec", "~> 2.3.0"
|
11
|
+
gem "bundler", "~> 1.0.0"
|
12
|
+
gem "jeweler", "~> 1.5.2"
|
13
|
+
gem "mocha"
|
14
|
+
gem "ruby-debug"
|
15
|
+
end
|
data/Gemfile.lock
ADDED
@@ -0,0 +1,38 @@
|
|
1
|
+
GEM
|
2
|
+
remote: http://rubygems.org/
|
3
|
+
specs:
|
4
|
+
columnize (0.3.2)
|
5
|
+
diff-lcs (1.1.2)
|
6
|
+
git (1.2.5)
|
7
|
+
jeweler (1.5.2)
|
8
|
+
bundler (~> 1.0.0)
|
9
|
+
git (>= 1.2.5)
|
10
|
+
rake
|
11
|
+
json (1.5.1)
|
12
|
+
linecache (0.43)
|
13
|
+
mocha (0.9.12)
|
14
|
+
rake (0.8.7)
|
15
|
+
rspec (2.3.0)
|
16
|
+
rspec-core (~> 2.3.0)
|
17
|
+
rspec-expectations (~> 2.3.0)
|
18
|
+
rspec-mocks (~> 2.3.0)
|
19
|
+
rspec-core (2.3.1)
|
20
|
+
rspec-expectations (2.3.0)
|
21
|
+
diff-lcs (~> 1.1.2)
|
22
|
+
rspec-mocks (2.3.0)
|
23
|
+
ruby-debug (0.10.4)
|
24
|
+
columnize (>= 0.1)
|
25
|
+
ruby-debug-base (~> 0.10.4.0)
|
26
|
+
ruby-debug-base (0.10.4)
|
27
|
+
linecache (>= 0.3)
|
28
|
+
|
29
|
+
PLATFORMS
|
30
|
+
ruby
|
31
|
+
|
32
|
+
DEPENDENCIES
|
33
|
+
bundler (~> 1.0.0)
|
34
|
+
jeweler (~> 1.5.2)
|
35
|
+
json
|
36
|
+
mocha
|
37
|
+
rspec (~> 2.3.0)
|
38
|
+
ruby-debug
|
data/LICENSE.txt
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Copyright (c) 2011 Daniel Higginbotham
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
4
|
+
a copy of this software and associated documentation files (the
|
5
|
+
"Software"), to deal in the Software without restriction, including
|
6
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
7
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
8
|
+
permit persons to whom the Software is furnished to do so, subject to
|
9
|
+
the following conditions:
|
10
|
+
|
11
|
+
The above copyright notice and this permission notice shall be
|
12
|
+
included in all copies or substantial portions of the Software.
|
13
|
+
|
14
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
15
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
16
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
17
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
18
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
19
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
20
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.rdoc
ADDED
@@ -0,0 +1,19 @@
|
|
1
|
+
= whoops_notifier
|
2
|
+
|
3
|
+
Description goes here.
|
4
|
+
|
5
|
+
== Contributing to whoops_notifier
|
6
|
+
|
7
|
+
* Check out the latest master to make sure the feature hasn't been implemented or the bug hasn't been fixed yet
|
8
|
+
* Check out the issue tracker to make sure someone already hasn't requested it and/or contributed it
|
9
|
+
* Fork the project
|
10
|
+
* Start a feature/bugfix branch
|
11
|
+
* Commit and push until you are happy with your contribution
|
12
|
+
* Make sure to add tests for it. This is important so I don't break it in a future version unintentionally.
|
13
|
+
* Please try not to mess with the Rakefile, version, or history. If you want to have your own version, or is otherwise necessary, that is fine, but please isolate to its own commit so I can cherry-pick around it.
|
14
|
+
|
15
|
+
== Copyright
|
16
|
+
|
17
|
+
Copyright (c) 2011 Daniel Higginbotham. See LICENSE.txt for
|
18
|
+
further details.
|
19
|
+
|
data/Rakefile
ADDED
@@ -0,0 +1,50 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
require 'bundler'
|
3
|
+
begin
|
4
|
+
Bundler.setup(:default, :development)
|
5
|
+
rescue Bundler::BundlerError => e
|
6
|
+
$stderr.puts e.message
|
7
|
+
$stderr.puts "Run `bundle install` to install missing gems"
|
8
|
+
exit e.status_code
|
9
|
+
end
|
10
|
+
require 'rake'
|
11
|
+
|
12
|
+
require 'jeweler'
|
13
|
+
Jeweler::Tasks.new do |gem|
|
14
|
+
# gem is a Gem::Specification... see http://docs.rubygems.org/read/chapter/20 for more options
|
15
|
+
gem.name = "whoops_notifier"
|
16
|
+
gem.homepage = "http://github.com/flyingmachine/whoops_notifier"
|
17
|
+
gem.license = "MIT"
|
18
|
+
gem.summary = %Q{Handles basic notification responsibilities and allows creation of report creation strategies}
|
19
|
+
gem.description = %Q{Handles basic notification responsibilities and allows creation of report creation strategies}
|
20
|
+
gem.email = "daniel@flyingmachinestudios.com"
|
21
|
+
gem.authors = ["Daniel Higginbotham"]
|
22
|
+
# Include your dependencies below. Runtime dependencies are required when using your gem,
|
23
|
+
# and development dependencies are only needed for development (ie running rake tasks, tests, etc)
|
24
|
+
# gem.add_runtime_dependency 'jabber4r', '> 0.1'
|
25
|
+
# gem.add_development_dependency 'rspec', '> 1.2.3'
|
26
|
+
end
|
27
|
+
Jeweler::RubygemsDotOrgTasks.new
|
28
|
+
|
29
|
+
require 'rspec/core'
|
30
|
+
require 'rspec/core/rake_task'
|
31
|
+
RSpec::Core::RakeTask.new(:spec) do |spec|
|
32
|
+
spec.pattern = FileList['spec/**/*_spec.rb']
|
33
|
+
end
|
34
|
+
|
35
|
+
RSpec::Core::RakeTask.new(:rcov) do |spec|
|
36
|
+
spec.pattern = 'spec/**/*_spec.rb'
|
37
|
+
spec.rcov = true
|
38
|
+
end
|
39
|
+
|
40
|
+
task :default => :spec
|
41
|
+
|
42
|
+
require 'rake/rdoctask'
|
43
|
+
Rake::RDocTask.new do |rdoc|
|
44
|
+
version = File.exist?('VERSION') ? File.read('VERSION') : ""
|
45
|
+
|
46
|
+
rdoc.rdoc_dir = 'rdoc'
|
47
|
+
rdoc.title = "whoops_notifier #{version}"
|
48
|
+
rdoc.rdoc_files.include('README*')
|
49
|
+
rdoc.rdoc_files.include('lib/**/*.rb')
|
50
|
+
end
|
data/VERSION
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
0.0.0
|
@@ -0,0 +1,30 @@
|
|
1
|
+
require 'net/http'
|
2
|
+
require 'net/https'
|
3
|
+
require 'json'
|
4
|
+
|
5
|
+
module WhoopsNotifier
|
6
|
+
autoload :Configuration, 'whoops_notifier/configuration'
|
7
|
+
autoload :Investigator, 'whoops_notifier/investigator'
|
8
|
+
autoload :Report, 'whoops_notifier/report'
|
9
|
+
autoload :Sender, 'whoops_notifier/sender'
|
10
|
+
autoload :Strategy, 'whoops_notifier/strategy'
|
11
|
+
|
12
|
+
class << self
|
13
|
+
attr_accessor :strategies, :config
|
14
|
+
def notify(strategy_name, evidence = {})
|
15
|
+
if strategy_name.is_a? Hash
|
16
|
+
notify("default::basic", strategy_name)
|
17
|
+
else
|
18
|
+
investigator = Investigator.new(strategies[strategy_name], evidence)
|
19
|
+
investigator.investigate!
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
self.strategies = {}
|
25
|
+
self.config = Configuration.new
|
26
|
+
end
|
27
|
+
|
28
|
+
Dir[File.join(File.dirname(__FILE__),"whoops_notifier/strategies/*.rb")].each do |strategy_file|
|
29
|
+
require strategy_file
|
30
|
+
end
|
@@ -0,0 +1,96 @@
|
|
1
|
+
# Copyright (c) 2007, Tammer Saleh, Thoughtbot, Inc.
|
2
|
+
module WhoopsNotifier
|
3
|
+
# Used to set up and modify settings for the notifier.
|
4
|
+
class Configuration
|
5
|
+
|
6
|
+
OPTIONS = [:host, :http_open_timeout, :http_read_timeout,
|
7
|
+
:port, :protocol, :proxy_host,
|
8
|
+
:proxy_pass, :proxy_port, :proxy_user, :secure].freeze
|
9
|
+
|
10
|
+
# The host to connect to
|
11
|
+
attr_accessor :host
|
12
|
+
|
13
|
+
# The port on which your Whoops server runs (defaults to 443 for secure
|
14
|
+
# connections, 80 for insecure connections).
|
15
|
+
attr_accessor :port
|
16
|
+
|
17
|
+
# +true+ for https connections, +false+ for http connections.
|
18
|
+
attr_accessor :secure
|
19
|
+
|
20
|
+
# The HTTP open timeout in seconds (defaults to 2).
|
21
|
+
attr_accessor :http_open_timeout
|
22
|
+
|
23
|
+
# The HTTP read timeout in seconds (defaults to 5).
|
24
|
+
attr_accessor :http_read_timeout
|
25
|
+
|
26
|
+
# The hostname of your proxy server (if using a proxy)
|
27
|
+
attr_accessor :proxy_host
|
28
|
+
|
29
|
+
# The port of your proxy server (if using a proxy)
|
30
|
+
attr_accessor :proxy_port
|
31
|
+
|
32
|
+
# The username to use when logging into your proxy server (if using a proxy)
|
33
|
+
attr_accessor :proxy_user
|
34
|
+
|
35
|
+
# The password to use when logging into your proxy server (if using a proxy)
|
36
|
+
attr_accessor :proxy_pass
|
37
|
+
|
38
|
+
# The logger used by WhoopsNotifier
|
39
|
+
attr_accessor :logger
|
40
|
+
|
41
|
+
|
42
|
+
alias_method :secure?, :secure
|
43
|
+
|
44
|
+
def initialize
|
45
|
+
@secure = false
|
46
|
+
@host = nil
|
47
|
+
@http_open_timeout = 2
|
48
|
+
@http_read_timeout = 5
|
49
|
+
end
|
50
|
+
|
51
|
+
# Allows config options to be read like a hash
|
52
|
+
#
|
53
|
+
# @param [Symbol] option Key for a given attribute
|
54
|
+
def [](option)
|
55
|
+
send(option)
|
56
|
+
end
|
57
|
+
|
58
|
+
# Returns a hash of all configurable options
|
59
|
+
def to_hash
|
60
|
+
OPTIONS.inject({}) do |hash, option|
|
61
|
+
hash.merge(option.to_sym => send(option))
|
62
|
+
end
|
63
|
+
end
|
64
|
+
|
65
|
+
# Returns a hash of all configurable options merged with +hash+
|
66
|
+
#
|
67
|
+
# @param [Hash] hash A set of configuration options that will take precedence over the defaults
|
68
|
+
def merge(hash)
|
69
|
+
to_hash.merge(hash)
|
70
|
+
end
|
71
|
+
|
72
|
+
def port
|
73
|
+
@port || default_port
|
74
|
+
end
|
75
|
+
|
76
|
+
def protocol
|
77
|
+
if secure?
|
78
|
+
'https'
|
79
|
+
else
|
80
|
+
'http'
|
81
|
+
end
|
82
|
+
end
|
83
|
+
|
84
|
+
private
|
85
|
+
|
86
|
+
def default_port
|
87
|
+
if secure?
|
88
|
+
443
|
89
|
+
else
|
90
|
+
80
|
91
|
+
end
|
92
|
+
end
|
93
|
+
|
94
|
+
end
|
95
|
+
|
96
|
+
end
|
@@ -0,0 +1,27 @@
|
|
1
|
+
module WhoopsNotifier
|
2
|
+
class Investigator
|
3
|
+
# get data from evidence using a strategy to create a report, then send or ignore
|
4
|
+
attr_accessor :strategy, :report, :evidence, :ignore_report
|
5
|
+
|
6
|
+
def initialize(strategy, evidence)
|
7
|
+
raise ArgumentError, "strategy can not be nil" if strategy.nil?
|
8
|
+
raise ArgumentError, "strategy must respond to 'call'" unless strategy.respond_to?(:call)
|
9
|
+
self.strategy = strategy
|
10
|
+
self.evidence = evidence
|
11
|
+
self.report = Report.new
|
12
|
+
end
|
13
|
+
|
14
|
+
def investigate!
|
15
|
+
create_report
|
16
|
+
send_report unless ignore_report
|
17
|
+
end
|
18
|
+
|
19
|
+
def create_report
|
20
|
+
strategy.call(self)
|
21
|
+
end
|
22
|
+
|
23
|
+
def send_report
|
24
|
+
Sender.new(WhoopsNotifier.config.to_hash).send_report(self.report.to_hash)
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
@@ -0,0 +1,20 @@
|
|
1
|
+
module WhoopsNotifier
|
2
|
+
class Report
|
3
|
+
ATTRIBUTES = [:event_type, :service, :environment, :message, :identifier, :event_time, :details]
|
4
|
+
ATTRIBUTES.each do |attribute|
|
5
|
+
attr_accessor attribute
|
6
|
+
end
|
7
|
+
|
8
|
+
def initialize
|
9
|
+
self.event_time = Time.now
|
10
|
+
end
|
11
|
+
|
12
|
+
def to_hash
|
13
|
+
h = {}
|
14
|
+
ATTRIBUTES.each do |attribute|
|
15
|
+
h[attribute] = self.send(attribute)
|
16
|
+
end
|
17
|
+
h
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
@@ -0,0 +1,82 @@
|
|
1
|
+
module WhoopsNotifier
|
2
|
+
class Sender
|
3
|
+
NOTICES_URI = '/events/'.freeze
|
4
|
+
HTTP_ERRORS = [Timeout::Error,
|
5
|
+
Errno::EINVAL,
|
6
|
+
Errno::ECONNRESET,
|
7
|
+
EOFError,
|
8
|
+
Net::HTTPBadResponse,
|
9
|
+
Net::HTTPHeaderSyntaxError,
|
10
|
+
Net::ProtocolError,
|
11
|
+
Errno::ECONNREFUSED].freeze
|
12
|
+
|
13
|
+
HEADERS = {
|
14
|
+
'Content-type' => 'application/json',
|
15
|
+
'Accept' => 'application/json'
|
16
|
+
}
|
17
|
+
|
18
|
+
def initialize(options = {})
|
19
|
+
[:proxy_host, :proxy_port, :proxy_user, :proxy_pass, :protocol,
|
20
|
+
:host, :port, :secure, :http_open_timeout, :http_read_timeout].each do |option|
|
21
|
+
instance_variable_set("@#{option}", options[option])
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
# Sends the notice data off to Hoptoad for processing.
|
26
|
+
#
|
27
|
+
# @param [Hash] data The notice to be sent off
|
28
|
+
def send_report(data)
|
29
|
+
# TODO: format
|
30
|
+
# TODO: validation
|
31
|
+
data = {:event => data}.to_json
|
32
|
+
logger.debug { "Sending request to #{url.to_s}:\n#{data}" } if logger
|
33
|
+
|
34
|
+
http =
|
35
|
+
Net::HTTP::Proxy(proxy_host, proxy_port, proxy_user, proxy_pass).
|
36
|
+
new(url.host, url.port)
|
37
|
+
|
38
|
+
http.read_timeout = http_read_timeout
|
39
|
+
http.open_timeout = http_open_timeout
|
40
|
+
http.use_ssl = secure
|
41
|
+
|
42
|
+
response = begin
|
43
|
+
http.post(url.path, data, HEADERS)
|
44
|
+
rescue *HTTP_ERRORS => e
|
45
|
+
log :error, "Timeout while contacting the Whoops server."
|
46
|
+
nil
|
47
|
+
end
|
48
|
+
|
49
|
+
case response
|
50
|
+
when Net::HTTPSuccess then
|
51
|
+
log :info, "Success: #{response.class}", response
|
52
|
+
else
|
53
|
+
log :error, "Failure: #{response.class}", response
|
54
|
+
end
|
55
|
+
|
56
|
+
if response && response.respond_to?(:body)
|
57
|
+
error_id = response.body.match(%r{<error-id[^>]*>(.*?)</error-id>})
|
58
|
+
error_id[1] if error_id
|
59
|
+
end
|
60
|
+
end
|
61
|
+
|
62
|
+
private
|
63
|
+
|
64
|
+
attr_reader :proxy_host, :proxy_port, :proxy_user, :proxy_pass, :protocol,
|
65
|
+
:host, :port, :secure, :http_open_timeout, :http_read_timeout
|
66
|
+
|
67
|
+
def url
|
68
|
+
URI.parse("#{protocol}://#{host}:#{port}").merge(NOTICES_URI)
|
69
|
+
end
|
70
|
+
|
71
|
+
def log(level, message, response = nil)
|
72
|
+
logger.send level, LOG_PREFIX + message if logger
|
73
|
+
# HoptoadNotifier.report_environment_info
|
74
|
+
# HoptoadNotifier.report_response_body(response.body) if response && response.respond_to?(:body)
|
75
|
+
end
|
76
|
+
|
77
|
+
def logger
|
78
|
+
WhoopsNotifier.config.logger
|
79
|
+
end
|
80
|
+
|
81
|
+
end
|
82
|
+
end
|
@@ -0,0 +1,11 @@
|
|
1
|
+
strategy = WhoopsNotifier::Strategy.new("default::basic")
|
2
|
+
|
3
|
+
strategy.add_report_modifier(:use_basic_hash) do |report, evidence|
|
4
|
+
report.event_type = evidence[:event_type]
|
5
|
+
report.service = evidence[:service]
|
6
|
+
report.environment = evidence[:environment]
|
7
|
+
report.message = evidence[:message]
|
8
|
+
report.identifier = evidence[:identifier]
|
9
|
+
report.event_time = evidence[:event_time] if evidence[:event_time]
|
10
|
+
report.details = evidence[:details]
|
11
|
+
end
|
@@ -0,0 +1,50 @@
|
|
1
|
+
module WhoopsNotifier
|
2
|
+
class Strategy
|
3
|
+
# ask witnesses for data, create a report using a strategy, send or ignore
|
4
|
+
attr_accessor :name, :ignore_criteria, :report_modifiers
|
5
|
+
|
6
|
+
def initialize(name)
|
7
|
+
self.name = name
|
8
|
+
self.ignore_criteria = []
|
9
|
+
self.report_modifiers = []
|
10
|
+
WhoopsNotifier.strategies[name] = self
|
11
|
+
end
|
12
|
+
|
13
|
+
def call(investigator)
|
14
|
+
report_modifiers.each do |report_modifier|
|
15
|
+
report_modifier.call(investigator.report, investigator.evidence)
|
16
|
+
end
|
17
|
+
|
18
|
+
ignore_criteria.each do |ignore_criterion|
|
19
|
+
if ignore_criterion.call(investigator.report)
|
20
|
+
investigator.ignore_report = true
|
21
|
+
break
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
# block should take one param, the investigator
|
27
|
+
# use evidence to build the report
|
28
|
+
def add_report_modifier(name, &block)
|
29
|
+
give_name(name, block)
|
30
|
+
@report_modifiers << block
|
31
|
+
end
|
32
|
+
|
33
|
+
# block takes one param, the investigator's report
|
34
|
+
def add_ignore_criterion(name, &block)
|
35
|
+
give_name(name, block)
|
36
|
+
@ignore_criteria << block
|
37
|
+
end
|
38
|
+
|
39
|
+
def give_name(name, block)
|
40
|
+
class << block
|
41
|
+
attr_accessor :name
|
42
|
+
end
|
43
|
+
block.name = name
|
44
|
+
end
|
45
|
+
|
46
|
+
def inspect
|
47
|
+
"#{name}\nreport modifiers: #{report_modifiers.collect{|r| r.name}.join(", ")}\nignore criteria: #{ignore_criteria.collect{|i| i.name}.join(", ")}"
|
48
|
+
end
|
49
|
+
end
|
50
|
+
end
|
@@ -0,0 +1,35 @@
|
|
1
|
+
require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
|
2
|
+
|
3
|
+
describe "WhoopsNotifier::Investigator" do
|
4
|
+
describe "#initialize" do
|
5
|
+
it "should raise an exception if strategy is nil" do
|
6
|
+
lambda{WhoopsNotifier::Investigator.new(nil, {})}.should raise_exception(ArgumentError)
|
7
|
+
end
|
8
|
+
|
9
|
+
it "should raise an exception if strategy argument does not respond to call" do
|
10
|
+
lambda{WhoopsNotifier::Investigator.new(true, {})}.should raise_exception(ArgumentError)
|
11
|
+
end
|
12
|
+
|
13
|
+
it "should not raise an exception if strategy argument responds to call" do
|
14
|
+
lambda{WhoopsNotifier::Investigator.new(Proc.new{}, {})}.should_not raise_exception
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
describe "#investigate!" do
|
19
|
+
it "should not send report if ignore_report is true" do
|
20
|
+
strategy = mock(:call)
|
21
|
+
investigator = WhoopsNotifier::Investigator.new(strategy, {})
|
22
|
+
investigator.ignore_report = true
|
23
|
+
|
24
|
+
investigator.expects(:send_report).never
|
25
|
+
|
26
|
+
investigator.investigate!
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
describe "#send_report" do
|
31
|
+
it "should send the report's hash" do
|
32
|
+
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,12 @@
|
|
1
|
+
$LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
|
2
|
+
$LOAD_PATH.unshift(File.dirname(__FILE__))
|
3
|
+
require 'rspec'
|
4
|
+
require 'whoops_notifier'
|
5
|
+
|
6
|
+
# Requires supporting files with custom matchers and macros, etc,
|
7
|
+
# in ./support/ and its subdirectories.
|
8
|
+
Dir["#{File.dirname(__FILE__)}/support/**/*.rb"].each {|f| require f}
|
9
|
+
|
10
|
+
RSpec.configure do |config|
|
11
|
+
config.mock_with :mocha
|
12
|
+
end
|
@@ -0,0 +1,69 @@
|
|
1
|
+
require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
|
2
|
+
|
3
|
+
describe "WhoopsNotifier::Strategy" do
|
4
|
+
describe "#initialize" do
|
5
|
+
it "should add strategy to WhoopsNotifier.strategies" do
|
6
|
+
s = WhoopsNotifier::Strategy.new(:test)
|
7
|
+
WhoopsNotifier.strategies[:test].should == s
|
8
|
+
end
|
9
|
+
|
10
|
+
it "should create empty arrays for ignore criteria and report_modifiers" do
|
11
|
+
s = WhoopsNotifier::Strategy.new(:test)
|
12
|
+
s.ignore_criteria.should == []
|
13
|
+
s.report_modifiers.should == []
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
describe "#add_report_modifier" do
|
18
|
+
it "should add a named block" do
|
19
|
+
s = WhoopsNotifier::Strategy.new(:test)
|
20
|
+
s.add_report_modifier(:add_message) { |investigator| }
|
21
|
+
|
22
|
+
s.report_modifiers.first.name.should == :add_message
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
describe "#call" do
|
27
|
+
it "should change the investigator's 'ignore' attribute to true if any ignore criteria are true" do
|
28
|
+
strategy = WhoopsNotifier::Strategy.new(:test)
|
29
|
+
investigator = WhoopsNotifier::Investigator.new(strategy, nil)
|
30
|
+
|
31
|
+
strategy.add_ignore_criterion(:always_ignore) do |report|
|
32
|
+
true
|
33
|
+
end
|
34
|
+
|
35
|
+
strategy.call(investigator)
|
36
|
+
investigator.ignore_report.should == true
|
37
|
+
end
|
38
|
+
|
39
|
+
it "should modify the investigator's report according to the report modifiers" do
|
40
|
+
strategy = WhoopsNotifier::Strategy.new(:test)
|
41
|
+
investigator = WhoopsNotifier::Investigator.new(strategy, {:service => "service"})
|
42
|
+
strategy.add_report_modifier(:add_details){ |report, evidence|
|
43
|
+
report.service = evidence[:service] + " test"
|
44
|
+
}
|
45
|
+
|
46
|
+
strategy.call(investigator)
|
47
|
+
|
48
|
+
investigator.report.service.should == "service test"
|
49
|
+
end
|
50
|
+
end
|
51
|
+
|
52
|
+
describe "#inspect" do
|
53
|
+
it "should list name, report modifier names, and ignore criteria names" do
|
54
|
+
strategy = WhoopsNotifier::Strategy.new(:awesome_strategy)
|
55
|
+
investigator = WhoopsNotifier::Investigator.new(strategy, nil)
|
56
|
+
|
57
|
+
strategy.add_report_modifier(:report1){ }
|
58
|
+
strategy.add_report_modifier(:report2){ }
|
59
|
+
|
60
|
+
strategy.add_ignore_criterion(:ignore1){ true }
|
61
|
+
strategy.add_ignore_criterion(:ignore2){ true }
|
62
|
+
|
63
|
+
strategy.inspect.should == "awesome_strategy
|
64
|
+
report modifiers: report1, report2
|
65
|
+
ignore criteria: ignore1, ignore2"
|
66
|
+
|
67
|
+
end
|
68
|
+
end
|
69
|
+
end
|
@@ -0,0 +1,81 @@
|
|
1
|
+
# Generated by jeweler
|
2
|
+
# DO NOT EDIT THIS FILE DIRECTLY
|
3
|
+
# Instead, edit Jeweler::Tasks in Rakefile, and run 'rake gemspec'
|
4
|
+
# -*- encoding: utf-8 -*-
|
5
|
+
|
6
|
+
Gem::Specification.new do |s|
|
7
|
+
s.name = %q{whoops_notifier}
|
8
|
+
s.version = "0.0.0"
|
9
|
+
|
10
|
+
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
|
+
s.authors = ["Daniel Higginbotham"]
|
12
|
+
s.date = %q{2011-05-30}
|
13
|
+
s.description = %q{Handles basic notification responsibilities and allows creation of report creation strategies}
|
14
|
+
s.email = %q{daniel@flyingmachinestudios.com}
|
15
|
+
s.extra_rdoc_files = [
|
16
|
+
"LICENSE.txt",
|
17
|
+
"README.rdoc"
|
18
|
+
]
|
19
|
+
s.files = [
|
20
|
+
".document",
|
21
|
+
".rspec",
|
22
|
+
"Gemfile",
|
23
|
+
"Gemfile.lock",
|
24
|
+
"LICENSE.txt",
|
25
|
+
"README.rdoc",
|
26
|
+
"Rakefile",
|
27
|
+
"VERSION",
|
28
|
+
"lib/whoops_notifier.rb",
|
29
|
+
"lib/whoops_notifier/configuration.rb",
|
30
|
+
"lib/whoops_notifier/investigator.rb",
|
31
|
+
"lib/whoops_notifier/report.rb",
|
32
|
+
"lib/whoops_notifier/sender.rb",
|
33
|
+
"lib/whoops_notifier/strategies/basic.rb",
|
34
|
+
"lib/whoops_notifier/strategy.rb",
|
35
|
+
"spec/investigator_spec.rb",
|
36
|
+
"spec/spec_helper.rb",
|
37
|
+
"spec/strategy_spec.rb",
|
38
|
+
"spec/whoops_notifier_spec.rb",
|
39
|
+
"whoops_notifier.gemspec"
|
40
|
+
]
|
41
|
+
s.homepage = %q{http://github.com/flyingmachine/whoops_notifier}
|
42
|
+
s.licenses = ["MIT"]
|
43
|
+
s.require_paths = ["lib"]
|
44
|
+
s.rubygems_version = %q{1.3.7}
|
45
|
+
s.summary = %q{Handles basic notification responsibilities and allows creation of report creation strategies}
|
46
|
+
s.test_files = [
|
47
|
+
"spec/investigator_spec.rb",
|
48
|
+
"spec/spec_helper.rb",
|
49
|
+
"spec/strategy_spec.rb",
|
50
|
+
"spec/whoops_notifier_spec.rb"
|
51
|
+
]
|
52
|
+
|
53
|
+
if s.respond_to? :specification_version then
|
54
|
+
current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
|
55
|
+
s.specification_version = 3
|
56
|
+
|
57
|
+
if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
|
58
|
+
s.add_runtime_dependency(%q<json>, [">= 0"])
|
59
|
+
s.add_development_dependency(%q<rspec>, ["~> 2.3.0"])
|
60
|
+
s.add_development_dependency(%q<bundler>, ["~> 1.0.0"])
|
61
|
+
s.add_development_dependency(%q<jeweler>, ["~> 1.5.2"])
|
62
|
+
s.add_development_dependency(%q<mocha>, [">= 0"])
|
63
|
+
s.add_development_dependency(%q<ruby-debug>, [">= 0"])
|
64
|
+
else
|
65
|
+
s.add_dependency(%q<json>, [">= 0"])
|
66
|
+
s.add_dependency(%q<rspec>, ["~> 2.3.0"])
|
67
|
+
s.add_dependency(%q<bundler>, ["~> 1.0.0"])
|
68
|
+
s.add_dependency(%q<jeweler>, ["~> 1.5.2"])
|
69
|
+
s.add_dependency(%q<mocha>, [">= 0"])
|
70
|
+
s.add_dependency(%q<ruby-debug>, [">= 0"])
|
71
|
+
end
|
72
|
+
else
|
73
|
+
s.add_dependency(%q<json>, [">= 0"])
|
74
|
+
s.add_dependency(%q<rspec>, ["~> 2.3.0"])
|
75
|
+
s.add_dependency(%q<bundler>, ["~> 1.0.0"])
|
76
|
+
s.add_dependency(%q<jeweler>, ["~> 1.5.2"])
|
77
|
+
s.add_dependency(%q<mocha>, [">= 0"])
|
78
|
+
s.add_dependency(%q<ruby-debug>, [">= 0"])
|
79
|
+
end
|
80
|
+
end
|
81
|
+
|
metadata
ADDED
@@ -0,0 +1,179 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: whoops_notifier
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
hash: 31
|
5
|
+
prerelease: false
|
6
|
+
segments:
|
7
|
+
- 0
|
8
|
+
- 0
|
9
|
+
- 0
|
10
|
+
version: 0.0.0
|
11
|
+
platform: ruby
|
12
|
+
authors:
|
13
|
+
- Daniel Higginbotham
|
14
|
+
autorequire:
|
15
|
+
bindir: bin
|
16
|
+
cert_chain: []
|
17
|
+
|
18
|
+
date: 2011-05-30 00:00:00 -04:00
|
19
|
+
default_executable:
|
20
|
+
dependencies:
|
21
|
+
- !ruby/object:Gem::Dependency
|
22
|
+
prerelease: false
|
23
|
+
type: :runtime
|
24
|
+
name: json
|
25
|
+
version_requirements: &id001 !ruby/object:Gem::Requirement
|
26
|
+
none: false
|
27
|
+
requirements:
|
28
|
+
- - ">="
|
29
|
+
- !ruby/object:Gem::Version
|
30
|
+
hash: 3
|
31
|
+
segments:
|
32
|
+
- 0
|
33
|
+
version: "0"
|
34
|
+
requirement: *id001
|
35
|
+
- !ruby/object:Gem::Dependency
|
36
|
+
prerelease: false
|
37
|
+
type: :development
|
38
|
+
name: rspec
|
39
|
+
version_requirements: &id002 !ruby/object:Gem::Requirement
|
40
|
+
none: false
|
41
|
+
requirements:
|
42
|
+
- - ~>
|
43
|
+
- !ruby/object:Gem::Version
|
44
|
+
hash: 3
|
45
|
+
segments:
|
46
|
+
- 2
|
47
|
+
- 3
|
48
|
+
- 0
|
49
|
+
version: 2.3.0
|
50
|
+
requirement: *id002
|
51
|
+
- !ruby/object:Gem::Dependency
|
52
|
+
prerelease: false
|
53
|
+
type: :development
|
54
|
+
name: bundler
|
55
|
+
version_requirements: &id003 !ruby/object:Gem::Requirement
|
56
|
+
none: false
|
57
|
+
requirements:
|
58
|
+
- - ~>
|
59
|
+
- !ruby/object:Gem::Version
|
60
|
+
hash: 23
|
61
|
+
segments:
|
62
|
+
- 1
|
63
|
+
- 0
|
64
|
+
- 0
|
65
|
+
version: 1.0.0
|
66
|
+
requirement: *id003
|
67
|
+
- !ruby/object:Gem::Dependency
|
68
|
+
prerelease: false
|
69
|
+
type: :development
|
70
|
+
name: jeweler
|
71
|
+
version_requirements: &id004 !ruby/object:Gem::Requirement
|
72
|
+
none: false
|
73
|
+
requirements:
|
74
|
+
- - ~>
|
75
|
+
- !ruby/object:Gem::Version
|
76
|
+
hash: 7
|
77
|
+
segments:
|
78
|
+
- 1
|
79
|
+
- 5
|
80
|
+
- 2
|
81
|
+
version: 1.5.2
|
82
|
+
requirement: *id004
|
83
|
+
- !ruby/object:Gem::Dependency
|
84
|
+
prerelease: false
|
85
|
+
type: :development
|
86
|
+
name: mocha
|
87
|
+
version_requirements: &id005 !ruby/object:Gem::Requirement
|
88
|
+
none: false
|
89
|
+
requirements:
|
90
|
+
- - ">="
|
91
|
+
- !ruby/object:Gem::Version
|
92
|
+
hash: 3
|
93
|
+
segments:
|
94
|
+
- 0
|
95
|
+
version: "0"
|
96
|
+
requirement: *id005
|
97
|
+
- !ruby/object:Gem::Dependency
|
98
|
+
prerelease: false
|
99
|
+
type: :development
|
100
|
+
name: ruby-debug
|
101
|
+
version_requirements: &id006 !ruby/object:Gem::Requirement
|
102
|
+
none: false
|
103
|
+
requirements:
|
104
|
+
- - ">="
|
105
|
+
- !ruby/object:Gem::Version
|
106
|
+
hash: 3
|
107
|
+
segments:
|
108
|
+
- 0
|
109
|
+
version: "0"
|
110
|
+
requirement: *id006
|
111
|
+
description: Handles basic notification responsibilities and allows creation of report creation strategies
|
112
|
+
email: daniel@flyingmachinestudios.com
|
113
|
+
executables: []
|
114
|
+
|
115
|
+
extensions: []
|
116
|
+
|
117
|
+
extra_rdoc_files:
|
118
|
+
- LICENSE.txt
|
119
|
+
- README.rdoc
|
120
|
+
files:
|
121
|
+
- .document
|
122
|
+
- .rspec
|
123
|
+
- Gemfile
|
124
|
+
- Gemfile.lock
|
125
|
+
- LICENSE.txt
|
126
|
+
- README.rdoc
|
127
|
+
- Rakefile
|
128
|
+
- VERSION
|
129
|
+
- lib/whoops_notifier.rb
|
130
|
+
- lib/whoops_notifier/configuration.rb
|
131
|
+
- lib/whoops_notifier/investigator.rb
|
132
|
+
- lib/whoops_notifier/report.rb
|
133
|
+
- lib/whoops_notifier/sender.rb
|
134
|
+
- lib/whoops_notifier/strategies/basic.rb
|
135
|
+
- lib/whoops_notifier/strategy.rb
|
136
|
+
- spec/investigator_spec.rb
|
137
|
+
- spec/spec_helper.rb
|
138
|
+
- spec/strategy_spec.rb
|
139
|
+
- spec/whoops_notifier_spec.rb
|
140
|
+
- whoops_notifier.gemspec
|
141
|
+
has_rdoc: true
|
142
|
+
homepage: http://github.com/flyingmachine/whoops_notifier
|
143
|
+
licenses:
|
144
|
+
- MIT
|
145
|
+
post_install_message:
|
146
|
+
rdoc_options: []
|
147
|
+
|
148
|
+
require_paths:
|
149
|
+
- lib
|
150
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
151
|
+
none: false
|
152
|
+
requirements:
|
153
|
+
- - ">="
|
154
|
+
- !ruby/object:Gem::Version
|
155
|
+
hash: 3
|
156
|
+
segments:
|
157
|
+
- 0
|
158
|
+
version: "0"
|
159
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
160
|
+
none: false
|
161
|
+
requirements:
|
162
|
+
- - ">="
|
163
|
+
- !ruby/object:Gem::Version
|
164
|
+
hash: 3
|
165
|
+
segments:
|
166
|
+
- 0
|
167
|
+
version: "0"
|
168
|
+
requirements: []
|
169
|
+
|
170
|
+
rubyforge_project:
|
171
|
+
rubygems_version: 1.3.7
|
172
|
+
signing_key:
|
173
|
+
specification_version: 3
|
174
|
+
summary: Handles basic notification responsibilities and allows creation of report creation strategies
|
175
|
+
test_files:
|
176
|
+
- spec/investigator_spec.rb
|
177
|
+
- spec/spec_helper.rb
|
178
|
+
- spec/strategy_spec.rb
|
179
|
+
- spec/whoops_notifier_spec.rb
|