From 9a903f523cbd3a494e5d300051b1584424e1e8bd Mon Sep 17 00:00:00 2001 From: Elliot Winkler Date: Thu, 5 Feb 2015 18:03:32 -0700 Subject: [PATCH] Raise an error if no Appraisal is specified If you attempt to run tests without specifying an Appraisal, then you will be going off of the main Gemfile. The Gemfile is not guaranteed to contain all of the dependencies necessary to run tests, so it is very likely that you'll get an obscure error somewhere. Instead of letting this happen, raise a specific error. --- spec/acceptance_spec_helper.rb | 6 ++++ spec/support/tests/current_bundle.rb | 47 ++++++++++++++++++++++++++++ spec/unit_spec_helper.rb | 6 ++++ 3 files changed, 59 insertions(+) create mode 100644 spec/support/tests/current_bundle.rb diff --git a/spec/acceptance_spec_helper.rb b/spec/acceptance_spec_helper.rb index f9150bfe..b0730b9b 100644 --- a/spec/acceptance_spec_helper.rb +++ b/spec/acceptance_spec_helper.rb @@ -1,3 +1,9 @@ +require_relative 'support/tests/current_bundle' + +Tests::CurrentBundle.instance.assert_appraisal! + +#--- + require 'rspec/core' Dir[ File.join(File.expand_path('../support/acceptance/**/*.rb', __FILE__)) ].sort.each do |file| diff --git a/spec/support/tests/current_bundle.rb b/spec/support/tests/current_bundle.rb new file mode 100644 index 00000000..d5039a44 --- /dev/null +++ b/spec/support/tests/current_bundle.rb @@ -0,0 +1,47 @@ +require 'bundler' +require 'appraisal' + +module Tests + class CurrentBundle + AppraisalNotSpecified = Class.new(ArgumentError) + + include Singleton + + def assert_appraisal! + unless appraisal? + message = <`. +Possible appraisals are: #{possible_appraisals} + +EOT + raise AppraisalNotSpecified, message + end + end + + private + + def possible_appraisals + appraisals = [] + + Appraisal::File.each do |appraisal| + appraisals << appraisal.name + end + + appraisals + end + + def path + Bundler.default_gemfile + end + + def appraisal? + path.dirname == root.join('gemfiles') + end + + def root + Pathname.new('../../../..').expand_path(__FILE__) + end + end +end diff --git a/spec/unit_spec_helper.rb b/spec/unit_spec_helper.rb index 5806eb3f..fd000746 100644 --- a/spec/unit_spec_helper.rb +++ b/spec/unit_spec_helper.rb @@ -1,3 +1,9 @@ +require_relative 'support/tests/current_bundle' + +Tests::CurrentBundle.instance.assert_appraisal! + +#--- + require File.expand_path('../support/unit/rails_application', __FILE__) def monkey_patch_minitest_to_do_nothing