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

Create test for agent_helper in gem files #2118

Merged
merged 7 commits into from
Jul 11, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion newrelic_rpm.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ Gem::Specification.new do |s|
'homepage_uri' => 'https://newrelic.com/ruby'
}

reject_list = File.read('./.build_ignore').split("\n")
reject_list = File.read(File.expand_path('../.build_ignore', __FILE__)).split("\n")
file_list = `git ls-files -z`.split("\x0").reject { |f| reject_list.any? { |rf| f.start_with?(rf) } }
# test/agent_helper.rb is a requirement for the NewRelic::Agent.require_test_helper public API
test_helper_path = 'test/agent_helper.rb'
Expand Down
22 changes: 22 additions & 0 deletions test/new_relic/gemspec_files_test.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
# This file is distributed under New Relic's license terms.
# See https://github.com/newrelic/newrelic-ruby-agent/blob/main/LICENSE for complete details.
# frozen_string_literal: true

require 'minitest/autorun'
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@ajesler - I swapped out the test_helper require statement with minitest/autorun because we don't want/need the agent to be loaded for this particular test.

This is what we do with our other utilities, like our CveNotifierTests


class GemspecFilesTest < Minitest::Test
def test_the_test_agent_helper_is_shipped_in_the_gem_files
skip if defined?(Rails::VERSION)
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__)

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

assert gem_spec, "Failed to parse '#{gem_spec_file_path}'"
assert_equal('newrelic_rpm', gem_spec.name)
assert_includes(gem_spec.files, 'test/agent_helper.rb')
end
end
end