exceptions_to_slack 1.0.0 → 1.1.0

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: 18cbcfb3bda1a6a6032b8eed4782a3b5a321c1a7
4
- data.tar.gz: eb275434209fe2a26010e8b97d5f6776295cd951
3
+ metadata.gz: e1041c85765abefc1378bcd1474ce18c48d487f3
4
+ data.tar.gz: 1d982c665a395c011f0c2a83770b3da45ce1cac5
5
5
  SHA512:
6
- metadata.gz: e4bd13f1154dcf3c13365f81fe56c1b9419244f465224fd50c74f9125c7d12b17cd008ae2ddfac21d1cc8826d815d9584901cd87d866c40bc464052a3cd23393
7
- data.tar.gz: 11465da40b9527a066b9853493d069fbd7e4651e1f44e5dc7ec09e58ba4f71bc3f9a7b459df8242404ae5342fc204e0c6df7bab5e080597ca4b8e166d18cd67d
6
+ metadata.gz: f21b0a3358b1d1a67f5fb162c6bbd04bb899bf96e6da6499483084000e03c842569a5a5efa852bb67b81373ae850169337451d26ea6687de615740ca8b597033
7
+ data.tar.gz: b72aaa2ac06cf42701b28933267490ccbba023f1fce26d8abef0982fe9fd462e6622f8d57e60cf56b8183263393650ef0940f202b08e4aa1040ea8a16361eab0
data/README.md CHANGED
@@ -12,9 +12,13 @@ Add this line to your application's Gemfile:
12
12
 
13
13
  Rails 3: add as rack middleware to `application.rb'
14
14
 
15
- config.middleware.use ExceptionsToSlack::Notifier,
16
- :team => "YOUR TEAM",
17
- :token => "YOUR TOKEN",
18
- :channel => "YOUR CHANNEL",
19
- :user => "USER MESSAGE WILL COME FROM"
15
+ ```ruby
16
+ config.middleware.use ExceptionsToSlack::Notifier,
17
+ team: 'your-team-name', # required
18
+ token: 'your-api-token', # required, https://my.slack.com/services/new/incoming-webhook
19
+ channel: '#general', # required
20
+ user: 'Exception Notifier', # optional, defaults to Notifier
21
+ ignore: /Foo/, # optional pattern for exceptions not to be sent
22
+ additional_parameters: {icon_emoji: ':ghost:'} # optional parameters to send to slack
23
+ ```
20
24
 
data/Rakefile CHANGED
@@ -1,7 +1,8 @@
1
1
  require 'bundler/gem_tasks'
2
- require 'rspec/core/rake_task'
3
2
 
4
- RSpec::Core::RakeTask.new(:spec)
3
+ task :test do
4
+ Dir.glob('./test/**/*_test.rb').each {|file| require file}
5
+ end
5
6
 
6
- task :default => :spec
7
+ task :default => :test
7
8
 
@@ -15,5 +15,5 @@ Gem::Specification.new do |gem|
15
15
  gem.version = ExceptionsToSlack::VERSION
16
16
 
17
17
  gem.add_dependency("slack-notifier", "~> 0.5.0")
18
- gem.add_development_dependency("rspec", "~> 2.14.1")
18
+ gem.add_development_dependency("webmock", "~> 1.18.0")
19
19
  end
@@ -8,6 +8,7 @@ module ExceptionsToSlack
8
8
  @notifier.channel = options[:channel] || raise("Channel is required")
9
9
  @notifier.username = options[:user] || "Notifier"
10
10
  @ignore = options[:ignore]
11
+ @additional_parameters = options[:additional_parameters] || {}
11
12
  end
12
13
 
13
14
  def call(env)
@@ -17,20 +18,16 @@ module ExceptionsToSlack
17
18
  raise exception
18
19
  end
19
20
 
21
+ private
22
+
20
23
  def send_to_slack(exception)
21
24
  begin
22
- @notifier.ping message_for(exception)
25
+ @notifier.ping message_for(exception), @additional_parameters.merge({attachments: [attachment_for(exception)]})
23
26
  rescue => slack_exception
24
27
  $stderr.puts "\nWARN: Unable to send message to Slack: #{slack_exception}\n"
25
28
  end
26
29
  end
27
30
 
28
- def message_for(exception)
29
- "[#{exception.class}] #{exception}"
30
- end
31
-
32
- private
33
-
34
31
  def team(options)
35
32
  options[:team] || raise("Team name is required")
36
33
  end
@@ -38,6 +35,18 @@ module ExceptionsToSlack
38
35
  def token(options)
39
36
  options[:token] || raise("Token is required")
40
37
  end
38
+
39
+ def message_for(exception)
40
+ "[#{exception.class}] #{exception}"
41
+ end
42
+
43
+ def attachment_for(exception)
44
+ {
45
+ fallback: 'Stack trace',
46
+ color: 'warning',
47
+ text: exception.backtrace.join("\n")
48
+ }
49
+ end
41
50
  end
42
51
  end
43
52
 
@@ -1,3 +1,3 @@
1
1
  module ExceptionsToSlack
2
- VERSION = "1.0.0"
2
+ VERSION = '1.1.0'
3
3
  end
@@ -1,2 +1,2 @@
1
- require "exceptions_to_slack/version"
2
- require "exceptions_to_slack/notifier"
1
+ require 'exceptions_to_slack/version'
2
+ require 'exceptions_to_slack/notifier'
@@ -0,0 +1,47 @@
1
+ require_relative '../test_helper'
2
+
3
+ class TestNotifier < MiniTest::Unit::TestCase
4
+ TEAM = 'the-team'
5
+ TOKEN = 'the-token'
6
+ CHANNEL = 'the-channel'
7
+
8
+ def setup
9
+ @app = MiniTest::Mock.new
10
+
11
+ @notifier = ExceptionsToSlack::Notifier.new(@app, {
12
+ team: TEAM,
13
+ token: TOKEN,
14
+ channel: CHANNEL,
15
+ ignore: /ignored/
16
+ })
17
+ end
18
+
19
+ def test_exceptions_are_sent_to_slack
20
+ def @app.call(env) raise ':boom:' end
21
+
22
+ WebMock.stub_request(:post, 'https://the-team.slack.com/services/hooks/incoming-webhook?token=the-token').with do |request|
23
+ form = URI.decode_www_form(request.body)
24
+
25
+ assert_equal 1, form.size
26
+ assert_equal 2, form[0].size
27
+ assert_equal 'payload', form[0][0]
28
+
29
+ payload = JSON.parse(form[0][1])
30
+ assert_equal '[RuntimeError] :boom:', payload['text']
31
+ assert_equal CHANNEL, payload['channel']
32
+ assert_equal 'Notifier', payload['username']
33
+ assert !payload['attachments'][0]['text'].empty?
34
+
35
+ true
36
+ end
37
+
38
+ -> {@notifier.call([])}.must_raise RuntimeError
39
+ end
40
+
41
+ def test_exceptions_that_are_ignored
42
+ def @app.call(env) raise 'should be ignored if raised' end
43
+ # WebMock will raise if we try to send something to slack
44
+
45
+ -> {@notifier.call([])}.must_raise RuntimeError
46
+ end
47
+ end
@@ -0,0 +1,5 @@
1
+ require 'exceptions_to_slack'
2
+
3
+ require 'minitest/autorun'
4
+ require 'minitest/mock'
5
+ require 'webmock/test_unit'
metadata CHANGED
@@ -1,43 +1,43 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: exceptions_to_slack
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.0
4
+ version: 1.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Darrin Holst
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-05-15 00:00:00.000000000 Z
11
+ date: 2014-06-06 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: slack-notifier
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
- - - "~>"
17
+ - - ~>
18
18
  - !ruby/object:Gem::Version
19
19
  version: 0.5.0
20
20
  type: :runtime
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
- - - "~>"
24
+ - - ~>
25
25
  - !ruby/object:Gem::Version
26
26
  version: 0.5.0
27
27
  - !ruby/object:Gem::Dependency
28
- name: rspec
28
+ name: webmock
29
29
  requirement: !ruby/object:Gem::Requirement
30
30
  requirements:
31
- - - "~>"
31
+ - - ~>
32
32
  - !ruby/object:Gem::Version
33
- version: 2.14.1
33
+ version: 1.18.0
34
34
  type: :development
35
35
  prerelease: false
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
38
- - - "~>"
38
+ - - ~>
39
39
  - !ruby/object:Gem::Version
40
- version: 2.14.1
40
+ version: 1.18.0
41
41
  description:
42
42
  email:
43
43
  - darrinholst@gmail.com
@@ -45,7 +45,7 @@ executables: []
45
45
  extensions: []
46
46
  extra_rdoc_files: []
47
47
  files:
48
- - ".gitignore"
48
+ - .gitignore
49
49
  - Gemfile
50
50
  - LICENSE
51
51
  - README.md
@@ -54,6 +54,8 @@ files:
54
54
  - lib/exceptions_to_slack.rb
55
55
  - lib/exceptions_to_slack/notifier.rb
56
56
  - lib/exceptions_to_slack/version.rb
57
+ - test/exceptions_to_slack/notifier_test.rb
58
+ - test/test_helper.rb
57
59
  homepage: http://github.com/darrinholst/exceptions_to_slack
58
60
  licenses: []
59
61
  metadata: {}
@@ -63,12 +65,12 @@ require_paths:
63
65
  - lib
64
66
  required_ruby_version: !ruby/object:Gem::Requirement
65
67
  requirements:
66
- - - ">="
68
+ - - '>='
67
69
  - !ruby/object:Gem::Version
68
70
  version: '0'
69
71
  required_rubygems_version: !ruby/object:Gem::Requirement
70
72
  requirements:
71
- - - ">="
73
+ - - '>='
72
74
  - !ruby/object:Gem::Version
73
75
  version: '0'
74
76
  requirements: []
@@ -77,4 +79,6 @@ rubygems_version: 2.2.2
77
79
  signing_key:
78
80
  specification_version: 4
79
81
  summary: Send rails exceptions to Slack
80
- test_files: []
82
+ test_files:
83
+ - test/exceptions_to_slack/notifier_test.rb
84
+ - test/test_helper.rb