Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Rescue arguments
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
You can’t perform that action at this time.