diff options
author | eregon <eregon@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2017-09-20 20:18:52 +0000 |
---|---|---|
committer | eregon <eregon@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2017-09-20 20:18:52 +0000 |
commit | 1d15d5f08032acf1b7bceacbb450d617ff6e0931 (patch) | |
tree | a3785a79899302bc149e4a6e72f624ac27dc1f10 /spec/ruby/library/uri | |
parent | 75bfc6440d595bf339007f4fb280fd4d743e89c1 (diff) |
Move spec/rubyspec to spec/ruby for consistency
* Other ruby implementations use the spec/ruby directory.
[Misc #13792] [ruby-core:82287]
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@59979 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'spec/ruby/library/uri')
111 files changed, 2284 insertions, 0 deletions
diff --git a/spec/ruby/library/uri/decode_www_form_component_spec.rb b/spec/ruby/library/uri/decode_www_form_component_spec.rb new file mode 100644 index 0000000000..04cc634947 --- /dev/null +++ b/spec/ruby/library/uri/decode_www_form_component_spec.rb @@ -0,0 +1,6 @@ +require File.expand_path('../../../spec_helper', __FILE__) +require 'uri' + +describe "URI.decode_www_form_component" do + it "needs to be reviewed for spec completeness" +end diff --git a/spec/ruby/library/uri/decode_www_form_spec.rb b/spec/ruby/library/uri/decode_www_form_spec.rb new file mode 100644 index 0000000000..d4854a6ece --- /dev/null +++ b/spec/ruby/library/uri/decode_www_form_spec.rb @@ -0,0 +1,6 @@ +require File.expand_path('../../../spec_helper', __FILE__) +require 'uri' + +describe "URI.decode_www_form" do + it "needs to be reviewed for spec completeness" +end diff --git a/spec/ruby/library/uri/encode_www_form_component_spec.rb b/spec/ruby/library/uri/encode_www_form_component_spec.rb new file mode 100644 index 0000000000..753b6d50d0 --- /dev/null +++ b/spec/ruby/library/uri/encode_www_form_component_spec.rb @@ -0,0 +1,6 @@ +require File.expand_path('../../../spec_helper', __FILE__) +require 'uri' + +describe "URI.encode_www_form_component" do + it "needs to be reviewed for spec completeness" +end diff --git a/spec/ruby/library/uri/encode_www_form_spec.rb b/spec/ruby/library/uri/encode_www_form_spec.rb new file mode 100644 index 0000000000..b72b928344 --- /dev/null +++ b/spec/ruby/library/uri/encode_www_form_spec.rb @@ -0,0 +1,6 @@ +require File.expand_path('../../../spec_helper', __FILE__) +require 'uri' + +describe "URI.encode_www_form" do + it "needs to be reviewed for spec completeness" +end diff --git a/spec/ruby/library/uri/eql_spec.rb b/spec/ruby/library/uri/eql_spec.rb new file mode 100644 index 0000000000..2bbc5291e9 --- /dev/null +++ b/spec/ruby/library/uri/eql_spec.rb @@ -0,0 +1,10 @@ +require File.expand_path('../../../spec_helper', __FILE__) +require File.expand_path('../fixtures/normalization', __FILE__) +require File.expand_path('../shared/eql', __FILE__) +require 'uri' + +describe "URI#eql?" do + it_behaves_like :uri_eql, :eql? + + it_behaves_like :uri_eql_against_other_types, :eql? +end diff --git a/spec/ruby/library/uri/equality_spec.rb b/spec/ruby/library/uri/equality_spec.rb new file mode 100644 index 0000000000..07d48a9583 --- /dev/null +++ b/spec/ruby/library/uri/equality_spec.rb @@ -0,0 +1,46 @@ +require File.expand_path('../../../spec_helper', __FILE__) +require File.expand_path('../fixtures/normalization', __FILE__) +require File.expand_path('../shared/eql', __FILE__) +require 'uri' + +describe "URI#==" do + it "ignores capitalization of host names" do + URI("http://exAMPLE.cOm").should == URI("http://example.com") + end + + it "ignores capitalization of scheme" do + URI("hTTp://example.com").should == URI("http://example.com") + end + + it "treats a blank path and a path of '/' as the same" do + URI("http://example.com").should == URI("http://example.com/") + end + + it "is case sensitive in all components of the URI but the host and scheme" do + URI("http://example.com/paTH").should_not == URI("http://example.com/path") + URI("http://[email protected]").should_not == URI("http://[email protected]") + URI("http://example.com/path?quERy").should_not == URI("http://example.com/path?query") + URI("http://example.com/#fragMENT").should_not == URI("http://example.com/#fragment") + end + + it "differentiates based on port number" do + URI("http://example.com:8080").should_not == URI("http://example.com") + end + + # Note: The previous tests will be included in following ones + + it_behaves_like :uri_eql, :== + + it_behaves_like :uri_eql_against_other_types, :== + + quarantine! do # Quarantined until redmine:2542 is accepted + it "returns true only if the normalized forms are equivalent" do + URISpec::NORMALIZED_FORMS.each do |form| + normal_uri = URI(form[:normalized]) + form[:equivalent].each do |same| + URI(same).should == normal_uri + end + end + end + end +end diff --git a/spec/ruby/library/uri/escape/decode_spec.rb b/spec/ruby/library/uri/escape/decode_spec.rb new file mode 100644 index 0000000000..34d3e787c4 --- /dev/null +++ b/spec/ruby/library/uri/escape/decode_spec.rb @@ -0,0 +1,6 @@ +require File.expand_path('../../../../spec_helper', __FILE__) +require 'uri' + +describe "URI::Escape#decode" do + it "needs to be reviewed for spec completeness" +end diff --git a/spec/ruby/library/uri/escape/encode_spec.rb b/spec/ruby/library/uri/escape/encode_spec.rb new file mode 100644 index 0000000000..edde60b3cd --- /dev/null +++ b/spec/ruby/library/uri/escape/encode_spec.rb @@ -0,0 +1,6 @@ +require File.expand_path('../../../../spec_helper', __FILE__) +require 'uri' + +describe "URI::Escape#encode" do + it "needs to be reviewed for spec completeness" +end diff --git a/spec/ruby/library/uri/escape/escape_spec.rb b/spec/ruby/library/uri/escape/escape_spec.rb new file mode 100644 index 0000000000..3c6b957b18 --- /dev/null +++ b/spec/ruby/library/uri/escape/escape_spec.rb @@ -0,0 +1,6 @@ +require File.expand_path('../../../../spec_helper', __FILE__) +require 'uri' + +describe "URI::Escape#escape" do + it "needs to be reviewed for spec completeness" +end diff --git a/spec/ruby/library/uri/escape/unescape_spec.rb b/spec/ruby/library/uri/escape/unescape_spec.rb new file mode 100644 index 0000000000..6a7165a0d3 --- /dev/null +++ b/spec/ruby/library/uri/escape/unescape_spec.rb @@ -0,0 +1,6 @@ +require File.expand_path('../../../../spec_helper', __FILE__) +require 'uri' + +describe "URI::Escape#unescape" do + it "needs to be reviewed for spec completeness" +end diff --git a/spec/ruby/library/uri/extract_spec.rb b/spec/ruby/library/uri/extract_spec.rb new file mode 100644 index 0000000000..7b660851b6 --- /dev/null +++ b/spec/ruby/library/uri/extract_spec.rb @@ -0,0 +1,86 @@ +require File.expand_path('../../../spec_helper', __FILE__) +require 'uri' + +describe "URI.extract" do + it "behaves according to its documentation" do + URI.extract("text here http://foo.example.org/bla and here mailto:[email protected] and here also.").should == ["http://foo.example.org/bla", "mailto:[email protected]"] + end + + it "treats contiguous URIs as a single URI" do + URI.extract('http://example.jphttp://example.jp').should == ['http://example.jphttp://example.jp'] + end + + it "treats pretty much anything with a colon as a URI" do + URI.extract('From: XXX [mailto:[email protected]]').should == ['From:', 'mailto:[email protected]]'] + end + + it "wraps a URI string in an array" do + URI.extract("http://github.com/brixen/rubyspec/tree/master").should == ["http://github.com/brixen/rubyspec/tree/master"] + end + + it "pulls a variety of protocol URIs from a string" do + URI.extract("this is a string, it has http://rubini.us/ in it").should == ["http://rubini.us/"] + URI.extract("mailto:[email protected]").should == ["mailto:[email protected]"] + URI.extract("ftp://ruby-lang.org/").should == ["ftp://ruby-lang.org/"] + URI.extract("https://mail.google.com").should == ["https://mail.google.com"] + URI.extract("anything://example.com/").should == ["anything://example.com/"] + end + + it "pulls all URIs within a string in order into an array when a block is not given" do + URI.extract("1.3. Example URI + + The following examples illustrate URI that are in common use. + + ftp://ftp.is.co.za/rfc/rfc1808.txt + -- ftp scheme for File Transfer Protocol services + + gopher://spinaltap.micro.umn.edu/00/Weather/California/Los%20Angeles + -- gopher scheme for Gopher and Gopher+ Protocol services + + http://www.math.uio.no/faq/compression-faq/part1.html + -- http scheme for Hypertext Transfer Protocol services + + mailto:[email protected] + -- mailto scheme for electronic mail addresses + + news:comp.infosystems.www.servers.unix + -- news scheme for USENET news groups and articles + + telnet://melvyl.ucop.edu/ + -- telnet scheme for interactive services via the TELNET Protocol + ").should == ["ftp://ftp.is.co.za/rfc/rfc1808.txt","gopher://spinaltap.micro.umn.edu/00/Weather/California/Los%20Angeles","http://www.math.uio.no/faq/compression-faq/part1.html","mailto:[email protected]","news:comp.infosystems.www.servers.unix","telnet://melvyl.ucop.edu/"] + end + + it "yields each URI in the given string in order to a block, if given, and returns nil" do + results = ["http://foo.example.org/bla", "mailto:[email protected]"] + URI.extract("text here http://foo.example.org/bla and here mailto:[email protected] and here also.") {|uri| + uri.should == results.shift + }.should == nil + results.should == [] + end + + it "allows the user to specify a list of acceptable protocols of URIs to scan for" do + URI.extract("1.3. Example URI + + The following examples illustrate URI that are in common use. + + ftp://ftp.is.co.za/rfc/rfc1808.txt + -- ftp scheme for File Transfer Protocol services + + gopher://spinaltap.micro.umn.edu/00/Weather/California/Los%20Angeles + -- gopher scheme for Gopher and Gopher+ Protocol services + + http://www.math.uio.no/faq/compression-faq/part1.html + -- http scheme for Hypertext Transfer Protocol services + + mailto:[email protected] + -- mailto scheme for electronic mail addresses + + news:comp.infosystems.www.servers.unix + -- news scheme for USENET news groups and articles + + telnet://melvyl.ucop.edu/ + -- telnet scheme for interactive services via the TELNET Protocol + ", ["http","ftp","mailto"]).should == ["ftp://ftp.is.co.za/rfc/rfc1808.txt","http://www.math.uio.no/faq/compression-faq/part1.html","mailto:[email protected]"] + end +end diff --git a/spec/ruby/library/uri/fixtures/classes.rb b/spec/ruby/library/uri/fixtures/classes.rb new file mode 100644 index 0000000000..e1179307cc --- /dev/null +++ b/spec/ruby/library/uri/fixtures/classes.rb @@ -0,0 +1,11 @@ +require 'uri' + +module URISpec + def self.components(uri) + result = {} + uri.component.each do |component| + result[component] = uri.send(component) + end + result + end +end diff --git a/spec/ruby/library/uri/fixtures/normalization.rb b/spec/ruby/library/uri/fixtures/normalization.rb new file mode 100644 index 0000000000..cbc26c9b48 --- /dev/null +++ b/spec/ruby/library/uri/fixtures/normalization.rb @@ -0,0 +1,54 @@ +module URISpec + # Not an exhaustive list. Refer to rfc3986 + NORMALIZED_FORMS = [ + { normalized: "http://example.com/", + equivalent: %w{ hTTp://example.com/ + http://exaMple.com/ + http://exa%4dple.com/ + http://exa%4Dple.com/ + http://exa%6dple.com/ + http://exa%6Dple.com/ + http://@example.com/ + http://example.com:/ + http://example.com:80/ + http://example.com + }, + different: %w{ http://example.com/# + http://example.com/? + http://example.com:8888/ + http:///example.com + http:example.com + https://example.com/ + }, + }, + { normalized: "http://example.com/index.html", + equivalent: %w{ http://example.com/index.ht%6dl + http://example.com/index.ht%6Dl + }, + different: %w{ http://example.com/index.hTMl + http://example.com/index.ht%4dl + http://example.com/index + http://example.com/ + http://example.com/ + }, + }, + { normalized: "http://example.com/x?y#z", + equivalent: %w{ http://example.com/x?y#%7a + http://example.com/x?y#%7A + http://example.com/x?%79#z + }, + different: %w{ http://example.com/x?Y#z + http://example.com/x?y#Z + http://example.com/x?y=#z + http://example.com/x?y + http://example.com/x#z + }, + }, + { normalized: "http://example.com/x?q=a%20b", + equivalent: %w{ + }, + different: %w{ http://example.com/x?q=a+b + }, + }, + ] +end diff --git a/spec/ruby/library/uri/ftp/build_spec.rb b/spec/ruby/library/uri/ftp/build_spec.rb new file mode 100644 index 0000000000..c7765e2868 --- /dev/null +++ b/spec/ruby/library/uri/ftp/build_spec.rb @@ -0,0 +1,6 @@ +require File.expand_path('../../../../spec_helper', __FILE__) +require 'uri' + +describe "URI::FTP.build" do + it "needs to be reviewed for spec completeness" +end diff --git a/spec/ruby/library/uri/ftp/merge_spec.rb b/spec/ruby/library/uri/ftp/merge_spec.rb new file mode 100644 index 0000000000..b766e992ca --- /dev/null +++ b/spec/ruby/library/uri/ftp/merge_spec.rb @@ -0,0 +1,6 @@ +require File.expand_path('../../../../spec_helper', __FILE__) +require 'uri' + +describe "URI::FTP#merge" do + it "needs to be reviewed for spec completeness" +end diff --git a/spec/ruby/library/uri/ftp/new2_spec.rb b/spec/ruby/library/uri/ftp/new2_spec.rb new file mode 100644 index 0000000000..a43916af6a --- /dev/null +++ b/spec/ruby/library/uri/ftp/new2_spec.rb @@ -0,0 +1,6 @@ +require File.expand_path('../../../../spec_helper', __FILE__) +require 'uri' + +describe "URI::FTP.new2" do + it "needs to be reviewed for spec completeness" +end diff --git a/spec/ruby/library/uri/ftp/path_spec.rb b/spec/ruby/library/uri/ftp/path_spec.rb new file mode 100644 index 0000000000..9e1a00602f --- /dev/null +++ b/spec/ruby/library/uri/ftp/path_spec.rb @@ -0,0 +1,26 @@ +require File.expand_path('../../../../spec_helper', __FILE__) +require 'uri' + +describe "URI::FTP#path=" do + before :each do + @url = URI.parse('ftp://example.com') + end + + it "does not require a leading /" do + @url.path = 'foo' + @url.path.should == 'foo' + end + + it "does not strip the leading /" do + @url.path = '/foo' + @url.path.should == '/foo' + end +end + +describe "URI::FTP#path" do + it "unescapes the leading /" do + url = URI.parse('ftp://example.com/%2Ffoo') + + url.path.should == '/foo' + end +end diff --git a/spec/ruby/library/uri/ftp/set_typecode_spec.rb b/spec/ruby/library/uri/ftp/set_typecode_spec.rb new file mode 100644 index 0000000000..b815bc8740 --- /dev/null +++ b/spec/ruby/library/uri/ftp/set_typecode_spec.rb @@ -0,0 +1,6 @@ +require File.expand_path('../../../../spec_helper', __FILE__) +require 'uri' + +describe "URI::FTP#set_typecode" do + it "needs to be reviewed for spec completeness" +end diff --git a/spec/ruby/library/uri/ftp/to_s_spec.rb b/spec/ruby/library/uri/ftp/to_s_spec.rb new file mode 100644 index 0000000000..e4e2832e86 --- /dev/null +++ b/spec/ruby/library/uri/ftp/to_s_spec.rb @@ -0,0 +1,15 @@ +require File.expand_path('../../../../spec_helper', __FILE__) +require 'uri' + + +describe "URI::FTP#to_s" do + before :each do + @url = URI.parse('ftp://example.com') + end + + it "escapes the leading /" do + @url.path = '/foo' + + @url.to_s.should == 'ftp://example.com/%2Ffoo' + end +end diff --git a/spec/ruby/library/uri/ftp/typecode_spec.rb b/spec/ruby/library/uri/ftp/typecode_spec.rb new file mode 100644 index 0000000000..b298c2ae98 --- /dev/null +++ b/spec/ruby/library/uri/ftp/typecode_spec.rb @@ -0,0 +1,10 @@ +require File.expand_path('../../../../spec_helper', __FILE__) +require 'uri' + +describe "URI::FTP#typecode" do + it "needs to be reviewed for spec completeness" +end + +describe "URI::FTP#typecode=" do + it "needs to be reviewed for spec completeness" +end diff --git a/spec/ruby/library/uri/generic/absolute_spec.rb b/spec/ruby/library/uri/generic/absolute_spec.rb new file mode 100644 index 0000000000..4f6526b827 --- /dev/null +++ b/spec/ruby/library/uri/generic/absolute_spec.rb @@ -0,0 +1,10 @@ +require File.expand_path('../../../../spec_helper', __FILE__) +require 'uri' + +describe "URI::Generic#absolute" do + it "needs to be reviewed for spec completeness" +end + +describe "URI::Generic#absolute?" do + it "needs to be reviewed for spec completeness" +end diff --git a/spec/ruby/library/uri/generic/build2_spec.rb b/spec/ruby/library/uri/generic/build2_spec.rb new file mode 100644 index 0000000000..0b9a6788f6 --- /dev/null +++ b/spec/ruby/library/uri/generic/build2_spec.rb @@ -0,0 +1,6 @@ +require File.expand_path('../../../../spec_helper', __FILE__) +require 'uri' + +describe "URI::Generic.build2" do + it "needs to be reviewed for spec completeness" +end diff --git a/spec/ruby/library/uri/generic/build_spec.rb b/spec/ruby/library/uri/generic/build_spec.rb new file mode 100644 index 0000000000..6fa5d6ac55 --- /dev/null +++ b/spec/ruby/library/uri/generic/build_spec.rb @@ -0,0 +1,6 @@ +require File.expand_path('../../../../spec_helper', __FILE__) +require 'uri' + +describe "URI::Generic.build" do + it "needs to be reviewed for spec completeness" +end diff --git a/spec/ruby/library/uri/generic/coerce_spec.rb b/spec/ruby/library/uri/generic/coerce_spec.rb new file mode 100644 index 0000000000..1b1a040f63 --- /dev/null +++ b/spec/ruby/library/uri/generic/coerce_spec.rb @@ -0,0 +1,6 @@ +require File.expand_path('../../../../spec_helper', __FILE__) +require 'uri' + +describe "URI::Generic#coerce" do + it "needs to be reviewed for spec completeness" +end diff --git a/spec/ruby/library/uri/generic/component_ary_spec.rb b/spec/ruby/library/uri/generic/component_ary_spec.rb new file mode 100644 index 0000000000..3244073e0e --- /dev/null +++ b/spec/ruby/library/uri/generic/component_ary_spec.rb @@ -0,0 +1,6 @@ +require File.expand_path('../../../../spec_helper', __FILE__) +require 'uri' + +describe "URI::Generic#component_ary" do + it "needs to be reviewed for spec completeness" +end diff --git a/spec/ruby/library/uri/generic/component_spec.rb b/spec/ruby/library/uri/generic/component_spec.rb new file mode 100644 index 0000000000..6fb83d7796 --- /dev/null +++ b/spec/ruby/library/uri/generic/component_spec.rb @@ -0,0 +1,10 @@ +require File.expand_path('../../../../spec_helper', __FILE__) +require 'uri' + +describe "URI::Generic#component" do + it "needs to be reviewed for spec completeness" +end + +describe "URI::Generic.component" do + it "needs to be reviewed for spec completeness" +end diff --git a/spec/ruby/library/uri/generic/default_port_spec.rb b/spec/ruby/library/uri/generic/default_port_spec.rb new file mode 100644 index 0000000000..d1e0ce2d3f --- /dev/null +++ b/spec/ruby/library/uri/generic/default_port_spec.rb @@ -0,0 +1,10 @@ +require File.expand_path('../../../../spec_helper', __FILE__) +require 'uri' + +describe "URI::Generic#default_port" do + it "needs to be reviewed for spec completeness" +end + +describe "URI::Generic.default_port" do + it "needs to be reviewed for spec completeness" +end diff --git a/spec/ruby/library/uri/generic/eql_spec.rb b/spec/ruby/library/uri/generic/eql_spec.rb new file mode 100644 index 0000000000..65f9204a19 --- /dev/null +++ b/spec/ruby/library/uri/generic/eql_spec.rb @@ -0,0 +1,6 @@ +require File.expand_path('../../../../spec_helper', __FILE__) +require 'uri' + +describe "URI::Generic#eql?" do + it "needs to be reviewed for spec completeness" +end diff --git a/spec/ruby/library/uri/generic/equal_value_spec.rb b/spec/ruby/library/uri/generic/equal_value_spec.rb new file mode 100644 index 0000000000..f41b202498 --- /dev/null +++ b/spec/ruby/library/uri/generic/equal_value_spec.rb @@ -0,0 +1,6 @@ +require File.expand_path('../../../../spec_helper', __FILE__) +require 'uri' + +describe "URI::Generic#==" do + it "needs to be reviewed for spec completeness" +end diff --git a/spec/ruby/library/uri/generic/fragment_spec.rb b/spec/ruby/library/uri/generic/fragment_spec.rb new file mode 100644 index 0000000000..de6f4e078d --- /dev/null +++ b/spec/ruby/library/uri/generic/fragment_spec.rb @@ -0,0 +1,10 @@ +require File.expand_path('../../../../spec_helper', __FILE__) +require 'uri' + +describe "URI::Generic#fragment" do + it "needs to be reviewed for spec completeness" +end + +describe "URI::Generic#fragment=" do + it "needs to be reviewed for spec completeness" +end diff --git a/spec/ruby/library/uri/generic/hash_spec.rb b/spec/ruby/library/uri/generic/hash_spec.rb new file mode 100644 index 0000000000..3410558067 --- /dev/null +++ b/spec/ruby/library/uri/generic/hash_spec.rb @@ -0,0 +1,6 @@ +require File.expand_path('../../../../spec_helper', __FILE__) +require 'uri' + +describe "URI::Generic#hash" do + it "needs to be reviewed for spec completeness" +end diff --git a/spec/ruby/library/uri/generic/hierarchical_spec.rb b/spec/ruby/library/uri/generic/hierarchical_spec.rb new file mode 100644 index 0000000000..1c90dc4f8f --- /dev/null +++ b/spec/ruby/library/uri/generic/hierarchical_spec.rb @@ -0,0 +1,6 @@ +require File.expand_path('../../../../spec_helper', __FILE__) +require 'uri' + +describe "URI::Generic#hierarchical?" do + it "needs to be reviewed for spec completeness" +end diff --git a/spec/ruby/library/uri/generic/host_spec.rb b/spec/ruby/library/uri/generic/host_spec.rb new file mode 100644 index 0000000000..6fb6c1c36a --- /dev/null +++ b/spec/ruby/library/uri/generic/host_spec.rb @@ -0,0 +1,10 @@ +require File.expand_path('../../../../spec_helper', __FILE__) +require 'uri' + +describe "URI::Generic#host" do + it "needs to be reviewed for spec completeness" +end + +describe "URI::Generic#host=" do + it "needs to be reviewed for spec completeness" +end diff --git a/spec/ruby/library/uri/generic/inspect_spec.rb b/spec/ruby/library/uri/generic/inspect_spec.rb new file mode 100644 index 0000000000..696c3308d4 --- /dev/null +++ b/spec/ruby/library/uri/generic/inspect_spec.rb @@ -0,0 +1,6 @@ +require File.expand_path('../../../../spec_helper', __FILE__) +require 'uri' + +describe "URI::Generic#inspect" do + it "needs to be reviewed for spec completeness" +end diff --git a/spec/ruby/library/uri/generic/merge_spec.rb b/spec/ruby/library/uri/generic/merge_spec.rb new file mode 100644 index 0000000000..63642197e1 --- /dev/null +++ b/spec/ruby/library/uri/generic/merge_spec.rb @@ -0,0 +1,10 @@ +require File.expand_path('../../../../spec_helper', __FILE__) +require 'uri' + +describe "URI::Generic#merge" do + it "needs to be reviewed for spec completeness" +end + +describe "URI::Generic#merge!" do + it "needs to be reviewed for spec completeness" +end diff --git a/spec/ruby/library/uri/generic/minus_spec.rb b/spec/ruby/library/uri/generic/minus_spec.rb new file mode 100644 index 0000000000..3426a6068b --- /dev/null +++ b/spec/ruby/library/uri/generic/minus_spec.rb @@ -0,0 +1,6 @@ +require File.expand_path('../../../../spec_helper', __FILE__) +require 'uri' + +describe "URI::Generic#-" do + it "needs to be reviewed for spec completeness" +end diff --git a/spec/ruby/library/uri/generic/normalize_spec.rb b/spec/ruby/library/uri/generic/normalize_spec.rb new file mode 100644 index 0000000000..ac02b644d0 --- /dev/null +++ b/spec/ruby/library/uri/generic/normalize_spec.rb @@ -0,0 +1,10 @@ +require File.expand_path('../../../../spec_helper', __FILE__) +require 'uri' + +describe "URI::Generic#normalize" do + it "needs to be reviewed for spec completeness" +end + +describe "URI::Generic#normalize!" do + it "needs to be reviewed for spec completeness" +end diff --git a/spec/ruby/library/uri/generic/opaque_spec.rb b/spec/ruby/library/uri/generic/opaque_spec.rb new file mode 100644 index 0000000000..f418c220f2 --- /dev/null +++ b/spec/ruby/library/uri/generic/opaque_spec.rb @@ -0,0 +1,10 @@ +require File.expand_path('../../../../spec_helper', __FILE__) +require 'uri' + +describe "URI::Generic#opaque" do + it "needs to be reviewed for spec completeness" +end + +describe "URI::Generic#opaque=" do + it "needs to be reviewed for spec completeness" +end diff --git a/spec/ruby/library/uri/generic/password_spec.rb b/spec/ruby/library/uri/generic/password_spec.rb new file mode 100644 index 0000000000..087db60fb9 --- /dev/null +++ b/spec/ruby/library/uri/generic/password_spec.rb @@ -0,0 +1,10 @@ +require File.expand_path('../../../../spec_helper', __FILE__) +require 'uri' + +describe "URI::Generic#password" do + it "needs to be reviewed for spec completeness" +end + +describe "URI::Generic#password=" do + it "needs to be reviewed for spec completeness" +end diff --git a/spec/ruby/library/uri/generic/path_spec.rb b/spec/ruby/library/uri/generic/path_spec.rb new file mode 100644 index 0000000000..5ea60b5418 --- /dev/null +++ b/spec/ruby/library/uri/generic/path_spec.rb @@ -0,0 +1,10 @@ +require File.expand_path('../../../../spec_helper', __FILE__) +require 'uri' + +describe "URI::Generic#path" do + it "needs to be reviewed for spec completeness" +end + +describe "URI::Generic#path=" do + it "needs to be reviewed for spec completeness" +end diff --git a/spec/ruby/library/uri/generic/plus_spec.rb b/spec/ruby/library/uri/generic/plus_spec.rb new file mode 100644 index 0000000000..3d1c031022 --- /dev/null +++ b/spec/ruby/library/uri/generic/plus_spec.rb @@ -0,0 +1,6 @@ +require File.expand_path('../../../../spec_helper', __FILE__) +require 'uri' + +describe "URI::Generic#+" do + it "needs to be reviewed for spec completeness" +end diff --git a/spec/ruby/library/uri/generic/port_spec.rb b/spec/ruby/library/uri/generic/port_spec.rb new file mode 100644 index 0000000000..148e84ff14 --- /dev/null +++ b/spec/ruby/library/uri/generic/port_spec.rb @@ -0,0 +1,10 @@ +require File.expand_path('../../../../spec_helper', __FILE__) +require 'uri' + +describe "URI::Generic#port" do + it "needs to be reviewed for spec completeness" +end + +describe "URI::Generic#port=" do + it "needs to be reviewed for spec completeness" +end diff --git a/spec/ruby/library/uri/generic/query_spec.rb b/spec/ruby/library/uri/generic/query_spec.rb new file mode 100644 index 0000000000..945fdc06a3 --- /dev/null +++ b/spec/ruby/library/uri/generic/query_spec.rb @@ -0,0 +1,10 @@ +require File.expand_path('../../../../spec_helper', __FILE__) +require 'uri' + +describe "URI::Generic#query" do + it "needs to be reviewed for spec completeness" +end + +describe "URI::Generic#query=" do + it "needs to be reviewed for spec completeness" +end diff --git a/spec/ruby/library/uri/generic/registry_spec.rb b/spec/ruby/library/uri/generic/registry_spec.rb new file mode 100644 index 0000000000..6a48b25465 --- /dev/null +++ b/spec/ruby/library/uri/generic/registry_spec.rb @@ -0,0 +1,10 @@ +require File.expand_path('../../../../spec_helper', __FILE__) +require 'uri' + +describe "URI::Generic#registry" do + it "needs to be reviewed for spec completeness" +end + +describe "URI::Generic#registry=" do + it "needs to be reviewed for spec completeness" +end diff --git a/spec/ruby/library/uri/generic/relative_spec.rb b/spec/ruby/library/uri/generic/relative_spec.rb new file mode 100644 index 0000000000..09730fa4eb --- /dev/null +++ b/spec/ruby/library/uri/generic/relative_spec.rb @@ -0,0 +1,6 @@ +require File.expand_path('../../../../spec_helper', __FILE__) +require 'uri' + +describe "URI::Generic#relative?" do + it "needs to be reviewed for spec completeness" +end diff --git a/spec/ruby/library/uri/generic/route_from_spec.rb b/spec/ruby/library/uri/generic/route_from_spec.rb new file mode 100644 index 0000000000..03321cbf0d --- /dev/null +++ b/spec/ruby/library/uri/generic/route_from_spec.rb @@ -0,0 +1,6 @@ +require File.expand_path('../../../../spec_helper', __FILE__) +require 'uri' + +describe "URI::Generic#route_from" do + it "needs to be reviewed for spec completeness" +end diff --git a/spec/ruby/library/uri/generic/route_to_spec.rb b/spec/ruby/library/uri/generic/route_to_spec.rb new file mode 100644 index 0000000000..a12e1f7649 --- /dev/null +++ b/spec/ruby/library/uri/generic/route_to_spec.rb @@ -0,0 +1,6 @@ +require File.expand_path('../../../../spec_helper', __FILE__) +require 'uri' + +describe "URI::Generic#route_to" do + it "needs to be reviewed for spec completeness" +end diff --git a/spec/ruby/library/uri/generic/scheme_spec.rb b/spec/ruby/library/uri/generic/scheme_spec.rb new file mode 100644 index 0000000000..fa3dfcb8aa --- /dev/null +++ b/spec/ruby/library/uri/generic/scheme_spec.rb @@ -0,0 +1,10 @@ +require File.expand_path('../../../../spec_helper', __FILE__) +require 'uri' + +describe "URI::Generic#scheme" do + it "needs to be reviewed for spec completeness" +end + +describe "URI::Generic#scheme=" do + it "needs to be reviewed for spec completeness" +end diff --git a/spec/ruby/library/uri/generic/select_spec.rb b/spec/ruby/library/uri/generic/select_spec.rb new file mode 100644 index 0000000000..5cc104f5dd --- /dev/null +++ b/spec/ruby/library/uri/generic/select_spec.rb @@ -0,0 +1,6 @@ +require File.expand_path('../../../../spec_helper', __FILE__) +require 'uri' + +describe "URI::Generic#select" do + it "needs to be reviewed for spec completeness" +end diff --git a/spec/ruby/library/uri/generic/set_fragment_spec.rb b/spec/ruby/library/uri/generic/set_fragment_spec.rb new file mode 100644 index 0000000000..cebad46585 --- /dev/null +++ b/spec/ruby/library/uri/generic/set_fragment_spec.rb @@ -0,0 +1,6 @@ +require File.expand_path('../../../../spec_helper', __FILE__) +require 'uri' + +describe "URI::Generic#set_fragment" do + it "needs to be reviewed for spec completeness" +end diff --git a/spec/ruby/library/uri/generic/set_host_spec.rb b/spec/ruby/library/uri/generic/set_host_spec.rb new file mode 100644 index 0000000000..357b7a6889 --- /dev/null +++ b/spec/ruby/library/uri/generic/set_host_spec.rb @@ -0,0 +1,6 @@ +require File.expand_path('../../../../spec_helper', __FILE__) +require 'uri' + +describe "URI::Generic#set_host" do + it "needs to be reviewed for spec completeness" +end diff --git a/spec/ruby/library/uri/generic/set_opaque_spec.rb b/spec/ruby/library/uri/generic/set_opaque_spec.rb new file mode 100644 index 0000000000..afd6597675 --- /dev/null +++ b/spec/ruby/library/uri/generic/set_opaque_spec.rb @@ -0,0 +1,6 @@ +require File.expand_path('../../../../spec_helper', __FILE__) +require 'uri' + +describe "URI::Generic#set_opaque" do + it "needs to be reviewed for spec completeness" +end diff --git a/spec/ruby/library/uri/generic/set_password_spec.rb b/spec/ruby/library/uri/generic/set_password_spec.rb new file mode 100644 index 0000000000..15b4fdc37d --- /dev/null +++ b/spec/ruby/library/uri/generic/set_password_spec.rb @@ -0,0 +1,6 @@ +require File.expand_path('../../../../spec_helper', __FILE__) +require 'uri' + +describe "URI::Generic#set_password" do + it "needs to be reviewed for spec completeness" +end diff --git a/spec/ruby/library/uri/generic/set_path_spec.rb b/spec/ruby/library/uri/generic/set_path_spec.rb new file mode 100644 index 0000000000..b4366d789c --- /dev/null +++ b/spec/ruby/library/uri/generic/set_path_spec.rb @@ -0,0 +1,6 @@ +require File.expand_path('../../../../spec_helper', __FILE__) +require 'uri' + +describe "URI::Generic#set_path" do + it "needs to be reviewed for spec completeness" +end diff --git a/spec/ruby/library/uri/generic/set_port_spec.rb b/spec/ruby/library/uri/generic/set_port_spec.rb new file mode 100644 index 0000000000..aa65bb96e3 --- /dev/null +++ b/spec/ruby/library/uri/generic/set_port_spec.rb @@ -0,0 +1,6 @@ +require File.expand_path('../../../../spec_helper', __FILE__) +require 'uri' + +describe "URI::Generic#set_port" do + it "needs to be reviewed for spec completeness" +end diff --git a/spec/ruby/library/uri/generic/set_query_spec.rb b/spec/ruby/library/uri/generic/set_query_spec.rb new file mode 100644 index 0000000000..b1c25e56ca --- /dev/null +++ b/spec/ruby/library/uri/generic/set_query_spec.rb @@ -0,0 +1,6 @@ +require File.expand_path('../../../../spec_helper', __FILE__) +require 'uri' + +describe "URI::Generic#set_query" do + it "needs to be reviewed for spec completeness" +end diff --git a/spec/ruby/library/uri/generic/set_registry_spec.rb b/spec/ruby/library/uri/generic/set_registry_spec.rb new file mode 100644 index 0000000000..602f868ac1 --- /dev/null +++ b/spec/ruby/library/uri/generic/set_registry_spec.rb @@ -0,0 +1,6 @@ +require File.expand_path('../../../../spec_helper', __FILE__) +require 'uri' + +describe "URI::Generic#set_registry" do + it "needs to be reviewed for spec completeness" +end diff --git a/spec/ruby/library/uri/generic/set_scheme_spec.rb b/spec/ruby/library/uri/generic/set_scheme_spec.rb new file mode 100644 index 0000000000..e1a94c5b1a --- /dev/null +++ b/spec/ruby/library/uri/generic/set_scheme_spec.rb @@ -0,0 +1,6 @@ +require File.expand_path('../../../../spec_helper', __FILE__) +require 'uri' + +describe "URI::Generic#set_scheme" do + it "needs to be reviewed for spec completeness" +end diff --git a/spec/ruby/library/uri/generic/set_user_spec.rb b/spec/ruby/library/uri/generic/set_user_spec.rb new file mode 100644 index 0000000000..36a6ac9e85 --- /dev/null +++ b/spec/ruby/library/uri/generic/set_user_spec.rb @@ -0,0 +1,6 @@ +require File.expand_path('../../../../spec_helper', __FILE__) +require 'uri' + +describe "URI::Generic#set_user" do + it "needs to be reviewed for spec completeness" +end diff --git a/spec/ruby/library/uri/generic/set_userinfo_spec.rb b/spec/ruby/library/uri/generic/set_userinfo_spec.rb new file mode 100644 index 0000000000..cbe80d9809 --- /dev/null +++ b/spec/ruby/library/uri/generic/set_userinfo_spec.rb @@ -0,0 +1,6 @@ +require File.expand_path('../../../../spec_helper', __FILE__) +require 'uri' + +describe "URI::Generic#set_userinfo" do + it "needs to be reviewed for spec completeness" +end diff --git a/spec/ruby/library/uri/generic/to_s_spec.rb b/spec/ruby/library/uri/generic/to_s_spec.rb new file mode 100644 index 0000000000..c0a0f803ef --- /dev/null +++ b/spec/ruby/library/uri/generic/to_s_spec.rb @@ -0,0 +1,6 @@ +require File.expand_path('../../../../spec_helper', __FILE__) +require 'uri' + +describe "URI::Generic#to_s" do + it "needs to be reviewed for spec completeness" +end diff --git a/spec/ruby/library/uri/generic/use_registry_spec.rb b/spec/ruby/library/uri/generic/use_registry_spec.rb new file mode 100644 index 0000000000..4e7ae6a5cf --- /dev/null +++ b/spec/ruby/library/uri/generic/use_registry_spec.rb @@ -0,0 +1,6 @@ +require File.expand_path('../../../../spec_helper', __FILE__) +require 'uri' + +describe "URI::Generic.use_registry" do + it "needs to be reviewed for spec completeness" +end diff --git a/spec/ruby/library/uri/generic/user_spec.rb b/spec/ruby/library/uri/generic/user_spec.rb new file mode 100644 index 0000000000..b785ef6879 --- /dev/null +++ b/spec/ruby/library/uri/generic/user_spec.rb @@ -0,0 +1,10 @@ +require File.expand_path('../../../../spec_helper', __FILE__) +require 'uri' + +describe "URI::Generic#user" do + it "needs to be reviewed for spec completeness" +end + +describe "URI::Generic#user=" do + it "needs to be reviewed for spec completeness" +end diff --git a/spec/ruby/library/uri/generic/userinfo_spec.rb b/spec/ruby/library/uri/generic/userinfo_spec.rb new file mode 100644 index 0000000000..5d0fc50b65 --- /dev/null +++ b/spec/ruby/library/uri/generic/userinfo_spec.rb @@ -0,0 +1,10 @@ +require File.expand_path('../../../../spec_helper', __FILE__) +require 'uri' + +describe "URI::Generic#userinfo" do + it "needs to be reviewed for spec completeness" +end + +describe "URI::Generic#userinfo=" do + it "needs to be reviewed for spec completeness" +end diff --git a/spec/ruby/library/uri/http/build_spec.rb b/spec/ruby/library/uri/http/build_spec.rb new file mode 100644 index 0000000000..85103167e0 --- /dev/null +++ b/spec/ruby/library/uri/http/build_spec.rb @@ -0,0 +1,6 @@ +require File.expand_path('../../../../spec_helper', __FILE__) +require 'uri' + +describe "URI::HTTP.build" do + it "needs to be reviewed for spec completeness" +end diff --git a/spec/ruby/library/uri/http/request_uri_spec.rb b/spec/ruby/library/uri/http/request_uri_spec.rb new file mode 100644 index 0000000000..85d89aba77 --- /dev/null +++ b/spec/ruby/library/uri/http/request_uri_spec.rb @@ -0,0 +1,16 @@ +require File.expand_path('../../../../spec_helper', __FILE__) +require 'uri' + +describe "URI::HTTP.request_uri" do + it "returns a string of the path + query" do + URI("http://reddit.com/r/ruby/").request_uri.should == "/r/ruby/" + URI("http://reddit.com/r/ruby/search?q=rubinius").request_uri.should == "/r/ruby/search?q=rubinius" + end + + it "returns '/' if the path of the URI is blank" do + URI("http://ruby.reddit.com").request_uri.should == "/" + end +end +describe "URI::HTTP#request_uri" do + it "needs to be reviewed for spec completeness" +end diff --git a/spec/ruby/library/uri/join_spec.rb b/spec/ruby/library/uri/join_spec.rb new file mode 100644 index 0000000000..681ba45cc7 --- /dev/null +++ b/spec/ruby/library/uri/join_spec.rb @@ -0,0 +1,57 @@ +require File.expand_path('../../../spec_helper', __FILE__) +require 'uri' + +describe "URI.join" do + it "returns a URI object of the concatenation of a protocol and domain, and a path" do + URI.join("http://localhost/","main.rbx").should == URI.parse("http://localhost/main.rbx") + end + + it "accepts URI objects" do + URI.join(URI("http://localhost/"),"main.rbx").should == URI.parse("http://localhost/main.rbx") + URI.join("http://localhost/",URI("main.rbx")).should == URI.parse("http://localhost/main.rbx") + URI.join(URI("http://localhost/"),URI("main.rbx")).should == URI.parse("http://localhost/main.rbx") + end + + it "accepts string-like arguments with to_str" do + str = mock('string-like') + str.should_receive(:to_str).and_return("http://ruby-lang.org") + str2 = mock('string-like also') + str2.should_receive(:to_str).and_return("foo/bar") + URI.join(str, str2).should == URI.parse("http://ruby-lang.org/foo/bar") + end + + it "raises an error if given no argument" do + lambda{ URI.join }.should raise_error + end + + it "doesn't create redundant '/'s" do + URI.join("http://localhost/", "/main.rbx").should == URI.parse("http://localhost/main.rbx") + end + + it "discards arguments given before an absolute uri" do + URI.join("http://localhost/a/b/c/d", "http://ruby-lang.com/foo", "bar").should == URI.parse("http://ruby-lang.com/bar") + end + + it "resolves .. in paths" do + URI.join("http://localhost/a/b/c/d", "../../e/f", "g/h/../i").to_s.should == "http://localhost/a/e/g/i" + end +end + + +# assert_equal(URI.parse('http://foo/bar'), URI.join('http://foo/bar')) +# assert_equal(URI.parse('http://foo/bar'), URI.join('http://foo', 'bar')) +# assert_equal(URI.parse('http://foo/bar/'), URI.join('http://foo', 'bar/')) +# +# assert_equal(URI.parse('http://foo/baz'), URI.join('http://foo', 'bar', 'baz')) +# assert_equal(URI.parse('http://foo/baz'), URI.join('http://foo', 'bar', '/baz')) +# assert_equal(URI.parse('http://foo/baz/'), URI.join('http://foo', 'bar', '/baz/')) +# assert_equal(URI.parse('http://foo/bar/baz'), URI.join('http://foo', 'bar/', 'baz')) +# assert_equal(URI.parse('http://foo/hoge'), URI.join('http://foo', 'bar', 'baz', 'hoge')) +# +# assert_equal(URI.parse('http://foo/bar/baz'), URI.join('http://foo', 'bar/baz')) +# assert_equal(URI.parse('http://foo/bar/hoge'), URI.join('http://foo', 'bar/baz', 'hoge')) +# assert_equal(URI.parse('http://foo/bar/baz/hoge'), URI.join('http://foo', 'bar/baz/', 'hoge')) +# assert_equal(URI.parse('http://foo/hoge'), URI.join('http://foo', 'bar/baz', '/hoge')) +# assert_equal(URI.parse('http://foo/bar/hoge'), URI.join('http://foo', 'bar/baz', 'hoge')) +# assert_equal(URI.parse('http://foo/bar/baz/hoge'), URI.join('http://foo', 'bar/baz/', 'hoge')) +# assert_equal(URI.parse('http://foo/hoge'), URI.join('http://foo', 'bar/baz', '/hoge')) diff --git a/spec/ruby/library/uri/ldap/attributes_spec.rb b/spec/ruby/library/uri/ldap/attributes_spec.rb new file mode 100644 index 0000000000..2309de7c62 --- /dev/null +++ b/spec/ruby/library/uri/ldap/attributes_spec.rb @@ -0,0 +1,10 @@ +require File.expand_path('../../../../spec_helper', __FILE__) +require 'uri' + +describe "URI::LDAP#attributes" do + it "needs to be reviewed for spec completeness" +end + +describe "URI::LDAP#attributes=" do + it "needs to be reviewed for spec completeness" +end diff --git a/spec/ruby/library/uri/ldap/build_spec.rb b/spec/ruby/library/uri/ldap/build_spec.rb new file mode 100644 index 0000000000..99e2611b1f --- /dev/null +++ b/spec/ruby/library/uri/ldap/build_spec.rb @@ -0,0 +1,6 @@ +require File.expand_path('../../../../spec_helper', __FILE__) +require 'uri' + +describe "URI::LDAP.build" do + it "needs to be reviewed for spec completeness" +end diff --git a/spec/ruby/library/uri/ldap/dn_spec.rb b/spec/ruby/library/uri/ldap/dn_spec.rb new file mode 100644 index 0000000000..b1371611d3 --- /dev/null +++ b/spec/ruby/library/uri/ldap/dn_spec.rb @@ -0,0 +1,10 @@ +require File.expand_path('../../../../spec_helper', __FILE__) +require 'uri' + +describe "URI::LDAP#dn" do + it "needs to be reviewed for spec completeness" +end + +describe "URI::LDAP#dn=" do + it "needs to be reviewed for spec completeness" +end diff --git a/spec/ruby/library/uri/ldap/extensions_spec.rb b/spec/ruby/library/uri/ldap/extensions_spec.rb new file mode 100644 index 0000000000..2d9b09e6a7 --- /dev/null +++ b/spec/ruby/library/uri/ldap/extensions_spec.rb @@ -0,0 +1,10 @@ +require File.expand_path('../../../../spec_helper', __FILE__) +require 'uri' + +describe "URI::LDAP#extensions" do + it "needs to be reviewed for spec completeness" +end + +describe "URI::LDAP#extensions=" do + it "needs to be reviewed for spec completeness" +end diff --git a/spec/ruby/library/uri/ldap/filter_spec.rb b/spec/ruby/library/uri/ldap/filter_spec.rb new file mode 100644 index 0000000000..1f996339db --- /dev/null +++ b/spec/ruby/library/uri/ldap/filter_spec.rb @@ -0,0 +1,10 @@ +require File.expand_path('../../../../spec_helper', __FILE__) +require 'uri' + +describe "URI::LDAP#filter" do + it "needs to be reviewed for spec completeness" +end + +describe "URI::LDAP#filter=" do + it "needs to be reviewed for spec completeness" +end diff --git a/spec/ruby/library/uri/ldap/hierarchical_spec.rb b/spec/ruby/library/uri/ldap/hierarchical_spec.rb new file mode 100644 index 0000000000..97c23a7f0c --- /dev/null +++ b/spec/ruby/library/uri/ldap/hierarchical_spec.rb @@ -0,0 +1,6 @@ +require File.expand_path('../../../../spec_helper', __FILE__) +require 'uri' + +describe "URI::LDAP#hierarchical?" do + it "needs to be reviewed for spec completeness" +end diff --git a/spec/ruby/library/uri/ldap/scope_spec.rb b/spec/ruby/library/uri/ldap/scope_spec.rb new file mode 100644 index 0000000000..d4a02e08f0 --- /dev/null +++ b/spec/ruby/library/uri/ldap/scope_spec.rb @@ -0,0 +1,10 @@ +require File.expand_path('../../../../spec_helper', __FILE__) +require 'uri' + +describe "URI::LDAP#scope" do + it "needs to be reviewed for spec completeness" +end + +describe "URI::LDAP#scope=" do + it "needs to be reviewed for spec completeness" +end diff --git a/spec/ruby/library/uri/ldap/set_attributes_spec.rb b/spec/ruby/library/uri/ldap/set_attributes_spec.rb new file mode 100644 index 0000000000..1bbcb34837 --- /dev/null +++ b/spec/ruby/library/uri/ldap/set_attributes_spec.rb @@ -0,0 +1,6 @@ +require File.expand_path('../../../../spec_helper', __FILE__) +require 'uri' + +describe "URI::LDAP#set_attributes" do + it "needs to be reviewed for spec completeness" +end diff --git a/spec/ruby/library/uri/ldap/set_dn_spec.rb b/spec/ruby/library/uri/ldap/set_dn_spec.rb new file mode 100644 index 0000000000..abb640b585 --- /dev/null +++ b/spec/ruby/library/uri/ldap/set_dn_spec.rb @@ -0,0 +1,6 @@ +require File.expand_path('../../../../spec_helper', __FILE__) +require 'uri' + +describe "URI::LDAP#set_dn" do + it "needs to be reviewed for spec completeness" +end diff --git a/spec/ruby/library/uri/ldap/set_extensions_spec.rb b/spec/ruby/library/uri/ldap/set_extensions_spec.rb new file mode 100644 index 0000000000..5cd2077aab --- /dev/null +++ b/spec/ruby/library/uri/ldap/set_extensions_spec.rb @@ -0,0 +1,6 @@ +require File.expand_path('../../../../spec_helper', __FILE__) +require 'uri' + +describe "URI::LDAP#set_extensions" do + it "needs to be reviewed for spec completeness" +end diff --git a/spec/ruby/library/uri/ldap/set_filter_spec.rb b/spec/ruby/library/uri/ldap/set_filter_spec.rb new file mode 100644 index 0000000000..f1b8e5e595 --- /dev/null +++ b/spec/ruby/library/uri/ldap/set_filter_spec.rb @@ -0,0 +1,6 @@ +require File.expand_path('../../../../spec_helper', __FILE__) +require 'uri' + +describe "URI::LDAP#set_filter" do + it "needs to be reviewed for spec completeness" +end diff --git a/spec/ruby/library/uri/ldap/set_scope_spec.rb b/spec/ruby/library/uri/ldap/set_scope_spec.rb new file mode 100644 index 0000000000..5a0841cfd8 --- /dev/null +++ b/spec/ruby/library/uri/ldap/set_scope_spec.rb @@ -0,0 +1,6 @@ +require File.expand_path('../../../../spec_helper', __FILE__) +require 'uri' + +describe "URI::LDAP#set_scope" do + it "needs to be reviewed for spec completeness" +end diff --git a/spec/ruby/library/uri/mailto/build_spec.rb b/spec/ruby/library/uri/mailto/build_spec.rb new file mode 100644 index 0000000000..cb57f0c794 --- /dev/null +++ b/spec/ruby/library/uri/mailto/build_spec.rb @@ -0,0 +1,98 @@ +require File.expand_path('../../../../spec_helper', __FILE__) +require 'uri' + +describe "URI::Mailto.build" do + it "conforms to the MatzRuby tests" do + ok = [] + bad = [] + + # RFC2368, 6. Examples + # mailto:[email protected] + ok << ["mailto:[email protected]"] + ok[-1] << ["[email protected]", nil] + ok[-1] << {to: "[email protected]"} + + # mailto:[email protected]?subject=current-issue + ok << ["mailto:[email protected]?subject=current-issue"] + ok[-1] << ["[email protected]", ["subject=current-issue"]] + ok[-1] << {to: "[email protected]", + headers: ["subject=current-issue"]} + + # mailto:[email protected]?body=send%20current-issue + ok << ["mailto:[email protected]?body=send%20current-issue"] + ok[-1] << ["[email protected]", ["body=send%20current-issue"]] + ok[-1] << {to: "[email protected]", + headers: ["body=send%20current-issue"]} + + # mailto:[email protected]?body=send%20current-issue%0D%0Asend%20index + ok << ["mailto:[email protected]?body=send%20current-issue%0D%0Asend%20index"] + ok[-1] << ["[email protected]", + ["body=send%20current-issue%0D%0Asend%20index"]] + ok[-1] << {to: "[email protected]", + headers: ["body=send%20current-issue%0D%0Asend%20index"]} + + # mailto:[email protected]?In-Reply-To=%[email protected] + ok << ["mailto:[email protected]?In-Reply-To=%[email protected]"] + ok[-1] << ["[email protected]", + ["In-Reply-To=%[email protected]"]] + ok[-1] << {to: "[email protected]", + headers: ["In-Reply-To=%[email protected]"]} + + # mailto:[email protected]?body=subscribe%20bamboo-l + ok << ["mailto:[email protected]?body=subscribe%20bamboo-l"] + ok[-1] << ["[email protected]", ["body=subscribe%20bamboo-l"]] + ok[-1] << {to: "[email protected]", + headers: ["body=subscribe%20bamboo-l"]} + + # mailto:[email protected][email protected]&body=hello + ok << ["mailto:[email protected][email protected]&body=hello"] + ok[-1] << ["[email protected]", ["[email protected]", "body=hello"]] + ok[-1] << {to: "[email protected]", + headers: ["[email protected]", "body=hello"]} + + # mailto:[email protected]&[email protected]&body=hello + ok << ["mailto:[email protected]&[email protected]&body=hello"] + ok[-1] << [nil, + ["[email protected]", "[email protected]", "body=hello"]] + ok[-1] << {headers: ["[email protected]", "[email protected]", "body=hello"]} + + # mailto:gorby%[email protected] + ok << ["mailto:gorby%[email protected]"] + ok[-1] << ["gorby%[email protected]", nil] + ok[-1] << {to: "gorby%[email protected]"} + + # mailto:unlikely%[email protected]?blat=foop + ok << ["mailto:unlikely%[email protected]?blat=foop"] + ok[-1] << ["unlikely%[email protected]", ["blat=foop"]] + ok[-1] << {to: "unlikely%[email protected]", + headers: ["blat=foop"]} + + ok_all = ok.flatten.join("\0") + + # mailto:[email protected][email protected]?body=hello ; WRONG! + bad << ["[email protected]", ["[email protected]?body=hello"]] + + # mailto:javascript:alert() + bad << ["javascript:alert()", []] + + # '=' which is in hname or hvalue is wrong. + bad << ["[email protected]?subject=1+1=2", []] + + ok.each do |x| + URI::MailTo.build(x[1]).to_s.should == x[0] + URI::MailTo.build(x[2]).to_s.should == x[0] + end + + bad.each do |x| + lambda { URI::MailTo.build(x) }.should raise_error(URI::InvalidComponentError) + end + + ok.flatten.join("\0").should == ok_all + end +end + + + +describe "URI::MailTo.build" do + it "needs to be reviewed for spec completeness" +end diff --git a/spec/ruby/library/uri/mailto/headers_spec.rb b/spec/ruby/library/uri/mailto/headers_spec.rb new file mode 100644 index 0000000000..844fdee714 --- /dev/null +++ b/spec/ruby/library/uri/mailto/headers_spec.rb @@ -0,0 +1,10 @@ +require File.expand_path('../../../../spec_helper', __FILE__) +require 'uri' + +describe "URI::MailTo#headers" do + it "needs to be reviewed for spec completeness" +end + +describe "URI::MailTo#headers=" do + it "needs to be reviewed for spec completeness" +end diff --git a/spec/ruby/library/uri/mailto/set_headers_spec.rb b/spec/ruby/library/uri/mailto/set_headers_spec.rb new file mode 100644 index 0000000000..c1384d5dca --- /dev/null +++ b/spec/ruby/library/uri/mailto/set_headers_spec.rb @@ -0,0 +1,6 @@ +require File.expand_path('../../../../spec_helper', __FILE__) +require 'uri' + +describe "URI::MailTo#set_headers" do + it "needs to be reviewed for spec completeness" +end diff --git a/spec/ruby/library/uri/mailto/set_to_spec.rb b/spec/ruby/library/uri/mailto/set_to_spec.rb new file mode 100644 index 0000000000..a8351a2092 --- /dev/null +++ b/spec/ruby/library/uri/mailto/set_to_spec.rb @@ -0,0 +1,6 @@ +require File.expand_path('../../../../spec_helper', __FILE__) +require 'uri' + +describe "URI::MailTo#set_to" do + it "needs to be reviewed for spec completeness" +end diff --git a/spec/ruby/library/uri/mailto/to_mailtext_spec.rb b/spec/ruby/library/uri/mailto/to_mailtext_spec.rb new file mode 100644 index 0000000000..4c7a48874f --- /dev/null +++ b/spec/ruby/library/uri/mailto/to_mailtext_spec.rb @@ -0,0 +1,6 @@ +require File.expand_path('../../../../spec_helper', __FILE__) +require 'uri' + +describe "URI::MailTo#to_mailtext" do + it "needs to be reviewed for spec completeness" +end diff --git a/spec/ruby/library/uri/mailto/to_rfc822text_spec.rb b/spec/ruby/library/uri/mailto/to_rfc822text_spec.rb new file mode 100644 index 0000000000..e769f62deb --- /dev/null +++ b/spec/ruby/library/uri/mailto/to_rfc822text_spec.rb @@ -0,0 +1,6 @@ +require File.expand_path('../../../../spec_helper', __FILE__) +require 'uri' + +describe "URI::MailTo#to_rfc822text" do + it "needs to be reviewed for spec completeness" +end diff --git a/spec/ruby/library/uri/mailto/to_s_spec.rb b/spec/ruby/library/uri/mailto/to_s_spec.rb new file mode 100644 index 0000000000..2709d19d27 --- /dev/null +++ b/spec/ruby/library/uri/mailto/to_s_spec.rb @@ -0,0 +1,6 @@ +require File.expand_path('../../../../spec_helper', __FILE__) +require 'uri' + +describe "URI::MailTo#to_s" do + it "needs to be reviewed for spec completeness" +end diff --git a/spec/ruby/library/uri/mailto/to_spec.rb b/spec/ruby/library/uri/mailto/to_spec.rb new file mode 100644 index 0000000000..f30d23dd53 --- /dev/null +++ b/spec/ruby/library/uri/mailto/to_spec.rb @@ -0,0 +1,10 @@ +require File.expand_path('../../../../spec_helper', __FILE__) +require 'uri' + +describe "URI::MailTo#to" do + it "needs to be reviewed for spec completeness" +end + +describe "URI::MailTo#to=" do + it "needs to be reviewed for spec completeness" +end diff --git a/spec/ruby/library/uri/merge_spec.rb b/spec/ruby/library/uri/merge_spec.rb new file mode 100644 index 0000000000..c62e80d6b2 --- /dev/null +++ b/spec/ruby/library/uri/merge_spec.rb @@ -0,0 +1,20 @@ +require File.expand_path('../../../spec_helper', __FILE__) +require 'uri' + +describe "URI#merge" do + it "returns the receiver and the argument, joined as per URI.join" do + URI("http://localhost/").merge("main.rbx").should == URI.parse("http://localhost/main.rbx") + URI("http://localhost/a/b/c/d").merge("http://ruby-lang.com/foo").should == URI.parse("http://ruby-lang.com/foo") + URI("http://localhost/a/b/c/d").merge("../../e/f").to_s.should == "http://localhost/a/e/f" + end + + it "accepts URI objects as argument" do + URI("http://localhost/").merge(URI("main.rbx")).should == URI.parse("http://localhost/main.rbx") + end + + it "accepts a string-like argument" do + str = mock('string-like') + str.should_receive(:to_str).and_return("foo/bar") + URI("http://localhost/").merge(str).should == URI.parse("http://localhost/foo/bar") + end +end diff --git a/spec/ruby/library/uri/normalize_spec.rb b/spec/ruby/library/uri/normalize_spec.rb new file mode 100644 index 0000000000..079a9ad61d --- /dev/null +++ b/spec/ruby/library/uri/normalize_spec.rb @@ -0,0 +1,35 @@ +require File.expand_path('../../../spec_helper', __FILE__) +require File.expand_path('../fixtures/normalization', __FILE__) +require 'uri' + +describe "URI#normalize" do + it "adds a / onto the end of the URI if the path is blank" do + no_path = URI("http://example.com") + no_path.to_s.should_not == "http://example.com/" + no_path.normalize.to_s.should == "http://example.com/" + end + + it "downcases the host of the URI" do + uri = URI("http://exAMPLE.cOm/") + uri.to_s.should_not == "http://example.com/" + uri.normalize.to_s.should == "http://example.com/" + end + + # The previous tests are included by the one below + + quarantine! do # Quarantined until redmine:2542 is accepted + it "respects RFC 3986" do + URISpec::NORMALIZED_FORMS.each do |form| + normal_uri = URI(form[:normalized]) + normalized = normal_uri.normalize.to_s + normal_uri.to_s.should == normalized + form[:equivalent].each do |same| + URI(same).normalize.to_s.should == normalized + end + form[:different].each do |other| + URI(other).normalize.to_s.should_not == normalized + end + end + end + end +end diff --git a/spec/ruby/library/uri/parse_spec.rb b/spec/ruby/library/uri/parse_spec.rb new file mode 100644 index 0000000000..4aa84ae2ee --- /dev/null +++ b/spec/ruby/library/uri/parse_spec.rb @@ -0,0 +1,203 @@ +require File.expand_path('../../../spec_helper', __FILE__) +require File.expand_path('../fixtures/classes', __FILE__) + +describe "URI.parse" do + + it "returns a URI::HTTP object when parsing an HTTP URI" do + URI.parse("http://www.example.com/").should be_kind_of(URI::HTTP) + end + + it "populates the components of a parsed URI::HTTP, setting the port to 80 by default" do + # general case + URISpec.components(URI.parse("http://user:[email protected]/path/?query=val&q2=val2#fragment")).should == { + scheme: "http", + userinfo: "user:pass", + host: "example.com", + port: 80, + path: "/path/", + query: "query=val&q2=val2", + fragment: "fragment" + } + + # multiple paths + URISpec.components(URI.parse("http://a/b/c/d;p?q")).should == { + scheme: "http", + userinfo: nil, + host: "a", + port: 80, + path: "/b/c/d;p", + query: "q", + fragment: nil + } + + # multi-level domain + URISpec.components(URI.parse('http://www.math.uio.no/faq/compression-faq/part1.html')).should == { + scheme: "http", + userinfo: nil, + host: "www.math.uio.no", + port: 80, + path: "/faq/compression-faq/part1.html", + query: nil, + fragment: nil + } + end + + it "parses out the port number of a URI, when given" do + URI.parse("http://example.com:8080/").port.should == 8080 + end + + it "returns a URI::HTTPS object when parsing an HTTPS URI" do + URI.parse("https://important-intern-net.net").should be_kind_of(URI::HTTPS) + end + + it "sets the port of a parsed https URI to 443 by default" do + URI.parse("https://example.com/").port.should == 443 + end + + it "populates the components of a parsed URI::FTP object" do + # generic, empty password. + url = URI.parse("ftp://[email protected]/pub/ruby/1.8/ruby-1.8.6.tar.bz2;type=i") + url.should be_kind_of(URI::FTP) + URISpec.components(url).should == { + scheme: "ftp", + userinfo: "anonymous", + host: "ruby-lang.org", + port: 21, + path: "pub/ruby/1.8/ruby-1.8.6.tar.bz2", + typecode: "i" + } + + # multidomain, no user or password + url = URI.parse('ftp://ftp.is.co.za/rfc/rfc1808.txt') + url.should be_kind_of(URI::FTP) + URISpec.components(url).should == { + scheme: "ftp", + userinfo: nil, + host: "ftp.is.co.za", + port: 21, + path: "rfc/rfc1808.txt", + typecode: nil + } + + # empty user + url = URI.parse('ftp://:pass@localhost/') + url.should be_kind_of(URI::FTP) + URISpec.components(url).should == { + scheme: "ftp", + userinfo: ":pass", + host: "localhost", + port: 21, + path: "", + typecode: nil + } + url.password.should == "pass" + end + + it "returns a URI::LDAP object when parsing an LDAP URI" do + #taken from http://www.faqs.org/rfcs/rfc2255.html 'cause I don't really know what an LDAP url looks like + ldap_uris = %w{ ldap:///o=University%20of%20Michigan,c=US ldap://ldap.itd.umich.edu/o=University%20of%20Michigan,c=US ldap://ldap.itd.umich.edu/o=University%20of%20Michigan,c=US?postalAddress ldap://host.com:6666/o=University%20of%20Michigan,c=US??sub?(cn=Babs%20Jensen) ldap://ldap.itd.umich.edu/c=GB?objectClass?one ldap://ldap.question.com/o=Question%3f,c=US?mail ldap://ldap.netscape.com/o=Babsco,c=US??(int=%5c00%5c00%5c00%5c04) ldap:///??sub??bindname=cn=Manager%2co=Foo ldap:///??sub??!bindname=cn=Manager%2co=Foo } + ldap_uris.each do |ldap_uri| + URI.parse(ldap_uri).should be_kind_of(URI::LDAP) + end + end + + it "populates the components of a parsed URI::LDAP object" do + URISpec.components(URI.parse("ldap://ldap.itd.umich.edu/o=University%20of%20Michigan,c=US?postalAddress?scope?filter?extensions")).should == { + scheme: "ldap", + host: "ldap.itd.umich.edu", + port: 389, + dn: "o=University%20of%20Michigan,c=US", + attributes: "postalAddress", + scope: "scope", + filter: "filter", + extensions: "extensions" + } + end + + it "returns a URI::MailTo object when passed a mailto URI" do + URI.parse("mailto:[email protected]").should be_kind_of(URI::MailTo) + end + + it "populates the components of a parsed URI::MailTo object" do + URISpec.components(URI.parse("mailto:[email protected]?subject=Discounts%20On%20Imported%20methods!!!&body=Exciting%20offer")).should == { + scheme: "mailto", + to: "[email protected]", + headers: [["subject","Discounts%20On%20Imported%20methods!!!"], + ["body", "Exciting%20offer"]] + } + end + + # TODO + # Test registry + it "does its best to extract components from URI::Generic objects" do + # generic + URISpec.components(URI("scheme://userinfo@host/path?query#fragment")).should == { + scheme: "scheme", + userinfo: "userinfo", + host: "host", + port: nil, + path: "/path", + query: "query", + fragment: "fragment", + registry: nil, + opaque: nil + } + + # gopher + gopher = URI.parse('gopher://spinaltap.micro.umn.edu/00/Weather/California/Los%20Angeles') + gopher.should be_kind_of(URI::Generic) + + URISpec.components(gopher).should == { + scheme: "gopher", + userinfo: nil, + host: "spinaltap.micro.umn.edu", + port: nil, + path: "/00/Weather/California/Los%20Angeles", + query: nil, + fragment: nil, + registry: nil, + opaque: nil + } + + # news + news = URI.parse('news:comp.infosystems.www.servers.unix') + news.should be_kind_of(URI::Generic) + URISpec.components(news).should == { + scheme: "news", + userinfo: nil, + host: nil, + port: nil, + path: nil, + query: nil, + fragment: nil, + registry: nil, + opaque: "comp.infosystems.www.servers.unix" + } + + # telnet + telnet = URI.parse('telnet://melvyl.ucop.edu/') + telnet.should be_kind_of(URI::Generic) + URISpec.components(telnet).should == { + scheme: "telnet", + userinfo: nil, + host: "melvyl.ucop.edu", + port: nil, + path: "/", + query: nil, + fragment: nil, + registry: nil, + opaque: nil + } + + # files + file_l = URI.parse('file:///foo/bar.txt') + file_l.should be_kind_of(URI::Generic) + file = URI.parse('file:/foo/bar.txt') + file.should be_kind_of(URI::Generic) + end + + it "doesn't raise errors on URIs which has underscore in reg_name" do + URI.parse('http://a_b:80/').host.should == "a_b" + URI.parse('http://a_b/').host.should == "a_b" + end +end diff --git a/spec/ruby/library/uri/parser/escape_spec.rb b/spec/ruby/library/uri/parser/escape_spec.rb new file mode 100644 index 0000000000..8682e0ebce --- /dev/null +++ b/spec/ruby/library/uri/parser/escape_spec.rb @@ -0,0 +1,6 @@ +require File.expand_path('../../../../spec_helper', __FILE__) +require 'uri' + +describe "URI::Parser#escape" do + it "needs to be reviewed for spec completeness" +end diff --git a/spec/ruby/library/uri/parser/extract_spec.rb b/spec/ruby/library/uri/parser/extract_spec.rb new file mode 100644 index 0000000000..5dac947060 --- /dev/null +++ b/spec/ruby/library/uri/parser/extract_spec.rb @@ -0,0 +1,7 @@ +require File.expand_path('../../../../spec_helper', __FILE__) +require File.expand_path('../../shared/extract', __FILE__) +require 'uri' + +describe "URI::Parser#extract" do + it_behaves_like :uri_extract, :extract, URI::Parser.new +end diff --git a/spec/ruby/library/uri/parser/inspect_spec.rb b/spec/ruby/library/uri/parser/inspect_spec.rb new file mode 100644 index 0000000000..2eaeeeafee --- /dev/null +++ b/spec/ruby/library/uri/parser/inspect_spec.rb @@ -0,0 +1,6 @@ +require File.expand_path('../../../../spec_helper', __FILE__) +require 'uri' + +describe "URI::Parser#split" do + it "needs to be reviewed for spec completeness" +end diff --git a/spec/ruby/library/uri/parser/join_spec.rb b/spec/ruby/library/uri/parser/join_spec.rb new file mode 100644 index 0000000000..1800a16236 --- /dev/null +++ b/spec/ruby/library/uri/parser/join_spec.rb @@ -0,0 +1,7 @@ +require File.expand_path('../../../../spec_helper', __FILE__) +require File.expand_path('../../shared/join', __FILE__) +require 'uri' + +describe "URI::Parser#join" do + it_behaves_like :uri_join, :join, URI::Parser.new +end diff --git a/spec/ruby/library/uri/parser/make_regexp_spec.rb b/spec/ruby/library/uri/parser/make_regexp_spec.rb new file mode 100644 index 0000000000..e27f0d14db --- /dev/null +++ b/spec/ruby/library/uri/parser/make_regexp_spec.rb @@ -0,0 +1,6 @@ +require File.expand_path('../../../../spec_helper', __FILE__) +require 'uri' + +describe "URI::Parser#make_regexp" do + it "needs to be reviewed for spec completeness" +end diff --git a/spec/ruby/library/uri/parser/parse_spec.rb b/spec/ruby/library/uri/parser/parse_spec.rb new file mode 100644 index 0000000000..76c1970645 --- /dev/null +++ b/spec/ruby/library/uri/parser/parse_spec.rb @@ -0,0 +1,7 @@ +require File.expand_path('../../../../spec_helper', __FILE__) +require File.expand_path('../../fixtures/classes', __FILE__) +require File.expand_path('../../shared/parse', __FILE__) + +describe "URI::Parser#parse" do + it_behaves_like :uri_parse, :parse, URI::Parser.new +end diff --git a/spec/ruby/library/uri/parser/split_spec.rb b/spec/ruby/library/uri/parser/split_spec.rb new file mode 100644 index 0000000000..2eaeeeafee --- /dev/null +++ b/spec/ruby/library/uri/parser/split_spec.rb @@ -0,0 +1,6 @@ +require File.expand_path('../../../../spec_helper', __FILE__) +require 'uri' + +describe "URI::Parser#split" do + it "needs to be reviewed for spec completeness" +end diff --git a/spec/ruby/library/uri/parser/unescape_spec.rb b/spec/ruby/library/uri/parser/unescape_spec.rb new file mode 100644 index 0000000000..8ffc534226 --- /dev/null +++ b/spec/ruby/library/uri/parser/unescape_spec.rb @@ -0,0 +1,6 @@ +require File.expand_path('../../../../spec_helper', __FILE__) +require 'uri' + +describe "URI::Parser#unescape" do + it "needs to be reviewed for spec completeness" +end diff --git a/spec/ruby/library/uri/plus_spec.rb b/spec/ruby/library/uri/plus_spec.rb new file mode 100644 index 0000000000..45c1aa5e57 --- /dev/null +++ b/spec/ruby/library/uri/plus_spec.rb @@ -0,0 +1,459 @@ +require File.expand_path('../../../spec_helper', __FILE__) +require 'uri' + +#an alias of URI#merge +describe "URI#+" do + it "replaces the end of the path of the URI when added to a string that looks like a relative path" do + (URI('http://foo') + 'bar').should == URI("http://foo/bar") + (URI('http://foo/baz') + 'bar').should == URI("http://foo/bar") + (URI('http://foo/baz/') + 'bar').should == URI("http://foo/baz/bar") + (URI('mailto:[email protected]') + "#bar").should == URI("mailto:[email protected]#bar") + end + + it "replaces the entire path of the URI when added to a string that begins with a /" do + (URI('http://foo/baz/') + '/bar').should == URI("http://foo/bar") + end + + it "replaces the entire url when added to a string that looks like a full url" do + (URI.parse('http://a/b') + 'http://x/y').should == URI("http://x/y") + (URI.parse('telnet:example.com') + 'http://x/y').should == URI("http://x/y") + end + + it "canonicalizes the URI's path, removing ../'s" do + (URI.parse('http://a/b/c/../') + "./").should == URI("http://a/b/") + (URI.parse('http://a/b/c/../') + ".").should == URI("http://a/b/") + (URI.parse('http://a/b/c/') + "../").should == URI("http://a/b/") + (URI.parse('http://a/b/c/../../') + "./").should == URI("http://a/") + (URI.parse('http://a/b/c/') + "../e/").should == URI("http://a/b/e/") + (URI.parse('http://a/b/c/') + "../e/../").should == URI("http://a/b/") + (URI.parse('http://a/b/../c/') + ".").should == URI("http://a/c/") + + (URI.parse('http://a/b/c/../../../') + ".").should == URI("http://a/") + end + + it "doesn't conconicalize the path when adding to the empty string" do + (URI.parse('http://a/b/c/../') + "").should == URI("http://a/b/c/../") + end + + it "raises a URI::BadURIError when adding two relative URIs" do + lambda {URI.parse('a/b/c') + "d"}.should raise_error(URI::BadURIError) + end + + #Todo: make more BDD? + it "conforms to the merge specifications from rfc 2396" do + @url = 'http://a/b/c/d;p?q' + @base_url = URI.parse(@url) + +# http://a/b/c/d;p?q +# g:h = g:h + url = @base_url.merge('g:h') + url.should be_kind_of(URI::Generic) + url.to_s.should == 'g:h' + url = @base_url.route_to('g:h') + url.should be_kind_of(URI::Generic) + url.to_s.should == 'g:h' + +# http://a/b/c/d;p?q +# g = http://a/b/c/g + url = @base_url.merge('g') + url.should be_kind_of(URI::HTTP) + url.to_s.should == 'http://a/b/c/g' + url = @base_url.route_to('http://a/b/c/g') + url.should be_kind_of(URI::Generic) + url.to_s.should == 'g' + +# http://a/b/c/d;p?q +# ./g = http://a/b/c/g + url = @base_url.merge('./g') + url.should be_kind_of(URI::HTTP) + url.to_s.should == 'http://a/b/c/g' + url = @base_url.route_to('http://a/b/c/g') + url.should be_kind_of(URI::Generic) + url.to_s.should_not == './g' # ok + url.to_s.should == 'g' + +# http://a/b/c/d;p?q +# g/ = http://a/b/c/g/ + url = @base_url.merge('g/') + url.should be_kind_of(URI::HTTP) + url.to_s.should == 'http://a/b/c/g/' + url = @base_url.route_to('http://a/b/c/g/') + url.should be_kind_of(URI::Generic) + url.to_s.should == 'g/' + +# http://a/b/c/d;p?q +# /g = http://a/g + url = @base_url.merge('/g') + url.should be_kind_of(URI::HTTP) + url.to_s.should == 'http://a/g' + url = @base_url.route_to('http://a/g') + url.should be_kind_of(URI::Generic) + url.to_s.should_not == '/g' # ok + url.to_s.should == '../../g' + +# http://a/b/c/d;p?q +# //g = http://g + url = @base_url.merge('//g') + url.should be_kind_of(URI::HTTP) + url.to_s.should == 'http://g' + url = @base_url.route_to('http://g') + url.should be_kind_of(URI::Generic) + url.to_s.should == '//g' + +# http://a/b/c/d;p?q +# ?y = http://a/b/c/?y + url = @base_url.merge('?y') + url.should be_kind_of(URI::HTTP) + + url.to_s.should == 'http://a/b/c/d;p?y' + + url = @base_url.route_to('http://a/b/c/?y') + url.should be_kind_of(URI::Generic) + url.to_s.should == '?y' + +# http://a/b/c/d;p?q +# g?y = http://a/b/c/g?y + url = @base_url.merge('g?y') + url.should be_kind_of(URI::HTTP) + url.to_s.should == 'http://a/b/c/g?y' + url = @base_url.route_to('http://a/b/c/g?y') + url.should be_kind_of(URI::Generic) + url.to_s.should == 'g?y' + +# http://a/b/c/d;p?q +# #s = (current document)#s + url = @base_url.merge('#s') + url.should be_kind_of(URI::HTTP) + url.to_s.should == @base_url.to_s + '#s' + url = @base_url.route_to(@base_url.to_s + '#s') + url.should be_kind_of(URI::Generic) + url.to_s.should == '#s' + +# http://a/b/c/d;p?q +# g#s = http://a/b/c/g#s + url = @base_url.merge('g#s') + url.should be_kind_of(URI::HTTP) + url.to_s.should == 'http://a/b/c/g#s' + url = @base_url.route_to('http://a/b/c/g#s') + url.should be_kind_of(URI::Generic) + url.to_s.should == 'g#s' + +# http://a/b/c/d;p?q +# g?y#s = http://a/b/c/g?y#s + url = @base_url.merge('g?y#s') + url.should be_kind_of(URI::HTTP) + url.to_s.should == 'http://a/b/c/g?y#s' + url = @base_url.route_to('http://a/b/c/g?y#s') + url.should be_kind_of(URI::Generic) + url.to_s.should == 'g?y#s' + +# http://a/b/c/d;p?q +# ;x = http://a/b/c/;x + url = @base_url.merge(';x') + url.should be_kind_of(URI::HTTP) + url.to_s.should == 'http://a/b/c/;x' + url = @base_url.route_to('http://a/b/c/;x') + url.should be_kind_of(URI::Generic) + url.to_s.should == ';x' + +# http://a/b/c/d;p?q +# g;x = http://a/b/c/g;x + url = @base_url.merge('g;x') + url.should be_kind_of(URI::HTTP) + url.to_s.should == 'http://a/b/c/g;x' + url = @base_url.route_to('http://a/b/c/g;x') + url.should be_kind_of(URI::Generic) + url.to_s.should == 'g;x' + +# http://a/b/c/d;p?q +# g;x?y#s = http://a/b/c/g;x?y#s + url = @base_url.merge('g;x?y#s') + url.should be_kind_of(URI::HTTP) + url.to_s.should == 'http://a/b/c/g;x?y#s' + url = @base_url.route_to('http://a/b/c/g;x?y#s') + url.should be_kind_of(URI::Generic) + url.to_s.should == 'g;x?y#s' + +# http://a/b/c/d;p?q +# . = http://a/b/c/ + url = @base_url.merge('.') + url.should be_kind_of(URI::HTTP) + url.to_s.should == 'http://a/b/c/' + url = @base_url.route_to('http://a/b/c/') + url.should be_kind_of(URI::Generic) + url.to_s.should_not == '.' # ok + url.to_s.should == './' + +# http://a/b/c/d;p?q +# ./ = http://a/b/c/ + url = @base_url.merge('./') + url.should be_kind_of(URI::HTTP) + url.to_s.should == 'http://a/b/c/' + url = @base_url.route_to('http://a/b/c/') + url.should be_kind_of(URI::Generic) + url.to_s.should == './' + +# http://a/b/c/d;p?q +# .. = http://a/b/ + url = @base_url.merge('..') + url.should be_kind_of(URI::HTTP) + url.to_s.should == 'http://a/b/' + url = @base_url.route_to('http://a/b/') + url.should be_kind_of(URI::Generic) + url.to_s.should_not == '..' # ok + url.to_s.should == '../' + +# http://a/b/c/d;p?q +# ../ = http://a/b/ + url = @base_url.merge('../') + url.should be_kind_of(URI::HTTP) + url.to_s.should == 'http://a/b/' + url = @base_url.route_to('http://a/b/') + url.should be_kind_of(URI::Generic) + url.to_s.should == '../' + +# http://a/b/c/d;p?q +# ../g = http://a/b/g + url = @base_url.merge('../g') + url.should be_kind_of(URI::HTTP) + url.to_s.should == 'http://a/b/g' + url = @base_url.route_to('http://a/b/g') + url.should be_kind_of(URI::Generic) + url.to_s.should == '../g' + +# http://a/b/c/d;p?q +# ../.. = http://a/ + url = @base_url.merge('../..') + url.should be_kind_of(URI::HTTP) + url.to_s.should == 'http://a/' + url = @base_url.route_to('http://a/') + url.should be_kind_of(URI::Generic) + url.to_s.should_not == '../..' # ok + url.to_s.should == '../../' + +# http://a/b/c/d;p?q +# ../../ = http://a/ + url = @base_url.merge('../../') + url.should be_kind_of(URI::HTTP) + url.to_s.should == 'http://a/' + url = @base_url.route_to('http://a/') + url.should be_kind_of(URI::Generic) + url.to_s.should == '../../' + +# http://a/b/c/d;p?q +# ../../g = http://a/g + url = @base_url.merge('../../g') + url.should be_kind_of(URI::HTTP) + url.to_s.should == 'http://a/g' + url = @base_url.route_to('http://a/g') + url.should be_kind_of(URI::Generic) + url.to_s.should == '../../g' + +# http://a/b/c/d;p?q +# <> = (current document) + url = @base_url.merge('') + url.should be_kind_of(URI::HTTP) + url.to_s.should == 'http://a/b/c/d;p?q' + url = @base_url.route_to('http://a/b/c/d;p?q') + url.should be_kind_of(URI::Generic) + url.to_s.should == '' + +# http://a/b/c/d;p?q +# /./g = http://a/./g + url = @base_url.merge('/./g') + url.should be_kind_of(URI::HTTP) + + url.to_s.should == 'http://a/g' + + url = @base_url.route_to('http://a/./g') + url.should be_kind_of(URI::Generic) + url.to_s.should == '/./g' + +# http://a/b/c/d;p?q +# /../g = http://a/../g + url = @base_url.merge('/../g') + url.should be_kind_of(URI::HTTP) + + url.to_s.should == 'http://a/g' + + url = @base_url.route_to('http://a/../g') + url.should be_kind_of(URI::Generic) + url.to_s.should == '/../g' + +# http://a/b/c/d;p?q +# g. = http://a/b/c/g. + url = @base_url.merge('g.') + url.should be_kind_of(URI::HTTP) + url.to_s.should == 'http://a/b/c/g.' + url = @base_url.route_to('http://a/b/c/g.') + url.should be_kind_of(URI::Generic) + url.to_s.should == 'g.' + +# http://a/b/c/d;p?q +# .g = http://a/b/c/.g + url = @base_url.merge('.g') + url.should be_kind_of(URI::HTTP) + url.to_s.should == 'http://a/b/c/.g' + url = @base_url.route_to('http://a/b/c/.g') + url.should be_kind_of(URI::Generic) + url.to_s.should == '.g' + +# http://a/b/c/d;p?q +# g.. = http://a/b/c/g.. + url = @base_url.merge('g..') + url.should be_kind_of(URI::HTTP) + url.to_s.should == 'http://a/b/c/g..' + url = @base_url.route_to('http://a/b/c/g..') + url.should be_kind_of(URI::Generic) + url.to_s.should == 'g..' + +# http://a/b/c/d;p?q +# ..g = http://a/b/c/..g + url = @base_url.merge('..g') + url.should be_kind_of(URI::HTTP) + url.to_s.should == 'http://a/b/c/..g' + url = @base_url.route_to('http://a/b/c/..g') + url.should be_kind_of(URI::Generic) + url.to_s.should == '..g' + +# http://a/b/c/d;p?q +# ../../../g = http://a/../g + url = @base_url.merge('../../../g') + url.should be_kind_of(URI::HTTP) + + url.to_s.should == 'http://a/g' + + url = @base_url.route_to('http://a/../g') + url.should be_kind_of(URI::Generic) + url.to_s.should_not == '../../../g' # ok? yes, it confuses you + url.to_s.should == '/../g' # and it is clearly + +# http://a/b/c/d;p?q +# ../../../../g = http://a/../../g + url = @base_url.merge('../../../../g') + url.should be_kind_of(URI::HTTP) + + url.to_s.should == 'http://a/g' + + url = @base_url.route_to('http://a/../../g') + url.should be_kind_of(URI::Generic) + url.to_s.should_not == '../../../../g' # ok? yes, it confuses you + url.to_s.should == '/../../g' # and it is clearly + +# http://a/b/c/d;p?q +# ./../g = http://a/b/g + url = @base_url.merge('./../g') + url.should be_kind_of(URI::HTTP) + url.to_s.should == 'http://a/b/g' + url = @base_url.route_to('http://a/b/g') + url.should be_kind_of(URI::Generic) + url.to_s.should_not == './../g' # ok + url.to_s.should == '../g' + +# http://a/b/c/d;p?q +# ./g/. = http://a/b/c/g/ + url = @base_url.merge('./g/.') + url.should be_kind_of(URI::HTTP) + url.to_s.should == 'http://a/b/c/g/' + url = @base_url.route_to('http://a/b/c/g/') + url.should be_kind_of(URI::Generic) + url.to_s.should_not == './g/.' # ok + url.to_s.should == 'g/' + +# http://a/b/c/d;p?q +# g/./h = http://a/b/c/g/h + url = @base_url.merge('g/./h') + url.should be_kind_of(URI::HTTP) + url.to_s.should == 'http://a/b/c/g/h' + url = @base_url.route_to('http://a/b/c/g/h') + url.should be_kind_of(URI::Generic) + url.to_s.should_not == 'g/./h' # ok + url.to_s.should == 'g/h' + +# http://a/b/c/d;p?q +# g/../h = http://a/b/c/h + url = @base_url.merge('g/../h') + url.should be_kind_of(URI::HTTP) + url.to_s.should == 'http://a/b/c/h' + url = @base_url.route_to('http://a/b/c/h') + url.should be_kind_of(URI::Generic) + url.to_s.should_not == 'g/../h' # ok + url.to_s.should == 'h' + +# http://a/b/c/d;p?q +# g;x=1/./y = http://a/b/c/g;x=1/y + url = @base_url.merge('g;x=1/./y') + url.should be_kind_of(URI::HTTP) + url.to_s.should == 'http://a/b/c/g;x=1/y' + url = @base_url.route_to('http://a/b/c/g;x=1/y') + url.should be_kind_of(URI::Generic) + url.to_s.should_not == 'g;x=1/./y' # ok + url.to_s.should == 'g;x=1/y' + +# http://a/b/c/d;p?q +# g;x=1/../y = http://a/b/c/y + url = @base_url.merge('g;x=1/../y') + url.should be_kind_of(URI::HTTP) + url.to_s.should == 'http://a/b/c/y' + url = @base_url.route_to('http://a/b/c/y') + url.should be_kind_of(URI::Generic) + url.to_s.should_not == 'g;x=1/../y' # ok + url.to_s.should == 'y' + +# http://a/b/c/d;p?q +# g?y/./x = http://a/b/c/g?y/./x + url = @base_url.merge('g?y/./x') + url.should be_kind_of(URI::HTTP) + url.to_s.should == 'http://a/b/c/g?y/./x' + url = @base_url.route_to('http://a/b/c/g?y/./x') + url.should be_kind_of(URI::Generic) + url.to_s.should == 'g?y/./x' + +# http://a/b/c/d;p?q +# g?y/../x = http://a/b/c/g?y/../x + url = @base_url.merge('g?y/../x') + url.should be_kind_of(URI::HTTP) + url.to_s.should == 'http://a/b/c/g?y/../x' + url = @base_url.route_to('http://a/b/c/g?y/../x') + url.should be_kind_of(URI::Generic) + url.to_s.should == 'g?y/../x' + +# http://a/b/c/d;p?q +# g#s/./x = http://a/b/c/g#s/./x + url = @base_url.merge('g#s/./x') + url.should be_kind_of(URI::HTTP) + url.to_s.should == 'http://a/b/c/g#s/./x' + url = @base_url.route_to('http://a/b/c/g#s/./x') + url.should be_kind_of(URI::Generic) + url.to_s.should == 'g#s/./x' + +# http://a/b/c/d;p?q +# g#s/../x = http://a/b/c/g#s/../x + url = @base_url.merge('g#s/../x') + url.should be_kind_of(URI::HTTP) + url.to_s.should == 'http://a/b/c/g#s/../x' + url = @base_url.route_to('http://a/b/c/g#s/../x') + url.should be_kind_of(URI::Generic) + url.to_s.should == 'g#s/../x' + +# http://a/b/c/d;p?q +# http:g = http:g ; for validating parsers +# | http://a/b/c/g ; for backwards compatibility + url = @base_url.merge('http:g') + url.should be_kind_of(URI::HTTP) + url.to_s.should == 'http:g' + url = @base_url.route_to('http:g') + url.should be_kind_of(URI::Generic) + url.to_s.should == 'http:g' + end +end + +#TODO: incorporate these tests: +# +# u = URI.parse('http://foo/bar/baz') +# assert_equal(nil, u.merge!("")) +# assert_equal(nil, u.merge!(u)) +# assert(nil != u.merge!(".")) +# assert_equal('http://foo/bar/', u.to_s) +# assert(nil != u.merge!("../baz")) +# assert_equal('http://foo/baz', u.to_s) diff --git a/spec/ruby/library/uri/regexp_spec.rb b/spec/ruby/library/uri/regexp_spec.rb new file mode 100644 index 0000000000..cf63507013 --- /dev/null +++ b/spec/ruby/library/uri/regexp_spec.rb @@ -0,0 +1,18 @@ +require File.expand_path('../../../spec_helper', __FILE__) +require 'uri' + +#I'm more or less ok with these limited tests, as the more extensive extract tests +#use URI.regexp +describe "URI.regexp" do + it "behaves according to the MatzRuby tests" do + URI.regexp.should == URI.regexp + 'x http:// x'.slice(URI.regexp).should == 'http://' + 'x http:// x'.slice(URI.regexp(['http'])).should == 'http://' + 'x http:// x ftp://'.slice(URI.regexp(['http'])).should == 'http://' + 'http://'.slice(URI.regexp([])).should == nil + ''.slice(URI.regexp).should == nil + 'xxxx'.slice(URI.regexp).should == nil + ':'.slice(URI.regexp).should == nil + 'From:'.slice(URI.regexp).should == 'From:' + end +end diff --git a/spec/ruby/library/uri/route_from_spec.rb b/spec/ruby/library/uri/route_from_spec.rb new file mode 100644 index 0000000000..11a2c44f90 --- /dev/null +++ b/spec/ruby/library/uri/route_from_spec.rb @@ -0,0 +1,23 @@ +require File.expand_path('../../../spec_helper', __FILE__) +require 'uri' + +describe "URI#route_from" do + + #this could be split out a good bit better + it "gives the minimal difference between the current URI and the target" do + URI("http://example.com/a.html").route_from('http://example.com/a.html').to_s.should == "" + URI("http://example.com/a.html").route_from('http://example.com/b.html').to_s.should == "a.html" + URI("http://example.com/a/").route_from('http://example.com/b/').to_s.should == "../a/" + URI("http://example.com/b/").route_from('http://example.com/a/c').to_s.should == "../b/" + URI("http://example.com/b/").route_from('http://example.com/a/b/').to_s.should == "../../b/" + URI("http://example.com/b/").route_from('http://EXAMPLE.cOm/a/b/').to_s.should == "../../b/" + URI("http://example.net/b/").route_from('http://example.com/a/b/').to_s.should == "//example.net/b/" + URI("mailto:[email protected]#bar").route_from('mailto:[email protected]').to_s.should == "#bar" + end + + it "accepts a string-like argument" do + str = mock('string-like') + str.should_receive(:to_str).and_return("http://example.com/b.html") + URI("http://example.com/a.html").route_from(str).to_s.should == "a.html" + end +end diff --git a/spec/ruby/library/uri/route_to_spec.rb b/spec/ruby/library/uri/route_to_spec.rb new file mode 100644 index 0000000000..2eb68afdfd --- /dev/null +++ b/spec/ruby/library/uri/route_to_spec.rb @@ -0,0 +1,26 @@ +require File.expand_path('../../../spec_helper', __FILE__) +require 'uri' + +describe "URI#route_to" do + + #this could be split out a good bit better + it "gives the minimal difference between the current URI and the target" do + URI("http://example.com/a.html").route_to('http://example.com/a.html').to_s.should == "" + URI("http://example.com/a.html").route_to('http://example.com/b.html').to_s.should == "b.html" + URI("http://example.com/a/").route_to('http://example.com/b/').to_s.should == "../b/" + URI("http://example.com/a/c").route_to('http://example.com/b/').to_s.should == "../b/" + URI("http://example.com/a/b/").route_to('http://example.com/b/').to_s.should == "../../b/" + URI("http://example.com/a/b/").route_to('http://EXAMPLE.cOm/b/').to_s.should == "../../b/" + URI("http://example.com/a/b/").route_to('http://example.net/b/').to_s.should == "//example.net/b/" + URI("mailto:[email protected]").route_to('mailto:[email protected]#bar').to_s.should == "#bar" + + #this was a little surprising to me + URI("mailto:[email protected]#bar").route_to('mailto:[email protected]').to_s.should == "" + end + + it "accepts a string-like argument" do + str = mock('string-like') + str.should_receive(:to_str).and_return("http://example.com/b.html") + URI("http://example.com/a.html").route_to(str).to_s.should == "b.html" + end +end diff --git a/spec/ruby/library/uri/select_spec.rb b/spec/ruby/library/uri/select_spec.rb new file mode 100644 index 0000000000..46474757cc --- /dev/null +++ b/spec/ruby/library/uri/select_spec.rb @@ -0,0 +1,31 @@ +require File.expand_path('../../../spec_helper', __FILE__) +require 'uri' + +describe "URI#select" do + it "takes any number of component names as symbols, and returns an array of those components" do + URI("http://host:8080/path/").select.should == [] + URI("http://host:8080/path/").select(:scheme,:host,:port,:path).should == [ + "http","host",8080,"/path/"] + end + + it "returns nil for any valid component that isn't set and doesn't have a default" do + uri = URI("http://host") + uri.select(:userinfo, :query, :fragment).should == [nil] * 3 + uri.select(:port, :path).should == [80, ''] + end + + it "raises an ArgumentError if a component is requested that isn't valid under the given scheme" do + [ + lambda {URI("mailto:[email protected]").select(:path)}, + lambda {URI("http://blog.blag.web").select(:typecode)}, + ].each do |select_lambda| + select_lambda.should raise_error(ArgumentError) + end + end + + it "raises an ArgumentError if given strings rather than symbols" do + lambda { + URI("http://host:8080/path/").select("scheme","host","port",'path') + }.should raise_error(ArgumentError) + end +end diff --git a/spec/ruby/library/uri/set_component_spec.rb b/spec/ruby/library/uri/set_component_spec.rb new file mode 100644 index 0000000000..9b8372108a --- /dev/null +++ b/spec/ruby/library/uri/set_component_spec.rb @@ -0,0 +1,47 @@ +require File.expand_path('../../../spec_helper', __FILE__) +require 'uri' + +#TODO: make this more BDD +describe "URI#select" do + it "conforms to the MatzRuby tests" do + uri = URI.parse('http://foo:bar@baz') + (uri.user = 'oof').should == 'oof' + uri.to_s.should == 'http://oof:bar@baz' + (uri.password = 'rab').should == 'rab' + uri.to_s.should == 'http://oof:rab@baz' + (uri.userinfo = 'foo').should == 'foo' + uri.to_s.should == 'http://foo:rab@baz' + (uri.userinfo = ['foo', 'bar']).should == ['foo', 'bar'] + uri.to_s.should == 'http://foo:bar@baz' + (uri.userinfo = ['foo']).should == ['foo'] + uri.to_s.should == 'http://foo:bar@baz' + (uri.host = 'zab').should == 'zab' + uri.to_s.should == 'http://foo:bar@zab' + (uri.port = 8080).should == 8080 + uri.to_s.should == 'http://foo:bar@zab:8080' + (uri.path = '/').should == '/' + uri.to_s.should == 'http://foo:bar@zab:8080/' + (uri.query = 'a=1').should == 'a=1' + uri.to_s.should == 'http://foo:bar@zab:8080/?a=1' + (uri.fragment = 'b123').should == 'b123' + uri.to_s.should == 'http://foo:bar@zab:8080/?a=1#b123' + + uri = URI.parse('http://example.com') + lambda { uri.password = 'bar' }.should raise_error(URI::InvalidURIError) + uri.userinfo = 'foo:bar' + uri.to_s.should == 'http://foo:[email protected]' + lambda { uri.registry = 'bar' }.should raise_error(URI::InvalidURIError) + lambda { uri.opaque = 'bar' }.should raise_error(URI::InvalidURIError) + + uri = URI.parse('mailto:[email protected]') + lambda { uri.user = 'bar' }.should raise_error(URI::InvalidURIError) + lambda { uri.password = 'bar' }.should raise_error(URI::InvalidURIError) + lambda { uri.userinfo = ['bar', 'baz'] }.should raise_error(URI::InvalidURIError) + lambda { uri.host = 'bar' }.should raise_error(URI::InvalidURIError) + lambda { uri.port = 'bar' }.should raise_error(URI::InvalidURIError) + lambda { uri.path = 'bar' }.should raise_error(URI::InvalidURIError) + lambda { uri.query = 'bar' }.should raise_error(URI::InvalidURIError) + end +end + + diff --git a/spec/ruby/library/uri/shared/eql.rb b/spec/ruby/library/uri/shared/eql.rb new file mode 100644 index 0000000000..2cc960d39a --- /dev/null +++ b/spec/ruby/library/uri/shared/eql.rb @@ -0,0 +1,17 @@ +describe :uri_eql, shared: true do + it "returns false if the normalized forms are different" do + URISpec::NORMALIZED_FORMS.each do |form| + normal_uri = URI(form[:normalized]) + form[:different].each do |other| + URI(other).send(@method, normal_uri).should be_false + end + end + end +end + +describe :uri_eql_against_other_types, shared: true do + it "returns false for when compared to non-uri objects" do + URI("http://example.com/").send(@method, "http://example.com/").should be_false + URI("http://example.com/").send(@method, nil).should be_false + end +end diff --git a/spec/ruby/library/uri/shared/extract.rb b/spec/ruby/library/uri/shared/extract.rb new file mode 100644 index 0000000000..efe60ae4b9 --- /dev/null +++ b/spec/ruby/library/uri/shared/extract.rb @@ -0,0 +1,83 @@ +describe :uri_extract, shared: true do + it "behaves according to its documentation" do + @object.extract("text here http://foo.example.org/bla and here mailto:[email protected] and here also.").should == ["http://foo.example.org/bla", "mailto:[email protected]"] + end + + it "treats contiguous URIs as a single URI" do + @object.extract('http://example.jphttp://example.jp').should == ['http://example.jphttp://example.jp'] + end + + it "treats pretty much anything with a colon as a URI" do + @object.extract('From: XXX [mailto:[email protected]]').should == ['From:', 'mailto:[email protected]]'] + end + + it "wraps a URI string in an array" do + @object.extract("http://github.com/brixen/rubyspec/tree/master").should == ["http://github.com/brixen/rubyspec/tree/master"] + end + + it "pulls a variety of protocol URIs from a string" do + @object.extract("this is a string, it has http://rubini.us/ in it").should == ["http://rubini.us/"] + @object.extract("mailto:[email protected]").should == ["mailto:[email protected]"] + @object.extract("ftp://ruby-lang.org/").should == ["ftp://ruby-lang.org/"] + @object.extract("https://mail.google.com").should == ["https://mail.google.com"] + @object.extract("anything://example.com/").should == ["anything://example.com/"] + end + + it "pulls all URIs within a string in order into an array when a block is not given" do + @object.extract("1.3. Example URI + + The following examples illustrate URI that are in common use. + + ftp://ftp.is.co.za/rfc/rfc1808.txt + -- ftp scheme for File Transfer Protocol services + + gopher://spinaltap.micro.umn.edu/00/Weather/California/Los%20Angeles + -- gopher scheme for Gopher and Gopher+ Protocol services + + http://www.math.uio.no/faq/compression-faq/part1.html + -- http scheme for Hypertext Transfer Protocol services + + mailto:[email protected] + -- mailto scheme for electronic mail addresses + + news:comp.infosystems.www.servers.unix + -- news scheme for USENET news groups and articles + + telnet://melvyl.ucop.edu/ + -- telnet scheme for interactive services via the TELNET Protocol + ").should == ["ftp://ftp.is.co.za/rfc/rfc1808.txt","gopher://spinaltap.micro.umn.edu/00/Weather/California/Los%20Angeles","http://www.math.uio.no/faq/compression-faq/part1.html","mailto:[email protected]","news:comp.infosystems.www.servers.unix","telnet://melvyl.ucop.edu/"] + end + + it "yields each URI in the given string in order to a block, if given, and returns nil" do + results = ["http://foo.example.org/bla", "mailto:[email protected]"] + @object.extract("text here http://foo.example.org/bla and here mailto:[email protected] and here also.") {|uri| + uri.should == results.shift + }.should == nil + results.should == [] + end + + it "allows the user to specify a list of acceptable protocols of URIs to scan for" do + @object.extract("1.3. Example URI + + The following examples illustrate URI that are in common use. + + ftp://ftp.is.co.za/rfc/rfc1808.txt + -- ftp scheme for File Transfer Protocol services + + gopher://spinaltap.micro.umn.edu/00/Weather/California/Los%20Angeles + -- gopher scheme for Gopher and Gopher+ Protocol services + + http://www.math.uio.no/faq/compression-faq/part1.html + -- http scheme for Hypertext Transfer Protocol services + + mailto:[email protected] + -- mailto scheme for electronic mail addresses + + news:comp.infosystems.www.servers.unix + -- news scheme for USENET news groups and articles + + telnet://melvyl.ucop.edu/ + -- telnet scheme for interactive services via the TELNET Protocol + ", ["http","ftp","mailto"]).should == ["ftp://ftp.is.co.za/rfc/rfc1808.txt","http://www.math.uio.no/faq/compression-faq/part1.html","mailto:[email protected]"] + end +end diff --git a/spec/ruby/library/uri/shared/join.rb b/spec/ruby/library/uri/shared/join.rb new file mode 100644 index 0000000000..dfe44e9be2 --- /dev/null +++ b/spec/ruby/library/uri/shared/join.rb @@ -0,0 +1,54 @@ +describe :uri_join, shared: true do + it "returns a URI object of the concatenation of a protocol and domain, and a path" do + @object.join("http://localhost/","main.rbx").should == URI.parse("http://localhost/main.rbx") + end + + it "accepts URI objects" do + @object.join(URI("http://localhost/"),"main.rbx").should == URI.parse("http://localhost/main.rbx") + @object.join("http://localhost/",URI("main.rbx")).should == URI.parse("http://localhost/main.rbx") + @object.join(URI("http://localhost/"),URI("main.rbx")).should == URI.parse("http://localhost/main.rbx") + end + + it "accepts string-like arguments with to_str" do + str = mock('string-like') + str.should_receive(:to_str).and_return("http://ruby-lang.org") + str2 = mock('string-like also') + str2.should_receive(:to_str).and_return("foo/bar") + @object.join(str, str2).should == URI.parse("http://ruby-lang.org/foo/bar") + end + + it "raises an error if given no argument" do + lambda{ @object.join }.should raise_error + end + + it "doesn't create redundant '/'s" do + @object.join("http://localhost/", "/main.rbx").should == URI.parse("http://localhost/main.rbx") + end + + it "discards arguments given before an absolute uri" do + @object.join("http://localhost/a/b/c/d", "http://ruby-lang.com/foo", "bar").should == URI.parse("http://ruby-lang.com/bar") + end + + it "resolves .. in paths" do + @object.join("http://localhost/a/b/c/d", "../../e/f", "g/h/../i").to_s.should == "http://localhost/a/e/g/i" + end +end + + +# assert_equal(URI.parse('http://foo/bar'), URI.join('http://foo/bar')) +# assert_equal(URI.parse('http://foo/bar'), URI.join('http://foo', 'bar')) +# assert_equal(URI.parse('http://foo/bar/'), URI.join('http://foo', 'bar/')) +# +# assert_equal(URI.parse('http://foo/baz'), URI.join('http://foo', 'bar', 'baz')) +# assert_equal(URI.parse('http://foo/baz'), URI.join('http://foo', 'bar', '/baz')) +# assert_equal(URI.parse('http://foo/baz/'), URI.join('http://foo', 'bar', '/baz/')) +# assert_equal(URI.parse('http://foo/bar/baz'), URI.join('http://foo', 'bar/', 'baz')) +# assert_equal(URI.parse('http://foo/hoge'), URI.join('http://foo', 'bar', 'baz', 'hoge')) +# +# assert_equal(URI.parse('http://foo/bar/baz'), URI.join('http://foo', 'bar/baz')) +# assert_equal(URI.parse('http://foo/bar/hoge'), URI.join('http://foo', 'bar/baz', 'hoge')) +# assert_equal(URI.parse('http://foo/bar/baz/hoge'), URI.join('http://foo', 'bar/baz/', 'hoge')) +# assert_equal(URI.parse('http://foo/hoge'), URI.join('http://foo', 'bar/baz', '/hoge')) +# assert_equal(URI.parse('http://foo/bar/hoge'), URI.join('http://foo', 'bar/baz', 'hoge')) +# assert_equal(URI.parse('http://foo/bar/baz/hoge'), URI.join('http://foo', 'bar/baz/', 'hoge')) +# assert_equal(URI.parse('http://foo/hoge'), URI.join('http://foo', 'bar/baz', '/hoge')) diff --git a/spec/ruby/library/uri/shared/parse.rb b/spec/ruby/library/uri/shared/parse.rb new file mode 100644 index 0000000000..5ecbffcaf2 --- /dev/null +++ b/spec/ruby/library/uri/shared/parse.rb @@ -0,0 +1,199 @@ +describe :uri_parse, shared: true do + it "returns a URI::HTTP object when parsing an HTTP URI" do + @object.parse("http://www.example.com/").should be_kind_of(URI::HTTP) + end + + it "populates the components of a parsed URI::HTTP, setting the port to 80 by default" do + # general case + URISpec.components(@object.parse("http://user:[email protected]/path/?query=val&q2=val2#fragment")).should == { + scheme: "http", + userinfo: "user:pass", + host: "example.com", + port: 80, + path: "/path/", + query: "query=val&q2=val2", + fragment: "fragment" + } + + # multiple paths + URISpec.components(@object.parse("http://a/b/c/d;p?q")).should == { + scheme: "http", + userinfo: nil, + host: "a", + port: 80, + path: "/b/c/d;p", + query: "q", + fragment: nil + } + + # multi-level domain + URISpec.components(@object.parse('http://www.math.uio.no/faq/compression-faq/part1.html')).should == { + scheme: "http", + userinfo: nil, + host: "www.math.uio.no", + port: 80, + path: "/faq/compression-faq/part1.html", + query: nil, + fragment: nil + } + end + + it "parses out the port number of a URI, when given" do + @object.parse("http://example.com:8080/").port.should == 8080 + end + + it "returns a URI::HTTPS object when parsing an HTTPS URI" do + @object.parse("https://important-intern-net.net").should be_kind_of(URI::HTTPS) + end + + it "sets the port of a parsed https URI to 443 by default" do + @object.parse("https://example.com/").port.should == 443 + end + + it "populates the components of a parsed URI::FTP object" do + # generic, empty password. + url = @object.parse("ftp://[email protected]/pub/ruby/1.8/ruby-1.8.6.tar.bz2;type=i") + url.should be_kind_of(URI::FTP) + URISpec.components(url).should == { + scheme: "ftp", + userinfo: "anonymous", + host: "ruby-lang.org", + port: 21, + path: "pub/ruby/1.8/ruby-1.8.6.tar.bz2", + typecode: "i" + } + + # multidomain, no user or password + url = @object.parse('ftp://ftp.is.co.za/rfc/rfc1808.txt') + url.should be_kind_of(URI::FTP) + URISpec.components(url).should == { + scheme: "ftp", + userinfo: nil, + host: "ftp.is.co.za", + port: 21, + path: "rfc/rfc1808.txt", + typecode: nil + } + + # empty user + url = @object.parse('ftp://:pass@localhost/') + url.should be_kind_of(URI::FTP) + URISpec.components(url).should == { + scheme: "ftp", + userinfo: ":pass", + host: "localhost", + port: 21, + path: "", + typecode: nil + } + url.password.should == "pass" + end + + it "returns a URI::LDAP object when parsing an LDAP URI" do + #taken from http://www.faqs.org/rfcs/rfc2255.html 'cause I don't really know what an LDAP url looks like + ldap_uris = %w{ ldap:///o=University%20of%20Michigan,c=US ldap://ldap.itd.umich.edu/o=University%20of%20Michigan,c=US ldap://ldap.itd.umich.edu/o=University%20of%20Michigan,c=US?postalAddress ldap://host.com:6666/o=University%20of%20Michigan,c=US??sub?(cn=Babs%20Jensen) ldap://ldap.itd.umich.edu/c=GB?objectClass?one ldap://ldap.question.com/o=Question%3f,c=US?mail ldap://ldap.netscape.com/o=Babsco,c=US??(int=%5c00%5c00%5c00%5c04) ldap:///??sub??bindname=cn=Manager%2co=Foo ldap:///??sub??!bindname=cn=Manager%2co=Foo } + ldap_uris.each do |ldap_uri| + @object.parse(ldap_uri).should be_kind_of(URI::LDAP) + end + end + + it "populates the components of a parsed URI::LDAP object" do + URISpec.components(@object.parse("ldap://ldap.itd.umich.edu/o=University%20of%20Michigan,c=US?postalAddress?scope?filter?extensions")).should == { + scheme: "ldap", + host: "ldap.itd.umich.edu", + port: 389, + dn: "o=University%20of%20Michigan,c=US", + attributes: "postalAddress", + scope: "scope", + filter: "filter", + extensions: "extensions" + } + end + + it "returns a URI::MailTo object when passed a mailto URI" do + @object.parse("mailto:[email protected]").should be_kind_of(URI::MailTo) + end + + it "populates the components of a parsed URI::MailTo object" do + URISpec.components(@object.parse("mailto:[email protected]?subject=Discounts%20On%20Imported%20methods!!!&body=Exciting%20offer")).should == { + scheme: "mailto", + to: "[email protected]", + headers: [["subject","Discounts%20On%20Imported%20methods!!!"], + ["body", "Exciting%20offer"]] + } + end + + # TODO + # Test registry + it "does its best to extract components from URI::Generic objects" do + # generic + URISpec.components(URI("scheme://userinfo@host/path?query#fragment")).should == { + scheme: "scheme", + userinfo: "userinfo", + host: "host", + port: nil, + path: "/path", + query: "query", + fragment: "fragment", + registry: nil, + opaque: nil + } + + # gopher + gopher = @object.parse('gopher://spinaltap.micro.umn.edu/00/Weather/California/Los%20Angeles') + gopher.should be_kind_of(URI::Generic) + + URISpec.components(gopher).should == { + scheme: "gopher", + userinfo: nil, + host: "spinaltap.micro.umn.edu", + port: nil, + path: "/00/Weather/California/Los%20Angeles", + query: nil, + fragment: nil, + registry: nil, + opaque: nil + } + + # news + news = @object.parse('news:comp.infosystems.www.servers.unix') + news.should be_kind_of(URI::Generic) + URISpec.components(news).should == { + scheme: "news", + userinfo: nil, + host: nil, + port: nil, + path: nil, + query: nil, + fragment: nil, + registry: nil, + opaque: "comp.infosystems.www.servers.unix" + } + + # telnet + telnet = @object.parse('telnet://melvyl.ucop.edu/') + telnet.should be_kind_of(URI::Generic) + URISpec.components(telnet).should == { + scheme: "telnet", + userinfo: nil, + host: "melvyl.ucop.edu", + port: nil, + path: "/", + query: nil, + fragment: nil, + registry: nil, + opaque: nil + } + + # files + file_l = @object.parse('file:///foo/bar.txt') + file_l.should be_kind_of(URI::Generic) + file = @object.parse('file:/foo/bar.txt') + file.should be_kind_of(URI::Generic) + end + + it "raises errors on malformed URIs" do + lambda { @object.parse('http://a_b:80/') }.should raise_error(URI::InvalidURIError) + lambda { @object.parse('http://a_b/') }.should raise_error(URI::InvalidURIError) + end +end diff --git a/spec/ruby/library/uri/split_spec.rb b/spec/ruby/library/uri/split_spec.rb new file mode 100644 index 0000000000..f0ab6ff35c --- /dev/null +++ b/spec/ruby/library/uri/split_spec.rb @@ -0,0 +1,6 @@ +require File.expand_path('../../../spec_helper', __FILE__) +require 'uri' + +describe "URI.split" do + it "needs to be reviewed for spec completeness" +end diff --git a/spec/ruby/library/uri/uri_spec.rb b/spec/ruby/library/uri/uri_spec.rb new file mode 100644 index 0000000000..90936a770f --- /dev/null +++ b/spec/ruby/library/uri/uri_spec.rb @@ -0,0 +1,29 @@ +require File.expand_path('../../../spec_helper', __FILE__) +require 'uri' + +#the testing is light here as this is an alias for URI.parse + +#we're just testing that the method ends up in the right place +describe "the URI method" do + it "parses a given URI, returning a URI object" do + result = URI.parse("http://ruby-lang.org") + URI("http://ruby-lang.org").should == result + Kernel::URI("http://ruby-lang.org").should == result + end + + it "converts its argument with to_str" do + str = mock('string-like') + str.should_receive(:to_str).and_return("http://ruby-lang.org") + URI(str).should == URI.parse("http://ruby-lang.org") + end + + it "returns the argument if it is a URI object" do + result = URI.parse("http://ruby-lang.org") + URI(result).should equal(result) + end + + #apparently this was a concern? imported from MRI tests + it "does not add a URI method to Object instances" do + lambda {Object.new.URI("http://ruby-lang.org/")}.should raise_error(NoMethodError) + end +end diff --git a/spec/ruby/library/uri/util/make_components_hash_spec.rb b/spec/ruby/library/uri/util/make_components_hash_spec.rb new file mode 100644 index 0000000000..0f491112e8 --- /dev/null +++ b/spec/ruby/library/uri/util/make_components_hash_spec.rb @@ -0,0 +1,6 @@ +require File.expand_path('../../../../spec_helper', __FILE__) +require 'uri' + +describe "URI::Util.make_components_hash" do + it "needs to be reviewed for spec completeness" +end |