Skip to content

Instantly share code, notes, and snippets.

@krisleech
Created May 15, 2019 17:16
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save krisleech/081a666e52e51a8db16189f33cf40d7a to your computer and use it in GitHub Desktop.
Save krisleech/081a666e52e51a8db16189f33cf40d7a to your computer and use it in GitHub Desktop.
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