1 require_relative '../../spec_helper'
4 describe "URI#select" do
5 it "takes any number of component names as symbols, and returns an array of those components" do
6 URI("http://host:8080/path/").select.should == []
7 URI("http://host:8080/path/").select(:scheme,:host,:port,:path).should == [
8 "http","host",8080,"/path/"]
11 it "returns nil for any valid component that isn't set and doesn't have a default" do
12 uri = URI("http://host")
13 uri.select(:userinfo, :query, :fragment).should == [nil] * 3
14 uri.select(:port, :path).should == [80, '']
17 it "raises an ArgumentError if a component is requested that isn't valid under the given scheme" do
18 -> { URI("mailto:spam@mailinator.com").select(:path) }.should raise_error(ArgumentError)
19 -> { URI("http://blog.blag.web").select(:typecode) }.should raise_error(ArgumentError)
22 it "raises an ArgumentError if given strings rather than symbols" do
24 URI("http://host:8080/path/").select("scheme","host","port",'path')
25 }.should raise_error(ArgumentError)