Skip to content

Commit

Permalink
support relative BUNDLE_GEMFILE path in tests (#245)
Browse files Browse the repository at this point in the history
* support relative BUNDLE_GEMFILE
* reduce test verbosity
* remove duplicate require
  • Loading branch information
pcai authored Sep 30, 2024
1 parent fca88a3 commit 17307b4
Show file tree
Hide file tree
Showing 5 changed files with 10 additions and 9 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ jobs:
- ruby: "head"
gemfile: gemfiles/rails_head.gemfile
env:
BUNDLE_GEMFILE: ${{ github.workspace }}/${{ matrix.gemfile }}
BUNDLE_GEMFILE: ${{ matrix.gemfile }}
steps:
- name: Checkout code
uses: actions/checkout@v4
Expand Down
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
- Test Rails 7.1 and 7.2 (https://github.com/zombocom/derailed_benchmarks/pull/242)
- Switch from dead_end to syntax_suggest (https://github.com/zombocom/derailed_benchmarks/pull/243)
- require `ruby2_keywords` so drb doesn't break in ruby < 2.7 (https://github.com/zombocom/derailed_benchmarks/pull/244)
- support relative BUNDLE_GEMFILE in tests (https://github.com/zombocom/derailed_benchmarks/pull/245)

## 2.1.2

Expand Down
2 changes: 1 addition & 1 deletion gemfiles/rails_head.gemfile
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# frozen_string_literal: true

# $ BUNDLE_GEMFILE="$(pwd)/gemfiles/rails_git.gemfile" bundle exec m test/integration/tasks_test.rb:50
# $ BUNDLE_GEMFILE="gemfiles/rails_git.gemfile" bundle exec m test/integration/tasks_test.rb:50

source "https://rubygems.org"

Expand Down
12 changes: 7 additions & 5 deletions test/integration/tasks_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ def teardown
end

def run!(cmd)
puts "Running: #{cmd}"
out = `#{cmd}`
raise "Could not run #{cmd}, output: #{out}" unless $?.success?
out
Expand All @@ -25,8 +24,11 @@ def rake(cmd, options = {})
env = options[:env] || {}
env_string = env.map {|key, value| "#{key.shellescape}=#{value.to_s.shellescape}" }.join(" ")
cmd = "env #{env_string} bundle exec rake -f perf.rake #{cmd} --trace"
puts "Running: #{cmd}"
result = Bundler.with_original_env { `cd '#{rails_app_path}' && #{cmd} 2>&1` }
result = Bundler.with_original_env do
# Ensure relative BUNDLE_GEMFILE is expanded so path is still correct after cd
ENV['BUNDLE_GEMFILE'] = File.expand_path(ENV['BUNDLE_GEMFILE']) if ENV['BUNDLE_GEMFILE']
`cd '#{rails_app_path}' && #{cmd} 2>&1`
end
if assert_success && !$?.success?
puts result
raise "Expected '#{cmd}' to return a success status.\nOutput: #{result}"
Expand All @@ -44,7 +46,7 @@ def rake(cmd, options = {})
end

test 'rails perf:library from git' do
# BUNDLE_GEMFILE="$(pwd)/gemfiles/rails_git.gemfile" bundle exec m test/integration/tasks_test.rb:<linenumber>
# BUNDLE_GEMFILE="gemfiles/rails_git.gemfile" bundle exec m test/integration/tasks_test.rb:<linenumber>

skip # unless ENV['USING_RAILS_GIT']

Expand All @@ -54,7 +56,7 @@ def rake(cmd, options = {})
end

test "rails perf:library with bad script" do
# BUNDLE_GEMFILE="$(pwd)/gemfiles/rails_git.gemfile" bundle exec m test/integration/tasks_test.rb:<linenumber>
# BUNDLE_GEMFILE="gemfiles/rails_git.gemfile" bundle exec m test/integration/tasks_test.rb:<linenumber>

skip # unless ENV['USING_RAILS_GIT']

Expand Down
2 changes: 0 additions & 2 deletions test/test_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
# Configure Rails Envinronment
ENV["RAILS_ENV"] = "test"


require "ruby2_keywords" if RUBY_VERSION < "2.7"

require 'rails'
Expand All @@ -18,7 +17,6 @@
require 'derailed_benchmarks'

require File.expand_path("../rails_app/config/environment.rb", __FILE__)
require "rails/test_help"

ActionMailer::Base.delivery_method = :test
ActionMailer::Base.perform_deliveries = true
Expand Down

0 comments on commit 17307b4

Please sign in to comment.