execute_with_rescue_with_airbrake 0.0.2 → 0.0.3

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,3 +1,3 @@
1
1
  module ExecuteWithRescueWithAirbrake
2
- VERSION = "0.0.2"
2
+ VERSION = "0.0.3".freeze
3
3
  end
@@ -1,54 +1,53 @@
1
- require 'spec_helper'
2
-
1
+ require "spec_helper"
3
2
 
4
3
  describe ExecuteWithRescue::Mixins::WithAirbrake do
5
4
  let(:test_class) { TestServiceWithAirbrake }
6
5
  let(:test_class_instance) { test_class.new }
7
6
  let(:call_service) { test_class_instance.call }
8
7
 
9
- shared_context 'when airbrake adapter assumed exists' do
8
+ shared_context "when airbrake adapter assumed exists" do
10
9
  let(:adapter_class) do
11
10
  ExecuteWithRescueWithAirbrake::Adapters::AirbrakeAdapter
12
11
  end
13
12
  let!(:adapter_instance) { adapter_class.new }
14
13
  before do
15
14
  # Avoid Error
16
- allow(test_class_instance)
17
- .to receive(:_execute_with_rescue_current_airbrake_adapter)
18
- .and_return(adapter_instance)
15
+ allow(test_class_instance).
16
+ to receive(:_execute_with_rescue_current_airbrake_adapter).
17
+ and_return(adapter_instance)
19
18
  end
20
19
  end
21
20
 
22
- describe 'included modules' do
21
+ describe "included modules" do
23
22
  subject { test_class.ancestors }
24
23
 
25
- it {should include ExecuteWithRescue::Mixins::Core}
26
- it {should include ExecuteWithRescue::Mixins::WithAirbrake}
24
+ it { should include ExecuteWithRescue::Mixins::Core }
25
+ it { should include ExecuteWithRescue::Mixins::WithAirbrake }
27
26
  end
28
27
 
29
- describe 'call delegated methods' do
30
- context 'without calling #execute_with_rescue' do
28
+ describe "call delegated methods" do
29
+ context "without calling #execute_with_rescue" do
31
30
  let(:test_class) { TestServiceWithAirbrakeWithoutExecuteWithRescueCall }
32
31
  let(:expected_error_class) { ExecuteWithRescue::Errors::NoAirbrakeAdapter }
33
32
 
34
33
  specify do
35
- expect{ call_service }
36
- .to raise_error(expected_error_class)
34
+ expect { call_service }.
35
+ to raise_error(expected_error_class)
37
36
  end
38
37
  end
39
- context 'without calling #execute_with_rescue' do
38
+ context "without calling #execute_with_rescue" do
40
39
  let(:test_class) { TestServiceWithAirbrakeWithExecuteWithRescueCall }
41
40
 
42
41
  specify do
43
- expect{ call_service }
44
- .to_not raise_error
42
+ expect { call_service }.
43
+ to_not raise_error
45
44
  end
46
45
  end
47
- context 'with calling #execute_with_rescue'
46
+ context "with calling #execute_with_rescue"
48
47
  end
49
48
 
50
- describe 'delegation' do
51
- include_context 'when airbrake adapter assumed exists'
49
+ describe "delegation" do
50
+ include_context "when airbrake adapter assumed exists"
52
51
 
53
52
  before do
54
53
  allow(adapter_instance).to receive(method_name)
@@ -56,7 +55,7 @@ describe ExecuteWithRescue::Mixins::WithAirbrake do
56
55
 
57
56
  let(:send_message) { test_class_instance.send(method_name) }
58
57
 
59
- shared_examples_for 'delegation' do
58
+ shared_examples_for "delegation" do
60
59
  specify do
61
60
  expect(adapter_instance).to receive(method_name)
62
61
 
@@ -64,77 +63,80 @@ describe ExecuteWithRescue::Mixins::WithAirbrake do
64
63
  end
65
64
  end
66
65
 
67
- describe 'for #set_default_airbrake_notice_error_class' do
66
+ describe "for #set_default_airbrake_notice_error_class" do
68
67
  let(:method_name) { :set_default_airbrake_notice_error_class }
69
68
 
70
- it_behaves_like 'delegation'
69
+ it_behaves_like "delegation"
71
70
  end
72
- describe 'for #set_default_airbrake_notice_error_message' do
71
+ describe "for #set_default_airbrake_notice_error_message" do
73
72
  let(:method_name) { :set_default_airbrake_notice_error_message }
74
73
 
75
- it_behaves_like 'delegation'
74
+ it_behaves_like "delegation"
76
75
  end
77
- describe 'for #add_default_airbrake_notice_parameters' do
76
+ describe "for #add_default_airbrake_notice_parameters" do
78
77
  let(:method_name) { :add_default_airbrake_notice_parameters }
79
78
 
80
- it_behaves_like 'delegation'
79
+ it_behaves_like "delegation"
81
80
  end
82
81
  end
83
82
 
84
- describe 'execution' do
85
- include_context 'when airbrake adapter assumed exists'
83
+ describe "execution" do
84
+ include_context "when airbrake adapter assumed exists"
86
85
 
87
86
  before { allow(Airbrake.configuration).to receive(:public?) { true } }
88
87
 
89
- describe 'when there is no error raised' do
88
+ describe "when there is no error raised" do
90
89
  specify do
91
- expect(Airbrake)
92
- .to_not receive(:notify_or_ignore)
90
+ expect(Airbrake).
91
+ to_not receive(:notify_or_ignore)
93
92
 
94
93
  call_service
95
94
  end
96
95
  end
97
- describe 'when there is error raised' do
98
- context 'and it is a standard error' do
96
+ describe "when there is error raised" do
97
+ context "and it is a standard error" do
99
98
  let(:test_class) { TestServiceWithAirbrakeWithError }
100
99
 
101
100
  specify do
102
- expect(Airbrake)
103
- .to(receive(:notify_or_ignore)
104
- .with(kind_of(StandardError), {}))
101
+ expect(Airbrake).
102
+ to receive(:notify_or_ignore).
103
+ with(kind_of(StandardError), {})
105
104
 
106
105
  call_service
107
106
  end
108
107
  end
109
108
 
110
- describe 'setting custom airbrake options' do
109
+ describe "setting custom airbrake options" do
111
110
  let(:test_class) { TestServiceWithAirbrakeWithErrorAndAirbrakeOption }
112
111
 
113
112
  specify do
114
- expect(Airbrake)
115
- .to(receive(:notify_or_ignore)
116
- .with(kind_of(StandardError), {
117
- error_class: test_class::CustomError,
118
- error_message: 'hi',
119
- parameters: {
120
- foo: :bar
121
- },
122
- }))
113
+ expect(Airbrake).
114
+ to receive(:notify_or_ignore).
115
+ with(
116
+ kind_of(StandardError),
117
+ error_class: test_class::CustomError,
118
+ error_message: "hi",
119
+ parameters: {
120
+ foo: :bar
121
+ },
122
+ )
123
123
 
124
124
  call_service
125
125
  end
126
126
  end
127
127
 
128
- describe 'setting custom airbrake options with an error that requires argument on initialize' do
128
+ describe "setting custom airbrake options with an error "\
129
+ "that requires argument on initialize" do
129
130
  let(:test_class) { TestServiceWithAirbrakeWithCustomErrorAndMessage }
130
131
 
131
132
  specify do
132
- expect(Airbrake)
133
- .to(receive(:notify_or_ignore)
134
- .with(kind_of(StandardError), {
135
- error_class: test_class::CustomErrorWithMessage,
136
- error_message: "#{:foo.class} has error",
137
- }))
133
+ expect(Airbrake).
134
+ to receive(:notify_or_ignore).
135
+ with(
136
+ kind_of(StandardError),
137
+ error_class: test_class::CustomErrorWithMessage,
138
+ error_message: "#{:foo.class} has error",
139
+ )
138
140
 
139
141
  call_service
140
142
  end
@@ -1,5 +1,4 @@
1
- require 'spec_helper'
2
-
1
+ require "spec_helper"
3
2
 
4
3
  describe ExecuteWithRescueWithAirbrake::Adapters::AirbrakeAdapter do
5
4
  let!(:instance) { described_class.new }
@@ -7,41 +6,39 @@ describe ExecuteWithRescueWithAirbrake::Adapters::AirbrakeAdapter do
7
6
  let!(:notice_options) do
8
7
  {parameters: {}}
9
8
  end
10
- let!(:exception_rescued) { StandardError.new('hi I am test error') }
9
+ let!(:exception_rescued) { StandardError.new("hi I am test error") }
11
10
 
12
11
  let(:notify_or_raise) { instance.notify_or_raise(exception_rescued) }
13
12
 
14
- #before { }
15
-
16
- context 'when exception should not be notified according to Airbrake' do
13
+ context "when exception should not be notified according to Airbrake" do
17
14
  before { allow(Airbrake.configuration).to receive(:public?) { false } }
18
15
 
19
- it 're-raise the rescue error' do
20
- expect { notify_or_raise }.to raise_error(exception_rescued.class,
21
- exception_rescued.message)
16
+ it "re-raise the rescue error" do
17
+ expect { notify_or_raise }.
18
+ to raise_error(
19
+ exception_rescued.class,
20
+ exception_rescued.message,
21
+ )
22
22
  end
23
23
  end
24
- context 'when exception should be notified according to Airbrake' do
24
+ context "when exception should be notified according to Airbrake" do
25
25
  before { allow(Airbrake.configuration).to receive(:public?) { true } }
26
26
 
27
- it 'does not re-raise the rescued error' do
27
+ it "does not re-raise the rescued error" do
28
28
  expect { notify_or_raise }.to_not raise_error
29
29
  end
30
30
  end
31
31
 
32
- context 'assuming Airbrake says it error should be notified' do
32
+ context "assuming Airbrake says it error should be notified" do
33
33
  before { allow(Airbrake.configuration).to receive(:public?) { true } }
34
34
 
35
- it 'calls Airbrake.notify_or_ignore' do
35
+ it "calls Airbrake.notify_or_ignore" do
36
36
  expect(Airbrake).to receive(:notify_or_ignore)
37
37
 
38
38
  notify_or_raise
39
-
40
- # expect(Airbrake).to have_received(:notify_or_ignore)
41
39
  end
42
40
 
43
-
44
- describe '#set_default_airbrake_notice_error_class' do
41
+ describe "#set_default_airbrake_notice_error_class" do
45
42
  let(:set_error_class) do
46
43
  instance.set_default_airbrake_notice_error_class(
47
44
  default_error_class)
@@ -51,62 +48,62 @@ describe ExecuteWithRescueWithAirbrake::Adapters::AirbrakeAdapter do
51
48
 
52
49
  before do
53
50
  # Return the options only
54
- allow(Airbrake).to receive(:notify_or_ignore) {|*args| args.last }
51
+ allow(Airbrake).to receive(:notify_or_ignore) { |*args| args.last }
55
52
  end
56
53
  let(:options_hash) { notify_or_raise }
57
54
  subject { options_hash }
58
55
 
59
- context 'when its not called' do
56
+ context "when its not called" do
60
57
  its(:keys) { should_not include(option_key) }
61
58
  end
62
- context 'when its called with nil' do
59
+ context "when its called with nil" do
63
60
  let(:default_error_class) { nil }
64
61
  before { set_error_class }
65
62
 
66
63
  its(:keys) { should_not include(option_key) }
67
64
  end
68
- context 'when its called with custom error' do
65
+ context "when its called with custom error" do
69
66
  let(:default_error_class) { ArgumentError }
70
67
  before { set_error_class }
71
68
 
72
- it { should include({option_key => default_error_class}) }
69
+ it { should include(option_key => default_error_class) }
73
70
  end
74
71
  end
75
72
 
76
- describe '#set_default_airbrake_notice_error_message' do
73
+ describe "#set_default_airbrake_notice_error_message" do
77
74
  let(:set_error_message) do
78
- instance.set_default_airbrake_notice_error_message(
79
- default_error_message)
75
+ instance.
76
+ set_default_airbrake_notice_error_message(default_error_message)
80
77
  end
81
78
  let(:default_error_message) { nil }
82
79
  let(:option_key) { :error_message }
83
80
 
84
81
  before do
85
82
  # Return the options only
86
- allow(Airbrake).to receive(:notify_or_ignore) {|*args| args.last }
83
+ allow(Airbrake).to receive(:notify_or_ignore) { |*args| args.last }
87
84
  end
88
85
  let(:options_hash) { notify_or_raise }
89
86
  subject { options_hash }
90
87
 
91
- context 'when its not called' do
88
+ context "when its not called" do
92
89
  its(:keys) { should_not include(option_key) }
93
90
  end
94
- context 'when its called with nil' do
91
+ context "when its called with nil" do
95
92
  let(:default_error_message) { nil }
96
93
  before { set_error_message }
97
94
 
98
95
  its(:keys) { should_not include(option_key) }
99
96
  end
100
- context 'when its called with custom error' do
101
- let(:default_error_message) { 'hello' }
97
+ context "when its called with custom error" do
98
+ let(:default_error_message) { "hello" }
102
99
  before { set_error_message }
103
100
 
104
- it { should include({option_key => default_error_message}) }
101
+ it { should include(option_key => default_error_message) }
105
102
  end
106
103
  end
107
104
 
108
- describe '#add_default_airbrake_notice_parameters' do
109
- # Must defined as method or it won't run twice
105
+ describe "#add_default_airbrake_notice_parameters" do
106
+ # Must defined as method or it won"t run twice
110
107
  def add_parameters(params = new_parameters)
111
108
  instance.add_default_airbrake_notice_parameters(
112
109
  params)
@@ -116,94 +113,95 @@ describe ExecuteWithRescueWithAirbrake::Adapters::AirbrakeAdapter do
116
113
 
117
114
  before do
118
115
  # Return the options only
119
- allow(Airbrake).to receive(:notify_or_ignore) {|*args| args.last }
116
+ allow(Airbrake).
117
+ to receive(:notify_or_ignore) { |*args| args.last }
120
118
  end
121
119
  let(:options_hash) { notify_or_raise }
122
120
  let(:parameters_hash) { options_hash[option_key] }
123
121
 
124
122
  subject { options_hash }
125
123
 
126
- context 'when its not called' do
124
+ context "when its not called" do
127
125
  its(:keys) { should_not include(option_key) }
128
126
  end
129
- context 'when its called with non hash' do
130
- let(:new_parameters) { Array.new }
127
+ context "when its called with non hash" do
128
+ let(:new_parameters) { [] }
131
129
  let(:expected_error_class) do
132
130
  described_class::Errors::InvalidParameters
133
131
  end
134
132
 
135
133
  specify do
136
- expect { add_parameters }
137
- .to raise_error(expected_error_class)
134
+ expect { add_parameters }.
135
+ to raise_error(expected_error_class)
138
136
  end
139
137
  end
140
- context 'when its called with empty hash' do
138
+ context "when its called with empty hash" do
141
139
  let(:new_parameters) { Hash.new }
142
140
  before { add_parameters }
143
141
 
144
142
  its(:keys) { should_not include(option_key) }
145
143
  end
146
144
 
147
- context 'when its called with non-empty hash' do
145
+ context "when its called with non-empty hash" do
148
146
  subject { parameters_hash }
149
147
 
150
148
  let(:new_parameters) { {foo: :bar} }
151
149
 
152
- context 'and there is no conflicting key' do
150
+ context "and there is no conflicting key" do
153
151
  before { add_parameters }
154
152
 
155
153
  it { should include(new_parameters) }
156
154
  end
157
155
 
158
- context 'and there is a conflicting key' do
156
+ context "and there is a conflicting key" do
159
157
  before { add_parameters }
160
158
  let(:expected_error_class) do
161
159
  described_class::Errors::ParameterKeyConflict
162
160
  end
163
161
 
164
- context 'in symbol' do
162
+ context "in symbol" do
165
163
  specify do
166
- expect { add_parameters }
167
- .to raise_error(expected_error_class)
164
+ expect { add_parameters }.
165
+ to raise_error(expected_error_class)
168
166
  end
169
167
  end
170
- context 'in string' do
168
+ context "in string" do
171
169
  specify do
172
- expect { add_parameters(new_parameters.stringify_keys) }
173
- .to raise_error(expected_error_class)
170
+ expect { add_parameters(new_parameters.stringify_keys) }.
171
+ to raise_error(expected_error_class)
174
172
  end
175
173
  end
176
174
  end
177
175
  end
178
176
  end
179
177
 
180
-
181
- describe 'options passed' do
182
- context 'when nothing is set' do
178
+ describe "options passed" do
179
+ context "when nothing is set" do
183
180
  specify do
184
- expect(Airbrake)
185
- .to(receive(:notify_or_ignore)
186
- .with(kind_of(StandardError), {}))
181
+ expect(Airbrake).
182
+ to receive(:notify_or_ignore).
183
+ with(kind_of(StandardError), {})
187
184
 
188
185
  notify_or_raise
189
186
  end
190
187
  end
191
- context 'when all things are set' do
188
+ context "when all things are set" do
192
189
  let!(:custom_error_class) { Class.new(StandardError) }
193
- let!(:custom_error_message) { 'hi' }
190
+ let!(:custom_error_message) { "hi" }
194
191
  let!(:custom_parameters) { {foo: :bar}.stringify_keys }
195
192
  before { instance.set_default_airbrake_notice_error_class(custom_error_class) }
196
193
  before { instance.set_default_airbrake_notice_error_message(custom_error_message) }
197
194
  before { instance.add_default_airbrake_notice_parameters(custom_parameters) }
198
195
 
199
196
  specify do
200
- expect(Airbrake)
201
- .to(receive(:notify_or_ignore)
202
- .with(kind_of(StandardError), {
203
- error_class: custom_error_class,
204
- error_message: custom_error_message,
205
- parameters: custom_parameters.symbolize_keys,
206
- }))
197
+ expect(Airbrake).
198
+ to receive(:notify_or_ignore).
199
+ with(
200
+ kind_of(StandardError),
201
+ error_class: custom_error_class,
202
+ error_message: custom_error_message,
203
+ parameters: custom_parameters.symbolize_keys,
204
+ )
207
205
 
208
206
  notify_or_raise
209
207
  end