diff options
Diffstat (limited to 'spec/ruby/library/uri')
| -rw-r--r-- | spec/ruby/library/uri/join_spec.rb | 2 | ||||
| -rw-r--r-- | spec/ruby/library/uri/mailto/build_spec.rb | 2 | ||||
| -rw-r--r-- | spec/ruby/library/uri/parse_spec.rb | 24 | ||||
| -rw-r--r-- | spec/ruby/library/uri/parser/extract_spec.rb | 87 | ||||
| -rw-r--r-- | spec/ruby/library/uri/parser/join_spec.rb | 59 | ||||
| -rw-r--r-- | spec/ruby/library/uri/parser/parse_spec.rb | 210 | ||||
| -rw-r--r-- | spec/ruby/library/uri/plus_spec.rb | 170 | ||||
| -rw-r--r-- | spec/ruby/library/uri/select_spec.rb | 6 | ||||
| -rw-r--r-- | spec/ruby/library/uri/set_component_spec.rb | 60 | ||||
| -rw-r--r-- | spec/ruby/library/uri/shared/eql.rb | 6 | ||||
| -rw-r--r-- | spec/ruby/library/uri/shared/extract.rb | 83 | ||||
| -rw-r--r-- | spec/ruby/library/uri/shared/join.rb | 56 | ||||
| -rw-r--r-- | spec/ruby/library/uri/shared/parse.rb | 206 | ||||
| -rw-r--r-- | spec/ruby/library/uri/uri_spec.rb | 4 |
14 files changed, 488 insertions, 487 deletions
diff --git a/spec/ruby/library/uri/join_spec.rb b/spec/ruby/library/uri/join_spec.rb index 796f74134f..1777303360 100644 --- a/spec/ruby/library/uri/join_spec.rb +++ b/spec/ruby/library/uri/join_spec.rb @@ -23,7 +23,7 @@ describe "URI.join" do it "raises an error if given no argument" do -> { URI.join - }.should raise_error(ArgumentError) + }.should.raise(ArgumentError) end it "doesn't create redundant '/'s" do diff --git a/spec/ruby/library/uri/mailto/build_spec.rb b/spec/ruby/library/uri/mailto/build_spec.rb index 2c011626ab..081707b1cf 100644 --- a/spec/ruby/library/uri/mailto/build_spec.rb +++ b/spec/ruby/library/uri/mailto/build_spec.rb @@ -84,7 +84,7 @@ describe "URI::Mailto.build" do end bad.each do |x| - -> { URI::MailTo.build(x) }.should raise_error(URI::InvalidComponentError) + -> { URI::MailTo.build(x) }.should.raise(URI::InvalidComponentError) end ok.flatten.join("\0").should == ok_all diff --git a/spec/ruby/library/uri/parse_spec.rb b/spec/ruby/library/uri/parse_spec.rb index e9ec59b490..f0373fbf5e 100644 --- a/spec/ruby/library/uri/parse_spec.rb +++ b/spec/ruby/library/uri/parse_spec.rb @@ -4,7 +4,7 @@ require_relative 'fixtures/classes' 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) + URI.parse("http://www.example.com/").should.is_a?(URI::HTTP) end it "populates the components of a parsed URI::HTTP, setting the port to 80 by default" do @@ -47,7 +47,7 @@ describe "URI.parse" do 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) + URI.parse("https://important-intern-net.net").should.is_a?(URI::HTTPS) end it "sets the port of a parsed https URI to 443 by default" do @@ -57,7 +57,7 @@ describe "URI.parse" do it "populates the components of a parsed URI::FTP object" do # generic, empty password. url = URI.parse("ftp://anonymous@ruby-lang.org/pub/ruby/1.8/ruby-1.8.6.tar.bz2;type=i") - url.should be_kind_of(URI::FTP) + url.should.is_a?(URI::FTP) URISpec.components(url).should == { scheme: "ftp", userinfo: "anonymous", @@ -69,7 +69,7 @@ describe "URI.parse" do # multidomain, no user or password url = URI.parse('ftp://ftp.is.co.za/rfc/rfc1808.txt') - url.should be_kind_of(URI::FTP) + url.should.is_a?(URI::FTP) URISpec.components(url).should == { scheme: "ftp", userinfo: nil, @@ -81,7 +81,7 @@ describe "URI.parse" do # empty user url = URI.parse('ftp://:pass@localhost/') - url.should be_kind_of(URI::FTP) + url.should.is_a?(URI::FTP) URISpec.components(url).should == { scheme: "ftp", userinfo: ":pass", @@ -97,7 +97,7 @@ describe "URI.parse" 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) + URI.parse(ldap_uri).should.is_a?(URI::LDAP) end end @@ -115,7 +115,7 @@ describe "URI.parse" do end it "returns a URI::MailTo object when passed a mailto URI" do - URI.parse("mailto:spam@mailinator.com").should be_kind_of(URI::MailTo) + URI.parse("mailto:spam@mailinator.com").should.is_a?(URI::MailTo) end it "populates the components of a parsed URI::MailTo object" do @@ -145,7 +145,7 @@ describe "URI.parse" do # gopher gopher = URI.parse('gopher://spinaltap.micro.umn.edu/00/Weather/California/Los%20Angeles') - gopher.should be_kind_of(URI::Generic) + gopher.should.is_a?(URI::Generic) URISpec.components(gopher).should == { scheme: "gopher", @@ -161,7 +161,7 @@ describe "URI.parse" do # news news = URI.parse('news:comp.infosystems.www.servers.unix') - news.should be_kind_of(URI::Generic) + news.should.is_a?(URI::Generic) URISpec.components(news).should == { scheme: "news", userinfo: nil, @@ -176,7 +176,7 @@ describe "URI.parse" do # telnet telnet = URI.parse('telnet://melvyl.ucop.edu/') - telnet.should be_kind_of(URI::Generic) + telnet.should.is_a?(URI::Generic) URISpec.components(telnet).should == { scheme: "telnet", userinfo: nil, @@ -191,9 +191,9 @@ describe "URI.parse" do # files file_l = URI.parse('file:///foo/bar.txt') - file_l.should be_kind_of(URI::Generic) + file_l.should.is_a?(URI::Generic) file = URI.parse('file:/foo/bar.txt') - file.should be_kind_of(URI::Generic) + file.should.is_a?(URI::Generic) end it "doesn't raise errors on URIs which has underscore in reg_name" do diff --git a/spec/ruby/library/uri/parser/extract_spec.rb b/spec/ruby/library/uri/parser/extract_spec.rb index 20d4565b08..f5ecd6ec8e 100644 --- a/spec/ruby/library/uri/parser/extract_spec.rb +++ b/spec/ruby/library/uri/parser/extract_spec.rb @@ -1,7 +1,90 @@ require_relative '../../../spec_helper' -require_relative '../shared/extract' require 'uri' describe "URI::Parser#extract" do - it_behaves_like :uri_extract, :extract, URI::Parser.new + before :all do + @parser = URI::Parser.new + end + + it "behaves according to its documentation" do + @parser.extract("text here http://foo.example.org/bla and here mailto:test@example.com and here also.").should == ["http://foo.example.org/bla", "mailto:test@example.com"] + end + + it "treats contiguous URIs as a single URI" do + @parser.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 + @parser.extract('From: XXX [mailto:xxx@xxx.xxx.xxx]').should == ['From:', 'mailto:xxx@xxx.xxx.xxx]'] + end + + it "wraps a URI string in an array" do + @parser.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 + @parser.extract("this is a string, it has http://rubini.us/ in it").should == ["http://rubini.us/"] + @parser.extract("mailto:spambait@example.com").should == ["mailto:spambait@example.com"] + @parser.extract("ftp://ruby-lang.org/").should == ["ftp://ruby-lang.org/"] + @parser.extract("https://mail.google.com").should == ["https://mail.google.com"] + @parser.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 + @parser.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:mduerst@ifi.unizh.ch + -- 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:mduerst@ifi.unizh.ch","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:test@example.com"] + @parser.extract("text here http://foo.example.org/bla and here mailto:test@example.com 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 + @parser.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:mduerst@ifi.unizh.ch + -- 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:mduerst@ifi.unizh.ch"] + end end diff --git a/spec/ruby/library/uri/parser/join_spec.rb b/spec/ruby/library/uri/parser/join_spec.rb index 0c9230be76..0fb29cf00a 100644 --- a/spec/ruby/library/uri/parser/join_spec.rb +++ b/spec/ruby/library/uri/parser/join_spec.rb @@ -1,7 +1,62 @@ require_relative '../../../spec_helper' -require_relative '../shared/join' require 'uri' describe "URI::Parser#join" do - it_behaves_like :uri_join, :join, URI::Parser.new + before :all do + @parser = URI::Parser.new + end + + it "returns a URI object of the concatenation of a protocol and domain, and a path" do + @parser.join("http://localhost/","main.rbx").should == URI.parse("http://localhost/main.rbx") + end + + it "accepts URI objects" do + @parser.join(URI("http://localhost/"),"main.rbx").should == URI.parse("http://localhost/main.rbx") + @parser.join("http://localhost/",URI("main.rbx")).should == URI.parse("http://localhost/main.rbx") + @parser.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") + @parser.join(str, str2).should == URI.parse("http://ruby-lang.org/foo/bar") + end + + it "raises an error if given no argument" do + -> { + @parser.join + }.should.raise(ArgumentError) + end + + it "doesn't create redundant '/'s" do + @parser.join("http://localhost/", "/main.rbx").should == URI.parse("http://localhost/main.rbx") + end + + it "discards arguments given before an absolute uri" do + @parser.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 + @parser.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/parser/parse_spec.rb b/spec/ruby/library/uri/parser/parse_spec.rb index df126eab6d..0e6a06ebe5 100644 --- a/spec/ruby/library/uri/parser/parse_spec.rb +++ b/spec/ruby/library/uri/parser/parse_spec.rb @@ -1,7 +1,213 @@ require_relative '../../../spec_helper' require_relative '../fixtures/classes' -require_relative '../shared/parse' describe "URI::Parser#parse" do - it_behaves_like :uri_parse, :parse, URI::Parser.new + before :all do + @parser = URI::Parser.new + end + + it "returns a URI::HTTP object when parsing an HTTP URI" do + @parser.parse("http://www.example.com/").should.is_a?(URI::HTTP) + end + + it "populates the components of a parsed URI::HTTP, setting the port to 80 by default" do + # general case + URISpec.components(@parser.parse("http://user:pass@example.com/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(@parser.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(@parser.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 + @parser.parse("http://example.com:8080/").port.should == 8080 + end + + it "returns a URI::HTTPS object when parsing an HTTPS URI" do + @parser.parse("https://important-intern-net.net").should.is_a?(URI::HTTPS) + end + + it "sets the port of a parsed https URI to 443 by default" do + @parser.parse("https://example.com/").port.should == 443 + end + + it "populates the components of a parsed URI::FTP object" do + # generic, empty password. + url = @parser.parse("ftp://anonymous@ruby-lang.org/pub/ruby/1.8/ruby-1.8.6.tar.bz2;type=i") + url.should.is_a?(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 = @parser.parse('ftp://ftp.is.co.za/rfc/rfc1808.txt') + url.should.is_a?(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 = @parser.parse('ftp://:pass@localhost/') + url.should.is_a?(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| + @parser.parse(ldap_uri).should.is_a?(URI::LDAP) + end + end + + it "populates the components of a parsed URI::LDAP object" do + URISpec.components(@parser.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 + @parser.parse("mailto:spam@mailinator.com").should.is_a?(URI::MailTo) + end + + it "populates the components of a parsed URI::MailTo object" do + URISpec.components(@parser.parse("mailto:spam@mailinator.com?subject=Discounts%20On%20Imported%20methods!!!&body=Exciting%20offer")).should == { + scheme: "mailto", + to: "spam@mailinator.com", + 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 = @parser.parse('gopher://spinaltap.micro.umn.edu/00/Weather/California/Los%20Angeles') + gopher.should.is_a?(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 = @parser.parse('news:comp.infosystems.www.servers.unix') + news.should.is_a?(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 = @parser.parse('telnet://melvyl.ucop.edu/') + telnet.should.is_a?(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 = @parser.parse('file:///foo/bar.txt') + file_l.should.is_a?(URI::Generic) + file = @parser.parse('file:/foo/bar.txt') + file.should.is_a?(URI::Generic) + end + + if URI::DEFAULT_PARSER == URI::RFC2396_Parser + it "raises errors on malformed URIs" do + -> { @parser.parse('http://a_b:80/') }.should.raise(URI::InvalidURIError) + -> { @parser.parse('http://a_b/') }.should.raise(URI::InvalidURIError) + end + elsif URI::DEFAULT_PARSER == URI::RFC3986_Parser + it "does not raise errors on URIs contained underscore" do + -> { @parser.parse('http://a_b:80/') }.should_not.raise(URI::InvalidURIError) + -> { @parser.parse('http://a_b/') }.should_not.raise(URI::InvalidURIError) + end + end end diff --git a/spec/ruby/library/uri/plus_spec.rb b/spec/ruby/library/uri/plus_spec.rb index b84b0767c1..51fb5e3750 100644 --- a/spec/ruby/library/uri/plus_spec.rb +++ b/spec/ruby/library/uri/plus_spec.rb @@ -36,7 +36,7 @@ describe "URI#+" do end it "raises a URI::BadURIError when adding two relative URIs" do - -> {URI.parse('a/b/c') + "d"}.should raise_error(URI::BadURIError) + -> {URI.parse('a/b/c') + "d"}.should.raise(URI::BadURIError) end #Todo: make more BDD? @@ -47,403 +47,403 @@ describe "URI#+" do # 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.should.is_a?(URI::Generic) url.to_s.should == 'g:h' url = @base_url.route_to('g:h') - url.should be_kind_of(URI::Generic) + url.should.is_a?(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.should.is_a?(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.should.is_a?(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.should.is_a?(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.should.is_a?(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.should.is_a?(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.should.is_a?(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.should.is_a?(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.should.is_a?(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.should.is_a?(URI::HTTP) url.to_s.should == 'http://g' url = @base_url.route_to('http://g') - url.should be_kind_of(URI::Generic) + url.should.is_a?(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.should.is_a?(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.should.is_a?(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.should.is_a?(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.should.is_a?(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.should.is_a?(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.should.is_a?(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.should.is_a?(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.should.is_a?(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.should.is_a?(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.should.is_a?(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.should.is_a?(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.should.is_a?(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.should.is_a?(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.should.is_a?(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.should.is_a?(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.should.is_a?(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.should.is_a?(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.should.is_a?(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.should.is_a?(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.should.is_a?(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.should.is_a?(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.should.is_a?(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.should.is_a?(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.should.is_a?(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.should.is_a?(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.should.is_a?(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.should.is_a?(URI::HTTP) url.to_s.should == 'http://a/' url = @base_url.route_to('http://a/') - url.should be_kind_of(URI::Generic) + url.should.is_a?(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.should.is_a?(URI::HTTP) url.to_s.should == 'http://a/' url = @base_url.route_to('http://a/') - url.should be_kind_of(URI::Generic) + url.should.is_a?(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.should.is_a?(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.should.is_a?(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.should.is_a?(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.should.is_a?(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.should.is_a?(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.should.is_a?(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.should.is_a?(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.should.is_a?(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.should.is_a?(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.should.is_a?(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.should.is_a?(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.should.is_a?(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.should.is_a?(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.should.is_a?(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.should.is_a?(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.should.is_a?(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.should.is_a?(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.should.is_a?(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.should.is_a?(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.should.is_a?(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.should.is_a?(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.should.is_a?(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.should.is_a?(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.should.is_a?(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.should.is_a?(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.should.is_a?(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.should.is_a?(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.should.is_a?(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.should.is_a?(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.should.is_a?(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.should.is_a?(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.should.is_a?(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.should.is_a?(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.should.is_a?(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.should.is_a?(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.should.is_a?(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.should.is_a?(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.should.is_a?(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.should.is_a?(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.should.is_a?(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.should.is_a?(URI::HTTP) url.to_s.should == 'http:g' url = @base_url.route_to('http:g') - url.should be_kind_of(URI::Generic) + url.should.is_a?(URI::Generic) url.to_s.should == 'http:g' end end diff --git a/spec/ruby/library/uri/select_spec.rb b/spec/ruby/library/uri/select_spec.rb index 839b68b3a1..27591f69f2 100644 --- a/spec/ruby/library/uri/select_spec.rb +++ b/spec/ruby/library/uri/select_spec.rb @@ -15,13 +15,13 @@ describe "URI#select" do end it "raises an ArgumentError if a component is requested that isn't valid under the given scheme" do - -> { URI("mailto:spam@mailinator.com").select(:path) }.should raise_error(ArgumentError) - -> { URI("http://blog.blag.web").select(:typecode) }.should raise_error(ArgumentError) + -> { URI("mailto:spam@mailinator.com").select(:path) }.should.raise(ArgumentError) + -> { URI("http://blog.blag.web").select(:typecode) }.should.raise(ArgumentError) end it "raises an ArgumentError if given strings rather than symbols" do -> { URI("http://host:8080/path/").select("scheme","host","port",'path') - }.should raise_error(ArgumentError) + }.should.raise(ArgumentError) end end diff --git a/spec/ruby/library/uri/set_component_spec.rb b/spec/ruby/library/uri/set_component_spec.rb index 642a5d6fcf..15f1ed1f87 100644 --- a/spec/ruby/library/uri/set_component_spec.rb +++ b/spec/ruby/library/uri/set_component_spec.rb @@ -6,40 +6,42 @@ 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' + version_is(URI::VERSION, "1.0.4") do + uri.to_s.should == 'http://oof@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@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@baz' + (uri.host = 'zab').should == 'zab' + uri.to_s.should == 'http://zab' + (uri.port = 8080).should == 8080 + uri.to_s.should == 'http://zab:8080' + (uri.path = '/').should == '/' + uri.to_s.should == 'http://zab:8080/' + (uri.query = 'a=1').should == 'a=1' + uri.to_s.should == 'http://zab:8080/?a=1' + (uri.fragment = 'b123').should == 'b123' + uri.to_s.should == 'http://zab:8080/?a=1#b123' + end uri = URI.parse('http://example.com') - -> { uri.password = 'bar' }.should raise_error(URI::InvalidURIError) + -> { uri.password = 'bar' }.should.raise(URI::InvalidURIError) uri.userinfo = 'foo:bar' uri.to_s.should == 'http://foo:bar@example.com' - -> { uri.registry = 'bar' }.should raise_error(URI::InvalidURIError) - -> { uri.opaque = 'bar' }.should raise_error(URI::InvalidURIError) + -> { uri.registry = 'bar' }.should.raise(URI::InvalidURIError) + -> { uri.opaque = 'bar' }.should.raise(URI::InvalidURIError) uri = URI.parse('mailto:foo@example.com') - -> { uri.user = 'bar' }.should raise_error(URI::InvalidURIError) - -> { uri.password = 'bar' }.should raise_error(URI::InvalidURIError) - -> { uri.userinfo = ['bar', 'baz'] }.should raise_error(URI::InvalidURIError) - -> { uri.host = 'bar' }.should raise_error(URI::InvalidURIError) - -> { uri.port = 'bar' }.should raise_error(URI::InvalidURIError) - -> { uri.path = 'bar' }.should raise_error(URI::InvalidURIError) - -> { uri.query = 'bar' }.should raise_error(URI::InvalidURIError) + -> { uri.user = 'bar' }.should.raise(URI::InvalidURIError) + -> { uri.password = 'bar' }.should.raise(URI::InvalidURIError) + -> { uri.userinfo = ['bar', 'baz'] }.should.raise(URI::InvalidURIError) + -> { uri.host = 'bar' }.should.raise(URI::InvalidURIError) + -> { uri.port = 'bar' }.should.raise(URI::InvalidURIError) + -> { uri.path = 'bar' }.should.raise(URI::InvalidURIError) + -> { uri.query = 'bar' }.should.raise(URI::InvalidURIError) end end diff --git a/spec/ruby/library/uri/shared/eql.rb b/spec/ruby/library/uri/shared/eql.rb index 2cc960d39a..978c4aae05 100644 --- a/spec/ruby/library/uri/shared/eql.rb +++ b/spec/ruby/library/uri/shared/eql.rb @@ -3,7 +3,7 @@ describe :uri_eql, shared: true 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 + URI(other).send(@method, normal_uri).should == false end end end @@ -11,7 +11,7 @@ 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 + URI("http://example.com/").send(@method, "http://example.com/").should == false + URI("http://example.com/").send(@method, nil).should == false end end diff --git a/spec/ruby/library/uri/shared/extract.rb b/spec/ruby/library/uri/shared/extract.rb deleted file mode 100644 index efe60ae4b9..0000000000 --- a/spec/ruby/library/uri/shared/extract.rb +++ /dev/null @@ -1,83 +0,0 @@ -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:test@example.com and here also.").should == ["http://foo.example.org/bla", "mailto:test@example.com"] - 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:xxx@xxx.xxx.xxx]').should == ['From:', 'mailto:xxx@xxx.xxx.xxx]'] - 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:spambait@example.com").should == ["mailto:spambait@example.com"] - @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:mduerst@ifi.unizh.ch - -- 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:mduerst@ifi.unizh.ch","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:test@example.com"] - @object.extract("text here http://foo.example.org/bla and here mailto:test@example.com 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:mduerst@ifi.unizh.ch - -- 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:mduerst@ifi.unizh.ch"] - end -end diff --git a/spec/ruby/library/uri/shared/join.rb b/spec/ruby/library/uri/shared/join.rb deleted file mode 100644 index 4df0782b37..0000000000 --- a/spec/ruby/library/uri/shared/join.rb +++ /dev/null @@ -1,56 +0,0 @@ -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 - -> { - @object.join - }.should raise_error(ArgumentError) - 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 deleted file mode 100644 index c5057b6c4b..0000000000 --- a/spec/ruby/library/uri/shared/parse.rb +++ /dev/null @@ -1,206 +0,0 @@ -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:pass@example.com/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://anonymous@ruby-lang.org/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:spam@mailinator.com").should be_kind_of(URI::MailTo) - end - - it "populates the components of a parsed URI::MailTo object" do - URISpec.components(@object.parse("mailto:spam@mailinator.com?subject=Discounts%20On%20Imported%20methods!!!&body=Exciting%20offer")).should == { - scheme: "mailto", - to: "spam@mailinator.com", - 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 - - if URI::DEFAULT_PARSER == URI::RFC2396_Parser - it "raises errors on malformed URIs" do - -> { @object.parse('http://a_b:80/') }.should raise_error(URI::InvalidURIError) - -> { @object.parse('http://a_b/') }.should raise_error(URI::InvalidURIError) - end - elsif URI::DEFAULT_PARSER == URI::RFC3986_Parser - it "does not raise errors on URIs contained underscore" do - -> { @object.parse('http://a_b:80/') }.should_not raise_error(URI::InvalidURIError) - -> { @object.parse('http://a_b/') }.should_not raise_error(URI::InvalidURIError) - end - end -end diff --git a/spec/ruby/library/uri/uri_spec.rb b/spec/ruby/library/uri/uri_spec.rb index 45a7502052..eab4e7176c 100644 --- a/spec/ruby/library/uri/uri_spec.rb +++ b/spec/ruby/library/uri/uri_spec.rb @@ -19,11 +19,11 @@ describe "the URI method" do it "returns the argument if it is a URI object" do result = URI.parse("http://ruby-lang.org") - URI(result).should equal(result) + 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 - -> {Object.new.URI("http://ruby-lang.org/")}.should raise_error(NoMethodError) + -> {Object.new.URI("http://ruby-lang.org/")}.should.raise(NoMethodError) end end |
