rspec-webservice_matchers 4.2.0 → 4.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 74cae05a568aaf50d4a5024783e63f569416dde2
|
4
|
+
data.tar.gz: 6ff3a433c3867e935422a9ad9b8d175cc9104299
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 63d78bb3502bdcbf84758a7962da667fdba8a83f7732bd4a05d746e8d424ca6c3312bd8f025202aebbc7b7f908494ff1544c9e2c91b3c46c78843a297eccb5fa
|
7
|
+
data.tar.gz: cdb219e308ec0c5402f304e49247bcdfe011fa489e0f48dd013e41388c798cd8c1c2cd201327b50b43e164b39b33debf4ec958d675873ff43afb167ec4947ab5
|
data/README.md
CHANGED
@@ -28,10 +28,11 @@ These new RSpec matchers:
|
|
28
28
|
|
29
29
|
| Notes
|
30
30
|
-------------------------------|------------------------------------------------
|
31
|
-
**be_status** | A low-level matcher to explicitly check for a 200, 503, or any other code
|
32
31
|
**be_up** | Looks for a 200, but will follow up to four redirects
|
32
|
+
**be_fast** | Checks for Google [PageSpeed](https://developers.google.com/speed/pagespeed/insights/) score >= 90. Requires a [Google website API key](https://developers.google.com/speed/docs/insights/v2/getting-started) in the environment variable `WEBSERVICE_MATCHER_INSIGHTS_KEY`.
|
33
|
+
**enforce_https_everywhere** | Passes if the site will _only_ allow SSL connections. See the [EFF project, HTTPS Everywhere](https://www.eff.org/https-everywhere)
|
33
34
|
**have_a_valid_cert** | Will fail if there's no cert, or it's expired or incorrectly configured
|
34
|
-
**
|
35
|
+
**be_status** | A low-level matcher to explicitly check for a 200, 503, or any other code
|
35
36
|
**redirect_permanently_to** | Checks for 301 and a correct destination URL
|
36
37
|
**redirect_temporarily_to** | Checks for 302 or 307 and a correct destination
|
37
38
|
|
@@ -47,6 +48,7 @@ require 'rspec/webservice_matchers'
|
|
47
48
|
describe 'My app' do
|
48
49
|
context 'www.myapp.com' do
|
49
50
|
it { should be_up }
|
51
|
+
it { should be_fast }
|
50
52
|
it { should have_a_valid_cert }
|
51
53
|
end
|
52
54
|
|
@@ -15,8 +15,13 @@ module RSpec
|
|
15
15
|
def self.page_speed_score(url:)
|
16
16
|
url_param = CGI.escape(Util.make_url(url))
|
17
17
|
key = ENV['WEBSERVICE_MATCHER_INSIGHTS_KEY']
|
18
|
+
if key.nil?
|
19
|
+
fail 'be_fast requires the WEBSERVICE_MATCHER_INSIGHTS_KEY '\
|
20
|
+
'environment variable to be set to a Google PageSpeed '\
|
21
|
+
'Insights API key.'
|
22
|
+
end
|
18
23
|
endpoint = 'https://www.googleapis.com/pagespeedonline/v2/runPagespeed'
|
19
|
-
api_url
|
24
|
+
api_url = "#{endpoint}?url=#{url_param}&screenshot=false&key=#{key}"
|
20
25
|
BeFast.parse(json: Excon.get(api_url).body)[:score]
|
21
26
|
end
|
22
27
|
|
@@ -19,5 +19,18 @@ describe RSpec::WebserviceMatchers::BeFast do
|
|
19
19
|
it 'performs a Google PageSpeed Insights API query on a slow site' do
|
20
20
|
expect('nonstop.qa').not_to be_fast
|
21
21
|
end
|
22
|
+
|
23
|
+
it 'raises a friendly error if the api key has not been set' do
|
24
|
+
# Remove the key
|
25
|
+
key = ENV['WEBSERVICE_MATCHER_INSIGHTS_KEY']
|
26
|
+
ENV['WEBSERVICE_MATCHER_INSIGHTS_KEY'] = nil
|
27
|
+
|
28
|
+
expect {
|
29
|
+
expect('nonstop.qa').not_to be_fast
|
30
|
+
}.to raise_error(RuntimeError, /API keyx/)
|
31
|
+
|
32
|
+
# Replace the key
|
33
|
+
ENV['WEBSERVICE_MATCHER_INSIGHTS_KEY'] = key
|
34
|
+
end
|
22
35
|
end
|
23
36
|
end
|