airbrake-ruby 4.0.1 → 4.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/airbrake-ruby.rb +7 -71
- data/lib/airbrake-ruby/config.rb +19 -22
- data/lib/airbrake-ruby/config/validator.rb +71 -43
- data/lib/airbrake-ruby/deploy_notifier.rb +4 -4
- data/lib/airbrake-ruby/notice_notifier.rb +3 -4
- data/lib/airbrake-ruby/performance_notifier.rb +4 -5
- data/lib/airbrake-ruby/promise.rb +30 -20
- data/lib/airbrake-ruby/version.rb +1 -1
- data/spec/airbrake_spec.rb +4 -4
- data/spec/backtrace_spec.rb +4 -4
- data/spec/config/validator_spec.rb +128 -133
- data/spec/config_spec.rb +72 -227
- data/spec/deploy_notifier_spec.rb +14 -3
- data/spec/filters/git_repository_filter.rb +6 -6
- data/spec/notice_notifier_spec.rb +11 -4
- data/spec/notice_notifier_spec/options_spec.rb +12 -12
- data/spec/notice_spec.rb +24 -24
- data/spec/performance_notifier_spec.rb +10 -1
- data/spec/promise_spec.rb +32 -0
- data/spec/spec_helper.rb +2 -0
- data/spec/sync_sender_spec.rb +4 -4
- data/spec/tdigest_spec.rb +2 -2
- data/spec/truncator_spec.rb +2 -2
- metadata +2 -2
@@ -1,13 +1,24 @@
|
|
1
1
|
RSpec.describe Airbrake::DeployNotifier do
|
2
|
-
before
|
2
|
+
before do
|
3
|
+
Airbrake::Config.instance = Airbrake::Config.new(project_id: 1, project_key: '123')
|
4
|
+
end
|
3
5
|
|
4
6
|
describe "#notify" do
|
5
7
|
it "returns a promise" do
|
6
|
-
stub_request(:post, 'https://api.airbrake.io/api/v4/projects/1/deploys')
|
7
|
-
to_return(status: 201, body: '{}')
|
8
|
+
stub_request(:post, 'https://api.airbrake.io/api/v4/projects/1/deploys')
|
9
|
+
.to_return(status: 201, body: '{}')
|
8
10
|
expect(subject.notify({})).to be_an(Airbrake::Promise)
|
9
11
|
end
|
10
12
|
|
13
|
+
context "when config is invalid" do
|
14
|
+
before { Airbrake::Config.instance.merge(project_id: nil) }
|
15
|
+
|
16
|
+
it "returns a rejected promise" do
|
17
|
+
promise = subject.notify({})
|
18
|
+
expect(promise).to be_rejected
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
11
22
|
context "when environment is configured" do
|
12
23
|
before { Airbrake::Config.instance.merge(environment: 'fooenv') }
|
13
24
|
|
@@ -7,20 +7,20 @@ RSpec.describe Airbrake::Filters::GitRepositoryFilter do
|
|
7
7
|
|
8
8
|
describe "#initialize" do
|
9
9
|
it "parses standard git version" do
|
10
|
-
allow_any_instance_of(Kernel)
|
11
|
-
to receive(:`).and_return('git version 2.18.0')
|
10
|
+
allow_any_instance_of(Kernel)
|
11
|
+
.to receive(:`).and_return('git version 2.18.0')
|
12
12
|
expect { subject }.not_to raise_error
|
13
13
|
end
|
14
14
|
|
15
15
|
it "parses release candidate git version" do
|
16
|
-
allow_any_instance_of(Kernel)
|
17
|
-
to receive(:`).and_return('git version 2.21.0-rc0')
|
16
|
+
allow_any_instance_of(Kernel)
|
17
|
+
.to receive(:`).and_return('git version 2.21.0-rc0')
|
18
18
|
expect { subject }.not_to raise_error
|
19
19
|
end
|
20
20
|
|
21
21
|
it "parses git version with brackets" do
|
22
|
-
allow_any_instance_of(Kernel)
|
23
|
-
to receive(:`).and_return('git version 2.17.2 (Apple Git-113)')
|
22
|
+
allow_any_instance_of(Kernel)
|
23
|
+
.to receive(:`).and_return('git version 2.17.2 (Apple Git-113)')
|
24
24
|
expect { subject }.not_to raise_error
|
25
25
|
end
|
26
26
|
end
|
@@ -1,4 +1,3 @@
|
|
1
|
-
# rubocop:disable Layout/DotPosition
|
2
1
|
RSpec.describe Airbrake::NoticeNotifier do
|
3
2
|
before do
|
4
3
|
Airbrake::Config.instance = Airbrake::Config.new(
|
@@ -108,6 +107,15 @@ RSpec.describe Airbrake::NoticeNotifier do
|
|
108
107
|
sleep 1
|
109
108
|
end
|
110
109
|
|
110
|
+
context "when config is invalid" do
|
111
|
+
before { Airbrake::Config.instance.merge(project_id: nil) }
|
112
|
+
|
113
|
+
it "returns a rejected promise" do
|
114
|
+
promise = subject.notify({})
|
115
|
+
expect(promise).to be_rejected
|
116
|
+
end
|
117
|
+
end
|
118
|
+
|
111
119
|
context "when a notice is not ignored" do
|
112
120
|
it "yields the notice" do
|
113
121
|
expect { |b| subject.notify('ex', &b) }
|
@@ -169,7 +177,7 @@ RSpec.describe Airbrake::NoticeNotifier do
|
|
169
177
|
|
170
178
|
it "returns a rejected promise" do
|
171
179
|
promise = subject.notify('foo', bingo: 'bango')
|
172
|
-
expect(promise.value).to eq('error' => "
|
180
|
+
expect(promise.value).to eq('error' => "current environment 'test' is ignored")
|
173
181
|
end
|
174
182
|
end
|
175
183
|
end
|
@@ -253,7 +261,7 @@ RSpec.describe Airbrake::NoticeNotifier do
|
|
253
261
|
|
254
262
|
it "returns an error hash" do
|
255
263
|
expect(subject.notify_sync('foo'))
|
256
|
-
.to eq('error' => "
|
264
|
+
.to eq('error' => "current environment 'test' is ignored")
|
257
265
|
end
|
258
266
|
end
|
259
267
|
end
|
@@ -406,4 +414,3 @@ RSpec.describe Airbrake::NoticeNotifier do
|
|
406
414
|
end
|
407
415
|
end
|
408
416
|
end
|
409
|
-
# rubocop:enable Layout/DotPosition
|
@@ -74,8 +74,8 @@ RSpec.describe Airbrake::NoticeNotifier do
|
|
74
74
|
subject.notify_sync(ex)
|
75
75
|
|
76
76
|
expect(
|
77
|
-
a_request(:post, endpoint)
|
78
|
-
with(body: %r|{"file":"/PROJECT_ROOT/airbrake/ruby/spec/airbrake_spec.+|)
|
77
|
+
a_request(:post, endpoint)
|
78
|
+
.with(body: %r|{"file":"/PROJECT_ROOT/airbrake/ruby/spec/airbrake_spec.+|)
|
79
79
|
).to have_been_made.once
|
80
80
|
end
|
81
81
|
|
@@ -86,8 +86,8 @@ RSpec.describe Airbrake::NoticeNotifier do
|
|
86
86
|
it "being included into the notice's payload" do
|
87
87
|
subject.notify_sync(ex)
|
88
88
|
expect(
|
89
|
-
a_request(:post, endpoint)
|
90
|
-
with(body: %r{"rootDirectory":"/bingo/bango"})
|
89
|
+
a_request(:post, endpoint)
|
90
|
+
.with(body: %r{"rootDirectory":"/bingo/bango"})
|
91
91
|
).to have_been_made.once
|
92
92
|
end
|
93
93
|
end
|
@@ -148,12 +148,12 @@ RSpec.describe Airbrake::NoticeNotifier do
|
|
148
148
|
|
149
149
|
proxied_request = requests.pop(true)
|
150
150
|
|
151
|
-
expect(proxied_request.header['proxy-authorization'].first)
|
152
|
-
to eq('Basic dXNlcjpwYXNzd29yZA==')
|
151
|
+
expect(proxied_request.header['proxy-authorization'].first)
|
152
|
+
.to eq('Basic dXNlcjpwYXNzd29yZA==')
|
153
153
|
|
154
154
|
# rubocop:disable Metrics/LineLength
|
155
|
-
expect(proxied_request.request_line)
|
156
|
-
to eq("POST http://localhost:#{proxy.config[:Port]}/api/v3/projects/105138/notices HTTP/1.1\r\n")
|
155
|
+
expect(proxied_request.request_line)
|
156
|
+
.to eq("POST http://localhost:#{proxy.config[:Port]}/api/v3/projects/105138/notices HTTP/1.1\r\n")
|
157
157
|
# rubocop:enable Metrics/LineLength
|
158
158
|
end
|
159
159
|
end
|
@@ -165,8 +165,8 @@ RSpec.describe Airbrake::NoticeNotifier do
|
|
165
165
|
it "being included into the notice's payload" do
|
166
166
|
subject.notify_sync(ex)
|
167
167
|
expect(
|
168
|
-
a_request(:post, endpoint)
|
169
|
-
with(body: /"context":{.*"environment":"production".*}/)
|
168
|
+
a_request(:post, endpoint)
|
169
|
+
.with(body: /"context":{.*"environment":"production".*}/)
|
170
170
|
).to have_been_made.once
|
171
171
|
end
|
172
172
|
end
|
@@ -210,8 +210,8 @@ RSpec.describe Airbrake::NoticeNotifier do
|
|
210
210
|
|
211
211
|
it "returns early and doesn't try to parse the given exception" do
|
212
212
|
expect(Airbrake::Notice).not_to receive(:new)
|
213
|
-
expect(subject.notify_sync(ex))
|
214
|
-
to eq('error' => "
|
213
|
+
expect(subject.notify_sync(ex))
|
214
|
+
.to eq('error' => "current environment 'development' is ignored")
|
215
215
|
expect(a_request(:post, endpoint)).not_to have_been_made
|
216
216
|
end
|
217
217
|
end
|
data/spec/notice_spec.rb
CHANGED
@@ -85,8 +85,8 @@ RSpec.describe Airbrake::Notice do
|
|
85
85
|
|
86
86
|
context "when truncation failed" do
|
87
87
|
it "returns nil" do
|
88
|
-
expect_any_instance_of(Airbrake::Truncator)
|
89
|
-
to receive(:reduce_max_size).and_return(0)
|
88
|
+
expect_any_instance_of(Airbrake::Truncator)
|
89
|
+
.to receive(:reduce_max_size).and_return(0)
|
90
90
|
|
91
91
|
encoded = Base64.encode64("\xD3\xE6\xBC\x9D\xBA").encode!('ASCII-8BIT')
|
92
92
|
bad_string = Base64.decode64(encoded)
|
@@ -118,8 +118,8 @@ RSpec.describe Airbrake::Notice do
|
|
118
118
|
let(:backtrace_size) { 1000 }
|
119
119
|
|
120
120
|
it "doesn't happen" do
|
121
|
-
expect(notice.to_json)
|
122
|
-
to match(/bingo":\["#<Object:.+>","#<#<Class:.+>:.+>"/)
|
121
|
+
expect(notice.to_json)
|
122
|
+
.to match(/bingo":\["#<Object:.+>","#<#<Class:.+>:.+>"/)
|
123
123
|
end
|
124
124
|
end
|
125
125
|
|
@@ -128,8 +128,8 @@ RSpec.describe Airbrake::Notice do
|
|
128
128
|
let(:backtrace_size) { 50_000 }
|
129
129
|
|
130
130
|
it "happens" do
|
131
|
-
expect(notice.to_json)
|
132
|
-
to match(/bingo":\[".+Object.+",".+Class.+"/)
|
131
|
+
expect(notice.to_json)
|
132
|
+
.to match(/bingo":\[".+Object.+",".+Class.+"/)
|
133
133
|
end
|
134
134
|
end
|
135
135
|
end
|
@@ -219,13 +219,13 @@ RSpec.describe Airbrake::Notice do
|
|
219
219
|
it "overwrites the 'notifier' payload with the default values" do
|
220
220
|
notice[:notifier] = { name: 'bingo', bango: 'bongo' }
|
221
221
|
|
222
|
-
expect(notice.to_json)
|
223
|
-
to match(/"notifier":{"name":"airbrake-ruby","version":".+","url":".+"}/)
|
222
|
+
expect(notice.to_json)
|
223
|
+
.to match(/"notifier":{"name":"airbrake-ruby","version":".+","url":".+"}/)
|
224
224
|
end
|
225
225
|
|
226
226
|
it "always contains context/hostname" do
|
227
|
-
expect(notice.to_json)
|
228
|
-
to match(/"context":{.*"hostname":".+".*}/)
|
227
|
+
expect(notice.to_json)
|
228
|
+
.to match(/"context":{.*"hostname":".+".*}/)
|
229
229
|
end
|
230
230
|
|
231
231
|
it "defaults to the error severity" do
|
@@ -233,18 +233,18 @@ RSpec.describe Airbrake::Notice do
|
|
233
233
|
end
|
234
234
|
|
235
235
|
it "always contains environment/program_name" do
|
236
|
-
expect(notice.to_json)
|
237
|
-
to match(%r|"environment":{"program_name":.+/rspec.*|)
|
236
|
+
expect(notice.to_json)
|
237
|
+
.to match(%r|"environment":{"program_name":.+/rspec.*|)
|
238
238
|
end
|
239
239
|
|
240
240
|
it "contains errors" do
|
241
|
-
expect(notice.to_json)
|
242
|
-
to match(/"errors":\[{"type":"AirbrakeTestError","message":"App crash/)
|
241
|
+
expect(notice.to_json)
|
242
|
+
.to match(/"errors":\[{"type":"AirbrakeTestError","message":"App crash/)
|
243
243
|
end
|
244
244
|
|
245
245
|
it "contains a backtrace" do
|
246
|
-
expect(notice.to_json)
|
247
|
-
to match(%r|"backtrace":\[{"file":"/home/.+/spec/spec_helper.rb"|)
|
246
|
+
expect(notice.to_json)
|
247
|
+
.to match(%r|"backtrace":\[{"file":"/home/.+/spec/spec_helper.rb"|)
|
248
248
|
end
|
249
249
|
|
250
250
|
it "contains params" do
|
@@ -259,8 +259,8 @@ RSpec.describe Airbrake::Notice do
|
|
259
259
|
|
260
260
|
it "raises error if notice is ignored" do
|
261
261
|
notice.ignore!
|
262
|
-
expect { notice[:params] }
|
263
|
-
to raise_error(Airbrake::Error, 'cannot access ignored Airbrake::Notice')
|
262
|
+
expect { notice[:params] }
|
263
|
+
.to raise_error(Airbrake::Error, 'cannot access ignored Airbrake::Notice')
|
264
264
|
end
|
265
265
|
end
|
266
266
|
|
@@ -273,18 +273,18 @@ RSpec.describe Airbrake::Notice do
|
|
273
273
|
|
274
274
|
it "raises error if notice is ignored" do
|
275
275
|
notice.ignore!
|
276
|
-
expect { notice[:params] = {} }
|
277
|
-
to raise_error(Airbrake::Error, 'cannot access ignored Airbrake::Notice')
|
276
|
+
expect { notice[:params] = {} }
|
277
|
+
.to raise_error(Airbrake::Error, 'cannot access ignored Airbrake::Notice')
|
278
278
|
end
|
279
279
|
|
280
280
|
it "raises error when trying to assign unrecognized key" do
|
281
|
-
expect { notice[:bingo] = 1 }
|
282
|
-
to raise_error(Airbrake::Error, /:bingo is not recognized among/)
|
281
|
+
expect { notice[:bingo] = 1 }
|
282
|
+
.to raise_error(Airbrake::Error, /:bingo is not recognized among/)
|
283
283
|
end
|
284
284
|
|
285
285
|
it "raises when setting non-hash objects as the value" do
|
286
|
-
expect { notice[:params] = Object.new }
|
287
|
-
to raise_error(Airbrake::Error, 'Got Object value, wanted a Hash')
|
286
|
+
expect { notice[:params] = Object.new }
|
287
|
+
.to raise_error(Airbrake::Error, 'Got Object value, wanted a Hash')
|
288
288
|
end
|
289
289
|
end
|
290
290
|
|
@@ -217,7 +217,7 @@ RSpec.describe Airbrake::PerformanceNotifier do
|
|
217
217
|
)
|
218
218
|
|
219
219
|
expect(a_request(:put, routes)).not_to have_been_made
|
220
|
-
expect(promise.value).to eq('error' => "
|
220
|
+
expect(promise.value).to eq('error' => "current environment 'test' is ignored")
|
221
221
|
end
|
222
222
|
|
223
223
|
it "sends environment when it's specified" do
|
@@ -238,6 +238,15 @@ RSpec.describe Airbrake::PerformanceNotifier do
|
|
238
238
|
).to have_been_made
|
239
239
|
end
|
240
240
|
|
241
|
+
context "when config is invalid" do
|
242
|
+
before { Airbrake::Config.instance.merge(project_id: nil) }
|
243
|
+
|
244
|
+
it "returns a rejected promise" do
|
245
|
+
promise = subject.notify({})
|
246
|
+
expect(promise).to be_rejected
|
247
|
+
end
|
248
|
+
end
|
249
|
+
|
241
250
|
describe "payload grouping" do
|
242
251
|
let(:flush_period) { 0.5 }
|
243
252
|
|
data/spec/promise_spec.rb
CHANGED
@@ -162,4 +162,36 @@ RSpec.describe Airbrake::Promise do
|
|
162
162
|
expect(array).to match_array([999])
|
163
163
|
end
|
164
164
|
end
|
165
|
+
|
166
|
+
describe "#rejected?" do
|
167
|
+
context "when it was rejected" do
|
168
|
+
before { subject.reject(1) }
|
169
|
+
it { is_expected.to be_rejected }
|
170
|
+
end
|
171
|
+
|
172
|
+
context "when it wasn't rejected" do
|
173
|
+
it { is_expected.not_to be_rejected }
|
174
|
+
end
|
175
|
+
|
176
|
+
context "when it was resolved" do
|
177
|
+
before { subject.resolve }
|
178
|
+
it { is_expected.not_to be_rejected }
|
179
|
+
end
|
180
|
+
end
|
181
|
+
|
182
|
+
describe "#resolved?" do
|
183
|
+
context "when it was resolved" do
|
184
|
+
before { subject.resolve }
|
185
|
+
it { is_expected.to be_resolved }
|
186
|
+
end
|
187
|
+
|
188
|
+
context "when it wasn't resolved" do
|
189
|
+
it { is_expected.not_to be_resolved }
|
190
|
+
end
|
191
|
+
|
192
|
+
context "when it was rejected" do
|
193
|
+
before { subject.reject(1) }
|
194
|
+
it { is_expected.not_to be_resolved }
|
195
|
+
end
|
196
|
+
end
|
165
197
|
end
|
data/spec/spec_helper.rb
CHANGED
data/spec/sync_sender_spec.rb
CHANGED
@@ -55,8 +55,8 @@ RSpec.describe Airbrake::SyncSender do
|
|
55
55
|
|
56
56
|
context "when request body is nil" do
|
57
57
|
it "doesn't send data" do
|
58
|
-
expect_any_instance_of(Airbrake::Truncator)
|
59
|
-
to receive(:reduce_max_size).and_return(0)
|
58
|
+
expect_any_instance_of(Airbrake::Truncator)
|
59
|
+
.to receive(:reduce_max_size).and_return(0)
|
60
60
|
|
61
61
|
encoded = Base64.encode64("\xD3\xE6\xBC\x9D\xBA").encode!('ASCII-8BIT')
|
62
62
|
bad_string = Base64.decode64(encoded)
|
@@ -75,8 +75,8 @@ RSpec.describe Airbrake::SyncSender do
|
|
75
75
|
/truncation failed/
|
76
76
|
)
|
77
77
|
expect(subject.send(notice, promise)).to be_an(Airbrake::Promise)
|
78
|
-
expect(promise.value)
|
79
|
-
to match('error' => '**Airbrake: data was not sent because of missing body')
|
78
|
+
expect(promise.value)
|
79
|
+
.to match('error' => '**Airbrake: data was not sent because of missing body')
|
80
80
|
end
|
81
81
|
end
|
82
82
|
|
data/spec/tdigest_spec.rb
CHANGED
@@ -178,8 +178,8 @@ RSpec.describe Airbrake::TDigest do
|
|
178
178
|
|
179
179
|
it "returns a tdigest with less than or equal centroids" do
|
180
180
|
new_tdigest = subject + @other
|
181
|
-
expect(new_tdigest.centroids.size)
|
182
|
-
to be <= subject.centroids.size + @other.centroids.size
|
181
|
+
expect(new_tdigest.centroids.size)
|
182
|
+
.to be <= subject.centroids.size + @other.centroids.size
|
183
183
|
end
|
184
184
|
|
185
185
|
it "has the size of the two digests combined" do
|
data/spec/truncator_spec.rb
CHANGED
@@ -104,8 +104,8 @@ RSpec.describe Airbrake::Truncator do
|
|
104
104
|
context "given an arbitrary object that doesn't respond to #to_json" do
|
105
105
|
let(:object) do
|
106
106
|
obj = Object.new
|
107
|
-
allow(obj).to receive(:to_json)
|
108
|
-
and_raise(Airbrake::Notice::JSON_EXCEPTIONS.first)
|
107
|
+
allow(obj).to receive(:to_json)
|
108
|
+
.and_raise(Airbrake::Notice::JSON_EXCEPTIONS.first)
|
109
109
|
obj
|
110
110
|
end
|
111
111
|
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: airbrake-ruby
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 4.0
|
4
|
+
version: 4.1.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Airbrake Technologies, Inc.
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2019-02-
|
11
|
+
date: 2019-02-28 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rbtree3
|