Skip to content

Instantly share code, notes, and snippets.

@eightbitraptor
Created January 28, 2020 17:10
Show Gist options
  • Save eightbitraptor/f30b6a2c10f174f0f1fbdd0e23617f5c to your computer and use it in GitHub Desktop.
Save eightbitraptor/f30b6a2c10f174f0f1fbdd0e23617f5c to your computer and use it in GitHub Desktop.
a repro script for a bug in the way ruby parser handles splats followed by commas
require 'minitest/autorun'
require 'ruby_parser'
FirstException = Class.new(StandardError)
SecondException = Class.new(StandardError)
ThirdException = Class.new(StandardError)
EXCEPTIONS = [SecondException]
def my_method(error)
raise error
rescue FirstException, *EXCEPTIONS, ThirdException => e
e.to_s
end
class TestArraySplatFollowedByComma < Minitest::Test
def test_that_first_exception_is_caught_correctly
assert_equal "FirstException", my_method(FirstException)
end
def test_that_splatted_exception_is_caught_correctly
assert_equal "SecondException", my_method(SecondException)
end
def test_that_last_exception_is_caught_correctly
assert_equal "ThirdException", my_method(ThirdException)
end
end
class TestRubyParserBehaviour < Minitest::Test
def test_that_the_code_is_parsed_correctly
RubyParser.for_current_ruby.parse(method(:my_method).source)
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment