Skip to content

Instantly share code, notes, and snippets.

Last active November 25, 2023 07:00
  • Star 6 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
Star You must be signed in to star a gist
Save chrisroos/0ddf618ac711abe0f465 to your computer and use it in GitHub Desktop.
Example of using bundler/inline

I came across 'bundler/inline' in Bundler pull request 3440, which I'd found from Rails pull request 20429. This now has a little snippet on the What's new page of the Bundler site.

This little example demonstrates how I might use it to create a single file using minitest.

I've just noticed that this script was working for me because I already had minitest installed as a system gem. If I uninstall the gem then the script fails because it can't find minitest. The source code documents an option to install gems if they don't exist (gemfile(true) do) but that doesn't seem to work for me. I see the following error:

Fetching gem metadata from
Fetching version metadata from
Resolving dependencies...
Using metaclass 0.0.4

ArgumentError: different prefix: "" and "/Users/chrisroos/tmp/wem/.bundle/bin"
Bundler::InstallError: An error occurred while installing metaclass (0.0.4), and Bundler cannot continue. Make sure that `gem install metaclass -v '0.0.4'` succeeds before bundling.

I've now realised that the install option doesn't work because my bundler config is set to install gems to ./.bundle. If I ignore my bundler config then the gem is installed as expected:

BUNDLE_IGNORE_CONFIG=true ruby example-test-using-bundler-inline.rb 
require 'bundler/inline'
gemfile do
source ''
gem 'minitest', require: false
require 'minitest/autorun'
class MyTest < Minitest::Test
def test_should_be_true
assert_equal true, true
Copy link

mufid commented Feb 15, 2017

Hey Thanks!

Btw it does not work for me somehow. Turns out i still have Gemfile and Gemfile.lock. After i delete those 2 files, the script is now owrking.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment