smoke_detector 1.0.0 → 1.1.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,7 +1,8 @@
1
1
  require 'spec_helper'
2
2
 
3
3
  describe SmokeDetector::Providers::Rollbar do
4
- let(:provider) { SmokeDetector::Providers::Rollbar.new('api_key', nil, settings) }
4
+ let(:provider) { SmokeDetector::Providers::Rollbar.new('api_key', client_settings, settings) }
5
+ let(:client_settings) { nil }
5
6
  let(:settings) { {} }
6
7
  let(:err) { StandardError.new('error') }
7
8
  let(:data) { {custom: :data} }
@@ -91,4 +92,37 @@ describe SmokeDetector::Providers::Rollbar do
91
92
  end
92
93
  end
93
94
  end
95
+
96
+ describe "#client_settings" do
97
+ let(:settings) { { environment: ::Rails.env } }
98
+ let(:client_api_key) { "client_api_key" }
99
+ let(:hostWhiteList) { %w(google.com yahoo.com aol.com) }
100
+ let(:ignoredMessages) { ["Hey, ignore this", "Ignore this too"] }
101
+ let(:personData) { { email: "yo@gabbagabba.limosine" } }
102
+
103
+ let(:client_settings) do
104
+ {
105
+ api_key: client_api_key,
106
+ hostWhiteList: hostWhiteList,
107
+ ignoredMessages: ignoredMessages,
108
+ payload: {
109
+ person: personData
110
+ }
111
+ }
112
+ end
113
+
114
+ subject { provider.client_settings }
115
+
116
+ it "merges default settings" do
117
+ expect(subject).to include(:payload)
118
+ expect(subject[:payload]).to include(:environment)
119
+ expect(subject[:payload][:environment]).to eq(::Rails.env)
120
+ end
121
+
122
+ it "includes configured client settings" do
123
+ expect(subject[:api_key]).to eq(client_api_key)
124
+ expect(subject[:hostWhiteList]).to eq(hostWhiteList)
125
+ expect(subject[:payload][:person]).to eq(personData)
126
+ end
127
+ end
94
128
  end
@@ -1,5 +1,6 @@
1
1
  require 'spec_helper'
2
2
  require 'nokogiri'
3
+ require 'jshintrb'
3
4
 
4
5
  describe SmokeDetector::JavaScriptMonitors do
5
6
 
@@ -13,15 +14,33 @@ describe SmokeDetector::JavaScriptMonitors do
13
14
  end
14
15
  end
15
16
 
17
+ shared_examples "a page with a valid rollbar json config" do
18
+ it "has no errors" do
19
+ get '/widgets'
20
+ content = Nokogiri::HTML(response.body).css('head script:contains("_rollbarConfig")').children.first.to_s
21
+ errors = Jshintrb.lint(content)
22
+ expect(errors).to be_empty
23
+ end
24
+ end
25
+
16
26
  context 'with a Rollbar client API key configured' do
17
27
  before do
18
- SmokeDetector.register_provider(:rollbar, 'key', {api_key: 'client_key' })
28
+ SmokeDetector.register_provider(:rollbar, 'key', { api_key: 'client_key' })
19
29
  end
20
30
 
21
31
  it 'injects the Rollbar JS snippet into the <head>' do
22
32
  get '/widgets'
23
33
  expect(Nokogiri::HTML(response.body).css('head script:contains("_rollbarConfig")')).to_not be_empty
24
34
  end
35
+
36
+ it "translates api_key to accessToken" do
37
+ get '/widgets'
38
+ rollbar_snippet = Nokogiri::HTML(response.body).css('head script:contains("_rollbarConfig")').children.first
39
+ position = /"accessToken":"client_key"/
40
+ expect(position).to_not be_nil
41
+ end
42
+
43
+ it_behaves_like "a page with a valid rollbar json config"
25
44
  end
26
45
 
27
46
  context 'without a Rollbar client API key configured' do
@@ -33,31 +52,42 @@ describe SmokeDetector::JavaScriptMonitors do
33
52
  get '/widgets'
34
53
  expect(Nokogiri::HTML(response.body).css('head script:contains("_rollbarConfig")')).to be_empty
35
54
  end
55
+
56
+ it_behaves_like "a page with a valid rollbar json config"
36
57
  end
37
58
 
38
59
  context 'hostWhitelist' do
60
+ let(:client_settings) { { api_key: 'client_key', hostWhiteList: host_whitelist } }
61
+
39
62
  before do
40
- SmokeDetector.register_provider(:rollbar, 'key', {api_key: 'client_key', host_whitelist: host_whitelist})
63
+ SmokeDetector.register_provider(:rollbar, 'key', client_settings)
41
64
  end
42
65
 
43
66
  shared_examples "a properly set hostWhiteList" do
44
67
  it 'injects the Rollbar JS snippet into the <head>' do
45
68
  get '/widgets'
46
- rollbar_snippet = Nokogiri::HTML(response.body).css('head script:contains("_rollbarConfig")').children.first
69
+ rollbar_snippet = Nokogiri::HTML(response.body).css('head script:contains("_rollbarConfig")').children.first.to_s
47
70
  expect(rollbar_snippet).to_not be_nil
48
71
  end
49
72
 
50
73
  it 'sets hostWhitelist' do
51
74
  get '/widgets'
52
- script_content = Nokogiri::HTML(response.body).css('head script:contains("_rollbarConfig")').children.first
53
- position = /hostWhiteList:\s*#{Regexp.escape(host_whitelist.to_s)}/i =~ script_content
75
+ script_content = Nokogiri::HTML(response.body).css('head script:contains("_rollbarConfig")').children.first.to_s
76
+ position = /\"hostWhiteList\":#{Regexp.escape(host_whitelist.to_json)}/i =~ script_content
54
77
  expect(position).to_not be_nil
55
78
  end
79
+
80
+ it_behaves_like "a page with a valid rollbar json config"
56
81
  end
57
82
 
58
83
  context 'with hostWhitelist Rollbar client setting configured' do
59
- let(:host_whitelist) { ['example.com', 'facebook.com'] }
84
+ let(:host_whitelist) { ["example.com", "facebook.com"] }
60
85
  it_behaves_like "a properly set hostWhiteList"
86
+
87
+ context 'with snake-case setting' do
88
+ let(:client_settings) { { api_key: 'client_key', host_whitelist: host_whitelist } }
89
+ it_behaves_like "a properly set hostWhiteList"
90
+ end
61
91
  end
62
92
 
63
93
  context 'with hostWhitelist Rollbar client setting unset' do
@@ -68,21 +98,28 @@ describe SmokeDetector::JavaScriptMonitors do
68
98
 
69
99
  context 'ignoredMessages' do
70
100
  before do
71
- SmokeDetector.register_provider(:rollbar, 'key', {api_key: 'client_key', ignored_messages: ignored_messages})
101
+ SmokeDetector.register_provider(:rollbar, 'key', {api_key: 'client_key', ignoredMessages: ignored_messages})
72
102
  end
73
103
 
74
104
  shared_examples "a properly set ignoredMessages" do
75
105
  it 'injects the Rollbar JS snippet into the <head> with ignoredMessages set' do
76
106
  get '/widgets'
77
- script_content = Nokogiri::HTML(response.body).css('head script:contains("_rollbarConfig")').children.first
78
- position = /ignoredMessages:\s*#{Regexp.escape(ignored_messages.to_s)}/i =~ script_content
107
+ script_content = Nokogiri::HTML(response.body).css('head script:contains("_rollbarConfig")').children.first.to_s
108
+ position = /\"ignoredMessages\":#{Regexp.escape(ignored_messages.to_json)}/i =~ script_content
79
109
  expect(position).to_not be_nil
80
110
  end
111
+
112
+ it_behaves_like "a page with a valid rollbar json config"
81
113
  end
82
114
 
83
115
  context "with ignoredMessages Rollbar client setting configured" do
84
- let(:ignored_messages) { ['Error: Llamas are actually pretty cool.', 'Exception: The jerkstore called, and they ran out of you.'] }
116
+ let(:ignored_messages) { ["Error: Llamas are actually pretty cool.", "Exception: The jerkstore called, and they ran out of you."] }
85
117
  it_behaves_like "a properly set ignoredMessages"
118
+
119
+ context 'with snake-case setting' do
120
+ let(:client_settings) { { api_key: 'client_key', ignored_messages: ignored_messages } }
121
+ it_behaves_like "a properly set ignoredMessages"
122
+ end
86
123
  end
87
124
 
88
125
  context 'with ignoredMessages Rollbar client setting unset' do
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: smoke_detector
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.0
4
+ version: 1.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Chris Friedrich
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-11-13 00:00:00.000000000 Z
11
+ date: 2014-10-29 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails
@@ -52,6 +52,20 @@ dependencies:
52
52
  - - ~>
53
53
  - !ruby/object:Gem::Version
54
54
  version: 1.0.0
55
+ - !ruby/object:Gem::Dependency
56
+ name: jshintrb
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - '>='
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - '>='
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
55
69
  - !ruby/object:Gem::Dependency
56
70
  name: nokogiri
57
71
  requirement: !ruby/object:Gem::Requirement
@@ -172,20 +186,22 @@ executables: []
172
186
  extensions: []
173
187
  extra_rdoc_files: []
174
188
  files:
189
+ - MIT-LICENSE
190
+ - README.md
191
+ - Rakefile
192
+ - lib/smoke_detector.rb
175
193
  - lib/smoke_detector/controller_methods.rb
176
194
  - lib/smoke_detector/engine.rb
177
195
  - lib/smoke_detector/exceptions.rb
178
196
  - lib/smoke_detector/middleware/javascript_monitors.rb
197
+ - lib/smoke_detector/providers.rb
179
198
  - lib/smoke_detector/providers/airbrake.rb
180
199
  - lib/smoke_detector/providers/provider.rb
181
200
  - lib/smoke_detector/providers/rollbar.rb
182
- - lib/smoke_detector/providers.rb
183
201
  - lib/smoke_detector/version.rb
184
- - lib/smoke_detector.rb
185
202
  - lib/tasks/smoke_detector_tasks.rake
186
- - MIT-LICENSE
187
- - Rakefile
188
- - README.md
203
+ - spec/dummy/README.rdoc
204
+ - spec/dummy/Rakefile
189
205
  - spec/dummy/app/assets/javascripts/application.js
190
206
  - spec/dummy/app/assets/stylesheets/application.css
191
207
  - spec/dummy/app/controllers/application_controller.rb
@@ -194,6 +210,7 @@ files:
194
210
  - spec/dummy/app/models/widget.rb
195
211
  - spec/dummy/app/views/layouts/application.html.erb
196
212
  - spec/dummy/app/views/widgets/index.html.erb
213
+ - spec/dummy/config.ru
197
214
  - spec/dummy/config/application.rb
198
215
  - spec/dummy/config/boot.rb
199
216
  - spec/dummy/config/database.yml
@@ -210,7 +227,6 @@ files:
210
227
  - spec/dummy/config/initializers/wrap_parameters.rb
211
228
  - spec/dummy/config/locales/en.yml
212
229
  - spec/dummy/config/routes.rb
213
- - spec/dummy/config.ru
214
230
  - spec/dummy/db/schema.rb
215
231
  - spec/dummy/db/test.sqlite3
216
232
  - spec/dummy/log/test.log
@@ -218,8 +234,6 @@ files:
218
234
  - spec/dummy/public/422.html
219
235
  - spec/dummy/public/500.html
220
236
  - spec/dummy/public/favicon.ico
221
- - spec/dummy/Rakefile
222
- - spec/dummy/README.rdoc
223
237
  - spec/dummy/script/rails
224
238
  - spec/models/providers/airbrake_spec.rb
225
239
  - spec/models/providers/provider_spec.rb
@@ -252,7 +266,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
252
266
  version: '0'
253
267
  requirements: []
254
268
  rubyforge_project:
255
- rubygems_version: 2.0.14
269
+ rubygems_version: 2.4.1
256
270
  signing_key:
257
271
  specification_version: 4
258
272
  summary: Errors Alerts