Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add test for gemspec files #2117

Closed
kaylareopelle opened this issue Jul 6, 2023 · 4 comments · Fixed by #2118
Closed

Add test for gemspec files #2117

kaylareopelle opened this issue Jul 6, 2023 · 4 comments · Fixed by #2118
Assignees

Comments

@kaylareopelle
Copy link
Contributor

#2113 revealed our recent changes to the files included in the Ruby agent unintentionally broke the NewRelic::Agent.require_test_helper public API. We have some tests that try to protect this from happening, but they didn't catch the problem in this case.

The lines of code to test are around the s.files assignment:

reject_list = File.read('./.build_ignore').split("\n")
file_list = `git ls-files -z`.split("\x0").reject { |f| reject_list.any? { |rf| f.start_with?(rf) } }
build_file_path = 'lib/new_relic/build.rb'
file_list << build_file_path if File.exist?(build_file_path)
s.files = file_list

At a minimum, we need to test whether test/agent_helper.rb is included in the build.

@workato-integration
Copy link

@ajesler
Copy link
Contributor

ajesler commented Jul 7, 2023

I had a play this afternoon with spec'ing the test file inclusion, and this was where I got to.

Gem::Specification.load evals the gemspec file and builds the files list.

The raindow effect in the minitest output was an unexpected delight.

# frozen_string_literal: true
# test/new_relic/gem_file_test.rb
# $ TEST="test/new_relic/gem_file_test.rb" bundle exec rake test

require_relative '../test_helper'

class GemFileTest < Minitest::Test
  def test_the_test_agent_helper_is_shipped_in_the_gem_files
    agent_helper_file = 'test/agent_helper.rb'

    gem_spec_file_path = File.expand_path('../../../newrelic_rpm.gemspec', __FILE__)

    gem_spec = Gem::Specification.load(gem_spec_file_path)

    assert_equal('newrelic_rpm', gem_spec.name)
    assert_includes(gem_spec.files, agent_helper_file)
  end
end

@kaylareopelle
Copy link
Contributor Author

This is great, @ajesler! Thank you! Glad you enjoyed minitest/pride! 🌈

I went ahead and added this, with one small tweak, to #2118 as a co-authored commit. Are you comfortable with that approach?

@ajesler
Copy link
Contributor

ajesler commented Jul 9, 2023

Yep, that sounds great to me.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Archived in project
Development

Successfully merging a pull request may close this issue.

3 participants