Fixed rendering of URIs with port number; moved match.rb to test_helper (where it belongs)

This commit is contained in:
Alexey Verkhovsky 2005-01-16 16:04:45 +00:00
parent 832cfdf605
commit 178f3f53ee
4 changed files with 35 additions and 19 deletions

View file

@ -1,19 +0,0 @@
# This module is to be included in unit tests that involve matching chunks.
# It provides a easy way to test whether a chunk matches a particular string
# and any the values of any fields that should be set after a match.
module ChunkMatch
# Asserts a number of tests for the given type and text.
def match(type, test_text, expected)
pattern = type.pattern
assert_match(pattern, test_text)
pattern =~ test_text # Previous assertion guarantees match
chunk = type.new($~)
# Test if requested parts are correct.
for method_sym, value in expected do
assert_respond_to(chunk, method_sym)
assert_equal(value, chunk.method(method_sym).call, "Checking value of '#{method_sym}'")
end
end
end

View file

@ -35,6 +35,9 @@ class URIChunk < Chunk::Abstract
# markup. (Images: !URI!) and other punctuation eg, (http://wiki.com/)
URI_ENDING = '[)!]'
# Correct a typo bug in ruby 1.8.x lib/uri/common.rb
PORT = '\\d*'
# The basic URI expression as a string
URI_PATTERN =
"(?:(#{SCHEME})://)?" + # Optional scheme:// (\1|\8)

View file

@ -32,6 +32,7 @@ class WikiServiceWithNoPersistence
end
end
# With the new cookies infrastructure, @response.cookies['foo'] is no good anymore.
# Pending implementation in Rails, here is a convenience method for accessing cookies from a test
@ -46,3 +47,24 @@ module ActionController
end
end
end
# This module is to be included in unit tests that involve matching chunks.
# It provides a easy way to test whether a chunk matches a particular string
# and any the values of any fields that should be set after a match.
module ChunkMatch
# Asserts a number of tests for the given type and text.
def match(type, test_text, expected)
pattern = type.pattern
assert_match(pattern, test_text)
pattern =~ test_text # Previous assertion guarantees match
chunk = type.new($~)
# Test if requested parts are correct.
for method_sym, value in expected do
assert_respond_to(chunk, method_sym)
assert_equal(value, chunk.method(method_sym).call, "Checking value of '#{method_sym}'")
end
end
end

View file

@ -89,4 +89,14 @@ class URITest < Test::Unit::TestCase
:path => '/~mail2minh/SonyEricssonP80xPlatform.sis'
)
end
def test_uri_with_port
match(
URIChunk,
"This text contains a URL http://someplace.org:8080/~person/stuff.cgi?arg=val, doesn't it?",
:scheme => 'http', :host => 'someplace.org', :port => '8080', :path => '/~person/stuff.cgi',
:query => 'arg=val'
)
end
end