1
0
Fork 0
mirror of https://github.com/ruby/ruby.git synced 2022-11-09 12:17:21 -05:00
ruby--ruby/spec/bundler/bundler/env_spec.rb
David Rodríguez 5a384e2c08 Fix some bundler specs (#2380)
* These seem to consistenly pass already

* Show actual command when running `make test-bundler`

Current the setup command that installs the necessary gems for testing
bundler was printed, but not the actual command that runs the tests.
That was a bit confusing.

* Borrow trick from setproctitle specs

* A title that long doesn't get set sometimes

No idea why, but the test doesn't need that the title is that long.

* Fix most gem helper spec ruby-core failures

* Fix the rest of the gem helper failures

* Fix version spec by improving the assertion

* Remove unnecessary `BUNDLE_RUBY` environment var

We can use `RUBY` when necessary, and `BUNDLE_RUBY` is not a good name
because bundler considers `BUNDLE_*` variables as settings.

* Rename `BUNDLE_GEM` to `GEM_COMMAND`

This is more descriptive I think, and also friendlier for bundler
because `BUNDLE_` env variables are interpreted by bundler as settings,
and this is not a bundler setting.

This fixes one bundler spec failure in config specs against ruby-core.

* Fix quality spec when run in core

Use the proper path helper.

* Fix dummy lib builder to never load default gems

If a dummy library is named as a default gem, when requiring the library
from its executable, the default gem would be loaded when running from
core, because in core all default gems share path with bundler, and thus
they are always in the $LOAD_PATH. We fix the issue by loading lib
relatively inside dummy lib executables.

* More exact assertions

Sometimes I have the problem that I do some "print debugging" inside
specs, and suddently the spec passes. This happens when the assertion is
too relaxed, and the things I print make it match, specially when they
are simple strings like "1.0" than can be easily be part of gem paths
that I print for debugging.

I fix this by making a more exact assertion.

* Detect the correct shebang when ENV["RUBY"] is set

* Relax assertion

So that the spec passes even if another paths containing "ext" are in
the load path. This works to fix a ruby-core issue, but it's a better
assertion in general. We just want to know that the extension path was
added.

* Use folder structure independent path helper

It should fix this spec for ruby-core.

* Fix the last failing spec on ruby-core

* Skip `bundle open <default_gem>` spec when no default gems
2019-08-20 09:46:31 +09:00

200 lines
5.2 KiB
Ruby

# frozen_string_literal: true
require "openssl"
require "bundler/settings"
RSpec.describe Bundler::Env do
let(:git_proxy_stub) { Bundler::Source::Git::GitProxy.new(nil, nil, nil) }
describe "#report" do
it "prints the environment" do
out = described_class.report
expect(out).to include("Environment")
expect(out).to include(Bundler::VERSION)
expect(out).to include(Gem::VERSION)
expect(out).to include(described_class.send(:ruby_version))
expect(out).to include(described_class.send(:git_version))
expect(out).to include(OpenSSL::OPENSSL_VERSION)
end
describe "rubygems paths" do
it "prints gem home" do
with_clear_paths("GEM_HOME", "/a/b/c") do
out = described_class.report
expect(out).to include("Gem Home /a/b/c")
end
end
it "prints gem path" do
with_clear_paths("GEM_PATH", "/a/b/c:/d/e/f") do
out = described_class.report
expect(out).to include("Gem Path /a/b/c:/d/e/f")
end
end
it "prints user home" do
with_clear_paths("HOME", "/a/b/c") do
out = described_class.report
expect(out).to include("User Home /a/b/c")
end
end
it "prints user path" do
with_clear_paths("HOME", "/a/b/c") do
out = described_class.report
expect(out).to include("User Path /a/b/c/.gem")
end
end
it "prints bin dir" do
with_clear_paths("GEM_HOME", "/a/b/c") do
out = described_class.report
expect(out).to include("Bin Dir /a/b/c/bin")
end
end
private
def with_clear_paths(env_var, env_value)
old_env_var = ENV[env_var]
ENV[env_var] = env_value
Gem.clear_paths
yield
ensure
ENV[env_var] = old_env_var
end
end
context "when there is a Gemfile and a lockfile and print_gemfile is true" do
before do
gemfile "gem 'rack', '1.0.0'"
lockfile <<-L
GEM
remote: #{file_uri_for(gem_repo1)}/
specs:
rack (1.0.0)
DEPENDENCIES
rack
BUNDLED WITH
1.10.0
L
end
let(:output) { described_class.report(:print_gemfile => true) }
it "prints the Gemfile" do
expect(output).to include("Gemfile")
expect(output).to include("'rack', '1.0.0'")
end
it "prints the lockfile" do
expect(output).to include("Gemfile.lock")
expect(output).to include("rack (1.0.0)")
end
end
context "when there no Gemfile and print_gemfile is true" do
let(:output) { described_class.report(:print_gemfile => true) }
it "prints the environment" do
expect(output).to start_with("## Environment")
end
end
context "when Gemfile contains a gemspec and print_gemspecs is true" do
let(:gemspec) do
strip_whitespace(<<-GEMSPEC)
Gem::Specification.new do |gem|
gem.name = "foo"
gem.author = "Fumofu"
end
GEMSPEC
end
before do
gemfile("gemspec")
File.open(bundled_app.join("foo.gemspec"), "wb") do |f|
f.write(gemspec)
end
end
it "prints the gemspec" do
output = described_class.report(:print_gemspecs => true)
expect(output).to include("foo.gemspec")
expect(output).to include(gemspec)
end
end
context "when eval_gemfile is used" do
it "prints all gemfiles" do
create_file "other/Gemfile-other", "gem 'rack'"
create_file "other/Gemfile", "eval_gemfile 'Gemfile-other'"
create_file "Gemfile-alt", <<-G
source "#{file_uri_for(gem_repo1)}"
eval_gemfile "other/Gemfile"
G
gemfile "eval_gemfile #{File.expand_path("Gemfile-alt").dump}"
output = described_class.report(:print_gemspecs => true)
expect(output).to include(strip_whitespace(<<-ENV))
## Gemfile
### Gemfile
```ruby
eval_gemfile #{File.expand_path("Gemfile-alt").dump}
```
### Gemfile-alt
```ruby
source "#{file_uri_for(gem_repo1)}"
eval_gemfile "other/Gemfile"
```
### other/Gemfile
```ruby
eval_gemfile 'Gemfile-other'
```
### other/Gemfile-other
```ruby
gem 'rack'
```
### Gemfile.lock
```
<No #{bundled_app("Gemfile.lock")} found>
```
ENV
end
end
context "when the git version is OS specific" do
it "includes OS specific information with the version number" do
expect(git_proxy_stub).to receive(:git).with("--version").
and_return("git version 1.2.3 (Apple Git-BS)")
expect(Bundler::Source::Git::GitProxy).to receive(:new).and_return(git_proxy_stub)
expect(described_class.report).to include("Git 1.2.3 (Apple Git-BS)")
end
end
end
describe ".version_of" do
let(:parsed_version) { described_class.send(:version_of, "ruby") }
it "strips version of new line characters" do
expect(parsed_version).to_not end_with("\n")
end
end
end