2015-02-05 20:03:32 -05:00
|
|
|
require 'bundler'
|
|
|
|
require 'appraisal'
|
|
|
|
|
|
|
|
module Tests
|
|
|
|
class CurrentBundle
|
|
|
|
AppraisalNotSpecified = Class.new(ArgumentError)
|
|
|
|
|
|
|
|
include Singleton
|
|
|
|
|
|
|
|
def assert_appraisal!
|
2015-10-28 20:39:46 -04:00
|
|
|
unless appraisal_in_use?
|
2015-02-05 20:03:32 -05:00
|
|
|
message = <<EOT
|
|
|
|
|
|
|
|
|
|
|
|
Please run tests starting with `appraisal <appraisal_name>`.
|
2015-10-28 20:39:46 -04:00
|
|
|
Possible appraisals are: #{available_appraisals}
|
2015-02-05 20:03:32 -05:00
|
|
|
|
|
|
|
EOT
|
|
|
|
raise AppraisalNotSpecified, message
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2015-10-28 20:39:46 -04:00
|
|
|
def appraisal_in_use?
|
|
|
|
path.dirname == root.join('gemfiles')
|
|
|
|
end
|
|
|
|
|
|
|
|
def latest_appraisal
|
|
|
|
available_appraisals.sort.last
|
|
|
|
end
|
|
|
|
|
2015-02-05 20:03:32 -05:00
|
|
|
private
|
|
|
|
|
2015-10-28 20:39:46 -04:00
|
|
|
def available_appraisals
|
2015-02-05 20:03:32 -05:00
|
|
|
appraisals = []
|
|
|
|
|
|
|
|
Appraisal::File.each do |appraisal|
|
|
|
|
appraisals << appraisal.name
|
|
|
|
end
|
|
|
|
|
|
|
|
appraisals
|
|
|
|
end
|
|
|
|
|
2015-10-28 20:39:46 -04:00
|
|
|
def current_appraisal
|
|
|
|
if appraisal_in_use?
|
|
|
|
File.basename(path, ".gemfile")
|
|
|
|
end
|
2015-02-05 20:03:32 -05:00
|
|
|
end
|
|
|
|
|
2015-10-28 20:39:46 -04:00
|
|
|
def path
|
|
|
|
Bundler.default_gemfile
|
2015-02-05 20:03:32 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
def root
|
|
|
|
Pathname.new('../../../..').expand_path(__FILE__)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|