|
| 1 | +require "PATH" |
| 2 | + |
| 3 | +describe PATH do |
| 4 | + describe "#initialize" do |
| 5 | + it "can take multiple arguments" do |
| 6 | + expect(described_class.new("/path1", "/path2")).to eq("/path1:/path2") |
| 7 | + end |
| 8 | + |
| 9 | + it "can parse a mix of arrays and arguments" do |
| 10 | + expect(described_class.new(["/path1", "/path2"], "/path3")).to eq("/path1:/path2:/path3") |
| 11 | + end |
| 12 | + |
| 13 | + it "splits an existing PATH" do |
| 14 | + expect(described_class.new("/path1:/path2")).to eq(["/path1", "/path2"]) |
| 15 | + end |
| 16 | + end |
| 17 | + |
| 18 | + describe "#to_ary" do |
| 19 | + it "returns a PATH array" do |
| 20 | + expect(described_class.new("/path1", "/path2").to_ary).to eq(["/path1", "/path2"]) |
| 21 | + end |
| 22 | + end |
| 23 | + |
| 24 | + describe "#to_str" do |
| 25 | + it "returns a PATH string" do |
| 26 | + expect(described_class.new("/path1", "/path2").to_str).to eq("/path1:/path2") |
| 27 | + end |
| 28 | + end |
| 29 | + |
| 30 | + describe "#prepend" do |
| 31 | + it "prepends a path to a PATH" do |
| 32 | + expect(described_class.new("/path1").prepend("/path2").to_str).to eq("/path2:/path1") |
| 33 | + end |
| 34 | + end |
| 35 | + |
| 36 | + describe "#append" do |
| 37 | + it "prepends a path to a PATH" do |
| 38 | + expect(described_class.new("/path1").append("/path2").to_str).to eq("/path1:/path2") |
| 39 | + end |
| 40 | + end |
| 41 | + |
| 42 | + describe "#validate" do |
| 43 | + it "returns a new PATH without non-existent paths" do |
| 44 | + allow(File).to receive(:directory?).with("/path1").and_return(true) |
| 45 | + allow(File).to receive(:directory?).with("/path2").and_return(false) |
| 46 | + |
| 47 | + path = described_class.new("/path1", "/path2") |
| 48 | + expect(path.validate.to_ary).to eq(["/path1"]) |
| 49 | + expect(path.to_ary).to eq(["/path1", "/path2"]) |
| 50 | + end |
| 51 | + end |
| 52 | +end |
0 commit comments