@@ -136,26 +136,28 @@ def cname_packet(domain)
136
136
expect ( health_check . valid_domain? ) . to be ( false )
137
137
end
138
138
139
- it "returns valid json" do
140
- data = JSON . parse GitHubPages ::HealthCheck . new ( "benbalter.com" ) . to_json
141
- expect ( data . length ) . to eql ( 14 )
142
- data . each { |key , value | expect ( [ true , false , nil ] . include? ( value ) ) . to eql ( true ) }
143
- end
139
+ context "served by pages" do
140
+ it "returns valid json" do
141
+ stub_request ( :head , "benbalter.com" ) .
142
+ to_return ( :status => 200 , :headers => { :server => "GitHub.com" } )
144
143
145
- it "return the error" do
146
- check = GitHubPages ::HealthCheck . new "developer.facebook.com"
147
- expect ( check . valid? ) . to eql ( false )
148
- expect ( check . reason . class ) . to eql ( GitHubPages ::HealthCheck ::InvalidCNAME )
149
- expect ( check . reason . message ) . to eql ( "CNAME does not point to GitHub Pages" )
150
- end
144
+ data = JSON . parse GitHubPages ::HealthCheck . new ( "benbalter.com" ) . to_json
145
+ expect ( data . length ) . to eql ( 14 )
146
+ data . each { |key , value | expect ( [ true , false , nil ] . include? ( value ) ) . to eql ( true ) }
147
+ end
151
148
152
- context "served by pages" do
153
149
it "knows when a domain is served by pages" do
150
+ stub_request ( :head , "http://choosealicense.com" ) .
151
+ to_return ( :status => 200 , :headers => { :server => "GitHub.com" } )
152
+
154
153
check = GitHubPages ::HealthCheck . new "choosealicense.com"
155
154
expect ( check . served_by_pages? ) . to eql ( true )
156
155
end
157
156
158
157
it "knows when a GitHub domain is served by pages" do
158
+ stub_request ( :head , "https://mac.github.com" ) .
159
+ to_return ( :status => 200 , :headers => { :server => "GitHub.com" } )
160
+
159
161
check = GitHubPages ::HealthCheck . new "mac.github.com"
160
162
expect ( check . served_by_pages? ) . to eql ( true )
161
163
end
@@ -165,21 +167,45 @@ def cname_packet(domain)
165
167
# › curl -I http://getbootstrap.com/
166
168
# HTTP/1.1 302 Found
167
169
# Location: /
170
+ stub_request ( :head , "http://getbootstrap.com" ) .
171
+ to_return ( :status => 302 , :headers => { :location => "/" } )
172
+
173
+ stub_request ( :head , "http://getbootstrap.com/" ) .
174
+ to_return ( :status => 200 , :headers => { :server => "GitHub.com" } )
175
+
168
176
check = GitHubPages ::HealthCheck . new "getbootstrap.com"
169
177
expect ( check . served_by_pages? ) . to eql ( true )
170
178
end
171
179
172
180
it "knows when a domain with a redirect is served by pages" do
181
+ stub_request ( :head , "http://management.cio.gov" ) .
182
+ to_return ( :status => 302 , :headers => { :location => "https://management.cio.gov" } )
183
+
184
+ stub_request ( :head , "https://management.cio.gov" ) .
185
+ to_return ( :status => 200 , :headers => { :server => "GitHub.com" } )
186
+
173
187
check = GitHubPages ::HealthCheck . new "management.cio.gov"
174
188
expect ( check . served_by_pages? ) . to eql ( true )
175
189
end
190
+ end
191
+
192
+ context "not served by pages" do
176
193
177
194
it "knows when a domain isn't served by pages" do
195
+ stub_request ( :head , "http://google.com" ) . to_return ( :status => 200 , :headers => { } )
178
196
check = GitHubPages ::HealthCheck . new "google.com"
179
197
expect ( check . served_by_pages? ) . to eql ( false )
180
198
expect ( check . reason . class ) . to eql ( GitHubPages ::HealthCheck ::NotServedByPages )
181
199
expect ( check . reason . message ) . to eql ( "Domain does not resolve to the GitHub Pages server" )
182
200
end
201
+
202
+ it "returns the error" do
203
+ stub_request ( :head , "http://developers.facebook.com" ) . to_return ( :status => 200 , :headers => { } )
204
+ check = GitHubPages ::HealthCheck . new "developers.facebook.com"
205
+ expect ( check . valid? ) . to eql ( false )
206
+ expect ( check . reason . class ) . to eql ( GitHubPages ::HealthCheck ::InvalidCNAME )
207
+ expect ( check . reason . message ) . to eql ( "CNAME does not point to GitHub Pages" )
208
+ end
183
209
end
184
210
185
211
context "proxies" do
@@ -199,11 +225,15 @@ def cname_packet(domain)
199
225
end
200
226
201
227
it "detects proxied sites" do
228
+ stub_request ( :head , "http://management.cio.gov" ) .
229
+ to_return ( :status => 200 , :headers => { :server => "GitHub.com" } )
230
+
202
231
check = GitHubPages ::HealthCheck . new "management.cio.gov"
203
232
expect ( check . proxied? ) . to eql ( true )
204
233
end
205
234
206
235
it "knows a site not served by pages isn't proxied" do
236
+ stub_request ( :head , "http://google.com" ) . to_return ( :status => 200 , :headers => { } )
207
237
check = GitHubPages ::HealthCheck . new "google.com"
208
238
expect ( check . proxied? ) . to eql ( false )
209
239
end
0 commit comments