Skip to content

Latest commit

 

History

History
46 lines (35 loc) · 1.35 KB

test_arbitrary_beaker_versions.md

File metadata and controls

46 lines (35 loc) · 1.35 KB

Test arbitrary beaker versions without modifying test code

In order to adjust the beaker version used without commiting a change to a Gemfile, we at Puppet often use a method in our code that changes the dependency based on the existence of ENV variables in the shell that beaker is executing from. The code itself looks like this:

def location_for(place, fake_version = nil)
  if place =~ /^(git[:@][^#]*)#(.*)/
    [fake_version, { :git => $1, :branch => $2, :require => false }].compact
  elsif place =~ /^file:\/\/(.*)/
    ['>= 0', { :path => File.expand_path($1), :require => false }]
  else
    [place, { :require => false }]
  end
end

Once this method definition is in place in the Gemfile, we can call it in a gem command, like this:

gem 'beaker', *location_for(ENV['BEAKER_VERSION'] || '~> 2.0')

Example BEAKER_VERSIONs

git locations

[email protected]:puppetlabs/beaker.git#master
git://github.com/puppetlabs/beaker.git#master

file locations

file://../relative/path/to/beaker

By adjusting the shell environment that beaker is running in, we can modify what version of beaker is installed by bundler on your test coordinator without modifying any of the test code. This strategy can be used for any gem dependency, and is often used when testing beaker libraries at Puppet.