whoops_notifier 0.0.1 → 0.0.2

Sign up to get free protection for your applications and to get access to all the features.
data/Gemfile CHANGED
@@ -7,9 +7,9 @@ gem "json"
7
7
  # Add dependencies to develop your gem here.
8
8
  # Include everything needed to run rake, tests, features, etc.
9
9
  group :development do
10
- gem "rspec", "~> 2.3.0"
10
+ gem "rspec", "~> 2.6.0"
11
11
  gem "bundler", "~> 1.0.0"
12
12
  gem "jeweler", "~> 1.5.2"
13
- gem "mocha"
14
13
  gem "ruby-debug"
14
+ gem "fakeweb"
15
15
  end
@@ -3,6 +3,7 @@ GEM
3
3
  specs:
4
4
  columnize (0.3.2)
5
5
  diff-lcs (1.1.2)
6
+ fakeweb (1.3.0)
6
7
  git (1.2.5)
7
8
  jeweler (1.5.2)
8
9
  bundler (~> 1.0.0)
@@ -10,16 +11,15 @@ GEM
10
11
  rake
11
12
  json (1.5.1)
12
13
  linecache (0.43)
13
- mocha (0.9.12)
14
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)
15
+ rspec (2.6.0)
16
+ rspec-core (~> 2.6.0)
17
+ rspec-expectations (~> 2.6.0)
18
+ rspec-mocks (~> 2.6.0)
19
+ rspec-core (2.6.4)
20
+ rspec-expectations (2.6.0)
21
21
  diff-lcs (~> 1.1.2)
22
- rspec-mocks (2.3.0)
22
+ rspec-mocks (2.6.0)
23
23
  ruby-debug (0.10.4)
24
24
  columnize (>= 0.1)
25
25
  ruby-debug-base (~> 0.10.4.0)
@@ -31,8 +31,8 @@ PLATFORMS
31
31
 
32
32
  DEPENDENCIES
33
33
  bundler (~> 1.0.0)
34
+ fakeweb
34
35
  jeweler (~> 1.5.2)
35
36
  json
36
- mocha
37
- rspec (~> 2.3.0)
37
+ rspec (~> 2.6.0)
38
38
  ruby-debug
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.0.1
1
+ 0.0.2
@@ -11,21 +11,32 @@ module WhoopsNotifier
11
11
 
12
12
  class << self
13
13
  attr_accessor :strategies, :config
14
+
15
+ # @overload notify(evidence)
16
+ # Notify using the default basic strategy
17
+ # @param [Hash] evidence the evidence expected by the basic strategy
18
+ # @overload notify(strategy_name, evidence)
19
+ # @param [Symbol, String] strategy_name
20
+ # @param [Hash] evidence same as above
14
21
  def notify(strategy_name, evidence = {})
15
22
  if strategy_name.is_a? Hash
16
23
  notify("default::basic", strategy_name)
17
24
  else
18
25
  investigator = Investigator.new(strategies[strategy_name], evidence)
19
26
  investigator.investigate!
27
+ send_report(investigator.report) unless investigator.ignore_report?
20
28
  end
21
29
  end
30
+
31
+ def send_report(report)
32
+ Sender.new(WhoopsNotifier.config.to_hash).send_report(report.to_hash)
33
+ end
22
34
  end
23
35
 
24
36
  def self.config
25
37
  @config ||= Configuration.new
26
38
  end
27
39
 
28
-
29
40
  self.strategies = {}
30
41
  end
31
42
 
@@ -1,4 +1,6 @@
1
- # Copyright (c) 2007, Tammer Saleh, Thoughtbot, Inc.
1
+ require 'yaml'
2
+
3
+ # Borrows heavily from Hoptoad Notifier by Tammer Saleh
2
4
  module WhoopsNotifier
3
5
  # Used to set up and modify settings for the notifier.
4
6
  class Configuration
@@ -90,6 +92,7 @@ module WhoopsNotifier
90
92
 
91
93
  def set_with_hash(config)
92
94
  OPTIONS.each do |option|
95
+ next unless self.respond_to?("#{option}=")
93
96
  if config.has_key?(option)
94
97
  self.send("#{option}=", config[option])
95
98
  elsif config.has_key?(option.to_s)
@@ -1,7 +1,8 @@
1
1
  module WhoopsNotifier
2
2
  class Investigator
3
- # get data from evidence using a strategy to create a report, then send or ignore
3
+ # get data from evidence using a strategy to create a report and decide whether it should be ignored
4
4
  attr_accessor :strategy, :report, :evidence, :ignore_report
5
+ alias :ignore_report? :ignore_report
5
6
 
6
7
  def initialize(strategy, evidence)
7
8
  raise ArgumentError, "strategy can not be nil" if strategy.nil?
@@ -13,15 +14,10 @@ module WhoopsNotifier
13
14
 
14
15
  def investigate!
15
16
  create_report
16
- send_report unless ignore_report
17
17
  end
18
18
 
19
19
  def create_report
20
20
  strategy.call(self)
21
21
  end
22
-
23
- def send_report
24
- Sender.new(WhoopsNotifier.config.to_hash).send_report(self.report.to_hash)
25
- end
26
22
  end
27
23
  end
@@ -1,6 +1,6 @@
1
1
  module WhoopsNotifier
2
2
  class Report
3
- ATTRIBUTES = [:event_type, :service, :environment, :message, :identifier, :event_time, :details]
3
+ ATTRIBUTES = [:event_type, :service, :environment, :message, :event_group_identifier, :event_time, :details]
4
4
  ATTRIBUTES.each do |attribute|
5
5
  attr_accessor attribute
6
6
  end
@@ -22,13 +22,13 @@ module WhoopsNotifier
22
22
  end
23
23
  end
24
24
 
25
- # Sends the notice data off to Hoptoad for processing.
25
+ # Sends the notice data off to Whoops for processing.
26
26
  #
27
27
  # @param [Hash] data The notice to be sent off
28
28
  def send_report(data)
29
29
  # TODO: format
30
30
  # TODO: validation
31
- data = {:event => data}.to_json
31
+ data = prepare_data(data)
32
32
  logger.debug { "Sending request to #{url.to_s}:\n#{data}" } if logger
33
33
 
34
34
  http =
@@ -58,6 +58,10 @@ module WhoopsNotifier
58
58
  error_id[1] if error_id
59
59
  end
60
60
  end
61
+
62
+ def prepare_data(data)
63
+ {:event => data}.to_json
64
+ end
61
65
 
62
66
  private
63
67
 
@@ -70,13 +74,10 @@ module WhoopsNotifier
70
74
 
71
75
  def log(level, message, response = nil)
72
76
  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
77
  end
76
78
 
77
79
  def logger
78
80
  WhoopsNotifier.config.logger
79
- end
80
-
81
+ end
81
82
  end
82
83
  end
@@ -31,7 +31,7 @@ module WhoopsNotifier
31
31
  end
32
32
 
33
33
  # block takes one param, the investigator's report
34
- def add_ignore_criterion(name, &block)
34
+ def add_ignore_case(name, &block)
35
35
  give_name(name, block)
36
36
  @ignore_criteria << block
37
37
  end
@@ -1,6 +1,15 @@
1
1
  describe "WhoopsNotifier::Configuration" do
2
2
  describe "#set" do
3
- after(:each) { WhoopsNotifier.config.host = nil }
3
+ before(:each) {
4
+ @real_config = WhoopsNotifier.config.to_hash
5
+ WhoopsNotifier::Configuration::OPTIONS.each do |option|
6
+ WhoopsNotifier.config.send("#{option}=", nil) if WhoopsNotifier.config.respond_to?("#{option}=".to_sym)
7
+ end
8
+ }
9
+ after(:each) {
10
+ WhoopsNotifier.config.set(@real_config)
11
+ }
12
+
4
13
  let(:config_path) { File.join(File.dirname(__FILE__), "fixtures/whoops_notifier.yml") }
5
14
  it "should set the config from a yaml filename" do
6
15
  WhoopsNotifier.config.set(config_path)
@@ -17,19 +17,13 @@ describe "WhoopsNotifier::Investigator" do
17
17
 
18
18
  describe "#investigate!" do
19
19
  it "should not send report if ignore_report is true" do
20
- strategy = mock(:call)
20
+ strategy = lambda{}
21
21
  investigator = WhoopsNotifier::Investigator.new(strategy, {})
22
22
  investigator.ignore_report = true
23
23
 
24
- investigator.expects(:send_report).never
24
+ investigator.should_not_receive(:send_report)
25
25
 
26
26
  investigator.investigate!
27
27
  end
28
- end
29
-
30
- describe "#send_report" do
31
- it "should send the report's hash" do
32
-
33
- end
34
- end
28
+ end
35
29
  end
@@ -0,0 +1,15 @@
1
+ require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
2
+
3
+ describe WhoopsNotifier::Sender do
4
+ describe "#send_report" do
5
+ it "should send a report to the configured URL when given a config object" do
6
+ FakeWeb.register_uri(:post, "http://whoops.com/events/", :body => "success")
7
+
8
+ sender = WhoopsNotifier::Sender.new(WhoopsNotifier.config)
9
+ sender.send_report({:test => true})
10
+
11
+ request = FakeWeb.last_request
12
+ request.body.should =~ /"test"/
13
+ end
14
+ end
15
+ end
@@ -1,12 +1,13 @@
1
- $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
2
- $LOAD_PATH.unshift(File.dirname(__FILE__))
1
+ rspec_dir = File.dirname(__FILE__)
2
+
3
+ $LOAD_PATH.unshift(File.join(rspec_dir, '..', 'lib'))
4
+ $LOAD_PATH.unshift(rspec_dir)
3
5
  require 'rspec'
4
6
  require 'whoops_notifier'
7
+ require 'fakeweb'
5
8
 
6
9
  # Requires supporting files with custom matchers and macros, etc,
7
10
  # in ./support/ and its subdirectories.
8
- Dir["#{File.dirname(__FILE__)}/support/**/*.rb"].each {|f| require f}
11
+ Dir["#{rspec_dir}/support/**/*.rb"].each {|f| require f}
9
12
 
10
- RSpec.configure do |config|
11
- config.mock_with :mocha
12
- end
13
+ WhoopsNotifier.config.set(File.join(rspec_dir, "fixtures", "whoops_notifier.yml"))
@@ -2,12 +2,12 @@ require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
2
2
 
3
3
  describe "WhoopsNotifier::Strategy" do
4
4
  describe "#initialize" do
5
- it "should add strategy to WhoopsNotifier.strategies" do
5
+ it "adds a strategy to WhoopsNotifier.strategies" do
6
6
  s = WhoopsNotifier::Strategy.new(:test)
7
7
  WhoopsNotifier.strategies[:test].should == s
8
8
  end
9
9
 
10
- it "should create empty arrays for ignore criteria and report_modifiers" do
10
+ it "creates empty arrays for ignore criteria and report_modifiers" do
11
11
  s = WhoopsNotifier::Strategy.new(:test)
12
12
  s.ignore_criteria.should == []
13
13
  s.report_modifiers.should == []
@@ -15,7 +15,7 @@ describe "WhoopsNotifier::Strategy" do
15
15
  end
16
16
 
17
17
  describe "#add_report_modifier" do
18
- it "should add a named block" do
18
+ it "adds a named block" do
19
19
  s = WhoopsNotifier::Strategy.new(:test)
20
20
  s.add_report_modifier(:add_message) { |investigator| }
21
21
 
@@ -23,12 +23,21 @@ describe "WhoopsNotifier::Strategy" do
23
23
  end
24
24
  end
25
25
 
26
+ describe "#add_ignore_case" do
27
+ it "adds a named ignore criteria block" do
28
+ s = WhoopsNotifier::Strategy.new(:test)
29
+ s.add_ignore_case(:ignore_if_empty) { |investigator| }
30
+
31
+ s.ignore_criteria.first.name.should == :ignore_if_empty
32
+ end
33
+ end
34
+
26
35
  describe "#call" do
27
36
  it "should change the investigator's 'ignore' attribute to true if any ignore criteria are true" do
28
37
  strategy = WhoopsNotifier::Strategy.new(:test)
29
38
  investigator = WhoopsNotifier::Investigator.new(strategy, nil)
30
39
 
31
- strategy.add_ignore_criterion(:always_ignore) do |report|
40
+ strategy.add_ignore_case(:always_ignore) do |report|
32
41
  true
33
42
  end
34
43
 
@@ -57,8 +66,8 @@ describe "WhoopsNotifier::Strategy" do
57
66
  strategy.add_report_modifier(:report1){ }
58
67
  strategy.add_report_modifier(:report2){ }
59
68
 
60
- strategy.add_ignore_criterion(:ignore1){ true }
61
- strategy.add_ignore_criterion(:ignore2){ true }
69
+ strategy.add_ignore_case(:ignore1){ true }
70
+ strategy.add_ignore_case(:ignore2){ true }
62
71
 
63
72
  strategy.inspect.should == "awesome_strategy
64
73
  report modifiers: report1, report2
@@ -1,12 +1,56 @@
1
1
  require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
2
2
 
3
3
  describe "WhoopsNotifier" do
4
+ before(:each) { FakeWeb.clean_registry }
5
+
4
6
  describe ".strategies" do
7
+ it "is a hash with keys of strategy names and values of strategy objects" do
8
+ WhoopsNotifier.strategies.each do |key, value|
9
+ (key.instance_of?(Symbol) || key.instance_of?(String)).should be_true
10
+ value.should be_a WhoopsNotifier::Strategy
11
+ end
12
+ end
5
13
  end
6
14
 
7
15
  describe ".config" do
16
+ it "returns a WhoopsNotifier::Configuration object" do
17
+ WhoopsNotifier.config.should be_a(WhoopsNotifier::Configuration)
18
+ end
8
19
  end
9
20
 
10
21
  describe ".notify" do
22
+ let(:investigator){ double(:investigator, :investigate! => nil, :report => nil) }
23
+
24
+ it "uses the basic strategy if no strategy name is provided" do
25
+ WhoopsNotifier.stub(:send_report)
26
+ investigator.stub(:ignore_report?).and_return(false)
27
+ WhoopsNotifier::Investigator.should_receive(:new).with(WhoopsNotifier.strategies["default::basic"], {}).and_return(investigator)
28
+ WhoopsNotifier.notify({})
29
+ end
30
+
31
+ it "sends a report when the investigator is not ignoring the event" do
32
+ investigator.should_receive(:ignore_report?).and_return(false)
33
+ WhoopsNotifier::Investigator.stub(:new).and_return(investigator)
34
+
35
+ WhoopsNotifier.should_receive(:send_report)
36
+ WhoopsNotifier.notify({})
37
+ end
38
+
39
+ it "does not sned a request if the investigator is ignoring the event" do
40
+ investigator.should_receive(:ignore_report?).and_return(true)
41
+ WhoopsNotifier::Investigator.stub(:new).and_return(investigator)
42
+
43
+ WhoopsNotifier.should_not_receive(:send_report)
44
+ WhoopsNotifier.notify({})
45
+ end
46
+ end
47
+
48
+ describe ".send_report" do
49
+ it "should send a report to the configured URL" do
50
+ FakeWeb.register_uri(:post, "http://whoops.com/events/", :body => "success")
51
+ WhoopsNotifier.notify({})
52
+ request = FakeWeb.last_request
53
+ request.body.should =~ /"event"/
54
+ end
11
55
  end
12
56
  end
@@ -5,11 +5,11 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{whoops_notifier}
8
- s.version = "0.0.1"
8
+ s.version = "0.0.2"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["Daniel Higginbotham"]
12
- s.date = %q{2011-06-03}
12
+ s.date = %q{2011-06-09}
13
13
  s.description = %q{Handles basic notification responsibilities and allows creation of report creation strategies}
14
14
  s.email = %q{daniel@flyingmachinestudios.com}
15
15
  s.extra_rdoc_files = [
@@ -35,6 +35,7 @@ Gem::Specification.new do |s|
35
35
  "spec/configuration_spec.rb",
36
36
  "spec/fixtures/whoops_notifier.yml",
37
37
  "spec/investigator_spec.rb",
38
+ "spec/sender_spec.rb",
38
39
  "spec/spec_helper.rb",
39
40
  "spec/strategy_spec.rb",
40
41
  "spec/whoops_notifier_spec.rb",
@@ -48,6 +49,7 @@ Gem::Specification.new do |s|
48
49
  s.test_files = [
49
50
  "spec/configuration_spec.rb",
50
51
  "spec/investigator_spec.rb",
52
+ "spec/sender_spec.rb",
51
53
  "spec/spec_helper.rb",
52
54
  "spec/strategy_spec.rb",
53
55
  "spec/whoops_notifier_spec.rb"
@@ -59,26 +61,26 @@ Gem::Specification.new do |s|
59
61
 
60
62
  if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
61
63
  s.add_runtime_dependency(%q<json>, [">= 0"])
62
- s.add_development_dependency(%q<rspec>, ["~> 2.3.0"])
64
+ s.add_development_dependency(%q<rspec>, ["~> 2.6.0"])
63
65
  s.add_development_dependency(%q<bundler>, ["~> 1.0.0"])
64
66
  s.add_development_dependency(%q<jeweler>, ["~> 1.5.2"])
65
- s.add_development_dependency(%q<mocha>, [">= 0"])
66
67
  s.add_development_dependency(%q<ruby-debug>, [">= 0"])
68
+ s.add_development_dependency(%q<fakeweb>, [">= 0"])
67
69
  else
68
70
  s.add_dependency(%q<json>, [">= 0"])
69
- s.add_dependency(%q<rspec>, ["~> 2.3.0"])
71
+ s.add_dependency(%q<rspec>, ["~> 2.6.0"])
70
72
  s.add_dependency(%q<bundler>, ["~> 1.0.0"])
71
73
  s.add_dependency(%q<jeweler>, ["~> 1.5.2"])
72
- s.add_dependency(%q<mocha>, [">= 0"])
73
74
  s.add_dependency(%q<ruby-debug>, [">= 0"])
75
+ s.add_dependency(%q<fakeweb>, [">= 0"])
74
76
  end
75
77
  else
76
78
  s.add_dependency(%q<json>, [">= 0"])
77
- s.add_dependency(%q<rspec>, ["~> 2.3.0"])
79
+ s.add_dependency(%q<rspec>, ["~> 2.6.0"])
78
80
  s.add_dependency(%q<bundler>, ["~> 1.0.0"])
79
81
  s.add_dependency(%q<jeweler>, ["~> 1.5.2"])
80
- s.add_dependency(%q<mocha>, [">= 0"])
81
82
  s.add_dependency(%q<ruby-debug>, [">= 0"])
83
+ s.add_dependency(%q<fakeweb>, [">= 0"])
82
84
  end
83
85
  end
84
86
 
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: whoops_notifier
3
3
  version: !ruby/object:Gem::Version
4
- hash: 29
4
+ hash: 27
5
5
  prerelease: false
6
6
  segments:
7
7
  - 0
8
8
  - 0
9
- - 1
10
- version: 0.0.1
9
+ - 2
10
+ version: 0.0.2
11
11
  platform: ruby
12
12
  authors:
13
13
  - Daniel Higginbotham
@@ -15,7 +15,7 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2011-06-03 00:00:00 -04:00
18
+ date: 2011-06-09 00:00:00 -04:00
19
19
  default_executable:
20
20
  dependencies:
21
21
  - !ruby/object:Gem::Dependency
@@ -41,12 +41,12 @@ dependencies:
41
41
  requirements:
42
42
  - - ~>
43
43
  - !ruby/object:Gem::Version
44
- hash: 3
44
+ hash: 23
45
45
  segments:
46
46
  - 2
47
- - 3
47
+ - 6
48
48
  - 0
49
- version: 2.3.0
49
+ version: 2.6.0
50
50
  requirement: *id002
51
51
  - !ruby/object:Gem::Dependency
52
52
  prerelease: false
@@ -83,7 +83,7 @@ dependencies:
83
83
  - !ruby/object:Gem::Dependency
84
84
  prerelease: false
85
85
  type: :development
86
- name: mocha
86
+ name: ruby-debug
87
87
  version_requirements: &id005 !ruby/object:Gem::Requirement
88
88
  none: false
89
89
  requirements:
@@ -97,7 +97,7 @@ dependencies:
97
97
  - !ruby/object:Gem::Dependency
98
98
  prerelease: false
99
99
  type: :development
100
- name: ruby-debug
100
+ name: fakeweb
101
101
  version_requirements: &id006 !ruby/object:Gem::Requirement
102
102
  none: false
103
103
  requirements:
@@ -136,6 +136,7 @@ files:
136
136
  - spec/configuration_spec.rb
137
137
  - spec/fixtures/whoops_notifier.yml
138
138
  - spec/investigator_spec.rb
139
+ - spec/sender_spec.rb
139
140
  - spec/spec_helper.rb
140
141
  - spec/strategy_spec.rb
141
142
  - spec/whoops_notifier_spec.rb
@@ -177,6 +178,7 @@ summary: Handles basic notification responsibilities and allows creation of repo
177
178
  test_files:
178
179
  - spec/configuration_spec.rb
179
180
  - spec/investigator_spec.rb
181
+ - spec/sender_spec.rb
180
182
  - spec/spec_helper.rb
181
183
  - spec/strategy_spec.rb
182
184
  - spec/whoops_notifier_spec.rb