rspec-webservice_matchers 1.1.1 → 1.1.2
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: 89064b80f84f72a5fd43886b4ef08bddfdd25eab
|
4
|
+
data.tar.gz: d0da9d277e5023d76d52fd5ca524492434266b10
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 338608ed8145220d05925acf13eb5bad0aba255f5452154af1c01f91e188142dd857a45e02caa2dbcf9f7bea05b50e4d190e70fc2635ce75dcc949f883ee0c0f
|
7
|
+
data.tar.gz: 0bc6ca8f292510bc568e5e1bf4735d76fe426bc104eec4454f919c6e261dc9f72bce935f4bc6ab5a89754b764822404b9cb92c47f558951d787d6867bbd0c8f9
|
@@ -14,8 +14,8 @@ module RSpec
|
|
14
14
|
|
15
15
|
# Test by seeing if Curl retrieves without complaining
|
16
16
|
begin
|
17
|
-
conn = Faraday.new
|
18
|
-
response = conn.head
|
17
|
+
conn = Faraday.new
|
18
|
+
response = conn.head("https://#{domain_name_or_url}")
|
19
19
|
return true
|
20
20
|
rescue
|
21
21
|
# Not serving SSL, expired, or incorrect domain name in certificate
|
@@ -37,18 +37,17 @@ module RSpec
|
|
37
37
|
# Pass successfully if we get a 301 to the place we intend.
|
38
38
|
RSpec::Matchers.define :redirect_permanently_to do |expected|
|
39
39
|
match do |url|
|
40
|
-
|
41
|
-
|
42
|
-
response.status == 301 && response.headers['
|
40
|
+
response = Faraday.new.head(url)
|
41
|
+
# binding.pry
|
42
|
+
response.status == 301 && response.headers['location'] == expected
|
43
43
|
end
|
44
44
|
end
|
45
45
|
|
46
46
|
# Pass successfully if we get a 302 or 307 to the place we intend.
|
47
47
|
RSpec::Matchers.define :redirect_temporarily_to do |expected|
|
48
48
|
match do |url|
|
49
|
-
|
50
|
-
response
|
51
|
-
[302, 307].include?(response.status) && response.headers['Location'] == expected
|
49
|
+
response = Faraday.new.head(url)
|
50
|
+
[302, 307].include?(response.status) && response.headers['location'] == expected
|
52
51
|
end
|
53
52
|
end
|
54
53
|
|
@@ -58,9 +57,8 @@ module RSpec
|
|
58
57
|
# 3. which is correctly configured
|
59
58
|
RSpec::Matchers.define :enforce_https_everywhere do
|
60
59
|
match do |domain_name|
|
61
|
-
|
62
|
-
|
63
|
-
new_url = response.headers['Location']
|
60
|
+
response = Faraday.new.head("http://#{domain_name}")
|
61
|
+
new_url = response.headers['location']
|
64
62
|
(response.status == 301) && (/https/ === new_url) && (RSpec::WebserviceMatchers.has_valid_ssl_cert?(new_url))
|
65
63
|
end
|
66
64
|
end
|
@@ -70,8 +68,7 @@ module RSpec
|
|
70
68
|
RSpec::Matchers.define :be_status do |expected|
|
71
69
|
match do |url_or_domain_name|
|
72
70
|
url = RSpec::WebserviceMatchers.make_url(url_or_domain_name)
|
73
|
-
|
74
|
-
response = conn.head
|
71
|
+
response = Faraday.new.head(url)
|
75
72
|
response.status == expected
|
76
73
|
end
|
77
74
|
end
|
@@ -81,11 +78,11 @@ module RSpec
|
|
81
78
|
RSpec::Matchers.define :be_up do
|
82
79
|
match do |url_or_domain_name|
|
83
80
|
url = RSpec::WebserviceMatchers.make_url(url_or_domain_name)
|
84
|
-
conn = Faraday.new
|
81
|
+
conn = Faraday.new do |c|
|
85
82
|
c.use FaradayMiddleware::FollowRedirects, limit: 5
|
86
83
|
c.adapter :net_http
|
87
84
|
end
|
88
|
-
response = conn.head
|
85
|
+
response = conn.head(url)
|
89
86
|
response.status == 200
|
90
87
|
end
|
91
88
|
end
|
@@ -1,11 +1,13 @@
|
|
1
1
|
require 'rspec/webservice_matchers'
|
2
2
|
|
3
3
|
#
|
4
|
-
# TODO: Set up a server for these. (Or a mock?)
|
4
|
+
# TODO: Set up a server for these. (Or a mock?)
|
5
|
+
# Faraday supports testing: we can use that now.
|
5
6
|
#
|
6
7
|
describe 'redirect_permanently_to' do
|
7
8
|
it 'passes when receiving a 301 to the given URL' do
|
8
9
|
expect('http://weblaws.org').to redirect_permanently_to('http://www.weblaws.org/')
|
10
|
+
expect('http://www.getquisitive.com/press-kit/').to redirect_permanently_to 'http://getquisitive.com/press-kit/'
|
9
11
|
end
|
10
12
|
end
|
11
13
|
|