/spec/addressable/uri_spec.rb
Ruby | 5836 lines | 4843 code | 901 blank | 92 comment | 806 complexity | 5e424523a8dc28e4ad74f908ed39c151 MD5 | raw file
Possible License(s): Apache-2.0
Large files files are truncated, but you can click here to view the full file
- # coding: utf-8
- # Copyright (C) 2006-2013 Bob Aman
- #
- # Licensed under the Apache License, Version 2.0 (the "License");
- # you may not use this file except in compliance with the License.
- # You may obtain a copy of the License at
- #
- # http://www.apache.org/licenses/LICENSE-2.0
- #
- # Unless required by applicable law or agreed to in writing, software
- # distributed under the License is distributed on an "AS IS" BASIS,
- # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- # See the License for the specific language governing permissions and
- # limitations under the License.
- require "spec_helper"
- require "addressable/uri"
- if !"".respond_to?("force_encoding")
- class String
- def force_encoding(encoding)
- @encoding = encoding
- end
- def encoding
- @encoding ||= Encoding::ASCII_8BIT
- end
- end
- class Encoding
- def initialize(name)
- @name = name
- end
- def to_s
- return @name
- end
- UTF_8 = Encoding.new("UTF-8")
- ASCII_8BIT = Encoding.new("US-ASCII")
- end
- end
- module Fake
- module URI
- class HTTP
- def initialize(uri)
- @uri = uri
- end
- def to_s
- return @uri.to_s
- end
- alias :to_str :to_s
- end
- end
- end
- describe Addressable::URI, "when created with a non-numeric port number" do
- it "should raise an error" do
- (lambda do
- Addressable::URI.new(:port => "bogus")
- end).should raise_error(Addressable::URI::InvalidURIError)
- end
- end
- describe Addressable::URI, "when created with a non-string scheme" do
- it "should raise an error" do
- (lambda do
- Addressable::URI.new(:scheme => :bogus)
- end).should raise_error(TypeError)
- end
- end
- describe Addressable::URI, "when created with a non-string user" do
- it "should raise an error" do
- (lambda do
- Addressable::URI.new(:user => :bogus)
- end).should raise_error(TypeError)
- end
- end
- describe Addressable::URI, "when created with a non-string password" do
- it "should raise an error" do
- (lambda do
- Addressable::URI.new(:password => :bogus)
- end).should raise_error(TypeError)
- end
- end
- describe Addressable::URI, "when created with a non-string userinfo" do
- it "should raise an error" do
- (lambda do
- Addressable::URI.new(:userinfo => :bogus)
- end).should raise_error(TypeError)
- end
- end
- describe Addressable::URI, "when created with a non-string host" do
- it "should raise an error" do
- (lambda do
- Addressable::URI.new(:host => :bogus)
- end).should raise_error(TypeError)
- end
- end
- describe Addressable::URI, "when created with a non-string authority" do
- it "should raise an error" do
- (lambda do
- Addressable::URI.new(:authority => :bogus)
- end).should raise_error(TypeError)
- end
- end
- describe Addressable::URI, "when created with a non-string authority" do
- it "should raise an error" do
- (lambda do
- Addressable::URI.new(:authority => :bogus)
- end).should raise_error(TypeError)
- end
- end
- describe Addressable::URI, "when created with a non-string path" do
- it "should raise an error" do
- (lambda do
- Addressable::URI.new(:path => :bogus)
- end).should raise_error(TypeError)
- end
- end
- describe Addressable::URI, "when created with a non-string query" do
- it "should raise an error" do
- (lambda do
- Addressable::URI.new(:query => :bogus)
- end).should raise_error(TypeError)
- end
- end
- describe Addressable::URI, "when created with a non-string fragment" do
- it "should raise an error" do
- (lambda do
- Addressable::URI.new(:fragment => :bogus)
- end).should raise_error(TypeError)
- end
- end
- describe Addressable::URI, "when created with a scheme but no hierarchical " +
- "segment" do
- it "should raise an error" do
- (lambda do
- Addressable::URI.parse("http:")
- end).should raise_error(Addressable::URI::InvalidURIError)
- end
- end
- describe Addressable::URI, "when created with an invalid host" do
- it "should raise an error" do
- (lambda do
- Addressable::URI.new(:host => "<invalid>")
- end).should raise_error(Addressable::URI::InvalidURIError)
- end
- end
- describe Addressable::URI, "when created from nil components" do
- before do
- @uri = Addressable::URI.new
- end
- it "should have a nil site value" do
- @uri.site.should == nil
- end
- it "should have an empty path" do
- @uri.path.should == ""
- end
- it "should be an empty uri" do
- @uri.to_s.should == ""
- end
- it "should have a nil default port" do
- @uri.default_port.should == nil
- end
- it "should be empty" do
- @uri.should be_empty
- end
- it "should raise an error if the scheme is set to whitespace" do
- (lambda do
- @uri.scheme = "\t \n"
- end).should raise_error(Addressable::URI::InvalidURIError)
- end
- it "should raise an error if the scheme is set to all digits" do
- (lambda do
- @uri.scheme = "123"
- end).should raise_error(Addressable::URI::InvalidURIError)
- end
- it "should raise an error if set into an invalid state" do
- (lambda do
- @uri.user = "user"
- end).should raise_error(Addressable::URI::InvalidURIError)
- end
- it "should raise an error if set into an invalid state" do
- (lambda do
- @uri.password = "pass"
- end).should raise_error(Addressable::URI::InvalidURIError)
- end
- it "should raise an error if set into an invalid state" do
- (lambda do
- @uri.scheme = "http"
- @uri.fragment = "fragment"
- end).should raise_error(Addressable::URI::InvalidURIError)
- end
- it "should raise an error if set into an invalid state" do
- (lambda do
- @uri.fragment = "fragment"
- @uri.scheme = "http"
- end).should raise_error(Addressable::URI::InvalidURIError)
- end
- end
- describe Addressable::URI, "when initialized from individual components" do
- before do
- @uri = Addressable::URI.new(
- :scheme => "http",
- :user => "user",
- :password => "password",
- :host => "example.com",
- :port => 8080,
- :path => "/path",
- :query => "query=value",
- :fragment => "fragment"
- )
- end
- it "returns 'http' for #scheme" do
- @uri.scheme.should == "http"
- end
- it "returns 'http' for #normalized_scheme" do
- @uri.normalized_scheme.should == "http"
- end
- it "returns 'user' for #user" do
- @uri.user.should == "user"
- end
- it "returns 'user' for #normalized_user" do
- @uri.normalized_user.should == "user"
- end
- it "returns 'password' for #password" do
- @uri.password.should == "password"
- end
- it "returns 'password' for #normalized_password" do
- @uri.normalized_password.should == "password"
- end
- it "returns 'user:password' for #userinfo" do
- @uri.userinfo.should == "user:password"
- end
- it "returns 'user:password' for #normalized_userinfo" do
- @uri.normalized_userinfo.should == "user:password"
- end
- it "returns 'example.com' for #host" do
- @uri.host.should == "example.com"
- end
- it "returns 'example.com' for #normalized_host" do
- @uri.normalized_host.should == "example.com"
- end
- it "returns 'user:password@example.com:8080' for #authority" do
- @uri.authority.should == "user:password@example.com:8080"
- end
- it "returns 'user:password@example.com:8080' for #normalized_authority" do
- @uri.normalized_authority.should == "user:password@example.com:8080"
- end
- it "returns 8080 for #port" do
- @uri.port.should == 8080
- end
- it "returns 8080 for #normalized_port" do
- @uri.normalized_port.should == 8080
- end
- it "returns 80 for #default_port" do
- @uri.default_port.should == 80
- end
- it "returns 'http://user:password@example.com:8080' for #site" do
- @uri.site.should == "http://user:password@example.com:8080"
- end
- it "returns 'http://user:password@example.com:8080' for #normalized_site" do
- @uri.normalized_site.should == "http://user:password@example.com:8080"
- end
- it "returns '/path' for #path" do
- @uri.path.should == "/path"
- end
- it "returns '/path' for #normalized_path" do
- @uri.normalized_path.should == "/path"
- end
- it "returns 'query=value' for #query" do
- @uri.query.should == "query=value"
- end
- it "returns 'query=value' for #normalized_query" do
- @uri.normalized_query.should == "query=value"
- end
- it "returns 'fragment' for #fragment" do
- @uri.fragment.should == "fragment"
- end
- it "returns 'fragment' for #normalized_fragment" do
- @uri.normalized_fragment.should == "fragment"
- end
- it "returns #hash" do
- @uri.hash.should_not be nil
- end
- it "returns #to_s" do
- @uri.to_s.should ==
- "http://user:password@example.com:8080/path?query=value#fragment"
- end
- it "should not be empty" do
- @uri.should_not be_empty
- end
- it "should not be frozen" do
- @uri.should_not be_frozen
- end
- it "should allow destructive operations" do
- expect { @uri.normalize! }.not_to raise_error
- end
- end
- describe Addressable::URI, "when initialized from " +
- "frozen individual components" do
- before do
- @uri = Addressable::URI.new(
- :scheme => "http".freeze,
- :user => "user".freeze,
- :password => "password".freeze,
- :host => "example.com".freeze,
- :port => "8080".freeze,
- :path => "/path".freeze,
- :query => "query=value".freeze,
- :fragment => "fragment".freeze
- )
- end
- it "returns 'http' for #scheme" do
- @uri.scheme.should == "http"
- end
- it "returns 'http' for #normalized_scheme" do
- @uri.normalized_scheme.should == "http"
- end
- it "returns 'user' for #user" do
- @uri.user.should == "user"
- end
- it "returns 'user' for #normalized_user" do
- @uri.normalized_user.should == "user"
- end
- it "returns 'password' for #password" do
- @uri.password.should == "password"
- end
- it "returns 'password' for #normalized_password" do
- @uri.normalized_password.should == "password"
- end
- it "returns 'user:password' for #userinfo" do
- @uri.userinfo.should == "user:password"
- end
- it "returns 'user:password' for #normalized_userinfo" do
- @uri.normalized_userinfo.should == "user:password"
- end
- it "returns 'example.com' for #host" do
- @uri.host.should == "example.com"
- end
- it "returns 'example.com' for #normalized_host" do
- @uri.normalized_host.should == "example.com"
- end
- it "returns 'user:password@example.com:8080' for #authority" do
- @uri.authority.should == "user:password@example.com:8080"
- end
- it "returns 'user:password@example.com:8080' for #normalized_authority" do
- @uri.normalized_authority.should == "user:password@example.com:8080"
- end
- it "returns 8080 for #port" do
- @uri.port.should == 8080
- end
- it "returns 8080 for #normalized_port" do
- @uri.normalized_port.should == 8080
- end
- it "returns 80 for #default_port" do
- @uri.default_port.should == 80
- end
- it "returns 'http://user:password@example.com:8080' for #site" do
- @uri.site.should == "http://user:password@example.com:8080"
- end
- it "returns 'http://user:password@example.com:8080' for #normalized_site" do
- @uri.normalized_site.should == "http://user:password@example.com:8080"
- end
- it "returns '/path' for #path" do
- @uri.path.should == "/path"
- end
- it "returns '/path' for #normalized_path" do
- @uri.normalized_path.should == "/path"
- end
- it "returns 'query=value' for #query" do
- @uri.query.should == "query=value"
- end
- it "returns 'query=value' for #normalized_query" do
- @uri.normalized_query.should == "query=value"
- end
- it "returns 'fragment' for #fragment" do
- @uri.fragment.should == "fragment"
- end
- it "returns 'fragment' for #normalized_fragment" do
- @uri.normalized_fragment.should == "fragment"
- end
- it "returns #hash" do
- @uri.hash.should_not be nil
- end
- it "returns #to_s" do
- @uri.to_s.should ==
- "http://user:password@example.com:8080/path?query=value#fragment"
- end
- it "should not be empty" do
- @uri.should_not be_empty
- end
- it "should not be frozen" do
- @uri.should_not be_frozen
- end
- it "should allow destructive operations" do
- expect { @uri.normalize! }.not_to raise_error
- end
- end
- describe Addressable::URI, "when parsed from a frozen string" do
- before do
- @uri = Addressable::URI.parse(
- "http://user:password@example.com:8080/path?query=value#fragment".freeze
- )
- end
- it "returns 'http' for #scheme" do
- @uri.scheme.should == "http"
- end
- it "returns 'http' for #normalized_scheme" do
- @uri.normalized_scheme.should == "http"
- end
- it "returns 'user' for #user" do
- @uri.user.should == "user"
- end
- it "returns 'user' for #normalized_user" do
- @uri.normalized_user.should == "user"
- end
- it "returns 'password' for #password" do
- @uri.password.should == "password"
- end
- it "returns 'password' for #normalized_password" do
- @uri.normalized_password.should == "password"
- end
- it "returns 'user:password' for #userinfo" do
- @uri.userinfo.should == "user:password"
- end
- it "returns 'user:password' for #normalized_userinfo" do
- @uri.normalized_userinfo.should == "user:password"
- end
- it "returns 'example.com' for #host" do
- @uri.host.should == "example.com"
- end
- it "returns 'example.com' for #normalized_host" do
- @uri.normalized_host.should == "example.com"
- end
- it "returns 'user:password@example.com:8080' for #authority" do
- @uri.authority.should == "user:password@example.com:8080"
- end
- it "returns 'user:password@example.com:8080' for #normalized_authority" do
- @uri.normalized_authority.should == "user:password@example.com:8080"
- end
- it "returns 8080 for #port" do
- @uri.port.should == 8080
- end
- it "returns 8080 for #normalized_port" do
- @uri.normalized_port.should == 8080
- end
- it "returns 80 for #default_port" do
- @uri.default_port.should == 80
- end
- it "returns 'http://user:password@example.com:8080' for #site" do
- @uri.site.should == "http://user:password@example.com:8080"
- end
- it "returns 'http://user:password@example.com:8080' for #normalized_site" do
- @uri.normalized_site.should == "http://user:password@example.com:8080"
- end
- it "returns '/path' for #path" do
- @uri.path.should == "/path"
- end
- it "returns '/path' for #normalized_path" do
- @uri.normalized_path.should == "/path"
- end
- it "returns 'query=value' for #query" do
- @uri.query.should == "query=value"
- end
- it "returns 'query=value' for #normalized_query" do
- @uri.normalized_query.should == "query=value"
- end
- it "returns 'fragment' for #fragment" do
- @uri.fragment.should == "fragment"
- end
- it "returns 'fragment' for #normalized_fragment" do
- @uri.normalized_fragment.should == "fragment"
- end
- it "returns #hash" do
- @uri.hash.should_not be nil
- end
- it "returns #to_s" do
- @uri.to_s.should ==
- "http://user:password@example.com:8080/path?query=value#fragment"
- end
- it "should not be empty" do
- @uri.should_not be_empty
- end
- it "should not be frozen" do
- @uri.should_not be_frozen
- end
- it "should allow destructive operations" do
- expect { @uri.normalize! }.not_to raise_error
- end
- end
- describe Addressable::URI, "when frozen" do
- before do
- @uri = Addressable::URI.new.freeze
- end
- it "returns nil for #scheme" do
- @uri.scheme.should == nil
- end
- it "returns nil for #normalized_scheme" do
- @uri.normalized_scheme.should == nil
- end
- it "returns nil for #user" do
- @uri.user.should == nil
- end
- it "returns nil for #normalized_user" do
- @uri.normalized_user.should == nil
- end
- it "returns nil for #password" do
- @uri.password.should == nil
- end
- it "returns nil for #normalized_password" do
- @uri.normalized_password.should == nil
- end
- it "returns nil for #userinfo" do
- @uri.userinfo.should == nil
- end
- it "returns nil for #normalized_userinfo" do
- @uri.normalized_userinfo.should == nil
- end
- it "returns nil for #host" do
- @uri.host.should == nil
- end
- it "returns nil for #normalized_host" do
- @uri.normalized_host.should == nil
- end
- it "returns nil for #authority" do
- @uri.authority.should == nil
- end
- it "returns nil for #normalized_authority" do
- @uri.normalized_authority.should == nil
- end
- it "returns nil for #port" do
- @uri.port.should == nil
- end
- it "returns nil for #normalized_port" do
- @uri.normalized_port.should == nil
- end
- it "returns nil for #default_port" do
- @uri.default_port.should == nil
- end
- it "returns nil for #site" do
- @uri.site.should == nil
- end
- it "returns nil for #normalized_site" do
- @uri.normalized_site.should == nil
- end
- it "returns '' for #path" do
- @uri.path.should == ''
- end
- it "returns '' for #normalized_path" do
- @uri.normalized_path.should == ''
- end
- it "returns nil for #query" do
- @uri.query.should == nil
- end
- it "returns nil for #normalized_query" do
- @uri.normalized_query.should == nil
- end
- it "returns nil for #fragment" do
- @uri.fragment.should == nil
- end
- it "returns nil for #normalized_fragment" do
- @uri.normalized_fragment.should == nil
- end
- it "returns #hash" do
- @uri.hash.should_not be nil
- end
- it "returns #to_s" do
- @uri.to_s.should == ''
- end
- it "should be empty" do
- @uri.should be_empty
- end
- it "should be frozen" do
- @uri.should be_frozen
- end
- it "should not be frozen after duping" do
- @uri.dup.should_not be_frozen
- end
- it "should not allow destructive operations" do
- expect { @uri.normalize! }.to raise_error { |error|
- error.message.should match(/can't modify frozen/)
- error.should satisfy { |e| RuntimeError === e || TypeError === e }
- }
- end
- end
- describe Addressable::URI, "when frozen" do
- before do
- @uri = Addressable::URI.parse(
- "HTTP://example.com.:%38%30/%70a%74%68?a=%31#1%323"
- ).freeze
- end
- it "returns 'HTTP' for #scheme" do
- @uri.scheme.should == "HTTP"
- end
- it "returns 'http' for #normalized_scheme" do
- @uri.normalized_scheme.should == "http"
- @uri.normalize.scheme.should == "http"
- end
- it "returns nil for #user" do
- @uri.user.should == nil
- end
- it "returns nil for #normalized_user" do
- @uri.normalized_user.should == nil
- end
- it "returns nil for #password" do
- @uri.password.should == nil
- end
- it "returns nil for #normalized_password" do
- @uri.normalized_password.should == nil
- end
- it "returns nil for #userinfo" do
- @uri.userinfo.should == nil
- end
- it "returns nil for #normalized_userinfo" do
- @uri.normalized_userinfo.should == nil
- end
- it "returns 'example.com.' for #host" do
- @uri.host.should == "example.com."
- end
- it "returns nil for #normalized_host" do
- @uri.normalized_host.should == "example.com"
- @uri.normalize.host.should == "example.com"
- end
- it "returns 'example.com.:80' for #authority" do
- @uri.authority.should == "example.com.:80"
- end
- it "returns 'example.com:80' for #normalized_authority" do
- @uri.normalized_authority.should == "example.com"
- @uri.normalize.authority.should == "example.com"
- end
- it "returns 80 for #port" do
- @uri.port.should == 80
- end
- it "returns nil for #normalized_port" do
- @uri.normalized_port.should == nil
- @uri.normalize.port.should == nil
- end
- it "returns 80 for #default_port" do
- @uri.default_port.should == 80
- end
- it "returns 'HTTP://example.com.:80' for #site" do
- @uri.site.should == "HTTP://example.com.:80"
- end
- it "returns 'http://example.com' for #normalized_site" do
- @uri.normalized_site.should == "http://example.com"
- @uri.normalize.site.should == "http://example.com"
- end
- it "returns '/%70a%74%68' for #path" do
- @uri.path.should == "/%70a%74%68"
- end
- it "returns '/path' for #normalized_path" do
- @uri.normalized_path.should == "/path"
- @uri.normalize.path.should == "/path"
- end
- it "returns 'a=%31' for #query" do
- @uri.query.should == "a=%31"
- end
- it "returns 'a=1' for #normalized_query" do
- @uri.normalized_query.should == "a=1"
- @uri.normalize.query.should == "a=1"
- end
- it "returns '1%323' for #fragment" do
- @uri.fragment.should == "1%323"
- end
- it "returns '123' for #normalized_fragment" do
- @uri.normalized_fragment.should == "123"
- @uri.normalize.fragment.should == "123"
- end
- it "returns #hash" do
- @uri.hash.should_not be nil
- end
- it "returns #to_s" do
- @uri.to_s.should == 'HTTP://example.com.:80/%70a%74%68?a=%31#1%323'
- @uri.normalize.to_s.should == 'http://example.com/path?a=1#123'
- end
- it "should not be empty" do
- @uri.should_not be_empty
- end
- it "should be frozen" do
- @uri.should be_frozen
- end
- it "should not be frozen after duping" do
- @uri.dup.should_not be_frozen
- end
- it "should not allow destructive operations" do
- expect { @uri.normalize! }.to raise_error { |error|
- error.message.should match(/can't modify frozen/)
- error.should satisfy { |e| RuntimeError === e || TypeError === e }
- }
- end
- end
- describe Addressable::URI, "when created from string components" do
- before do
- @uri = Addressable::URI.new(
- :scheme => "http", :host => "example.com"
- )
- end
- it "should have a site value of 'http://example.com'" do
- @uri.site.should == "http://example.com"
- end
- it "should be equal to the equivalent parsed URI" do
- @uri.should == Addressable::URI.parse("http://example.com")
- end
- it "should raise an error if invalid components omitted" do
- (lambda do
- @uri.omit(:bogus)
- end).should raise_error(ArgumentError)
- (lambda do
- @uri.omit(:scheme, :bogus, :path)
- end).should raise_error(ArgumentError)
- end
- end
- describe Addressable::URI, "when created with a nil host but " +
- "non-nil authority components" do
- it "should raise an error" do
- (lambda do
- Addressable::URI.new(:user => "user", :password => "pass", :port => 80)
- end).should raise_error(Addressable::URI::InvalidURIError)
- end
- end
- describe Addressable::URI, "when created with both an authority and a user" do
- it "should raise an error" do
- (lambda do
- Addressable::URI.new(
- :user => "user", :authority => "user@example.com:80"
- )
- end).should raise_error(ArgumentError)
- end
- end
- describe Addressable::URI, "when created with an authority and no port" do
- before do
- @uri = Addressable::URI.new(:authority => "user@example.com")
- end
- it "should not infer a port" do
- @uri.port.should == nil
- @uri.default_port.should == nil
- @uri.inferred_port.should == nil
- end
- it "should have a site value of '//user@example.com'" do
- @uri.site.should == "//user@example.com"
- end
- it "should have a 'null' origin" do
- @uri.origin.should == 'null'
- end
- end
- describe Addressable::URI, "when created with both a userinfo and a user" do
- it "should raise an error" do
- (lambda do
- Addressable::URI.new(:user => "user", :userinfo => "user:pass")
- end).should raise_error(ArgumentError)
- end
- end
- describe Addressable::URI, "when created with a path that hasn't been " +
- "prefixed with a '/' but a host specified" do
- before do
- @uri = Addressable::URI.new(
- :scheme => "http", :host => "example.com", :path => "path"
- )
- end
- it "should prefix a '/' to the path" do
- @uri.should == Addressable::URI.parse("http://example.com/path")
- end
- it "should have a site value of 'http://example.com'" do
- @uri.site.should == "http://example.com"
- end
- it "should have an origin of 'http://example.com" do
- @uri.origin.should == 'http://example.com'
- end
- end
- describe Addressable::URI, "when created with a path that hasn't been " +
- "prefixed with a '/' but no host specified" do
- before do
- @uri = Addressable::URI.new(
- :scheme => "http", :path => "path"
- )
- end
- it "should not prefix a '/' to the path" do
- @uri.should == Addressable::URI.parse("http:path")
- end
- it "should have a site value of 'http:'" do
- @uri.site.should == "http:"
- end
- it "should have a 'null' origin" do
- @uri.origin.should == 'null'
- end
- end
- describe Addressable::URI, "when parsed from an Addressable::URI object" do
- it "should not have unexpected side-effects" do
- original_uri = Addressable::URI.parse("http://example.com/")
- new_uri = Addressable::URI.parse(original_uri)
- new_uri.host = 'www.example.com'
- new_uri.host.should == 'www.example.com'
- new_uri.to_s.should == 'http://www.example.com/'
- original_uri.host.should == 'example.com'
- original_uri.to_s.should == 'http://example.com/'
- end
- it "should not have unexpected side-effects" do
- original_uri = Addressable::URI.parse("http://example.com/")
- new_uri = Addressable::URI.heuristic_parse(original_uri)
- new_uri.host = 'www.example.com'
- new_uri.host.should == 'www.example.com'
- new_uri.to_s.should == 'http://www.example.com/'
- original_uri.host.should == 'example.com'
- original_uri.to_s.should == 'http://example.com/'
- end
- end
- describe Addressable::URI, "when parsed from something that looks " +
- "like a URI object" do
- it "should parse without error" do
- uri = Addressable::URI.parse(Fake::URI::HTTP.new("http://example.com/"))
- (lambda do
- Addressable::URI.parse(uri)
- end).should_not raise_error
- end
- end
- describe Addressable::URI, "when parsed from ''" do
- before do
- @uri = Addressable::URI.parse("")
- end
- it "should have no scheme" do
- @uri.scheme.should == nil
- end
- it "should not be considered to be ip-based" do
- @uri.should_not be_ip_based
- end
- it "should have a path of ''" do
- @uri.path.should == ""
- end
- it "should have a request URI of '/'" do
- @uri.request_uri.should == "/"
- end
- it "should be considered relative" do
- @uri.should be_relative
- end
- it "should be considered to be in normal form" do
- @uri.normalize.should be_eql(@uri)
- end
- it "should have a 'null' origin" do
- @uri.origin.should == 'null'
- end
- end
- # Section 1.1.2 of RFC 3986
- describe Addressable::URI, "when parsed from " +
- "'ftp://ftp.is.co.za/rfc/rfc1808.txt'" do
- before do
- @uri = Addressable::URI.parse("ftp://ftp.is.co.za/rfc/rfc1808.txt")
- end
- it "should use the 'ftp' scheme" do
- @uri.scheme.should == "ftp"
- end
- it "should be considered to be ip-based" do
- @uri.should be_ip_based
- end
- it "should have a host of 'ftp.is.co.za'" do
- @uri.host.should == "ftp.is.co.za"
- end
- it "should have inferred_port of 21" do
- @uri.inferred_port.should == 21
- end
- it "should have a path of '/rfc/rfc1808.txt'" do
- @uri.path.should == "/rfc/rfc1808.txt"
- end
- it "should not have a request URI" do
- @uri.request_uri.should == nil
- end
- it "should be considered to be in normal form" do
- @uri.normalize.should be_eql(@uri)
- end
- it "should have an origin of 'ftp://ftp.is.co.za'" do
- @uri.origin.should == 'ftp://ftp.is.co.za'
- end
- end
- # Section 1.1.2 of RFC 3986
- describe Addressable::URI, "when parsed from " +
- "'http://www.ietf.org/rfc/rfc2396.txt'" do
- before do
- @uri = Addressable::URI.parse("http://www.ietf.org/rfc/rfc2396.txt")
- end
- it "should use the 'http' scheme" do
- @uri.scheme.should == "http"
- end
- it "should be considered to be ip-based" do
- @uri.should be_ip_based
- end
- it "should have a host of 'www.ietf.org'" do
- @uri.host.should == "www.ietf.org"
- end
- it "should have inferred_port of 80" do
- @uri.inferred_port.should == 80
- end
- it "should have a path of '/rfc/rfc2396.txt'" do
- @uri.path.should == "/rfc/rfc2396.txt"
- end
- it "should have a request URI of '/rfc/rfc2396.txt'" do
- @uri.request_uri.should == "/rfc/rfc2396.txt"
- end
- it "should be considered to be in normal form" do
- @uri.normalize.should be_eql(@uri)
- end
- it "should correctly omit components" do
- @uri.omit(:scheme).to_s.should == "//www.ietf.org/rfc/rfc2396.txt"
- @uri.omit(:path).to_s.should == "http://www.ietf.org"
- end
- it "should correctly omit components destructively" do
- @uri.omit!(:scheme)
- @uri.to_s.should == "//www.ietf.org/rfc/rfc2396.txt"
- end
- it "should have an origin of 'http://www.ietf.org'" do
- @uri.origin.should == 'http://www.ietf.org'
- end
- end
- # Section 1.1.2 of RFC 3986
- describe Addressable::URI, "when parsed from " +
- "'ldap://[2001:db8::7]/c=GB?objectClass?one'" do
- before do
- @uri = Addressable::URI.parse("ldap://[2001:db8::7]/c=GB?objectClass?one")
- end
- it "should use the 'ldap' scheme" do
- @uri.scheme.should == "ldap"
- end
- it "should be considered to be ip-based" do
- @uri.should be_ip_based
- end
- it "should have a host of '[2001:db8::7]'" do
- @uri.host.should == "[2001:db8::7]"
- end
- it "should have inferred_port of 389" do
- @uri.inferred_port.should == 389
- end
- it "should have a path of '/c=GB'" do
- @uri.path.should == "/c=GB"
- end
- it "should not have a request URI" do
- @uri.request_uri.should == nil
- end
- it "should not allow request URI assignment" do
- (lambda do
- @uri.request_uri = "/"
- end).should raise_error(Addressable::URI::InvalidURIError)
- end
- it "should have a query of 'objectClass?one'" do
- @uri.query.should == "objectClass?one"
- end
- it "should be considered to be in normal form" do
- @uri.normalize.should be_eql(@uri)
- end
- it "should correctly omit components" do
- @uri.omit(:scheme, :authority).to_s.should == "/c=GB?objectClass?one"
- @uri.omit(:path).to_s.should == "ldap://[2001:db8::7]?objectClass?one"
- end
- it "should correctly omit components destructively" do
- @uri.omit!(:scheme, :authority)
- @uri.to_s.should == "/c=GB?objectClass?one"
- end
- it "should raise an error if omission would create an invalid URI" do
- (lambda do
- @uri.omit(:authority, :path)
- end).should raise_error(Addressable::URI::InvalidURIError)
- end
- it "should have an origin of 'ldap://[2001:db8::7]'" do
- @uri.origin.should == 'ldap://[2001:db8::7]'
- end
- end
- # Section 1.1.2 of RFC 3986
- describe Addressable::URI, "when parsed from " +
- "'mailto:John.Doe@example.com'" do
- before do
- @uri = Addressable::URI.parse("mailto:John.Doe@example.com")
- end
- it "should use the 'mailto' scheme" do
- @uri.scheme.should == "mailto"
- end
- it "should not be considered to be ip-based" do
- @uri.should_not be_ip_based
- end
- it "should not have an inferred_port" do
- @uri.inferred_port.should == nil
- end
- it "should have a path of 'John.Doe@example.com'" do
- @uri.path.should == "John.Doe@example.com"
- end
- it "should not have a request URI" do
- @uri.request_uri.should == nil
- end
- it "should be considered to be in normal form" do
- @uri.normalize.should be_eql(@uri)
- end
- it "should have a 'null' origin" do
- @uri.origin.should == 'null'
- end
- end
- # Section 2 of RFC 6068
- describe Addressable::URI, "when parsed from " +
- "'mailto:?to=addr1@an.example,addr2@an.example'" do
- before do
- @uri = Addressable::URI.parse(
- "mailto:?to=addr1@an.example,addr2@an.example"
- )
- end
- it "should use the 'mailto' scheme" do
- @uri.scheme.should == "mailto"
- end
- it "should not be considered to be ip-based" do
- @uri.should_not be_ip_based
- end
- it "should not have an inferred_port" do
- @uri.inferred_port.should == nil
- end
- it "should have a path of ''" do
- @uri.path.should == ""
- end
- it "should not have a request URI" do
- @uri.request_uri.should == nil
- end
- it "should have the To: field value parameterized" do
- @uri.query_values(Hash)["to"].should == (
- "addr1@an.example,addr2@an.example"
- )
- end
- it "should be considered to be in normal form" do
- @uri.normalize.should be_eql(@uri)
- end
- it "should have a 'null' origin" do
- @uri.origin.should == 'null'
- end
- end
- # Section 1.1.2 of RFC 3986
- describe Addressable::URI, "when parsed from " +
- "'news:comp.infosystems.www.servers.unix'" do
- before do
- @uri = Addressable::URI.parse("news:comp.infosystems.www.servers.unix")
- end
- it "should use the 'news' scheme" do
- @uri.scheme.should == "news"
- end
- it "should not have an inferred_port" do
- @uri.inferred_port.should == nil
- end
- it "should not be considered to be ip-based" do
- @uri.should_not be_ip_based
- end
- it "should have a path of 'comp.infosystems.www.servers.unix'" do
- @uri.path.should == "comp.infosystems.www.servers.unix"
- end
- it "should not have a request URI" do
- @uri.request_uri.should == nil
- end
- it "should be considered to be in normal form" do
- @uri.normalize.should be_eql(@uri)
- end
- it "should have a 'null' origin" do
- @uri.origin.should == 'null'
- end
- end
- # Section 1.1.2 of RFC 3986
- describe Addressable::URI, "when parsed from " +
- "'tel:+1-816-555-1212'" do
- before do
- @uri = Addressable::URI.parse("tel:+1-816-555-1212")
- end
- it "should use the 'tel' scheme" do
- @uri.scheme.should == "tel"
- end
- it "should not be considered to be ip-based" do
- @uri.should_not be_ip_based
- end
- it "should not have an inferred_port" do
- @uri.inferred_port.should == nil
- end
- it "should have a path of '+1-816-555-1212'" do
- @uri.path.should == "+1-816-555-1212"
- end
- it "should not have a request URI" do
- @uri.request_uri.should == nil
- end
- it "should be considered to be in normal form" do
- @uri.normalize.should be_eql(@uri)
- end
- it "should have a 'null' origin" do
- @uri.origin.should == 'null'
- end
- end
- # Section 1.1.2 of RFC 3986
- describe Addressable::URI, "when parsed from " +
- "'telnet://192.0.2.16:80/'" do
- before do
- @uri = Addressable::URI.parse("telnet://192.0.2.16:80/")
- end
- it "should use the 'telnet' scheme" do
- @uri.scheme.should == "telnet"
- end
- it "should have a host of '192.0.2.16'" do
- @uri.host.should == "192.0.2.16"
- end
- it "should have a port of 80" do
- @uri.port.should == 80
- end
- it "should have a inferred_port of 80" do
- @uri.inferred_port.should == 80
- end
- it "should have a default_port of 23" do
- @uri.default_port.should == 23
- end
- it "should be considered to be ip-based" do
- @uri.should be_ip_based
- end
- it "should have a path of '/'" do
- @uri.path.should == "/"
- end
- it "should not have a request URI" do
- @uri.request_uri.should == nil
- end
- it "should be considered to be in normal form" do
- @uri.normalize.should be_eql(@uri)
- end
- it "should have an origin of 'telnet://192.0.2.16:80'" do
- @uri.origin.should == 'telnet://192.0.2.16:80'
- end
- end
- # Section 1.1.2 of RFC 3986
- describe Addressable::URI, "when parsed from " +
- "'urn:oasis:names:specification:docbook:dtd:xml:4.1.2'" do
- before do
- @uri = Addressable::URI.parse(
- "urn:oasis:names:specification:docbook:dtd:xml:4.1.2")
- end
- it "should use the 'urn' scheme" do
- @uri.scheme.should == "urn"
- end
- it "should not have an inferred_port" do
- @uri.inferred_port.should == nil
- end
- it "should not be considered to be ip-based" do
- @uri.should_not be_ip_based
- end
- it "should have a path of " +
- "'oasis:names:specification:docbook:dtd:xml:4.1.2'" do
- @uri.path.should == "oasis:names:specification:docbook:dtd:xml:4.1.2"
- end
- it "should not have a request URI" do
- @uri.request_uri.should == nil
- end
- it "should be considered to be in normal form" do
- @uri.normalize.should be_eql(@uri)
- end
- it "should have a 'null' origin" do
- @uri.origin.should == 'null'
- end
- end
- describe Addressable::URI, "when heuristically parsed from " +
- "'192.0.2.16:8000/path'" do
- before do
- @uri = Addressable::URI.heuristic_parse("192.0.2.16:8000/path")
- end
- it "should use the 'http' scheme" do
- @uri.scheme.should == "http"
- end
- it "should have a host of '192.0.2.16'" do
- @uri.host.should == "192.0.2.16"
- end
- it "should have a port of '8000'" do
- @uri.port.should == 8000
- end
- it "should be considered to be ip-based" do
- @uri.should be_ip_based
- end
- it "should have a path of '/path'" do
- @uri.path.should == "/path"
- end
- it "should be considered to be in normal form" do
- @uri.normalize.should be_eql(@uri)
- end
- it "should have an origin of 'http://192.0.2.16:8000'" do
- @uri.origin.should == 'http://192.0.2.16:8000'
- end
- end
- describe Addressable::URI, "when parsed from " +
- "'http://example.com'" do
- before do
- @uri = Addressable::URI.parse("http://example.com")
- end
- it "when inspected, should have the correct URI" do
- @uri.inspect.should include("http://example.com")
- end
- it "when inspected, should have the correct class name" do
- @uri.inspect.should include("Addressable::URI")
- end
- it "when inspected, should have the correct object id" do
- @uri.inspect.should include("%#0x" % @uri.object_id)
- end
- it "should use the 'http' scheme" do
- @uri.scheme.should == "http"
- end
- it "should be considered to be ip-based" do
- @uri.should be_ip_based
- end
- it "should have an authority segment of 'example.com'" do
- @uri.authority.should == "example.com"
- end
- it "should have a host of 'example.com'" do
- @uri.host.should == "example.com"
- end
- it "should be considered ip-based" do
- @uri.should be_ip_based
- end
- it "should have no username" do
- @uri.user.should == nil
- end
- it "should have no password" do
- @uri.password.should == nil
- end
- it "should use port 80" do
- @uri.inferred_port.should == 80
- end
- it "should not have a specified port" do
- @uri.port.should == nil
- end
- it "should have an empty path" do
- @uri.path.should == ""
- end
- it "should have no query string" do
- @uri.query.should == nil
- @uri.query_values.should == nil
- end
- it "should have a request URI of '/'" do
- @uri.request_uri.should == "/"
- end
- it "should have no fragment" do
- @uri.fragment.should == nil
- end
- it "should be considered absolute" do
- @uri.should be_absolute
- end
- it "should not be considered relative" do
- @uri.should_not be_relative
- end
- it "should not be exactly equal to 42" do
- @uri.eql?(42).should == false
- end
- it "should not be equal to 42" do
- (@uri == 42).should == false
- end
- it "should not be roughly equal to 42" do
- (@uri === 42).should == false
- end
- it "should be exactly equal to http://example.com" do
- @uri.eql?(Addressable::URI.parse("http://example.com")).should == true
- end
- it "should be roughly equal to http://example.com/" do
- (@uri === Addressable::URI.parse("http://example.com/")).should == true
- end
- it "should be roughly equal to the string 'http://example.com/'" do
- (@uri === "http://example.com/").should == true
- end
- it "should not be roughly equal to the string " +
- "'http://example.com:bogus/'" do
- (lambda do
- (@uri === "http://example.com:bogus/").should == false
- end).should_not raise_error
- end
- it "should result in itself when joined with itself" do
- @uri.join(@uri).to_s.should == "http://example.com"
- @uri.join!(@uri).to_s.should == "http://example.com"
- end
- it "should be equivalent to http://EXAMPLE.com" do
- @uri.should == Addressable::URI.parse("http://EXAMPLE.com")
- end
- it "should be equivalent to http://EXAMPLE.com:80/" do
- @uri.should == Addressable::URI.parse("http://EXAMPLE.com:80/")
- end
- it "should have the same hash as http://example.com" do
- @uri.hash.should == Addressable::URI.parse("http://example.com").hash
- end
- it "should have the same hash as http://EXAMPLE.com after assignment" do
- @uri.host = "EXAMPLE.com"
- @uri.hash.should == Addressable::URI.parse("http://EXAMPLE.com").hash
- end
- it "should have a different hash from http://EXAMPLE.com" do
- @uri.hash.should_not == Addressable::URI.parse("http://EXAMPLE.com").hash
- end
- # Section 6.2.3 of RFC 3986
- it "should be equivalent to http://example.com/" do
- @uri.should == Addressable::URI.parse("http://example.com/")
- end
- # Section 6.2.3 of RFC 3986
- it "should be equivalent to http://example.com:/" do
- @uri.should == Addressable::URI.parse("http://example.com:/")
- end
- # Section 6.2.3 of RFC 3986
- it "should be equivalent to http://example.com:80/" do
- @uri.should == Addressable::URI.parse("http://example.com:80/")
- end
- # Section 6.2.2.1 of RFC 3986
- it "should be equivalent to http://EXAMPLE.COM/" do
- @uri.should == Addressable::URI.parse("http://EXAMPLE.COM/")
- end
- it "should have a route of '/path/' to 'http://example.com/path/'" do
- @uri.route_to("http://example.com/path/").should ==
- Addressable::URI.parse("/path/")
- end
- it "should have a route of '..' from 'http://example.com/path/'" do
- @uri.route_from("http://example.com/path/").should ==
- Addressable::URI.parse("..")
- end
- it "should have a route of '#' to 'http://example.com/'" do
- @uri.route_to("http://example.com/").should ==
- Addressable::URI.parse("#")
- end
- it "should have a route of 'http://elsewhere.com/' to " +
- "'http://elsewhere.com/'" do
- @uri.route_to("http://elsewhere.com/").should ==
- Addressable::URI.parse("http://elsewhere.com/")
- end
- it "when joined with 'relative/path' should be " +
- "'http://example.com/relative/path'" do
- @uri.join('relative/path').should ==
- Addressable::URI.parse("http://example.com/relative/path")
- end
- it "when joined with a bogus object a TypeError should be raised" do
- (lambda do
- @uri.join(42)
- end).should raise_error(TypeError)
- end
- it "should have the correct username after assignment" do
- @uri.user = "newuser"
- @uri.user.should == "newuser"
- @uri.password.should == nil
- @uri.to_s.should == "http://newuser@example.com"
- end
- it "should have the correct username after assignment" do
- @uri.user = "user@123!"
- @uri.user.should == "user@123!"
- @uri.normalized_user.should == "user%40123%21"
- @uri.password.should == nil
- @uri.normalize.to_s.should == "http://user%40123%21@example.com/"
- end
- it "should have the correct password after assignment" do
- @uri.password = "newpass"
- @uri.password.should == "newpass"
- @uri.user.should == ""
- @uri.to_s.should == "http://:newpass@example.com"
- end
- it "should have the correct password after assignment" do
- @uri.password = "#secret@123!"
- @uri.password.should == "#secret@123!"
- @uri.normalized_password.should == "%23secret%40123%21"
- @uri.user.should == ""
- @uri.normalize.to_s.should == "http://:%23secret%40123%21@example.com/"
- @uri.omit(:password).to_s.should == "http://example.com"
- end
- it "should have the correct user/pass after repeated assignment" do
- @uri.user = nil
- @uri.user.should == nil
- @uri.password = "newpass"
- @uri.password.should == "newpass"
- # Username cannot be nil if the password is set
- @uri.user.should == ""
- @uri.to_s.should == "http://:newpass@example.com"
- @uri.user = "newuser"
- @uri.user.should == "newuser"
- @uri.password = nil
- @uri.password.should == nil
- @uri.to_s.should == "http://newuser@example.com"
- @uri.user = "newuser"
- @uri.user.should == "newuser"
- @uri.password = ""
- @uri.password.should == ""
- @uri.to_s.should == "http://newuser:@example.com"
- @uri.password = "newpass"
- @uri.password.should == "newpass"
- @uri.user = nil
- # Username cannot be nil if the password is set
- @uri.user.should == ""
- @uri.to_s.should == "http://:newpass@example.com"
- end
- it "should have the correct user/pass after userinfo assignment" do
- @uri.user = "newuser"
- @uri.user.should == "newuser"
- @uri.password = "newpass"
- @uri.password.should == "newpass"
- @uri.userinfo = nil
- @uri.userinfo.should == nil
- @uri.user.should == nil
- @uri.password.should == nil
- end
- it "should correctly convert to a hash" do
- @uri.to_hash.should == {
- :scheme => "http",
- :user => nil,
- :password => nil,
- :host => "example.com",
- :port => nil,
- :path => "",
- :query => nil,
- :fragment => nil
- }
- end
- it "should be identical to its duplicate" do
- @uri.should == @uri.dup
- end
- it "should have an origin of 'http://example.com'" do
- @uri.origin.should == 'http://example.com'
- end
- end
- # Section 5.1.2 of RFC 2616
- describe Addressable::URI, "when parsed from " +
- "'http://www.w3.org/pub/WWW/TheProject.html'" do
- before do
- @uri = Addressable::URI.parse("http://www.w3.org/pub/WWW/TheProject.html")
- end
- it "should have the correct request URI" do
- @uri.request_uri.should == "/pub/WWW/TheProject.html"
- end
- it "should have the correct request URI after assignment" do
- @uri.request_uri = "/some/where/else.html?query?string"
- @uri.request_uri.should == "/some/where/else.html?query?string"
- @uri.path.should == "/some/where/else.html"
- @uri.query.should == "query?string"
- end
- it "should have the correct request URI after assignment" do
- @uri.request_uri = "?x=y"
- @uri.request_uri.should == "/?x=y"
- @uri.path.should == "/"
- @uri.query.should == "x=y"
- end
- it "should raise an error if the site value is set to something bogus" do
- (lambda do
- @uri.site = 42
- end).should raise_error(TypeError)
- end
- it "should raise an error if the request URI is set to something bogus" do
- (lambda do
- @uri.request_uri = 42
- end).should raise_error(TypeError)
- end
- it "should correctly convert to a hash" do
- @uri.to_hash.should == {
- :scheme => "http",
- :user => nil,
- :password => nil,
- :host => "www.w3.org",
- :port => nil,
- :path => "/pub/WWW/TheProject.html",
- :query => nil,
- :fragment => nil
- }
- end
- it "should have an origin of 'http://www.w3.org'" do
- @uri.origin.should == 'http://www.w3.org'
- end
- end
- describe Addressable::URI, "when parsing IPv6 addresses" do
- it "should not raise an error for " +
- "'http://[3ffe:1900:4545:3:200:f8ff:fe21:67cf]/'" do
- Addressable::URI.parse("http://[3ffe:1900:4545:3:200:f8ff:fe21:67cf]/")
- end
- it "should not raise an error for " +
- "'http://[fe80:0:0:0:200:f8ff:fe21:67cf]/'" do
- Addressable::URI.parse("http://[fe80:0:0:0:200:f8ff:fe21:67cf]/")
- end
- it "should not raise an error for " +
- "'http://[fe80::200:f8ff:fe21:67cf]/'" do
- Addressable::URI.parse("http://[fe80::200:f8ff:fe21:67cf]/")
- end
- it "should not raise an error for " +
- "'http://[::1]/'" do
- Addressable::URI.parse("http://[::1]/")
- end
- it "should not raise an error for " +
- "'http://[fe80::1]/'" do
- Addressable::URI.parse("http://[fe80::1]/")
- end
- it "should raise an error for " +
- "'http://[<invalid>]/'" do
- (lambda do
- Addressable::URI.parse("http://[<invalid>]/")
- end).should raise_error(Addressable::URI::InvalidURIError)
- end
- end
- describe Addressable::URI, "when parsing IPv6 address" do
- subject { Addressable::URI.parse("http://[3ffe:1900:4545:3:200:f8ff:fe21:67cf]/") }
- its(:host) { should == '[3ffe:1900:4545:3:200:f8ff:fe21:67cf]' }
- its(:hostname) { should == '3ffe:1900:4545:3:200:f8ff:fe21:67cf' }
- end
- describe Addressable::URI, "when assigning IPv6 address" do
- it "should allow to set bare IPv6 address as hostname" do
- uri = Addressable::URI.parse("http://[::1]/")
- uri.hostname = '3ffe:1900:4545:3:200:f8ff:fe21:67cf'
- uri.to_s.should == 'http://[3ffe:1900:4545:3:200:f8ff:fe21:67cf]/'
- end
- it "should not allow to set bare IPv6 address as host" do
- uri = Addressable::URI.parse("http://[::1]/")
- pending "not checked"
- (lambda do
- uri.host = '3ffe:1900:4545:3:200:f8ff:fe21:67cf'
- end).should raise_error(Addressable::URI::InvalidURIError)
- end
- end
- describe Addressable::URI, "when parsing IPvFuture addresses" do
- it "should not raise an error for " +
- "'http://[v9.3ffe:1900:4545:3:200:f8ff:fe21:67cf]/'" do
- Addressable::URI.parse("http://[v9.3ffe:1900:4545:3:200:f8ff:fe21:67cf]/")
- end
- it "should not raise an error for " +
- "'http://[vff.fe80:0:0:0:200:f8ff:fe21:67cf]/'" do
- Addressable::URI.parse("http://[vff.fe80:0:0:0:200:f8ff:fe21:67cf]/")
- end
- it "should not raise an error for " +
- "'http://[v12.fe80::200:f8ff:fe21:67cf]/'" do
- Addressable::URI.parse("http://[v12.fe80::200:f8ff:fe21:67cf]/")
- end
- it "should not raise an error for " +
- "'http://[va0.::1]/'" do
- Addressable::URI.parse("http://[va0.::1]/")
- end
- it "should not raise an error for " +
- "'http://[v255.fe80::1]/'" do
- Addressable::URI.parse("http://[v255.fe80::1]/")
- end
- it "should raise an error for " +
- "'http://[v0.<invalid>]/'" do
- (lambda do
- Addressable::URI.parse("http://[v0.<invalid>]/")
- end).should raise_error(Addressable::URI::InvalidURIError)
- end
- end
- describe Addressable::URI, "when parsed from " +
- "'http://example.com/'" do
- before do
- @uri = Addressable::URI.parse("http://example.com/")
- end
- # Based on http://intertwingly.net/blog/2004/07/31/URI-Equivalence
- it "should be equivalent to http://example.com" do
- @uri.should == Addressable::URI.parse("http://example.com")
- end
- # Based on http://intertwingly.net/blog/2004/07/31/URI-Equivalence
- it "should be equivalent to HTTP://example.com/" do
- @uri.should == Addressable::URI.parse("HTTP://example.com/")
- end
- # Based on http://intertwingly.net/blog/2004/07/31/URI-Equivalence
- it "should be equivalent to http://example.com:/" do
- @uri.should == Addressable::URI.parse("http://example.com:/")
- end
- # Based on http://intertwingly.net/blog/2004/07/31/URI-Equivalence
- it "should be equivalent to http://example.com:80/" do
- @uri.should == Addressable::URI.parse("http://example.com:80/")
- end
- # Based on http://intertwingly.net/blog/2004/07/31/URI-Equivalence
- it "should be equivalent to http://Example.com/" do
- @uri.should == Addressable::URI.parse("http://Example.com/")
- end
- it "should have the correct username after assignment" do
- @uri.user = nil
- @uri.user.should == nil
- @uri.password.should == nil
- @uri.to…
Large files files are truncated, but you can click here to view the full file