test/extra/validators/test_links.rb in nanoc-3.3.7 vs test/extra/validators/test_links.rb in nanoc-3.4.0
- old
+ new
@@ -47,15 +47,25 @@
assert validator.send(:is_valid_external_href?, 'foo://example.com/')
refute validator.send(:is_valid_external_href?, 'http://example.com/">')
end
def test_fetch_http_status_for
- # Create validator
+ @app = lambda { |env| [ env['REQUEST_PATH'][1..-1].to_i, {}, [ '... Useless body ...' ] ] }
+ @server = nil
+
+ @thread = Thread.new do
+ Rack::Handler::WEBrick.run(@app, :Host => @host='127.0.0.1', :Port => @port=9204) do |server|
+ @server = server
+ end
+ end
+
+ Thread.pass until @server
+
validator = Nanoc::Extra::Validators::Links.new('output', [ 'index.html' ])
+ assert_equal 200, validator.send(:fetch_http_status_for, URI.parse('http://127.0.0.1:9204/200'))
+ assert_equal 404, validator.send(:fetch_http_status_for, URI.parse('http://127.0.0.1:9204/404'))
- # Test
- assert_equal 200, validator.send(:fetch_http_status_for, URI.parse('http://httpstat.us/200'))
- assert_equal 200, validator.send(:fetch_http_status_for, URI.parse('https://httpstat.us/200'))
- assert_equal 404, validator.send(:fetch_http_status_for, URI.parse('http://httpstat.us/404'))
+ @server.stop
+ @thread.kill
end
end