summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJay Mundrawala <jdmundrawala@gmail.com>2016-02-01 14:03:51 -0800
committerKartik Null Cating-Subramanian <ksubramanian@chef.io>2016-02-04 12:25:57 -0500
commit8045115ca8137bcd85a362776c2b623fe8e7a713 (patch)
tree61c060f51fc12d6a577b272d787bbe3abc351643
parentdfeb0a2f8888ea8e1f1860e3da7ad7a1a4dac56f (diff)
downloadchef-8045115ca8137bcd85a362776c2b623fe8e7a713.tar.gz
WIP make rubygems unit specs unit like
-rw-r--r--spec/unit/provider/package/rubygems_spec.rb59
1 files changed, 49 insertions, 10 deletions
diff --git a/spec/unit/provider/package/rubygems_spec.rb b/spec/unit/provider/package/rubygems_spec.rb
index 4ae0e22fba..79b2afe3c1 100644
--- a/spec/unit/provider/package/rubygems_spec.rb
+++ b/spec/unit/provider/package/rubygems_spec.rb
@@ -480,16 +480,30 @@ describe Chef::Provider::Package::Rubygems do
@provider.current_resource = @current_resource
@gem_dep = Gem::Dependency.new("rspec-core", @spec_version)
allow(@provider).to receive(:load_current_resource)
+ version = Gem::Version.new(@spec_version)
+ allow(@provider.gem_env).to receive(:candidate_version_from_remote).
+ with(@gem_dep).
+ and_return(version)
end
describe "in the current gem environment" do
it "installs the gem via the gems api when no explicit options are used" do
+ version = Gem::Version.new(@spec_version)
+ expect(@provider.gem_env).to receive(:candidate_version_from_remote).
+ with(Gem::Dependency.new("rspec-core", @spec_version)).
+ and_return(version)
+
expect(@provider.gem_env).to receive(:install).with(@gem_dep, :sources => nil)
@provider.run_action(:install)
expect(@new_resource).to be_updated_by_last_action
end
it "installs the gem via the gems api when a remote source is provided" do
+ version = Gem::Version.new(@spec_version)
+ expect(@provider.gem_env).to receive(:candidate_version_from_remote).
+ with(@gem_dep, "http://gems.example.org").
+ and_return(version)
+
@new_resource.source("http://gems.example.org")
sources = ["http://gems.example.org"]
expect(@provider.gem_env).to receive(:install).with(@gem_dep, :sources => sources)
@@ -516,6 +530,11 @@ describe Chef::Provider::Package::Rubygems do
# this catches 'gem_package "foo"' when "./foo" is a file in the cwd, and instead of installing './foo' it fetches the remote gem
it "installs the gem via the gems api, when the package has no file separator characters in it, but a matching file exists in cwd" do
+ version = Gem::Version.new(@spec_version)
+ expect(@provider.gem_env).to receive(:candidate_version_from_remote).
+ with(@gem_dep).
+ and_return(version)
+
allow(::File).to receive(:exists?).and_return(true)
@new_resource.package_name("rspec-core")
expect(@provider.gem_env).to receive(:install).with(@gem_dep, :sources => nil)
@@ -524,6 +543,11 @@ describe Chef::Provider::Package::Rubygems do
end
it "installs the gem by shelling out when options are provided as a String" do
+ version = Gem::Version.new(@spec_version)
+ expect(@provider.gem_env).to receive(:candidate_version_from_remote).
+ with(@gem_dep).
+ and_return(version)
+
@new_resource.options("-i /alt/install/location")
expected ="gem install rspec-core -q --no-rdoc --no-ri -v \"#{@spec_version}\" -i /alt/install/location"
expect(@provider).to receive(:shell_out!).with(expected, env: nil, timeout: 900)
@@ -532,6 +556,11 @@ describe Chef::Provider::Package::Rubygems do
end
it "installs the gem with rubygems.org as an added source" do
+ version = Gem::Version.new(@spec_version)
+ expect(@provider.gem_env).to receive(:candidate_version_from_remote).
+ with(@gem_dep, "http://mirror.ops.rhcloud.com/mirror/ruby").
+ and_return(version)
+
@new_resource.gem_binary("/foo/bar")
@new_resource.source("http://mirror.ops.rhcloud.com/mirror/ruby")
expected ="/foo/bar install rspec-core -q --no-rdoc --no-ri -v \"#{@spec_version}\" --source=#{@new_resource.source} --source=https://rubygems.org"
@@ -541,6 +570,11 @@ describe Chef::Provider::Package::Rubygems do
end
it "installs the gem with cleared sources and explict source when specified" do
+ version = Gem::Version.new(@spec_version)
+ expect(@provider.gem_env).to receive(:candidate_version_from_remote).
+ with(@gem_dep, "http://mirror.ops.rhcloud.com/mirror/ruby").
+ and_return(version)
+
@new_resource.gem_binary("/foo/bar")
@new_resource.source("http://mirror.ops.rhcloud.com/mirror/ruby")
@new_resource.clear_sources(true)
@@ -550,19 +584,24 @@ describe Chef::Provider::Package::Rubygems do
expect(@new_resource).to be_updated_by_last_action
end
- context "when no version is given" do
- let(:target_version) { nil }
+ #context "when no version is given" do
+ #let(:target_version) { nil }
- it "installs the gem by shelling out when options are provided but no version is given" do
- @new_resource.options("-i /alt/install/location")
- expected ="gem install rspec-core -q --no-rdoc --no-ri -v \"#{@provider.candidate_version}\" -i /alt/install/location"
- expect(@provider).to receive(:shell_out!).with(expected, env: nil, timeout: 900)
- @provider.run_action(:install)
- expect(@new_resource).to be_updated_by_last_action
- end
- end
+ #it "installs the gem by shelling out when options are provided but no version is given" do
+ #@new_resource.options("-i /alt/install/location")
+ #expected ="gem install \"rspec-core\" -q --no-rdoc --no-ri -v \"#{@provider.candidate_version}\" -i /alt/install/location"
+ #expect(@provider).to receive(:shell_out!).with(expected, env: nil, timeout: 900)
+ #@provider.run_action(:install)
+ #expect(@new_resource).to be_updated_by_last_action
+ #end
+ #end
it "installs the gem via the gems api when options are given as a Hash" do
+ version = Gem::Version.new(@spec_version)
+ expect(@provider.gem_env).to receive(:candidate_version_from_remote).
+ with(@gem_dep).
+ and_return(version)
+
@new_resource.options(:install_dir => "/alt/install/location")
expect(@provider.gem_env).to receive(:install).with(@gem_dep, :sources => nil, :install_dir => "/alt/install/location")
@provider.run_action(:install)