rspec-webservice_matchers 4.0.2 → 4.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/rspec/webservice_matchers/redirect_helpers.rb +64 -0
- data/lib/rspec/webservice_matchers/redirect_permanently_to.rb +9 -27
- data/lib/rspec/webservice_matchers/redirect_temporarily_to.rb +8 -27
- data/lib/rspec/webservice_matchers/util.rb +1 -13
- data/lib/rspec/webservice_matchers/version.rb +1 -1
- metadata +3 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 2b238603ebf7eb99200ebeed083b9d902362abce
|
4
|
+
data.tar.gz: e66536bd2aebb782227b02ad3d8aa2f3f01d2f04
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 336f8d6acad41a9a274d8cdd816522a4545bc6a3d7c24d8ed6dd2c98e588036b35dd176890752e1e9e1997bd18f687066688a79b9e1aecfd103924d7bd3f7c15
|
7
|
+
data.tar.gz: 34abd12248f8b59a2f058f203f9bd67d321147760fa3f5543fe440533701d468bf64922d746c208d442c334552c0845844fc415e3ccd47196fe7188f9ecae575
|
@@ -0,0 +1,64 @@
|
|
1
|
+
require 'rspec/webservice_matchers/util'
|
2
|
+
|
3
|
+
module RSpec
|
4
|
+
module WebserviceMatchers
|
5
|
+
module RedirectHelpers
|
6
|
+
def redirect_failure_message(exception, status, actual_location, kind)
|
7
|
+
return Util.error_message(exception) if exception
|
8
|
+
|
9
|
+
errors = []
|
10
|
+
unless redirect? status, kind: kind
|
11
|
+
errors << "received a #{kind_for(status)} redirect"
|
12
|
+
end
|
13
|
+
unless locations_match? expected, actual_location
|
14
|
+
errors << "received location #{actual_location}"
|
15
|
+
end
|
16
|
+
unless redirect? status
|
17
|
+
errors << "not a redirect: received status #{status}"
|
18
|
+
end
|
19
|
+
|
20
|
+
Util.error_message(errors)
|
21
|
+
end
|
22
|
+
|
23
|
+
def redirects_correctly?(status, actual_loc, expected_loc, kind)
|
24
|
+
redirect?(status, kind: kind) && locations_match?(expected_loc, actual_loc)
|
25
|
+
end
|
26
|
+
|
27
|
+
def redirect_result(url_or_domain_name)
|
28
|
+
status, headers = Util.head(url_or_domain_name)
|
29
|
+
[status, headers['location']]
|
30
|
+
end
|
31
|
+
|
32
|
+
def locations_match?(expected, actual)
|
33
|
+
actual =~ %r{#{expected}/?}
|
34
|
+
end
|
35
|
+
|
36
|
+
def redirect?(status, kind: nil)
|
37
|
+
case kind
|
38
|
+
when :permanent
|
39
|
+
permanent_redirect?(status)
|
40
|
+
when :temporary
|
41
|
+
temp_redirect?(status)
|
42
|
+
else
|
43
|
+
temp_redirect?(status) || permanent_redirect?(status)
|
44
|
+
end
|
45
|
+
end
|
46
|
+
|
47
|
+
def temp_redirect?(status)
|
48
|
+
[302, 307].include?(status)
|
49
|
+
end
|
50
|
+
|
51
|
+
def permanent_redirect?(status)
|
52
|
+
status == 301
|
53
|
+
end
|
54
|
+
|
55
|
+
def kind_for(status)
|
56
|
+
{
|
57
|
+
301 => 'permanent',
|
58
|
+
302 => 'temporary',
|
59
|
+
307 => 'temporary'
|
60
|
+
}[status]
|
61
|
+
end
|
62
|
+
end
|
63
|
+
end
|
64
|
+
end
|
@@ -1,44 +1,26 @@
|
|
1
1
|
require 'rspec/webservice_matchers/util'
|
2
|
+
require 'rspec/webservice_matchers/redirect_helpers'
|
2
3
|
|
3
4
|
module RSpec
|
4
5
|
module WebserviceMatchers
|
5
6
|
module RedirectPermanentlyTo
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
7
|
+
RSpec::Matchers.define :redirect_permanently_to do |expected_location|
|
8
|
+
include RedirectHelpers
|
9
|
+
kind = :permanent
|
10
|
+
status = actual_location = exception = nil
|
10
11
|
|
11
12
|
match do |url_or_domain_name|
|
12
13
|
begin
|
13
|
-
status,
|
14
|
-
actual_location
|
15
|
-
|
16
|
-
Util.permanent_redirect?(status) &&
|
17
|
-
expected_location?(expected, actual_location)
|
18
|
-
rescue Exception => e
|
14
|
+
status, actual_location = redirect_result(url_or_domain_name)
|
15
|
+
redirects_correctly?(status, actual_location, expected_location, kind)
|
16
|
+
rescue Faraday::ConnectionFailed => e
|
19
17
|
exception = e
|
20
18
|
false
|
21
19
|
end
|
22
20
|
end
|
23
21
|
|
24
22
|
failure_message do
|
25
|
-
|
26
|
-
|
27
|
-
errors = []
|
28
|
-
if Util.temp_redirect? status
|
29
|
-
errors << "received a temporary redirect, status #{status}"
|
30
|
-
end
|
31
|
-
unless expected_location?(expected, actual_location)
|
32
|
-
errors << "received location #{actual_location}"
|
33
|
-
end
|
34
|
-
unless Util.redirect? status
|
35
|
-
errors << "not a redirect: received status #{status}"
|
36
|
-
end
|
37
|
-
Util.error_message(errors)
|
38
|
-
end
|
39
|
-
|
40
|
-
def expected_location?(expected, actual)
|
41
|
-
actual =~ %r{#{expected}/?}
|
23
|
+
redirect_failure_message(exception, status, actual_location, kind)
|
42
24
|
end
|
43
25
|
end
|
44
26
|
end
|
@@ -1,45 +1,26 @@
|
|
1
1
|
require 'rspec/webservice_matchers/util'
|
2
|
+
require 'rspec/webservice_matchers/redirect_helpers'
|
2
3
|
|
3
4
|
module RSpec
|
4
5
|
module WebserviceMatchers
|
5
6
|
module RedirectTemporarilyTo
|
6
|
-
|
7
|
-
|
8
|
-
|
7
|
+
RSpec::Matchers.define :redirect_temporarily_to do |expected_location|
|
8
|
+
include RedirectHelpers
|
9
|
+
kind = :temporary
|
9
10
|
status = actual_location = exception = nil
|
10
11
|
|
11
12
|
match do |url_or_domain_name|
|
12
13
|
begin
|
13
|
-
status,
|
14
|
-
actual_location
|
15
|
-
|
16
|
-
Util.temp_redirect?(status) &&
|
17
|
-
expected_location?(expected, actual_location)
|
18
|
-
rescue Exception => e
|
14
|
+
status, actual_location = redirect_result(url_or_domain_name)
|
15
|
+
redirects_correctly?(status, actual_location, expected_location, kind)
|
16
|
+
rescue Faraday::ConnectionFailed => e
|
19
17
|
exception = e
|
20
18
|
false
|
21
19
|
end
|
22
20
|
end
|
23
21
|
|
24
22
|
failure_message do
|
25
|
-
|
26
|
-
|
27
|
-
errors = []
|
28
|
-
if Util.permanent_redirect? status
|
29
|
-
errors << 'received a permanent redirect'
|
30
|
-
end
|
31
|
-
unless expected_location? expected, actual_location
|
32
|
-
errors << "received location #{actual_location}"
|
33
|
-
end
|
34
|
-
unless Util.redirect? status
|
35
|
-
errors << "not a redirect: received status #{status}"
|
36
|
-
end
|
37
|
-
|
38
|
-
Util.error_message(errors)
|
39
|
-
end
|
40
|
-
|
41
|
-
def expected_location?(expected, actual)
|
42
|
-
actual =~ %r{#{expected}/?}
|
23
|
+
redirect_failure_message(exception, status, actual_location, kind)
|
43
24
|
end
|
44
25
|
end
|
45
26
|
end
|
@@ -11,25 +11,13 @@ module RSpec
|
|
11
11
|
module Util
|
12
12
|
def self.error_message(errors)
|
13
13
|
return errors.message if errors.respond_to?(:message)
|
14
|
-
|
14
|
+
|
15
15
|
errors
|
16
16
|
.map(&:to_s)
|
17
17
|
.join('; ')
|
18
18
|
.capitalize
|
19
19
|
end
|
20
20
|
|
21
|
-
def self.redirect?(status)
|
22
|
-
temp_redirect?(status) || permanent_redirect?(status)
|
23
|
-
end
|
24
|
-
|
25
|
-
def self.temp_redirect?(status)
|
26
|
-
[302, 307].include?(status)
|
27
|
-
end
|
28
|
-
|
29
|
-
def self.permanent_redirect?(status)
|
30
|
-
status == 301
|
31
|
-
end
|
32
|
-
|
33
21
|
def self.status(url_or_domain_name, follow: false)
|
34
22
|
head(url_or_domain_name, follow: follow)[0]
|
35
23
|
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.0
|
4
|
+
version: 4.1.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Robb Shecter
|
@@ -140,6 +140,7 @@ files:
|
|
140
140
|
- lib/rspec/webservice_matchers/be_up.rb
|
141
141
|
- lib/rspec/webservice_matchers/enforce_https_everywhere.rb
|
142
142
|
- lib/rspec/webservice_matchers/have_a_valid_cert.rb
|
143
|
+
- lib/rspec/webservice_matchers/redirect_helpers.rb
|
143
144
|
- lib/rspec/webservice_matchers/redirect_permanently_to.rb
|
144
145
|
- lib/rspec/webservice_matchers/redirect_temporarily_to.rb
|
145
146
|
- lib/rspec/webservice_matchers/util.rb
|
@@ -180,3 +181,4 @@ test_files:
|
|
180
181
|
- spec/rspec/webservice_matchers/redirect_spec.rb
|
181
182
|
- spec/rspec/webservice_matchers/ssl_spec.rb
|
182
183
|
- spec/spec_helper.rb
|
184
|
+
has_rdoc:
|