2015-02-06 01:03:32 +00:00
|
|
|
require 'bundler'
|
|
|
|
require 'appraisal'
|
|
|
|
|
|
|
|
module Tests
|
|
|
|
class CurrentBundle
|
|
|
|
AppraisalNotSpecified = Class.new(ArgumentError)
|
|
|
|
|
|
|
|
include Singleton
|
|
|
|
|
|
|
|
def assert_appraisal!
|
2015-10-29 00:39:46 +00:00
|
|
|
unless appraisal_in_use?
|
2015-02-06 01:03:32 +00:00
|
|
|
message = <<EOT
|
|
|
|
|
|
|
|
|
|
|
|
Please run tests starting with `appraisal <appraisal_name>`.
|
2015-10-29 00:39:46 +00:00
|
|
|
Possible appraisals are: #{available_appraisals}
|
2015-02-06 01:03:32 +00:00
|
|
|
|
|
|
|
EOT
|
|
|
|
raise AppraisalNotSpecified, message
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2015-10-29 00:39:46 +00:00
|
|
|
def appraisal_in_use?
|
|
|
|
path.dirname == root.join('gemfiles')
|
|
|
|
end
|
|
|
|
|
2015-11-30 01:57:45 +00:00
|
|
|
def current_or_latest_appraisal
|
|
|
|
current_appraisal || latest_appraisal
|
|
|
|
end
|
|
|
|
|
2015-10-29 00:39:46 +00:00
|
|
|
def latest_appraisal
|
2020-09-06 13:09:31 +00:00
|
|
|
available_appraisals.max
|
2015-10-29 00:39:46 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
def available_appraisals
|
2018-01-24 06:01:41 +00:00
|
|
|
Appraisal::AppraisalFile.each.map(&:name)
|
2015-02-06 01:03:32 +00:00
|
|
|
end
|
|
|
|
|
2018-01-24 06:01:41 +00:00
|
|
|
private
|
|
|
|
|
2015-10-29 00:39:46 +00:00
|
|
|
def current_appraisal
|
|
|
|
if appraisal_in_use?
|
2020-09-04 14:38:31 +00:00
|
|
|
File.basename(path, '.gemfile')
|
2015-10-29 00:39:46 +00:00
|
|
|
end
|
2015-02-06 01:03:32 +00:00
|
|
|
end
|
|
|
|
|
2015-10-29 00:39:46 +00:00
|
|
|
def path
|
|
|
|
Bundler.default_gemfile
|
2015-02-06 01:03:32 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
def root
|
|
|
|
Pathname.new('../../../..').expand_path(__FILE__)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|