rspec-webservice_matchers 1.4.4 → 1.4.5

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: 61e21d1a503a63265b3ff7608ac69a75daa846b6
4
- data.tar.gz: 89c6aa33d5e010a2835e30b1d0a99a4d830587eb
3
+ metadata.gz: 02eddd454df17509b576e24d1ed58c35db8710f5
4
+ data.tar.gz: 6f6adc6984c5831ce98d5469824c43d63fce4923
5
5
  SHA512:
6
- metadata.gz: dc905ac397698db66464b220afe03b19aa704e7cf4d83d17bdd5f5cbf914ff349ffdde0f1796678f8dab7cfc6677e8b93879ca5ccd553d6fcf141f0164604503
7
- data.tar.gz: 25380cba323ad7aac3d13b6b27533d0d0fe88b0dcd0bd83359b2c045673430a8bc088e7a1a6849628f4332d3468036e1ad4e789fafad6d1ff192f90d2760abbf
6
+ metadata.gz: 5de73f534072a2ba6bfb08334e6288e023ed464f6142bf5fff420a03f6b32a2076b2daf4cd5ad2818b318f6a0d313fedd0f5150c166ae750afb171abcff89a21
7
+ data.tar.gz: a1d958399fe04fd78638ba264082e4e878bd17e8bc241523b9a4e100c9883b2b18dbd5b7a837de0b7cfe83591c4740671cf4faa71cffa3562360fccec38800e8
@@ -66,34 +66,81 @@ module RSpec
66
66
  failure_message_for_should do
67
67
  error_message
68
68
  end
69
-
70
- failure_message_for_should_not do
71
- error_message
72
- end
73
69
  end
74
70
 
75
71
 
76
72
  # Pass successfully if we get a 301 to the place we intend.
77
73
  RSpec::Matchers.define :redirect_permanently_to do |expected|
74
+ error_message = actual_status = actual_location = nil
75
+
78
76
  match do |url_or_domain_name|
79
- response = RSpec::WebserviceMatchers.connection.head(RSpec::WebserviceMatchers.make_url url_or_domain_name)
80
- expected = RSpec::WebserviceMatchers.make_url(expected)
81
- actual = response.headers['location']
82
- status = response.status
77
+ begin
78
+ response = RSpec::WebserviceMatchers.connection.head(RSpec::WebserviceMatchers.make_url url_or_domain_name)
79
+ expected = RSpec::WebserviceMatchers.make_url(expected)
80
+ actual_location = response.headers['location']
81
+ actual_status = response.status
82
+
83
+ (actual_status == 301) && (%r|#{expected}/?| === actual_location)
84
+ rescue Exception => e
85
+ error_message = e.message
86
+ false
87
+ end
88
+ end
83
89
 
84
- (status == 301) && (%r|#{expected}/?| === actual)
90
+ failure_message_for_should do
91
+ if ! error_message.nil?
92
+ error_message
93
+ else
94
+ mesgs = []
95
+ if [302, 307].include? actual_status
96
+ mesgs << "received a temporary redirect, status #{actual_status}"
97
+ end
98
+ if ! actual_location.nil? && ! (%r|#{expected}/?| === actual_location)
99
+ mesgs << "received location #{actual_location}"
100
+ end
101
+ if ! [301, 302, 307].include? actual_status
102
+ mesgs << "not a redirect: received status #{actual_status}"
103
+ end
104
+ mesgs.join('; ').capitalize
105
+ end
85
106
  end
86
107
  end
87
108
 
109
+
88
110
  # Pass successfully if we get a 302 or 307 to the place we intend.
89
111
  RSpec::Matchers.define :redirect_temporarily_to do |expected|
90
- match do |url|
91
- response = RSpec::WebserviceMatchers.connection.head(RSpec::WebserviceMatchers.make_url(url))
92
- expected = RSpec::WebserviceMatchers.make_url(expected)
93
- actual = response.headers['location']
94
- status = response.status
112
+ error_message = actual_status = actual_location = nil
113
+
114
+ match do |url_or_domain_name|
115
+ begin
116
+ response = RSpec::WebserviceMatchers.connection.head(RSpec::WebserviceMatchers.make_url url_or_domain_name)
117
+ expected = RSpec::WebserviceMatchers.make_url(expected)
118
+ actual_location = response.headers['location']
119
+ actual_status = response.status
120
+
121
+ [302, 307].include?(actual_status) && (%r|#{expected}/?| === actual_location)
122
+ rescue Exception => e
123
+ error_message = e.message
124
+ false
125
+ end
126
+ end
95
127
 
96
- [302, 307].include?(status) && (%r|#{expected}/?| === actual)
128
+ failure_message_for_should do
129
+ if ! error_message.nil?
130
+ error_message
131
+ else
132
+ mesgs = []
133
+ if actual_status == 301
134
+ mesgs << "received a permanent redirect, status #{actual_status}"
135
+ end
136
+ if ! actual_location.nil? && ! (%r|#{expected}/?| === actual_location)
137
+ mesgs << "received location #{actual_location}"
138
+ end
139
+ if ! [301, 302, 307].include? actual_status
140
+ mesgs << "not a redirect: received status #{actual_status}"
141
+ end
142
+ mesgs.join('; ').capitalize
143
+ end
97
144
  end
98
145
  end
99
146
 
@@ -123,7 +170,6 @@ module RSpec
123
170
  end
124
171
  end
125
172
 
126
-
127
173
  # Create a compound error message listing all of the
128
174
  # relevant actual values received.
129
175
  failure_message_for_should do
@@ -1,5 +1,5 @@
1
1
  module RSpec
2
2
  module WebserviceMatchers
3
- VERSION = "1.4.4"
3
+ VERSION = "1.4.5"
4
4
  end
5
5
  end
@@ -4,16 +4,40 @@ require 'rspec/webservice_matchers'
4
4
 
5
5
  describe 'redirect_permanently_to' do
6
6
  it 'passes when receiving a 301 to the given URL' do
7
- expect('http://perm-redirector.com').to redirect_permanently_to('http://www.website.com/')
7
+ expect('http://perm-redirector.com').to redirect_permanently_to 'http://www.website.com/'
8
8
  end
9
9
 
10
10
  it 'handles domain names gracefully' do
11
- expect('perm-redirector.com').to redirect_permanently_to('www.website.com/')
11
+ expect('perm-redirector.com').to redirect_permanently_to 'www.website.com/'
12
12
  end
13
13
 
14
- it 'handles missing final slash' do
15
- expect('perm-redirector.com').to redirect_permanently_to('www.website.com')
14
+ it 'handles a missing final slash' do
15
+ expect('perm-redirector.com').to redirect_permanently_to 'www.website.com'
16
16
  end
17
+
18
+ it 'gives a good error message for the wrong redirect type' do
19
+ expect {
20
+ expect('temp-redirector.org').to redirect_permanently_to 'http://a-page.com/a/page.txt'
21
+ }.to fail_matching(/temporary/i)
22
+ end
23
+
24
+ it 'gives a good error message for a redirect to the wrong location' do
25
+ expect {
26
+ expect('perm-redirector.com').to redirect_permanently_to 'http://the-wrong-site.com/'
27
+ }.to fail_matching(/location/i)
28
+ end
29
+
30
+ it 'gives a good error message for a non-redirect status' do
31
+ expect {
32
+ expect('notfound.com').to redirect_permanently_to 'http://the-wrong-site.com/'
33
+ }.to fail_matching(/404/i)
34
+ end
35
+
36
+ it 'gives a good error message when the hostname is bad' do
37
+ expect {
38
+ expect('asdhfjadhsfksd.com').to redirect_permanently_to 'http://the-wrong-site.com/'
39
+ }.to fail_matching(/not known/i)
40
+ end
17
41
  end
18
42
 
19
43
 
@@ -29,4 +53,28 @@ describe 'redirect_temporarily_to' do
29
53
  it 'passes when it gets a 307' do
30
54
  'temp-307-redirector.net'.should redirect_temporarily_to 'a-page.com/a/page.txt'
31
55
  end
32
- end
56
+
57
+ it 'gives a good error message for the wrong redirect type' do
58
+ expect {
59
+ expect('perm-redirector.com').to redirect_temporarily_to 'www.website.com/'
60
+ }.to fail_matching(/permanent/i)
61
+ end
62
+
63
+ it 'gives a good error message for a redirect to the wrong location' do
64
+ expect {
65
+ expect('temp-307-redirector.net').to redirect_temporarily_to 'www.nowhere.com'
66
+ }.to fail_matching(/location/i)
67
+ end
68
+
69
+ it 'gives a good error message for a non-redirect status' do
70
+ expect {
71
+ expect('notfound.com').to redirect_temporarily_to 'www.nowhere.com'
72
+ }.to fail_matching(/404/i)
73
+ end
74
+
75
+ it 'gives a good error message when the hostname is bad' do
76
+ expect {
77
+ expect('234678234687234.com').to redirect_temporarily_to 'www.nowhere.com'
78
+ }.to fail_matching(/not known/i)
79
+ end
80
+ 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: 1.4.4
4
+ version: 1.4.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - Robb Shecter