6ft Dan 6ft Dan - 3 months ago 7
Ruby Question

Test that bundle install creates extension

I maintain a Ruby gem that compiles a Rust extension. It works on the majority of Linux and Windows systems but doesn't build on Macs. The problem happens during the bundle/gem install process.

I need a way to add to the project's test suite a build and install gem success test. Preferably not installing it locally into the system but into a temporary directory. The tests should also verify the linked library file exists upon gem install.

If you need more context for the question here is my Github issue for resolving the cross-platform gem extension building: https://github.com/danielpclark/faster_path/issues/71


So I stumbled across https://rubybench.org/ and they have a benchmark for Bundler with a temporary directory:

require_relative 'support/benchmark_bundler.rb'
require 'bundler/cli'

noop_gem = Pathname(__FILE__).expand_path + '../gems/noop-gem'

Dir.mktmpdir do |dir|
  Dir.chdir(dir) do
    File.write('Gemfile', <<-GEMFILE)
      source 'https://rubygems.org'
      gem 'rails'
      gem 'noop-gem', path: '#{noop_gem}'
    system("bundle install --quiet")

    Benchmark.do_benchmark('bundle exec gem') do
      system("bundle exec noop-gem")

This basically does what I need, I just need to change the benchmark part for verifying extension building.