Skip to content

Commit 867fe8c

Browse files
committed
Refactor spec initialization
1 parent d6723a8 commit 867fe8c

20 files changed

+212
-220
lines changed

bin/bundle

+24-22
Original file line numberDiff line numberDiff line change
@@ -8,84 +8,84 @@
88
# this file is here to facilitate running it.
99
#
1010

11-
require 'rubygems'
11+
require "rubygems"
1212

1313
m = Module.new do
14-
module_function
14+
module_function
1515

1616
def invoked_as_script?
1717
File.expand_path($0) == File.expand_path(__FILE__)
1818
end
1919

2020
def env_var_version
21-
ENV['BUNDLER_VERSION']
21+
ENV["BUNDLER_VERSION"]
2222
end
2323

2424
def cli_arg_version
2525
return unless invoked_as_script? # don't want to hijack other binstubs
26-
return unless 'update'.start_with?(ARGV.first || ' ') # must be running `bundle update`
27-
26+
return unless "update".start_with?(ARGV.first || " ") # must be running `bundle update`
2827
bundler_version = nil
2928
update_index = nil
3029
ARGV.each_with_index do |a, i|
31-
bundler_version = a if update_index && update_index.succ == i && a =~ Gem::Version::ANCHORED_VERSION_PATTERN
30+
if update_index && update_index.succ == i && a =~ Gem::Version::ANCHORED_VERSION_PATTERN
31+
bundler_version = a
32+
end
3233
next unless a =~ /\A--bundler(?:[= ](#{Gem::Version::VERSION_PATTERN}))?\z/
33-
34-
bundler_version = Regexp.last_match(1) || '>= 0.a'
34+
bundler_version = $1 || ">= 0.a"
3535
update_index = i
3636
end
3737
bundler_version
3838
end
3939

4040
def gemfile
41-
gemfile = ENV['BUNDLE_GEMFILE']
41+
gemfile = ENV["BUNDLE_GEMFILE"]
4242
return gemfile if gemfile && !gemfile.empty?
4343

44-
File.expand_path('../Gemfile', __dir__)
44+
File.expand_path("../../Gemfile", __FILE__)
4545
end
4646

4747
def lockfile
4848
lockfile =
4949
case File.basename(gemfile)
50-
when 'gems.rb' then gemfile.sub(/\.rb$/, gemfile)
50+
when "gems.rb" then gemfile.sub(/\.rb$/, gemfile)
5151
else "#{gemfile}.lock"
5252
end
5353
File.expand_path(lockfile)
5454
end
5555

5656
def lockfile_version
5757
return unless File.file?(lockfile)
58-
5958
lockfile_contents = File.read(lockfile)
6059
return unless lockfile_contents =~ /\n\nBUNDLED WITH\n\s{2,}(#{Gem::Version::VERSION_PATTERN})\n/
61-
6260
Regexp.last_match(1)
6361
end
6462

6563
def bundler_version
66-
@bundler_version ||= env_var_version || cli_arg_version ||
67-
lockfile_version || "#{Gem::Requirement.default}.a"
64+
@bundler_version ||= begin
65+
env_var_version || cli_arg_version ||
66+
lockfile_version || "#{Gem::Requirement.default}.a"
67+
end
6868
end
6969

7070
def load_bundler!
71-
ENV['BUNDLE_GEMFILE'] ||= gemfile
71+
ENV["BUNDLE_GEMFILE"] ||= gemfile
7272

7373
# must dup string for RG < 1.8 compatibility
7474
activate_bundler(bundler_version.dup)
7575
end
7676

7777
def activate_bundler(bundler_version)
78-
bundler_version = '< 2' if Gem::Version.correct?(bundler_version) && Gem::Version.new(bundler_version).release < Gem::Version.new('2.0')
78+
if Gem::Version.correct?(bundler_version) && Gem::Version.new(bundler_version).release < Gem::Version.new("2.0")
79+
bundler_version = "< 2"
80+
end
7981
gem_error = activation_error_handling do
80-
gem 'bundler', bundler_version
82+
gem "bundler", bundler_version
8183
end
8284
return if gem_error.nil?
83-
8485
require_error = activation_error_handling do
85-
require 'bundler/version'
86+
require "bundler/version"
8687
end
8788
return if require_error.nil? && Gem::Requirement.new(bundler_version).satisfied_by?(Gem::Version.new(Bundler::VERSION))
88-
8989
warn "Activating bundler (#{bundler_version}) failed:\n#{gem_error.message}\n\nTo install the version of bundler this project requires, run `gem install bundler -v '#{bundler_version}'`"
9090
exit 42
9191
end
@@ -100,4 +100,6 @@ end
100100

101101
m.load_bundler!
102102

103-
load Gem.bin_path('bundler', 'bundle') if m.invoked_as_script?
103+
if m.invoked_as_script?
104+
load Gem.bin_path("bundler", "bundle")
105+
end

bin/byebug

+7-7
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,11 @@
88
# this file is here to facilitate running it.
99
#
1010

11-
require 'pathname'
12-
ENV['BUNDLE_GEMFILE'] ||= File.expand_path('../../Gemfile',
13-
Pathname.new(__FILE__).realpath)
11+
require "pathname"
12+
ENV["BUNDLE_GEMFILE"] ||= File.expand_path("../../Gemfile",
13+
Pathname.new(__FILE__).realpath)
1414

15-
bundle_binstub = File.expand_path('bundle', __dir__)
15+
bundle_binstub = File.expand_path("../bundle", __FILE__)
1616

1717
if File.file?(bundle_binstub)
1818
if File.read(bundle_binstub, 300) =~ /This file was generated by Bundler/
@@ -23,7 +23,7 @@ Replace `bin/bundle` by running `bundle binstubs bundler --force`, then run this
2323
end
2424
end
2525

26-
require 'rubygems'
27-
require 'bundler/setup'
26+
require "rubygems"
27+
require "bundler/setup"
2828

29-
load Gem.bin_path('byebug', 'byebug')
29+
load Gem.bin_path("byebug", "byebug")

bin/coderay

+7-7
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,11 @@
88
# this file is here to facilitate running it.
99
#
1010

11-
require 'pathname'
12-
ENV['BUNDLE_GEMFILE'] ||= File.expand_path('../../Gemfile',
13-
Pathname.new(__FILE__).realpath)
11+
require "pathname"
12+
ENV["BUNDLE_GEMFILE"] ||= File.expand_path("../../Gemfile",
13+
Pathname.new(__FILE__).realpath)
1414

15-
bundle_binstub = File.expand_path('bundle', __dir__)
15+
bundle_binstub = File.expand_path("../bundle", __FILE__)
1616

1717
if File.file?(bundle_binstub)
1818
if File.read(bundle_binstub, 300) =~ /This file was generated by Bundler/
@@ -23,7 +23,7 @@ Replace `bin/bundle` by running `bundle binstubs bundler --force`, then run this
2323
end
2424
end
2525

26-
require 'rubygems'
27-
require 'bundler/setup'
26+
require "rubygems"
27+
require "bundler/setup"
2828

29-
load Gem.bin_path('coderay', 'coderay')
29+
load Gem.bin_path("coderay", "coderay")

bin/fuzzy_match

+7-7
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,11 @@
88
# this file is here to facilitate running it.
99
#
1010

11-
require 'pathname'
12-
ENV['BUNDLE_GEMFILE'] ||= File.expand_path('../../Gemfile',
13-
Pathname.new(__FILE__).realpath)
11+
require "pathname"
12+
ENV["BUNDLE_GEMFILE"] ||= File.expand_path("../../Gemfile",
13+
Pathname.new(__FILE__).realpath)
1414

15-
bundle_binstub = File.expand_path('bundle', __dir__)
15+
bundle_binstub = File.expand_path("../bundle", __FILE__)
1616

1717
if File.file?(bundle_binstub)
1818
if File.read(bundle_binstub, 300) =~ /This file was generated by Bundler/
@@ -23,7 +23,7 @@ Replace `bin/bundle` by running `bundle binstubs bundler --force`, then run this
2323
end
2424
end
2525

26-
require 'rubygems'
27-
require 'bundler/setup'
26+
require "rubygems"
27+
require "bundler/setup"
2828

29-
load Gem.bin_path('fuzzy_match', 'fuzzy_match')
29+
load Gem.bin_path("fuzzy_match", "fuzzy_match")

bin/htmldiff

+7-7
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,11 @@
88
# this file is here to facilitate running it.
99
#
1010

11-
require 'pathname'
12-
ENV['BUNDLE_GEMFILE'] ||= File.expand_path('../../Gemfile',
13-
Pathname.new(__FILE__).realpath)
11+
require "pathname"
12+
ENV["BUNDLE_GEMFILE"] ||= File.expand_path("../../Gemfile",
13+
Pathname.new(__FILE__).realpath)
1414

15-
bundle_binstub = File.expand_path('bundle', __dir__)
15+
bundle_binstub = File.expand_path("../bundle", __FILE__)
1616

1717
if File.file?(bundle_binstub)
1818
if File.read(bundle_binstub, 300) =~ /This file was generated by Bundler/
@@ -23,7 +23,7 @@ Replace `bin/bundle` by running `bundle binstubs bundler --force`, then run this
2323
end
2424
end
2525

26-
require 'rubygems'
27-
require 'bundler/setup'
26+
require "rubygems"
27+
require "bundler/setup"
2828

29-
load Gem.bin_path('diff-lcs', 'htmldiff')
29+
load Gem.bin_path("diff-lcs", "htmldiff")

bin/httpclient

+7-7
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,11 @@
88
# this file is here to facilitate running it.
99
#
1010

11-
require 'pathname'
12-
ENV['BUNDLE_GEMFILE'] ||= File.expand_path('../../Gemfile',
13-
Pathname.new(__FILE__).realpath)
11+
require "pathname"
12+
ENV["BUNDLE_GEMFILE"] ||= File.expand_path("../../Gemfile",
13+
Pathname.new(__FILE__).realpath)
1414

15-
bundle_binstub = File.expand_path('bundle', __dir__)
15+
bundle_binstub = File.expand_path("../bundle", __FILE__)
1616

1717
if File.file?(bundle_binstub)
1818
if File.read(bundle_binstub, 300) =~ /This file was generated by Bundler/
@@ -23,7 +23,7 @@ Replace `bin/bundle` by running `bundle binstubs bundler --force`, then run this
2323
end
2424
end
2525

26-
require 'rubygems'
27-
require 'bundler/setup'
26+
require "rubygems"
27+
require "bundler/setup"
2828

29-
load Gem.bin_path('httpclient', 'httpclient')
29+
load Gem.bin_path("httpclient", "httpclient")

bin/ldiff

+7-7
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,11 @@
88
# this file is here to facilitate running it.
99
#
1010

11-
require 'pathname'
12-
ENV['BUNDLE_GEMFILE'] ||= File.expand_path('../../Gemfile',
13-
Pathname.new(__FILE__).realpath)
11+
require "pathname"
12+
ENV["BUNDLE_GEMFILE"] ||= File.expand_path("../../Gemfile",
13+
Pathname.new(__FILE__).realpath)
1414

15-
bundle_binstub = File.expand_path('bundle', __dir__)
15+
bundle_binstub = File.expand_path("../bundle", __FILE__)
1616

1717
if File.file?(bundle_binstub)
1818
if File.read(bundle_binstub, 300) =~ /This file was generated by Bundler/
@@ -23,7 +23,7 @@ Replace `bin/bundle` by running `bundle binstubs bundler --force`, then run this
2323
end
2424
end
2525

26-
require 'rubygems'
27-
require 'bundler/setup'
26+
require "rubygems"
27+
require "bundler/setup"
2828

29-
load Gem.bin_path('diff-lcs', 'ldiff')
29+
load Gem.bin_path("diff-lcs", "ldiff")

bin/pod

+7-7
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,11 @@
88
# this file is here to facilitate running it.
99
#
1010

11-
require 'pathname'
12-
ENV['BUNDLE_GEMFILE'] ||= File.expand_path('../../Gemfile',
13-
Pathname.new(__FILE__).realpath)
11+
require "pathname"
12+
ENV["BUNDLE_GEMFILE"] ||= File.expand_path("../../Gemfile",
13+
Pathname.new(__FILE__).realpath)
1414

15-
bundle_binstub = File.expand_path('bundle', __dir__)
15+
bundle_binstub = File.expand_path("../bundle", __FILE__)
1616

1717
if File.file?(bundle_binstub)
1818
if File.read(bundle_binstub, 300) =~ /This file was generated by Bundler/
@@ -23,7 +23,7 @@ Replace `bin/bundle` by running `bundle binstubs bundler --force`, then run this
2323
end
2424
end
2525

26-
require 'rubygems'
27-
require 'bundler/setup'
26+
require "rubygems"
27+
require "bundler/setup"
2828

29-
load Gem.bin_path('cocoapods', 'pod')
29+
load Gem.bin_path("cocoapods", "pod")

bin/pry

+7-7
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,11 @@
88
# this file is here to facilitate running it.
99
#
1010

11-
require 'pathname'
12-
ENV['BUNDLE_GEMFILE'] ||= File.expand_path('../../Gemfile',
13-
Pathname.new(__FILE__).realpath)
11+
require "pathname"
12+
ENV["BUNDLE_GEMFILE"] ||= File.expand_path("../../Gemfile",
13+
Pathname.new(__FILE__).realpath)
1414

15-
bundle_binstub = File.expand_path('bundle', __dir__)
15+
bundle_binstub = File.expand_path("../bundle", __FILE__)
1616

1717
if File.file?(bundle_binstub)
1818
if File.read(bundle_binstub, 300) =~ /This file was generated by Bundler/
@@ -23,7 +23,7 @@ Replace `bin/bundle` by running `bundle binstubs bundler --force`, then run this
2323
end
2424
end
2525

26-
require 'rubygems'
27-
require 'bundler/setup'
26+
require "rubygems"
27+
require "bundler/setup"
2828

29-
load Gem.bin_path('pry', 'pry')
29+
load Gem.bin_path("pry", "pry")

bin/rake

+7-7
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,11 @@
88
# this file is here to facilitate running it.
99
#
1010

11-
require 'pathname'
12-
ENV['BUNDLE_GEMFILE'] ||= File.expand_path('../../Gemfile',
13-
Pathname.new(__FILE__).realpath)
11+
require "pathname"
12+
ENV["BUNDLE_GEMFILE"] ||= File.expand_path("../../Gemfile",
13+
Pathname.new(__FILE__).realpath)
1414

15-
bundle_binstub = File.expand_path('bundle', __dir__)
15+
bundle_binstub = File.expand_path("../bundle", __FILE__)
1616

1717
if File.file?(bundle_binstub)
1818
if File.read(bundle_binstub, 300) =~ /This file was generated by Bundler/
@@ -23,7 +23,7 @@ Replace `bin/bundle` by running `bundle binstubs bundler --force`, then run this
2323
end
2424
end
2525

26-
require 'rubygems'
27-
require 'bundler/setup'
26+
require "rubygems"
27+
require "bundler/setup"
2828

29-
load Gem.bin_path('rake', 'rake')
29+
load Gem.bin_path("rake", "rake")

bin/rspec

+7-7
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,11 @@
88
# this file is here to facilitate running it.
99
#
1010

11-
require 'pathname'
12-
ENV['BUNDLE_GEMFILE'] ||= File.expand_path('../../Gemfile',
13-
Pathname.new(__FILE__).realpath)
11+
require "pathname"
12+
ENV["BUNDLE_GEMFILE"] ||= File.expand_path("../../Gemfile",
13+
Pathname.new(__FILE__).realpath)
1414

15-
bundle_binstub = File.expand_path('bundle', __dir__)
15+
bundle_binstub = File.expand_path("../bundle", __FILE__)
1616

1717
if File.file?(bundle_binstub)
1818
if File.read(bundle_binstub, 300) =~ /This file was generated by Bundler/
@@ -23,7 +23,7 @@ Replace `bin/bundle` by running `bundle binstubs bundler --force`, then run this
2323
end
2424
end
2525

26-
require 'rubygems'
27-
require 'bundler/setup'
26+
require "rubygems"
27+
require "bundler/setup"
2828

29-
load Gem.bin_path('rspec-core', 'rspec')
29+
load Gem.bin_path("rspec-core", "rspec")

0 commit comments

Comments
 (0)