Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Use raise_error with block
  • Loading branch information
jfirebaugh committed Feb 23, 2012
1 parent 094a8ee commit 71d369d
Showing 1 changed file with 17 additions and 41 deletions.
58 changes: 17 additions & 41 deletions spec/ruby/core/kernel/exit_spec.rb
Expand Up @@ -14,66 +14,42 @@
end

describe "Kernel.exit" do
before :each do
ScratchPad.clear
end

it "raises a SystemExit with status 0" do
begin
exit
ScratchPad.record :no_exit
rescue SystemExit => e
lambda { exit }.should raise_error(SystemExit) { |e|
e.status.should == 0
end
ScratchPad.recorded.should be_nil
}
end

it "raises a SystemExit with the specified status" do
[-2**16, -2**8, -8, -1, 0, 1 , 8, 2**8, 2**16].each { |value|
begin
exit(value)
ScratchPad.record :no_exit
rescue SystemExit => e
[-2**16, -2**8, -8, -1, 0, 1 , 8, 2**8, 2**16].each do |value|
lambda { exit(value) }.should raise_error(SystemExit) { |e|
e.status.should == value
end
ScratchPad.recorded.should be_nil
}
}
end
end

it "raises a SystemExit with the specified boolean status" do
{ true => 0, false => 1 }.each { |value, status|
begin
exit(value)
ScratchPad.record :no_exit
rescue SystemExit => e
{ true => 0, false => 1 }.each do |value, status|
lambda { exit(value) }.should raise_error(SystemExit) { |e|
e.status.should == status
end
ScratchPad.recorded.should be_nil
}
}
end
end

it "tries to convert the passed argument to an Integer using #to_int" do
obj = mock('5')
obj.should_receive(:to_int).and_return(5)
begin
exit(obj)
ScratchPad.record :no_exit
rescue SystemExit => e
e.status.should == 5
end
ScratchPad.recorded.should be_nil
lambda { exit(obj) }.should raise_error(SystemExit) { |e|
e.status.should == 5
}
end

it "converts the passed Float argument to an Integer" do
{ -2.2 => -2, -0.1 => 0, 5.5 => 5, 827.999 => 827 }.each { |value, status|
begin
exit(value)
ScratchPad.record :no_exit
rescue SystemExit => e
{ -2.2 => -2, -0.1 => 0, 5.5 => 5, 827.999 => 827 }.each do |value, status|
lambda { exit(value) }.should raise_error(SystemExit) { |e|
e.status.should == status
end
ScratchPad.recorded.should be_nil
}
}
end
end

it "raises TypeError if can't convert the argument to an Integer" do
Expand Down

0 comments on commit 71d369d

Please sign in to comment.