exception_notification-ikachan 0.1.0 → 0.1.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: d6b7bf509704cee5b7374e4a87570dfb12956ccc
|
4
|
+
data.tar.gz: 60b3b2cd16bf6e7c9b3f0ea42e8598fcc69c44ad
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 7c103dbb780ae535b67112d45986c85098fb9293185682567bff81c927d77980ff9fc12939d655efb2865abc297c96565239d1780de2b92cb28b3f1349b514eb
|
7
|
+
data.tar.gz: 95bf030d7fcb49993681ec0984e0544ff26483ff2e2e6e98c323ea07424b4445befdbb78d43c90d797a323578541f71736aa0d53104b0201d129804f324af287
|
@@ -12,7 +12,9 @@ module ExceptionNotifier
|
|
12
12
|
def notice_all(channels, message)
|
13
13
|
channels.each do |channel|
|
14
14
|
join(channel)
|
15
|
-
|
15
|
+
message.each_line do |line|
|
16
|
+
notice(channel, line)
|
17
|
+
end
|
16
18
|
end
|
17
19
|
end
|
18
20
|
|
@@ -62,7 +64,7 @@ module ExceptionNotifier
|
|
62
64
|
message: exception.message,
|
63
65
|
occurred: (exception.backtrace.first rescue nil),
|
64
66
|
}
|
65
|
-
params.merge!(build_params_from_request(options[:env]))
|
67
|
+
params.merge!(build_params_from_request(options[:env]))
|
66
68
|
@message = message_format % params
|
67
69
|
end
|
68
70
|
|
@@ -87,7 +89,8 @@ module ExceptionNotifier
|
|
87
89
|
end
|
88
90
|
end
|
89
91
|
|
90
|
-
def build_params_from_request(env)
|
92
|
+
def build_params_from_request(env=nil)
|
93
|
+
return default_params_from_request unless env
|
91
94
|
request = request_klass.new(env)
|
92
95
|
dest = {}
|
93
96
|
@request_param_names.map{|n| [n, n.sub(/^request_/, '')] }.each do |param_name, attribute|
|
@@ -96,6 +99,12 @@ module ExceptionNotifier
|
|
96
99
|
dest
|
97
100
|
end
|
98
101
|
|
102
|
+
def default_params_from_request
|
103
|
+
@request_param_names.each_with_object({}) do |name, dest|
|
104
|
+
dest[name.to_sym] = ''
|
105
|
+
end
|
106
|
+
end
|
107
|
+
|
99
108
|
# alias
|
100
109
|
VERSION = ExceptionNotification::Ikachan::VERSION
|
101
110
|
end
|
@@ -59,6 +59,13 @@ describe ExceptionNotifier::IkachanNotifier do
|
|
59
59
|
notifier.build_message(exception, {env: {'PATH_INFO' => '/foo/bar'}})
|
60
60
|
expect(notifier.message).to eq("/foo/bar")
|
61
61
|
end
|
62
|
+
|
63
|
+
it "should not raise error without env" do
|
64
|
+
expect {
|
65
|
+
notifier.build_message(exception)
|
66
|
+
}.not_to raise_error
|
67
|
+
expect(notifier.message).to eq("")
|
68
|
+
end
|
62
69
|
end
|
63
70
|
|
64
71
|
describe "message with more request info" do
|
@@ -122,20 +129,42 @@ describe ExceptionNotifier::IkachanNotifier do
|
|
122
129
|
{
|
123
130
|
base_url: 'ikachan.udzura.jp',
|
124
131
|
channel: '#udzura',
|
125
|
-
message_format:
|
132
|
+
message_format: message_format
|
126
133
|
}
|
127
134
|
end
|
128
135
|
let(:exception) { StandardError.new("Hello, exception!")}
|
129
136
|
|
130
|
-
|
131
|
-
|
132
|
-
|
133
|
-
|
134
|
-
|
137
|
+
describe 'single line' do
|
138
|
+
let(:message_format){ '%{class}: %{message}' }
|
139
|
+
|
140
|
+
it "should notice message to ikachan" do
|
141
|
+
stub_join = stub_request(:post, "http://ikachan.udzura.jp/join").
|
142
|
+
with(body: {"channel" => "#udzura"})
|
143
|
+
stub_notice = stub_request(:post, "http://ikachan.udzura.jp/notice").
|
144
|
+
with(body: {"channel" => "#udzura", "message" => "StandardError: Hello, exception!"})
|
135
145
|
|
136
|
-
|
137
|
-
|
138
|
-
|
146
|
+
notifier.call(exception, {})
|
147
|
+
stub_join.should have_been_requested.once
|
148
|
+
stub_notice.should have_been_requested.once
|
149
|
+
end
|
150
|
+
end
|
151
|
+
|
152
|
+
describe 'multiple line' do
|
153
|
+
let(:message_format){ <<-EOFormat }
|
154
|
+
%{class}
|
155
|
+
%{message}
|
156
|
+
extra info
|
157
|
+
EOFormat
|
158
|
+
it "should notice message to ikachan" do
|
159
|
+
stub_join = stub_request(:post, "http://ikachan.udzura.jp/join").
|
160
|
+
with(body: {"channel" => "#udzura"})
|
161
|
+
stub_notice = stub_request(:post, "http://ikachan.udzura.jp/notice").
|
162
|
+
with(body: {"channel" => "#udzura", "message" => an_instance_of(String)})
|
163
|
+
|
164
|
+
notifier.call(exception, {})
|
165
|
+
stub_join.should have_been_requested.once
|
166
|
+
stub_notice.should have_been_requested.times(3)
|
167
|
+
end
|
139
168
|
end
|
140
169
|
end
|
141
170
|
end
|