diff options
Diffstat (limited to 'spec/unit')
-rw-r--r-- | spec/unit/provider/remote_file/ftp_spec.rb | 4 | ||||
-rw-r--r-- | spec/unit/provider/remote_file_spec.rb | 3 | ||||
-rw-r--r-- | spec/unit/provider/service/debian_service_spec.rb | 6 | ||||
-rw-r--r-- | spec/unit/provider/service/openbsd_service_spec.rb | 3 | ||||
-rw-r--r-- | spec/unit/provider/service/upstart_service_spec.rb | 4 | ||||
-rw-r--r-- | spec/unit/provider/service/windows_spec.rb | 43 | ||||
-rw-r--r-- | spec/unit/shell/shell_session_spec.rb | 21 | ||||
-rw-r--r-- | spec/unit/shell_spec.rb | 20 |
8 files changed, 44 insertions, 60 deletions
diff --git a/spec/unit/provider/remote_file/ftp_spec.rb b/spec/unit/provider/remote_file/ftp_spec.rb index dbbddd8e84..10c8e5a4ee 100644 --- a/spec/unit/provider/remote_file/ftp_spec.rb +++ b/spec/unit/provider/remote_file/ftp_spec.rb @@ -53,7 +53,8 @@ describe Chef::Provider::RemoteFile::FTP do let(:tempfile) do t = StringIO.new - allow(t).to receive(:path).and_return(tempfile_path) + example = self + t.define_singleton_method(:path) { example.tempfile_path } t end @@ -137,7 +138,6 @@ describe Chef::Provider::RemoteFile::FTP do let(:uri) { URI.parse("ftp://opscode.com:8021/seattle.txt") } it "should connect on an alternate port when one is provided" do - uri = URI.parse("ftp://opscode.com:8021/seattle.txt") expect(ftp).to receive(:connect).with("opscode.com", 8021) fetcher.fetch end diff --git a/spec/unit/provider/remote_file_spec.rb b/spec/unit/provider/remote_file_spec.rb index de4a897847..d59d635a7c 100644 --- a/spec/unit/provider/remote_file_spec.rb +++ b/spec/unit/provider/remote_file_spec.rb @@ -32,7 +32,7 @@ describe Chef::Provider::RemoteFile do end let(:content) do - content = double('Chef::Provider::File::Content::RemoteFile') + double('Chef::Provider::File::Content::RemoteFile') end let(:node) { double('Chef::Node') } @@ -48,7 +48,6 @@ describe Chef::Provider::RemoteFile do subject(:provider) do provider = described_class.new(resource, run_context) allow(provider).to receive(:content).and_return(content) - allow(provider).to receive(:update_new_resource_checksum).and_return(nil) # Otherwise it doesn't behave like a File provider provider end diff --git a/spec/unit/provider/service/debian_service_spec.rb b/spec/unit/provider/service/debian_service_spec.rb index a4667e8ce8..c6d8ede23a 100644 --- a/spec/unit/provider/service/debian_service_spec.rb +++ b/spec/unit/provider/service/debian_service_spec.rb @@ -46,8 +46,6 @@ describe Chef::Provider::Service::Debian do context "when update-rc.d shows init linked to rc*.d/" do before do - allow(@provider).to receive(:assert_update_rcd_available) - result = <<-UPDATE_RC_D_SUCCESS Removing any system startup links for /etc/init.d/chef ... /etc/rc0.d/K20chef @@ -79,7 +77,6 @@ describe Chef::Provider::Service::Debian do context "when update-rc.d shows init isn't linked to rc*.d/" do before do - allow(@provider).to receive(:assert_update_rcd_available) @status = double("Status", :exitstatus => 0) @stdout = StringIO.new( " Removing any system startup links for /etc/init.d/chef ...") @@ -196,8 +193,6 @@ insserv: dryrun, not creating .depend.boot, .depend.start, and .depend.stop context "on #{model}" do context "when update-rc.d shows init linked to rc*.d/" do before do - allow(@provider).to receive(:assert_update_rcd_available) - @stdout = StringIO.new(expected_results["linked"]["stdout"]) @stderr = StringIO.new(expected_results["linked"]["stderr"]) @status = double("Status", :exitstatus => 0, :stdout => @stdout) @@ -223,7 +218,6 @@ insserv: dryrun, not creating .depend.boot, .depend.start, and .depend.stop context "when update-rc.d shows init isn't linked to rc*.d/" do before do - allow(@provider).to receive(:assert_update_rcd_available) @stdout = StringIO.new(expected_results["not linked"]["stdout"]) @stderr = StringIO.new(expected_results["not linked"]["stderr"]) @status = double("Status", :exitstatus => 0, :stdout => @stdout) diff --git a/spec/unit/provider/service/openbsd_service_spec.rb b/spec/unit/provider/service/openbsd_service_spec.rb index 1b5206470e..0e5d0d3ba9 100644 --- a/spec/unit/provider/service/openbsd_service_spec.rb +++ b/spec/unit/provider/service/openbsd_service_spec.rb @@ -134,8 +134,6 @@ describe Chef::Provider::Service::Openbsd do stub_etc_rcd_script provider.current_resource = current_resource current_resource.service_name(new_resource.service_name) - - allow(provider).to receive(:service_enable_variable_name).and_return("#{new_resource.service_name}_enable") end context "when the service is builtin" do @@ -248,7 +246,6 @@ describe Chef::Provider::Service::Openbsd do stub_etc_rcd_script expect(provider).to receive(:determine_current_status!) current_resource.running(false) - allow(provider).to receive(:service_enable_variable_name).and_return "#{new_resource.service_name}_enable" expect(::File).to receive(:open).with("/etc/rc.d/#{new_resource.service_name}") end diff --git a/spec/unit/provider/service/upstart_service_spec.rb b/spec/unit/provider/service/upstart_service_spec.rb index ca7ce8f930..1638d6205d 100644 --- a/spec/unit/provider/service/upstart_service_spec.rb +++ b/spec/unit/provider/service/upstart_service_spec.rb @@ -212,7 +212,7 @@ describe Chef::Provider::Service::Upstart do end it "should enable the service if it is not enabled" do - @file = Object.new + @file = instance_double("Chef::Util::FileEdit") allow(Chef::Util::FileEdit).to receive(:new).and_return(@file) allow(@current_resource).to receive(:enabled).and_return(false) expect(@file).to receive(:search_file_replace) @@ -221,7 +221,7 @@ describe Chef::Provider::Service::Upstart do end it "should disable the service if it is enabled" do - @file = Object.new + @file = instance_double("Chef::Util::FileEdit") allow(Chef::Util::FileEdit).to receive(:new).and_return(@file) allow(@current_resource).to receive(:enabled).and_return(true) expect(@file).to receive(:search_file_replace) diff --git a/spec/unit/provider/service/windows_spec.rb b/spec/unit/provider/service/windows_spec.rb index 784a2232b2..71464336cf 100644 --- a/spec/unit/provider/service/windows_spec.rb +++ b/spec/unit/provider/service/windows_spec.rb @@ -20,6 +20,44 @@ require 'spec_helper' require 'mixlib/shellout' +# A class that implements the same API as Win32::Service. All methods raise +# errors unless stubbed or redefined. +# +# This class is used because we cannot load win32-specific libraries on +# non-windows platforms, so we replace the constant with a subclass of this for +# unit tests. We need to provide the same API in order to enable the +# `verify_partial_doubles` RSpec option. +class Win32ServiceDouble + AUTO_START = 0x00000002 + DEMAND_START = 0x00000003 + DISABLED = 0x00000004 + + def self.status(arg) + raise "NOT IMPLEMENTED: the status method must be stubbed" + end + + def self.config_info(arg) + raise "NOT IMPLEMENTED: the config_info method must be stubbed" + end + + def self.exists?(arg) + raise "NOT IMPLEMENTED: the exists? method must be stubbed" + end + + def self.configure(arg) + raise "NOT IMPLEMENTED: the exists? method must be stubbed" + end + + def self.start(arg) + raise "NOT IMPLEMENTED: the start method must be stubbed" + end + + def self.stop(arg) + raise "NOT IMPLEMENTED: the stop method must be stubbed" + end + +end + describe Chef::Provider::Service::Windows, "load_current_resource" do before(:each) do @node = Chef::Node.new @@ -30,10 +68,7 @@ describe Chef::Provider::Service::Windows, "load_current_resource" do @provider.current_resource = Chef::Resource::WindowsService.new("current-chef") Object.send(:remove_const, 'Win32') if defined?(Win32) Win32 = Module.new - Win32::Service = Class.new - Win32::Service::AUTO_START = 0x00000002 - Win32::Service::DEMAND_START = 0x00000003 - Win32::Service::DISABLED = 0x00000004 + Win32::Service = Class.new(Win32ServiceDouble) allow(Win32::Service).to receive(:status).with(@new_resource.service_name).and_return( double("StatusStruct", :current_state => "running")) allow(Win32::Service).to receive(:config_info).with(@new_resource.service_name).and_return( diff --git a/spec/unit/shell/shell_session_spec.rb b/spec/unit/shell/shell_session_spec.rb index d72e3fa1bb..b6ff5a2e0f 100644 --- a/spec/unit/shell/shell_session_spec.rb +++ b/spec/unit/shell/shell_session_spec.rb @@ -18,27 +18,6 @@ require 'spec_helper' require "ostruct" - -class TestableShellSession < Shell::ShellSession - - def rebuild_node - nil - end - - def rebuild_collection - nil - end - - def loading - nil - end - - def loading_complete - nil - end - -end - describe Shell::ShellSession do it "is a singleton object" do diff --git a/spec/unit/shell_spec.rb b/spec/unit/shell_spec.rb index 0e028f4359..b892ca273e 100644 --- a/spec/unit/shell_spec.rb +++ b/spec/unit/shell_spec.rb @@ -18,26 +18,6 @@ require 'spec_helper' require "ostruct" -ObjectTestHarness = Proc.new do - extend Shell::Extensions::ObjectCoreExtensions - - def conf=(new_conf) - @conf = new_conf - end - - def conf - @conf - end - - desc "rspecin'" - def rspec_method - end -end - -class TestJobManager - attr_accessor :jobs -end - describe Shell do before do |