airbrake-ruby 5.2.0-java → 6.0.2-java

Sign up to get free protection for your applications and to get access to all the features.
Files changed (72) hide show
  1. checksums.yaml +4 -4
  2. data/lib/airbrake-ruby/async_sender.rb +3 -1
  3. data/lib/airbrake-ruby/config.rb +3 -3
  4. data/lib/airbrake-ruby/context.rb +51 -0
  5. data/lib/airbrake-ruby/filter_chain.rb +2 -0
  6. data/lib/airbrake-ruby/filters/context_filter.rb +4 -5
  7. data/lib/airbrake-ruby/filters/exception_attributes_filter.rb +1 -1
  8. data/lib/airbrake-ruby/filters/git_last_checkout_filter.rb +2 -2
  9. data/lib/airbrake-ruby/filters/git_repository_filter.rb +1 -1
  10. data/lib/airbrake-ruby/filters/git_revision_filter.rb +1 -1
  11. data/lib/airbrake-ruby/filters/keys_filter.rb +2 -2
  12. data/lib/airbrake-ruby/filters/sql_filter.rb +8 -8
  13. data/lib/airbrake-ruby/filters/thread_filter.rb +1 -1
  14. data/lib/airbrake-ruby/ignorable.rb +0 -2
  15. data/lib/airbrake-ruby/monotonic_time.rb +1 -1
  16. data/lib/airbrake-ruby/notice_notifier.rb +3 -4
  17. data/lib/airbrake-ruby/performance_notifier.rb +39 -40
  18. data/lib/airbrake-ruby/remote_settings/settings_data.rb +1 -1
  19. data/lib/airbrake-ruby/remote_settings.rb +26 -3
  20. data/lib/airbrake-ruby/stat.rb +1 -1
  21. data/lib/airbrake-ruby/tdigest.rb +10 -9
  22. data/lib/airbrake-ruby/thread_pool.rb +8 -6
  23. data/lib/airbrake-ruby/time_truncate.rb +2 -2
  24. data/lib/airbrake-ruby/timed_trace.rb +1 -3
  25. data/lib/airbrake-ruby/version.rb +1 -1
  26. data/lib/airbrake-ruby.rb +24 -23
  27. data/spec/airbrake_spec.rb +139 -76
  28. data/spec/async_sender_spec.rb +10 -8
  29. data/spec/backtrace_spec.rb +13 -10
  30. data/spec/benchmark_spec.rb +5 -3
  31. data/spec/code_hunk_spec.rb +24 -15
  32. data/spec/config/processor_spec.rb +12 -4
  33. data/spec/config/validator_spec.rb +5 -2
  34. data/spec/config_spec.rb +28 -20
  35. data/spec/context_spec.rb +54 -0
  36. data/spec/deploy_notifier_spec.rb +6 -4
  37. data/spec/file_cache_spec.rb +1 -0
  38. data/spec/filter_chain_spec.rb +29 -24
  39. data/spec/filters/context_filter_spec.rb +14 -5
  40. data/spec/filters/dependency_filter_spec.rb +3 -1
  41. data/spec/filters/exception_attributes_filter_spec.rb +5 -3
  42. data/spec/filters/gem_root_filter_spec.rb +5 -2
  43. data/spec/filters/git_last_checkout_filter_spec.rb +10 -12
  44. data/spec/filters/git_repository_filter.rb +9 -9
  45. data/spec/filters/git_revision_filter_spec.rb +20 -20
  46. data/spec/filters/keys_allowlist_spec.rb +25 -16
  47. data/spec/filters/keys_blocklist_spec.rb +25 -18
  48. data/spec/filters/root_directory_filter_spec.rb +3 -3
  49. data/spec/filters/sql_filter_spec.rb +26 -26
  50. data/spec/filters/system_exit_filter_spec.rb +4 -2
  51. data/spec/filters/thread_filter_spec.rb +15 -13
  52. data/spec/loggable_spec.rb +2 -2
  53. data/spec/monotonic_time_spec.rb +8 -6
  54. data/spec/nested_exception_spec.rb +46 -46
  55. data/spec/notice_notifier/options_spec.rb +23 -13
  56. data/spec/notice_notifier_spec.rb +52 -47
  57. data/spec/notice_spec.rb +6 -2
  58. data/spec/performance_notifier_spec.rb +69 -62
  59. data/spec/promise_spec.rb +38 -32
  60. data/spec/remote_settings/callback_spec.rb +27 -8
  61. data/spec/remote_settings/settings_data_spec.rb +4 -4
  62. data/spec/remote_settings_spec.rb +23 -9
  63. data/spec/response_spec.rb +34 -12
  64. data/spec/stashable_spec.rb +5 -5
  65. data/spec/stat_spec.rb +7 -5
  66. data/spec/sync_sender_spec.rb +49 -16
  67. data/spec/tdigest_spec.rb +60 -55
  68. data/spec/thread_pool_spec.rb +65 -56
  69. data/spec/time_truncate_spec.rb +23 -6
  70. data/spec/timed_trace_spec.rb +32 -30
  71. data/spec/truncator_spec.rb +72 -43
  72. metadata +54 -50
@@ -1,4 +1,6 @@
1
1
  RSpec.describe Airbrake::PerformanceNotifier do
2
+ subject(:perf_notifier) { described_class.new }
3
+
2
4
  let(:routes) { 'https://api.airbrake.io/api/v5/projects/1/routes-stats' }
3
5
  let(:queries) { 'https://api.airbrake.io/api/v5/projects/1/queries-stats' }
4
6
  let(:breakdowns) { 'https://api.airbrake.io/api/v5/projects/1/routes-breakdowns' }
@@ -22,7 +24,7 @@ RSpec.describe Airbrake::PerformanceNotifier do
22
24
 
23
25
  describe "#notify" do
24
26
  it "sends full query" do
25
- subject.notify(
27
+ perf_notifier.notify(
26
28
  Airbrake::Query.new(
27
29
  method: 'POST',
28
30
  route: '/foo',
@@ -34,7 +36,7 @@ RSpec.describe Airbrake::PerformanceNotifier do
34
36
  time: Time.new(2018, 1, 1, 0, 49, 0, 0),
35
37
  ),
36
38
  )
37
- subject.close
39
+ perf_notifier.close
38
40
 
39
41
  expect(
40
42
  a_request(:put, queries).with(body: %r|
@@ -55,7 +57,7 @@ RSpec.describe Airbrake::PerformanceNotifier do
55
57
  end
56
58
 
57
59
  it "sends full request" do
58
- subject.notify(
60
+ perf_notifier.notify(
59
61
  Airbrake::Request.new(
60
62
  method: 'POST',
61
63
  route: '/foo',
@@ -64,7 +66,7 @@ RSpec.describe Airbrake::PerformanceNotifier do
64
66
  time: Time.new(2018, 1, 1, 0, 49, 0, 0),
65
67
  ),
66
68
  )
67
- subject.close
69
+ perf_notifier.close
68
70
 
69
71
  expect(
70
72
  a_request(:put, routes).with(body: %r|
@@ -82,7 +84,7 @@ RSpec.describe Airbrake::PerformanceNotifier do
82
84
  end
83
85
 
84
86
  it "sends full performance breakdown" do
85
- subject.notify(
87
+ perf_notifier.notify(
86
88
  Airbrake::PerformanceBreakdown.new(
87
89
  method: 'DELETE',
88
90
  route: '/routes-breakdowns',
@@ -92,7 +94,7 @@ RSpec.describe Airbrake::PerformanceNotifier do
92
94
  groups: { db: 131, view: 421 },
93
95
  ),
94
96
  )
95
- subject.close
97
+ perf_notifier.close
96
98
 
97
99
  expect(
98
100
  a_request(:put, breakdowns).with(body: %r|
@@ -124,7 +126,7 @@ RSpec.describe Airbrake::PerformanceNotifier do
124
126
  end
125
127
 
126
128
  it "sends full queue" do
127
- subject.notify(
129
+ perf_notifier.notify(
128
130
  Airbrake::Queue.new(
129
131
  queue: 'emails',
130
132
  error_count: 2,
@@ -133,7 +135,7 @@ RSpec.describe Airbrake::PerformanceNotifier do
133
135
  time: Time.new(2018, 1, 1, 0, 49, 0, 0),
134
136
  ),
135
137
  )
136
- subject.close
138
+ perf_notifier.close
137
139
 
138
140
  expect(
139
141
  a_request(:put, queues).with(body: /
@@ -164,7 +166,7 @@ RSpec.describe Airbrake::PerformanceNotifier do
164
166
  end
165
167
 
166
168
  it "rounds time to the floor minute" do
167
- subject.notify(
169
+ perf_notifier.notify(
168
170
  Airbrake::Request.new(
169
171
  method: 'GET',
170
172
  route: '/foo',
@@ -173,7 +175,7 @@ RSpec.describe Airbrake::PerformanceNotifier do
173
175
  time: Time.new(2018, 1, 1, 0, 0, 20, 0),
174
176
  ),
175
177
  )
176
- subject.close
178
+ perf_notifier.close
177
179
 
178
180
  expect(
179
181
  a_request(:put, routes).with(body: /"time":"2018-01-01T00:00:00\+00:00"/),
@@ -181,7 +183,7 @@ RSpec.describe Airbrake::PerformanceNotifier do
181
183
  end
182
184
 
183
185
  it "increments routes with the same key" do
184
- subject.notify(
186
+ perf_notifier.notify(
185
187
  Airbrake::Request.new(
186
188
  method: 'GET',
187
189
  route: '/foo',
@@ -189,7 +191,7 @@ RSpec.describe Airbrake::PerformanceNotifier do
189
191
  timing: 213,
190
192
  ),
191
193
  )
192
- subject.notify(
194
+ perf_notifier.notify(
193
195
  Airbrake::Request.new(
194
196
  method: 'GET',
195
197
  route: '/foo',
@@ -197,7 +199,7 @@ RSpec.describe Airbrake::PerformanceNotifier do
197
199
  timing: 123,
198
200
  ),
199
201
  )
200
- subject.close
202
+ perf_notifier.close
201
203
 
202
204
  expect(
203
205
  a_request(:put, routes).with(body: /"count":2/),
@@ -205,7 +207,7 @@ RSpec.describe Airbrake::PerformanceNotifier do
205
207
  end
206
208
 
207
209
  it "groups routes by time" do
208
- subject.notify(
210
+ perf_notifier.notify(
209
211
  Airbrake::Request.new(
210
212
  method: 'GET',
211
213
  route: '/foo',
@@ -214,7 +216,7 @@ RSpec.describe Airbrake::PerformanceNotifier do
214
216
  time: Time.new(2018, 1, 1, 0, 0, 49, 0),
215
217
  ),
216
218
  )
217
- subject.notify(
219
+ perf_notifier.notify(
218
220
  Airbrake::Request.new(
219
221
  method: 'GET',
220
222
  route: '/foo',
@@ -223,7 +225,7 @@ RSpec.describe Airbrake::PerformanceNotifier do
223
225
  time: Time.new(2018, 1, 1, 0, 1, 49, 0),
224
226
  ),
225
227
  )
226
- subject.close
228
+ perf_notifier.close
227
229
 
228
230
  expect(
229
231
  a_request(:put, routes).with(
@@ -241,7 +243,7 @@ RSpec.describe Airbrake::PerformanceNotifier do
241
243
  end
242
244
 
243
245
  it "groups routes by route key" do
244
- subject.notify(
246
+ perf_notifier.notify(
245
247
  Airbrake::Request.new(
246
248
  method: 'GET',
247
249
  route: '/foo',
@@ -250,7 +252,7 @@ RSpec.describe Airbrake::PerformanceNotifier do
250
252
  time: Time.new(2018, 1, 1, 0, 49, 0, 0),
251
253
  ),
252
254
  )
253
- subject.notify(
255
+ perf_notifier.notify(
254
256
  Airbrake::Request.new(
255
257
  method: 'POST',
256
258
  route: '/foo',
@@ -259,7 +261,7 @@ RSpec.describe Airbrake::PerformanceNotifier do
259
261
  time: Time.new(2018, 1, 1, 0, 49, 0, 0),
260
262
  ),
261
263
  )
262
- subject.close
264
+ perf_notifier.close
263
265
 
264
266
  expect(
265
267
  a_request(:put, routes).with(
@@ -277,7 +279,7 @@ RSpec.describe Airbrake::PerformanceNotifier do
277
279
  end
278
280
 
279
281
  it "groups performance breakdowns by route key" do
280
- subject.notify(
282
+ perf_notifier.notify(
281
283
  Airbrake::PerformanceBreakdown.new(
282
284
  method: 'DELETE',
283
285
  route: '/routes-breakdowns',
@@ -287,7 +289,7 @@ RSpec.describe Airbrake::PerformanceNotifier do
287
289
  groups: { db: 131, view: 421 },
288
290
  ),
289
291
  )
290
- subject.notify(
292
+ perf_notifier.notify(
291
293
  Airbrake::PerformanceBreakdown.new(
292
294
  method: 'DELETE',
293
295
  route: '/routes-breakdowns',
@@ -297,7 +299,7 @@ RSpec.describe Airbrake::PerformanceNotifier do
297
299
  groups: { db: 55, view: 11 },
298
300
  ),
299
301
  )
300
- subject.close
302
+ perf_notifier.close
301
303
 
302
304
  expect(
303
305
  a_request(:put, breakdowns).with(body: %r|
@@ -329,7 +331,7 @@ RSpec.describe Airbrake::PerformanceNotifier do
329
331
  end
330
332
 
331
333
  it "groups queues by queue key" do
332
- subject.notify(
334
+ perf_notifier.notify(
333
335
  Airbrake::Queue.new(
334
336
  queue: 'emails',
335
337
  error_count: 2,
@@ -338,7 +340,7 @@ RSpec.describe Airbrake::PerformanceNotifier do
338
340
  time: Time.new(2018, 1, 1, 0, 49, 0, 0),
339
341
  ),
340
342
  )
341
- subject.notify(
343
+ perf_notifier.notify(
342
344
  Airbrake::Queue.new(
343
345
  queue: 'emails',
344
346
  error_count: 3,
@@ -347,7 +349,7 @@ RSpec.describe Airbrake::PerformanceNotifier do
347
349
  time: Time.new(2018, 1, 1, 0, 49, 0, 0),
348
350
  ),
349
351
  )
350
- subject.close
352
+ perf_notifier.close
351
353
 
352
354
  expect(
353
355
  a_request(:put, queues).with(body: /
@@ -378,7 +380,7 @@ RSpec.describe Airbrake::PerformanceNotifier do
378
380
  end
379
381
 
380
382
  it "returns a promise" do
381
- promise = subject.notify(
383
+ promise = perf_notifier.notify(
382
384
  Airbrake::Request.new(
383
385
  method: 'GET',
384
386
  route: '/foo',
@@ -386,7 +388,7 @@ RSpec.describe Airbrake::PerformanceNotifier do
386
388
  timing: 123,
387
389
  ),
388
390
  )
389
- subject.close
391
+ perf_notifier.close
390
392
 
391
393
  expect(promise).to be_an(Airbrake::Promise)
392
394
  expect(promise.value).to eq('' => '')
@@ -396,16 +398,19 @@ RSpec.describe Airbrake::PerformanceNotifier do
396
398
  request = Airbrake::Request.new(
397
399
  method: 'GET', route: '/foo', status_code: 200, timing: 123,
398
400
  )
399
- expect(Airbrake::Config.instance).to receive(:check_performance_options)
400
- .with(request).and_return(Airbrake::Promise.new)
401
- subject.notify(request)
402
- subject.close
401
+ allow(Airbrake::Config.instance).to receive(:check_performance_options)
402
+ .and_return(Airbrake::Promise.new)
403
+ perf_notifier.notify(request)
404
+ perf_notifier.close
405
+
406
+ expect(Airbrake::Config.instance)
407
+ .to have_received(:check_performance_options).with(request)
403
408
  end
404
409
 
405
410
  it "sends environment when it's specified" do
406
411
  Airbrake::Config.instance.merge(performance_stats: true, environment: 'test')
407
412
 
408
- subject.notify(
413
+ perf_notifier.notify(
409
414
  Airbrake::Request.new(
410
415
  method: 'POST',
411
416
  route: '/foo',
@@ -413,7 +418,7 @@ RSpec.describe Airbrake::PerformanceNotifier do
413
418
  timing: 123,
414
419
  ),
415
420
  )
416
- subject.close
421
+ perf_notifier.close
417
422
 
418
423
  expect(
419
424
  a_request(:put, routes).with(
@@ -426,7 +431,7 @@ RSpec.describe Airbrake::PerformanceNotifier do
426
431
  before { Airbrake::Config.instance.merge(project_id: nil) }
427
432
 
428
433
  it "returns a rejected promise" do
429
- promise = subject.notify({})
434
+ promise = perf_notifier.notify({})
430
435
  expect(promise).to be_rejected
431
436
  end
432
437
  end
@@ -442,7 +447,7 @@ RSpec.describe Airbrake::PerformanceNotifier do
442
447
  performance_stats_flush_period: flush_period,
443
448
  )
444
449
 
445
- subject.notify(
450
+ perf_notifier.notify(
446
451
  Airbrake::Request.new(
447
452
  method: 'GET',
448
453
  route: '/foo',
@@ -451,7 +456,7 @@ RSpec.describe Airbrake::PerformanceNotifier do
451
456
  ),
452
457
  )
453
458
 
454
- subject.notify(
459
+ perf_notifier.notify(
455
460
  Airbrake::Query.new(
456
461
  method: 'POST',
457
462
  route: '/foo',
@@ -468,10 +473,10 @@ RSpec.describe Airbrake::PerformanceNotifier do
468
473
  end
469
474
 
470
475
  context "when an ignore filter was defined" do
471
- before { subject.add_filter(&:ignore!) }
476
+ before { perf_notifier.add_filter(&:ignore!) }
472
477
 
473
478
  it "doesn't notify airbrake of requests" do
474
- subject.notify(
479
+ perf_notifier.notify(
475
480
  Airbrake::Request.new(
476
481
  method: 'GET',
477
482
  route: '/foo',
@@ -479,13 +484,13 @@ RSpec.describe Airbrake::PerformanceNotifier do
479
484
  timing: 1,
480
485
  ),
481
486
  )
482
- subject.close
487
+ perf_notifier.close
483
488
 
484
489
  expect(a_request(:put, routes)).not_to have_been_made
485
490
  end
486
491
 
487
492
  it "doesn't notify airbrake of queries" do
488
- subject.notify(
493
+ perf_notifier.notify(
489
494
  Airbrake::Query.new(
490
495
  method: 'POST',
491
496
  route: '/foo',
@@ -493,13 +498,13 @@ RSpec.describe Airbrake::PerformanceNotifier do
493
498
  timing: 1,
494
499
  ),
495
500
  )
496
- subject.close
501
+ perf_notifier.close
497
502
 
498
503
  expect(a_request(:put, queries)).not_to have_been_made
499
504
  end
500
505
 
501
506
  it "returns a rejected promise" do
502
- promise = subject.notify(
507
+ promise = perf_notifier.notify(
503
508
  Airbrake::Query.new(
504
509
  method: 'POST',
505
510
  route: '/foo',
@@ -507,7 +512,7 @@ RSpec.describe Airbrake::PerformanceNotifier do
507
512
  timing: 1,
508
513
  ),
509
514
  )
510
- subject.close
515
+ perf_notifier.close
511
516
 
512
517
  expect(promise.value).to eq(
513
518
  'error' => 'Airbrake::Query was ignored by a filter',
@@ -517,13 +522,13 @@ RSpec.describe Airbrake::PerformanceNotifier do
517
522
 
518
523
  context "when a filter that modifies payload was defined" do
519
524
  before do
520
- subject.add_filter do |resource|
521
- resource.route = '[Filtered]'
525
+ perf_notifier.add_filter do |metric|
526
+ metric.route = '[Filtered]'
522
527
  end
523
528
  end
524
529
 
525
530
  it "notifies airbrake with modified payload" do
526
- subject.notify(
531
+ perf_notifier.notify(
527
532
  Airbrake::Query.new(
528
533
  method: 'POST',
529
534
  route: '/foo',
@@ -531,7 +536,7 @@ RSpec.describe Airbrake::PerformanceNotifier do
531
536
  timing: 123,
532
537
  ),
533
538
  )
534
- subject.close
539
+ perf_notifier.close
535
540
 
536
541
  expect(
537
542
  a_request(:put, queries).with(
@@ -544,16 +549,16 @@ RSpec.describe Airbrake::PerformanceNotifier do
544
549
  context "when provided :timing is zero" do
545
550
  it "doesn't notify" do
546
551
  queue = Airbrake::Queue.new(queue: 'bananas', error_count: 0, timing: 0)
547
- subject.notify(queue)
548
- subject.close
552
+ perf_notifier.notify(queue)
553
+ perf_notifier.close
549
554
 
550
555
  expect(a_request(:put, queues)).not_to have_been_made
551
556
  end
552
557
 
553
558
  it "returns a rejected promise" do
554
559
  queue = Airbrake::Queue.new(queue: 'bananas', error_count: 0, timing: 0)
555
- promise = subject.notify(queue)
556
- subject.close
560
+ promise = perf_notifier.notify(queue)
561
+ perf_notifier.close
557
562
 
558
563
  expect(promise.value).to eq('error' => ':timing cannot be zero')
559
564
  end
@@ -562,7 +567,7 @@ RSpec.describe Airbrake::PerformanceNotifier do
562
567
 
563
568
  describe "#notify_sync" do
564
569
  it "notifies synchronously" do
565
- retval = subject.notify_sync(
570
+ retval = perf_notifier.notify_sync(
566
571
  Airbrake::Query.new(
567
572
  method: 'POST',
568
573
  route: '/foo',
@@ -591,7 +596,7 @@ RSpec.describe Airbrake::PerformanceNotifier do
591
596
 
592
597
  it "kills the background thread" do
593
598
  expect_any_instance_of(Thread).to receive(:kill).and_call_original
594
- subject.notify(
599
+ perf_notifier.notify(
595
600
  Airbrake::Query.new(
596
601
  method: 'POST',
597
602
  route: '/foo',
@@ -599,30 +604,32 @@ RSpec.describe Airbrake::PerformanceNotifier do
599
604
  timing: 123,
600
605
  ),
601
606
  )
602
- subject.close
607
+ perf_notifier.close
603
608
  end
604
609
 
605
610
  it "logs the exit message" do
606
611
  allow(Airbrake::Loggable.instance).to receive(:debug)
607
- expect(Airbrake::Loggable.instance).to receive(:debug).with(
608
- /performance notifier closed/,
612
+
613
+ perf_notifier.close
614
+
615
+ expect(Airbrake::Loggable.instance).to have_received(:debug).with(
616
+ /Airbrake::PerformanceNotifier thread pool closed/,
609
617
  )
610
- subject.close
611
618
  end
612
619
  end
613
620
 
614
621
  describe "#delete_filter" do
615
622
  let(:filter) do
616
623
  Class.new do
617
- def call(resource); end
624
+ def call(metric); end
618
625
  end
619
626
  end
620
627
 
621
- before { subject.add_filter(filter.new) }
628
+ before { perf_notifier.add_filter(filter.new) }
622
629
 
623
630
  it "deletes a filter" do
624
- subject.delete_filter(filter)
625
- subject.notify(
631
+ perf_notifier.delete_filter(filter)
632
+ perf_notifier.notify(
626
633
  Airbrake::Request.new(
627
634
  method: 'POST',
628
635
  route: '/foo',
@@ -630,7 +637,7 @@ RSpec.describe Airbrake::PerformanceNotifier do
630
637
  timing: 123,
631
638
  ),
632
639
  )
633
- subject.close
640
+ perf_notifier.close
634
641
 
635
642
  expect(a_request(:put, routes)).to have_been_made
636
643
  end
data/spec/promise_spec.rb CHANGED
@@ -1,15 +1,17 @@
1
1
  RSpec.describe Airbrake::Promise do
2
+ subject(:promise) { described_class.new }
3
+
2
4
  describe ".then" do
3
5
  let(:resolved_with) { [] }
4
6
  let(:rejected_with) { [] }
5
7
 
6
8
  context "when it is not resolved" do
7
9
  it "returns self" do
8
- expect(subject.then {}).to eq(subject)
10
+ expect(promise.then { anything }).to eq(promise)
9
11
  end
10
12
 
11
13
  it "doesn't call the resolve callbacks yet" do
12
- subject.then { resolved_with << 1 }.then { resolved_with << 2 }
14
+ promise.then { resolved_with << 1 }.then { resolved_with << 2 }
13
15
  expect(resolved_with).to be_empty
14
16
  end
15
17
  end
@@ -17,12 +19,12 @@ RSpec.describe Airbrake::Promise do
17
19
  context "when it is resolved" do
18
20
  shared_examples "then specs" do
19
21
  it "returns self" do
20
- expect(subject.then {}).to eq(subject)
22
+ expect(promise.then { anything }).to eq(promise)
21
23
  end
22
24
 
23
25
  it "yields the resolved value" do
24
26
  yielded = nil
25
- subject.then { |value| yielded = value }
27
+ promise.then { |value| yielded = value }
26
28
  expect(yielded).to eq('id' => '123')
27
29
  end
28
30
 
@@ -37,29 +39,29 @@ RSpec.describe Airbrake::Promise do
37
39
 
38
40
  context "and there are some resolve and reject callbacks in place" do
39
41
  before do
40
- subject.then { resolved_with << 1 }.then { resolved_with << 2 }
41
- subject.rescue { rejected_with << 1 }.rescue { rejected_with << 2 }
42
- subject.resolve('id' => '123')
42
+ promise.then { resolved_with << 1 }.then { resolved_with << 2 }
43
+ promise.rescue { rejected_with << 1 }.rescue { rejected_with << 2 }
44
+ promise.resolve('id' => '123')
43
45
  end
44
46
 
45
47
  include_examples "then specs"
46
48
 
47
49
  it "registers the resolve callbacks" do
48
- subject.resolve('id' => '456')
50
+ promise.resolve('id' => '456')
49
51
  expect(resolved_with).to match_array([1, 2, 1, 2])
50
52
  end
51
53
  end
52
54
 
53
55
  context "and additional then callbacks are added" do
54
56
  before do
55
- subject.resolve('id' => '123')
56
- subject.then { resolved_with << 1 }.then { resolved_with << 2 }
57
+ promise.resolve('id' => '123')
58
+ promise.then { resolved_with << 1 }.then { resolved_with << 2 }
57
59
  end
58
60
 
59
61
  include_examples "then specs"
60
62
 
61
63
  it "doesn't register new resolve callbacks" do
62
- subject.resolve('id' => '456')
64
+ promise.resolve('id' => '456')
63
65
  expect(resolved_with).to match_array([1, 2])
64
66
  end
65
67
  end
@@ -72,11 +74,11 @@ RSpec.describe Airbrake::Promise do
72
74
 
73
75
  context "when it is not rejected" do
74
76
  it "returns self" do
75
- expect(subject.then {}).to eq(subject)
77
+ expect(promise.then { anything }).to eq(promise)
76
78
  end
77
79
 
78
80
  it "doesn't call the reject callbacks yet" do
79
- subject.rescue { rejected_with << 1 }.rescue { rejected_with << 2 }
81
+ promise.rescue { rejected_with << 1 }.rescue { rejected_with << 2 }
80
82
  expect(rejected_with).to be_empty
81
83
  end
82
84
  end
@@ -84,12 +86,12 @@ RSpec.describe Airbrake::Promise do
84
86
  context "when it is rejected" do
85
87
  shared_examples "rescue specs" do
86
88
  it "returns self" do
87
- expect(subject.rescue {}).to eq(subject)
89
+ expect(promise.rescue { anything }).to eq(promise)
88
90
  end
89
91
 
90
92
  it "yields the rejected value" do
91
93
  yielded = nil
92
- subject.rescue { |value| yielded = value }
94
+ promise.rescue { |value| yielded = value }
93
95
  expect(yielded).to eq('bingo')
94
96
  end
95
97
 
@@ -104,29 +106,29 @@ RSpec.describe Airbrake::Promise do
104
106
 
105
107
  context "and there are some resolve and reject callbacks in place" do
106
108
  before do
107
- subject.then { resolved_with << 1 }.then { resolved_with << 2 }
108
- subject.rescue { rejected_with << 1 }.rescue { rejected_with << 2 }
109
- subject.reject('bingo')
109
+ promise.then { resolved_with << 1 }.then { resolved_with << 2 }
110
+ promise.rescue { rejected_with << 1 }.rescue { rejected_with << 2 }
111
+ promise.reject('bingo')
110
112
  end
111
113
 
112
114
  include_examples "rescue specs"
113
115
 
114
116
  it "registers the reject callbacks" do
115
- subject.reject('bingo again')
117
+ promise.reject('bingo again')
116
118
  expect(rejected_with).to match_array([1, 2, 1, 2])
117
119
  end
118
120
  end
119
121
 
120
122
  context "and additional reject callbacks are added" do
121
123
  before do
122
- subject.reject('bingo')
123
- subject.rescue { rejected_with << 1 }.rescue { rejected_with << 2 }
124
+ promise.reject('bingo')
125
+ promise.rescue { rejected_with << 1 }.rescue { rejected_with << 2 }
124
126
  end
125
127
 
126
128
  include_examples "rescue specs"
127
129
 
128
130
  it "doesn't register new reject callbacks" do
129
- subject.reject('bingo again')
131
+ promise.reject('bingo again')
130
132
  expect(rejected_with).to match_array([1, 2])
131
133
  end
132
134
  end
@@ -135,37 +137,38 @@ RSpec.describe Airbrake::Promise do
135
137
 
136
138
  describe ".resolve" do
137
139
  it "returns self" do
138
- expect(subject.resolve(1)).to eq(subject)
140
+ expect(promise.resolve(1)).to eq(promise)
139
141
  end
140
142
 
141
143
  it "executes callbacks attached with .then" do
142
144
  array = []
143
- subject.then { |notice_id| array << notice_id }.rescue { array << 999 }
145
+ promise.then { |notice_id| array << notice_id }.rescue { array << 999 }
144
146
 
145
147
  expect(array.size).to be_zero
146
- subject.resolve(1)
148
+ promise.resolve(1)
147
149
  expect(array).to match_array([1])
148
150
  end
149
151
  end
150
152
 
151
153
  describe ".reject" do
152
154
  it "returns self" do
153
- expect(subject.reject(1)).to eq(subject)
155
+ expect(promise.reject(1)).to eq(promise)
154
156
  end
155
157
 
156
158
  it "executes callbacks attached with .rescue" do
157
159
  array = []
158
- subject.then { array << 1 }.rescue { |error| array << error }
160
+ promise.then { array << 1 }.rescue { |error| array << error }
159
161
 
160
162
  expect(array.size).to be_zero
161
- subject.reject(999)
163
+ promise.reject(999)
162
164
  expect(array).to match_array([999])
163
165
  end
164
166
  end
165
167
 
166
168
  describe "#rejected?" do
167
169
  context "when it was rejected" do
168
- before { subject.reject(1) }
170
+ before { promise.reject(1) }
171
+
169
172
  it { is_expected.to be_rejected }
170
173
  end
171
174
 
@@ -174,14 +177,16 @@ RSpec.describe Airbrake::Promise do
174
177
  end
175
178
 
176
179
  context "when it was resolved" do
177
- before { subject.resolve }
180
+ before { promise.resolve }
181
+
178
182
  it { is_expected.not_to be_rejected }
179
183
  end
180
184
  end
181
185
 
182
186
  describe "#resolved?" do
183
187
  context "when it was resolved" do
184
- before { subject.resolve }
188
+ before { promise.resolve }
189
+
185
190
  it { is_expected.to be_resolved }
186
191
  end
187
192
 
@@ -190,7 +195,8 @@ RSpec.describe Airbrake::Promise do
190
195
  end
191
196
 
192
197
  context "when it was rejected" do
193
- before { subject.reject(1) }
198
+ before { promise.reject(1) }
199
+
194
200
  it { is_expected.not_to be_resolved }
195
201
  end
196
202
  end