0
私は温度変換を行う方法を持っています。
このメソッドは、場合によってはTypeErrorを発生させることを目的としています。
rspecでどうすれば確認できますか?ruby-rspec、TypeErrorの引き上げを処理する方法は?
Failures:
1) It should raise TypeError for unknown conversion type 'blob_to_blob' should raise a TypeError when what_to_what param has the value 'blob_to_blob'
Failure/Error: raise TypeError
TypeError:
TypeError
# ./converter_spec.rb:7:in `converter'
# ./converter_spec.rb:25
Finished in 0.00134 seconds
3 examples, 1 failure
コード:
def converter(temperature,what_to_what)
if what_to_what == 'farenheit_to_centigrade'
(temperature-32)/2
elsif what_to_what == 'centigrade_to_farenheit'
(temperature*2)+ 32
else
raise TypeError
end
end
describe "It should be able to convert farenheit to centigrade" do
it "should convert 50 to 9" do
converter(50, 'farenheit_to_centigrade').should == 9
end
end
describe "It should be able to convert centigrade to farenheit" do
it "should convert 9 to 50" do
converter(9, 'centigrade_to_farenheit').should == 50
end
end
describe "It should raise TypeError for unknown conversion type 'blob_to_blob'" do
it "should raise a TypeError when what_to_what param has the value 'blob_to_blob'" do
converter(9, 'blob_to_blob').should raise TypeError
end
end