@@ -172,6 +172,42 @@ describe "URI" do
172172 it { URI .new(path: " /foo" ).hostname.should be_nil }
173173 end
174174
175+ describe " #host" do
176+ it " works with IPv6 address literals" do
177+ uri = URI .new(" http" , " [::1]" , path: " foo" )
178+ uri.hostname.should eq(" ::1" )
179+ uri.host.should eq(" [::1]" )
180+ uri.to_s.should eq " http://[::1]/foo"
181+ uri.host = " [::1]"
182+ uri.to_s.should eq " http://[::1]/foo"
183+
184+ uri = URI .new(" http" , " ::1" , path: " foo" )
185+ uri.hostname.should eq(" ::1" )
186+ uri.host.should eq(" [::1]" )
187+ uri.to_s.should eq " http://[::1]/foo"
188+ uri.host = " ::1"
189+ uri.to_s.should eq " http://[::1]/foo"
190+ end
191+
192+ it " works with IPv4 addresses" do
193+ uri = URI .new(" http" , " 192.168.0.2" , path: " foo" )
194+ uri.hostname.should eq(" 192.168.0.2" )
195+ uri.host.should eq(" 192.168.0.2" )
196+ uri.to_s.should eq " http://192.168.0.2/foo"
197+ uri.host = " 192.168.0.2"
198+ uri.to_s.should eq " http://192.168.0.2/foo"
199+ end
200+
201+ it " works with domain names" do
202+ uri = URI .new(" http" , " test.domain" , path: " foo" )
203+ uri.hostname.should eq(" test.domain" )
204+ uri.host.should eq(" test.domain" )
205+ uri.to_s.should eq " http://test.domain/foo"
206+ uri.host = " test.domain"
207+ uri.to_s.should eq " http://test.domain/foo"
208+ end
209+ end
210+
175211 describe " #authority" do
176212 it { URI .new.authority.should be_nil }
177213 it { URI .new(scheme: " scheme" ).authority.should be_nil }
0 commit comments