Skip to content

Commit 9990989

Browse files
committed
Add a way to use the latest appraisal each time
1 parent 6397394 commit 9990989

File tree

4 files changed

+75
-66
lines changed

4 files changed

+75
-66
lines changed

bin/rspec

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
#!/usr/bin/env ruby
2+
3+
require_relative "../support/current_bundle"
4+
5+
current_bundle = SuperDiff::CurrentBundle.instance
6+
7+
ENV["BUNDLE_GEMFILE"] ||= current_bundle.latest_appraisal.gemfile_path
8+
9+
exec("bundle", "exec", "rspec", *ARGV)

spec/spec_helper.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,9 @@
1010

1111
#---
1212

13-
require_relative "support/current_bundle"
13+
require_relative "../support/current_bundle"
1414

15-
SuperDiff::Test::CurrentBundle.instance.assert_appraisal!
15+
SuperDiff::CurrentBundle.instance.assert_appraisal!
1616

1717
#---
1818

spec/support/current_bundle.rb

Lines changed: 0 additions & 64 deletions
This file was deleted.

support/current_bundle.rb

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
require "bundler"
2+
require "appraisal"
3+
require "shellwords"
4+
5+
module SuperDiff
6+
class CurrentBundle
7+
include Singleton
8+
9+
ROOT_DIR = Pathname.new("../..").expand_path(__dir__)
10+
APPRAISAL_GEMFILES_PATH = ROOT_DIR.join("gemfiles")
11+
12+
def assert_appraisal!
13+
unless appraisal_in_use?
14+
raise AppraisalNotSpecified.new(<<~MESSAGE)
15+
Please run tests by specifying an appraisal, like:
16+
17+
bundle exec appraisal <appraisal_name> #{current_command}
18+
19+
Possible appraisals are:
20+
21+
#{available_appraisals.map { |appraisal| "- #{appraisal.name}\n" }.join}
22+
23+
Or to simply go with the latest appraisal, use:
24+
25+
bin/rspec #{current_command}
26+
MESSAGE
27+
end
28+
end
29+
30+
def current_appraisal
31+
if path
32+
available_appraisals.find do |appraisal|
33+
appraisal.gemfile_path == path.to_s
34+
end
35+
else
36+
nil
37+
end
38+
end
39+
40+
def latest_appraisal
41+
available_appraisals.max_by(&:name)
42+
end
43+
44+
private
45+
46+
def appraisal_in_use?
47+
!current_appraisal.nil?
48+
end
49+
50+
def path
51+
Bundler.default_gemfile
52+
end
53+
54+
def available_appraisals
55+
@_available_appraisals ||= Appraisal::AppraisalFile.new.appraisals
56+
end
57+
58+
def current_command
59+
Shellwords.join([File.basename($0)] + ARGV)
60+
end
61+
62+
class AppraisalNotSpecified < ArgumentError; end
63+
end
64+
end

0 commit comments

Comments
 (0)