From 5b65b93f2f353627d9fed2fe4c2f361354b779e9 Mon Sep 17 00:00:00 2001 From: Alex Bullen Date: Tue, 23 Apr 2019 17:23:21 -0700 Subject: [PATCH] Bring in ice_nine as a test dependency and implement tests using it to ensure there are no unnecessary mutations in uri_spec.rb --- Gemfile | 1 + spec/addressable/uri_spec.rb | 63 ++++++++++++++++++++++++++++++++++++ 2 files changed, 64 insertions(+) diff --git a/Gemfile b/Gemfile index 9ca55cab..afcdf435 100644 --- a/Gemfile +++ b/Gemfile @@ -5,6 +5,7 @@ gemspec group :test do gem 'rspec', '~> 3.5' gem 'rspec-its', '~> 1.1' + gem 'ice_nine', '~> 0.11' end group :development do diff --git a/spec/addressable/uri_spec.rb b/spec/addressable/uri_spec.rb index 7cecd0c9..4c12485c 100644 --- a/spec/addressable/uri_spec.rb +++ b/spec/addressable/uri_spec.rb @@ -21,6 +21,8 @@ require "addressable/uri" require "uri" require "ipaddr" +require "ice_nine" +require "ice_nine/core_ext/object" if !"".respond_to?("force_encoding") class String @@ -999,6 +1001,67 @@ def to_s end end +describe Addressable::URI, "when normalized and then deeply frozen" do + before do + @uri = Addressable::URI.parse( + "http://user:password@example.com:8080/path?query=value#fragment" + ).normalize!.deep_freeze! + end + + it "#normalized_scheme should not error" do + expect{ @uri.normalized_scheme }.not_to raise_error + end + + it "#normalized_user should not error" do + expect{ @uri.normalized_user }.not_to raise_error + end + + it "#normalized_password should not error" do + expect{ @uri.normalized_password }.not_to raise_error + end + + it "#normalized_userinfo should not error" do + p @uri.normalized_userinfo + expect{ @uri.normalized_userinfo }.not_to raise_error + end + + it "#normalized_host should not error" do + expect{@uri.normalized_host}.not_to raise_error + end + + it "#normalized_authority should not error" do + expect{ @uri.normalized_authority }.not_to raise_error + end + + it "#normalized_port should not error" do + expect{ @uri.normalized_port }.not_to raise_error + end + + it "#normalized_site should not error" do + expect{ @uri.normalized_site }.not_to raise_error + end + + it "#normalized_path should not error" do + expect{ @uri.normalized_path }.not_to raise_error + end + + it "#normalized_query should not error" do + expect{ @uri.normalized_query }.not_to raise_error + end + + it "#normalized_fragment should not error" do + expect{ @uri.normalized_fragment }.not_to raise_error + end + + it "should be frozen" do + expect(@uri).to be_frozen + end + + it "should not allow destructive operations" do + expect { @uri.normalize! }.to raise_error(FrozenError) + end +end + describe Addressable::URI, "when created from string components" do before do @uri = Addressable::URI.new(