summaryrefslogtreecommitdiff
path: root/spec
diff options
context:
space:
mode:
authorLamont Granquist <lamont@scriptkiddie.org>2015-01-07 09:14:50 -0800
committerLamont Granquist <lamont@scriptkiddie.org>2015-01-12 11:53:15 -0800
commit6d7ee4010e67f6921a78e2b57152de9eaa725b11 (patch)
treeebf595bb3c98847ca0f2e4485973ade18427c714 /spec
parentc1869a22ecec29aaafdd09e19e5291b1946e6498 (diff)
downloadchef-6d7ee4010e67f6921a78e2b57152de9eaa725b11.tar.gz
add a compile_time flag to chef_gem resource
the default is still the same, but will warn that users should start being explicit. setting compile_time false will become the new default in chef-13 and is encouraged to avoid the compile_time arms race.
Diffstat (limited to 'spec')
-rw-r--r--spec/unit/resource/chef_gem_spec.rb60
1 files changed, 57 insertions, 3 deletions
diff --git a/spec/unit/resource/chef_gem_spec.rb b/spec/unit/resource/chef_gem_spec.rb
index 480856d19f..657713d54f 100644
--- a/spec/unit/resource/chef_gem_spec.rb
+++ b/spec/unit/resource/chef_gem_spec.rb
@@ -32,16 +32,70 @@ describe Chef::Resource::ChefGem, "initialize" do
end
describe Chef::Resource::ChefGem, "gem_binary" do
+ let(:resource) { Chef::Resource::ChefGem.new("foo") }
+
before(:each) do
expect(RbConfig::CONFIG).to receive(:[]).with('bindir').and_return("/opt/chef/embedded/bin")
- @resource = Chef::Resource::ChefGem.new("foo")
end
it "should raise an exception when gem_binary is set" do
- expect { @resource.gem_binary("/lol/cats/gem") }.to raise_error(ArgumentError)
+ expect { resource.gem_binary("/lol/cats/gem") }.to raise_error(ArgumentError)
+ end
+
+ it "should set the gem_binary based on computing it from RbConfig" do
+ expect(resource.gem_binary).to eql("/opt/chef/embedded/bin/gem")
end
it "should set the gem_binary based on computing it from RbConfig" do
- expect(@resource.gem_binary).to eql("/opt/chef/embedded/bin/gem")
+ expect(resource.compile_time).to be nil
+ end
+
+ context "when building the resource" do
+ let(:node) do
+ Chef::Node.new.tap {|n| n.normal[:tags] = [] }
+ end
+
+ let(:run_context) do
+ Chef::RunContext.new(node, {}, nil)
+ end
+
+ let(:recipe) do
+ Chef::Recipe.new("hjk", "test", run_context)
+ end
+
+ let(:resource) { Chef::Resource::ChefGem.new("foo", run_context) }
+
+ before do
+ expect(Chef::Resource::ChefGem).to receive(:new).and_return(resource)
+ end
+
+ it "runs the install at compile-time by default", :chef_lt_13_only do
+ expect(resource).to receive(:run_action).with(:install)
+ expect(Chef::Log).to receive(:warn).at_least(:once)
+ recipe.chef_gem "foo"
+ end
+
+ # the default behavior will change in Chef-13
+ it "does not runs the install at compile-time by default", :chef_gte_13_only do
+ expect(resource).not_to receive(:run_action).with(:install)
+ expect(Chef::Log).not_to receive(:warn)
+ recipe.chef_gem "foo"
+ end
+
+ it "compile_time true installs at compile-time" do
+ expect(resource).to receive(:run_action).with(:install)
+ expect(Chef::Log).not_to receive(:warn)
+ recipe.chef_gem "foo" do
+ compile_time true
+ end
+ end
+
+ it "compile_time false does not install at compile-time" do
+ expect(resource).not_to receive(:run_action).with(:install)
+ expect(Chef::Log).not_to receive(:warn)
+ recipe.chef_gem "foo" do
+ compile_time false
+ end
+ end
end
end