Skip to content

Commit 7e39924

Browse files
committed
Match error messages for TypeError in File specs
There are two different code paths: true/false/nil uses the default inspect string in the error message, other objects use the class name. The conversion into Integer is even more inconsistent, where it's sometimes "from X to integer" and sometimes "of X into Integer".
1 parent 011609c commit 7e39924

15 files changed

Lines changed: 47 additions & 38 deletions

core/file/basename_spec.rb

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -105,10 +105,10 @@
105105
end
106106

107107
it "raises a TypeError if the arguments are not String types" do
108-
-> { File.basename(nil) }.should raise_error(TypeError)
109-
-> { File.basename(1) }.should raise_error(TypeError)
110-
-> { File.basename("bar.txt", 1) }.should raise_error(TypeError)
111-
-> { File.basename(true) }.should raise_error(TypeError)
108+
-> { File.basename(nil) }.should raise_error(TypeError, "no implicit conversion of nil into String")
109+
-> { File.basename(1) }.should raise_error(TypeError, "no implicit conversion of Integer into String")
110+
-> { File.basename("bar.txt", 1) }.should raise_error(TypeError, "no implicit conversion of Integer into String")
111+
-> { File.basename(true) }.should raise_error(TypeError, "no implicit conversion of true into String")
112112
end
113113

114114
it "accepts an object that has a #to_path method" do

core/file/chmod_spec.rb

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,8 @@
106106
end
107107

108108
it "throws a TypeError if the given path is not coercible into a string" do
109-
-> { File.chmod(0, []) }.should raise_error(TypeError)
109+
-> { File.chmod(0, []) }.should raise_error(TypeError, "no implicit conversion of Array into String")
110+
-> { File.chmod(0, false) }.should raise_error(TypeError, "no implicit conversion of false into String")
110111
end
111112

112113
it "raises an error for a non existent path" do

core/file/dirname_spec.rb

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -134,10 +134,10 @@ def object.to_int; 2; end
134134
end
135135

136136
it "raises a TypeError if not passed a String type" do
137-
-> { File.dirname(nil) }.should raise_error(TypeError)
138-
-> { File.dirname(0) }.should raise_error(TypeError)
139-
-> { File.dirname(true) }.should raise_error(TypeError)
140-
-> { File.dirname(false) }.should raise_error(TypeError)
137+
-> { File.dirname(nil) }.should raise_error(TypeError, "no implicit conversion of nil into String")
138+
-> { File.dirname(0) }.should raise_error(TypeError, "no implicit conversion of Integer into String")
139+
-> { File.dirname(true) }.should raise_error(TypeError, "no implicit conversion of true into String")
140+
-> { File.dirname(false) }.should raise_error(TypeError, "no implicit conversion of false into String")
141141
end
142142

143143
# Windows specific tests

core/file/expand_path_spec.rb

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -117,9 +117,9 @@
117117
end
118118

119119
it "raises a TypeError if not passed a String type" do
120-
-> { File.expand_path(1) }.should raise_error(TypeError)
121-
-> { File.expand_path(nil) }.should raise_error(TypeError)
122-
-> { File.expand_path(true) }.should raise_error(TypeError)
120+
-> { File.expand_path(1) }.should raise_error(TypeError, "no implicit conversion of Integer into String")
121+
-> { File.expand_path(nil) }.should raise_error(TypeError, "no implicit conversion of nil into String")
122+
-> { File.expand_path(true) }.should raise_error(TypeError, "no implicit conversion of true into String")
123123
end
124124

125125
platform_is_not :windows do

core/file/extname_spec.rb

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -57,10 +57,10 @@
5757
end
5858

5959
it "raises a TypeError if not passed a String type" do
60-
-> { File.extname(nil) }.should raise_error(TypeError)
61-
-> { File.extname(0) }.should raise_error(TypeError)
62-
-> { File.extname(true) }.should raise_error(TypeError)
63-
-> { File.extname(false) }.should raise_error(TypeError)
60+
-> { File.extname(nil) }.should raise_error(TypeError, "no implicit conversion of nil into String")
61+
-> { File.extname(0) }.should raise_error(TypeError, "no implicit conversion of Integer into String")
62+
-> { File.extname(true) }.should raise_error(TypeError, "no implicit conversion of true into String")
63+
-> { File.extname(false) }.should raise_error(TypeError, "no implicit conversion of false into String")
6464
end
6565

6666
it "raises an ArgumentError if not passed one argument" do

core/file/join_spec.rb

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -108,11 +108,11 @@
108108
end
109109

110110
it "raises a TypeError exception when args are nil" do
111-
-> { File.join nil }.should raise_error(TypeError)
111+
-> { File.join nil }.should raise_error(TypeError, "no implicit conversion of nil into String")
112112
end
113113

114114
it "calls #to_str" do
115-
-> { File.join(mock('x')) }.should raise_error(TypeError)
115+
-> { File.join(mock('x')) }.should raise_error(TypeError, "no implicit conversion of MockObject into String")
116116

117117
bin = mock("bin")
118118
bin.should_receive(:to_str).exactly(:twice).and_return("bin")
@@ -129,7 +129,7 @@
129129
end
130130

131131
it "calls #to_path" do
132-
-> { File.join(mock('x')) }.should raise_error(TypeError)
132+
-> { File.join(mock('x')) }.should raise_error(TypeError, "no implicit conversion of MockObject into String")
133133

134134
bin = mock("bin")
135135
bin.should_receive(:to_path).exactly(:twice).and_return("bin")

core/file/link_spec.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,8 @@
3232
end
3333

3434
it "raises a TypeError if not passed String types" do
35-
-> { File.link(@file, nil) }.should raise_error(TypeError)
36-
-> { File.link(@file, 1) }.should raise_error(TypeError)
35+
-> { File.link(@file, nil) }.should raise_error(TypeError, "no implicit conversion of nil into String")
36+
-> { File.link(@file, 1) }.should raise_error(TypeError, "no implicit conversion of Integer into String")
3737
end
3838
end
3939
end

core/file/mkfifo_spec.rb

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,8 @@
1919

2020
context "when path passed is not a String value" do
2121
it "raises a TypeError" do
22-
-> { File.mkfifo(:"/tmp/fifo") }.should raise_error(TypeError)
22+
-> { File.mkfifo(:"/tmp/fifo") }.should raise_error(TypeError, "no implicit conversion of Symbol into String")
23+
-> { File.mkfifo(false) }.should raise_error(TypeError, "no implicit conversion of false into String")
2324
end
2425
end
2526

core/file/new_spec.rb

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -195,12 +195,13 @@
195195
end
196196

197197
it "raises a TypeError if the first parameter can't be coerced to a string" do
198-
-> { File.new(true) }.should raise_error(TypeError)
199-
-> { File.new(false) }.should raise_error(TypeError)
198+
-> { File.new(true) }.should raise_error(TypeError, "no implicit conversion of true into String")
199+
-> { File.new(false) }.should raise_error(TypeError, "no implicit conversion of false into String")
200+
-> { File.new([]) }.should raise_error(TypeError, "no implicit conversion of Array into String")
200201
end
201202

202203
it "raises a TypeError if the first parameter is nil" do
203-
-> { File.new(nil) }.should raise_error(TypeError)
204+
-> { File.new(nil) }.should raise_error(TypeError, "no implicit conversion of nil into String")
204205
end
205206

206207
it "raises an Errno::EBADF if the first parameter is an invalid file descriptor" do

core/file/open_spec.rb

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -543,9 +543,10 @@
543543
end
544544

545545
it "raises a TypeError if passed a filename that is not a String or Integer type" do
546-
-> { File.open(true) }.should raise_error(TypeError)
547-
-> { File.open(false) }.should raise_error(TypeError)
548-
-> { File.open(nil) }.should raise_error(TypeError)
546+
-> { File.open(true) }.should raise_error(TypeError, "no implicit conversion of true into String")
547+
-> { File.open(false) }.should raise_error(TypeError, "no implicit conversion of false into String")
548+
-> { File.open(nil) }.should raise_error(TypeError, "no implicit conversion of nil into String")
549+
-> { File.open([]) }.should raise_error(TypeError, "no implicit conversion of Array into String")
549550
end
550551

551552
it "raises a SystemCallError if passed an invalid Integer type" do

0 commit comments

Comments
 (0)