Created
May 15, 2019 17:16
-
-
Save krisleech/081a666e52e51a8db16189f33cf40d7a to your computer and use it in GitHub Desktop.
Rescue arguments
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require "bundler/inline" | |
gemfile(true) do | |
source "https://rubygems.org" | |
gem "rspec" | |
end | |
BoomError = Class.new(StandardError) | |
RSpec.describe 'rescue arguments' do | |
# passes | |
describe 'no arguments' do | |
it 'rescues StandardError' do | |
expect do | |
begin | |
raise BoomError | |
rescue | |
end | |
end.not_to raise_error | |
end | |
end | |
# fails, it rescues nothing | |
describe 'splat nil' do | |
it 'rescues StandardError' do | |
expect do | |
begin | |
raise BoomError | |
rescue *nil | |
end | |
end.not_to raise_error | |
end | |
end | |
# fails, as expected with TypeError | |
describe 'nil' do | |
it 'rescues StandardError' do | |
expect do | |
begin | |
raise BoomError | |
rescue nil | |
end | |
end.not_to raise_error | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment