test/extra/validators/test_links.rb in nanoc-3.4.3 vs test/extra/validators/test_links.rb in nanoc-3.5.0b1
- old
+ new
@@ -2,70 +2,6 @@
class Nanoc::Extra::Validators::LinksTest < MiniTest::Unit::TestCase
include Nanoc::TestHelpers
- def test_is_external_href?
- # Create validator
- validator = Nanoc::Extra::Validators::Links.new(nil, nil)
-
- # Test
- assert validator.send(:is_external_href?, 'http://example.com/')
- assert validator.send(:is_external_href?, 'https://example.com/')
- assert validator.send(:is_external_href?, 'mailto:bob@example.com')
- assert !validator.send(:is_external_href?, '../stuff')
- assert !validator.send(:is_external_href?, '/stuff')
- end
-
- def test_is_valid_internal_href?
- # Create files
- FileUtils.mkdir_p('output')
- FileUtils.mkdir_p('output/stuff')
- File.open('output/origin', 'w') { |io| io.write('hi') }
- File.open('output/foo', 'w') { |io| io.write('hi') }
- File.open('output/stuff/blah', 'w') { |io| io.write('hi') }
-
- # Create validator
- validator = Nanoc::Extra::Validators::Links.new('output', [ 'index.html' ])
-
- # Test
- assert validator.send(:is_valid_internal_href?, 'foo', 'output/origin')
- assert validator.send(:is_valid_internal_href?, 'origin', 'output/origin')
- assert validator.send(:is_valid_internal_href?, 'stuff/blah', 'output/origin')
- assert validator.send(:is_valid_internal_href?, '/foo', 'output/origin')
- assert validator.send(:is_valid_internal_href?, '/origin', 'output/origin')
- assert validator.send(:is_valid_internal_href?, '/stuff/blah', 'output/origin')
- end
-
- def test_is_valid_external_href?
- # Create validator
- validator = Nanoc::Extra::Validators::Links.new('output', [ 'index.html' ])
- validator.stubs(:fetch_http_status_for).returns(200)
-
- # Test
- assert validator.send(:is_valid_external_href?, 'http://example.com/')
- assert validator.send(:is_valid_external_href?, 'https://example.com/')
- 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
- @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'))
-
- @server.stop
- @thread.kill
- end
-
end