Skip to content
This repository has been archived by the owner on Apr 14, 2021. It is now read-only.

Commit

Permalink
Merge #7402
Browse files Browse the repository at this point in the history
7402: Spec normalizations r=deivid-rodriguez a=deivid-rodriguez

### What was the end-user problem that led to this PR?

The problem was that I saw some room for improvement in our specs and I couldn't help myself :)

### What is your fix for the problem, implemented in this PR?

Essentially, the idea of this PR is to avoid using `__FILE__` or other folder-structure specific constructs to look for files, and instead use our helpers ìn `spec/support/path.rb`. The idea is that the helpers in this file are aware that `bundler` specs can be run from ruby-core or the upstream repo, and the folder structure is different for both.

Also, the PR normalizes some naming, some duplicated helpers, and the way we require files from specs.

Co-authored-by: David Rodríguez <deivid.rodriguez@riseup.net>
(cherry picked from commit 2e7a37b)
  • Loading branch information
bundlerbot authored and deivid-rodriguez committed Nov 7, 2019
1 parent 212900f commit e133e7a
Show file tree
Hide file tree
Showing 58 changed files with 118 additions and 126 deletions.
2 changes: 1 addition & 1 deletion spec/bundler/shared_helpers_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -236,7 +236,7 @@
shared_examples_for "ENV['RUBYOPT'] gets set correctly" do
it "ensures -rbundler/setup is at the beginning of ENV['RUBYOPT']" do
subject.set_bundle_environment
expect(ENV["RUBYOPT"].split(" ")).to start_with("-r#{lib}/bundler/setup")
expect(ENV["RUBYOPT"].split(" ")).to start_with("-r#{lib_dir}/bundler/setup")
end
end

Expand Down
6 changes: 3 additions & 3 deletions spec/commands/exec_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@
else
require 'tempfile'
io = Tempfile.new("io-test-fd")
args = %W[#{Gem.ruby} -I#{lib} #{bindir.join("bundle")} exec --keep-file-descriptors #{Gem.ruby} #{command.path} \#{io.to_i}]
args = %W[#{Gem.ruby} -I#{lib_dir} #{bindir.join("bundle")} exec --keep-file-descriptors #{Gem.ruby} #{command.path} \#{io.to_i}]
args << { io.to_i => io }
exec(*args)
end
Expand Down Expand Up @@ -279,7 +279,7 @@
G

rubyopt = ENV["RUBYOPT"]
rubyopt = "-r#{lib}/bundler/setup #{rubyopt}"
rubyopt = "-r#{lib_dir}/bundler/setup #{rubyopt}"

bundle "exec 'echo $RUBYOPT'"
expect(out).to have_rubyopts(rubyopt)
Expand All @@ -294,7 +294,7 @@
G

rubylib = ENV["RUBYLIB"]
rubylib = rubylib.to_s.split(File::PATH_SEPARATOR).unshift lib.to_s
rubylib = rubylib.to_s.split(File::PATH_SEPARATOR).unshift lib_dir.to_s
rubylib = rubylib.uniq.join(File::PATH_SEPARATOR)

bundle "exec 'echo $RUBYLIB'"
Expand Down
4 changes: 2 additions & 2 deletions spec/commands/newgem_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ def gem_skeleton_assertions
user = bundleuser
EOF
@git_config_location = ENV["GIT_CONFIG"]
path = "#{File.expand_path(tmp, File.dirname(__FILE__))}/test_git_config.txt"
path = "#{tmp}/test_git_config.txt"
File.open(path, "w") {|f| f.write(git_config_content) }
ENV["GIT_CONFIG"] = path
end
Expand Down Expand Up @@ -181,7 +181,7 @@ def gem_skeleton_assertions
context "when git is not available" do
# This spec cannot have `git` available in the test env
before do
load_paths = [lib, spec]
load_paths = [lib_dir, spec_dir]
load_path_str = "-I#{load_paths.join(File::PATH_SEPARATOR)}"

sys_exec "#{Gem.ruby} #{load_path_str} #{bindir.join("bundle")} gem #{gem_name}", "PATH" => ""
Expand Down
2 changes: 1 addition & 1 deletion spec/install/gemfile/groups_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -333,7 +333,7 @@
G

ruby <<-R
require "#{lib}/bundler"
require "#{lib_dir}/bundler"
Bundler.setup :default
Bundler.require :default
puts RACK
Expand Down
2 changes: 1 addition & 1 deletion spec/realworld/dependency_api_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
port = find_unused_port
@server_uri = "http://127.0.0.1:#{port}"

require File.expand_path("../../support/artifice/endpoint_timeout", __FILE__)
require_relative "../support/artifice/endpoint_timeout"

@t = Thread.new do
server = Rack::Server.start(:app => EndpointTimeout,
Expand Down
6 changes: 3 additions & 3 deletions spec/realworld/double_check_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,9 @@
RUBY

cmd = <<-RUBY
require "#{lib}/bundler"
require #{File.expand_path("../../support/artifice/vcr.rb", __FILE__).dump}
require "#{lib}/bundler/inline"
require "#{lib_dir}/bundler"
require "#{spec_dir}/support/artifice/vcr"
require "#{lib_dir}/bundler/inline"
gemfile(true) do
source "https://rubygems.org"
gem "rails", path: "."
Expand Down
8 changes: 4 additions & 4 deletions spec/realworld/edgecases_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@
RSpec.describe "real world edgecases", :realworld => true, :sometimes => true do
def rubygems_version(name, requirement)
ruby! <<-RUBY
require #{File.expand_path("../../support/artifice/vcr.rb", __FILE__).dump}
require "bundler"
require "bundler/source/rubygems/remote"
require "bundler/fetcher"
require "#{spec_dir}/support/artifice/vcr"
require "#{lib_dir}/bundler"
require "#{lib_dir}/bundler/source/rubygems/remote"
require "#{lib_dir}/bundler/fetcher"
rubygem = Bundler.ui.silence do
source = Bundler::Source::Rubygems::Remote.new(URI("https://rubygems.org"))
fetcher = Bundler::Fetcher.new(source)
Expand Down
2 changes: 1 addition & 1 deletion spec/realworld/gemfile_source_header_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ def setup_server
@port = find_unused_port
@server_uri = "http://127.0.0.1:#{@port}"

require File.expand_path("../../support/artifice/endpoint_mirror_source", __FILE__)
require_relative "../support/artifice/endpoint_mirror_source"

@t = Thread.new do
Rack::Server.start(:app => EndpointMirrorSource,
Expand Down
2 changes: 1 addition & 1 deletion spec/realworld/mirror_probe_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ def setup_server
@server_port = find_unused_port
@server_uri = "http://#{host}:#{@server_port}"

require File.expand_path("../../support/artifice/endpoint", __FILE__)
require_relative "../support/artifice/endpoint"

@server_thread = Thread.new do
Rack::Server.start(:app => Endpoint,
Expand Down
4 changes: 2 additions & 2 deletions spec/runtime/gem_tasks_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,15 @@
end
bundled_app("Rakefile").open("w") do |f|
f.write <<-RAKEFILE
$:.unshift("#{lib}")
$:.unshift("#{lib_dir}")
require "bundler/gem_tasks"
RAKEFILE
end
end

it "includes the relevant tasks" do
with_gem_path_as(Spec::Path.base_system_gems.to_s) do
sys_exec "#{rake} -T", "RUBYOPT" => "-I#{lib}"
sys_exec "#{rake} -T", "RUBYOPT" => "-I#{lib_dir}"
end

expect(err).to eq("")
Expand Down
8 changes: 4 additions & 4 deletions spec/runtime/inline_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@

RSpec.describe "bundler/inline#gemfile" do
def script(code, options = {})
requires = ["#{lib}/bundler/inline"]
requires.unshift File.expand_path("../../support/artifice/" + options.delete(:artifice) + ".rb", __FILE__) if options.key?(:artifice)
requires = ["#{lib_dir}/bundler/inline"]
requires.unshift "#{spec_dir}/support/artifice/" + options.delete(:artifice) if options.key?(:artifice)
requires = requires.map {|r| "require '#{r}'" }.join("\n")
@out = ruby("#{requires}\n\n" + code, options)
end
Expand Down Expand Up @@ -97,7 +97,7 @@ def script(code, options = {})

it "lets me use my own ui object" do
script <<-RUBY, :artifice => "endpoint"
require '#{lib}/bundler'
require '#{lib_dir}/bundler'
class MyBundlerUI < Bundler::UI::Silent
def confirm(msg, newline = nil)
puts "CONFIRMED!"
Expand Down Expand Up @@ -141,7 +141,7 @@ def confirm(msg, newline = nil)

it "does not mutate the option argument" do
script <<-RUBY
require '#{lib}/bundler'
require '#{lib_dir}/bundler'
options = { :ui => Bundler::UI::Shell.new }
gemfile(false, options) do
path "#{lib_path}" do
Expand Down
2 changes: 1 addition & 1 deletion spec/runtime/load_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@
G

ruby! <<-RUBY
require "#{lib}/bundler"
require "#{lib_dir}/bundler"
Bundler.setup :default
Bundler.require :default
puts RACK
Expand Down
2 changes: 1 addition & 1 deletion spec/runtime/require_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -193,7 +193,7 @@
G

cmd = <<-RUBY
require '#{lib}/bundler'
require '#{lib_dir}/bundler'
Bundler.require
RUBY
ruby(cmd)
Expand Down
Loading

0 comments on commit e133e7a

Please sign in to comment.