diff --git a/Library/Homebrew/PATH.rb b/Library/Homebrew/PATH.rb index de7167eb4b..263f26484e 100644 --- a/Library/Homebrew/PATH.rb +++ b/Library/Homebrew/PATH.rb @@ -32,7 +32,7 @@ class PATH end def to_ary - @paths + @paths.dup.to_ary end alias to_a to_ary diff --git a/Library/Homebrew/test/PATH_spec.rb b/Library/Homebrew/test/PATH_spec.rb index 68233c23c7..b6f884d665 100644 --- a/Library/Homebrew/test/PATH_spec.rb +++ b/Library/Homebrew/test/PATH_spec.rb @@ -23,6 +23,13 @@ describe PATH do it "returns a PATH array" do expect(described_class.new("/path1", "/path2").to_ary).to eq(["/path1", "/path2"]) end + + it "does not allow mutating the original" do + path = described_class.new("/path1", "/path2") + path.to_ary << "/path3" + + expect(path).not_to include("/path3") + end end describe "#to_str" do @@ -61,6 +68,12 @@ describe PATH do end end + describe "#==" do + it "always returns false when comparing against something which does not respons to `#to_ary` or `#to_str`" do + expect(described_class.new).not_to eq Object.new + end + end + describe "#include?" do it "returns true if a path is included" do path = described_class.new("/path1", "/path2")