Skip to content

Commit f45e328

Browse files
andrykonchineregon
authored andcommitted
Fix Rational() and add :exception keyword argument
1 parent 2591d96 commit f45e328

1 file changed

Lines changed: 36 additions & 0 deletions

File tree

core/kernel/Rational_spec.rb

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -141,20 +141,56 @@ def obj.to_r; []; end
141141
Rational(:sym, exception: false).should == nil
142142
Rational("abc", exception: false).should == nil
143143
end
144+
145+
it "swallows an exception raised in #to_r" do
146+
obj = Object.new
147+
def obj.to_r; raise; end
148+
Rational(obj, exception: false).should == nil
149+
end
150+
151+
it "swallows an exception raised in #to_int" do
152+
obj = Object.new
153+
def obj.to_int; raise; end
154+
Rational(obj, exception: false).should == nil
155+
end
144156
end
145157

146158
describe "and [non-Numeric, Numeric]" do
147159
it "swallows an error" do
148160
Rational(:sym, 1, exception: false).should == nil
149161
Rational("abc", 1, exception: false).should == nil
150162
end
163+
164+
it "swallows an exception raised in #to_r" do
165+
obj = Object.new
166+
def obj.to_r; raise; end
167+
Rational(obj, 1, exception: false).should == nil
168+
end
169+
170+
it "swallows an exception raised in #to_int" do
171+
obj = Object.new
172+
def obj.to_int; raise; end
173+
Rational(obj, 1, exception: false).should == nil
174+
end
151175
end
152176

153177
describe "and [anything, non-Numeric]" do
154178
it "swallows an error" do
155179
Rational(:sym, :sym, exception: false).should == nil
156180
Rational("abc", :sym, exception: false).should == nil
157181
end
182+
183+
it "swallows an exception raised in #to_r" do
184+
obj = Object.new
185+
def obj.to_r; raise; end
186+
Rational(obj, obj, exception: false).should == nil
187+
end
188+
189+
it "swallows an exception raised in #to_int" do
190+
obj = Object.new
191+
def obj.to_int; raise; end
192+
Rational(obj, obj, exception: false).should == nil
193+
end
158194
end
159195

160196
describe "and non-Numeric String arguments" do

0 commit comments

Comments
 (0)