From 498e8aebb6791426e8915684421591e544c9fad4 Mon Sep 17 00:00:00 2001 From: Amol Shinde Date: Fri, 23 Aug 2019 17:35:09 +0530 Subject: Added support to provide additional options to bundle install - Added option to skip gem metadata installation - Added test cases for gem installer Signed-off-by: Amol Shinde --- spec/unit/cookbook/gem_installer_spec.rb | 23 ++++++++++++++++++++++- 1 file changed, 22 insertions(+), 1 deletion(-) (limited to 'spec') diff --git a/spec/unit/cookbook/gem_installer_spec.rb b/spec/unit/cookbook/gem_installer_spec.rb index b7c8db514a..807e801aaf 100644 --- a/spec/unit/cookbook/gem_installer_spec.rb +++ b/spec/unit/cookbook/gem_installer_spec.rb @@ -59,23 +59,25 @@ describe Chef::Cookbook::GemInstaller do expect(File).to receive(:open).and_yield(gemfile) expect(gemfile).to receive(:path).and_return("") expect(IO).to receive(:read).and_return("") - expect(gem_installer).to receive(:shell_out!).and_return(shell_out) end it "generates a valid Gemfile" do + expect(gem_installer).to receive(:shell_out!).and_return(shell_out) expect { gem_installer.install }.to_not raise_error expect { bundler_dsl }.to_not raise_error end it "generate a Gemfile with all constraints" do + expect(gem_installer).to receive(:shell_out!).and_return(shell_out) expect { gem_installer.install }.to_not raise_error expect(bundler_dsl.dependencies.find { |d| d.name == "httpclient" }.requirements_list.length).to eql(2) end it "generates a valid Gemfile when Chef::Config[:rubygems_url] is set to a String" do + expect(gem_installer).to receive(:shell_out!).and_return(shell_out) Chef::Config[:rubygems_url] = "https://www.rubygems.org" expect { gem_installer.install }.to_not raise_error @@ -83,10 +85,29 @@ describe Chef::Cookbook::GemInstaller do end it "generates a valid Gemfile when Chef::Config[:rubygems_url] is set to an Array" do + expect(gem_installer).to receive(:shell_out!).and_return(shell_out) Chef::Config[:rubygems_url] = [ "https://www.rubygems.org" ] expect { gem_installer.install }.to_not raise_error expect(bundler_dsl.dependencies.find { |d| d.name == "httpclient" }.requirements_list.length).to eql(2) end + + it "skip metadata installation when Chef::Config[:skip_gem_metadata_installation] is set to true" do + Chef::Config[:skip_gem_metadata_installation] = true + expect(gem_installer.install).to_not receive(:shell_out!) + end + + it "install metadata when Chef::Config[:skip_gem_metadata_installation] is not true" do + expect(gem_installer).to receive(:shell_out!).and_return(shell_out) + expect(Chef::Log).to receive(:info).and_return("") + expect(gem_installer.install).to be_nil + end + + it "install from local cache when Chef::Config[:gem_installer_bundler_options] is set to local" do + Chef::Config[:gem_installer_bundler_options] = "--local" + expect(gem_installer).to receive(:shell_out!).with(["bundle", "install", "--local"], any_args).and_return(shell_out) + expect(Chef::Log).to receive(:info).and_return("") + expect(gem_installer.install).to be_nil + end end -- cgit v1.2.1