Skip to content

Commit

Permalink
Ruby 3.3+ fix for .gemspec test
Browse files Browse the repository at this point in the history
Ruby 3.3.0-preview2 causes an '(eval ...' String to be yielded for a
__FILE__ call performed within an `eval`. This String won't work
properly in contexts that expect a String representing a valid
filesystem path.

We don't want to touch the .gemspec file for the sake of the test, and
we don't yet want to refactor out the `eval` call that the test uses, so
for now let's just make sure the test never has to deal with a __FILE__
call within the `eval`.
  • Loading branch information
fallwith committed Sep 19, 2023
1 parent 6bb218f commit a5da5f5
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion test/new_relic/gemspec_files_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,13 @@ def test_the_test_agent_helper_is_shipped_in_the_gem_files
skip 'Gemspec test requires a newer version of Rubygems' unless Gem.respond_to?(:open_file)

gem_spec_file_path = File.expand_path('../../../newrelic_rpm.gemspec', __FILE__)
gem_spec_content = Gem.open_file(gem_spec_file_path, 'r:UTF-8:-', &:read)
# With Ruby 3.3.0-preview2, eval() yields '(eval ...' as the String value
# when __FILE__ is used so swap out __FILE__ for the known agent root path
gem_spec_content.gsub!('__FILE__', "'#{gem_spec_file_path}'")

Dir.chdir(File.dirname(gem_spec_file_path)) do
gem_spec = eval(Gem.open_file(gem_spec_file_path, 'r:UTF-8:-', &:read))
gem_spec = eval(gem_spec_content)

assert gem_spec, "Failed to parse '#{gem_spec_file_path}'"
assert_equal('newrelic_rpm', gem_spec.name)
Expand Down

0 comments on commit a5da5f5

Please sign in to comment.