rspec-webservice_matchers 4.2.0 → 4.3.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: cd87176a90aab44a6391d401105e413741b50f56
4
- data.tar.gz: e5b968adb8506a6c1d53080d97ad5394675112f7
3
+ metadata.gz: 74cae05a568aaf50d4a5024783e63f569416dde2
4
+ data.tar.gz: 6ff3a433c3867e935422a9ad9b8d175cc9104299
5
5
  SHA512:
6
- metadata.gz: c58d717c4f4958d8d9c6974ae3d28115c776063ff6ba318541a9f9c8a1a260f49ace18f351eee60b88996997de803136f403c7003d5bc8a63957b9d52513db82
7
- data.tar.gz: a0a3f88037789e31e8d92cbd03456e4c92dff3ae997970b136d64bc444fc821b8f73c73e4132c731bcde2aeb4e77c4d095af0fe5d8317fd9c6f92a00f99b46f8
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
- **enforce_https_everywhere** | Passes if the site will _only_ allow SSL connections. See the [EFF project, HTTP Everywhere](https://www.eff.org/https-everywhere)
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 = "#{endpoint}?url=#{url_param}&screenshot=false&key=#{key}"
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
 
@@ -1,5 +1,5 @@
1
1
  module RSpec
2
2
  module WebserviceMatchers
3
- VERSION = '4.2.0'
3
+ VERSION = '4.3.0'
4
4
  end
5
5
  end
@@ -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
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rspec-webservice_matchers
3
3
  version: !ruby/object:Gem::Version
4
- version: 4.2.0
4
+ version: 4.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Robb Shecter