|
37 | 37 | path.should_receive(:to_path).and_return("abc") |
38 | 38 | File.path(path).should == "abc" |
39 | 39 | end |
| 40 | + |
| 41 | + it "raises TypeError when #to_path result is not a string" do |
| 42 | + path = mock("path") |
| 43 | + path.should_receive(:to_path).and_return(nil) |
| 44 | + -> { File.path(path) }.should raise_error TypeError |
| 45 | + |
| 46 | + path = mock("path") |
| 47 | + path.should_receive(:to_path).and_return(42) |
| 48 | + -> { File.path(path) }.should raise_error TypeError |
| 49 | + end |
| 50 | + |
| 51 | + it "raises ArgumentError for string argument contains NUL character" do |
| 52 | + -> { File.path("\0") }.should raise_error ArgumentError |
| 53 | + -> { File.path("a\0") }.should raise_error ArgumentError |
| 54 | + -> { File.path("a\0c") }.should raise_error ArgumentError |
| 55 | + end |
| 56 | + |
| 57 | + it "raises ArgumentError when #to_path result contains NUL character" do |
| 58 | + path = mock("path") |
| 59 | + path.should_receive(:to_path).and_return("\0") |
| 60 | + -> { File.path(path) }.should raise_error ArgumentError |
| 61 | + |
| 62 | + path = mock("path") |
| 63 | + path.should_receive(:to_path).and_return("a\0") |
| 64 | + -> { File.path(path) }.should raise_error ArgumentError |
| 65 | + |
| 66 | + path = mock("path") |
| 67 | + path.should_receive(:to_path).and_return("a\0c") |
| 68 | + -> { File.path(path) }.should raise_error ArgumentError |
| 69 | + end |
| 70 | + |
| 71 | + it "raises Encoding::CompatibilityError for ASCII-incompatible string argument" do |
| 72 | + path = "abc".encode(Encoding::UTF_32BE) |
| 73 | + -> { File.path(path) }.should raise_error Encoding::CompatibilityError |
| 74 | + end |
| 75 | + |
| 76 | + it "raises Encoding::CompatibilityError when #to_path result is ASCII-incompatible" do |
| 77 | + path = mock("path") |
| 78 | + path.should_receive(:to_path).and_return("abc".encode(Encoding::UTF_32BE)) |
| 79 | + -> { File.path(path) }.should raise_error Encoding::CompatibilityError |
| 80 | + end |
40 | 81 | end |
0 commit comments