-
Notifications
You must be signed in to change notification settings - Fork 64
/
Copy pathexceptions_spec.rb
65 lines (52 loc) · 1.65 KB
/
exceptions_spec.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
require 'spec_helper'
describe SparkPostRails::DeliveryException do
subject { SparkPostRails::DeliveryException.new(error) }
describe 'string' do
let(:error) { 'Some delivery error' }
it 'preserves original message' do
begin
raise subject
rescue SparkPostRails::DeliveryException => err
expect(error).to eq(err.message)
end
end
end
describe 'array with error details' do
let(:error) { [{ 'message' => 'Message generation rejected', 'description' => 'recipient address suppressed due to customer policy', 'code' => '1902' }] }
it 'assigns message' do
expect(subject.service_message).to eq('Message generation rejected')
end
it 'assigns description' do
expect(subject.service_description).to eq('recipient address suppressed due to customer policy')
end
it 'assigns code' do
expect(subject.service_code).to eq('1902')
end
it 'preserves original message' do
begin
raise subject
rescue SparkPostRails::DeliveryException => err
expect(error.to_s).to eq(err.message)
end
end
end
describe 'array with partial details' do
let(:error) { [{ 'message' => 'end of world' }] }
it 'assigns message' do
expect(subject.service_message).to eq('end of world')
end
it 'assigns description' do
expect(subject.service_description).to be nil
end
it 'assigns code' do
expect(subject.service_code).to be nil
end
it 'preserves original message' do
begin
raise subject
rescue SparkPostRails::DeliveryException => err
expect(error.to_s).to eq(err.message)
end
end
end
end