2018-03-04 10:09:32 -05:00
|
|
|
require_relative '../../spec_helper'
|
|
|
|
require_relative 'fixtures/classes'
|
2017-05-07 08:04:49 -04:00
|
|
|
|
2019-02-21 10:38:59 -05:00
|
|
|
describe "Kernel#fail" do
|
2017-05-07 08:04:49 -04:00
|
|
|
it "is a private method" do
|
|
|
|
Kernel.should have_private_instance_method(:fail)
|
|
|
|
end
|
|
|
|
|
|
|
|
it "raises a RuntimeError" do
|
2019-07-27 06:40:09 -04:00
|
|
|
-> { fail }.should raise_error(RuntimeError)
|
2017-05-07 08:04:49 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
it "accepts an Object with an exception method returning an Exception" do
|
2019-02-21 10:38:59 -05:00
|
|
|
obj = Object.new
|
|
|
|
def obj.exception(msg)
|
|
|
|
StandardError.new msg
|
2017-05-07 08:04:49 -04:00
|
|
|
end
|
2019-07-27 06:40:09 -04:00
|
|
|
-> { fail obj, "..." }.should raise_error(StandardError, "...")
|
2017-05-07 08:04:49 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
it "instantiates the specified exception class" do
|
2019-02-21 10:38:59 -05:00
|
|
|
error_class = Class.new(RuntimeError)
|
2019-07-27 06:40:09 -04:00
|
|
|
-> { fail error_class }.should raise_error(error_class)
|
2017-05-07 08:04:49 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
it "uses the specified message" do
|
2019-07-27 06:40:09 -04:00
|
|
|
-> {
|
2017-05-07 08:04:49 -04:00
|
|
|
begin
|
|
|
|
fail "the duck is not irish."
|
|
|
|
rescue => e
|
|
|
|
e.message.should == "the duck is not irish."
|
|
|
|
raise
|
|
|
|
else
|
|
|
|
raise Exception
|
|
|
|
end
|
|
|
|
}.should raise_error(RuntimeError)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2019-02-21 10:38:59 -05:00
|
|
|
describe "Kernel.fail" do
|
2017-05-07 08:04:49 -04:00
|
|
|
it "needs to be reviewed for spec completeness"
|
|
|
|
end
|