summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBundlerbot <bot@bundler.io>2019-09-28 18:16:18 +0000
committerBundlerbot <bot@bundler.io>2019-09-28 18:16:18 +0000
commit2a4d88a7044528209321fd4441e995ec66f604b9 (patch)
tree6369dadb51b9bd1702324657be34704aacdba66c
parente719a58b26e2f85c885a950d90c8d4a0f7339c0f (diff)
parent0a67ac4dc2bad753e33e11352e97f73c9c1ddeee (diff)
downloadbundler-2a4d88a7044528209321fd4441e995ec66f604b9.tar.gz
Merge #7362
7362: Fix spec warnings r=deivid-rodriguez a=deivid-rodriguez ### What was the end-user problem that led to this PR? The problem was that our specs print some warnings to screen. ### What was your diagnosis of the problem? My diagnosis was that specs should have a clean output. ### What is your fix for the problem, implemented in this PR? My fix is to remove the warnings. Co-authored-by: David Rodríguez <deivid.rodriguez@riseup.net>
-rw-r--r--spec/bundler/ruby_version_spec.rb20
-rw-r--r--spec/runtime/with_unbundled_env_spec.rb26
2 files changed, 32 insertions, 14 deletions
diff --git a/spec/bundler/ruby_version_spec.rb b/spec/bundler/ruby_version_spec.rb
index 868d81088d..8c6c071d7f 100644
--- a/spec/bundler/ruby_version_spec.rb
+++ b/spec/bundler/ruby_version_spec.rb
@@ -400,12 +400,20 @@ RSpec.describe "Bundler::RubyVersion and its subclasses" do
let(:bundler_system_ruby_version) { subject }
around do |example|
- begin
- old_ruby_version = Bundler::RubyVersion.instance_variable_get("@ruby_version")
- Bundler::RubyVersion.instance_variable_set("@ruby_version", nil)
- example.run
- ensure
- Bundler::RubyVersion.instance_variable_set("@ruby_version", old_ruby_version)
+ if Bundler::RubyVersion.instance_variable_defined?("@ruby_version")
+ begin
+ old_ruby_version = Bundler::RubyVersion.instance_variable_get("@ruby_version")
+ Bundler::RubyVersion.remove_instance_variable("@ruby_version")
+ example.run
+ ensure
+ Bundler::RubyVersion.instance_variable_set("@ruby_version", old_ruby_version)
+ end
+ else
+ begin
+ example.run
+ ensure
+ Bundler::RubyVersion.remove_instance_variable("@ruby_version")
+ end
end
end
diff --git a/spec/runtime/with_unbundled_env_spec.rb b/spec/runtime/with_unbundled_env_spec.rb
index a5140ae463..05f3c8e3ab 100644
--- a/spec/runtime/with_unbundled_env_spec.rb
+++ b/spec/runtime/with_unbundled_env_spec.rb
@@ -1,5 +1,7 @@
# frozen_string_literal: true
+require_relative "../support/streams"
+
RSpec.describe "Bundler.with_env helpers" do
def bundle_exec_ruby!(code, options = {})
build_bundler_context options
@@ -127,13 +129,17 @@ RSpec.describe "Bundler.with_env helpers" do
describe "Bundler.with_clean_env", :bundler => 2 do
it "should set ENV to unbundled_env in the block" do
expected = Bundler.unbundled_env
- actual = Bundler.with_clean_env { ENV.to_hash }
+ actual = nil
+ capture(:stderr) do
+ actual = Bundler.with_clean_env { ENV.to_hash }
+ end
+
expect(actual).to eq(expected)
end
it "should restore the environment after execution" do
- Bundler.with_clean_env do
- ENV["FOO"] = "hello"
+ capture(:stderr) do
+ Bundler.with_clean_env { ENV["FOO"] = "hello" }
end
expect(ENV).not_to have_key("FOO")
@@ -175,7 +181,9 @@ RSpec.describe "Bundler.with_env helpers" do
describe "Bundler.clean_system", :bundler => 2 do
let(:code) do
<<~RUBY
- Bundler.clean_system(%([ "\$BUNDLE_FOO" = "bar" ] || exit 42))
+ capture(:stderr) do
+ Bundler.clean_system(%([ "\$BUNDLE_FOO" = "bar" ] || exit 42))
+ end
exit $?.exitstatus
RUBY
@@ -183,7 +191,7 @@ RSpec.describe "Bundler.with_env helpers" do
it "runs system inside with_clean_env" do
lib = File.expand_path("../../lib", __dir__)
- system({ "BUNDLE_FOO" => "bar" }, "ruby -I#{lib} -rbundler -e '#{code}'")
+ system({ "BUNDLE_FOO" => "bar" }, "ruby -I#{lib}:#{spec} -rsupport/streams -rbundler -e '#{code}'")
expect($?.exitstatus).to eq(42)
end
end
@@ -229,8 +237,10 @@ RSpec.describe "Bundler.with_env helpers" do
describe "Bundler.clean_exec", :bundler => 2 do
let(:code) do
<<~RUBY
- Process.fork do
- exit Bundler.clean_exec(%(test "\$BUNDLE_FOO" = "bar"))
+ capture(:stderr) do
+ Process.fork do
+ exit Bundler.clean_exec(%(test "\$BUNDLE_FOO" = "bar"))
+ end
end
_, status = Process.wait2
@@ -243,7 +253,7 @@ RSpec.describe "Bundler.with_env helpers" do
skip "Fork not implemented" if Gem.win_platform?
lib = File.expand_path("../../lib", __dir__)
- system({ "BUNDLE_FOO" => "bar" }, "ruby -I#{lib} -rbundler -e '#{code}'")
+ system({ "BUNDLE_FOO" => "bar" }, "ruby -I#{lib}:#{spec} -rsupport/streams -rbundler -e '#{code}'")
expect($?.exitstatus).to eq(1)
end
end