Skip to content

Instantly share code, notes, and snippets.

@yaroslav
Created December 15, 2024 11:15
Show Gist options
  • Save yaroslav/cadc2475fca5a0daf22cf81368875801 to your computer and use it in GitHub Desktop.
Save yaroslav/cadc2475fca5a0daf22cf81368875801 to your computer and use it in GitHub Desktop.
Integration testing Ruby gems with bundler inside a Ruby gem test suite with bundler
# Simler options run well locally, but fail hard on GitHub actions with --deployment, etc.
require 'bundler'
RSpec.describe 'matroshka type shit', type: :integration do
let(:tmp_dir) { Dir.mktmpdir('rails_bundling_test') }
let(:gem_root) { File.expand_path('../../../../', __dir__) }
before(:each) do
Dir.chdir(tmp_dir) do
Bundler.with_unbundled_env do
File.write('Gemfile', <<~RUBY)
source 'https://rubygems.org'
gem 'rails'
# ...
RUBY
output, status = capture("bundle install && bundle exec ...")
end
end
end
after(:each) do
FileUtils.rm_rf(tmp_dir)
end
it 'tests' do
Dir.chdir(tmp_dir) do
Bundler.with_unbundled_env do
output, _status = capture("...")
# ...
end
end
end
def capture(cmd)
env = {
'BUNDLE_GEMFILE' => File.join(tmp_dir, 'Gemfile'),
'BUNDLE_PATH' => File.join(tmp_dir, 'vendor/bundle'),
'BUNDLE_APP_CONFIG' => File.join(tmp_dir, '.bundle'),
'BUNDLE_DISABLE_SHARED_GEMS' => 'true',
'PATH' => "#{File.join(tmp_dir, "bin")}:#{File.join(tmp_dir, "vendor/bundle/bin")}:#{ENV["PATH"]}"
}
Open3.capture2e(env, cmd)
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment