tags: Bundler

Implement and Test in One File with bundler/inline and rspec/autorun

Sometimes I want to create a tiny one-off script that intended to run on a sandbox environment like a Docker container and needs only one file. Most of the time, I also need test frameworks to do some refactoring. It can be done with bundler/inline and rspec/autorun. require 'bundler/inline' gemfile do source 'https://rubygems.org' gem 'rspec' end def doit 'return a string' end require 'rspec/autorun' RSpec.describe '#doit' do example do expect(doit).to be_a(String) end end Usually, Bundler reads the dependencies from Gemfile. However, we can forgo this file by using gemfile block instead. As running the script, Bundler will install gems that are required by the block but not installed in the system. So the initial run may take a little longer time for installation. Note that you cannot place require 'rspec/autorun' before the gemfile block since some of the dependencies might not be installed yet before that.

Read more →

Gentaro "hibariya" Terada

Otakanomori, Nagareyama, Chiba, Japan
Email me

Likes Ruby, Internet, and Programming.