rspec-webservice_matchers 4.1.3 → 4.2.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 5ccbc925ba70b2fddb0c1b6776ff354b7b657d2f
4
- data.tar.gz: b46de035aabfe0a31d25ad93a6b08e19f2ca1082
3
+ metadata.gz: cd87176a90aab44a6391d401105e413741b50f56
4
+ data.tar.gz: e5b968adb8506a6c1d53080d97ad5394675112f7
5
5
  SHA512:
6
- metadata.gz: 4a847e62a9941b08faf2c9621a53c0cd5a81959ae4a3c838aa7014ba851d32244fed4410879c0596cb415a504329177c22db4734edf5a089c47f2766fe31dcd2
7
- data.tar.gz: 6c08b056cdb287de5f15994edf52780f8e2bd7d9d9575c1e4875d8542310617f793757e61849108dc2ba6da4f49d78425b8084775ff4cff71626143e0109b0f2
6
+ metadata.gz: c58d717c4f4958d8d9c6974ae3d28115c776063ff6ba318541a9f9c8a1a260f49ace18f351eee60b88996997de803136f403c7003d5bc8a63957b9d52513db82
7
+ data.tar.gz: a0a3f88037789e31e8d92cbd03456e4c92dff3ae997970b136d64bc444fc821b8f73c73e4132c731bcde2aeb4e77c4d095af0fe5d8317fd9c6f92a00f99b46f8
@@ -4,3 +4,4 @@ require 'rspec/webservice_matchers/redirect_temporarily_to'
4
4
  require 'rspec/webservice_matchers/enforce_https_everywhere'
5
5
  require 'rspec/webservice_matchers/be_status'
6
6
  require 'rspec/webservice_matchers/be_up'
7
+ require 'rspec/webservice_matchers/be_fast'
@@ -0,0 +1,37 @@
1
+ require 'cgi'
2
+ require 'json'
3
+ require 'rspec/webservice_matchers/util'
4
+
5
+ module RSpec
6
+ module WebserviceMatchers
7
+ module BeFast
8
+ def self.parse(json:)
9
+ response = JSON.parse(json)
10
+ {
11
+ score: response['ruleGroups']['SPEED']['score']
12
+ }
13
+ end
14
+
15
+ def self.page_speed_score(url:)
16
+ url_param = CGI.escape(Util.make_url(url))
17
+ key = ENV['WEBSERVICE_MATCHER_INSIGHTS_KEY']
18
+ endpoint = 'https://www.googleapis.com/pagespeedonline/v2/runPagespeed'
19
+ api_url = "#{endpoint}?url=#{url_param}&screenshot=false&key=#{key}"
20
+ BeFast.parse(json: Excon.get(api_url).body)[:score]
21
+ end
22
+
23
+ RSpec::Matchers.define :be_fast do
24
+ score = nil
25
+
26
+ match do |url|
27
+ score = BeFast.page_speed_score(url: url)
28
+ score >= 90
29
+ end
30
+
31
+ failure_message do
32
+ "PageSpeed score is #{score}. Score must be 90 or greater."
33
+ end
34
+ end
35
+ end
36
+ end
37
+ end
@@ -1,5 +1,5 @@
1
1
  module RSpec
2
2
  module WebserviceMatchers
3
- VERSION = '4.1.3'
3
+ VERSION = '4.2.0'
4
4
  end
5
5
  end
@@ -0,0 +1,401 @@
1
+ {
2
+ "kind": "pagespeedonline#result",
3
+ "id": "https://nonstop.qa/",
4
+ "responseCode": 200,
5
+ "title": "Nonstop QA - Continuous web quality + SLA compliance monitoring",
6
+ "ruleGroups": {
7
+ "SPEED": {
8
+ "score": 85
9
+ }
10
+ },
11
+ "pageStats": {
12
+ "numberResources": 15,
13
+ "numberHosts": 9,
14
+ "totalRequestBytes": "2605",
15
+ "numberStaticResources": 9,
16
+ "htmlResponseBytes": "10948",
17
+ "cssResponseBytes": "159008",
18
+ "imageResponseBytes": "5087",
19
+ "javascriptResponseBytes": "493092",
20
+ "otherResponseBytes": "90382",
21
+ "numberJsResources": 6,
22
+ "numberCssResources": 2
23
+ },
24
+ "formattedResults": {
25
+ "locale": "en_US",
26
+ "ruleResults": {
27
+ "AvoidLandingPageRedirects": {
28
+ "localizedRuleName": "Avoid landing page redirects",
29
+ "ruleImpact": 0.0,
30
+ "groups": [
31
+ "SPEED"
32
+ ],
33
+ "summary": {
34
+ "format": "Your page has no redirects. Learn more about {{BEGIN_LINK}}avoiding landing page redirects{{END_LINK}}.",
35
+ "args": [
36
+ {
37
+ "type": "HYPERLINK",
38
+ "key": "LINK",
39
+ "value": "https://developers.google.com/speed/docs/insights/AvoidRedirects"
40
+ }
41
+ ]
42
+ }
43
+ },
44
+ "EnableGzipCompression": {
45
+ "localizedRuleName": "Enable compression",
46
+ "ruleImpact": 0.0,
47
+ "groups": [
48
+ "SPEED"
49
+ ],
50
+ "summary": {
51
+ "format": "You have compression enabled. Learn more about {{BEGIN_LINK}}enabling compression{{END_LINK}}.",
52
+ "args": [
53
+ {
54
+ "type": "HYPERLINK",
55
+ "key": "LINK",
56
+ "value": "https://developers.google.com/speed/docs/insights/EnableCompression"
57
+ }
58
+ ]
59
+ }
60
+ },
61
+ "LeverageBrowserCaching": {
62
+ "localizedRuleName": "Leverage browser caching",
63
+ "ruleImpact": 1.4910714285714286,
64
+ "groups": [
65
+ "SPEED"
66
+ ],
67
+ "summary": {
68
+ "format": "Setting an expiry date or a maximum age in the HTTP headers for static resources instructs the browser to load previously downloaded resources from local disk rather than over the network."
69
+ },
70
+ "urlBlocks": [
71
+ {
72
+ "header": {
73
+ "format": "{{BEGIN_LINK}}Leverage browser caching{{END_LINK}} for the following cacheable resources:",
74
+ "args": [
75
+ {
76
+ "type": "HYPERLINK",
77
+ "key": "LINK",
78
+ "value": "https://developers.google.com/speed/docs/insights/LeverageBrowserCaching"
79
+ }
80
+ ]
81
+ },
82
+ "urls": [
83
+ {
84
+ "result": {
85
+ "format": "{{URL}} (expiration not specified)",
86
+ "args": [
87
+ {
88
+ "type": "URL",
89
+ "key": "URL",
90
+ "value": "https://d36ee2fcip1434.cloudfront.net/track.js"
91
+ }
92
+ ]
93
+ }
94
+ },
95
+ {
96
+ "result": {
97
+ "format": "{{URL}} ({{LIFETIME}})",
98
+ "args": [
99
+ {
100
+ "type": "URL",
101
+ "key": "URL",
102
+ "value": "https://js-agent.newrelic.com/nr-852.min.js"
103
+ },
104
+ {
105
+ "type": "DURATION",
106
+ "key": "LIFETIME",
107
+ "value": "60 minutes"
108
+ }
109
+ ]
110
+ }
111
+ },
112
+ {
113
+ "result": {
114
+ "format": "{{URL}} ({{LIFETIME}})",
115
+ "args": [
116
+ {
117
+ "type": "URL",
118
+ "key": "URL",
119
+ "value": "https://widget.uservoice.com/aviNttqTqP8TqdZep6xA.js"
120
+ },
121
+ {
122
+ "type": "DURATION",
123
+ "key": "LIFETIME",
124
+ "value": "2 hours"
125
+ }
126
+ ]
127
+ }
128
+ }
129
+ ]
130
+ }
131
+ ]
132
+ },
133
+ "MainResourceServerResponseTime": {
134
+ "localizedRuleName": "Reduce server response time",
135
+ "ruleImpact": 0.0,
136
+ "groups": [
137
+ "SPEED"
138
+ ],
139
+ "summary": {
140
+ "format": "Your server responded quickly. Learn more about {{BEGIN_LINK}}server response time optimization{{END_LINK}}.",
141
+ "args": [
142
+ {
143
+ "type": "HYPERLINK",
144
+ "key": "LINK",
145
+ "value": "https://developers.google.com/speed/docs/insights/Server"
146
+ }
147
+ ]
148
+ }
149
+ },
150
+ "MinifyCss": {
151
+ "localizedRuleName": "Minify CSS",
152
+ "ruleImpact": 0.0,
153
+ "groups": [
154
+ "SPEED"
155
+ ],
156
+ "summary": {
157
+ "format": "Your CSS is minified. Learn more about {{BEGIN_LINK}}minifying CSS{{END_LINK}}.",
158
+ "args": [
159
+ {
160
+ "type": "HYPERLINK",
161
+ "key": "LINK",
162
+ "value": "https://developers.google.com/speed/docs/insights/MinifyResources"
163
+ }
164
+ ]
165
+ }
166
+ },
167
+ "MinifyHTML": {
168
+ "localizedRuleName": "Minify HTML",
169
+ "ruleImpact": 0.0,
170
+ "groups": [
171
+ "SPEED"
172
+ ],
173
+ "summary": {
174
+ "format": "Your HTML is minified. Learn more about {{BEGIN_LINK}}minifying HTML{{END_LINK}}.",
175
+ "args": [
176
+ {
177
+ "type": "HYPERLINK",
178
+ "key": "LINK",
179
+ "value": "https://developers.google.com/speed/docs/insights/MinifyResources"
180
+ }
181
+ ]
182
+ }
183
+ },
184
+ "MinifyJavaScript": {
185
+ "localizedRuleName": "Minify JavaScript",
186
+ "ruleImpact": 0.0,
187
+ "groups": [
188
+ "SPEED"
189
+ ],
190
+ "summary": {
191
+ "format": "Your JavaScript content is minified. Learn more about {{BEGIN_LINK}}minifying JavaScript{{END_LINK}}.",
192
+ "args": [
193
+ {
194
+ "type": "HYPERLINK",
195
+ "key": "LINK",
196
+ "value": "https://developers.google.com/speed/docs/insights/MinifyResources"
197
+ }
198
+ ]
199
+ }
200
+ },
201
+ "MinimizeRenderBlockingResources": {
202
+ "localizedRuleName": "Eliminate render-blocking JavaScript and CSS in above-the-fold content",
203
+ "ruleImpact": 12.0,
204
+ "groups": [
205
+ "SPEED"
206
+ ],
207
+ "summary": {
208
+ "format": "Your page has {{NUM_SCRIPTS}} blocking script resources and {{NUM_CSS}} blocking CSS resources. This causes a delay in rendering your page.",
209
+ "args": [
210
+ {
211
+ "type": "INT_LITERAL",
212
+ "key": "NUM_SCRIPTS",
213
+ "value": "1"
214
+ },
215
+ {
216
+ "type": "INT_LITERAL",
217
+ "key": "NUM_CSS",
218
+ "value": "2"
219
+ }
220
+ ]
221
+ },
222
+ "urlBlocks": [
223
+ {
224
+ "header": {
225
+ "format": "None of the above-the-fold content on your page could be rendered without waiting for the following resources to load. Try to defer or asynchronously load blocking resources, or inline the critical portions of those resources directly in the HTML."
226
+ }
227
+ },
228
+ {
229
+ "header": {
230
+ "format": "{{BEGIN_LINK}}Remove render-blocking JavaScript{{END_LINK}}:",
231
+ "args": [
232
+ {
233
+ "type": "HYPERLINK",
234
+ "key": "LINK",
235
+ "value": "https://developers.google.com/speed/docs/insights/BlockingJS"
236
+ }
237
+ ]
238
+ },
239
+ "urls": [
240
+ {
241
+ "result": {
242
+ "format": "{{URL}}",
243
+ "args": [
244
+ {
245
+ "type": "URL",
246
+ "key": "URL",
247
+ "value": "https://nonstop.qa/assets/application-88cb88cc2fe9323a313583fee2897be7.js"
248
+ }
249
+ ]
250
+ }
251
+ }
252
+ ]
253
+ },
254
+ {
255
+ "header": {
256
+ "format": "{{BEGIN_LINK}}Optimize CSS Delivery{{END_LINK}} of the following:",
257
+ "args": [
258
+ {
259
+ "type": "HYPERLINK",
260
+ "key": "LINK",
261
+ "value": "https://developers.google.com/speed/docs/insights/OptimizeCSSDelivery"
262
+ }
263
+ ]
264
+ },
265
+ "urls": [
266
+ {
267
+ "result": {
268
+ "format": "{{URL}}",
269
+ "args": [
270
+ {
271
+ "type": "URL",
272
+ "key": "URL",
273
+ "value": "https://nonstop.qa/assets/application-105940a78fb9a03a8f465ff1d0b7a940.css"
274
+ }
275
+ ]
276
+ }
277
+ },
278
+ {
279
+ "result": {
280
+ "format": "{{URL}}",
281
+ "args": [
282
+ {
283
+ "type": "URL",
284
+ "key": "URL",
285
+ "value": "https://fonts.googleapis.com/css?family=Signika:300,700"
286
+ }
287
+ ]
288
+ }
289
+ }
290
+ ]
291
+ }
292
+ ]
293
+ },
294
+ "OptimizeImages": {
295
+ "localizedRuleName": "Optimize images",
296
+ "ruleImpact": 0.1125,
297
+ "groups": [
298
+ "SPEED"
299
+ ],
300
+ "summary": {
301
+ "format": "Properly formatting and compressing images can save many bytes of data."
302
+ },
303
+ "urlBlocks": [
304
+ {
305
+ "header": {
306
+ "format": "{{BEGIN_LINK}}Optimize the following images{{END_LINK}} to reduce their size by {{SIZE_IN_BYTES}} ({{PERCENTAGE}} reduction).",
307
+ "args": [
308
+ {
309
+ "type": "HYPERLINK",
310
+ "key": "LINK",
311
+ "value": "https://developers.google.com/speed/docs/insights/OptimizeImages"
312
+ },
313
+ {
314
+ "type": "BYTES",
315
+ "key": "SIZE_IN_BYTES",
316
+ "value": "816B"
317
+ },
318
+ {
319
+ "type": "PERCENTAGE",
320
+ "key": "PERCENTAGE",
321
+ "value": "42%"
322
+ }
323
+ ]
324
+ },
325
+ "urls": [
326
+ {
327
+ "result": {
328
+ "format": "Losslessly compressing {{URL}} could save {{SIZE_IN_BYTES}} ({{PERCENTAGE}} reduction).",
329
+ "args": [
330
+ {
331
+ "type": "URL",
332
+ "key": "URL",
333
+ "value": "https://widget.uservoice.com/pkg/clients/widget2/tab-right-dark-da2413549ce324fc421ae86a0e5881ee.png"
334
+ },
335
+ {
336
+ "type": "BYTES",
337
+ "key": "SIZE_IN_BYTES",
338
+ "value": "816B"
339
+ },
340
+ {
341
+ "type": "PERCENTAGE",
342
+ "key": "PERCENTAGE",
343
+ "value": "42%"
344
+ }
345
+ ]
346
+ }
347
+ }
348
+ ]
349
+ }
350
+ ]
351
+ },
352
+ "PrioritizeVisibleContent": {
353
+ "localizedRuleName": "Prioritize visible content",
354
+ "ruleImpact": 2.0,
355
+ "groups": [
356
+ "SPEED"
357
+ ],
358
+ "summary": {
359
+ "format": "Your page requires additional network round trips to render the above-the-fold content. For best performance, reduce the amount of HTML needed to render above-the-fold content."
360
+ },
361
+ "urlBlocks": [
362
+ {
363
+ "header": {
364
+ "format": "The entire HTML response was not sufficient to render the above-the-fold content. This usually indicates that additional resources, loaded after HTML parsing, were required to render above-the-fold content. {{BEGIN_LINK}}Prioritize visible content{{END_LINK}} that is needed for rendering above-the-fold by including it directly in the HTML response.",
365
+ "args": [
366
+ {
367
+ "type": "HYPERLINK",
368
+ "key": "LINK",
369
+ "value": "https://developers.google.com/speed/docs/insights/PrioritizeVisibleContent"
370
+ }
371
+ ]
372
+ },
373
+ "urls": [
374
+ {
375
+ "result": {
376
+ "format": "Only about {{PERCENTAGE}} of the final above-the-fold content could be rendered with the full HTML response {{SCREENSHOT}}.",
377
+ "args": [
378
+ {
379
+ "type": "PERCENTAGE",
380
+ "key": "PERCENTAGE",
381
+ "value": "4%"
382
+ },
383
+ {
384
+ "type": "SNAPSHOT_RECT",
385
+ "key": "SCREENSHOT",
386
+ "value": "snapshot:3"
387
+ }
388
+ ]
389
+ }
390
+ }
391
+ ]
392
+ }
393
+ ]
394
+ }
395
+ }
396
+ },
397
+ "version": {
398
+ "major": 1,
399
+ "minor": 15
400
+ }
401
+ }
@@ -0,0 +1,23 @@
1
+ # Specs for all of the PageSpeed code and matchers.
2
+
3
+ require 'spec_helper'
4
+ require 'rspec/webservice_matchers'
5
+ require 'rspec/webservice_matchers/util'
6
+
7
+ SAMPLE_JSON_RESPONSE = 'spec/fixtures/pagespeed.json'
8
+
9
+ describe RSpec::WebserviceMatchers::BeFast do
10
+ describe '#parse' do
11
+ it 'can parse the overall score' do
12
+ api_response = File.read(SAMPLE_JSON_RESPONSE)
13
+ data = RSpec::WebserviceMatchers::BeFast.parse(json: api_response)
14
+ expect(data[:score]).to eq(85)
15
+ end
16
+ end
17
+
18
+ describe '#be_fast' do
19
+ it 'performs a Google PageSpeed Insights API query on a slow site' do
20
+ expect('nonstop.qa').not_to be_fast
21
+ end
22
+ end
23
+ end
data/spec/spec_helper.rb CHANGED
@@ -18,7 +18,20 @@ RSpec.configure do |config|
18
18
 
19
19
  # Timeout scenarios
20
20
  WebMock.stub_request(:any, 'www.timeout.com').to_timeout
21
- WebMock.stub_request(:any, 'www.timeout-once.com').to_timeout.then.to_return({body: 'abc'})
21
+ WebMock.stub_request(:any, 'www.timeout-once.com').to_timeout.then.to_return(body: 'abc')
22
+
23
+ # Insights API
24
+ key = ENV['WEBSERVICE_MATCHER_INSIGHTS_KEY']
25
+ WebMock.stub_request(:get, "https://www.googleapis.com/pagespeedonline/v2/runPagespeed?key=#{key}&screenshot=false&url=http://nonstop.qa")
26
+ .with(headers:
27
+ {
28
+ 'Host' => 'www.googleapis.com:443',
29
+ 'User-Agent' => 'excon/0.45.4'
30
+ })
31
+ .to_return(
32
+ status: 200,
33
+ body: IO.read('spec/fixtures/pagespeed.json'),
34
+ headers: {})
22
35
 
23
36
  WebMock.allow_net_connect!
24
37
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rspec-webservice_matchers
3
3
  version: !ruby/object:Gem::Version
4
- version: 4.1.3
4
+ version: 4.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Robb Shecter
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-02-16 00:00:00.000000000 Z
11
+ date: 2016-02-26 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -136,6 +136,7 @@ files:
136
136
  - README.md
137
137
  - Rakefile
138
138
  - lib/rspec/webservice_matchers.rb
139
+ - lib/rspec/webservice_matchers/be_fast.rb
139
140
  - lib/rspec/webservice_matchers/be_status.rb
140
141
  - lib/rspec/webservice_matchers/be_up.rb
141
142
  - lib/rspec/webservice_matchers/enforce_https_everywhere.rb
@@ -146,6 +147,8 @@ files:
146
147
  - lib/rspec/webservice_matchers/util.rb
147
148
  - lib/rspec/webservice_matchers/version.rb
148
149
  - rspec-webservice_matchers.gemspec
150
+ - spec/fixtures/pagespeed.json
151
+ - spec/rspec/webservice_matchers/page_speed_spec.rb
149
152
  - spec/rspec/webservice_matchers/protcol_spec.rb
150
153
  - spec/rspec/webservice_matchers/public_api_spec.rb
151
154
  - spec/rspec/webservice_matchers/redirect_spec.rb
@@ -176,6 +179,8 @@ signing_key:
176
179
  specification_version: 4
177
180
  summary: Black-box web app configuration testing
178
181
  test_files:
182
+ - spec/fixtures/pagespeed.json
183
+ - spec/rspec/webservice_matchers/page_speed_spec.rb
179
184
  - spec/rspec/webservice_matchers/protcol_spec.rb
180
185
  - spec/rspec/webservice_matchers/public_api_spec.rb
181
186
  - spec/rspec/webservice_matchers/redirect_spec.rb