diff options
author | James Wen <jrw2175@columbia.edu> | 2016-01-07 01:27:42 -0500 |
---|---|---|
committer | James Wen <jrw2175@columbia.edu> | 2016-01-08 01:08:57 -0500 |
commit | db934707af011515f4c775cd7e372dffa86f8b7f (patch) | |
tree | 3d2335681461d08b311437639b8446fd54c9a4b2 | |
parent | 5dc64161d6b6310ab343f4a283fa779ae139461a (diff) | |
download | bundler-db934707af011515f4c775cd7e372dffa86f8b7f.tar.gz |
Refactor `Bundler::SharedHelpers` module unit tests to use said module as subject
-rw-r--r-- | spec/bundler/shared_helpers_spec.rb | 31 |
1 files changed, 13 insertions, 18 deletions
diff --git a/spec/bundler/shared_helpers_spec.rb b/spec/bundler/shared_helpers_spec.rb index cfd6374545..7384b085ec 100644 --- a/spec/bundler/shared_helpers_spec.rb +++ b/spec/bundler/shared_helpers_spec.rb @@ -2,15 +2,15 @@ require "spec_helper" require "bundler/shared_helpers" describe Bundler::SharedHelpers do + subject { Bundler::SharedHelpers } describe "#default_gemfile" do - subject { Bundler::SharedHelpers.default_gemfile } before do ENV["BUNDLE_GEMFILE"] = "/path/Gemfile" end context "Gemfile is present" do it "returns the Gemfile path" do expected_gemfile_path = Pathname.new("/path/Gemfile") - expect(subject).to eq(expected_gemfile_path) + expect(subject.default_gemfile).to eq(expected_gemfile_path) end end context "Gemfile is not present" do @@ -18,38 +18,36 @@ describe Bundler::SharedHelpers do ENV["BUNDLE_GEMFILE"] = nil end it "raises a GemfileNotFound error" do - expect { subject }.to raise_error(Bundler::GemfileNotFound, "Could not locate Gemfile") + expect { subject.default_gemfile }.to raise_error(Bundler::GemfileNotFound, "Could not locate Gemfile") end end end describe "#default_lockfile" do - subject { Bundler::SharedHelpers.default_lockfile } context "gemfile is gems.rb" do before do gemfile_path = Pathname.new("/path/gems.rb") - allow(Bundler::SharedHelpers).to receive(:default_gemfile).and_return(gemfile_path) + allow(subject).to receive(:default_gemfile).and_return(gemfile_path) end it "returns the gems.locked path" do expected_lockfile_path = Pathname.new("/path/gems.locked") - expect(subject).to eq(expected_lockfile_path) + expect(subject.default_lockfile).to eq(expected_lockfile_path) end end context "is a regular Gemfile" do before do gemfile_path = Pathname.new("/path/Gemfile") - allow(Bundler::SharedHelpers).to receive(:default_gemfile).and_return(gemfile_path) + allow(subject).to receive(:default_gemfile).and_return(gemfile_path) end it "returns the lock file path" do expected_lockfile_path = Pathname.new("/path/Gemfile.lock") - expect(subject).to eq(expected_lockfile_path) + expect(subject.default_lockfile).to eq(expected_lockfile_path) end end end describe "#default_bundle_dir" do - subject { Bundler::SharedHelpers.default_bundle_dir } context ".bundle does not exist" do it "returns nil" do - expect(subject).to eq(nil) + expect(subject.default_bundle_dir).to eq(nil) end end context ".bundle is global .bundle" do @@ -59,7 +57,7 @@ describe Bundler::SharedHelpers do allow(Bundler.rubygems).to receive(:user_home).and_return(global_rubygems_dir) end it "returns nil" do - expect(subject).to eq(nil) + expect(subject.default_bundle_dir).to eq(nil) end end context ".bundle is not global .bundle" do @@ -70,7 +68,7 @@ describe Bundler::SharedHelpers do end it "returns the .bundle path" do expected_bundle_dir_path = Pathname.new("#{bundled_app}/.bundle") - expect(subject).to eq(expected_bundle_dir_path) + expect(subject.default_bundle_dir).to eq(expected_bundle_dir_path) end end end @@ -79,21 +77,18 @@ describe Bundler::SharedHelpers do VALID_CONSTANT = 1 end context "when the namespace does have the requested constant" do - subject { Bundler::SharedHelpers.const_get_safely(:VALID_CONSTANT, TargetNamespace) } it "returns the value of the requested constant" do - expect(subject).to eq(1) + expect(subject.const_get_safely(:VALID_CONSTANT, TargetNamespace)).to eq(1) end end context "when the requested constant is passed as a string" do - subject { Bundler::SharedHelpers.const_get_safely("VALID_CONSTANT", TargetNamespace) } it "returns the value of the requested constant" do - expect(subject).to eq(1) + expect(subject.const_get_safely("VALID_CONSTANT", TargetNamespace)).to eq(1) end end context "when the namespace does not have the requested constant" do - subject { Bundler::SharedHelpers.const_get_safely("INVALID_CONSTANT", TargetNamespace) } it "returns nil" do - expect(subject).to eq(nil) + expect(subject.const_get_safely("INVALID_CONSTANT", TargetNamespace)).to eq(nil) end end end |