rspec-webservice_matchers 4.9.0 → 4.12.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (32) hide show
  1. checksums.yaml +5 -5
  2. data/.github/workflows/ruby.yml +35 -0
  3. data/HISTORY.md +13 -0
  4. data/README.md +11 -15
  5. data/circle.yml +2 -0
  6. data/lib/rspec/webservice_matchers/be_fast.rb +2 -46
  7. data/lib/rspec/webservice_matchers/be_status.rb +3 -2
  8. data/lib/rspec/webservice_matchers/be_up.rb +2 -24
  9. data/lib/rspec/webservice_matchers/enforce_https_everywhere.rb +7 -6
  10. data/lib/rspec/webservice_matchers/have_a_valid_cert.rb +3 -2
  11. data/lib/rspec/webservice_matchers/redirect_helpers.rb +5 -4
  12. data/lib/rspec/webservice_matchers/redirect_permanently_to.rb +2 -1
  13. data/lib/rspec/webservice_matchers/redirect_temporarily_to.rb +2 -1
  14. data/lib/rspec/webservice_matchers/version.rb +2 -1
  15. data/lib/web_test/be_fast.rb +59 -0
  16. data/lib/web_test/be_up.rb +25 -0
  17. data/lib/web_test/util.rb +105 -0
  18. data/rspec-webservice_matchers.gemspec +10 -9
  19. data/spec/failure_matchers.rb +16 -0
  20. data/spec/rspec/webservice_matchers/{protcol_spec.rb → protocol_spec.rb} +5 -8
  21. data/spec/rspec/webservice_matchers/public_api_spec.rb +6 -5
  22. data/spec/rspec/webservice_matchers/redirect_spec.rb +19 -18
  23. data/spec/rspec/webservice_matchers/ssl_spec.rb +72 -47
  24. data/spec/spec_helper.rb +3 -54
  25. data/spec/web_mock_config.rb +54 -0
  26. data/spec/web_test/be_up_spec.rb +93 -0
  27. data/spec/web_test/util_spec.rb +6 -0
  28. metadata +53 -35
  29. data/lib/rspec/webservice_matchers/util.rb +0 -97
  30. data/spec/rspec/webservice_matchers/be_fast_spec.rb +0 -28
  31. data/spec/rspec/webservice_matchers/be_up_spec.rb +0 -94
  32. data/spec/rspec/webservice_matchers/page_speed_spec.rb +0 -37
@@ -0,0 +1,54 @@
1
+ # frozen_string_literal: true
2
+ require 'faraday'
3
+ require 'webmock/rspec'
4
+
5
+ RSpec.configure do |config|
6
+ config.before(:each) do
7
+ # HOSTS WHICH RETURN ERRORS
8
+ WebMock.stub_request(:any, /notfound.com/).to_return(status: 404)
9
+ WebMock.stub_request(:any, 'outoforder.com').to_return(status: 503)
10
+ WebMock.stub_request(:any, 'not-a-domain.com')
11
+ .to_raise(Faraday::ConnectionFailed.new('Failed to open TCP ' \
12
+ 'connection to asdhfjkahsdfadfd.com:80 ' \
13
+ '(getaddrinfo: nodename nor servname provided, ' \
14
+ 'or not known)'))
15
+
16
+ # FUNCTIONING WEB PAGES
17
+ WebMock.stub_request :any, 'http://a-page.com/a/page.txt'
18
+ WebMock.stub_request :any, 'www.website.com'
19
+
20
+ # A HOST WHICH DOESN'T SUPPORT HEAD
21
+ WebMock.stub_request(:head, 'appengine.com').to_return(status: 405)
22
+ WebMock.stub_request(:get, 'appengine.com').to_return(status: 200)
23
+
24
+ # FUNCTIONING REDIRECTS
25
+ WebMock.stub_request(:head, 'perm-redirector.com')
26
+ .to_return(status: 301,
27
+ body: '',
28
+ headers: { Location: 'http://www.website.com/' })
29
+
30
+ WebMock.stub_request(:any, 'temp-redirector.org')
31
+ .to_return(status: 302,
32
+ headers: { Location: 'http://a-page.com/a/page.txt' })
33
+
34
+ WebMock.stub_request(:any, 'temp-307-redirector.net')
35
+ .to_return(status: 307,
36
+ headers: { Location: 'http://a-page.com/a/page.txt' })
37
+
38
+ # TIMEOUT SCENARIOS
39
+ WebMock.stub_request(:any, 'www.timeout.com').to_timeout
40
+ WebMock.stub_request(:any, 'www.timeout-once.com').to_timeout
41
+ .then.to_return(body: 'abc')
42
+
43
+ # PageSpeed Insights API
44
+ key = ENV['WEBSERVICE_MATCHER_INSIGHTS_KEY']
45
+ WebMock.stub_request(:get,
46
+ 'https://www.googleapis.com/pagespeedonline/v2/' \
47
+ "runPagespeed?key=#{key}&screenshot=false" \
48
+ '&url=http://nonstop.qa')
49
+ .to_return(
50
+ status: 200,
51
+ body: IO.read('spec/fixtures/pagespeed.json'),
52
+ headers: {})
53
+ end
54
+ end
@@ -0,0 +1,93 @@
1
+ # frozen_string_literal: true
2
+ require 'spec_helper'
3
+ require 'web_test/be_up'
4
+
5
+ RSpec.describe WebTest::BeUp do
6
+ it { is_expected.not_to be_nil }
7
+
8
+ describe '#test' do
9
+ it 'handles a simple 200' do
10
+ result = WebTest::BeUp.test url: 'http://www.website.com/'
11
+ expect(result.success?).to be true
12
+ expect(result.status_code).to be 200
13
+ end
14
+
15
+ it 'handles a simple 200 as a domain' do
16
+ result = WebTest::BeUp.test domain: 'www.website.com'
17
+ expect(result.success?).to be true
18
+ expect(result.status_code).to be 200
19
+ end
20
+
21
+ it 'handles a 404' do
22
+ result = WebTest::BeUp.test url: 'http://notfound.com/no.txt'
23
+ expect(result.success?).to be false
24
+ expect(result.status_code).to be 404
25
+ end
26
+ end
27
+
28
+ describe WebTest::BeUp::TestResult do
29
+ it 'requires :success' do
30
+ expect do
31
+ WebTest::BeUp::TestResult.new { |r| r.status_code = 200 }
32
+ end.to raise_error(ArgumentError)
33
+ end
34
+
35
+ it 'requires :status_code' do
36
+ expect do
37
+ WebTest::BeUp::TestResult.new { |r| r.success = true }
38
+ end.to raise_error(ArgumentError)
39
+ end
40
+
41
+ it 'accepts boolean :success & integer :status_code' do
42
+ result = WebTest::BeUp::TestResult.new do |r|
43
+ r.status_code = 404
44
+ r.success = false
45
+ end
46
+ expect(result).to be_an_instance_of(WebTest::BeUp::TestResult)
47
+ end
48
+
49
+ it 'requires boolean :success' do
50
+ expect do
51
+ WebTest::BeUp::TestResult.new do |r|
52
+ r.status_code = 200
53
+ r.success = 1
54
+ end
55
+ end.to raise_error(ArgumentError)
56
+ end
57
+
58
+ it 'requires integer :status_code' do
59
+ expect do
60
+ WebTest::BeUp::TestResult.new do |r|
61
+ r.status_code = '404'
62
+ r.success = false
63
+ end
64
+ end.to raise_error(ArgumentError)
65
+ end
66
+
67
+ it 'cannot have status < 100' do
68
+ expect do
69
+ WebTest::BeUp::TestResult.new do |r|
70
+ r.status_code = -5
71
+ r.success = false
72
+ end
73
+ end.to raise_error(ArgumentError)
74
+ end
75
+
76
+ it 'cannot have status > 510' do
77
+ expect do
78
+ WebTest::BeUp::TestResult.new do |r|
79
+ r.status_code = 511
80
+ r.success = false
81
+ end
82
+ end.to raise_error(ArgumentError)
83
+ end
84
+
85
+ it 'allows status 510' do
86
+ result = WebTest::BeUp::TestResult.new do |r|
87
+ r.status_code = 510
88
+ r.success = false
89
+ end
90
+ expect(result).to be_an_instance_of(WebTest::BeUp::TestResult)
91
+ end
92
+ end
93
+ end
@@ -0,0 +1,6 @@
1
+ # frozen_string_literal: true
2
+ require 'web_test/util'
3
+
4
+ RSpec.describe WebTest::Util do
5
+ it { is_expected.not_to be_nil }
6
+ 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.9.0
4
+ version: 4.12.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Robb Shecter
8
- autorequire:
8
+ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-03-30 00:00:00.000000000 Z
11
+ date: 2021-01-21 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -16,14 +16,14 @@ dependencies:
16
16
  requirements:
17
17
  - - "~>"
18
18
  - !ruby/object:Gem::Version
19
- version: '1.3'
19
+ version: '2.0'
20
20
  type: :development
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
24
  - - "~>"
25
25
  - !ruby/object:Gem::Version
26
- version: '1.3'
26
+ version: '2.0'
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: pry
29
29
  requirement: !ruby/object:Gem::Requirement
@@ -95,21 +95,21 @@ dependencies:
95
95
  - !ruby/object:Gem::Version
96
96
  version: '0'
97
97
  - !ruby/object:Gem::Dependency
98
- name: rspec
98
+ name: faraday
99
99
  requirement: !ruby/object:Gem::Requirement
100
100
  requirements:
101
- - - "~>"
101
+ - - ">="
102
102
  - !ruby/object:Gem::Version
103
- version: '3.0'
103
+ version: '0'
104
104
  type: :runtime
105
105
  prerelease: false
106
106
  version_requirements: !ruby/object:Gem::Requirement
107
107
  requirements:
108
- - - "~>"
108
+ - - ">="
109
109
  - !ruby/object:Gem::Version
110
- version: '3.0'
110
+ version: '0'
111
111
  - !ruby/object:Gem::Dependency
112
- name: faraday
112
+ name: faraday_middleware
113
113
  requirement: !ruby/object:Gem::Requirement
114
114
  requirements:
115
115
  - - ">="
@@ -123,40 +123,55 @@ dependencies:
123
123
  - !ruby/object:Gem::Version
124
124
  version: '0'
125
125
  - !ruby/object:Gem::Dependency
126
- name: faraday_middleware
126
+ name: rspec-core
127
127
  requirement: !ruby/object:Gem::Requirement
128
128
  requirements:
129
- - - ">="
129
+ - - "~>"
130
130
  - !ruby/object:Gem::Version
131
- version: '0'
131
+ version: '3.0'
132
132
  type: :runtime
133
133
  prerelease: false
134
134
  version_requirements: !ruby/object:Gem::Requirement
135
135
  requirements:
136
- - - ">="
136
+ - - "~>"
137
137
  - !ruby/object:Gem::Version
138
- version: '0'
138
+ version: '3.0'
139
+ - !ruby/object:Gem::Dependency
140
+ name: rspec-expectations
141
+ requirement: !ruby/object:Gem::Requirement
142
+ requirements:
143
+ - - "~>"
144
+ - !ruby/object:Gem::Version
145
+ version: '3.0'
146
+ type: :runtime
147
+ prerelease: false
148
+ version_requirements: !ruby/object:Gem::Requirement
149
+ requirements:
150
+ - - "~>"
151
+ - !ruby/object:Gem::Version
152
+ version: '3.0'
139
153
  - !ruby/object:Gem::Dependency
140
154
  name: validated_object
141
155
  requirement: !ruby/object:Gem::Requirement
142
156
  requirements:
143
- - - ">="
157
+ - - "~>"
144
158
  - !ruby/object:Gem::Version
145
- version: '0'
159
+ version: 1.1.0
146
160
  type: :runtime
147
161
  prerelease: false
148
162
  version_requirements: !ruby/object:Gem::Requirement
149
163
  requirements:
150
- - - ">="
164
+ - - "~>"
151
165
  - !ruby/object:Gem::Version
152
- version: '0'
166
+ version: 1.1.0
153
167
  description: Black-box web app configuration testing
154
168
  email:
155
- - robb@weblaws.org
169
+ - robb@public.law
156
170
  executables: []
157
171
  extensions: []
158
172
  extra_rdoc_files: []
159
173
  files:
174
+ - ".github/workflows/ruby.yml"
160
175
  - ".gitignore"
161
176
  - Gemfile
162
177
  - HISTORY.md
@@ -173,23 +188,26 @@ files:
173
188
  - lib/rspec/webservice_matchers/redirect_helpers.rb
174
189
  - lib/rspec/webservice_matchers/redirect_permanently_to.rb
175
190
  - lib/rspec/webservice_matchers/redirect_temporarily_to.rb
176
- - lib/rspec/webservice_matchers/util.rb
177
191
  - lib/rspec/webservice_matchers/version.rb
192
+ - lib/web_test/be_fast.rb
193
+ - lib/web_test/be_up.rb
194
+ - lib/web_test/util.rb
178
195
  - rspec-webservice_matchers.gemspec
196
+ - spec/failure_matchers.rb
179
197
  - spec/fixtures/pagespeed.json
180
- - spec/rspec/webservice_matchers/be_fast_spec.rb
181
- - spec/rspec/webservice_matchers/be_up_spec.rb
182
- - spec/rspec/webservice_matchers/page_speed_spec.rb
183
- - spec/rspec/webservice_matchers/protcol_spec.rb
198
+ - spec/rspec/webservice_matchers/protocol_spec.rb
184
199
  - spec/rspec/webservice_matchers/public_api_spec.rb
185
200
  - spec/rspec/webservice_matchers/redirect_spec.rb
186
201
  - spec/rspec/webservice_matchers/ssl_spec.rb
187
202
  - spec/spec_helper.rb
203
+ - spec/web_mock_config.rb
204
+ - spec/web_test/be_up_spec.rb
205
+ - spec/web_test/util_spec.rb
188
206
  homepage: https://github.com/dogweather/rspec-webservice_matchers
189
207
  licenses:
190
208
  - MIT
191
209
  metadata: {}
192
- post_install_message:
210
+ post_install_message:
193
211
  rdoc_options: []
194
212
  require_paths:
195
213
  - lib
@@ -197,25 +215,25 @@ required_ruby_version: !ruby/object:Gem::Requirement
197
215
  requirements:
198
216
  - - ">="
199
217
  - !ruby/object:Gem::Version
200
- version: 2.1.0
218
+ version: 2.4.0
201
219
  required_rubygems_version: !ruby/object:Gem::Requirement
202
220
  requirements:
203
221
  - - ">="
204
222
  - !ruby/object:Gem::Version
205
223
  version: '0'
206
224
  requirements: []
207
- rubyforge_project:
208
- rubygems_version: 2.6.2
209
- signing_key:
225
+ rubygems_version: 3.2.6
226
+ signing_key:
210
227
  specification_version: 4
211
228
  summary: Black-box web app configuration testing
212
229
  test_files:
230
+ - spec/failure_matchers.rb
213
231
  - spec/fixtures/pagespeed.json
214
- - spec/rspec/webservice_matchers/be_fast_spec.rb
215
- - spec/rspec/webservice_matchers/be_up_spec.rb
216
- - spec/rspec/webservice_matchers/page_speed_spec.rb
217
- - spec/rspec/webservice_matchers/protcol_spec.rb
232
+ - spec/rspec/webservice_matchers/protocol_spec.rb
218
233
  - spec/rspec/webservice_matchers/public_api_spec.rb
219
234
  - spec/rspec/webservice_matchers/redirect_spec.rb
220
235
  - spec/rspec/webservice_matchers/ssl_spec.rb
221
236
  - spec/spec_helper.rb
237
+ - spec/web_mock_config.rb
238
+ - spec/web_test/be_up_spec.rb
239
+ - spec/web_test/util_spec.rb
@@ -1,97 +0,0 @@
1
- # frozen_string_literal: true
2
- require 'faraday'
3
- require 'faraday_middleware'
4
-
5
- TIMEOUT_IN_SECONDS = 5
6
- OPEN_TIMEOUT_IN_SECONDS = 5
7
-
8
- module RSpec
9
- module WebserviceMatchers
10
- module Util
11
- def self.error_message(errors)
12
- return errors.message if errors.respond_to?(:message)
13
-
14
- errors
15
- .map(&:to_s)
16
- .join('; ')
17
- .capitalize
18
- end
19
-
20
- def self.status(url_or_domain_name, follow: false)
21
- code = head(url_or_domain_name, follow: follow)[0]
22
- return code if code != 405
23
- get(url_or_domain_name, follow: follow)[0]
24
- end
25
-
26
- def self.head(url_or_domain_name, follow: false)
27
- request(:head, url_or_domain_name, follow: follow)
28
- end
29
-
30
- def self.get(url_or_domain_name, follow: false)
31
- request(:get, url_or_domain_name, follow: follow)
32
- end
33
-
34
- def self.request(method, url_or_domain_name, follow: false)
35
- url = make_url(url_or_domain_name)
36
- response = recheck_on_timeout { connection(follow: follow).send(method, url) }
37
- [response.status, response.headers]
38
- end
39
-
40
- # @return true if the given page has status 200,
41
- # and follow a few redirects if necessary.
42
- def self.up?(url_or_domain_name)
43
- url = make_url(url_or_domain_name)
44
- conn = connection(follow: true)
45
- response = recheck_on_timeout { conn.head(url) }
46
- response.status == 200
47
- end
48
-
49
- def self.valid_cert?(domain_name_or_url)
50
- try_ssl_connection(domain_name_or_url)
51
- true
52
- rescue
53
- # Not serving SSL, expired, or incorrect domain name in certificate
54
- false
55
- end
56
-
57
- def self.try_ssl_connection(domain_name_or_url)
58
- url = "https://#{remove_protocol(domain_name_or_url)}"
59
- recheck_on_timeout { connection.head(url) }
60
- true
61
- end
62
-
63
- # private
64
-
65
- def self.connection(follow: false)
66
- Faraday.new do |c|
67
- c.options[:timeout] = TIMEOUT_IN_SECONDS
68
- c.options[:open_timeout] = OPEN_TIMEOUT_IN_SECONDS
69
- c.use(FaradayMiddleware::FollowRedirects, limit: 4) if follow
70
- c.adapter :net_http
71
- end
72
- end
73
-
74
- # Ensure that the given string is a URL,
75
- # making it into one if necessary.
76
- def self.make_url(url_or_domain_name)
77
- if %r{^https?://} =~ url_or_domain_name
78
- url_or_domain_name
79
- else
80
- "http://#{url_or_domain_name}"
81
- end
82
- end
83
-
84
- # Normalize the input: remove 'http(s)://' if it's there
85
- def self.remove_protocol(domain_name_or_url)
86
- %r{^https?://(?<name>.+)$} =~ domain_name_or_url
87
- name || domain_name_or_url
88
- end
89
-
90
- def self.recheck_on_timeout
91
- yield
92
- rescue Faraday::Error::TimeoutError
93
- yield
94
- end
95
- end
96
- end
97
- end
@@ -1,28 +0,0 @@
1
- # frozen_string_literal: true
2
- require 'spec_helper'
3
- require 'rspec/webservice_matchers/be_fast'
4
- include RSpec::WebserviceMatchers
5
-
6
- describe BeFast do
7
- describe BeFast::TestResult do
8
- it 'requires :success' do
9
- expect {
10
- BeFast::TestResult.new {}
11
- }.to raise_error(ArgumentError, /success/i)
12
- end
13
-
14
- it 'requires :score' do
15
- expect {
16
- BeFast::TestResult.new { |r| r.success = true }
17
- }.to raise_error(ArgumentError, /score/i)
18
- end
19
- end
20
-
21
- describe '#test' do
22
- it 'handles a fast site' do
23
- result = BeFast.test url: 'http://nonstop.qa'
24
- expect( result.success? ).to be true
25
- expect( result.score ).to be >= 85
26
- end
27
- end
28
- end