diff options
author | lamont-granquist <lamont@scriptkiddie.org> | 2014-01-30 16:18:36 -0800 |
---|---|---|
committer | lamont-granquist <lamont@scriptkiddie.org> | 2014-01-30 16:18:36 -0800 |
commit | 960463222e123c25a6a6701437a8f375794ac71c (patch) | |
tree | 2bf1f5d51dda3097372fcb4d86eba4fb387e5f08 | |
parent | 93e601b61ef3f049760379a94794607f8287903a (diff) | |
parent | f1c684be191f8f13961712fa9c4e6bfc402a95c5 (diff) | |
download | chef-960463222e123c25a6a6701437a8f375794ac71c.tar.gz |
Merge pull request #1238 from opscode/lcg/rspec-2.14-deprecation-warnings
Lcg/rspec 2.14 deprecation warnings
233 files changed, 2261 insertions, 2254 deletions
diff --git a/chef.gemspec b/chef.gemspec index 5d0283d9d7..d378dfc182 100644 --- a/chef.gemspec +++ b/chef.gemspec @@ -43,7 +43,7 @@ Gem::Specification.new do |s| s.add_development_dependency "sdoc", "~> 0.3.0" %w(rake rack rspec_junit_formatter).each { |gem| s.add_development_dependency gem } - %w(rspec-core rspec-expectations rspec-mocks).each { |gem| s.add_development_dependency gem, "~> 2.13.0" } + %w(rspec-core rspec-expectations rspec-mocks).each { |gem| s.add_development_dependency gem, "~> 2.14.0" } s.bindir = "bin" # chef-service-manager is a windows only executable. diff --git a/spec/functional/knife/cookbook_delete_spec.rb b/spec/functional/knife/cookbook_delete_spec.rb index 2d52fb91a3..ee620bf165 100644 --- a/spec/functional/knife/cookbook_delete_spec.rb +++ b/spec/functional/knife/cookbook_delete_spec.rb @@ -51,7 +51,7 @@ describe Chef::Knife::CookbookDelete do end it "logs an error and exits" do - @knife.ui.stub!(:stderr).and_return(@log_output) + @knife.ui.stub(:stderr).and_return(@log_output) lambda {@knife.run}.should raise_error(SystemExit) @log_output.string.should match(/Cannot find a cookbook named no-such-cookbook to delete/) end @@ -67,8 +67,8 @@ describe Chef::Knife::CookbookDelete do it "asks for confirmation, then deletes the cookbook" do stdin, stdout = StringIO.new("y\n"), StringIO.new - @knife.ui.stub!(:stdin).and_return(stdin) - @knife.ui.stub!(:stdout).and_return(stdout) + @knife.ui.stub(:stdin).and_return(stdin) + @knife.ui.stub(:stdout).and_return(stdout) cb100_deleted = false @api.delete("/cookbooks/obsolete-cookbook/1.0.0", 200) { cb100_deleted = true; "[\"true\"]" } @@ -83,8 +83,8 @@ describe Chef::Knife::CookbookDelete do @knife.config[:purge] = true stdin, stdout = StringIO.new("y\ny\n"), StringIO.new - @knife.ui.stub!(:stdin).and_return(stdin) - @knife.ui.stub!(:stdout).and_return(stdout) + @knife.ui.stub(:stdin).and_return(stdin) + @knife.ui.stub(:stdout).and_return(stdout) cb100_deleted = false @api.delete("/cookbooks/obsolete-cookbook/1.0.0?purge=true", 200) { cb100_deleted = true; "[\"true\"]" } @@ -126,8 +126,8 @@ describe Chef::Knife::CookbookDelete do cb100_deleted = cb110_deleted = cb120_deleted = nil @api.delete("/cookbooks/obsolete-cookbook/1.0.0", 200) { cb100_deleted = true; "[\"true\"]" } stdin, stdout = StringIO.new, StringIO.new - @knife.ui.stub!(:stdin).and_return(stdin) - @knife.ui.stub!(:stdout).and_return(stdout) + @knife.ui.stub(:stdin).and_return(stdin) + @knife.ui.stub(:stdout).and_return(stdout) stdin << "1\n" stdin.rewind @knife.run @@ -142,8 +142,8 @@ describe Chef::Knife::CookbookDelete do @api.delete("/cookbooks/obsolete-cookbook/1.2.0", 200) { cb120_deleted = true; "[\"true\"]" } stdin, stdout = StringIO.new("4\n"), StringIO.new - @knife.ui.stub!(:stdin).and_return(stdin) - @knife.ui.stub!(:stdout).and_return(stdout) + @knife.ui.stub(:stdin).and_return(stdin) + @knife.ui.stub(:stdout).and_return(stdout) @knife.run diff --git a/spec/functional/knife/ssh_spec.rb b/spec/functional/knife/ssh_spec.rb index fd8cfe0f7e..40d71859c7 100644 --- a/spec/functional/knife/ssh_spec.rb +++ b/spec/functional/knife/ssh_spec.rb @@ -252,7 +252,7 @@ describe Chef::Knife::Ssh do # if available, but #merge_configs (which is called by #configure_chef) is # necessary to have default options merged in. @knife.merge_configs - @knife.stub!(:ssh_command).and_return { 0 } + @knife.stub(:ssh_command).and_return { 0 } @api = TinyServer::API.instance @api.clear diff --git a/spec/functional/resource/link_spec.rb b/spec/functional/resource/link_spec.rb index 36bc858a74..9dc0afca06 100644 --- a/spec/functional/resource/link_spec.rb +++ b/spec/functional/resource/link_spec.rb @@ -132,7 +132,7 @@ describe Chef::Resource::Link do describe 'the :delete action' do before(:each) do @info = [] - Chef::Log.stub!(:info) { |msg| @info << msg } + Chef::Log.stub(:info) { |msg| @info << msg } resource.run_action(:delete) end @@ -153,7 +153,7 @@ describe Chef::Resource::Link do describe 'the :delete action' do before(:each) do @info = [] - Chef::Log.stub!(:info) { |msg| @info << msg } + Chef::Log.stub(:info) { |msg| @info << msg } resource.run_action(:delete) end @@ -174,7 +174,7 @@ describe Chef::Resource::Link do describe 'the :create action' do before(:each) do @info = [] - Chef::Log.stub!(:info) { |msg| @info << msg } + Chef::Log.stub(:info) { |msg| @info << msg } resource.run_action(:create) end @@ -195,7 +195,7 @@ describe Chef::Resource::Link do describe 'the :create action' do before(:each) do @info = [] - Chef::Log.stub!(:info) { |msg| @info << msg } + Chef::Log.stub(:info) { |msg| @info << msg } resource.run_action(:create) end @@ -216,7 +216,7 @@ describe Chef::Resource::Link do describe 'the :create action' do before(:each) do @info = [] - Chef::Log.stub!(:info) { |msg| @info << msg } + Chef::Log.stub(:info) { |msg| @info << msg } resource.run_action(:create) end it 'preserves the hard link' do @@ -241,7 +241,7 @@ describe Chef::Resource::Link do describe 'the :create action' do before(:each) do @info = [] - Chef::Log.stub!(:info) { |msg| @info << msg } + Chef::Log.stub(:info) { |msg| @info << msg } resource.run_action(:create) end it 'links to the target file' do diff --git a/spec/functional/resource/registry_spec.rb b/spec/functional/resource/registry_spec.rb index 8f3cfa9a8a..455c31c283 100644 --- a/spec/functional/resource/registry_spec.rb +++ b/spec/functional/resource/registry_spec.rb @@ -111,10 +111,10 @@ describe Chef::Resource::RegistryKey, :windows_only do before do @node.name("windowsbox") - @rest_client = mock("Chef::REST (mock)") - @rest_client.stub!(:create_url).and_return("reports/nodes/windowsbox/runs/#{@run_id}"); - @rest_client.stub!(:raw_http_request).and_return({"result"=>"ok"}); - @rest_client.stub!(:post_rest).and_return({"uri"=>"https://example.com/reports/nodes/windowsbox/runs/#{@run_id}"}); + @rest_client = double("Chef::REST (mock)") + @rest_client.stub(:create_url).and_return("reports/nodes/windowsbox/runs/#{@run_id}"); + @rest_client.stub(:raw_http_request).and_return({"result"=>"ok"}); + @rest_client.stub(:post_rest).and_return({"uri"=>"https://example.com/reports/nodes/windowsbox/runs/#{@run_id}"}); @resource_reporter = Chef::ResourceReporter.new(@rest_client) @events.register(@resource_reporter) @@ -124,8 +124,8 @@ describe Chef::Resource::RegistryKey, :windows_only do @resource_reporter.run_started(@run_status) @new_resource.cookbook_name = "monkey" - @cookbook_version = mock("Cookbook::Version", :version => "1.2.3") - @new_resource.stub!(:cookbook_version).and_return(@cookbook_version) + @cookbook_version = double("Cookbook::Version", :version => "1.2.3") + @new_resource.stub(:cookbook_version).and_return(@cookbook_version) end after (:all) do @@ -547,7 +547,7 @@ describe Chef::Resource::RegistryKey, :windows_only do @new_resource.values([{:name=>"BriskWalk",:type=>:string,:data=>"is good for health"}]) @new_resource.recursive(false) @new_resource.run_action(:delete_key) - @new_resource.should_not raise_error(ArgumentError) + @new_resource.should_not raise_error end it "does nothing if the action is delete_key" do @new_resource.key(reg_parent + '\OpscodeWhyRun') diff --git a/spec/functional/run_lock_spec.rb b/spec/functional/run_lock_spec.rb index 51645c0ae3..3fe77ff7ff 100644 --- a/spec/functional/run_lock_spec.rb +++ b/spec/functional/run_lock_spec.rb @@ -163,7 +163,7 @@ describe Chef::RunLock do let!(:run_lock) { Chef::RunLock.new(lockfile) } it "creates the full path to the lockfile" do - lambda { run_lock.acquire }.should_not raise_error(Errno::ENOENT) + lambda { run_lock.acquire }.should_not raise_error File.should exist(lockfile) end diff --git a/spec/integration/knife/download_spec.rb b/spec/integration/knife/download_spec.rb index ce8df38bd8..f266b47b1b 100644 --- a/spec/integration/knife/download_spec.rb +++ b/spec/integration/knife/download_spec.rb @@ -973,7 +973,7 @@ EOM cookbook 'x', '1.0.0', { 'metadata.rb' => 'version "1.0.0"' } when_the_repository 'is empty' do - it 'knife download /cookbooks/x signs all requests' do + it 'knife download /cookbooks/x signs all requests', :ruby_gte_19_only do # Check that BasicClient.request() always gets called with X-OPS-USERID original_new = Chef::HTTP::BasicClient.method(:new) diff --git a/spec/integration/solo/solo_spec.rb b/spec/integration/solo/solo_spec.rb index 94d279c726..cd4678f94d 100644 --- a/spec/integration/solo/solo_spec.rb +++ b/spec/integration/solo/solo_spec.rb @@ -79,7 +79,7 @@ EOM Process.waitpid(s1) Process.waitpid(s2) end - }.should_not raise_error(Timeout::Error) + }.should_not raise_error # Unfortunately file / directory helpers in integration tests # are implemented using before(:each) so we need to do all below diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index 9114c35eaf..5098a1fb85 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -86,7 +86,6 @@ Dir["spec/support/**/*.rb"]. map { |f| f.gsub(%r[spec/], '')}. each { |f| require f } - OHAI_SYSTEM = Ohai::System.new OHAI_SYSTEM.require_plugin("os") OHAI_SYSTEM.require_plugin("platform") diff --git a/spec/support/mock/platform.rb b/spec/support/mock/platform.rb index 78b704ea9b..df90d1eda2 100644 --- a/spec/support/mock/platform.rb +++ b/spec/support/mock/platform.rb @@ -6,7 +6,7 @@ # testing code that mixes in platform specific modules like +Chef::Mixin::Securable+ # or +Chef::FileAccessControl+ def platform_mock(platform = :unix, &block) - Chef::Platform.stub!(:windows?).and_return(platform == :windows ? true : false) + Chef::Platform.stub(:windows?).and_return(platform == :windows ? true : false) ENV['SYSTEMDRIVE'] = (platform == :windows ? 'C:' : nil) if block_given? mock_constants({"RUBY_PLATFORM" => (platform == :windows ? 'i386-mingw32' : 'x86_64-darwin11.2.0'), diff --git a/spec/support/shared/functional/securable_resource.rb b/spec/support/shared/functional/securable_resource.rb index 3952b783dc..48daf78ae3 100644 --- a/spec/support/shared/functional/securable_resource.rb +++ b/spec/support/shared/functional/securable_resource.rb @@ -482,7 +482,7 @@ shared_examples_for "a securable resource without existing target" do it 'warns when mode tries to set owner bits but owner is not specified' do @warn = [] - Chef::Log.stub!(:warn) { |msg| @warn << msg } + Chef::Log.stub(:warn) { |msg| @warn << msg } resource.mode 0400 resource.run_action(:create) @@ -492,7 +492,7 @@ shared_examples_for "a securable resource without existing target" do it 'warns when mode tries to set group bits but group is not specified' do @warn = [] - Chef::Log.stub!(:warn) { |msg| @warn << msg } + Chef::Log.stub(:warn) { |msg| @warn << msg } resource.mode 0040 resource.run_action(:create) diff --git a/spec/support/shared/unit/api_error_inspector.rb b/spec/support/shared/unit/api_error_inspector.rb index 8231ceb195..b59fbce2c7 100644 --- a/spec/support/shared/unit/api_error_inspector.rb +++ b/spec/support/shared/unit/api_error_inspector.rb @@ -72,7 +72,7 @@ shared_examples_for "an api error inspector" do before do @response_body = "synchronize the clock on your host" @response = Net::HTTPUnauthorized.new("1.1", "401", "(response) unauthorized") - @response.stub!(:body).and_return(@response_body) + @response.stub(:body).and_return(@response_body) @exception = Net::HTTPServerException.new("(exception) unauthorized", @response) @inspector = described_class.new(@node_name, @exception, @config) @inspector.add_explanation(@description) @@ -88,7 +88,7 @@ shared_examples_for "an api error inspector" do before do @response_body = "check your key and node name" @response = Net::HTTPUnauthorized.new("1.1", "401", "(response) unauthorized") - @response.stub!(:body).and_return(@response_body) + @response.stub(:body).and_return(@response_body) @exception = Net::HTTPServerException.new("(exception) unauthorized", @response) @inspector = described_class.new(@node_name, @exception, @config) @inspector.add_explanation(@description) @@ -104,7 +104,7 @@ shared_examples_for "an api error inspector" do before do @response_body = "forbidden" @response = Net::HTTPForbidden.new("1.1", "403", "(response) forbidden") - @response.stub!(:body).and_return(@response_body) + @response.stub(:body).and_return(@response_body) @exception = Net::HTTPServerException.new("(exception) forbidden", @response) @inspector = described_class.new(@node_name, @exception, @config) @inspector.add_explanation(@description) @@ -120,7 +120,7 @@ shared_examples_for "an api error inspector" do before do @response_body = "didn't like your data" @response = Net::HTTPBadRequest.new("1.1", "400", "(response) bad request") - @response.stub!(:body).and_return(@response_body) + @response.stub(:body).and_return(@response_body) @exception = Net::HTTPServerException.new("(exception) bad request", @response) @inspector = described_class.new(@node_name, @exception, @config) @inspector.add_explanation(@description) @@ -136,7 +136,7 @@ shared_examples_for "an api error inspector" do before do @response_body = "probably caused by a redirect to a get" @response = Net::HTTPNotFound.new("1.1", "404", "(response) not found") - @response.stub!(:body).and_return(@response_body) + @response.stub(:body).and_return(@response_body) @exception = Net::HTTPServerException.new("(exception) not found", @response) @inspector = described_class.new(@node_name, @exception, @config) @inspector.add_explanation(@description) @@ -151,7 +151,7 @@ shared_examples_for "an api error inspector" do before do @response_body = "sad trombone" @response = Net::HTTPInternalServerError.new("1.1", "500", "(response) internal server error") - @response.stub!(:body).and_return(@response_body) + @response.stub(:body).and_return(@response_body) @exception = Net::HTTPFatalError.new("(exception) internal server error", @response) @inspector = described_class.new(@node_name, @exception, @config) @inspector.add_explanation(@description) @@ -166,7 +166,7 @@ shared_examples_for "an api error inspector" do before do @response_body = "sad trombone orchestra" @response = Net::HTTPBadGateway.new("1.1", "502", "(response) bad gateway") - @response.stub!(:body).and_return(@response_body) + @response.stub(:body).and_return(@response_body) @exception = Net::HTTPFatalError.new("(exception) bad gateway", @response) @inspector = described_class.new(@node_name, @exception, @config) @inspector.add_explanation(@description) diff --git a/spec/support/shared/unit/provider/file.rb b/spec/support/shared/unit/provider/file.rb index 72dda3c07a..c3d678816a 100644 --- a/spec/support/shared/unit/provider/file.rb +++ b/spec/support/shared/unit/provider/file.rb @@ -108,6 +108,16 @@ end shared_examples_for Chef::Provider::File do + let!(:tempfile) do + Tempfile.new("rspec-shared-file-provider") + end + + before(:each) do + content.stub(:tempfile).and_return(tempfile) + File.stub(:exist?).with(tempfile.path).and_call_original + File.stub(:exists?).with(tempfile.path).and_call_original + end + it "should return a #{described_class}" do provider.should be_a_kind_of(described_class) end @@ -220,11 +230,11 @@ shared_examples_for Chef::Provider::File do Chef::Platform.stub(:windows?).and_return(false) # mock up the filesystem to behave like unix setup_normal_file - stat_struct = mock("::File.stat", :mode => 0600, :uid => 0, :gid => 0, :mtime => 10000) + stat_struct = double("::File.stat", :mode => 0600, :uid => 0, :gid => 0, :mtime => 10000) resource_real_path = File.realpath(resource.path) File.should_receive(:stat).with(resource_real_path).at_least(:once).and_return(stat_struct) - Etc.stub(:getgrgid).with(0).and_return(mock("Group Ent", :name => "wheel")) - Etc.stub(:getpwuid).with(0).and_return(mock("User Ent", :name => "root")) + Etc.stub(:getgrgid).with(0).and_return(double("Group Ent", :name => "wheel")) + Etc.stub(:getpwuid).with(0).and_return(double("User Ent", :name => "root")) end context "when the new_resource does not specify any state" do @@ -345,11 +355,11 @@ shared_examples_for Chef::Provider::File do Chef::Platform.stub(:windows?).and_return(false) # mock up the filesystem to behave like unix setup_normal_file - stat_struct = mock("::File.stat", :mode => 0600, :uid => 0, :gid => 0, :mtime => 10000) + stat_struct = double("::File.stat", :mode => 0600, :uid => 0, :gid => 0, :mtime => 10000) resource_real_path = File.realpath(resource.path) File.stub(:stat).with(resource_real_path).and_return(stat_struct) - Etc.stub(:getgrgid).with(0).and_return(mock("Group Ent", :name => "wheel")) - Etc.stub(:getpwuid).with(0).and_return(mock("User Ent", :name => "root")) + Etc.stub(:getgrgid).with(0).and_return(double("Group Ent", :name => "wheel")) + Etc.stub(:getpwuid).with(0).and_return(double("User Ent", :name => "root")) provider.send(:load_resource_attributes_from_file, resource) end @@ -386,7 +396,7 @@ shared_examples_for Chef::Provider::File do it "does not raise an exception in why-run mode" do Chef::Config[:why_run] = true - lambda {provider.run_action(action)}.should_not raise_error(Chef::Exceptions::EnclosingDirectoryDoesNotExist) + lambda {provider.run_action(action)}.should_not raise_error Chef::Config[:why_run] = false end end @@ -635,7 +645,7 @@ shared_examples_for Chef::Provider::File do it "should not try to backup or delete the file, and should not be updated by last action" do provider.should_not_receive(:do_backup) File.should_not_receive(:delete) - lambda { provider.run_action(:delete) }.should_not raise_error() + lambda { provider.run_action(:delete) }.should_not raise_error resource.should_not be_updated_by_last_action end end diff --git a/spec/support/shared/unit/provider/useradd_based_user_provider.rb b/spec/support/shared/unit/provider/useradd_based_user_provider.rb index e9fe06dfd7..a95d19d33c 100644 --- a/spec/support/shared/unit/provider/useradd_based_user_provider.rb +++ b/spec/support/shared/unit/provider/useradd_based_user_provider.rb @@ -57,21 +57,21 @@ shared_examples_for "a useradd-based user provider" do |supported_useradd_option end it "should set the option for #{attribute} if the new resources #{attribute} is not nil" do - @new_resource.stub!(attribute).and_return("hola") + @new_resource.stub(attribute).and_return("hola") provider.universal_options.should eql([option, 'hola']) end it "should set the option for #{attribute} if the new resources #{attribute} is not nil, without homedir management" do - @new_resource.stub!(:supports).and_return({:manage_home => false, + @new_resource.stub(:supports).and_return({:manage_home => false, :non_unique => false}) - @new_resource.stub!(attribute).and_return("hola") + @new_resource.stub(attribute).and_return("hola") provider.universal_options.should eql([option, 'hola']) end it "should set the option for #{attribute} if the new resources #{attribute} is not nil, without homedir management (using real attributes)" do - @new_resource.stub!(:manage_home).and_return(false) - @new_resource.stub!(:non_unique).and_return(false) - @new_resource.stub!(attribute).and_return("hola") + @new_resource.stub(:manage_home).and_return(false) + @new_resource.stub(:non_unique).and_return(false) + @new_resource.stub(attribute).and_return("hola") provider.universal_options.should eql([option, 'hola']) end end @@ -79,7 +79,7 @@ shared_examples_for "a useradd-based user provider" do |supported_useradd_option it "should combine all the possible options" do combined_opts = [] supported_useradd_options.sort{ |a,b| a[0] <=> b[0] }.each do |attribute, option| - @new_resource.stub!(attribute).and_return("hola") + @new_resource.stub(attribute).and_return("hola") combined_opts << option << 'hola' end provider.universal_options.should eql(combined_opts) @@ -99,8 +99,8 @@ shared_examples_for "a useradd-based user provider" do |supported_useradd_option describe "when the resource has a different home directory and supports home directory management" do before do - @new_resource.stub!(:home).and_return("/wowaweea") - @new_resource.stub!(:supports).and_return({:manage_home => true, + @new_resource.stub(:home).and_return("/wowaweea") + @new_resource.stub(:supports).and_return({:manage_home => true, :non_unique => false}) end @@ -112,9 +112,9 @@ shared_examples_for "a useradd-based user provider" do |supported_useradd_option describe "when the resource has a different home directory and supports home directory management (using real attributes)" do before do - @new_resource.stub!(:home).and_return("/wowaweea") - @new_resource.stub!(:manage_home).and_return(true) - @new_resource.stub!(:non_unique).and_return(false) + @new_resource.stub(:home).and_return("/wowaweea") + @new_resource.stub(:manage_home).and_return(true) + @new_resource.stub(:non_unique).and_return(false) end it "should set -m -d /homedir" do @@ -125,7 +125,7 @@ shared_examples_for "a useradd-based user provider" do |supported_useradd_option describe "when the resource supports non_unique ids" do before do - @new_resource.stub!(:supports).and_return({:manage_home => false, + @new_resource.stub(:supports).and_return({:manage_home => false, :non_unique => true}) end @@ -136,8 +136,8 @@ shared_examples_for "a useradd-based user provider" do |supported_useradd_option describe "when the resource supports non_unique ids (using real attributes)" do before do - @new_resource.stub!(:manage_home).and_return(false) - @new_resource.stub!(:non_unique).and_return(true) + @new_resource.stub(:manage_home).and_return(false) + @new_resource.stub(:non_unique).and_return(true) end it "should set -m -o" do @@ -260,12 +260,12 @@ shared_examples_for "a useradd-based user provider" do |supported_useradd_option describe "when checking the lock" do # lazy initialize so we can modify stdout and stderr strings let(:passwd_s_status) do - mock("Mixlib::ShellOut command", :exitstatus => 0, :stdout => @stdout, :stderr => @stderr) + double("Mixlib::ShellOut command", :exitstatus => 0, :stdout => @stdout, :stderr => @stderr) end before(:each) do # @node = Chef::Node.new - # @new_resource = mock("Chef::Resource::User", + # @new_resource = double("Chef::Resource::User", # :nil_object => true, # :username => "adam" # ) @@ -313,9 +313,9 @@ shared_examples_for "a useradd-based user provider" do |supported_useradd_option provider.should_receive(:shell_out!). with("passwd", "-S", @new_resource.username, {:returns=>[0, 1]}). and_return(passwd_s_status) - rpm_status = mock("Mixlib::ShellOut command", :exitstatus => 0, :stdout => "passwd-0.73-1\n", :stderr => "") + rpm_status = double("Mixlib::ShellOut command", :exitstatus => 0, :stdout => "passwd-0.73-1\n", :stderr => "") provider.should_receive(:shell_out!).with("rpm -q passwd").and_return(rpm_status) - lambda { provider.check_lock }.should_not raise_error(Chef::Exceptions::User) + lambda { provider.check_lock }.should_not raise_error end it "should raise a Chef::Exceptions::User if passwd -S exits with 1 on #{os} and the passwd package is not version 0.73-1" do @@ -324,7 +324,7 @@ shared_examples_for "a useradd-based user provider" do |supported_useradd_option provider.should_receive(:shell_out!). with("passwd", "-S", @new_resource.username, {:returns=>[0, 1]}). and_return(passwd_s_status) - rpm_status = mock("Mixlib::ShellOut command", :exitstatus => 0, :stdout => "passwd-0.73-2\n", :stderr => "") + rpm_status = double("Mixlib::ShellOut command", :exitstatus => 0, :stdout => "passwd-0.73-2\n", :stderr => "") provider.should_receive(:shell_out!).with("rpm -q passwd").and_return(rpm_status) lambda { provider.check_lock }.should raise_error(Chef::Exceptions::User) end @@ -338,7 +338,7 @@ shared_examples_for "a useradd-based user provider" do |supported_useradd_option context "when in why run mode" do before do - passwd_status = mock("Mixlib::ShellOut command", :exitstatus => 0, :stdout => "", :stderr => "passwd: user 'chef-test' does not exist\n") + passwd_status = double("Mixlib::ShellOut command", :exitstatus => 0, :stdout => "", :stderr => "passwd: user 'chef-test' does not exist\n") provider.should_receive(:shell_out!). with("passwd", "-S", @new_resource.username, {:returns=>[0, 1]}). and_return(passwd_status) @@ -398,9 +398,9 @@ shared_examples_for "a useradd-based user provider" do |supported_useradd_option ].each do |home_check| it home_check["action"] do provider.current_resource.home home_check["current_resource_home"].first - @current_home_mock = mock("Pathname") + @current_home_mock = double("Pathname") provider.new_resource.home home_check["new_resource_home"].first - @new_home_mock = mock("Pathname") + @new_home_mock = double("Pathname") Pathname.should_receive(:new).with(@current_resource.home).and_return(@current_home_mock) @current_home_mock.should_receive(:cleanpath).and_return(home_check["current_resource_home"].last) diff --git a/spec/unit/api_client/registration_spec.rb b/spec/unit/api_client/registration_spec.rb index 0d21730664..845c217f72 100644 --- a/spec/unit/api_client/registration_spec.rb +++ b/spec/unit/api_client/registration_spec.rb @@ -50,10 +50,10 @@ describe Chef::ApiClient::Registration do end describe "when creating/updating the client on the server" do - let(:http_mock) { mock("Chef::REST mock") } + let(:http_mock) { double("Chef::REST mock") } before do - registration.stub!(:http_api).and_return(http_mock) + registration.stub(:http_api).and_return(http_mock) end it "creates a new ApiClient on the server using the validator identity" do @@ -103,7 +103,7 @@ describe Chef::ApiClient::Registration do describe "when writing the private key to disk" do before do - registration.stub!(:private_key).and_return('--begin rsa key etc--') + registration.stub(:private_key).and_return('--begin rsa key etc--') end # Permission read via File.stat is busted on windows, though creating the @@ -125,10 +125,10 @@ describe Chef::ApiClient::Registration do describe "when registering a client" do - let(:http_mock) { mock("Chef::REST mock") } + let(:http_mock) { double("Chef::REST mock") } before do - registration.stub!(:http_api).and_return(http_mock) + registration.stub(:http_api).and_return(http_mock) end it "creates the client on the server and writes the key" do diff --git a/spec/unit/api_client_spec.rb b/spec/unit/api_client_spec.rb index 0df863cb78..4ccd64bafe 100644 --- a/spec/unit/api_client_spec.rb +++ b/spec/unit/api_client_spec.rb @@ -189,8 +189,8 @@ describe Chef::ApiClient do describe "when requesting a new key" do before do - @http_client = mock("Chef::REST mock") - Chef::REST.stub!(:new).and_return(@http_client) + @http_client = double("Chef::REST mock") + Chef::REST.stub(:new).and_return(@http_client) end context "and the client does not exist on the server" do diff --git a/spec/unit/application/apply.rb b/spec/unit/application/apply.rb index 0dc24544b0..32c98c6ed6 100644 --- a/spec/unit/application/apply.rb +++ b/spec/unit/application/apply.rb @@ -21,7 +21,7 @@ describe Chef::Application::Apply do before do @app = Chef::Application::Recipe.new - @app.stub!(:configure_logging).and_return(true) + @app.stub(:configure_logging).and_return(true) @recipe_text = "package 'nyancat'" Chef::Config[:solo] = true end @@ -36,10 +36,10 @@ describe Chef::Application::Apply do before do @recipe_file_name = "foo.rb" @recipe_path = File.expand_path("foo.rb") - @recipe_file = mock("Tempfile (mock)", :read => @recipe_text) - @app.stub!(:open).with(@recipe_path).and_return(@recipe_file) - File.stub!(:exist?).with("foo.rb").and_return(true) - Chef::Application.stub!(:fatal!).and_return(true) + @recipe_file = double("Tempfile (mock)", :read => @recipe_text) + @app.stub(:open).with(@recipe_path).and_return(@recipe_file) + File.stub(:exist?).with("foo.rb").and_return(true) + Chef::Application.stub(:fatal!).and_return(true) end it "should read text properly" do @app.read_recipe_file(@recipe_file_name)[0].should == @recipe_text @@ -49,7 +49,7 @@ describe Chef::Application::Apply do end describe "when recipe doesn't exist" do before do - File.stub!(:exist?).with(@recipe_file_name).and_return(false) + File.stub(:exist?).with(@recipe_file_name).and_return(false) end it "should raise a fatal" do Chef::Application.should_receive(:fatal!) diff --git a/spec/unit/application/client_spec.rb b/spec/unit/application/client_spec.rb index 219a894cc6..f84932073f 100644 --- a/spec/unit/application/client_spec.rb +++ b/spec/unit/application/client_spec.rb @@ -23,9 +23,9 @@ describe Chef::Application::Client, "reconfigure" do ARGV.clear @app = Chef::Application::Client.new - @app.stub!(:configure_opt_parser).and_return(true) - @app.stub!(:configure_chef).and_return(true) - @app.stub!(:configure_logging).and_return(true) + @app.stub(:configure_opt_parser).and_return(true) + @app.stub(:configure_chef).and_return(true) + @app.stub(:configure_logging).and_return(true) @app.cli_arguments = [] Chef::Config[:interval] = 10 @@ -91,9 +91,9 @@ describe Chef::Application::Client, "setup_application" do before do @app = Chef::Application::Client.new # this is all stuff the reconfigure method needs - @app.stub!(:configure_opt_parser).and_return(true) - @app.stub!(:configure_chef).and_return(true) - @app.stub!(:configure_logging).and_return(true) + @app.stub(:configure_opt_parser).and_return(true) + @app.stub(:configure_chef).and_return(true) + @app.stub(:configure_logging).and_return(true) end it "should change privileges" do diff --git a/spec/unit/application/knife_spec.rb b/spec/unit/application/knife_spec.rb index 16f94c7786..1baaad110d 100644 --- a/spec/unit/application/knife_spec.rb +++ b/spec/unit/application/knife_spec.rb @@ -35,8 +35,8 @@ describe Chef::Application::Knife do before(:each) do @knife = Chef::Application::Knife.new - @knife.stub!(:puts) - Chef::Knife.stub!(:list_commands) + @knife.stub(:puts) + Chef::Knife.stub(:list_commands) end it "should exit 1 and print the options if no arguments are given at all" do @@ -54,7 +54,7 @@ describe Chef::Application::Knife do it "should run a sub command with the applications command line option prototype" do with_argv(*%w{noop knife command with some args}) do - knife = mock(Chef::Knife) + knife = double(Chef::Knife) Chef::Knife.should_receive(:run).with(ARGV, @knife.options).and_return(knife) @knife.should_receive(:exit).with(0) @knife.run @@ -76,7 +76,7 @@ describe Chef::Application::Knife do describe "when given a path to the client key" do it "expands a relative path relative to the CWD" do relative_path = '.chef/client.pem' - Dir.stub!(:pwd).and_return(CHEF_SPEC_DATA) + Dir.stub(:pwd).and_return(CHEF_SPEC_DATA) with_argv(*%W{noop knife command -k #{relative_path}}) do @knife.should_receive(:exit).with(0) @knife.run @@ -158,7 +158,7 @@ describe Chef::Application::Knife do it "should run a sub command with the applications command line option prototype" do with_argv(*%w{noop knife command with some args}) do - knife = mock(Chef::Knife) + knife = double(Chef::Knife) Chef::Knife.should_receive(:run).with(ARGV, @knife.options).and_return(knife) @knife.should_receive(:exit).with(0) @knife.run diff --git a/spec/unit/application/solo_spec.rb b/spec/unit/application/solo_spec.rb index 41e0cf3b2b..d2f8b93169 100644 --- a/spec/unit/application/solo_spec.rb +++ b/spec/unit/application/solo_spec.rb @@ -20,9 +20,9 @@ require 'spec_helper' describe Chef::Application::Solo do before do @app = Chef::Application::Solo.new - @app.stub!(:configure_opt_parser).and_return(true) - @app.stub!(:configure_chef).and_return(true) - @app.stub!(:configure_logging).and_return(true) + @app.stub(:configure_opt_parser).and_return(true) + @app.stub(:configure_chef).and_return(true) + @app.stub(:configure_logging).and_return(true) Chef::Config[:recipe_url] = false Chef::Config[:json_attribs] = false Chef::Config[:solo] = true @@ -70,14 +70,14 @@ describe Chef::Application::Solo do before do Chef::Config[:cookbook_path] = "#{Dir.tmpdir}/chef-solo/cookbooks" Chef::Config[:recipe_url] = "http://junglist.gen.nz/recipes.tgz" - FileUtils.stub!(:mkdir_p).and_return(true) + FileUtils.stub(:mkdir_p).and_return(true) @tarfile = StringIO.new("remote_tarball_content") - @app.stub!(:open).with("http://junglist.gen.nz/recipes.tgz").and_yield(@tarfile) + @app.stub(:open).with("http://junglist.gen.nz/recipes.tgz").and_yield(@tarfile) @target_file = StringIO.new - File.stub!(:open).with("#{Dir.tmpdir}/chef-solo/recipes.tgz", "wb").and_yield(@target_file) + File.stub(:open).with("#{Dir.tmpdir}/chef-solo/recipes.tgz", "wb").and_yield(@target_file) - Chef::Mixin::Command.stub!(:run_command).and_return(true) + Chef::Mixin::Command.stub(:run_command).and_return(true) end it "should create the recipes path based on the parent of the cookbook path" do @@ -107,14 +107,14 @@ describe Chef::Application::Solo do before do Chef::Config[:solo] = true - Chef::Daemon.stub!(:change_privilege) - @chef_client = mock("Chef::Client") - Chef::Client.stub!(:new).and_return(@chef_client) + Chef::Daemon.stub(:change_privilege) + @chef_client = double("Chef::Client") + Chef::Client.stub(:new).and_return(@chef_client) @app = Chef::Application::Solo.new # this is all stuff the reconfigure method needs - @app.stub!(:configure_opt_parser).and_return(true) - @app.stub!(:configure_chef).and_return(true) - @app.stub!(:configure_logging).and_return(true) + @app.stub(:configure_opt_parser).and_return(true) + @app.stub(:configure_chef).and_return(true) + @app.stub(:configure_logging).and_return(true) end it "should change privileges" do diff --git a/spec/unit/application_spec.rb b/spec/unit/application_spec.rb index 426dbd5242..6110a8a3c5 100644 --- a/spec/unit/application_spec.rb +++ b/spec/unit/application_spec.rb @@ -24,8 +24,8 @@ describe Chef::Application do ARGV.clear Chef::Log.logger = Logger.new(StringIO.new) @app = Chef::Application.new - Dir.stub!(:chdir).and_return(0) - @app.stub!(:reconfigure) + Dir.stub(:chdir).and_return(0) + @app.stub(:reconfigure) Chef::Log.init(STDERR) end @@ -36,8 +36,8 @@ describe Chef::Application do describe "reconfigure" do before do @app = Chef::Application.new - @app.stub!(:configure_chef).and_return(true) - @app.stub!(:configure_logging).and_return(true) + @app.stub(:configure_chef).and_return(true) + @app.stub(:configure_logging).and_return(true) end it "should configure chef" do @@ -59,10 +59,10 @@ describe Chef::Application do describe "run" do before do - @app.stub!(:setup_application).and_return(true) - @app.stub!(:run_application).and_return(true) - @app.stub!(:configure_chef).and_return(true) - @app.stub!(:configure_logging).and_return(true) + @app.stub(:setup_application).and_return(true) + @app.stub(:run_application).and_return(true) + @app.stub(:configure_chef).and_return(true) + @app.stub(:configure_logging).and_return(true) end it "should reconfigure the application before running" do @@ -85,8 +85,8 @@ describe Chef::Application do describe "configure_chef" do before do @app = Chef::Application.new - #Chef::Config.stub!(:merge!).and_return(true) - @app.stub!(:parse_options).and_return(true) + #Chef::Config.stub(:merge!).and_return(true) + @app.stub(:parse_options).and_return(true) end it "should parse the commandline options" do @@ -152,12 +152,12 @@ describe Chef::Application do describe "when configuring the logger" do before do @app = Chef::Application.new - Chef::Log.stub!(:init) + Chef::Log.stub(:init) end it "should initialise the chef logger" do - Chef::Log.stub!(:level=) - @monologger = mock("Monologger") + Chef::Log.stub(:level=) + @monologger = double("Monologger") MonoLogger.should_receive(:new).with(Chef::Config[:log_location]).and_return(@monologger) Chef::Log.should_receive(:init).with(@monologger) @app.configure_logging @@ -173,7 +173,7 @@ describe Chef::Application do shared_examples_for "log_level_is_auto" do context "when STDOUT is to a tty" do before do - STDOUT.stub!(:tty?).and_return(true) + STDOUT.stub(:tty?).and_return(true) end it "configures the log level to :warn" do @@ -195,7 +195,7 @@ describe Chef::Application do context "when STDOUT is not to a tty" do before do - STDOUT.stub!(:tty?).and_return(false) + STDOUT.stub(:tty?).and_return(false) end it "configures the log level to :info" do @@ -230,9 +230,9 @@ describe Chef::Application do describe "class method: fatal!" do before do - STDERR.stub!(:puts).with("FATAL: blah").and_return(true) - Chef::Log.stub!(:fatal).with("blah").and_return(true) - Process.stub!(:exit).and_return(true) + STDERR.stub(:puts).with("FATAL: blah").and_return(true) + Chef::Log.stub(:fatal).and_return(true) + Process.stub(:exit).and_return(true) end it "should log an error message to the logger" do @@ -281,7 +281,7 @@ describe Chef::Application do @app.config[:config_file] = "/tmp/non-existing-dir/file" config_file_regexp = Regexp.new @app.config[:config_file] Chef::Log.should_receive(:warn).at_least(:once).with(config_file_regexp).and_return(true) - Chef::Log.should_receive(:warn).any_number_of_times.and_return(true) + Chef::Log.stub(:warn).and_return(true) @app.configure_chef end end diff --git a/spec/unit/checksum/storage/filesystem_spec.rb b/spec/unit/checksum/storage/filesystem_spec.rb index 144dc69ff1..755a64fe07 100644 --- a/spec/unit/checksum/storage/filesystem_spec.rb +++ b/spec/unit/checksum/storage/filesystem_spec.rb @@ -26,8 +26,8 @@ describe Chef::Checksum::Storage::Filesystem do @now = Time.now - Time.stub!(:now).and_return(@now) - Chef::Config.stub!(:checksum_path).and_return("/var/chef/checksums") + Time.stub(:now).and_return(@now) + Chef::Config.stub(:checksum_path).and_return("/var/chef/checksums") @checksum_of_the_file = "3fafecfb15585ede6b840158cbc2f399" @storage = Chef::Checksum::Storage::Filesystem.new("/not/used/path", @checksum_of_the_file) diff --git a/spec/unit/client_spec.rb b/spec/unit/client_spec.rb index f33f8d494c..6dc10c21b8 100644 --- a/spec/unit/client_spec.rb +++ b/spec/unit/client_spec.rb @@ -37,9 +37,9 @@ shared_examples_for Chef::Client do :platform => 'example-platform', :platform_version => 'example-platform-1.0', :data => {} } - ohai_data.stub!(:all_plugins).and_return(true) - ohai_data.stub!(:data).and_return(ohai_data) - Ohai::System.stub!(:new).and_return(ohai_data) + ohai_data.stub(:all_plugins).and_return(true) + ohai_data.stub(:data).and_return(ohai_data) + Ohai::System.stub(:new).and_return(ohai_data) @node = Chef::Node.new @node.name(@fqdn) @@ -81,7 +81,7 @@ shared_examples_for Chef::Client do context "and STDOUT is a TTY" do before do - STDOUT.stub!(:tty?).and_return(true) + STDOUT.stub(:tty?).and_return(true) end it "configures the :doc formatter" do @@ -104,7 +104,7 @@ shared_examples_for Chef::Client do context "and STDOUT is not a TTY" do before do - STDOUT.stub!(:tty?).and_return(false) + STDOUT.stub(:tty?).and_return(false) end it "configures the :null formatter" do @@ -168,10 +168,10 @@ shared_examples_for Chef::Client do describe "run" do it "should identify the node and run ohai, then register the client" do - mock_chef_rest_for_node = mock("Chef::REST (node)") - mock_chef_rest_for_cookbook_sync = mock("Chef::REST (cookbook sync)") - mock_chef_rest_for_node_save = mock("Chef::REST (node save)") - mock_chef_runner = mock("Chef::Runner") + mock_chef_rest_for_node = double("Chef::REST (node)") + mock_chef_rest_for_cookbook_sync = double("Chef::REST (cookbook sync)") + mock_chef_rest_for_node_save = double("Chef::REST (node save)") + mock_chef_runner = double("Chef::Runner") # --Client.register # Make sure Client#register thinks the client key doesn't @@ -253,15 +253,15 @@ shared_examples_for Chef::Client do end it "should remove the run_lock on failure of #load_node" do - @run_lock = mock("Chef::RunLock", :acquire => true) - Chef::RunLock.stub!(:new).and_return(@run_lock) + @run_lock = double("Chef::RunLock", :acquire => true) + Chef::RunLock.stub(:new).and_return(@run_lock) - @events = mock("Chef::EventDispatch::Dispatcher").as_null_object - Chef::EventDispatch::Dispatcher.stub!(:new).and_return(@events) + @events = double("Chef::EventDispatch::Dispatcher").as_null_object + Chef::EventDispatch::Dispatcher.stub(:new).and_return(@events) # @events is created on Chef::Client.new, so we need to recreate it after mocking @client = Chef::Client.new - @client.stub!(:load_node).and_raise(Exception) + @client.stub(:load_node).and_raise(Exception) @run_lock.should_receive(:release) if(Chef::Config[:client_fork] && !windows?) @client.should_receive(:fork) do |&block| @@ -274,8 +274,8 @@ shared_examples_for Chef::Client do describe "when notifying other objects of the status of the chef run" do before do Chef::Client.clear_notifications - Chef::Node.stub!(:find_or_create).and_return(@node) - @node.stub!(:save) + Chef::Node.stub(:find_or_create).and_return(@node) + @node.stub(:save) @client.load_node @client.build_node end @@ -324,7 +324,7 @@ shared_examples_for Chef::Client do # build_node will call Node#expand! with server, which will # eventually hit the server to expand the included role. - mock_chef_rest = mock("Chef::REST") + mock_chef_rest = double("Chef::REST") mock_chef_rest.should_receive(:get_rest).with("roles/role_containing_cookbook1").and_return(role_containing_cookbook1) Chef::REST.should_receive(:new).and_return(mock_chef_rest) @@ -332,7 +332,7 @@ shared_examples_for Chef::Client do @node[:roles].should be_nil @node[:recipes].should be_nil - @client.policy_builder.stub!(:node).and_return(@node) + @client.policy_builder.stub(:node).and_return(@node) # chefspec and possibly others use the return value of this method @client.build_node.should == @node @@ -385,7 +385,7 @@ shared_examples_for Chef::Client do context "fatal admin check is configured" do it "should not raise an exception" do - @client.do_windows_admin_check.should_not raise_error(Chef::Exceptions::WindowsNotAdmin) + @client.do_windows_admin_check.should_not raise_error end end end @@ -402,7 +402,7 @@ shared_examples_for Chef::Client do context "fatal admin check is configured" do it "should raise an exception" do - @client.do_windows_admin_check.should_not raise_error(Chef::Exceptions::WindowsNotAdmin) + @client.do_windows_admin_check.should_not raise_error end end end @@ -434,7 +434,7 @@ shared_examples_for Chef::Client do original_runlist = @node.run_list.dup - mock_chef_rest = mock("Chef::REST") + mock_chef_rest = double("Chef::REST") mock_chef_rest.should_receive(:get_rest).with("roles/test_role").and_return(override_role) Chef::REST.should_receive(:new).and_return(mock_chef_rest) diff --git a/spec/unit/config_spec.rb b/spec/unit/config_spec.rb index 2bf003bbdb..0f9bfce4aa 100644 --- a/spec/unit/config_spec.rb +++ b/spec/unit/config_spec.rb @@ -99,8 +99,8 @@ describe Chef::Config do describe "class method: manage_secret_key" do before do - Chef::FileCache.stub!(:load).and_return(true) - Chef::FileCache.stub!(:has_key?).with("chef_server_cookie_id").and_return(false) + Chef::FileCache.stub(:load).and_return(true) + Chef::FileCache.stub(:has_key?).with("chef_server_cookie_id").and_return(false) end it "should generate and store a chef server cookie id" do @@ -110,7 +110,7 @@ describe Chef::Config do describe "when the filecache has a chef server cookie id key" do before do - Chef::FileCache.stub!(:has_key?).with("chef_server_cookie_id").and_return(true) + Chef::FileCache.stub(:has_key?).with("chef_server_cookie_id").and_return(true) end it "should not generate and store a chef server cookie id" do @@ -132,7 +132,7 @@ describe Chef::Config do it "should return a windows path on windows systems" do platform_mock :windows do path = "/etc/chef/cookbooks" - ENV.stub!(:[]).with('SYSTEMDRIVE').and_return('C:') + ENV.stub(:[]).with('SYSTEMDRIVE').and_return('C:') # match on a regex that looks for the base path with an optional # system drive at the beginning (c:) # system drive is not hardcoded b/c it can change and b/c it is not present on linux systems diff --git a/spec/unit/cookbook/metadata_spec.rb b/spec/unit/cookbook/metadata_spec.rb index 9822146131..cba2aff5da 100644 --- a/spec/unit/cookbook/metadata_spec.rb +++ b/spec/unit/cookbook/metadata_spec.rb @@ -247,7 +247,7 @@ describe Chef::Cookbook::Metadata do it "should not accept anything but a string for display_name" do lambda { @meta.grouping("db/mysql/databases", :title => "foo") - }.should_not raise_error(ArgumentError) + }.should_not raise_error lambda { @meta.grouping("db/mysql/databases", :title => Hash.new) }.should raise_error(ArgumentError) @@ -256,7 +256,7 @@ describe Chef::Cookbook::Metadata do it "should not accept anything but a string for the description" do lambda { @meta.grouping("db/mysql/databases", :description => "foo") - }.should_not raise_error(ArgumentError) + }.should_not raise_error lambda { @meta.grouping("db/mysql/databases", :description => Hash.new) }.should raise_error(ArgumentError) @@ -281,7 +281,7 @@ describe Chef::Cookbook::Metadata do it "should not accept anything but a string for display_name" do lambda { @meta.attribute("db/mysql/databases", :display_name => "foo") - }.should_not raise_error(ArgumentError) + }.should_not raise_error lambda { @meta.attribute("db/mysql/databases", :display_name => Hash.new) }.should raise_error(ArgumentError) @@ -290,7 +290,7 @@ describe Chef::Cookbook::Metadata do it "should not accept anything but a string for the description" do lambda { @meta.attribute("db/mysql/databases", :description => "foo") - }.should_not raise_error(ArgumentError) + }.should_not raise_error lambda { @meta.attribute("db/mysql/databases", :description => Hash.new) }.should raise_error(ArgumentError) @@ -299,7 +299,7 @@ describe Chef::Cookbook::Metadata do it "should not accept anything but an array of strings for choice" do lambda { @meta.attribute("db/mysql/databases", :choice => ['dedicated', 'shared']) - }.should_not raise_error(ArgumentError) + }.should_not raise_error lambda { @meta.attribute("db/mysql/databases", :choice => [10, 'shared']) }.should raise_error(ArgumentError) @@ -316,10 +316,10 @@ describe Chef::Cookbook::Metadata do it "should let calculated be true or false" do lambda { @meta.attribute("db/mysql/databases", :calculated => true) - }.should_not raise_error(ArgumentError) + }.should_not raise_error lambda { @meta.attribute("db/mysql/databases", :calculated => false) - }.should_not raise_error(ArgumentError) + }.should_not raise_error lambda { @meta.attribute("db/mysql/databases", :calculated => Hash.new) }.should raise_error(ArgumentError) @@ -333,13 +333,13 @@ describe Chef::Cookbook::Metadata do it "accepts String for the attribute type" do lambda { @meta.attribute("db/mysql/databases", :type => "string") - }.should_not raise_error(ArgumentError) + }.should_not raise_error end it "accepts Array for the attribute type" do lambda { @meta.attribute("db/mysql/databases", :type => "array") - }.should_not raise_error(ArgumentError) + }.should_not raise_error lambda { @meta.attribute("db/mysql/databases", :type => Array.new) }.should raise_error(ArgumentError) @@ -348,38 +348,38 @@ describe Chef::Cookbook::Metadata do it "accepts symbol for the attribute type" do lambda { @meta.attribute("db/mysql/databases", :type => "symbol") - }.should_not raise_error(ArgumentError) + }.should_not raise_error end it "should let type be hash (backwards compatability only)" do lambda { @meta.attribute("db/mysql/databases", :type => "hash") - }.should_not raise_error(ArgumentError) + }.should_not raise_error end it "should let required be required, recommended or optional" do lambda { @meta.attribute("db/mysql/databases", :required => 'required') - }.should_not raise_error(ArgumentError) + }.should_not raise_error lambda { @meta.attribute("db/mysql/databases", :required => 'recommended') - }.should_not raise_error(ArgumentError) + }.should_not raise_error lambda { @meta.attribute("db/mysql/databases", :required => 'optional') - }.should_not raise_error(ArgumentError) + }.should_not raise_error end it "should convert required true to required" do lambda { @meta.attribute("db/mysql/databases", :required => true) - }.should_not raise_error(ArgumentError) + }.should_not raise_error #attrib = @meta.attributes["db/mysql/databases"][:required].should == "required" end it "should convert required false to optional" do lambda { @meta.attribute("db/mysql/databases", :required => false) - }.should_not raise_error(ArgumentError) + }.should_not raise_error #attrib = @meta.attributes["db/mysql/databases"][:required].should == "optional" end @@ -391,7 +391,7 @@ describe Chef::Cookbook::Metadata do it "should make sure recipes is an array" do lambda { @meta.attribute("db/mysql/databases", :recipes => []) - }.should_not raise_error(ArgumentError) + }.should_not raise_error lambda { @meta.attribute("db/mysql/databases", :required => Hash.new) }.should raise_error(ArgumentError) @@ -405,13 +405,13 @@ describe Chef::Cookbook::Metadata do it "should allow the default value to be a string, array, or hash" do lambda { @meta.attribute("db/mysql/databases", :default => []) - }.should_not raise_error(ArgumentError) + }.should_not raise_error lambda { @meta.attribute("db/mysql/databases", :default => {}) - }.should_not raise_error(ArgumentError) + }.should_not raise_error lambda { @meta.attribute("db/mysql/databases", :default => "alice in chains") - }.should_not raise_error(ArgumentError) + }.should_not raise_error lambda { @meta.attribute("db/mysql/databases", :required => :not_gonna_do_it) }.should raise_error(ArgumentError) @@ -441,14 +441,14 @@ describe Chef::Cookbook::Metadata do :default => "b" } @meta.attribute("db/mysql/databases", attrs) - }.should_not raise_error(ArgumentError) + }.should_not raise_error lambda { attrs = { :choice => [ "a", "b", "c", "d", "e"], :default => ["b", "d"] } @meta.attribute("db/mysql/databases", attrs) - }.should_not raise_error(ArgumentError) + }.should_not raise_error end it "should error if default is not a choice" do diff --git a/spec/unit/cookbook/synchronizer_spec.rb b/spec/unit/cookbook/synchronizer_spec.rb index 31f30c5bf4..c52593287a 100644 --- a/spec/unit/cookbook/synchronizer_spec.rb +++ b/spec/unit/cookbook/synchronizer_spec.rb @@ -14,7 +14,7 @@ describe Chef::CookbookCacheCleaner do end it "removes all files not validated during the chef run" do - file_cache = mock("Chef::FileCache with files from unused cookbooks") + file_cache = double("Chef::FileCache with files from unused cookbooks") unused_template_files = %w{cookbooks/unused/templates/default/foo.conf.erb cookbooks/unused/tempaltes/default/bar.conf.erb} valid_cached_cb_files = %w{cookbooks/valid1/recipes/default.rb cookbooks/valid2/recipes/default.rb} @cleaner.mark_file_as_valid('cookbooks/valid1/recipes/default.rb') @@ -23,7 +23,7 @@ describe Chef::CookbookCacheCleaner do file_cache.should_receive(:delete).with('cookbooks/unused/templates/default/foo.conf.erb') file_cache.should_receive(:delete).with('cookbooks/unused/tempaltes/default/bar.conf.erb') cookbook_hash = {"valid1"=> {}, "valid2" => {}} - @cleaner.stub!(:cache).and_return(file_cache) + @cleaner.stub(:cache).and_return(file_cache) @cleaner.cleanup_file_cache end @@ -37,7 +37,7 @@ describe Chef::CookbookCacheCleaner do end it "does not remove anything" do - @cleaner.cache.stub!(:find).and_return(%w{cookbooks/valid1/recipes/default.rb cookbooks/valid2/recipes/default.rb}) + @cleaner.cache.stub(:find).and_return(%w{cookbooks/valid1/recipes/default.rb cookbooks/valid2/recipes/default.rb}) @cleaner.cache.should_not_receive(:delete) @cleaner.cleanup_file_cache end @@ -81,7 +81,7 @@ describe Chef::CookbookSynchronizer do context "when the cache contains unneeded cookbooks" do before do - @file_cache = mock("Chef::FileCache with files from unused cookbooks") + @file_cache = double("Chef::FileCache with files from unused cookbooks") @valid_cached_cb_files = %w{cookbooks/valid1/recipes/default.rb cookbooks/valid2/recipes/default.rb} @obsolete_cb_files = %w{cookbooks/old1/recipes/default.rb cookbooks/old2/recipes/default.rb} @@ -94,7 +94,7 @@ describe Chef::CookbookSynchronizer do @file_cache.should_receive(:find).with(File.join(%w{cookbooks ** *})).and_return(@valid_cached_cb_files + @obsolete_cb_files) @file_cache.should_receive(:delete).with('cookbooks/old1/recipes/default.rb') @file_cache.should_receive(:delete).with('cookbooks/old2/recipes/default.rb') - @synchronizer.stub!(:cache).and_return(@file_cache) + @synchronizer.stub(:cache).and_return(@file_cache) @synchronizer.clear_obsoleted_cookbooks end end @@ -103,18 +103,18 @@ describe Chef::CookbookSynchronizer do before do # Would rather not stub out methods on the test subject, but setting up # the state is a PITA and tests for this behavior are above. - @synchronizer.stub!(:clear_obsoleted_cookbooks) + @synchronizer.stub(:clear_obsoleted_cookbooks) - @server_api = mock("Chef::REST (mock)") - @file_cache = mock("Chef::FileCache (mock)") - @synchronizer.stub!(:server_api).and_return(@server_api) - @synchronizer.stub!(:cache).and_return(@file_cache) + @server_api = double("Chef::REST (mock)") + @file_cache = double("Chef::FileCache (mock)") + @synchronizer.stub(:server_api).and_return(@server_api) + @synchronizer.stub(:cache).and_return(@file_cache) - @cookbook_a_default_recipe_tempfile = mock("Tempfile for cookbook_a default.rb recipe", + @cookbook_a_default_recipe_tempfile = double("Tempfile for cookbook_a default.rb recipe", :path => "/tmp/cookbook_a_recipes_default_rb") - @cookbook_a_default_attribute_tempfile = mock("Tempfile for cookbook_a default.rb attr file", + @cookbook_a_default_attribute_tempfile = double("Tempfile for cookbook_a default.rb attr file", :path => "/tmp/cookbook_a_attributes_default_rb") end @@ -167,13 +167,13 @@ describe Chef::CookbookSynchronizer do before do Chef::Config[:no_lazy_load] = true @synchronizer = Chef::CookbookSynchronizer.new(@cookbook_manifest, @events) - @synchronizer.stub!(:server_api).and_return(@server_api) - @synchronizer.stub!(:cache).and_return(@file_cache) - @synchronizer.stub!(:clear_obsoleted_cookbooks) + @synchronizer.stub(:server_api).and_return(@server_api) + @synchronizer.stub(:cache).and_return(@file_cache) + @synchronizer.stub(:clear_obsoleted_cookbooks) - @cookbook_a_file_default_tempfile = mock("Tempfile for cookbook_a megaman.conf file", + @cookbook_a_file_default_tempfile = double("Tempfile for cookbook_a megaman.conf file", :path => "/tmp/cookbook_a_file_default_tempfile") - @cookbook_a_template_default_tempfile = mock("Tempfile for cookbook_a apache.conf.erb template", + @cookbook_a_template_default_tempfile = double("Tempfile for cookbook_a apache.conf.erb template", :path => "/tmp/cookbook_a_template_default_tempfile") end diff --git a/spec/unit/daemon_spec.rb b/spec/unit/daemon_spec.rb index 8d66e08511..9132dae389 100644 --- a/spec/unit/daemon_spec.rb +++ b/spec/unit/daemon_spec.rb @@ -23,12 +23,12 @@ describe Chef::Daemon do if windows? mock_struct = #Struct::Passwd.new(nil, nil, 111, 111) mock_struct = OpenStruct.new(:uid => 2342, :gid => 2342) - Etc.stub!(:getpwnam).and_return mock_struct - Etc.stub!(:getgrnam).and_return mock_struct + Etc.stub(:getpwnam).and_return mock_struct + Etc.stub(:getgrnam).and_return mock_struct # mock unimplemented methods - Process.stub!(:initgroups).and_return nil - Process::GID.stub!(:change_privilege).and_return 11 - Process::UID.stub!(:change_privilege).and_return 11 + Process.stub(:initgroups).and_return nil + Process::GID.stub(:change_privilege).and_return 11 + Process::UID.stub(:change_privilege).and_return 11 end end @@ -73,13 +73,12 @@ describe Chef::Daemon do describe ".change_privilege" do before do - Chef::Application.stub!(:fatal!).and_return(true) + Chef::Application.stub(:fatal!).and_return(true) Chef::Config[:user] = 'aj' - Dir.stub!(:chdir) + Dir.stub(:chdir) end it "changes the working directory to root" do - Dir.rspec_reset Dir.should_receive(:chdir).with("/").and_return(0) Chef::Daemon.change_privilege end @@ -117,25 +116,25 @@ describe Chef::Daemon do describe "._change_privilege" do before do - Process.stub!(:euid).and_return(0) - Process.stub!(:egid).and_return(0) + Process.stub(:euid).and_return(0) + Process.stub(:egid).and_return(0) - Process::UID.stub!(:change_privilege).and_return(nil) - Process::GID.stub!(:change_privilege).and_return(nil) + Process::UID.stub(:change_privilege).and_return(nil) + Process::GID.stub(:change_privilege).and_return(nil) - @pw_user = mock("Struct::Passwd", :uid => 501) - @pw_group = mock("Struct::Group", :gid => 20) + @pw_user = double("Struct::Passwd", :uid => 501) + @pw_group = double("Struct::Group", :gid => 20) - Process.stub!(:initgroups).and_return(true) + Process.stub(:initgroups).and_return(true) - Etc.stub!(:getpwnam).and_return(@pw_user) - Etc.stub!(:getgrnam).and_return(@pw_group) + Etc.stub(:getpwnam).and_return(@pw_user) + Etc.stub(:getgrnam).and_return(@pw_group) end describe "with sufficient privileges" do before do - Process.stub!(:euid).and_return(0) - Process.stub!(:egid).and_return(0) + Process.stub(:euid).and_return(0) + Process.stub(:egid).and_return(0) end it "should initialize the supplemental group list" do @@ -156,12 +155,12 @@ describe Chef::Daemon do describe "with insufficient privileges" do before do - Process.stub!(:euid).and_return(999) - Process.stub!(:egid).and_return(999) + Process.stub(:euid).and_return(999) + Process.stub(:egid).and_return(999) end it "should log an appropriate error message and fail miserably" do - Process.stub!(:initgroups).and_raise(Errno::EPERM) + Process.stub(:initgroups).and_raise(Errno::EPERM) error = "Operation not permitted" if RUBY_PLATFORM.match("solaris2") || RUBY_PLATFORM.match("aix") error = "Not owner" diff --git a/spec/unit/data_bag_item_spec.rb b/spec/unit/data_bag_item_spec.rb index 4f017ebb60..ead0dadfa2 100644 --- a/spec/unit/data_bag_item_spec.rb +++ b/spec/unit/data_bag_item_spec.rb @@ -67,15 +67,15 @@ describe Chef::DataBagItem do end it "should accept alphanum/-/_ for the id" do - lambda { @data_bag_item.raw_data = { "id" => "h1-_" } }.should_not raise_error(ArgumentError) + lambda { @data_bag_item.raw_data = { "id" => "h1-_" } }.should_not raise_error end it "should accept alphanum.alphanum for the id" do - lambda { @data_bag_item.raw_data = { "id" => "foo.bar" } }.should_not raise_error(ArgumentError) + lambda { @data_bag_item.raw_data = { "id" => "foo.bar" } }.should_not raise_error end it "should accept .alphanum for the id" do - lambda { @data_bag_item.raw_data = { "id" => ".bozo" } }.should_not raise_error(ArgumentError) + lambda { @data_bag_item.raw_data = { "id" => ".bozo" } }.should_not raise_error end it "should raise an exception if the id contains anything but alphanum/-/_" do @@ -203,8 +203,8 @@ describe Chef::DataBagItem do describe "save" do before do - @rest = mock("Chef::REST") - Chef::REST.stub!(:new).and_return(@rest) + @rest = double("Chef::REST") + Chef::REST.stub(:new).and_return(@rest) @data_bag_item['id'] = "heart of darkness" raw_data = {"id" => "heart_of_darkness", "author" => "Conrad"} @data_bag_item.raw_data = raw_data @@ -216,7 +216,7 @@ describe Chef::DataBagItem do end it "should create if the item is not found" do - exception = mock("404 error", :code => "404") + exception = double("404 error", :code => "404") @rest.should_receive(:put_rest).and_raise(Net::HTTPServerException.new("foo", exception)) @rest.should_receive(:post_rest).with("data/books", @data_bag_item) @data_bag_item.save @@ -247,8 +247,8 @@ describe Chef::DataBagItem do describe "from an API call" do before do - @http_client = mock("Chef::REST") - Chef::REST.stub!(:new).and_return(@http_client) + @http_client = double("Chef::REST") + Chef::REST.stub(:new).and_return(@http_client) end it "converts raw data to a data bag item" do diff --git a/spec/unit/data_bag_spec.rb b/spec/unit/data_bag_spec.rb index 8c9465caf7..4ac843c869 100644 --- a/spec/unit/data_bag_spec.rb +++ b/spec/unit/data_bag_spec.rb @@ -78,12 +78,12 @@ describe Chef::DataBag do describe "when saving" do before do @data_bag.name('piggly_wiggly') - @rest = mock("Chef::REST") - Chef::REST.stub!(:new).and_return(@rest) + @rest = double("Chef::REST") + Chef::REST.stub(:new).and_return(@rest) end it "should silently proceed when the data bag already exists" do - exception = mock("409 error", :code => "409") + exception = double("409 error", :code => "409") @rest.should_receive(:post_rest).and_raise(Net::HTTPServerException.new("foo", exception)) @data_bag.save end @@ -111,7 +111,7 @@ describe Chef::DataBag do describe "from an API call" do before do Chef::Config[:chef_server_url] = 'https://myserver.example.com' - @http_client = mock('Chef::REST') + @http_client = double('Chef::REST') end it "should get the data bag from the server" do @@ -121,7 +121,7 @@ describe Chef::DataBag do end it "should return the data bag" do - Chef::REST.stub!(:new).and_return(@http_client) + Chef::REST.stub(:new).and_return(@http_client) @http_client.should_receive(:get_rest).with('data/foo').and_return({'bar' => 'https://myserver.example.com/data/foo/bar'}) data_bag = Chef::DataBag.load('foo') data_bag.should == {'bar' => 'https://myserver.example.com/data/foo/bar'} @@ -152,7 +152,7 @@ describe Chef::DataBag do it "should return the data bag" do File.should_receive(:directory?).with('/var/chef/data_bags').and_return(true) - Dir.stub!(:glob).and_return(["/var/chef/data_bags/foo/bar.json", "/var/chef/data_bags/foo/baz.json"]) + Dir.stub(:glob).and_return(["/var/chef/data_bags/foo/bar.json", "/var/chef/data_bags/foo/baz.json"]) IO.should_receive(:read).with('/var/chef/data_bags/foo/bar.json').and_return('{"id": "bar", "name": "Bob Bar" }') IO.should_receive(:read).with('/var/chef/data_bags/foo/baz.json').and_return('{"id": "baz", "name": "John Baz" }') data_bag = Chef::DataBag.load('foo') diff --git a/spec/unit/deprecation_spec.rb b/spec/unit/deprecation_spec.rb index 58db295067..8617cb3cb3 100644 --- a/spec/unit/deprecation_spec.rb +++ b/spec/unit/deprecation_spec.rb @@ -62,7 +62,7 @@ describe Chef::Deprecation do context 'deprecation warning messages' do before(:each) do @warning_output = [ ] - Chef::Log.stub!(:warn) { |msg| @warning_output << msg } + Chef::Log.stub(:warn) { |msg| @warning_output << msg } end it 'should be enabled for deprecated methods' do diff --git a/spec/unit/dsl/data_query_spec.rb b/spec/unit/dsl/data_query_spec.rb index 8960ad9957..e31c0725d6 100644 --- a/spec/unit/dsl/data_query_spec.rb +++ b/spec/unit/dsl/data_query_spec.rb @@ -27,7 +27,7 @@ describe Chef::DSL::DataQuery do before(:each) do @language = DataQueryDSLTester.new @node = Hash.new - @language.stub!(:node).and_return(@node) + @language.stub(:node).and_return(@node) end describe "when loading data bags and items" do diff --git a/spec/unit/environment_spec.rb b/spec/unit/environment_spec.rb index 5f9675a307..ebbcdd9861 100644 --- a/spec/unit/environment_spec.rb +++ b/spec/unit/environment_spec.rb @@ -355,16 +355,16 @@ describe Chef::Environment do describe "api model" do before(:each) do - @rest = mock("Chef::REST") - Chef::REST.stub!(:new).and_return(@rest) - @query = mock("Chef::Search::Query") - Chef::Search::Query.stub!(:new).and_return(@query) + @rest = double("Chef::REST") + Chef::REST.stub(:new).and_return(@rest) + @query = double("Chef::Search::Query") + Chef::Search::Query.stub(:new).and_return(@query) end describe "list" do describe "inflated" do it "should return a hash of environment names and objects" do - e1 = mock("Chef::Environment", :name => "one") + e1 = double("Chef::Environment", :name => "one") @query.should_receive(:search).with(:environment).and_yield(e1) r = Chef::Environment.list(true) r["one"].should == e1 diff --git a/spec/unit/file_access_control_spec.rb b/spec/unit/file_access_control_spec.rb index 609bd826b6..4e257c2a22 100644 --- a/spec/unit/file_access_control_spec.rb +++ b/spec/unit/file_access_control_spec.rb @@ -36,7 +36,7 @@ describe Chef::FileAccessControl do @run_context = Chef::RunContext.new(@node, {}, @events) @current_resource = Chef::Resource::File.new('/tmp/different_file.txt') @provider_requirements = Chef::Provider::ResourceRequirements.new(@resource, @run_context) - @provider = mock("File provider", :requirements => @provider_requirements, :manage_symlink_access? => false) + @provider = double("File provider", :requirements => @provider_requirements, :manage_symlink_access? => false) @fac = Chef::FileAccessControl.new(@current_resource, @resource, @provider) end @@ -217,7 +217,7 @@ describe Chef::FileAccessControl do @resource.group(2342) @current_resource.group(2342) - # @fac.stub!(:stat).and_return(OpenStruct.new(:gid => 2342)) + # @fac.stub(:stat).and_return(OpenStruct.new(:gid => 2342)) File.should_not_receive(:chown) @fac.set_group @fac.should_not be_modified @@ -267,7 +267,7 @@ describe Chef::FileAccessControl do it "sets the file's mode as specified in the resource when the current modes are incorrect" do # stat returns modes like 0100644 (octal) => 33188 (decimal) - #@fac.stub!(:stat).and_return(OpenStruct.new(:mode => 33188)) + #@fac.stub(:stat).and_return(OpenStruct.new(:mode => 33188)) @current_resource.mode("0644") File.should_receive(:chmod).with(256, '/tmp/different_file.txt') @fac.set_mode @@ -280,7 +280,7 @@ describe Chef::FileAccessControl do end it "does not set the file's mode when the current modes are correct" do - #@fac.stub!(:stat).and_return(OpenStruct.new(:mode => 0100400)) + #@fac.stub(:stat).and_return(OpenStruct.new(:mode => 0100400)) @current_resource.mode("0400") File.should_not_receive(:chmod) @fac.set_mode @@ -288,7 +288,7 @@ describe Chef::FileAccessControl do end it "sets all access controls on a file" do - @fac.stub!(:stat).and_return(OpenStruct.new(:owner => 99, :group => 99, :mode => 0100444)) + @fac.stub(:stat).and_return(OpenStruct.new(:owner => 99, :group => 99, :mode => 0100444)) @resource.mode(0400) @resource.owner(0) @resource.group(0) diff --git a/spec/unit/file_cache_spec.rb b/spec/unit/file_cache_spec.rb index 7680852cb9..f57f11dcc2 100644 --- a/spec/unit/file_cache_spec.rb +++ b/spec/unit/file_cache_spec.rb @@ -44,7 +44,7 @@ describe Chef::FileCache do describe "when storing a file" do before do - File.stub!(:open).and_yield(@io) + File.stub(:open).and_yield(@io) end it "should print the contents to the file" do diff --git a/spec/unit/file_content_management/deploy/mv_unix_spec.rb b/spec/unit/file_content_management/deploy/mv_unix_spec.rb index 2be0abe7bb..0e8662b8ec 100644 --- a/spec/unit/file_content_management/deploy/mv_unix_spec.rb +++ b/spec/unit/file_content_management/deploy/mv_unix_spec.rb @@ -37,7 +37,7 @@ describe Chef::FileContentManagement::Deploy::MvUnix do let(:target_file_mode) { 0644 } let(:target_file_stat) do - mock "File::Stat struct for target file", + double "File::Stat struct for target file", :mode => target_file_mode, :uid => target_file_uid, :gid => target_file_gid diff --git a/spec/unit/file_content_management/deploy/mv_windows_spec.rb b/spec/unit/file_content_management/deploy/mv_windows_spec.rb index 0a0b1f899a..7c2a2d7e71 100644 --- a/spec/unit/file_content_management/deploy/mv_windows_spec.rb +++ b/spec/unit/file_content_management/deploy/mv_windows_spec.rb @@ -51,11 +51,11 @@ describe Chef::FileContentManagement::Deploy::MvWindows do let(:staging_file_path) { "/tmp/random-dir/staging-file.tmp" } let(:target_file_security_object) do - mock "Securable Object for target file" + double "Securable Object for target file" end let(:updated_target_security_object) do - mock "Securable Object for target file after staging file deploy" + double "Securable Object for target file after staging file deploy" end before do @@ -79,17 +79,17 @@ describe Chef::FileContentManagement::Deploy::MvWindows do context "when run with administrator privileges" do - let(:original_target_file_owner) { mock("original target file owner") } - let(:original_target_file_group) { mock("original target file group") } + let(:original_target_file_owner) { double("original target file owner") } + let(:original_target_file_group) { double("original target file group") } let(:target_file_security_descriptor) do - mock "security descriptor for target file", + double "security descriptor for target file", :group => original_target_file_group, :owner => original_target_file_owner end let(:updated_target_security_descriptor) do - mock "security descriptor for target file" + double "security descriptor for target file" end @@ -116,17 +116,17 @@ describe Chef::FileContentManagement::Deploy::MvWindows do end context "and the target has a dacl and sacl" do - let(:inherited_dacl_ace) { mock("Windows dacl ace (inherited)", :inherited? => true) } - let(:not_inherited_dacl_ace) { mock("Windows dacl ace (not inherited)", :inherited? => false) } + let(:inherited_dacl_ace) { double("Windows dacl ace (inherited)", :inherited? => true) } + let(:not_inherited_dacl_ace) { double("Windows dacl ace (not inherited)", :inherited? => false) } let(:original_target_file_dacl) { [inherited_dacl_ace, not_inherited_dacl_ace] } - let(:inherited_sacl_ace) { mock("Windows sacl ace (inherited)", :inherited? => true) } - let(:not_inherited_sacl_ace) { mock("Windows sacl ace (not inherited)", :inherited? => false) } + let(:inherited_sacl_ace) { double("Windows sacl ace (inherited)", :inherited? => true) } + let(:not_inherited_sacl_ace) { double("Windows sacl ace (not inherited)", :inherited? => false) } let(:original_target_file_sacl) { [inherited_sacl_ace, not_inherited_sacl_ace] } - let(:custom_dacl) { mock("Windows ACL for non-inherited dacl aces") } - let(:custom_sacl) { mock("Windows ACL for non-inherited sacl aces") } + let(:custom_dacl) { double("Windows ACL for non-inherited dacl aces") } + let(:custom_sacl) { double("Windows ACL for non-inherited sacl aces") } before do target_file_security_descriptor.stub(:dacl_present?).and_return(true) diff --git a/spec/unit/formatters/error_inspectors/compile_error_inspector_spec.rb b/spec/unit/formatters/error_inspectors/compile_error_inspector_spec.rb index 0b20b0ef86..bea7eeed21 100644 --- a/spec/unit/formatters/error_inspectors/compile_error_inspector_spec.rb +++ b/spec/unit/formatters/error_inspectors/compile_error_inspector_spec.rb @@ -51,7 +51,7 @@ describe Chef::Formatters::ErrorInspectors::CompileErrorInspector do # Error inspector originally used file_cache_path which is incorrect on # chef-solo. Using cookbook_path should do the right thing for client and # solo. - Chef::Config.stub!(:cookbook_path).and_return([ "/home/someuser/dev-laptop/cookbooks" ]) + Chef::Config.stub(:cookbook_path).and_return([ "/home/someuser/dev-laptop/cookbooks" ]) @trace = [ "/home/someuser/dev-laptop/cookbooks/syntax-err/recipes/default.rb:14:in `from_file'", "/home/someuser/dev-laptop/cookbooks/syntax-err/recipes/default.rb:11:in `from_file'", @@ -71,7 +71,7 @@ describe Chef::Formatters::ErrorInspectors::CompileErrorInspector do describe "when explaining an error in the compile phase" do before do - Chef::Config.stub!(:cookbook_path).and_return([ "/var/chef/cache/cookbooks" ]) + Chef::Config.stub(:cookbook_path).and_return([ "/var/chef/cache/cookbooks" ]) recipe_lines = BAD_RECIPE.split("\n").map {|l| l << "\n" } IO.should_receive(:readlines).with("/var/chef/cache/cookbooks/syntax-err/recipes/default.rb").and_return(recipe_lines) @trace = [ @@ -96,7 +96,7 @@ describe Chef::Formatters::ErrorInspectors::CompileErrorInspector do describe "when explaining an error on windows" do before do - Chef::Config.stub!(:cookbook_path).and_return([ "C:/opscode/chef/var/cache/cookbooks" ]) + Chef::Config.stub(:cookbook_path).and_return([ "C:/opscode/chef/var/cache/cookbooks" ]) recipe_lines = BAD_RECIPE.split("\n").map {|l| l << "\n" } IO.should_receive(:readlines).at_least(1).times.with(/:\/opscode\/chef\/var\/cache\/cookbooks\/foo\/recipes\/default.rb/).and_return(recipe_lines) @trace = [ @@ -154,7 +154,7 @@ describe Chef::Formatters::ErrorInspectors::CompileErrorInspector do describe "when explaining an error on windows, and the backtrace lowercases the drive letter" do before do - Chef::Config.stub!(:cookbook_path).and_return([ "C:/opscode/chef/var/cache/cookbooks" ]) + Chef::Config.stub(:cookbook_path).and_return([ "C:/opscode/chef/var/cache/cookbooks" ]) recipe_lines = BAD_RECIPE.split("\n").map {|l| l << "\n" } IO.should_receive(:readlines).with("c:/opscode/chef/var/cache/cookbooks/foo/recipes/default.rb").and_return(recipe_lines) @trace = [ diff --git a/spec/unit/formatters/error_inspectors/cookbook_resolve_error_inspector_spec.rb b/spec/unit/formatters/error_inspectors/cookbook_resolve_error_inspector_spec.rb index 93129eadb8..c573dc016b 100644 --- a/spec/unit/formatters/error_inspectors/cookbook_resolve_error_inspector_spec.rb +++ b/spec/unit/formatters/error_inspectors/cookbook_resolve_error_inspector_spec.rb @@ -34,7 +34,7 @@ describe Chef::Formatters::ErrorInspectors::CookbookResolveErrorInspector do @response_body = %Q({"error": [{"message": "gtfo"}]) @response = Net::HTTPForbidden.new("1.1", "403", "(response) forbidden") - @response.stub!(:body).and_return(@response_body) + @response.stub(:body).and_return(@response_body) @exception = Net::HTTPServerException.new("(exception) forbidden", @response) @inspector = Chef::Formatters::ErrorInspectors::CookbookResolveErrorInspector.new(@expanded_run_list, @exception) @@ -55,7 +55,7 @@ describe Chef::Formatters::ErrorInspectors::CookbookResolveErrorInspector do @response_body = "{\"error\":[\"{\\\"non_existent_cookbooks\\\":[\\\"apache2\\\"],\\\"cookbooks_with_no_versions\\\":[\\\"users\\\"],\\\"message\\\":\\\"Run list contains invalid items: no such cookbook nope.\\\"}\"]}" @response = Net::HTTPPreconditionFailed.new("1.1", "412", "(response) unauthorized") - @response.stub!(:body).and_return(@response_body) + @response.stub(:body).and_return(@response_body) @exception = Net::HTTPServerException.new("(exception) precondition failed", @response) @inspector = Chef::Formatters::ErrorInspectors::CookbookResolveErrorInspector.new(@expanded_run_list, @exception) @@ -83,7 +83,7 @@ describe Chef::Formatters::ErrorInspectors::CookbookResolveErrorInspector do @response_body = "{\"error\":[{\"non_existent_cookbooks\":[],\"cookbooks_with_no_versions\":[],\"message\":\"unable to solve dependencies in alotted time.\"}]}" @response = Net::HTTPPreconditionFailed.new("1.1", "412", "(response) unauthorized") - @response.stub!(:body).and_return(@response_body) + @response.stub(:body).and_return(@response_body) @exception = Net::HTTPServerException.new("(exception) precondition failed", @response) @inspector = Chef::Formatters::ErrorInspectors::CookbookResolveErrorInspector.new(@expanded_run_list, @exception) @@ -106,7 +106,7 @@ describe Chef::Formatters::ErrorInspectors::CookbookResolveErrorInspector do @response_body = "{\"error\":[{\"non_existent_cookbooks\":[\"apache2\"],\"cookbooks_with_no_versions\":[\"users\"],\"message\":\"Run list contains invalid items: no such cookbook nope.\"}]}" @response = Net::HTTPPreconditionFailed.new("1.1", "412", "(response) unauthorized") - @response.stub!(:body).and_return(@response_body) + @response.stub(:body).and_return(@response_body) @exception = Net::HTTPServerException.new("(exception) precondition failed", @response) @inspector = Chef::Formatters::ErrorInspectors::CookbookResolveErrorInspector.new(@expanded_run_list, @exception) diff --git a/spec/unit/formatters/error_inspectors/cookbook_sync_error_inspector_spec.rb b/spec/unit/formatters/error_inspectors/cookbook_sync_error_inspector_spec.rb index eb8d302e5b..e586f5e3b3 100644 --- a/spec/unit/formatters/error_inspectors/cookbook_sync_error_inspector_spec.rb +++ b/spec/unit/formatters/error_inspectors/cookbook_sync_error_inspector_spec.rb @@ -29,7 +29,7 @@ describe Chef::Formatters::ErrorInspectors::CookbookSyncErrorInspector do before do @response_body = "sad trombone orchestra" @response = Net::HTTPBadGateway.new("1.1", "502", "(response) bad gateway") - @response.stub!(:body).and_return(@response_body) + @response.stub(:body).and_return(@response_body) @exception = Net::HTTPFatalError.new("(exception) bad gateway", @response) @inspector = described_class.new({}, @exception) @inspector.add_explanation(@description) diff --git a/spec/unit/formatters/error_inspectors/resource_failure_inspector_spec.rb b/spec/unit/formatters/error_inspectors/resource_failure_inspector_spec.rb index fdbb601005..588e56ec6b 100644 --- a/spec/unit/formatters/error_inspectors/resource_failure_inspector_spec.rb +++ b/spec/unit/formatters/error_inspectors/resource_failure_inspector_spec.rb @@ -38,7 +38,7 @@ describe Chef::Formatters::ErrorInspectors::ResourceFailureInspector do @outputter = Chef::Formatters::Outputter.new(@stdout, STDERR) #@outputter = Chef::Formatters::Outputter.new(STDOUT, STDERR) - Chef::Config.stub!(:cookbook_path).and_return([ "/var/chef/cache" ]) + Chef::Config.stub(:cookbook_path).and_return([ "/var/chef/cache" ]) end describe "when explaining an error converging a resource" do @@ -112,8 +112,8 @@ describe Chef::Formatters::ErrorInspectors::ResourceFailureInspector do before do # fake code to run through #recipe_snippet source_file = [ "if true", "var = non_existant", "end" ] - IO.stub!(:readlines).and_return(source_file) - File.stub!(:exists?).and_return(true) + IO.stub(:readlines).and_return(source_file) + File.stub(:exists?).and_return(true) end it "parses a Windows path" do @@ -132,8 +132,8 @@ describe Chef::Formatters::ErrorInspectors::ResourceFailureInspector do context "when the recipe file does not exist" do before do - File.stub!(:exists?).and_return(false) - IO.stub!(:readlines).and_raise(Errno::ENOENT) + File.stub(:exists?).and_return(false) + IO.stub(:readlines).and_raise(Errno::ENOENT) end it "does not try to parse a recipe in chef-shell/irb (CHEF-3411)" do @@ -172,7 +172,7 @@ describe Chef::Formatters::ErrorInspectors::ResourceFailureInspector do end it "does not generate an error" do - lambda { @inspector.add_explanation(@description) }.should_not raise_error(TypeError) + lambda { @inspector.add_explanation(@description) }.should_not raise_error @description.display(@outputter) end end diff --git a/spec/unit/formatters/error_inspectors/run_list_expansion_error_inspector_spec.rb b/spec/unit/formatters/error_inspectors/run_list_expansion_error_inspector_spec.rb index 706ff59c06..56a6eceec3 100644 --- a/spec/unit/formatters/error_inspectors/run_list_expansion_error_inspector_spec.rb +++ b/spec/unit/formatters/error_inspectors/run_list_expansion_error_inspector_spec.rb @@ -55,10 +55,10 @@ describe Chef::Formatters::ErrorInspectors::RunListExpansionErrorInspector do @response_body = "forbidden" @response = Net::HTTPForbidden.new("1.1", "403", "(response) forbidden") - @response.stub!(:body).and_return(@response_body) + @response.stub(:body).and_return(@response_body) @exception = Net::HTTPServerException.new("(exception) forbidden", @response) @inspector = Chef::Formatters::ErrorInspectors::RunListExpansionErrorInspector.new(@node, @exception) - @inspector.stub!(:config).and_return(:node_name => "unit-test.example.com") + @inspector.stub(:config).and_return(:node_name => "unit-test.example.com") @inspector.add_explanation(@description) end @@ -73,11 +73,11 @@ describe Chef::Formatters::ErrorInspectors::RunListExpansionErrorInspector do before do @response_body = "check your key and node name" @response = Net::HTTPUnauthorized.new("1.1", "401", "(response) unauthorized") - @response.stub!(:body).and_return(@response_body) + @response.stub(:body).and_return(@response_body) @exception = Net::HTTPServerException.new("(exception) unauthorized", @response) @inspector = Chef::Formatters::ErrorInspectors::RunListExpansionErrorInspector.new(@node, @exception) - @inspector.stub!(:config).and_return(:node_name => "unit-test.example.com", + @inspector.stub(:config).and_return(:node_name => "unit-test.example.com", :client_key => "/etc/chef/client.pem", :chef_server_url => "http://chef.example.com") diff --git a/spec/unit/handler/json_file_spec.rb b/spec/unit/handler/json_file_spec.rb index 1f47c40937..05270e4731 100644 --- a/spec/unit/handler/json_file_spec.rb +++ b/spec/unit/handler/json_file_spec.rb @@ -46,7 +46,7 @@ describe Chef::Handler::JsonFile do @run_status.run_context = @run_context @run_status.exception = Exception.new("Boy howdy!") @file_mock = StringIO.new - File.stub!(:open).and_yield(@file_mock) + File.stub(:open).and_yield(@file_mock) end diff --git a/spec/unit/handler_spec.rb b/spec/unit/handler_spec.rb index eab98e76a2..80d9df5e82 100644 --- a/spec/unit/handler_spec.rb +++ b/spec/unit/handler_spec.rb @@ -42,7 +42,7 @@ describe Chef::Handler do @run_status.run_context = @run_context @start_time = Time.now @end_time = @start_time + 4.2 - Time.stub!(:now).and_return(@start_time, @end_time) + Time.stub(:now).and_return(@start_time, @end_time) @run_status.start_clock @run_status.stop_clock end @@ -124,7 +124,7 @@ describe Chef::Handler do @run_status.run_context = @run_context @start_time = Time.now @end_time = @start_time + 4.2 - Time.stub!(:now).and_return(@start_time, @end_time) + Time.stub(:now).and_return(@start_time, @end_time) @run_status.start_clock @run_status.stop_clock end @@ -171,7 +171,7 @@ describe Chef::Handler do describe "when running a start handler" do before do @start_time = Time.now - Time.stub!(:now).and_return(@start_time) + Time.stub(:now).and_return(@start_time) @run_status.start_clock end diff --git a/spec/unit/knife/bootstrap_spec.rb b/spec/unit/knife/bootstrap_spec.rb index cc0336d8f6..b055cadcee 100644 --- a/spec/unit/knife/bootstrap_spec.rb +++ b/spec/unit/knife/bootstrap_spec.rb @@ -29,9 +29,9 @@ describe Chef::Knife::Bootstrap do @knife.merge_configs @knife.config[:template_file] = File.expand_path(File.join(CHEF_SPEC_DATA, "bootstrap", "test.erb")) @stdout = StringIO.new - @knife.ui.stub!(:stdout).and_return(@stdout) + @knife.ui.stub(:stdout).and_return(@stdout) @stderr = StringIO.new - @knife.ui.stub!(:stderr).and_return(@stderr) + @knife.ui.stub(:stderr).and_return(@stderr) end it "should return a name of default bootstrap template" do @@ -47,8 +47,8 @@ describe Chef::Knife::Bootstrap do it "should look for templates early in the run" do File.stub(:exists?).and_return(true) @knife.name_args = ['shatner'] - @knife.stub!(:read_template).and_return("") - @knife.stub!(:knife_ssh).and_return(true) + @knife.stub(:read_template).and_return("") + @knife.stub(:knife_ssh).and_return(true) @knife_ssh = @knife.knife_ssh @knife.should_receive(:find_template).ordered @knife.should_receive(:knife_ssh).ordered @@ -110,10 +110,10 @@ describe Chef::Knife::Bootstrap do it "should populate a hint file with JSON when given a file to read" do @knife.stub(:find_template).and_return(true) @knife.config[:template_file] = File.expand_path(File.join(CHEF_SPEC_DATA, "bootstrap", "test-hints.erb")) - ::File.stub!(:read).and_return('{ "foo" : "bar" }') + ::File.stub(:read).and_return('{ "foo" : "bar" }') @knife.instance_variable_set("@template_file", @knife.config[:template_file]) template_string = @knife.read_template - @knife.stub!(:read_template).and_return('{ "foo" : "bar" }') + @knife.stub(:read_template).and_return('{ "foo" : "bar" }') @knife.parse_options(["--hint", "openstack=hints/openstack.json"]) @knife.render_template(template_string).should match /\{\"foo\":\"bar\"\}/ end @@ -214,7 +214,7 @@ describe Chef::Knife::Bootstrap do Chef::Config[:knife][:ssh_port] = nil @knife.config[:forward_agent] = true @knife.config[:identity_file] = "~/.ssh/me.rsa" - @knife.stub!(:read_template).and_return("") + @knife.stub(:read_template).and_return("") @knife_ssh = @knife.knife_ssh end @@ -282,7 +282,7 @@ describe Chef::Knife::Bootstrap do Chef::Config[:knife][:identity_file] = "~/.ssh/you.rsa" Chef::Config[:knife][:ssh_gateway] = "towel.blinkenlights.nl" Chef::Config[:knife][:host_key_verify] = true - @knife.stub!(:read_template).and_return("") + @knife.stub(:read_template).and_return("") @knife_ssh = @knife.knife_ssh end @@ -316,20 +316,20 @@ describe Chef::Knife::Bootstrap do @knife.name_args = ["foo.example.com"] @knife.config[:ssh_user] = "rooty" @knife.config[:identity_file] = "~/.ssh/me.rsa" - @knife.stub!(:read_template).and_return("") + @knife.stub(:read_template).and_return("") @knife_ssh = @knife.knife_ssh end it "prompts the user for a password " do - @knife.stub!(:knife_ssh).and_return(@knife_ssh) - @knife_ssh.stub!(:get_password).and_return('typed_in_password') + @knife.stub(:knife_ssh).and_return(@knife_ssh) + @knife_ssh.stub(:get_password).and_return('typed_in_password') alternate_knife_ssh = @knife.knife_ssh_with_password_auth alternate_knife_ssh.config[:ssh_password].should == 'typed_in_password' end it "configures knife not to use the identity file that didn't work previously" do - @knife.stub!(:knife_ssh).and_return(@knife_ssh) - @knife_ssh.stub!(:get_password).and_return('typed_in_password') + @knife.stub(:knife_ssh).and_return(@knife_ssh) + @knife_ssh.stub(:get_password).and_return('typed_in_password') alternate_knife_ssh = @knife.knife_ssh_with_password_auth alternate_knife_ssh.config[:identity_file].should be_nil end @@ -341,9 +341,9 @@ describe Chef::Knife::Bootstrap do @knife.name_args = ["foo.example.com"] @knife.config[:ssh_user] = "rooty" @knife.config[:identity_file] = "~/.ssh/me.rsa" - @knife.stub!(:read_template).and_return("") + @knife.stub(:read_template).and_return("") @knife_ssh = @knife.knife_ssh - @knife.stub!(:knife_ssh).and_return(@knife_ssh) + @knife.stub(:knife_ssh).and_return(@knife_ssh) end it "verifies that a server to bootstrap was given as a command line arg" do @@ -358,11 +358,11 @@ describe Chef::Knife::Bootstrap do end it "falls back to password based auth when auth fails the first time" do - @knife.stub!(:puts) + @knife.stub(:puts) @fallback_knife_ssh = @knife_ssh.dup @knife_ssh.should_receive(:run).and_raise(Net::SSH::AuthenticationFailed.new("no ssh for you")) - @knife.stub!(:knife_ssh_with_password_auth).and_return(@fallback_knife_ssh) + @knife.stub(:knife_ssh_with_password_auth).and_return(@fallback_knife_ssh) @fallback_knife_ssh.should_receive(:run) @knife.run end diff --git a/spec/unit/knife/client_bulk_delete_spec.rb b/spec/unit/knife/client_bulk_delete_spec.rb index b7864ed098..bedd4911c5 100644 --- a/spec/unit/knife/client_bulk_delete_spec.rb +++ b/spec/unit/knife/client_bulk_delete_spec.rb @@ -26,16 +26,16 @@ describe Chef::Knife::ClientBulkDelete do @knife = Chef::Knife::ClientBulkDelete.new @knife.name_args = ["."] @stdout = StringIO.new - @knife.ui.stub!(:stdout).and_return(@stdout) - @knife.ui.stub!(:confirm).and_return(true) + @knife.ui.stub(:stdout).and_return(@stdout) + @knife.ui.stub(:confirm).and_return(true) @clients = Hash.new %w{tim dan stephen}.each do |client_name| client = Chef::ApiClient.new() client.name(client_name) - client.stub!(:destroy).and_return(true) + client.stub(:destroy).and_return(true) @clients[client_name] = client end - Chef::ApiClient.stub!(:list).and_return(@clients) + Chef::ApiClient.stub(:list).and_return(@clients) end describe "run" do diff --git a/spec/unit/knife/client_create_spec.rb b/spec/unit/knife/client_create_spec.rb index d07b6ceb17..69c55ba015 100644 --- a/spec/unit/knife/client_create_spec.rb +++ b/spec/unit/knife/client_create_spec.rb @@ -29,12 +29,12 @@ describe Chef::Knife::ClientCreate do } @knife.name_args = [ "adam" ] @client = Chef::ApiClient.new - @client.stub!(:save).and_return({ 'private_key' => '' }) - @knife.stub!(:edit_data).and_return(@client) - @knife.stub!(:puts) - Chef::ApiClient.stub!(:new).and_return(@client) + @client.stub(:save).and_return({ 'private_key' => '' }) + @knife.stub(:edit_data).and_return(@client) + @knife.stub(:puts) + Chef::ApiClient.stub(:new).and_return(@client) @stdout = StringIO.new - @knife.ui.stub!(:stdout).and_return(@stdout) + @knife.ui.stub(:stdout).and_return(@stdout) end describe "run" do @@ -62,8 +62,8 @@ describe Chef::Knife::ClientCreate do describe "with -f or --file" do it "should write the private key to a file" do @knife.config[:file] = "/tmp/monkeypants" - @client.stub!(:save).and_return({ 'private_key' => "woot" }) - filehandle = mock("Filehandle") + @client.stub(:save).and_return({ 'private_key' => "woot" }) + filehandle = double("Filehandle") filehandle.should_receive(:print).with('woot') File.should_receive(:open).with("/tmp/monkeypants", "w").and_yield(filehandle) @knife.run diff --git a/spec/unit/knife/client_reregister_spec.rb b/spec/unit/knife/client_reregister_spec.rb index d84978c497..daf18d5d25 100644 --- a/spec/unit/knife/client_reregister_spec.rb +++ b/spec/unit/knife/client_reregister_spec.rb @@ -22,9 +22,9 @@ describe Chef::Knife::ClientReregister do before(:each) do @knife = Chef::Knife::ClientReregister.new @knife.name_args = [ 'adam' ] - @client_mock = mock('client_mock', :private_key => "foo_key") + @client_mock = double('client_mock', :private_key => "foo_key") @stdout = StringIO.new - @knife.ui.stub!(:stdout).and_return(@stdout) + @knife.ui.stub(:stdout).and_return(@stdout) end context "when no client name is given on the command line" do diff --git a/spec/unit/knife/client_show_spec.rb b/spec/unit/knife/client_show_spec.rb index ce5f93ab5f..b5c95db097 100644 --- a/spec/unit/knife/client_show_spec.rb +++ b/spec/unit/knife/client_show_spec.rb @@ -22,7 +22,7 @@ describe Chef::Knife::ClientShow do before(:each) do @knife = Chef::Knife::ClientShow.new @knife.name_args = [ 'adam' ] - @client_mock = mock('client_mock') + @client_mock = double('client_mock') end describe 'run' do diff --git a/spec/unit/knife/config_file_selection_spec.rb b/spec/unit/knife/config_file_selection_spec.rb index 127e89be9b..0a623714d7 100644 --- a/spec/unit/knife/config_file_selection_spec.rb +++ b/spec/unit/knife/config_file_selection_spec.rb @@ -45,7 +45,7 @@ describe Chef::Knife do end before :each do - Chef::Config.stub!(:from_file).and_return(true) + Chef::Config.stub(:from_file).and_return(true) Chef::ConfigFetcher.stub(:new).and_return(missing_config_fetcher) end @@ -72,7 +72,7 @@ describe Chef::Knife do upward_dir = File.expand_path "#{Dir.pwd}/.chef" upward_config = File.expand_path "#{upward_dir}/knife.rb" have_config_file(upward_config) - Chef::Knife.stub!(:chef_config_dir).and_return(upward_dir) + Chef::Knife.stub(:chef_config_dir).and_return(upward_dir) @knife = Chef::Knife.new @knife.configure_chef @@ -89,7 +89,7 @@ describe Chef::Knife do end it "configure knife from nothing" do - ::File.stub!(:exist?).and_return(false) + ::File.stub(:exist?).and_return(false) @knife = Chef::Knife.new @knife.ui.should_receive(:warn).with("No knife configuration file found") @knife.configure_chef @@ -104,7 +104,7 @@ describe Chef::Knife do home_config = File.expand_path(File.join("#{ENV['HOME']}", "/.chef/knife.rb")) configs = [ env_config, pwd_config, upward_config, home_config ] - Chef::Knife.stub!(:chef_config_dir).and_return(upward_dir) + Chef::Knife.stub(:chef_config_dir).and_return(upward_dir) ENV['KNIFE_HOME'] = Dir.tmpdir @knife = Chef::Knife.new diff --git a/spec/unit/knife/configure_client_spec.rb b/spec/unit/knife/configure_client_spec.rb index ba832103bc..d101780317 100644 --- a/spec/unit/knife/configure_client_spec.rb +++ b/spec/unit/knife/configure_client_spec.rb @@ -26,7 +26,7 @@ describe Chef::Knife::ConfigureClient do Chef::Config[:validation_key] = '/etc/chef/validation.pem' @stdout = StringIO.new - @knife.ui.stub!(:stdout).and_return(@stdout) + @knife.ui.stub(:stdout).and_return(@stdout) end describe 'run' do @@ -56,7 +56,7 @@ describe Chef::Knife::ConfigureClient do end it 'should write out the config file' do - FileUtils.stub!(:mkdir_p) + FileUtils.stub(:mkdir_p) @knife.run @client_file.string.should match /log_level\s+\:info/ @client_file.string.should match /log_location\s+STDOUT/ @@ -65,13 +65,13 @@ describe Chef::Knife::ConfigureClient do end it 'should write out the validation.pem file' do - FileUtils.stub!(:mkdir_p) + FileUtils.stub(:mkdir_p) @knife.run @validation_file.string.should match /foo_bar_baz/ end it 'should print information on what is being configured' do - FileUtils.stub!(:mkdir_p) + FileUtils.stub(:mkdir_p) @knife.run @stdout.string.should match /creating client configuration/i @stdout.string.should match /writing client\.rb/i diff --git a/spec/unit/knife/configure_spec.rb b/spec/unit/knife/configure_spec.rb index 7c48be6727..eab42fadd5 100644 --- a/spec/unit/knife/configure_spec.rb +++ b/spec/unit/knife/configure_spec.rb @@ -6,20 +6,20 @@ describe Chef::Knife::Configure do Chef::Config[:node_name] = "webmonkey.example.com" @knife = Chef::Knife::Configure.new - @rest_client = mock("null rest client", :post_rest => { :result => :true }) - @knife.stub!(:rest).and_return(@rest_client) + @rest_client = double("null rest client", :post_rest => { :result => :true }) + @knife.stub(:rest).and_return(@rest_client) @out = StringIO.new - @knife.ui.stub!(:stdout).and_return(@out) + @knife.ui.stub(:stdout).and_return(@out) @knife.config[:config_file] = '/home/you/.chef/knife.rb' @in = StringIO.new("\n" * 7) - @knife.ui.stub!(:stdin).and_return(@in) + @knife.ui.stub(:stdin).and_return(@in) @err = StringIO.new - @knife.ui.stub!(:stderr).and_return(@err) + @knife.ui.stub(:stderr).and_return(@err) - Ohai::System.stub!(:new).and_return(ohai) + Ohai::System.stub(:new).and_return(ohai) end @@ -49,7 +49,7 @@ describe Chef::Knife::Configure do it "asks the user for the clientname they want for the new client if -i is specified" do @knife.config[:initial] = true - Etc.stub!(:getlogin).and_return("a-new-user") + Etc.stub(:getlogin).and_return("a-new-user") @knife.ask_user_for_config @out.string.should match(Regexp.escape("Please enter a name for the new user: [a-new-user]")) @knife.new_client_name.should == Etc.getlogin @@ -58,14 +58,14 @@ describe Chef::Knife::Configure do it "should not ask the user for the clientname they want for the new client if -i and --node_name are specified" do @knife.config[:initial] = true @knife.config[:node_name] = 'testnode' - Etc.stub!(:getlogin).and_return("a-new-user") + Etc.stub(:getlogin).and_return("a-new-user") @knife.ask_user_for_config @out.string.should_not match(Regexp.escape("Please enter a name for the new user")) @knife.new_client_name.should == 'testnode' end it "asks the user for the existing API username or clientname if -i is not specified" do - Etc.stub!(:getlogin).and_return("a-new-user") + Etc.stub(:getlogin).and_return("a-new-user") @knife.ask_user_for_config @out.string.should match(Regexp.escape("Please enter an existing username or clientname for the API: [a-new-user]")) @knife.new_client_name.should == Etc.getlogin @@ -175,7 +175,7 @@ describe Chef::Knife::Configure do @knife.config[:validation_key] = '/home/you/.chef/my-validation.pem' @knife.config[:repository] = '' @knife.config[:client_key] = '/home/you/a-new-user.pem' - Etc.stub!(:getlogin).and_return('a-new-user') + Etc.stub(:getlogin).and_return('a-new-user') @knife.ask_user_for_config @out.string.should match(/\s*/) @@ -197,10 +197,10 @@ describe Chef::Knife::Configure do end it "writes the new data to a config file" do - File.stub!(:expand_path).with("/home/you/.chef/knife.rb").and_return("/home/you/.chef/knife.rb") - File.stub!(:expand_path).with("/home/you/.chef/#{Etc.getlogin}.pem").and_return("/home/you/.chef/#{Etc.getlogin}.pem") - File.stub!(:expand_path).with(default_validator_key).and_return(default_validator_key) - File.stub!(:expand_path).with(default_admin_key).and_return(default_admin_key) + File.stub(:expand_path).with("/home/you/.chef/knife.rb").and_return("/home/you/.chef/knife.rb") + File.stub(:expand_path).with("/home/you/.chef/#{Etc.getlogin}.pem").and_return("/home/you/.chef/#{Etc.getlogin}.pem") + File.stub(:expand_path).with(default_validator_key).and_return(default_validator_key) + File.stub(:expand_path).with(default_admin_key).and_return(default_admin_key) FileUtils.should_receive(:mkdir_p).with("/home/you/.chef") config_file = StringIO.new ::File.should_receive(:open).with("/home/you/.chef/knife.rb", "w").and_yield config_file @@ -224,9 +224,9 @@ describe Chef::Knife::Configure do user_command = Chef::Knife::UserCreate.new user_command.should_receive(:run) - Etc.stub!(:getlogin).and_return("a-new-user") + Etc.stub(:getlogin).and_return("a-new-user") - Chef::Knife::UserCreate.stub!(:new).and_return(user_command) + Chef::Knife::UserCreate.stub(:new).and_return(user_command) FileUtils.should_receive(:mkdir_p).with("/home/you/.chef") ::File.should_receive(:open).with("/home/you/.chef/knife.rb", "w") @knife.config[:initial] = true diff --git a/spec/unit/knife/cookbook_bulk_delete_spec.rb b/spec/unit/knife/cookbook_bulk_delete_spec.rb index ced2a9a4e4..0cff690bc2 100644 --- a/spec/unit/knife/cookbook_bulk_delete_spec.rb +++ b/spec/unit/knife/cookbook_bulk_delete_spec.rb @@ -27,18 +27,18 @@ describe Chef::Knife::CookbookBulkDelete do @knife.config = {:print_after => nil} @knife.name_args = ["."] @stdout = StringIO.new - @knife.ui.stub!(:stdout).and_return(@stdout) - @knife.ui.stub!(:confirm).and_return(true) + @knife.ui.stub(:stdout).and_return(@stdout) + @knife.ui.stub(:confirm).and_return(true) @cookbooks = Hash.new %w{cheezburger pizza lasagna}.each do |cookbook_name| cookbook = Chef::CookbookVersion.new(cookbook_name) @cookbooks[cookbook_name] = cookbook end - @rest = mock("Chef::REST") - @rest.stub!(:get_rest).and_return(@cookbooks) - @rest.stub!(:delete_rest).and_return(true) - @knife.stub!(:rest).and_return(@rest) - Chef::CookbookVersion.stub!(:list).and_return(@cookbooks) + @rest = double("Chef::REST") + @rest.stub(:get_rest).and_return(@cookbooks) + @rest.stub(:delete_rest).and_return(true) + @knife.stub(:rest).and_return(@rest) + Chef::CookbookVersion.stub(:list).and_return(@cookbooks) end @@ -47,11 +47,11 @@ describe Chef::Knife::CookbookBulkDelete do describe "when there are several cookbooks on the server" do before do @cheezburger = {'cheezburger' => {"url" => "file:///dev/null", "versions" => [{"url" => "file:///dev/null-cheez", "version" => "1.0.0"}]}} - @rest.stub!(:get_rest).with('cookbooks/cheezburger').and_return(@cheezburger) + @rest.stub(:get_rest).with('cookbooks/cheezburger').and_return(@cheezburger) @pizza = {'pizza' => {"url" => "file:///dev/null", "versions" => [{"url" => "file:///dev/null-pizza", "version" => "2.0.0"}]}} - @rest.stub!(:get_rest).with('cookbooks/pizza').and_return(@pizza) + @rest.stub(:get_rest).with('cookbooks/pizza').and_return(@pizza) @lasagna = {'lasagna' => {"url" => "file:///dev/null", "versions" => [{"url" => "file:///dev/null-lasagna", "version" => "3.0.0"}]}} - @rest.stub!(:get_rest).with('cookbooks/lasagna').and_return(@lasagna) + @rest.stub(:get_rest).with('cookbooks/lasagna').and_return(@lasagna) end it "should print the cookbooks you are about to delete" do diff --git a/spec/unit/knife/cookbook_create_spec.rb b/spec/unit/knife/cookbook_create_spec.rb index 7891115285..06475d3ac9 100644 --- a/spec/unit/knife/cookbook_create_spec.rb +++ b/spec/unit/knife/cookbook_create_spec.rb @@ -26,7 +26,7 @@ describe Chef::Knife::CookbookCreate do @knife.config = {} @knife.name_args = ["foobar"] @stdout = StringIO.new - @knife.stub!(:stdout).and_return(@stdout) + @knife.stub(:stdout).and_return(@stdout) end describe "run" do @@ -35,10 +35,10 @@ describe Chef::Knife::CookbookCreate do it "should expand the path of the cookbook directory" do File.should_receive(:expand_path).with("~/tmp/monkeypants") @knife.config = {:cookbook_path => "~/tmp/monkeypants"} - @knife.stub!(:create_cookbook) - @knife.stub!(:create_readme) - @knife.stub!(:create_changelog) - @knife.stub!(:create_metadata) + @knife.stub(:create_cookbook) + @knife.stub(:create_readme) + @knife.stub(:create_changelog) + @knife.stub(:create_metadata) @knife.run end diff --git a/spec/unit/knife/cookbook_delete_spec.rb b/spec/unit/knife/cookbook_delete_spec.rb index afaa3b69a5..f4ba46f513 100644 --- a/spec/unit/knife/cookbook_delete_spec.rb +++ b/spec/unit/knife/cookbook_delete_spec.rb @@ -24,9 +24,9 @@ describe Chef::Knife::CookbookDelete do @knife.name_args = ['foobar'] @knife.cookbook_name = 'foobar' @stdout = StringIO.new - @knife.ui.stub!(:stdout).and_return(@stdout) + @knife.ui.stub(:stdout).and_return(@stdout) @stderr = StringIO.new - @knife.ui.stub!(:stderr).and_return(@stderr) + @knife.ui.stub(:stderr).and_return(@stderr) end describe 'run' do @@ -125,7 +125,7 @@ describe Chef::Knife::CookbookDelete do describe 'available_versions' do before(:each) do - @rest_mock = mock('rest') + @rest_mock = double('rest') @knife.should_receive(:rest).and_return(@rest_mock) @cookbook_data = { 'foobar' => { 'versions' => [{'version' => '1.0.0'}, {'version' => '1.1.0'}, @@ -163,7 +163,7 @@ describe Chef::Knife::CookbookDelete do describe 'ask_which_version_to_delete' do before(:each) do - @knife.stub!(:available_versions).and_return(['1.0.0', '1.1.0', '2.0.0']) + @knife.stub(:available_versions).and_return(['1.0.0', '1.1.0', '2.0.0']) end it 'should prompt the user to select a version' do @@ -202,7 +202,7 @@ describe Chef::Knife::CookbookDelete do end it 'should output that the cookbook was deleted' do - @knife.stub!(:delete_request) + @knife.stub(:delete_request) @knife.delete_version_without_confirmation('1.0.0') @stdout.string.should match /deleted cookbook\[foobar\]\[1.0.0\]/im end @@ -211,7 +211,7 @@ describe Chef::Knife::CookbookDelete do it 'should display the cookbook data' do object = '' @knife.config[:print_after] = true - @knife.stub!(:delete_request).and_return(object) + @knife.stub(:delete_request).and_return(object) @knife.should_receive(:format_for_display).with(object) @knife.delete_version_without_confirmation('1.0.0') end diff --git a/spec/unit/knife/cookbook_download_spec.rb b/spec/unit/knife/cookbook_download_spec.rb index cc3c300fdf..efab98f646 100644 --- a/spec/unit/knife/cookbook_download_spec.rb +++ b/spec/unit/knife/cookbook_download_spec.rb @@ -22,7 +22,7 @@ describe Chef::Knife::CookbookDownload do before(:each) do @knife = Chef::Knife::CookbookDownload.new @stdout = StringIO.new - @knife.ui.stub!(:stdout).and_return(@stdout) + @knife.ui.stub(:stdout).and_return(@stdout) end describe 'run' do @@ -44,7 +44,7 @@ describe Chef::Knife::CookbookDownload do before(:each) do @knife.name_args = ['foobar'] @knife.config[:download_directory] = '/var/tmp/chef' - @rest_mock = mock('rest') + @rest_mock = double('rest') @knife.stub(:rest).and_return(@rest_mock) @manifest_data = { @@ -66,18 +66,18 @@ describe Chef::Knife::CookbookDownload do ] } - @cookbook_mock = mock('cookbook') - @cookbook_mock.stub!(:version).and_return('1.0.0') - @cookbook_mock.stub!(:manifest).and_return(@manifest_data) + @cookbook_mock = double('cookbook') + @cookbook_mock.stub(:version).and_return('1.0.0') + @cookbook_mock.stub(:manifest).and_return(@manifest_data) @rest_mock.should_receive(:get_rest).with('cookbooks/foobar/1.0.0'). and_return(@cookbook_mock) end it 'should determine which version if one was not explicitly specified'do - @cookbook_mock.stub!(:manifest).and_return({}) + @cookbook_mock.stub(:manifest).and_return({}) @knife.should_receive(:determine_version).and_return('1.0.0') File.should_receive(:exists?).with('/var/tmp/chef/foobar-1.0.0').and_return(false) - Chef::CookbookVersion.stub!(:COOKBOOK_SEGEMENTS).and_return([]) + Chef::CookbookVersion.stub(:COOKBOOK_SEGEMENTS).and_return([]) @knife.run end @@ -87,8 +87,8 @@ describe Chef::Knife::CookbookDownload do @files = @manifest_data.values.map { |v| v.map { |i| i['path'] } }.flatten.uniq @files_mocks = {} @files.map { |f| File.basename(f) }.flatten.uniq.each do |f| - @files_mocks[f] = mock("#{f}_mock") - @files_mocks[f].stub!(:path).and_return("/var/tmp/#{f}") + @files_mocks[f] = double("#{f}_mock") + @files_mocks[f].stub(:path).and_return("/var/tmp/#{f}") end end @@ -207,7 +207,7 @@ describe Chef::Knife::CookbookDownload do describe 'ask_which_version' do before(:each) do @knife.cookbook_name = 'foobar' - @knife.stub!(:available_versions).and_return(['1.0.0', '1.1.0', '2.0.0']) + @knife.stub(:available_versions).and_return(['1.0.0', '1.1.0', '2.0.0']) end it 'should prompt the user to select a version' do diff --git a/spec/unit/knife/cookbook_list_spec.rb b/spec/unit/knife/cookbook_list_spec.rb index db6f061bd1..9ff16edb37 100644 --- a/spec/unit/knife/cookbook_list_spec.rb +++ b/spec/unit/knife/cookbook_list_spec.rb @@ -21,8 +21,8 @@ require 'spec_helper' describe Chef::Knife::CookbookList do before do @knife = Chef::Knife::CookbookList.new - @rest_mock = mock('rest') - @knife.stub!(:rest).and_return(@rest_mock) + @rest_mock = double('rest') + @knife.stub(:rest).and_return(@rest_mock) @cookbook_names = ['apache2', 'mysql'] @base_url = 'https://server.example.com/cookbooks' @cookbook_data = {} @@ -32,7 +32,7 @@ describe Chef::Knife::CookbookList do 'url' => "#{@base_url}/#{item}/1.0.1"}]} end @stdout = StringIO.new - @knife.ui.stub!(:stdout).and_return(@stdout) + @knife.ui.stub(:stdout).and_return(@stdout) end describe 'run' do diff --git a/spec/unit/knife/cookbook_metadata_from_file_spec.rb b/spec/unit/knife/cookbook_metadata_from_file_spec.rb index 6f406de6b7..68ab6740ab 100644 --- a/spec/unit/knife/cookbook_metadata_from_file_spec.rb +++ b/spec/unit/knife/cookbook_metadata_from_file_spec.rb @@ -27,10 +27,10 @@ describe Chef::Knife::CookbookMetadataFromFile do @tgt = File.expand_path(File.join(CHEF_SPEC_DATA, "metadata", "quick_start", "metadata.json")) @knife = Chef::Knife::CookbookMetadataFromFile.new @knife.name_args = [ @src ] - @knife.stub!(:to_json_pretty).and_return(true) + @knife.stub(:to_json_pretty).and_return(true) @md = Chef::Cookbook::Metadata.new Chef::Cookbook::Metadata.stub(:new).and_return(@md) - $stdout.stub!(:write) + $stdout.stub(:write) end after do diff --git a/spec/unit/knife/cookbook_metadata_spec.rb b/spec/unit/knife/cookbook_metadata_spec.rb index c664326a3d..92db650435 100644 --- a/spec/unit/knife/cookbook_metadata_spec.rb +++ b/spec/unit/knife/cookbook_metadata_spec.rb @@ -26,8 +26,8 @@ describe Chef::Knife::CookbookMetadata do @json_data = '{ "version": "1.0.0" }' @stdout = StringIO.new @stderr = StringIO.new - @knife.ui.stub!(:stdout).and_return(@stdout) - @knife.ui.stub!(:stderr).and_return(@stderr) + @knife.ui.stub(:stdout).and_return(@stdout) + @knife.ui.stub(:stderr).and_return(@stderr) end describe 'run' do @@ -84,7 +84,7 @@ describe Chef::Knife::CookbookMetadata do describe 'generate_metadata' do before(:each) do @knife.config[:cookbook_path] = @cookbook_dir - File.stub!(:expand_path).with("#{@cookbook_dir}/foobar/metadata.rb"). + File.stub(:expand_path).with("#{@cookbook_dir}/foobar/metadata.rb"). and_return("#{@cookbook_dir}/foobar/metadata.rb") end @@ -105,12 +105,12 @@ describe Chef::Knife::CookbookMetadata do describe 'generate_metadata_from_file' do before(:each) do - @metadata_mock = mock('metadata') - @json_file_mock = mock('json_file') + @metadata_mock = double('metadata') + @json_file_mock = double('json_file') end it 'should generate the metatdata json from metatdata.rb' do - Chef::Cookbook::Metadata.stub!(:new).and_return(@metadata_mock) + Chef::Cookbook::Metadata.stub(:new).and_return(@metadata_mock) @metadata_mock.should_receive(:name).with('foobar') @metadata_mock.should_receive(:from_file).with("#{@cookbook_dir}/foobar/metadata.rb") File.should_receive(:open).with("#{@cookbook_dir}/foobar/metadata.json", 'w'). @@ -127,7 +127,7 @@ describe Chef::Knife::CookbookMetadata do }.each_pair do |klass, description| it "should print an error and exit when an #{description} syntax exception is encountered" do exception = klass.new("#{description} blah") - Chef::Cookbook::Metadata.stub!(:new).and_raise(exception) + Chef::Cookbook::Metadata.stub(:new).and_raise(exception) lambda { @knife.generate_metadata_from_file('foobar', "#{@cookbook_dir}/foobar/metadata.rb") }.should raise_error(SystemExit) @@ -165,7 +165,7 @@ describe Chef::Knife::CookbookMetadata do IO.should_receive(:read).with("#{@cookbook_dir}/foobar/metadata.json"). and_return(@json_data) exception = klass.new("#{description} blah") - Chef::Cookbook::Metadata.stub!(:validate_json).and_raise(exception) + Chef::Cookbook::Metadata.stub(:validate_json).and_raise(exception) lambda { @knife.validate_metadata_json(@cookbook_dir, 'foobar') }.should raise_error(SystemExit) diff --git a/spec/unit/knife/cookbook_show_spec.rb b/spec/unit/knife/cookbook_show_spec.rb index 96fe738b0b..b862c3154c 100644 --- a/spec/unit/knife/cookbook_show_spec.rb +++ b/spec/unit/knife/cookbook_show_spec.rb @@ -25,10 +25,10 @@ describe Chef::Knife::CookbookShow do @knife = Chef::Knife::CookbookShow.new @knife.config = { } @knife.name_args = [ "cookbook_name" ] - @rest = mock(Chef::REST) - @knife.stub!(:rest).and_return(@rest) - @knife.stub!(:pretty_print).and_return(true) - @knife.stub!(:output).and_return(true) + @rest = double(Chef::REST) + @knife.stub(:rest).and_return(@rest) + @knife.stub(:pretty_print).and_return(true) + @knife.stub(:output).and_return(true) end describe "run" do diff --git a/spec/unit/knife/cookbook_site_download_spec.rb b/spec/unit/knife/cookbook_site_download_spec.rb index a3d43c5b4a..faf58f7bc7 100644 --- a/spec/unit/knife/cookbook_site_download_spec.rb +++ b/spec/unit/knife/cookbook_site_download_spec.rb @@ -24,7 +24,7 @@ describe Chef::Knife::CookbookSiteDownload do before do @knife = Chef::Knife::CookbookSiteDownload.new @knife.name_args = ['apache2'] - @noauth_rest = mock 'no auth rest' + @noauth_rest = double('no auth rest') @stdout = StringIO.new @cookbook_api_url = 'http://cookbooks.opscode.com/api/v1/cookbooks' @version = '1.0.2' @@ -58,7 +58,7 @@ describe Chef::Knife::CookbookSiteDownload do before do @cookbook_data = { 'version' => @version, 'file' => "http://example.com/apache2_#{@version_us}.tgz" } - @temp_file = stub :path => "/tmp/apache2_#{@version_us}.tgz" + @temp_file = double( :path => "/tmp/apache2_#{@version_us}.tgz" ) @file = File.join(Dir.pwd, "apache2-#{@version}.tar.gz") @noauth_rest.should_receive(:sign_on_redirect=).with(false) @@ -125,7 +125,7 @@ describe Chef::Knife::CookbookSiteDownload do @version_us = @version.gsub '.', '_' @cookbook_data = { 'version' => @version, 'file' => "http://example.com/apache2_#{@version_us}.tgz" } - @temp_file = stub :path => "/tmp/apache2_#{@version_us}.tgz" + @temp_file = double(:path => "/tmp/apache2_#{@version_us}.tgz") @file = File.join(Dir.pwd, "apache2-#{@version}.tar.gz") @knife.name_args << @version end diff --git a/spec/unit/knife/cookbook_site_install_spec.rb b/spec/unit/knife/cookbook_site_install_spec.rb index f7d7a397e6..3086c817d9 100644 --- a/spec/unit/knife/cookbook_site_install_spec.rb +++ b/spec/unit/knife/cookbook_site_install_spec.rb @@ -32,18 +32,18 @@ describe Chef::Knife::CookbookSiteInstall do @stdout = StringIO.new @stderr = StringIO.new - @knife.stub!(:stderr).and_return(@stdout) - @knife.stub!(:stdout).and_return(@stdout) + @knife.stub(:stderr).and_return(@stdout) + @knife.stub(:stdout).and_return(@stdout) #Assume all external commands would have succeed. :( - File.stub!(:unlink) - File.stub!(:rmtree) - @knife.stub!(:shell_out!).and_return(true) + File.stub(:unlink) + File.stub(:rmtree) + @knife.stub(:shell_out!).and_return(true) #CookbookSiteDownload Stup @downloader = {} - @knife.stub!(:download_cookbook_to).and_return(@downloader) - @downloader.stub!(:version).and_return do + @knife.stub(:download_cookbook_to).and_return(@downloader) + @downloader.stub(:version).and_return do if @knife.name_args.size == 2 @knife.name_args[1] else @@ -55,7 +55,7 @@ describe Chef::Knife::CookbookSiteInstall do @repo = stub(:sanity_check => true, :reset_to_default_state => true, :prepare_to_import => true, :finalize_updates_to => true, :merge_updates_from => true) - Chef::Knife::CookbookSCMRepo.stub!(:new).and_return(@repo) + Chef::Knife::CookbookSCMRepo.stub(:new).and_return(@repo) end diff --git a/spec/unit/knife/cookbook_site_share_spec.rb b/spec/unit/knife/cookbook_site_share_spec.rb index 3b912af0c5..14c4262cb3 100644 --- a/spec/unit/knife/cookbook_site_share_spec.rb +++ b/spec/unit/knife/cookbook_site_share_spec.rb @@ -29,25 +29,25 @@ describe Chef::Knife::CookbookSiteShare do @cookbook = Chef::CookbookVersion.new('cookbook_name') - @cookbook_loader = mock('Chef::CookbookLoader') - @cookbook_loader.stub!(:cookbook_exists?).and_return(true) - @cookbook_loader.stub!(:[]).and_return(@cookbook) - Chef::CookbookLoader.stub!(:new).and_return(@cookbook_loader) + @cookbook_loader = double('Chef::CookbookLoader') + @cookbook_loader.stub(:cookbook_exists?).and_return(true) + @cookbook_loader.stub(:[]).and_return(@cookbook) + Chef::CookbookLoader.stub(:new).and_return(@cookbook_loader) @cookbook_uploader = Chef::CookbookUploader.new('herpderp', File.join(CHEF_SPEC_DATA, 'cookbooks'), :rest => "norest") - Chef::CookbookUploader.stub!(:new).and_return(@cookbook_uploader) - @cookbook_uploader.stub!(:validate_cookbooks).and_return(true) - Chef::CookbookSiteStreamingUploader.stub!(:create_build_dir).and_return(Dir.mktmpdir) + Chef::CookbookUploader.stub(:new).and_return(@cookbook_uploader) + @cookbook_uploader.stub(:validate_cookbooks).and_return(true) + Chef::CookbookSiteStreamingUploader.stub(:create_build_dir).and_return(Dir.mktmpdir) Chef::Mixin::Command.stub(:run_command).and_return(true) @stdout = StringIO.new - @knife.ui.stub!(:stdout).and_return(@stdout) + @knife.ui.stub(:stdout).and_return(@stdout) end describe 'run' do before(:each) do - @knife.stub!(:do_upload).and_return(true) + @knife.stub(:do_upload).and_return(true) end it 'should should print usage and exit when given no arguments' do @@ -83,7 +83,7 @@ describe Chef::Knife::CookbookSiteShare do end it 'should exit and log to error when the tarball creation fails' do - Chef::Mixin::Command.stub!(:run_command).and_raise(Chef::Exceptions::Exec) + Chef::Mixin::Command.stub(:run_command).and_raise(Chef::Exceptions::Exec) @knife.ui.should_receive(:error) lambda { @knife.run }.should raise_error(SystemExit) end @@ -98,44 +98,44 @@ describe Chef::Knife::CookbookSiteShare do describe 'do_upload' do before(:each) do - @upload_response = mock('Net::HTTPResponse') - Chef::CookbookSiteStreamingUploader.stub!(:post).and_return(@upload_response) + @upload_response = double('Net::HTTPResponse') + Chef::CookbookSiteStreamingUploader.stub(:post).and_return(@upload_response) @stdout = StringIO.new @stderr = StringIO.new - @knife.ui.stub!(:stdout).and_return(@stdout) - @knife.ui.stub!(:stderr).and_return(@stderr) + @knife.ui.stub(:stdout).and_return(@stdout) + @knife.ui.stub(:stderr).and_return(@stderr) File.stub(:open).and_return(true) end it 'should post the cookbook to "http://cookbooks.opscode.com"' do response_text = {:uri => 'http://cookbooks.opscode.com/cookbooks/cookbook_name'}.to_json - @upload_response.stub!(:body).and_return(response_text) - @upload_response.stub!(:code).and_return(201) + @upload_response.stub(:body).and_return(response_text) + @upload_response.stub(:code).and_return(201) Chef::CookbookSiteStreamingUploader.should_receive(:post).with(/cookbooks\.opscode\.com/, anything(), anything(), anything()) @knife.run end it 'should alert the user when a version already exists' do response_text = {:error_messages => ['Version already exists']}.to_json - @upload_response.stub!(:body).and_return(response_text) - @upload_response.stub!(:code).and_return(409) + @upload_response.stub(:body).and_return(response_text) + @upload_response.stub(:code).and_return(409) lambda { @knife.run }.should raise_error(SystemExit) @stderr.string.should match(/ERROR(.+)cookbook already exists/) end it 'should pass any errors on to the user' do response_text = {:error_messages => ["You're holding it wrong"]}.to_json - @upload_response.stub!(:body).and_return(response_text) - @upload_response.stub!(:code).and_return(403) + @upload_response.stub(:body).and_return(response_text) + @upload_response.stub(:code).and_return(403) lambda { @knife.run }.should raise_error(SystemExit) @stderr.string.should match("ERROR(.*)You're holding it wrong") end it 'should print the body if no errors are exposed on failure' do response_text = {:system_error => "Your call was dropped", :reason => "There's a map for that"}.to_json - @upload_response.stub!(:body).and_return(response_text) - @upload_response.stub!(:code).and_return(500) + @upload_response.stub(:body).and_return(response_text) + @upload_response.stub(:code).and_return(500) @knife.ui.should_receive(:error).with(/#{Regexp.escape(response_text)}/)#.ordered @knife.ui.should_receive(:error).with(/Unknown error/)#.ordered lambda { @knife.run }.should raise_error(SystemExit) diff --git a/spec/unit/knife/cookbook_site_unshare_spec.rb b/spec/unit/knife/cookbook_site_unshare_spec.rb index ffba2ec664..14cda65b43 100644 --- a/spec/unit/knife/cookbook_site_unshare_spec.rb +++ b/spec/unit/knife/cookbook_site_unshare_spec.rb @@ -24,13 +24,13 @@ describe Chef::Knife::CookbookSiteUnshare do before(:each) do @knife = Chef::Knife::CookbookSiteUnshare.new @knife.name_args = ['cookbook_name'] - @knife.stub!(:confirm).and_return(true) + @knife.stub(:confirm).and_return(true) - @rest = mock('Chef::REST') - @rest.stub!(:delete_rest).and_return(true) - @knife.stub!(:rest).and_return(@rest) + @rest = double('Chef::REST') + @rest.stub(:delete_rest).and_return(true) + @knife.stub(:rest).and_return(@rest) @stdout = StringIO.new - @knife.ui.stub!(:stdout).and_return(@stdout) + @knife.ui.stub(:stdout).and_return(@stdout) end describe 'run' do @@ -55,14 +55,14 @@ describe Chef::Knife::CookbookSiteUnshare do end it 'should log an error and exit when forbidden' do - exception = mock('403 "Forbidden"', :code => '403') - @rest.stub!(:delete_rest).and_raise(Net::HTTPServerException.new('403 "Forbidden"', exception)) + exception = double('403 "Forbidden"', :code => '403') + @rest.stub(:delete_rest).and_raise(Net::HTTPServerException.new('403 "Forbidden"', exception)) @knife.ui.should_receive(:error) lambda { @knife.run }.should raise_error(SystemExit) end it 'should re-raise any non-forbidden errors on delete_rest' do - exception = mock('500 "Application Error"', :code => '500') + exception = double('500 "Application Error"', :code => '500') @rest.stub(:delete_rest).and_raise(Net::HTTPServerException.new('500 "Application Error"', exception)) lambda { @knife.run }.should raise_error(Net::HTTPServerException) end diff --git a/spec/unit/knife/cookbook_test_spec.rb b/spec/unit/knife/cookbook_test_spec.rb index 24c658dc6c..0e261c02a4 100644 --- a/spec/unit/knife/cookbook_test_spec.rb +++ b/spec/unit/knife/cookbook_test_spec.rb @@ -26,25 +26,25 @@ describe Chef::Knife::CookbookTest do Chef::Config[:node_name] = "webmonkey.example.com" @knife = Chef::Knife::CookbookTest.new @knife.config[:cookbook_path] = File.join(CHEF_SPEC_DATA,'cookbooks') - @knife.cookbook_loader.stub!(:cookbook_exists?).and_return(true) + @knife.cookbook_loader.stub(:cookbook_exists?).and_return(true) @cookbooks = [] %w{tats central_market jimmy_johns pho}.each do |cookbook_name| @cookbooks << Chef::CookbookVersion.new(cookbook_name) end @stdout = StringIO.new - @knife.ui.stub!(:stdout).and_return(@stdout) + @knife.ui.stub(:stdout).and_return(@stdout) end describe "run" do it "should test the cookbook" do - @knife.stub!(:test_cookbook).and_return(true) + @knife.stub(:test_cookbook).and_return(true) @knife.name_args = ["italian"] @knife.should_receive(:test_cookbook).with("italian") @knife.run end it "should test multiple cookbooks when provided" do - @knife.stub!(:test_cookbook).and_return(true) + @knife.stub(:test_cookbook).and_return(true) @knife.name_args = ["tats", "jimmy_johns"] @knife.should_receive(:test_cookbook).with("tats") @knife.should_receive(:test_cookbook).with("jimmy_johns") @@ -65,14 +65,14 @@ describe Chef::Knife::CookbookTest do describe "with -a or --all" do it "should test all of the cookbooks" do - @knife.stub!(:test_cookbook).and_return(true) + @knife.stub(:test_cookbook).and_return(true) @knife.config[:all] = true @loader = {} - @loader.stub!(:load_cookbooks).and_return(@loader) + @loader.stub(:load_cookbooks).and_return(@loader) @cookbooks.each do |cookbook| @loader[cookbook.name] = cookbook end - @knife.stub!(:cookbook_loader).and_return(@loader) + @knife.stub(:cookbook_loader).and_return(@loader) @loader.each do |key, cookbook| @knife.should_receive(:test_cookbook).with(cookbook.name) end diff --git a/spec/unit/knife/cookbook_upload_spec.rb b/spec/unit/knife/cookbook_upload_spec.rb index 5572430b50..65331b3952 100644 --- a/spec/unit/knife/cookbook_upload_spec.rb +++ b/spec/unit/knife/cookbook_upload_spec.rb @@ -30,24 +30,24 @@ describe Chef::Knife::CookbookUpload do @cookbook = Chef::CookbookVersion.new('test_cookbook') @cookbook_loader = {} - @cookbook_loader.stub!(:[]).and_return(@cookbook) - @cookbook_loader.stub!(:merged_cookbooks).and_return([]) - @cookbook_loader.stub!(:load_cookbooks).and_return(@cookbook_loader) - Chef::CookbookLoader.stub!(:new).and_return(@cookbook_loader) + @cookbook_loader.stub(:[]).and_return(@cookbook) + @cookbook_loader.stub(:merged_cookbooks).and_return([]) + @cookbook_loader.stub(:load_cookbooks).and_return(@cookbook_loader) + Chef::CookbookLoader.stub(:new).and_return(@cookbook_loader) @output = StringIO.new - @knife.ui.stub!(:stdout).and_return(@output) - @knife.ui.stub!(:stderr).and_return(@output) + @knife.ui.stub(:stdout).and_return(@output) + @knife.ui.stub(:stderr).and_return(@output) end describe 'with --concurrency' do it 'should upload cookbooks with predefined concurrency' do - @cookbook_uploader = stub(:upload_cookbooks => nil) + @cookbook_uploader = double(:upload_cookbooks => nil) Chef::CookbookVersion.stub(:list_all_versions).and_return({}) @knife.config[:concurrency] = 3 @test_cookbook = Chef::CookbookVersion.new('test_cookbook') - @cookbook_loader.stub!(:each).and_yield("test_cookbook", @test_cookbook) - @cookbook_loader.stub!(:cookbook_names).and_return(["test_cookbook"]) + @cookbook_loader.stub(:each).and_yield("test_cookbook", @test_cookbook) + @cookbook_loader.stub(:cookbook_names).and_return(["test_cookbook"]) Chef::CookbookUploader.should_receive(:new).with( kind_of(Array), kind_of(Array), {:force=>nil, :concurrency => 3}).and_return(double("Chef::CookbookUploader", :upload_cookbooks=> true)) @knife.run @@ -56,7 +56,7 @@ describe Chef::Knife::CookbookUpload do describe 'run' do before(:each) do - @cookbook_uploader = stub(:upload_cookbooks => nil) + @cookbook_uploader = double(:upload_cookbooks => nil) Chef::CookbookUploader.stub(:new => @cookbook_uploader) Chef::CookbookVersion.stub(:list_all_versions).and_return({}) end @@ -98,9 +98,9 @@ describe Chef::Knife::CookbookUpload do 'test_cookbook3' => Chef::CookbookVersion.new('test_cookbook3') } @cookbook_loader = {} - @cookbook_loader.stub!(:merged_cookbooks).and_return([]) + @cookbook_loader.stub(:merged_cookbooks).and_return([]) @cookbook_loader.stub(:[]) { |ckbk| @cookbooks[ckbk] } - Chef::CookbookLoader.stub!(:new).and_return(@cookbook_loader) + Chef::CookbookLoader.stub(:new).and_return(@cookbook_loader) end it "should read only one cookbook" do @@ -130,16 +130,16 @@ describe Chef::Knife::CookbookUpload do @test_cookbook2.metadata.depends("test_cookbook3") @test_cookbook3.metadata.depends("test_cookbook1") @test_cookbook3.metadata.depends("test_cookbook2") - @cookbook_loader.stub!(:[]) do |ckbk| + @cookbook_loader.stub(:[]) do |ckbk| { "test_cookbook1" => @test_cookbook1, "test_cookbook2" => @test_cookbook2, "test_cookbook3" => @test_cookbook3 }[ckbk] end - @knife.stub!(:cookbook_names).and_return(["test_cookbook1", "test_cookbook2", "test_cookbook3"]) + @knife.stub(:cookbook_names).and_return(["test_cookbook1", "test_cookbook2", "test_cookbook3"]) @knife.should_receive(:upload).exactly(3).times Timeout::timeout(5) do @knife.run - end.should_not raise_error(Timeout::Error) + end.should_not raise_error end end @@ -154,8 +154,8 @@ describe Chef::Knife::CookbookUpload do @knife.config[:all] = true @test_cookbook1 = Chef::CookbookVersion.new('test_cookbook1') @test_cookbook2 = Chef::CookbookVersion.new('test_cookbook2') - @cookbook_loader.stub!(:each).and_yield("test_cookbook1", @test_cookbook1).and_yield("test_cookbook2", @test_cookbook2) - @cookbook_loader.stub!(:cookbook_names).and_return(["test_cookbook1", "test_cookbook2"]) + @cookbook_loader.stub(:each).and_yield("test_cookbook1", @test_cookbook1).and_yield("test_cookbook2", @test_cookbook2) + @cookbook_loader.stub(:cookbook_names).and_return(["test_cookbook1", "test_cookbook2"]) end it 'should upload all cookbooks' do @@ -170,7 +170,7 @@ describe Chef::Knife::CookbookUpload do end it 'should update the version constraints for an environment' do - @knife.stub!(:assert_environment_valid!).and_return(true) + @knife.stub(:assert_environment_valid!).and_return(true) @knife.config[:environment] = "production" @knife.should_receive(:update_version_constraints).once @knife.run @@ -188,9 +188,9 @@ describe Chef::Knife::CookbookUpload do end it 'should not update the version constraints for an environment' do - @knife.stub!(:assert_environment_valid!).and_return(true) + @knife.stub(:assert_environment_valid!).and_return(true) @knife.config[:environment] = "production" - @knife.stub!(:upload).and_raise(Chef::Exceptions::CookbookFrozen) + @knife.stub(:upload).and_raise(Chef::Exceptions::CookbookFrozen) @knife.ui.should_receive(:error).with(/Failed to upload 1 cookbook/) @knife.ui.should_receive(:warn).with(/Not updating version constraints/) @knife.should_not_receive(:update_version_constraints) diff --git a/spec/unit/knife/core/cookbook_scm_repo_spec.rb b/spec/unit/knife/core/cookbook_scm_repo_spec.rb index 629164ad0a..69da5400b0 100644 --- a/spec/unit/knife/core/cookbook_scm_repo_spec.rb +++ b/spec/unit/knife/core/cookbook_scm_repo_spec.rb @@ -54,17 +54,17 @@ BRANCHES describe "and the repo dir exists" do before do - ::File.stub!(:directory?).with(@repo_path).and_return(true) + ::File.stub(:directory?).with(@repo_path).and_return(true) end it "exits when there is no git repo" do - ::File.stub!(:directory?).with(/.*\.git/).and_return(false) + ::File.stub(:directory?).with(/.*\.git/).and_return(false) lambda {@cookbook_repo.sanity_check}.should raise_error(SystemExit) end describe "and the repo is a git repo" do before do - ::File.stub!(:directory?).with(File.join(@repo_path, '.git')).and_return(true) + ::File.stub(:directory?).with(File.join(@repo_path, '.git')).and_return(true) end it "exits when the default branch doesn't exist" do @@ -92,7 +92,7 @@ DIRTY describe "and the repo is clean" do before do @clean_status = Mixlib::ShellOut.new.tap {|s| s.stdout.replace("\n")} - @cookbook_repo.stub!(:shell_out!).with('git status --porcelain', :cwd => @repo_path).and_return(@clean_status) + @cookbook_repo.stub(:shell_out!).with('git status --porcelain', :cwd => @repo_path).and_return(@clean_status) end it "passes the sanity check" do @@ -143,7 +143,7 @@ DIRTY before do @updates = Mixlib::ShellOut.new @updates.stdout.replace("\n") - @cookbook_repo.stub!(:shell_out!).with('git status --porcelain -- apache2', :cwd => @repo_path).and_return(@updates) + @cookbook_repo.stub(:shell_out!).with('git status --porcelain -- apache2', :cwd => @repo_path).and_return(@updates) end it "shows no changes in the pristine copy" do @@ -159,7 +159,7 @@ DIRTY before do @updates = Mixlib::ShellOut.new @updates.stdout.replace(" M cookbooks/apache2/recipes/default.rb\n") - @cookbook_repo.stub!(:shell_out!).with('git status --porcelain -- apache2', :cwd => @repo_path).and_return(@updates) + @cookbook_repo.stub(:shell_out!).with('git status --porcelain -- apache2', :cwd => @repo_path).and_return(@updates) end it "shows changes in the pristine copy" do diff --git a/spec/unit/knife/core/object_loader_spec.rb b/spec/unit/knife/core/object_loader_spec.rb index b3456e2b15..53a538da91 100644 --- a/spec/unit/knife/core/object_loader_spec.rb +++ b/spec/unit/knife/core/object_loader_spec.rb @@ -24,7 +24,7 @@ describe Chef::Knife::Core::ObjectLoader do before(:each) do @knife = Chef::Knife.new @stdout = StringIO.new - @knife.ui.stub!(:stdout).and_return(@stdout) + @knife.ui.stub(:stdout).and_return(@stdout) Dir.chdir(File.join(CHEF_SPEC_DATA, 'object_loader')) end diff --git a/spec/unit/knife/core/ui_spec.rb b/spec/unit/knife/core/ui_spec.rb index 18e88b6cde..c626747918 100644 --- a/spec/unit/knife/core/ui_spec.rb +++ b/spec/unit/knife/core/ui_spec.rb @@ -24,7 +24,11 @@ require 'spec_helper' describe Chef::Knife::UI do before do @out, @err, @in = StringIO.new, StringIO.new, StringIO.new - @config = {} + @config = { + :verbosity => 0, + :yes => nil, + :format => "summary", + } @ui = Chef::Knife::UI.new(@out, @err, @in, @config) end @@ -62,7 +66,7 @@ describe Chef::Knife::UI do before do @ui.config[:disable_editing] = false @ui.config[:editor] = my_editor - @mock = mock('Tempfile') + @mock = double('Tempfile') @mock.should_receive(:sync=).with(true) @mock.should_receive(:puts).with(json_from_ruby) @mock.should_receive(:close) @@ -168,7 +172,7 @@ describe Chef::Knife::UI do it "should ignore Errno::EPIPE exceptions (CHEF-3516)" do @out.stub(:puts).and_raise(Errno::EPIPE) @err.stub(:puts).and_raise(Errno::EPIPE) - lambda {@ui.send(method, "hi")}.should_not raise_error(Errno::EPIPE) + lambda {@ui.send(method, "hi")}.should raise_error(SystemExit) end it "should throw Errno::EPIPE exceptions with -VV (CHEF-3516)" do @@ -298,15 +302,9 @@ EOM it "formats hashes with nested array values appropriately" do @ui.output({ 'a' => [ [ 'foo', 'bar' ], [ 'baz', 'bjork' ] ], 'b' => 'c' }) - @out.string.should == <<EOM -a: - foo - bar - - baz - bjork -b: c -EOM + # XXX: using a HEREDOC at this point results in a line with required spaces which auto-whitespace removal settings + # on editors will remove and will break this test. + @out.string.should == "a:\n foo\n bar\n \n baz\n bjork\nb: c\n" end it "formats hashes with hash values appropriately" do @@ -412,28 +410,28 @@ EOM @question = "monkeys rule" @stdout = StringIO.new @ui.stub(:stdout).and_return(@stdout) - @ui.stdin.stub!(:readline).and_return("y") + @ui.stdin.stub(:readline).and_return("y") end it "should return true if you answer Y" do - @ui.stdin.stub!(:readline).and_return("Y") + @ui.stdin.stub(:readline).and_return("Y") @ui.confirm(@question).should == true end it "should return true if you answer y" do - @ui.stdin.stub!(:readline).and_return("y") + @ui.stdin.stub(:readline).and_return("y") @ui.confirm(@question).should == true end it "should exit 3 if you answer N" do - @ui.stdin.stub!(:readline).and_return("N") + @ui.stdin.stub(:readline).and_return("N") lambda { @ui.confirm(@question) }.should raise_error(SystemExit) { |e| e.status.should == 3 } end it "should exit 3 if you answer n" do - @ui.stdin.stub!(:readline).and_return("n") + @ui.stdin.stub(:readline).and_return("n") lambda { @ui.confirm(@question) }.should raise_error(SystemExit) { |e| e.status.should == 3 } @@ -449,16 +447,16 @@ EOM describe "when asking for free-form user input" do it "asks a question and returns the answer provided by the user" do out = StringIO.new - @ui.stub!(:stdout).and_return(out) - @ui.stub!(:stdin).and_return(StringIO.new("http://mychefserver.example.com\n")) + @ui.stub(:stdout).and_return(out) + @ui.stub(:stdin).and_return(StringIO.new("http://mychefserver.example.com\n")) @ui.ask_question("your chef server URL?").should == "http://mychefserver.example.com" out.string.should == "your chef server URL?" end it "suggests a default setting and returns the default when the user's response only contains whitespace" do out = StringIO.new - @ui.stub!(:stdout).and_return(out) - @ui.stub!(:stdin).and_return(StringIO.new(" \n")) + @ui.stub(:stdout).and_return(out) + @ui.stub(:stdin).and_return(StringIO.new(" \n")) @ui.ask_question("your chef server URL? ", :default => 'http://localhost:4000').should == "http://localhost:4000" out.string.should == "your chef server URL? [http://localhost:4000] " end diff --git a/spec/unit/knife/data_bag_create_spec.rb b/spec/unit/knife/data_bag_create_spec.rb index b2f24bbb39..984be8e58a 100644 --- a/spec/unit/knife/data_bag_create_spec.rb +++ b/spec/unit/knife/data_bag_create_spec.rb @@ -39,9 +39,9 @@ describe Chef::Knife::DataBagCreate do Chef::Config[:node_name] = "webmonkey.example.com" @knife = Chef::Knife::DataBagCreate.new @rest = ChefSpecs::ChefRest.new - @knife.stub!(:rest).and_return(@rest) + @knife.stub(:rest).and_return(@rest) @stdout = StringIO.new - @knife.ui.stub!(:stdout).and_return(@stdout) + @knife.ui.stub(:stdout).and_return(@stdout) end @@ -101,7 +101,7 @@ describe Chef::Knife::DataBagCreate do end it "creates an encrypted data bag item via --secret" do - @knife.stub!(:config).and_return({:secret => @secret}) + @knife.stub(:config).and_return({:secret => @secret}) @knife.run end @@ -109,7 +109,7 @@ describe Chef::Knife::DataBagCreate do secret_file = Tempfile.new("encrypted_data_bag_secret_file_test") secret_file.puts(@secret) secret_file.flush - @knife.stub!(:config).and_return({:secret_file => secret_file.path}) + @knife.stub(:config).and_return({:secret_file => secret_file.path}) @knife.run end end diff --git a/spec/unit/knife/data_bag_edit_spec.rb b/spec/unit/knife/data_bag_edit_spec.rb index 412a237321..866ca99174 100644 --- a/spec/unit/knife/data_bag_edit_spec.rb +++ b/spec/unit/knife/data_bag_edit_spec.rb @@ -29,11 +29,11 @@ describe Chef::Knife::DataBagEdit do Chef::Config[:node_name] = "webmonkey.example.com" @knife = Chef::Knife::DataBagEdit.new - @rest = mock('chef-rest-mock') - @knife.stub!(:rest).and_return(@rest) + @rest = double('chef-rest-mock') + @knife.stub(:rest).and_return(@rest) @stdout = StringIO.new - @knife.stub!(:stdout).and_return(@stdout) + @knife.stub(:stdout).and_return(@stdout) @log = Chef::Log @knife.name_args = ['bag_name', 'item_name'] end @@ -45,7 +45,7 @@ describe Chef::Knife::DataBagEdit do end it "saves edits on a data bag item" do - Chef::DataBagItem.stub!(:load).with('bag_name', 'item_name').and_return(@plain_data) + Chef::DataBagItem.stub(:load).with('bag_name', 'item_name').and_return(@plain_data) @knife.should_receive(:edit_data).with(@plain_data).and_return(@edited_data) @rest.should_receive(:put_rest).with("data/bag_name/item_name", @edited_data).ordered @knife.run @@ -58,7 +58,7 @@ describe Chef::Knife::DataBagEdit do @secret) @enc_edited_data = Chef::EncryptedDataBagItem.encrypt_data_bag_item(@edited_data, @secret) - Chef::DataBagItem.stub!(:load).with('bag_name', 'item_name').and_return(@enc_data) + Chef::DataBagItem.stub(:load).with('bag_name', 'item_name').and_return(@enc_data) # Random IV is used each time the data bag item is encrypted, so values # will not be equal if we encrypt same value twice. @@ -75,7 +75,7 @@ describe Chef::Knife::DataBagEdit do end it "decrypts and encrypts via --secret" do - @knife.stub!(:config).and_return({:secret => @secret}) + @knife.stub(:config).and_return({:secret => @secret}) @knife.should_receive(:edit_data).with(@plain_data).and_return(@edited_data) @rest.should_receive(:put_rest).with("data/bag_name/item_name", @enc_edited_data).ordered @@ -83,7 +83,7 @@ describe Chef::Knife::DataBagEdit do end it "decrypts and encrypts via --secret_file" do - @knife.stub!(:config).and_return({:secret_file => @secret_file.path}) + @knife.stub(:config).and_return({:secret_file => @secret_file.path}) @knife.should_receive(:edit_data).with(@plain_data).and_return(@edited_data) @rest.should_receive(:put_rest).with("data/bag_name/item_name", @enc_edited_data).ordered diff --git a/spec/unit/knife/data_bag_from_file_spec.rb b/spec/unit/knife/data_bag_from_file_spec.rb index cef1babd0b..8537045164 100644 --- a/spec/unit/knife/data_bag_from_file_spec.rb +++ b/spec/unit/knife/data_bag_from_file_spec.rb @@ -29,10 +29,10 @@ describe Chef::Knife::DataBagFromFile do before :each do Chef::Config[:node_name] = "webmonkey.example.com" @knife = Chef::Knife::DataBagFromFile.new - @rest = mock("Chef::REST") - @knife.stub!(:rest).and_return(@rest) + @rest = double("Chef::REST") + @knife.stub(:rest).and_return(@rest) @stdout = StringIO.new - @knife.ui.stub!(:stdout).and_return(@stdout) + @knife.ui.stub(:stdout).and_return(@stdout) @tmp_dir = Dir.mktmpdir @db_folder = File.join(@tmp_dir, 'data_bags', 'bag_name') FileUtils.mkdir_p(@db_folder) @@ -64,7 +64,7 @@ describe Chef::Knife::DataBagFromFile do it "loads from a file and saves" do @knife.loader.should_receive(:load_from).with("data_bags", 'bag_name', @db_file.path).and_return(@plain_data) dbag = Chef::DataBagItem.new - Chef::DataBagItem.stub!(:new).and_return(dbag) + Chef::DataBagItem.stub(:new).and_return(dbag) dbag.should_receive(:save) @knife.run @@ -77,7 +77,7 @@ describe Chef::Knife::DataBagFromFile do @knife.loader.should_receive(:load_from).with("data_bags", 'bag_name', @db_file.path).and_return(@plain_data) @knife.loader.should_receive(:load_from).with("data_bags", 'bag_name', @db_file2.path).and_return(@plain_data) dbag = Chef::DataBagItem.new - Chef::DataBagItem.stub!(:new).and_return(dbag) + Chef::DataBagItem.stub(:new).and_return(dbag) dbag.should_receive(:save).twice @knife.run @@ -91,7 +91,7 @@ describe Chef::Knife::DataBagFromFile do @knife.loader.should_receive(:load_from).with("data_bags", 'bag_name', @db_file.path).and_return(@plain_data) @knife.loader.should_receive(:load_from).with("data_bags", 'bag_name', @db_file2.path).and_return(@plain_data) dbag = Chef::DataBagItem.new - Chef::DataBagItem.stub!(:new).and_return(dbag) + Chef::DataBagItem.stub(:new).and_return(dbag) dbag.should_receive(:save).twice @knife.run end @@ -109,7 +109,7 @@ describe Chef::Knife::DataBagFromFile do it "loads all data bags when -a or --all options is provided" do @knife.name_args = [] - @knife.stub!(:config).and_return({:all => true}) + @knife.stub(:config).and_return({:all => true}) @knife.loader.should_receive(:load_from).with("data_bags", "bag_name", File.basename(@db_file.path)). and_return(@plain_data) @knife.loader.should_receive(:load_from).with("data_bags", "bag_name", File.basename(@db_file2.path)). @@ -117,18 +117,18 @@ describe Chef::Knife::DataBagFromFile do @knife.loader.should_receive(:load_from).with("data_bags", "bag_name2", File.basename(@db_file3.path)). and_return(@plain_data) dbag = Chef::DataBagItem.new - Chef::DataBagItem.stub!(:new).and_return(dbag) + Chef::DataBagItem.stub(:new).and_return(dbag) dbag.should_receive(:save).exactly(3).times @knife.run end it "loads all data bags items when -a or --all options is provided" do @knife.name_args = ["bag_name2"] - @knife.stub!(:config).and_return({:all => true}) + @knife.stub(:config).and_return({:all => true}) @knife.loader.should_receive(:load_from).with("data_bags", "bag_name2", File.basename(@db_file3.path)). and_return(@plain_data) dbag = Chef::DataBagItem.new - Chef::DataBagItem.stub!(:new).and_return(dbag) + Chef::DataBagItem.stub(:new).and_return(dbag) dbag.should_receive(:save) @knife.run dbag.data_bag.should == 'bag_name2' @@ -158,11 +158,11 @@ describe Chef::Knife::DataBagFromFile do end it "encrypts values when given --secret" do - @knife.stub!(:config).and_return({:secret => @secret}) + @knife.stub(:config).and_return({:secret => @secret}) @knife.loader.should_receive(:load_from).with("data_bags", "bag_name", @db_file.path).and_return(@plain_data) dbag = Chef::DataBagItem.new - Chef::DataBagItem.stub!(:new).and_return(dbag) + Chef::DataBagItem.stub(:new).and_return(dbag) dbag.should_receive(:save) @knife.run dbag.data_bag.should == 'bag_name' @@ -170,11 +170,11 @@ describe Chef::Knife::DataBagFromFile do end it "encrypts values when given --secret_file" do - @knife.stub!(:config).and_return({:secret_file => @secret_file.path}) + @knife.stub(:config).and_return({:secret_file => @secret_file.path}) - @knife.loader.stub!(:load_from).with("data_bags", 'bag_name', @db_file.path).and_return(@plain_data) + @knife.loader.stub(:load_from).with("data_bags", 'bag_name', @db_file.path).and_return(@plain_data) dbag = Chef::DataBagItem.new - Chef::DataBagItem.stub!(:new).and_return(dbag) + Chef::DataBagItem.stub(:new).and_return(dbag) dbag.should_receive(:save) @knife.run dbag.data_bag.should == 'bag_name' diff --git a/spec/unit/knife/data_bag_show_spec.rb b/spec/unit/knife/data_bag_show_spec.rb index d64b4f286d..d8d1077d0d 100644 --- a/spec/unit/knife/data_bag_show_spec.rb +++ b/spec/unit/knife/data_bag_show_spec.rb @@ -29,10 +29,10 @@ describe Chef::Knife::DataBagShow do Chef::Config[:node_name] = "webmonkey.example.com" @knife = Chef::Knife::DataBagShow.new @knife.config[:format] = 'json' - @rest = mock("Chef::REST") - @knife.stub!(:rest).and_return(@rest) + @rest = double("Chef::REST") + @knife.stub(:rest).and_return(@rest) @stdout = StringIO.new - @knife.ui.stub!(:stdout).and_return(@stdout) + @knife.ui.stub(:stdout).and_return(@stdout) end @@ -83,7 +83,7 @@ describe Chef::Knife::DataBagShow do end it "prints the decrypted contents of an item when given --secret" do - @knife.stub!(:config).and_return({:secret => @secret}) + @knife.stub(:config).and_return({:secret => @secret}) Chef::EncryptedDataBagItem.should_receive(:load). with('bag_name', 'item_name', @secret). and_return(Chef::EncryptedDataBagItem.new(@enc_data, @secret)) @@ -92,7 +92,7 @@ describe Chef::Knife::DataBagShow do end it "prints the decrypted contents of an item when given --secret_file" do - @knife.stub!(:config).and_return({:secret_file => @secret_file.path}) + @knife.stub(:config).and_return({:secret_file => @secret_file.path}) Chef::EncryptedDataBagItem.should_receive(:load). with('bag_name', 'item_name', @secret). and_return(Chef::EncryptedDataBagItem.new(@enc_data, @secret)) diff --git a/spec/unit/knife/environment_create_spec.rb b/spec/unit/knife/environment_create_spec.rb index 36f6556682..81bf6731b7 100644 --- a/spec/unit/knife/environment_create_spec.rb +++ b/spec/unit/knife/environment_create_spec.rb @@ -21,16 +21,16 @@ require 'spec_helper' describe Chef::Knife::EnvironmentCreate do before(:each) do @knife = Chef::Knife::EnvironmentCreate.new - @knife.stub!(:msg).and_return true - @knife.stub!(:output).and_return true - @knife.stub!(:show_usage).and_return true + @knife.stub(:msg).and_return true + @knife.stub(:output).and_return true + @knife.stub(:show_usage).and_return true @knife.name_args = [ "production" ] @environment = Chef::Environment.new - @environment.stub!(:save) + @environment.stub(:save) - Chef::Environment.stub!(:new).and_return @environment - @knife.stub!(:edit_data).and_return @environment + Chef::Environment.stub(:new).and_return @environment + @knife.stub(:edit_data).and_return @environment end describe "run" do diff --git a/spec/unit/knife/environment_delete_spec.rb b/spec/unit/knife/environment_delete_spec.rb index 219ae4a923..0f6b5f3272 100644 --- a/spec/unit/knife/environment_delete_spec.rb +++ b/spec/unit/knife/environment_delete_spec.rb @@ -21,17 +21,17 @@ require 'spec_helper' describe Chef::Knife::EnvironmentDelete do before(:each) do @knife = Chef::Knife::EnvironmentDelete.new - @knife.stub!(:msg).and_return true - @knife.stub!(:output).and_return true - @knife.stub!(:show_usage).and_return true - @knife.stub!(:confirm).and_return true + @knife.stub(:msg).and_return true + @knife.stub(:output).and_return true + @knife.stub(:show_usage).and_return true + @knife.stub(:confirm).and_return true @knife.name_args = [ "production" ] @environment = Chef::Environment.new @environment.name("production") @environment.description("Please delete me") - @environment.stub!(:destroy).and_return true - Chef::Environment.stub!(:load).and_return @environment + @environment.stub(:destroy).and_return true + Chef::Environment.stub(:load).and_return @environment end it "should confirm that you want to delete" do diff --git a/spec/unit/knife/environment_edit_spec.rb b/spec/unit/knife/environment_edit_spec.rb index 91f9f5d0f0..a82ead0b6b 100644 --- a/spec/unit/knife/environment_edit_spec.rb +++ b/spec/unit/knife/environment_edit_spec.rb @@ -21,16 +21,16 @@ require 'spec_helper' describe Chef::Knife::EnvironmentEdit do before(:each) do @knife = Chef::Knife::EnvironmentEdit.new - @knife.ui.stub!(:msg).and_return true - @knife.ui.stub!(:output).and_return true - @knife.ui.stub!(:show_usage).and_return true + @knife.ui.stub(:msg).and_return true + @knife.ui.stub(:output).and_return true + @knife.ui.stub(:show_usage).and_return true @knife.name_args = [ "production" ] @environment = Chef::Environment.new @environment.name("production") @environment.description("Please edit me") - @environment.stub!(:save).and_return true - Chef::Environment.stub!(:load).and_return @environment + @environment.stub(:save).and_return true + Chef::Environment.stub(:load).and_return @environment @knife.ui.stub(:edit_data).and_return @environment end diff --git a/spec/unit/knife/environment_from_file_spec.rb b/spec/unit/knife/environment_from_file_spec.rb index 7d028ae3b8..f208320c5d 100644 --- a/spec/unit/knife/environment_from_file_spec.rb +++ b/spec/unit/knife/environment_from_file_spec.rb @@ -25,15 +25,15 @@ describe Chef::Knife::EnvironmentFromFile do before(:each) do @knife = Chef::Knife::EnvironmentFromFile.new @stdout = StringIO.new - @knife.ui.stub!(:stdout).and_return(@stdout) + @knife.ui.stub(:stdout).and_return(@stdout) @knife.name_args = [ "spec.rb" ] @environment = Chef::Environment.new @environment.name("spec") @environment.description("runs the unit tests") @environment.cookbook_versions({"apt" => "= 1.2.3"}) - @environment.stub!(:save).and_return true - @knife.loader.stub!(:load_from).and_return @environment + @environment.stub(:save).and_return true + @knife.loader.stub(:load_from).and_return @environment end describe "run" do @@ -47,7 +47,7 @@ describe Chef::Knife::EnvironmentFromFile do before(:each) do @env_apple = @environment.dup @env_apple.name("apple") - @knife.loader.stub!(:load_from).with("apple.rb").and_return @env_apple + @knife.loader.stub(:load_from).with("apple.rb").and_return @env_apple end it "loads multiple environments if given" do @@ -57,10 +57,10 @@ describe Chef::Knife::EnvironmentFromFile do end it "loads all environments with -a" do - File.stub!(:expand_path).with("./environments/*.{json,rb}").and_return("/tmp/environments") - Dir.stub!(:glob).with("/tmp/environments").and_return(["spec.rb", "apple.rb"]) + File.stub(:expand_path).with("./environments/*.{json,rb}").and_return("/tmp/environments") + Dir.stub(:glob).with("/tmp/environments").and_return(["spec.rb", "apple.rb"]) @knife.name_args = [] - @knife.stub!(:config).and_return({:all => true}) + @knife.stub(:config).and_return({:all => true}) @environment.should_receive(:save).twice @knife.run end diff --git a/spec/unit/knife/environment_list_spec.rb b/spec/unit/knife/environment_list_spec.rb index 05a3ae748a..25d2714d23 100644 --- a/spec/unit/knife/environment_list_spec.rb +++ b/spec/unit/knife/environment_list_spec.rb @@ -21,16 +21,16 @@ require 'spec_helper' describe Chef::Knife::EnvironmentList do before(:each) do @knife = Chef::Knife::EnvironmentList.new - @knife.stub!(:msg).and_return true - @knife.stub!(:output).and_return true - @knife.stub!(:show_usage).and_return true + @knife.stub(:msg).and_return true + @knife.stub(:output).and_return true + @knife.stub(:show_usage).and_return true @environments = { "production" => "http://localhost:4000/environments/production", "development" => "http://localhost:4000/environments/development", "testing" => "http://localhost:4000/environments/testing" } - Chef::Environment.stub!(:list).and_return @environments + Chef::Environment.stub(:list).and_return @environments end it "should make an api call to list the environments" do diff --git a/spec/unit/knife/environment_show_spec.rb b/spec/unit/knife/environment_show_spec.rb index 1e1556f4c3..c7b0c21657 100644 --- a/spec/unit/knife/environment_show_spec.rb +++ b/spec/unit/knife/environment_show_spec.rb @@ -21,15 +21,15 @@ require 'spec_helper' describe Chef::Knife::EnvironmentShow do before(:each) do @knife = Chef::Knife::EnvironmentShow.new - @knife.stub!(:msg).and_return true - @knife.stub!(:output).and_return true - @knife.stub!(:show_usage).and_return true + @knife.stub(:msg).and_return true + @knife.stub(:output).and_return true + @knife.stub(:show_usage).and_return true @knife.name_args = [ "production" ] @environment = Chef::Environment.new @environment.name("production") @environment.description("Look at me!") - Chef::Environment.stub!(:load).and_return @environment + Chef::Environment.stub(:load).and_return @environment end it "should load the environment" do diff --git a/spec/unit/knife/index_rebuild_spec.rb b/spec/unit/knife/index_rebuild_spec.rb index eb4e8020c8..3a8ec00651 100644 --- a/spec/unit/knife/index_rebuild_spec.rb +++ b/spec/unit/knife/index_rebuild_spec.rb @@ -21,7 +21,7 @@ require 'spec_helper' describe Chef::Knife::IndexRebuild do let(:knife){Chef::Knife::IndexRebuild.new} - let(:rest_client){mock(Chef::REST)} + let(:rest_client){double(Chef::REST)} let(:stub_rest!) do knife.should_receive(:rest).and_return(rest_client) @@ -29,7 +29,7 @@ describe Chef::Knife::IndexRebuild do before :each do # This keeps the test output clean - knife.ui.stub!(:stdout).and_return(StringIO.new) + knife.ui.stub(:stdout).and_return(StringIO.new) end context "#grab_api_info" do diff --git a/spec/unit/knife/knife_help.rb b/spec/unit/knife/knife_help.rb index f5753e3d62..e66a44801b 100644 --- a/spec/unit/knife/knife_help.rb +++ b/spec/unit/knife/knife_help.rb @@ -37,10 +37,10 @@ describe Chef::Knife::Help do it "should suggest topics" do @knife.name_args = [ "list" ] - @knife.ui.stub!(:msg) + @knife.ui.stub(:msg) @knife.ui.should_receive(:info).with("Available help topics are: ") @knife.ui.should_receive(:msg).with(/knife/) - @knife.stub!(:exec) + @knife.stub(:exec) @knife.should_receive(:exit).with(1) @knife.run end @@ -57,9 +57,9 @@ describe Chef::Knife::Help do describe "find_manpages_for_query" do it "should error if it does not find a match" do - @knife.ui.stub!(:error) - @knife.ui.stub!(:info) - @knife.ui.stub!(:msg) + @knife.ui.stub(:error) + @knife.ui.stub(:info) + @knife.ui.stub(:msg) @knife.should_receive(:exit).with(1) @knife.ui.should_receive(:error).with("No help found for 'chickens'") @knife.ui.should_receive(:msg).with(/knife/) @@ -69,22 +69,22 @@ describe Chef::Knife::Help do describe "print_help_topics" do it "should print the known help topics" do - @knife.ui.stub!(:msg) - @knife.ui.stub!(:info) + @knife.ui.stub(:msg) + @knife.ui.stub(:info) @knife.ui.should_receive(:msg).with(/knife/) @knife.print_help_topics end it "should shorten topics prefixed by knife-" do - @knife.ui.stub!(:msg) - @knife.ui.stub!(:info) + @knife.ui.stub(:msg) + @knife.ui.stub(:info) @knife.ui.should_receive(:msg).with(/node/) @knife.print_help_topics end it "should not leave topics prefixed by knife-" do - @knife.ui.stub!(:msg) - @knife.ui.stub!(:info) + @knife.ui.stub(:msg) + @knife.ui.stub(:info) @knife.ui.should_not_receive(:msg).with(/knife-node/) @knife.print_help_topics end diff --git a/spec/unit/knife/node_bulk_delete_spec.rb b/spec/unit/knife/node_bulk_delete_spec.rb index 51f707dfcf..3faece5469 100644 --- a/spec/unit/knife/node_bulk_delete_spec.rb +++ b/spec/unit/knife/node_bulk_delete_spec.rb @@ -26,8 +26,8 @@ describe Chef::Knife::NodeBulkDelete do @knife = Chef::Knife::NodeBulkDelete.new @knife.name_args = ["."] @stdout = StringIO.new - @knife.ui.stub!(:stdout).and_return(@stdout) - @knife.ui.stub!(:confirm).and_return(true) + @knife.ui.stub(:stdout).and_return(@stdout) + @knife.ui.stub(:confirm).and_return(true) @nodes = Hash.new %w{adam brent jacob}.each do |node_name| @nodes[node_name] = "http://localhost:4000/nodes/#{node_name}" @@ -53,11 +53,11 @@ describe Chef::Knife::NodeBulkDelete do @inflatedish_list = @nodes.keys.inject({}) do |nodes_by_name, name| node = Chef::Node.new() node.name(name) - node.stub!(:destroy).and_return(true) + node.stub(:destroy).and_return(true) nodes_by_name[name] = node nodes_by_name end - @knife.stub!(:all_nodes).and_return(@inflatedish_list) + @knife.stub(:all_nodes).and_return(@inflatedish_list) end it "should print the nodes you are about to delete" do diff --git a/spec/unit/knife/node_delete_spec.rb b/spec/unit/knife/node_delete_spec.rb index bc30ae7e83..04eca389c6 100644 --- a/spec/unit/knife/node_delete_spec.rb +++ b/spec/unit/knife/node_delete_spec.rb @@ -26,13 +26,13 @@ describe Chef::Knife::NodeDelete do :print_after => nil } @knife.name_args = [ "adam" ] - @knife.stub!(:output).and_return(true) - @knife.stub!(:confirm).and_return(true) + @knife.stub(:output).and_return(true) + @knife.stub(:confirm).and_return(true) @node = Chef::Node.new() - @node.stub!(:destroy).and_return(true) - Chef::Node.stub!(:load).and_return(@node) + @node.stub(:destroy).and_return(true) + Chef::Node.stub(:load).and_return(@node) @stdout = StringIO.new - @knife.ui.stub!(:stdout).and_return(@stdout) + @knife.ui.stub(:stdout).and_return(@stdout) end describe "run" do diff --git a/spec/unit/knife/node_edit_spec.rb b/spec/unit/knife/node_edit_spec.rb index 7fbd8192d1..27db3416f4 100644 --- a/spec/unit/knife/node_edit_spec.rb +++ b/spec/unit/knife/node_edit_spec.rb @@ -45,7 +45,7 @@ describe Chef::Knife::NodeEdit do describe "after loading the node" do before do - @knife.stub!(:node).and_return(@node) + @knife.stub(:node).and_return(@node) @node.automatic_attrs = {:go => :away} @node.default_attrs = {:hide => :me} @node.override_attrs = {:dont => :show} @@ -94,7 +94,7 @@ describe Chef::Knife::NodeEdit do describe "edit_node" do before do - @knife.stub!(:node).and_return(@node) + @knife.stub(:node).and_return(@node) end let(:subject) { @knife.node_editor.edit_node } diff --git a/spec/unit/knife/node_from_file_spec.rb b/spec/unit/knife/node_from_file_spec.rb index c6b9610d9e..56a2a08b68 100644 --- a/spec/unit/knife/node_from_file_spec.rb +++ b/spec/unit/knife/node_from_file_spec.rb @@ -28,13 +28,13 @@ describe Chef::Knife::NodeFromFile do :print_after => nil } @knife.name_args = [ "adam.rb" ] - @knife.stub!(:output).and_return(true) - @knife.stub!(:confirm).and_return(true) + @knife.stub(:output).and_return(true) + @knife.stub(:confirm).and_return(true) @node = Chef::Node.new() - @node.stub!(:save) - @knife.loader.stub!(:load_from).and_return(@node) + @node.stub(:save) + @knife.loader.stub(:load_from).and_return(@node) @stdout = StringIO.new - @knife.ui.stub!(:stdout).and_return(@stdout) + @knife.ui.stub(:stdout).and_return(@stdout) end describe "run" do diff --git a/spec/unit/knife/node_list_spec.rb b/spec/unit/knife/node_list_spec.rb index 3482eab87c..cad2d6482d 100644 --- a/spec/unit/knife/node_list_spec.rb +++ b/spec/unit/knife/node_list_spec.rb @@ -23,13 +23,13 @@ describe Chef::Knife::NodeList do Chef::Config[:node_name] = "webmonkey.example.com" Chef::Config[:environment] = nil # reset this value each time, as it is not reloaded @knife = Chef::Knife::NodeList.new - @knife.stub!(:output).and_return(true) + @knife.stub(:output).and_return(true) @list = { "foo" => "http://example.com/foo", "bar" => "http://example.com/foo" } - Chef::Node.stub!(:list).and_return(@list) - Chef::Node.stub!(:list_by_environment).and_return(@list) + Chef::Node.stub(:list).and_return(@list) + Chef::Node.stub(:list_by_environment).and_return(@list) end describe "run" do diff --git a/spec/unit/knife/node_run_list_add_spec.rb b/spec/unit/knife/node_run_list_add_spec.rb index 80e372c30a..61f2e6af4c 100644 --- a/spec/unit/knife/node_run_list_add_spec.rb +++ b/spec/unit/knife/node_run_list_add_spec.rb @@ -26,10 +26,10 @@ describe Chef::Knife::NodeRunListAdd do :after => nil } @knife.name_args = [ "adam", "role[monkey]" ] - @knife.stub!(:output).and_return(true) + @knife.stub(:output).and_return(true) @node = Chef::Node.new() - @node.stub!(:save).and_return(true) - Chef::Node.stub!(:load).and_return(@node) + @node.stub(:save).and_return(true) + Chef::Node.stub(:load).and_return(@node) end describe "run" do diff --git a/spec/unit/knife/node_run_list_remove_spec.rb b/spec/unit/knife/node_run_list_remove_spec.rb index 90869e8baa..5a008a3e07 100644 --- a/spec/unit/knife/node_run_list_remove_spec.rb +++ b/spec/unit/knife/node_run_list_remove_spec.rb @@ -27,12 +27,12 @@ describe Chef::Knife::NodeRunListRemove do @node = Chef::Node.new() @node.name("knifetest-node") @node.run_list << "role[monkey]" - @node.stub!(:save).and_return(true) + @node.stub(:save).and_return(true) - @knife.ui.stub!(:output).and_return(true) - @knife.ui.stub!(:confirm).and_return(true) + @knife.ui.stub(:output).and_return(true) + @knife.ui.stub(:confirm).and_return(true) - Chef::Node.stub!(:load).and_return(@node) + Chef::Node.stub(:load).and_return(@node) end describe "run" do diff --git a/spec/unit/knife/node_run_list_set_spec.rb b/spec/unit/knife/node_run_list_set_spec.rb index bc102695ee..02281f8385 100644 --- a/spec/unit/knife/node_run_list_set_spec.rb +++ b/spec/unit/knife/node_run_list_set_spec.rb @@ -24,10 +24,10 @@ describe Chef::Knife::NodeRunListSet do @knife = Chef::Knife::NodeRunListSet.new @knife.config = {} @knife.name_args = [ "adam", "role[monkey]" ] - @knife.stub!(:output).and_return(true) + @knife.stub(:output).and_return(true) @node = Chef::Node.new() - @node.stub!(:save).and_return(true) - Chef::Node.stub!(:load).and_return(@node) + @node.stub(:save).and_return(true) + Chef::Node.stub(:load).and_return(@node) end describe "run" do @@ -117,8 +117,8 @@ describe Chef::Knife::NodeRunListSet do @stdout = StringIO.new @stderr = StringIO.new - @knife.ui.stub!(:stdout).and_return(@stdout) - @knife.ui.stub!(:stderr).and_return(@stderr) + @knife.ui.stub(:stdout).and_return(@stdout) + @knife.ui.stub(:stderr).and_return(@stderr) end it "should exit" do diff --git a/spec/unit/knife/node_show_spec.rb b/spec/unit/knife/node_show_spec.rb index eb3593fea1..72a269278e 100644 --- a/spec/unit/knife/node_show_spec.rb +++ b/spec/unit/knife/node_show_spec.rb @@ -28,9 +28,9 @@ describe Chef::Knife::NodeShow do :environment => nil } @knife.name_args = [ "adam" ] - @knife.stub!(:output).and_return(true) + @knife.stub(:output).and_return(true) @node = Chef::Node.new() - Chef::Node.stub!(:load).and_return(@node) + Chef::Node.stub(:load).and_return(@node) end describe "run" do diff --git a/spec/unit/knife/role_bulk_delete_spec.rb b/spec/unit/knife/role_bulk_delete_spec.rb index 0ee84f6455..eb1d3b4cff 100644 --- a/spec/unit/knife/role_bulk_delete_spec.rb +++ b/spec/unit/knife/role_bulk_delete_spec.rb @@ -27,16 +27,16 @@ describe Chef::Knife::RoleBulkDelete do } @knife.name_args = ["."] @stdout = StringIO.new - @knife.ui.stub!(:stdout).and_return(@stdout) - @knife.ui.stub!(:confirm).and_return(true) + @knife.ui.stub(:stdout).and_return(@stdout) + @knife.ui.stub(:confirm).and_return(true) @roles = Hash.new %w{dev staging production}.each do |role_name| role = Chef::Role.new() role.name(role_name) - role.stub!(:destroy).and_return(true) + role.stub(:destroy).and_return(true) @roles[role_name] = role end - Chef::Role.stub!(:list).and_return(@roles) + Chef::Role.stub(:list).and_return(@roles) end describe "run" do diff --git a/spec/unit/knife/role_create_spec.rb b/spec/unit/knife/role_create_spec.rb index 39fed8fb68..a4d7392b68 100644 --- a/spec/unit/knife/role_create_spec.rb +++ b/spec/unit/knife/role_create_spec.rb @@ -26,13 +26,13 @@ describe Chef::Knife::RoleCreate do :description => nil } @knife.name_args = [ "adam" ] - @knife.stub!(:output).and_return(true) + @knife.stub(:output).and_return(true) @role = Chef::Role.new() - @role.stub!(:save) - Chef::Role.stub!(:new).and_return(@role) - @knife.stub!(:edit_data).and_return(@role) + @role.stub(:save) + Chef::Role.stub(:new).and_return(@role) + @knife.stub(:edit_data).and_return(@role) @stdout = StringIO.new - @knife.ui.stub!(:stdout).and_return(@stdout) + @knife.ui.stub(:stdout).and_return(@stdout) end describe "run" do diff --git a/spec/unit/knife/role_delete_spec.rb b/spec/unit/knife/role_delete_spec.rb index 37b16de7df..0771446d49 100644 --- a/spec/unit/knife/role_delete_spec.rb +++ b/spec/unit/knife/role_delete_spec.rb @@ -26,13 +26,13 @@ describe Chef::Knife::RoleDelete do :print_after => nil } @knife.name_args = [ "adam" ] - @knife.stub!(:output).and_return(true) - @knife.stub!(:confirm).and_return(true) + @knife.stub(:output).and_return(true) + @knife.stub(:confirm).and_return(true) @role = Chef::Role.new() - @role.stub!(:destroy).and_return(true) - Chef::Role.stub!(:load).and_return(@role) + @role.stub(:destroy).and_return(true) + Chef::Role.stub(:load).and_return(@role) @stdout = StringIO.new - @knife.ui.stub!(:stdout).and_return(@stdout) + @knife.ui.stub(:stdout).and_return(@stdout) end describe "run" do diff --git a/spec/unit/knife/role_edit_spec.rb b/spec/unit/knife/role_edit_spec.rb index 3a002f348c..f6d3b41d98 100644 --- a/spec/unit/knife/role_edit_spec.rb +++ b/spec/unit/knife/role_edit_spec.rb @@ -24,12 +24,12 @@ describe Chef::Knife::RoleEdit do @knife = Chef::Knife::RoleEdit.new @knife.config[:print_after] = nil @knife.name_args = [ "adam" ] - @knife.ui.stub!(:output).and_return(true) + @knife.ui.stub(:output).and_return(true) @role = Chef::Role.new() - @role.stub!(:save) - Chef::Role.stub!(:load).and_return(@role) - @knife.ui.stub!(:edit_data).and_return(@role) - @knife.ui.stub!(:msg) + @role.stub(:save) + Chef::Role.stub(:load).and_return(@role) + @knife.ui.stub(:edit_data).and_return(@role) + @knife.ui.stub(:msg) end describe "run" do diff --git a/spec/unit/knife/role_from_file_spec.rb b/spec/unit/knife/role_from_file_spec.rb index 9b81bb14af..986414647c 100644 --- a/spec/unit/knife/role_from_file_spec.rb +++ b/spec/unit/knife/role_from_file_spec.rb @@ -28,13 +28,13 @@ describe Chef::Knife::RoleFromFile do :print_after => nil } @knife.name_args = [ "adam.rb" ] - @knife.stub!(:output).and_return(true) - @knife.stub!(:confirm).and_return(true) + @knife.stub(:output).and_return(true) + @knife.stub(:confirm).and_return(true) @role = Chef::Role.new() - @role.stub!(:save) - @knife.loader.stub!(:load_from).and_return(@role) + @role.stub(:save) + @knife.loader.stub(:load_from).and_return(@role) @stdout = StringIO.new - @knife.ui.stub!(:stdout).and_return(@stdout) + @knife.ui.stub(:stdout).and_return(@stdout) end describe "run" do diff --git a/spec/unit/knife/role_list_spec.rb b/spec/unit/knife/role_list_spec.rb index d0cd3b4413..ef9642c04c 100644 --- a/spec/unit/knife/role_list_spec.rb +++ b/spec/unit/knife/role_list_spec.rb @@ -22,12 +22,12 @@ describe Chef::Knife::RoleList do before(:each) do Chef::Config[:node_name] = "webmonkey.example.com" @knife = Chef::Knife::RoleList.new - @knife.stub!(:output).and_return(true) + @knife.stub(:output).and_return(true) @list = { "foo" => "http://example.com/foo", "bar" => "http://example.com/foo" } - Chef::Role.stub!(:list).and_return(@list) + Chef::Role.stub(:list).and_return(@list) end describe "run" do diff --git a/spec/unit/knife/ssh_spec.rb b/spec/unit/knife/ssh_spec.rb index 01dd742da0..eff7c9ba5b 100644 --- a/spec/unit/knife/ssh_spec.rb +++ b/spec/unit/knife/ssh_spec.rb @@ -45,8 +45,8 @@ describe Chef::Knife::Ssh do end def configure_query(node_array) - @query.stub!(:search).and_return([node_array]) - Chef::Search::Query.stub!(:new).and_return(@query) + @query.stub(:search).and_return([node_array]) + Chef::Search::Query.stub(:new).and_return(@query) end def self.should_return_specified_attributes @@ -99,10 +99,10 @@ describe Chef::Knife::Ssh do context "when there are some hosts found but they do not have an attribute to connect with" do before do - @query.stub!(:search).and_return([[@node_foo, @node_bar]]) + @query.stub(:search).and_return([[@node_foo, @node_bar]]) @node_foo.automatic_attrs[:fqdn] = nil @node_bar.automatic_attrs[:fqdn] = nil - Chef::Search::Query.stub!(:new).and_return(@query) + Chef::Search::Query.stub(:new).and_return(@query) end it "should raise a specific error (CHEF-3402)" do @@ -175,7 +175,7 @@ describe Chef::Knife::Ssh do before :each do @knife.instance_variable_set(:@longest, 0) ssh_config = {:timeout => 50, :user => "locutus", :port => 23 } - Net::SSH.stub!(:configuration_for).with('the.b.org').and_return(ssh_config) + Net::SSH.stub(:configuration_for).with('the.b.org').and_return(ssh_config) end it "uses the port from an ssh config file" do @@ -257,7 +257,7 @@ describe Chef::Knife::Ssh do before do @query = Chef::Search::Query.new @query.should_receive(:search).and_return([[@node_foo]]) - Chef::Search::Query.stub!(:new).and_return(@query) + Chef::Search::Query.stub(:new).and_return(@query) @knife.stub(:ssh_command).and_return(exit_code) @knife.name_args = ['*:*', 'false'] end diff --git a/spec/unit/knife/status_spec.rb b/spec/unit/knife/status_spec.rb index b009997ab1..6d8d9d5b25 100644 --- a/spec/unit/knife/status_spec.rb +++ b/spec/unit/knife/status_spec.rb @@ -25,12 +25,12 @@ describe Chef::Knife::Status do n.automatic_attrs["fqdn"] = "foobar" n.automatic_attrs["ohai_time"] = 1343845969 end - query = mock("Chef::Search::Query") - query.stub!(:search).and_yield(node) - Chef::Search::Query.stub!(:new).and_return(query) + query = double("Chef::Search::Query") + query.stub(:search).and_yield(node) + Chef::Search::Query.stub(:new).and_return(query) @knife = Chef::Knife::Status.new @stdout = StringIO.new - @knife.stub!(:highline).and_return(HighLine.new(StringIO.new, @stdout)) + @knife.stub(:highline).and_return(HighLine.new(StringIO.new, @stdout)) end describe "run" do diff --git a/spec/unit/knife/tag_create_spec.rb b/spec/unit/knife/tag_create_spec.rb index 925d060879..82e3ad68cd 100644 --- a/spec/unit/knife/tag_create_spec.rb +++ b/spec/unit/knife/tag_create_spec.rb @@ -7,10 +7,10 @@ describe Chef::Knife::TagCreate do @knife.name_args = [ Chef::Config[:node_name], "happytag" ] @node = Chef::Node.new - @node.stub! :save - Chef::Node.stub!(:load).and_return @node + @node.stub :save + Chef::Node.stub(:load).and_return @node @stdout = StringIO.new - @knife.ui.stub!(:stdout).and_return(@stdout) + @knife.ui.stub(:stdout).and_return(@stdout) end describe "run" do diff --git a/spec/unit/knife/tag_delete_spec.rb b/spec/unit/knife/tag_delete_spec.rb index ca279033a4..67e3dd3ff0 100644 --- a/spec/unit/knife/tag_delete_spec.rb +++ b/spec/unit/knife/tag_delete_spec.rb @@ -7,11 +7,11 @@ describe Chef::Knife::TagDelete do @knife.name_args = [ Chef::Config[:node_name], "sadtag" ] @node = Chef::Node.new - @node.stub! :save + @node.stub :save @node.tags << "sadtag" << "happytag" - Chef::Node.stub!(:load).and_return @node + Chef::Node.stub(:load).and_return @node @stdout = StringIO.new - @knife.ui.stub!(:stdout).and_return(@stdout) + @knife.ui.stub(:stdout).and_return(@stdout) end describe "run" do diff --git a/spec/unit/knife/tag_list_spec.rb b/spec/unit/knife/tag_list_spec.rb index 0de5d5ebd8..3724a5c0b7 100644 --- a/spec/unit/knife/tag_list_spec.rb +++ b/spec/unit/knife/tag_list_spec.rb @@ -7,9 +7,9 @@ describe Chef::Knife::TagList do @knife.name_args = [ Chef::Config[:node_name], "sadtag" ] @node = Chef::Node.new - @node.stub! :save + @node.stub :save @node.tags << "sadtag" << "happytag" - Chef::Node.stub!(:load).and_return @node + Chef::Node.stub(:load).and_return @node end describe "run" do diff --git a/spec/unit/knife/user_create_spec.rb b/spec/unit/knife/user_create_spec.rb index 0e36e148ac..cc803e99ce 100644 --- a/spec/unit/knife/user_create_spec.rb +++ b/spec/unit/knife/user_create_spec.rb @@ -30,14 +30,14 @@ describe Chef::Knife::UserCreate do @user_with_private_key = Chef::User.new @user_with_private_key.name "a_user" @user_with_private_key.private_key 'private_key' - @user.stub!(:create).and_return(@user_with_private_key) - Chef::User.stub!(:new).and_return(@user) - Chef::User.stub!(:from_hash).and_return(@user) - @knife.stub!(:edit_data).and_return(@user.to_hash) + @user.stub(:create).and_return(@user_with_private_key) + Chef::User.stub(:new).and_return(@user) + Chef::User.stub(:from_hash).and_return(@user) + @knife.stub(:edit_data).and_return(@user.to_hash) @stdout = StringIO.new @stderr = StringIO.new - @knife.ui.stub!(:stdout).and_return(@stdout) - @knife.ui.stub!(:stderr).and_return(@stderr) + @knife.ui.stub(:stdout).and_return(@stdout) + @knife.ui.stub(:stderr).and_return(@stderr) end it "creates a new user" do @@ -78,7 +78,7 @@ describe Chef::Knife::UserCreate do it "writes the private key to a file when --file is specified" do @knife.config[:file] = "/tmp/a_file" - filehandle = mock("filehandle") + filehandle = double("filehandle") filehandle.should_receive(:print).with('private_key') File.should_receive(:open).with("/tmp/a_file", "w").and_yield(filehandle) @knife.run diff --git a/spec/unit/knife/user_reregister_spec.rb b/spec/unit/knife/user_reregister_spec.rb index fddab57467..1cbbdb47d2 100644 --- a/spec/unit/knife/user_reregister_spec.rb +++ b/spec/unit/knife/user_reregister_spec.rb @@ -23,10 +23,10 @@ describe Chef::Knife::UserReregister do Chef::Knife::UserReregister.load_deps @knife = Chef::Knife::UserReregister.new @knife.name_args = [ 'a_user' ] - @user_mock = mock('user_mock', :private_key => "private_key") - Chef::User.stub!(:load).and_return(@user_mock) + @user_mock = double('user_mock', :private_key => "private_key") + Chef::User.stub(:load).and_return(@user_mock) @stdout = StringIO.new - @knife.ui.stub!(:stdout).and_return(@stdout) + @knife.ui.stub(:stdout).and_return(@stdout) end it 'prints usage and exits when a user name is not provided' do diff --git a/spec/unit/knife/user_show_spec.rb b/spec/unit/knife/user_show_spec.rb index f2bd959d15..af8485ad7d 100644 --- a/spec/unit/knife/user_show_spec.rb +++ b/spec/unit/knife/user_show_spec.rb @@ -23,7 +23,7 @@ describe Chef::Knife::UserShow do Chef::Knife::UserShow.load_deps @knife = Chef::Knife::UserShow.new @knife.name_args = [ 'my_user' ] - @user_mock = mock('user_mock') + @user_mock = double('user_mock') end it 'loads and displays the user' do diff --git a/spec/unit/knife_spec.rb b/spec/unit/knife_spec.rb index c6769b182a..daace18106 100644 --- a/spec/unit/knife_spec.rb +++ b/spec/unit/knife_spec.rb @@ -29,14 +29,14 @@ describe Chef::Knife do Chef::Config[:node_name] = "webmonkey.example.com" @knife = Chef::Knife.new - @knife.ui.stub!(:puts) - @knife.ui.stub!(:print) - Chef::Log.stub!(:init) - Chef::Log.stub!(:level) + @knife.ui.stub(:puts) + @knife.ui.stub(:print) + Chef::Log.stub(:init) + Chef::Log.stub(:level) [:debug, :info, :warn, :error, :crit].each do |level_sym| - Chef::Log.stub!(level_sym) + Chef::Log.stub(level_sym) end - Chef::Knife.stub!(:puts) + Chef::Knife.stub(:puts) @stdout = StringIO.new end @@ -52,7 +52,7 @@ describe Chef::Knife do ENV.should_receive(:[]).with("PWD").and_return("/home/someuser/prod/chef-repo") end - Dir.stub!(:pwd).and_return("/home/someuser/codes/chef-repo") + Dir.stub(:pwd).and_return("/home/someuser/codes/chef-repo") end after do @@ -183,7 +183,7 @@ describe Chef::Knife do end it "exits if no subcommand matches the CLI args" do - Chef::Knife.ui.stub!(:stdout).and_return(@stdout) + Chef::Knife.ui.stub(:stdout).and_return(@stdout) Chef::Knife.ui.should_receive(:fatal) lambda {Chef::Knife.run(%w{fuuu uuuu fuuuu})}.should raise_error(SystemExit) { |e| e.status.should_not == 0 } end @@ -264,8 +264,8 @@ describe Chef::Knife do it "formats 401s nicely" do response = Net::HTTPUnauthorized.new("1.1", "401", "Unauthorized") response.instance_variable_set(:@read, true) # I hate you, net/http. - response.stub!(:body).and_return(Chef::JSONCompat.to_json(:error => "y u no syncronize your clock?")) - @knife.stub!(:run).and_raise(Net::HTTPServerException.new("401 Unauthorized", response)) + response.stub(:body).and_return(Chef::JSONCompat.to_json(:error => "y u no syncronize your clock?")) + @knife.stub(:run).and_raise(Net::HTTPServerException.new("401 Unauthorized", response)) @knife.run_with_pretty_exceptions @stderr.string.should match(/ERROR: Failed to authenticate to/) @stdout.string.should match(/Response: y u no syncronize your clock\?/) @@ -274,9 +274,9 @@ describe Chef::Knife do it "formats 403s nicely" do response = Net::HTTPForbidden.new("1.1", "403", "Forbidden") response.instance_variable_set(:@read, true) # I hate you, net/http. - response.stub!(:body).and_return(Chef::JSONCompat.to_json(:error => "y u no administrator")) - @knife.stub!(:run).and_raise(Net::HTTPServerException.new("403 Forbidden", response)) - @knife.stub!(:username).and_return("sadpanda") + response.stub(:body).and_return(Chef::JSONCompat.to_json(:error => "y u no administrator")) + @knife.stub(:run).and_raise(Net::HTTPServerException.new("403 Forbidden", response)) + @knife.stub(:username).and_return("sadpanda") @knife.run_with_pretty_exceptions @stderr.string.should match(%r[ERROR: You authenticated successfully to http.+ as sadpanda but you are not authorized for this action]) @stdout.string.should match(%r[Response: y u no administrator]) @@ -285,8 +285,8 @@ describe Chef::Knife do it "formats 400s nicely" do response = Net::HTTPBadRequest.new("1.1", "400", "Bad Request") response.instance_variable_set(:@read, true) # I hate you, net/http. - response.stub!(:body).and_return(Chef::JSONCompat.to_json(:error => "y u search wrong")) - @knife.stub!(:run).and_raise(Net::HTTPServerException.new("400 Bad Request", response)) + response.stub(:body).and_return(Chef::JSONCompat.to_json(:error => "y u search wrong")) + @knife.stub(:run).and_raise(Net::HTTPServerException.new("400 Bad Request", response)) @knife.run_with_pretty_exceptions @stderr.string.should match(%r[ERROR: The data in your request was invalid]) @stdout.string.should match(%r[Response: y u search wrong]) @@ -295,8 +295,8 @@ describe Chef::Knife do it "formats 404s nicely" do response = Net::HTTPNotFound.new("1.1", "404", "Not Found") response.instance_variable_set(:@read, true) # I hate you, net/http. - response.stub!(:body).and_return(Chef::JSONCompat.to_json(:error => "nothing to see here")) - @knife.stub!(:run).and_raise(Net::HTTPServerException.new("404 Not Found", response)) + response.stub(:body).and_return(Chef::JSONCompat.to_json(:error => "nothing to see here")) + @knife.stub(:run).and_raise(Net::HTTPServerException.new("404 Not Found", response)) @knife.run_with_pretty_exceptions @stderr.string.should match(%r[ERROR: The object you are looking for could not be found]) @stdout.string.should match(%r[Response: nothing to see here]) @@ -305,8 +305,8 @@ describe Chef::Knife do it "formats 500s nicely" do response = Net::HTTPInternalServerError.new("1.1", "500", "Internal Server Error") response.instance_variable_set(:@read, true) # I hate you, net/http. - response.stub!(:body).and_return(Chef::JSONCompat.to_json(:error => "sad trombone")) - @knife.stub!(:run).and_raise(Net::HTTPFatalError.new("500 Internal Server Error", response)) + response.stub(:body).and_return(Chef::JSONCompat.to_json(:error => "sad trombone")) + @knife.stub(:run).and_raise(Net::HTTPFatalError.new("500 Internal Server Error", response)) @knife.run_with_pretty_exceptions @stderr.string.should match(%r[ERROR: internal server error]) @stdout.string.should match(%r[Response: sad trombone]) @@ -315,8 +315,8 @@ describe Chef::Knife do it "formats 502s nicely" do response = Net::HTTPBadGateway.new("1.1", "502", "Bad Gateway") response.instance_variable_set(:@read, true) # I hate you, net/http. - response.stub!(:body).and_return(Chef::JSONCompat.to_json(:error => "sadder trombone")) - @knife.stub!(:run).and_raise(Net::HTTPFatalError.new("502 Bad Gateway", response)) + response.stub(:body).and_return(Chef::JSONCompat.to_json(:error => "sadder trombone")) + @knife.stub(:run).and_raise(Net::HTTPFatalError.new("502 Bad Gateway", response)) @knife.run_with_pretty_exceptions @stderr.string.should match(%r[ERROR: bad gateway]) @stdout.string.should match(%r[Response: sadder trombone]) @@ -325,8 +325,8 @@ describe Chef::Knife do it "formats 503s nicely" do response = Net::HTTPServiceUnavailable.new("1.1", "503", "Service Unavailable") response.instance_variable_set(:@read, true) # I hate you, net/http. - response.stub!(:body).and_return(Chef::JSONCompat.to_json(:error => "saddest trombone")) - @knife.stub!(:run).and_raise(Net::HTTPFatalError.new("503 Service Unavailable", response)) + response.stub(:body).and_return(Chef::JSONCompat.to_json(:error => "saddest trombone")) + @knife.stub(:run).and_raise(Net::HTTPFatalError.new("503 Service Unavailable", response)) @knife.run_with_pretty_exceptions @stderr.string.should match(%r[ERROR: Service temporarily unavailable]) @stdout.string.should match(%r[Response: saddest trombone]) @@ -335,15 +335,15 @@ describe Chef::Knife do it "formats other HTTP errors nicely" do response = Net::HTTPPaymentRequired.new("1.1", "402", "Payment Required") response.instance_variable_set(:@read, true) # I hate you, net/http. - response.stub!(:body).and_return(Chef::JSONCompat.to_json(:error => "nobugfixtillyoubuy")) - @knife.stub!(:run).and_raise(Net::HTTPServerException.new("402 Payment Required", response)) + response.stub(:body).and_return(Chef::JSONCompat.to_json(:error => "nobugfixtillyoubuy")) + @knife.stub(:run).and_raise(Net::HTTPServerException.new("402 Payment Required", response)) @knife.run_with_pretty_exceptions @stderr.string.should match(%r[ERROR: Payment Required]) @stdout.string.should match(%r[Response: nobugfixtillyoubuy]) end it "formats NameError and NoMethodError nicely" do - @knife.stub!(:run).and_raise(NameError.new("Undefined constant FUUU")) + @knife.stub(:run).and_raise(NameError.new("Undefined constant FUUU")) @knife.run_with_pretty_exceptions @stderr.string.should match(%r[ERROR: knife encountered an unexpected error]) @stdout.string.should match(%r[This may be a bug in the 'knife' knife command or plugin]) @@ -351,15 +351,15 @@ describe Chef::Knife do end it "formats missing private key errors nicely" do - @knife.stub!(:run).and_raise(Chef::Exceptions::PrivateKeyMissing.new('key not there')) - @knife.stub!(:api_key).and_return("/home/root/.chef/no-key-here.pem") + @knife.stub(:run).and_raise(Chef::Exceptions::PrivateKeyMissing.new('key not there')) + @knife.stub(:api_key).and_return("/home/root/.chef/no-key-here.pem") @knife.run_with_pretty_exceptions @stderr.string.should match(%r[ERROR: Your private key could not be loaded from /home/root/.chef/no-key-here.pem]) @stdout.string.should match(%r[Check your configuration file and ensure that your private key is readable]) end it "formats connection refused errors nicely" do - @knife.stub!(:run).and_raise(Errno::ECONNREFUSED.new('y u no shut up')) + @knife.stub(:run).and_raise(Errno::ECONNREFUSED.new('y u no shut up')) @knife.run_with_pretty_exceptions # Errno::ECONNREFUSED message differs by platform # *nix = Errno::ECONNREFUSED: Connection refused diff --git a/spec/unit/lwrp_spec.rb b/spec/unit/lwrp_spec.rb index 19d3504f3c..0e0ea5dbb7 100644 --- a/spec/unit/lwrp_spec.rb +++ b/spec/unit/lwrp_spec.rb @@ -33,7 +33,7 @@ describe "LWRP" do describe "when overriding an existing class" do before :each do - $stderr.stub!(:write) + $stderr.stub(:write) end it "should log if attempting to load resource of same name" do @@ -179,7 +179,7 @@ describe "LWRP" do end it "should create a method for each attribute" do - new_resource = mock("new resource", :null_object=>true) + new_resource = double("new resource").as_null_object Chef::Provider::LwrpBuckPasser.new(nil, new_resource).methods.map{|m|m.to_sym}.should include(:action_pass_buck) Chef::Provider::LwrpThumbTwiddler.new(nil, new_resource).methods.map{|m|m.to_sym}.should include(:action_twiddle_thumbs) end diff --git a/spec/unit/mixin/checksum_spec.rb b/spec/unit/mixin/checksum_spec.rb index c0f0acdeb4..54689c9992 100644 --- a/spec/unit/mixin/checksum_spec.rb +++ b/spec/unit/mixin/checksum_spec.rb @@ -29,8 +29,8 @@ describe Chef::Mixin::Checksum do @checksum_user = Chef::CMCCheck.new @cache = Chef::Digester.instance @file = CHEF_SPEC_DATA + "/checksum/random.txt" - @stat = mock("File::Stat", { :mtime => Time.at(0) }) - File.stub!(:stat).and_return(@stat) + @stat = double("File::Stat", { :mtime => Time.at(0) }) + File.stub(:stat).and_return(@stat) end it "gets the checksum of a file" do diff --git a/spec/unit/mixin/command_spec.rb b/spec/unit/mixin/command_spec.rb index a2a2fef461..96660be436 100644 --- a/spec/unit/mixin/command_spec.rb +++ b/spec/unit/mixin/command_spec.rb @@ -76,7 +76,7 @@ describe Chef::Mixin::Command, :volatile do include Chef::Mixin::Command it "logs the command's stderr and stdout output if the command failed" do - Chef::Log.stub!(:level).and_return(:debug) + Chef::Log.stub(:level).and_return(:debug) begin run_command(:command => "sh -c 'echo hello; echo world >&2; false'") violated "Exception expected, but nothing raised." diff --git a/spec/unit/mixin/enforce_ownership_and_permissions_spec.rb b/spec/unit/mixin/enforce_ownership_and_permissions_spec.rb index cffb1b941d..fe72d53de5 100644 --- a/spec/unit/mixin/enforce_ownership_and_permissions_spec.rb +++ b/spec/unit/mixin/enforce_ownership_and_permissions_spec.rb @@ -56,8 +56,8 @@ describe Chef::Mixin::EnforceOwnershipAndPermissions do Struct::Passwd.new("root", "x", 0, 0, "root", "/root", "/bin/bash") end group_struct = OpenStruct.new(:name => "root", :passwd => "x", :gid => 0) - Etc.stub!(:getpwuid).and_return(passwd_struct) - Etc.stub!(:getgrgid).and_return(group_struct) + Etc.stub(:getpwuid).and_return(passwd_struct) + Etc.stub(:getgrgid).and_return(group_struct) end it "does not set updated_by_last_action on the new resource" do @@ -80,8 +80,8 @@ describe Chef::Mixin::EnforceOwnershipAndPermissions do Struct::Passwd.new("root", "x", 0, 0, "root", "/root", "/bin/bash") end group_struct = OpenStruct.new(:name => "root", :passwd => "x", :gid => 0) - Etc.stub!(:getpwuid).and_return(passwd_struct) - Etc.stub!(:getgrgid).and_return(group_struct) + Etc.stub(:getpwuid).and_return(passwd_struct) + Etc.stub(:getgrgid).and_return(group_struct) end it "sets updated_by_last_action on the new resource" do diff --git a/spec/unit/mixin/params_validate_spec.rb b/spec/unit/mixin/params_validate_spec.rb index 2947ebea4a..cc2fe198ca 100644 --- a/spec/unit/mixin/params_validate_spec.rb +++ b/spec/unit/mixin/params_validate_spec.rb @@ -32,7 +32,7 @@ describe Chef::Mixin::ParamsValidate do end it "should allow a hash and a hash as arguments to validate" do - lambda { @vo.validate({:one => "two"}, {}) }.should_not raise_error(ArgumentError) + lambda { @vo.validate({:one => "two"}, {}) }.should_not raise_error end it "should raise an argument error if validate is called incorrectly" do @@ -40,17 +40,17 @@ describe Chef::Mixin::ParamsValidate do end it "should require validation map keys to be symbols or strings" do - lambda { @vo.validate({:one => "two"}, { :one => true }) }.should_not raise_error(ArgumentError) - lambda { @vo.validate({:one => "two"}, { "one" => true }) }.should_not raise_error(ArgumentError) + lambda { @vo.validate({:one => "two"}, { :one => true }) }.should_not raise_error + lambda { @vo.validate({:one => "two"}, { "one" => true }) }.should_not raise_error lambda { @vo.validate({:one => "two"}, { Hash.new => true }) }.should raise_error(ArgumentError) end it "should allow options to be required with true" do - lambda { @vo.validate({:one => "two"}, { :one => true }) }.should_not raise_error(ArgumentError) + lambda { @vo.validate({:one => "two"}, { :one => true }) }.should_not raise_error end it "should allow options to be optional with false" do - lambda { @vo.validate({}, {:one => false})}.should_not raise_error(ArgumentError) + lambda { @vo.validate({}, {:one => false})}.should_not raise_error end it "should allow you to check what kind_of? thing an argument is with kind_of" do @@ -63,7 +63,7 @@ describe Chef::Mixin::ParamsValidate do } } ) - }.should_not raise_error(ArgumentError) + }.should_not raise_error lambda { @vo.validate( @@ -87,7 +87,7 @@ describe Chef::Mixin::ParamsValidate do } } ) - }.should_not raise_error(ArgumentError) + }.should_not raise_error lambda { @vo.validate( @@ -109,7 +109,7 @@ describe Chef::Mixin::ParamsValidate do } } ) - }.should_not raise_error(ArgumentError) + }.should_not raise_error end it "should allow you to specify whether an object has a method with respond_to" do @@ -122,7 +122,7 @@ describe Chef::Mixin::ParamsValidate do } } ) - }.should_not raise_error(ArgumentError) + }.should_not raise_error lambda { @vo.validate( @@ -146,7 +146,7 @@ describe Chef::Mixin::ParamsValidate do } } ) - }.should_not raise_error(ArgumentError) + }.should_not raise_error lambda { @vo.validate( @@ -180,7 +180,7 @@ describe Chef::Mixin::ParamsValidate do } } ) - }.should_not raise_error(ArgumentError) + }.should_not raise_error lambda { @vo.validate( @@ -208,7 +208,7 @@ describe Chef::Mixin::ParamsValidate do } } ) - }.should_not raise_error(ArgumentError) + }.should_not raise_error lambda { @vo.validate( @@ -250,7 +250,7 @@ describe Chef::Mixin::ParamsValidate do :three => { :default => "neato mosquito" } } ) - }.should_not raise_error(ArgumentError) + }.should_not raise_error args[:three].should == "neato mosquito" lambda { @vo.validate( @@ -292,7 +292,7 @@ describe Chef::Mixin::ParamsValidate do it "should accept keys that are strings in the options" do lambda { @vo.validate({ "one" => "two" }, { :one => { :regex => /^two$/ }}) - }.should_not raise_error(ArgumentError) + }.should_not raise_error end it "should allow an array to kind_of" do @@ -305,7 +305,7 @@ describe Chef::Mixin::ParamsValidate do } } ) - }.should_not raise_error(ArgumentError) + }.should_not raise_error lambda { @vo.validate( {:one => ["string"]}, @@ -315,7 +315,7 @@ describe Chef::Mixin::ParamsValidate do } } ) - }.should_not raise_error(ArgumentError) + }.should_not raise_error lambda { @vo.validate( {:one => Hash.new}, @@ -360,7 +360,7 @@ describe Chef::Mixin::ParamsValidate do it "should not raise an error when argument is nil and required is false" do lambda { @vo.set_or_return(:test, nil, { :required => false }) - }.should_not raise_error(ArgumentError) + }.should_not raise_error end it "should set and return @name, then return @name for foo when argument is nil" do diff --git a/spec/unit/mixin/path_sanity_spec.rb b/spec/unit/mixin/path_sanity_spec.rb index bea2e78ecd..64c667b483 100644 --- a/spec/unit/mixin/path_sanity_spec.rb +++ b/spec/unit/mixin/path_sanity_spec.rb @@ -33,9 +33,9 @@ describe Chef::Mixin::PathSanity do Chef::Config[:enforce_path_sanity] = true @ruby_bindir = '/some/ruby/bin' @gem_bindir = '/some/gem/bin' - Gem.stub!(:bindir).and_return(@gem_bindir) - RbConfig::CONFIG.stub!(:[]).with('bindir').and_return(@ruby_bindir) - Chef::Platform.stub!(:windows?).and_return(false) + Gem.stub(:bindir).and_return(@gem_bindir) + RbConfig::CONFIG.stub(:[]).with('bindir').and_return(@ruby_bindir) + Chef::Platform.stub(:windows?).and_return(false) end it "adds all useful PATHs even if environment is an empty hash" do @@ -65,8 +65,8 @@ describe Chef::Mixin::PathSanity do it "does not create entries for Ruby/Gem bindirs if they exist in SANE_PATH or PATH" do ruby_bindir = '/usr/bin' gem_bindir = '/yo/gabba/gabba' - Gem.stub!(:bindir).and_return(gem_bindir) - RbConfig::CONFIG.stub!(:[]).with('bindir').and_return(ruby_bindir) + Gem.stub(:bindir).and_return(gem_bindir) + RbConfig::CONFIG.stub(:[]).with('bindir').and_return(ruby_bindir) env = {"PATH" => gem_bindir} @sanity.enforce_path_sanity(env) env["PATH"].should == "/yo/gabba/gabba:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin" @@ -75,9 +75,9 @@ describe Chef::Mixin::PathSanity do it "builds a valid windows path" do ruby_bindir = 'C:\ruby\bin' gem_bindir = 'C:\gems\bin' - Gem.stub!(:bindir).and_return(gem_bindir) - RbConfig::CONFIG.stub!(:[]).with('bindir').and_return(ruby_bindir) - Chef::Platform.stub!(:windows?).and_return(true) + Gem.stub(:bindir).and_return(gem_bindir) + RbConfig::CONFIG.stub(:[]).with('bindir').and_return(ruby_bindir) + Chef::Platform.stub(:windows?).and_return(true) env = {"PATH" => 'C:\Windows\system32;C:\mr\softie'} @sanity.enforce_path_sanity(env) env["PATH"].should == "C:\\Windows\\system32;C:\\mr\\softie;#{ruby_bindir};#{gem_bindir}" diff --git a/spec/unit/mixin/securable_spec.rb b/spec/unit/mixin/securable_spec.rb index 0a2dba1ead..89916e0039 100644 --- a/spec/unit/mixin/securable_spec.rb +++ b/spec/unit/mixin/securable_spec.rb @@ -28,14 +28,14 @@ describe Chef::Mixin::Securable do end it "should accept a group name or id for group" do - lambda { @securable.group "root" }.should_not raise_error(ArgumentError) - lambda { @securable.group 123 }.should_not raise_error(ArgumentError) + lambda { @securable.group "root" }.should_not raise_error + lambda { @securable.group 123 }.should_not raise_error lambda { @securable.group "+bad:group" }.should raise_error(ArgumentError) end it "should accept a user name or id for owner" do - lambda { @securable.owner "root" }.should_not raise_error(ArgumentError) - lambda { @securable.owner 123 }.should_not raise_error(ArgumentError) + lambda { @securable.owner "root" }.should_not raise_error + lambda { @securable.owner 123 }.should_not raise_error lambda { @securable.owner "+bad:owner" }.should raise_error(ArgumentError) end @@ -55,30 +55,30 @@ describe Chef::Mixin::Securable do end it "should accept group/owner names with spaces and backslashes" do - lambda { @securable.group 'test\ group' }.should_not raise_error(ArgumentError) - lambda { @securable.owner 'test\ group' }.should_not raise_error(ArgumentError) + lambda { @securable.group 'test\ group' }.should_not raise_error + lambda { @securable.owner 'test\ group' }.should_not raise_error end it "should accept group/owner names that are a single character or digit" do - lambda { @securable.group 'v' }.should_not raise_error(ArgumentError) - lambda { @securable.group '1' }.should_not raise_error(ArgumentError) - lambda { @securable.owner 'v' }.should_not raise_error(ArgumentError) - lambda { @securable.owner '1' }.should_not raise_error(ArgumentError) + lambda { @securable.group 'v' }.should_not raise_error + lambda { @securable.group '1' }.should_not raise_error + lambda { @securable.owner 'v' }.should_not raise_error + lambda { @securable.owner '1' }.should_not raise_error end it "should not accept group/owner names starting with '-', '+', or '~'" do lambda { @securable.group '-test' }.should raise_error(ArgumentError) lambda { @securable.group '+test' }.should raise_error(ArgumentError) lambda { @securable.group '~test' }.should raise_error(ArgumentError) - lambda { @securable.group 'te-st' }.should_not raise_error(ArgumentError) - lambda { @securable.group 'te+st' }.should_not raise_error(ArgumentError) - lambda { @securable.group 'te~st' }.should_not raise_error(ArgumentError) + lambda { @securable.group 'te-st' }.should_not raise_error + lambda { @securable.group 'te+st' }.should_not raise_error + lambda { @securable.group 'te~st' }.should_not raise_error lambda { @securable.owner '-test' }.should raise_error(ArgumentError) lambda { @securable.owner '+test' }.should raise_error(ArgumentError) lambda { @securable.owner '~test' }.should raise_error(ArgumentError) - lambda { @securable.owner 'te-st' }.should_not raise_error(ArgumentError) - lambda { @securable.owner 'te+st' }.should_not raise_error(ArgumentError) - lambda { @securable.owner 'te~st' }.should_not raise_error(ArgumentError) + lambda { @securable.owner 'te-st' }.should_not raise_error + lambda { @securable.owner 'te+st' }.should_not raise_error + lambda { @securable.owner 'te~st' }.should_not raise_error end it "should not accept group/owner names containing ':', ',' or non-space whitespace" do @@ -109,11 +109,11 @@ describe Chef::Mixin::Securable do end it "should accept Active Directory-style domain names pulled in via LDAP (on unix hosts)" do - lambda { @securable.owner "domain\@user" }.should_not raise_error(ArgumentError) - lambda { @securable.owner "domain\\user" }.should_not raise_error(ArgumentError) - lambda { @securable.group "domain\@group" }.should_not raise_error(ArgumentError) - lambda { @securable.group "domain\\group" }.should_not raise_error(ArgumentError) - lambda { @securable.group "domain\\group^name" }.should_not raise_error(ArgumentError) + lambda { @securable.owner "domain\@user" }.should_not raise_error + lambda { @securable.owner "domain\\user" }.should_not raise_error + lambda { @securable.group "domain\@group" }.should_not raise_error + lambda { @securable.group "domain\\group" }.should_not raise_error + lambda { @securable.group "domain\\group^name" }.should_not raise_error end it "should not accept group/owner names containing embedded carriage returns" do @@ -125,22 +125,22 @@ describe Chef::Mixin::Securable do end it "should accept group/owner names in UTF-8" do - lambda { @securable.group 'tëst' }.should_not raise_error(ArgumentError) - lambda { @securable.group 'ë' }.should_not raise_error(ArgumentError) - lambda { @securable.owner 'tëst' }.should_not raise_error(ArgumentError) - lambda { @securable.owner 'ë' }.should_not raise_error(ArgumentError) + lambda { @securable.group 'tëst' }.should_not raise_error + lambda { @securable.group 'ë' }.should_not raise_error + lambda { @securable.owner 'tëst' }.should_not raise_error + lambda { @securable.owner 'ë' }.should_not raise_error end it "should accept a unix file mode in string form as an octal number" do - lambda { @securable.mode "0" }.should_not raise_error(ArgumentError) - lambda { @securable.mode "0000" }.should_not raise_error(ArgumentError) - lambda { @securable.mode "0111" }.should_not raise_error(ArgumentError) - lambda { @securable.mode "0444" }.should_not raise_error(ArgumentError) + lambda { @securable.mode "0" }.should_not raise_error + lambda { @securable.mode "0000" }.should_not raise_error + lambda { @securable.mode "0111" }.should_not raise_error + lambda { @securable.mode "0444" }.should_not raise_error - lambda { @securable.mode "111" }.should_not raise_error(ArgumentError) - lambda { @securable.mode "444" }.should_not raise_error(ArgumentError) - lambda { @securable.mode "7777" }.should_not raise_error(ArgumentError) - lambda { @securable.mode "07777" }.should_not raise_error(ArgumentError) + lambda { @securable.mode "111" }.should_not raise_error + lambda { @securable.mode "444" }.should_not raise_error + lambda { @securable.mode "7777" }.should_not raise_error + lambda { @securable.mode "07777" }.should_not raise_error lambda { @securable.mode "-01" }.should raise_error(ArgumentError) lambda { @securable.mode "010000" }.should raise_error(ArgumentError) @@ -156,17 +156,17 @@ describe Chef::Mixin::Securable do end it "should accept a unix file mode in numeric form as a ruby-interpreted integer" do - lambda { @securable.mode 0 }.should_not raise_error(ArgumentError) - lambda { @securable.mode 0000 }.should_not raise_error(ArgumentError) - lambda { @securable.mode 444 }.should_not raise_error(ArgumentError) - lambda { @securable.mode 0444 }.should_not raise_error(ArgumentError) - lambda { @securable.mode 07777 }.should_not raise_error(ArgumentError) + lambda { @securable.mode 0 }.should_not raise_error + lambda { @securable.mode 0000 }.should_not raise_error + lambda { @securable.mode 444 }.should_not raise_error + lambda { @securable.mode 0444 }.should_not raise_error + lambda { @securable.mode 07777 }.should_not raise_error - lambda { @securable.mode 292 }.should_not raise_error(ArgumentError) - lambda { @securable.mode 4095 }.should_not raise_error(ArgumentError) + lambda { @securable.mode 292 }.should_not raise_error + lambda { @securable.mode 4095 }.should_not raise_error - lambda { @securable.mode 0111 }.should_not raise_error(ArgumentError) - lambda { @securable.mode 73 }.should_not raise_error(ArgumentError) + lambda { @securable.mode 0111 }.should_not raise_error + lambda { @securable.mode 73 }.should_not raise_error lambda { @securable.mode -01 }.should raise_error(ArgumentError) lambda { @securable.mode 010000 }.should raise_error(ArgumentError) @@ -193,13 +193,13 @@ describe Chef::Mixin::Securable do end it "should accept a unix file mode in string form as an octal number" do - lambda { @securable.mode "0" }.should_not raise_error(ArgumentError) - lambda { @securable.mode "0000" }.should_not raise_error(ArgumentError) - lambda { @securable.mode "0111" }.should_not raise_error(ArgumentError) - lambda { @securable.mode "0444" }.should_not raise_error(ArgumentError) + lambda { @securable.mode "0" }.should_not raise_error + lambda { @securable.mode "0000" }.should_not raise_error + lambda { @securable.mode "0111" }.should_not raise_error + lambda { @securable.mode "0444" }.should_not raise_error - lambda { @securable.mode "111" }.should_not raise_error(ArgumentError) - lambda { @securable.mode "444" }.should_not raise_error(ArgumentError) + lambda { @securable.mode "111" }.should_not raise_error + lambda { @securable.mode "444" }.should_not raise_error lambda { @securable.mode "7777" }.should raise_error(ArgumentError) lambda { @securable.mode "07777" }.should raise_error(ArgumentError) @@ -217,17 +217,17 @@ describe Chef::Mixin::Securable do end it "should accept a unix file mode in numeric form as a ruby-interpreted integer" do - lambda { @securable.mode 0 }.should_not raise_error(ArgumentError) - lambda { @securable.mode 0000 }.should_not raise_error(ArgumentError) - lambda { @securable.mode 444 }.should_not raise_error(ArgumentError) - lambda { @securable.mode 0444 }.should_not raise_error(ArgumentError) + lambda { @securable.mode 0 }.should_not raise_error + lambda { @securable.mode 0000 }.should_not raise_error + lambda { @securable.mode 444 }.should_not raise_error + lambda { @securable.mode 0444 }.should_not raise_error lambda { @securable.mode 07777 }.should raise_error(ArgumentError) - lambda { @securable.mode 292 }.should_not raise_error(ArgumentError) + lambda { @securable.mode 292 }.should_not raise_error lambda { @securable.mode 4095 }.should raise_error(ArgumentError) - lambda { @securable.mode 0111 }.should_not raise_error(ArgumentError) - lambda { @securable.mode 73 }.should_not raise_error(ArgumentError) + lambda { @securable.mode 0111 }.should_not raise_error + lambda { @securable.mode 73 }.should_not raise_error lambda { @securable.mode -01 }.should raise_error(ArgumentError) lambda { @securable.mode 010000 }.should raise_error(ArgumentError) @@ -236,46 +236,46 @@ describe Chef::Mixin::Securable do end it "should allow you to specify :full_control, :modify, :read_execute, :read, and :write rights" do - lambda { @securable.rights :full_control, "The Dude" }.should_not raise_error(ArgumentError) - lambda { @securable.rights :modify, "The Dude" }.should_not raise_error(ArgumentError) - lambda { @securable.rights :read_execute, "The Dude" }.should_not raise_error(ArgumentError) - lambda { @securable.rights :read, "The Dude" }.should_not raise_error(ArgumentError) - lambda { @securable.rights :write, "The Dude" }.should_not raise_error(ArgumentError) + lambda { @securable.rights :full_control, "The Dude" }.should_not raise_error + lambda { @securable.rights :modify, "The Dude" }.should_not raise_error + lambda { @securable.rights :read_execute, "The Dude" }.should_not raise_error + lambda { @securable.rights :read, "The Dude" }.should_not raise_error + lambda { @securable.rights :write, "The Dude" }.should_not raise_error lambda { @securable.rights :to_party, "The Dude" }.should raise_error(ArgumentError) end it "should allow you to specify :full_control, :modify, :read_execute, :read, and :write deny_rights" do - lambda { @securable.deny_rights :full_control, "The Dude" }.should_not raise_error(ArgumentError) - lambda { @securable.deny_rights :modify, "The Dude" }.should_not raise_error(ArgumentError) - lambda { @securable.deny_rights :read_execute, "The Dude" }.should_not raise_error(ArgumentError) - lambda { @securable.deny_rights :read, "The Dude" }.should_not raise_error(ArgumentError) - lambda { @securable.deny_rights :write, "The Dude" }.should_not raise_error(ArgumentError) + lambda { @securable.deny_rights :full_control, "The Dude" }.should_not raise_error + lambda { @securable.deny_rights :modify, "The Dude" }.should_not raise_error + lambda { @securable.deny_rights :read_execute, "The Dude" }.should_not raise_error + lambda { @securable.deny_rights :read, "The Dude" }.should_not raise_error + lambda { @securable.deny_rights :write, "The Dude" }.should_not raise_error lambda { @securable.deny_rights :to_party, "The Dude" }.should raise_error(ArgumentError) end it "should accept a principal as a string or an array" do - lambda { @securable.rights :read, "The Dude" }.should_not raise_error(ArgumentError) - lambda { @securable.rights :read, ["The Dude","Donny"] }.should_not raise_error(ArgumentError) + lambda { @securable.rights :read, "The Dude" }.should_not raise_error + lambda { @securable.rights :read, ["The Dude","Donny"] }.should_not raise_error lambda { @securable.rights :read, 3 }.should raise_error(ArgumentError) end it "should allow you to specify whether the permissions applies_to_children with true/false/:containers_only/:objects_only" do - lambda { @securable.rights :read, "The Dude", :applies_to_children => false }.should_not raise_error(ArgumentError) - lambda { @securable.rights :read, "The Dude", :applies_to_children => true }.should_not raise_error(ArgumentError) - lambda { @securable.rights :read, "The Dude", :applies_to_children => :containers_only }.should_not raise_error(ArgumentError) - lambda { @securable.rights :read, "The Dude", :applies_to_children => :objects_only }.should_not raise_error(ArgumentError) + lambda { @securable.rights :read, "The Dude", :applies_to_children => false }.should_not raise_error + lambda { @securable.rights :read, "The Dude", :applies_to_children => true }.should_not raise_error + lambda { @securable.rights :read, "The Dude", :applies_to_children => :containers_only }.should_not raise_error + lambda { @securable.rights :read, "The Dude", :applies_to_children => :objects_only }.should_not raise_error lambda { @securable.rights :read, "The Dude", :applies_to_children => 'poop' }.should raise_error(ArgumentError) end it "should allow you to specify whether the permissions applies_to_self with true/false" do - lambda { @securable.rights :read, "The Dude", :applies_to_children => true, :applies_to_self => false }.should_not raise_error(ArgumentError) - lambda { @securable.rights :read, "The Dude", :applies_to_self => true }.should_not raise_error(ArgumentError) + lambda { @securable.rights :read, "The Dude", :applies_to_children => true, :applies_to_self => false }.should_not raise_error + lambda { @securable.rights :read, "The Dude", :applies_to_self => true }.should_not raise_error lambda { @securable.rights :read, "The Dude", :applies_to_self => 'poop' }.should raise_error(ArgumentError) end it "should allow you to specify whether the permissions applies one_level_deep with true/false" do - lambda { @securable.rights :read, "The Dude", :applies_to_children => true, :one_level_deep => false }.should_not raise_error(ArgumentError) - lambda { @securable.rights :read, "The Dude", :applies_to_children => true, :one_level_deep => true }.should_not raise_error(ArgumentError) + lambda { @securable.rights :read, "The Dude", :applies_to_children => true, :one_level_deep => false }.should_not raise_error + lambda { @securable.rights :read, "The Dude", :applies_to_children => true, :one_level_deep => true }.should_not raise_error lambda { @securable.rights :read, "The Dude", :applies_to_children => true, :one_level_deep => 'poop' }.should raise_error(ArgumentError) end @@ -290,26 +290,26 @@ describe Chef::Mixin::Securable do end it "should allow you to specify whether the permission applies_to_self only if you specified applies_to_children" do - lambda { @securable.rights :read, "The Dude", :applies_to_children => true, :applies_to_self => true }.should_not raise_error(ArgumentError) - lambda { @securable.rights :read, "The Dude", :applies_to_children => true, :applies_to_self => false }.should_not raise_error(ArgumentError) - lambda { @securable.rights :read, "The Dude", :applies_to_children => false, :applies_to_self => true }.should_not raise_error(ArgumentError) + lambda { @securable.rights :read, "The Dude", :applies_to_children => true, :applies_to_self => true }.should_not raise_error + lambda { @securable.rights :read, "The Dude", :applies_to_children => true, :applies_to_self => false }.should_not raise_error + lambda { @securable.rights :read, "The Dude", :applies_to_children => false, :applies_to_self => true }.should_not raise_error lambda { @securable.rights :read, "The Dude", :applies_to_children => false, :applies_to_self => false }.should raise_error(ArgumentError) - lambda { @securable.rights :read, "The Dude", :applies_to_self => true }.should_not raise_error(ArgumentError) - lambda { @securable.rights :read, "The Dude", :applies_to_self => false }.should_not raise_error(ArgumentError) + lambda { @securable.rights :read, "The Dude", :applies_to_self => true }.should_not raise_error + lambda { @securable.rights :read, "The Dude", :applies_to_self => false }.should_not raise_error end it "should allow you to specify whether the permission applies one_level_deep only if you specified applies_to_children" do - lambda { @securable.rights :read, "The Dude", :applies_to_children => true, :one_level_deep => true }.should_not raise_error(ArgumentError) - lambda { @securable.rights :read, "The Dude", :applies_to_children => true, :one_level_deep => false }.should_not raise_error(ArgumentError) + lambda { @securable.rights :read, "The Dude", :applies_to_children => true, :one_level_deep => true }.should_not raise_error + lambda { @securable.rights :read, "The Dude", :applies_to_children => true, :one_level_deep => false }.should_not raise_error lambda { @securable.rights :read, "The Dude", :applies_to_children => false, :one_level_deep => true }.should raise_error(ArgumentError) - lambda { @securable.rights :read, "The Dude", :applies_to_children => false, :one_level_deep => false }.should_not raise_error(ArgumentError) - lambda { @securable.rights :read, "The Dude", :one_level_deep => true }.should_not raise_error(ArgumentError) - lambda { @securable.rights :read, "The Dude", :one_level_deep => false }.should_not raise_error(ArgumentError) + lambda { @securable.rights :read, "The Dude", :applies_to_children => false, :one_level_deep => false }.should_not raise_error + lambda { @securable.rights :read, "The Dude", :one_level_deep => true }.should_not raise_error + lambda { @securable.rights :read, "The Dude", :one_level_deep => false }.should_not raise_error end it "should allow you to specify whether the permissions inherit with true/false" do - lambda { @securable.inherits true }.should_not raise_error(ArgumentError) - lambda { @securable.inherits false }.should_not raise_error(ArgumentError) + lambda { @securable.inherits true }.should_not raise_error + lambda { @securable.inherits false }.should_not raise_error lambda { @securable.inherits "monkey" }.should raise_error(ArgumentError) end end diff --git a/spec/unit/mixin/shell_out_spec.rb b/spec/unit/mixin/shell_out_spec.rb index c7ca56fe84..f325f687d9 100644 --- a/spec/unit/mixin/shell_out_spec.rb +++ b/spec/unit/mixin/shell_out_spec.rb @@ -32,7 +32,7 @@ describe Chef::Mixin::ShellOut do let(:output) { StringIO.new } let!(:capture_log_output) { Chef::Log.logger = Logger.new(output) } - let(:assume_deprecation_log_level) { Chef::Log.stub!(:level).and_return(:warn) } + let(:assume_deprecation_log_level) { Chef::Log.stub(:level).and_return(:warn) } context 'without options' do let(:command_args) { [ cmd ] } diff --git a/spec/unit/mixin/template_spec.rb b/spec/unit/mixin/template_spec.rb index ca2c3c7318..3aa0b9ba22 100644 --- a/spec/unit/mixin/template_spec.rb +++ b/spec/unit/mixin/template_spec.rb @@ -39,7 +39,7 @@ describe Chef::Mixin::Template, "render_template" do describe "when running on windows" do before do - Chef::Platform.stub!(:windows?).and_return(true) + Chef::Platform.stub(:windows?).and_return(true) end it "should render the templates with windows line endings" do @@ -54,7 +54,7 @@ describe Chef::Mixin::Template, "render_template" do describe "when running on unix" do before do - Chef::Platform.stub!(:windows?).and_return(false) + Chef::Platform.stub(:windows?).and_return(false) end it "should render the templates with unix line endings" do diff --git a/spec/unit/node/attribute_spec.rb b/spec/unit/node/attribute_spec.rb index 70905d334b..ef3fc60cc6 100644 --- a/spec/unit/node/attribute_spec.rb +++ b/spec/unit/node/attribute_spec.rb @@ -437,7 +437,7 @@ describe Chef::Node::Attribute do it "should let you set an attribute value when another hash has an intermediate value" do @attributes.normal["the_ghost"] = { "exterminate" => "the future" } - lambda { @attributes.normal["the_ghost"]["exterminate"]["tomorrow"] = false }.should_not raise_error(NoMethodError) + lambda { @attributes.normal["the_ghost"]["eviscerate"]["tomorrow"] = false }.should_not raise_error end it "should set the attribute value" do @@ -597,7 +597,7 @@ describe Chef::Node::Attribute do end it "should not raise an exception if one of the hashes has a nil value on a deep lookup" do - lambda { @attributes.place.keys { |k| } }.should_not raise_error(NoMethodError) + lambda { @attributes.place.keys { |k| } }.should_not raise_error end end @@ -981,7 +981,7 @@ describe Chef::Node::Attribute do if RUBY_VERSION >= "1.8.7" it "should not raise a LocalJumpError if no block is given" do - lambda { @attributes.select }.should_not raise_error(LocalJumpError) + lambda { @attributes.select }.should_not raise_error end else it "should raise a LocalJumpError if no block is given" do diff --git a/spec/unit/node_spec.rb b/spec/unit/node_spec.rb index 1cc40979cc..f2a78f87cd 100644 --- a/spec/unit/node_spec.rb +++ b/spec/unit/node_spec.rb @@ -46,12 +46,12 @@ describe Chef::Node do before do response = OpenStruct.new(:code => '404') exception = Net::HTTPServerException.new("404 not found", response) - Chef::Node.stub!(:load).and_raise(exception) + Chef::Node.stub(:load).and_raise(exception) node.name("created-node") end it "creates a new node for find_or_create" do - Chef::Node.stub!(:new).and_return(node) + Chef::Node.stub(:new).and_return(node) node.should_receive(:create).and_return(node) node = Chef::Node.find_or_create("created-node") node.name.should == 'created-node' @@ -62,7 +62,7 @@ describe Chef::Node do describe "when the node exists on the server" do before do node.name('existing-node') - Chef::Node.stub!(:load).and_return(node) + Chef::Node.stub(:load).and_return(node) end it "loads the node via the REST API for find_or_create" do @@ -405,7 +405,7 @@ describe Chef::Node do it "saves non-runlist json attrs for later" do expansion = Chef::RunList::RunListExpansion.new('_default', []) - node.run_list.stub!(:expand).and_return(expansion) + node.run_list.stub(:expand).and_return(expansion) node.consume_external_attrs(@ohai_data, {"foo" => "bar"}) node.expand! node.normal_attrs.should == {"foo" => "bar", "tags" => []} @@ -423,7 +423,7 @@ describe Chef::Node do Chef::Environment.should_receive(:load).with("rspec_env").and_return(@environment) @expansion = Chef::RunList::RunListExpansion.new("rspec_env", []) node.chef_environment("rspec_env") - node.run_list.stub!(:expand).and_return(@expansion) + node.run_list.stub(:expand).and_return(@expansion) end it "sets the 'recipes' automatic attribute to the recipes in the expanded run_list" do @@ -540,7 +540,7 @@ describe Chef::Node do @environment = Chef::Environment.new @environment.default_attributes = {:default => "from env", :d_env => "env only" } @environment.override_attributes = {:override => "from env", :o_env => "env only"} - Chef::Environment.stub!(:load).and_return(@environment) + Chef::Environment.stub(:load).and_return(@environment) node.apply_expansion_attributes(@expansion) end @@ -764,16 +764,16 @@ describe Chef::Node do describe "api model" do before(:each) do - @rest = mock("Chef::REST") - Chef::REST.stub!(:new).and_return(@rest) - @query = mock("Chef::Search::Query") - Chef::Search::Query.stub!(:new).and_return(@query) + @rest = double("Chef::REST") + Chef::REST.stub(:new).and_return(@rest) + @query = double("Chef::Search::Query") + Chef::Search::Query.stub(:new).and_return(@query) end describe "list" do describe "inflated" do it "should return a hash of node names and objects" do - n1 = mock("Chef::Node", :name => "one") + n1 = double("Chef::Node", :name => "one") @query.should_receive(:search).with(:node).and_yield(n1) r = Chef::Node.list(true) r["one"].should == n1 @@ -818,7 +818,7 @@ describe Chef::Node do it "should create if it cannot update" do node.name("monkey") - exception = mock("404 error", :code => "404") + exception = double("404 error", :code => "404") @rest.should_receive(:put_rest).and_raise(Net::HTTPServerException.new("foo", exception)) @rest.should_receive(:post_rest).with("nodes", node) node.save diff --git a/spec/unit/platform_spec.rb b/spec/unit/platform_spec.rb index 3904435ea0..e0386a1a61 100644 --- a/spec/unit/platform_spec.rb +++ b/spec/unit/platform_spec.rb @@ -151,7 +151,7 @@ describe Chef::Platform do it "should prefer an explicit provider" do kitty = Chef::Resource::Cat.new("loulou") - kitty.stub!(:provider).and_return(Chef::Provider::File) + kitty.stub(:provider).and_return(Chef::Provider::File) node = Chef::Node.new node.name("Intel") node.automatic_attrs[:platform] = "mac_os_x" diff --git a/spec/unit/provider/breakpoint_spec.rb b/spec/unit/provider/breakpoint_spec.rb index 977624597a..05f3e8e0ed 100644 --- a/spec/unit/provider/breakpoint_spec.rb +++ b/spec/unit/provider/breakpoint_spec.rb @@ -25,8 +25,8 @@ describe Chef::Provider::Breakpoint do @node = Chef::Node.new @events = Chef::EventDispatch::Dispatcher.new @run_context = Chef::RunContext.new(@node, {}, @events) - @collection = mock("resource collection") - @run_context.stub!(:resource_collection).and_return(@collection) + @collection = double("resource collection") + @run_context.stub(:resource_collection).and_return(@collection) @provider = Chef::Provider::Breakpoint.new(@resource, @run_context) end @@ -35,18 +35,18 @@ describe Chef::Provider::Breakpoint do end it "gets the iterator from @collection and pauses it" do - Shell.stub!(:running?).and_return(true) - @iterator = mock("stepable_iterator") - @collection.stub!(:iterator).and_return(@iterator) + Shell.stub(:running?).and_return(true) + @iterator = double("stepable_iterator") + @collection.stub(:iterator).and_return(@iterator) @iterator.should_receive(:pause) @provider.action_break @resource.should be_updated end it "doesn't pause the iterator if chef-shell isn't running" do - Shell.stub!(:running?).and_return(false) - @iterator = mock("stepable_iterator") - @collection.stub!(:iterator).and_return(@iterator) + Shell.stub(:running?).and_return(false) + @iterator = double("stepable_iterator") + @collection.stub(:iterator).and_return(@iterator) @iterator.should_not_receive(:pause) @provider.action_break end diff --git a/spec/unit/provider/cookbook_file/content_spec.rb b/spec/unit/provider/cookbook_file/content_spec.rb index b771b76aae..ed8942aaf2 100644 --- a/spec/unit/provider/cookbook_file/content_spec.rb +++ b/spec/unit/provider/cookbook_file/content_spec.rb @@ -20,15 +20,15 @@ require 'spec_helper' describe Chef::Provider::CookbookFile::Content do - let(:new_resource) { mock('Chef::Resource::CookbookFile (new)', :cookbook_name => 'apache2', :cookbook => 'apache2') } + let(:new_resource) { double('Chef::Resource::CookbookFile (new)', :cookbook_name => 'apache2', :cookbook => 'apache2') } let(:content) do - @run_context = mock('Chef::RunContext') - @current_resource = mock('Chef::Resource::CookbookFile (current)') + @run_context = double('Chef::RunContext') + @current_resource = double('Chef::Resource::CookbookFile (current)') Chef::Provider::CookbookFile::Content.new(new_resource, @current_resource, @run_context) end it "prefers the explicit cookbook name on the resource to the implicit one" do - new_resource.stub!(:cookbook).and_return('nginx') + new_resource.stub(:cookbook).and_return('nginx') content.send(:resource_cookbook).should == 'nginx' end diff --git a/spec/unit/provider/cookbook_file_spec.rb b/spec/unit/provider/cookbook_file_spec.rb index 05509fbae4..131fca2ba6 100644 --- a/spec/unit/provider/cookbook_file_spec.rb +++ b/spec/unit/provider/cookbook_file_spec.rb @@ -49,7 +49,7 @@ describe Chef::Provider::CookbookFile do end let(:content) do - content = mock('Chef::Provider::CookbookFile::Content') + content = double('Chef::Provider::CookbookFile::Content') end it_behaves_like Chef::Provider::File diff --git a/spec/unit/provider/cron/unix_spec.rb b/spec/unit/provider/cron/unix_spec.rb index ffdfa198b6..60e09baceb 100644 --- a/spec/unit/provider/cron/unix_spec.rb +++ b/spec/unit/provider/cron/unix_spec.rb @@ -39,7 +39,7 @@ describe Chef::Provider::Cron::Unix do describe "read_crontab" do before :each do - @status = mock("Status", :exitstatus => 0) + @status = double("Status", :exitstatus => 0) @stdout = StringIO.new(<<-CRONTAB) 0 2 * * * /some/other/command @@ -48,7 +48,7 @@ describe Chef::Provider::Cron::Unix do # Another comment CRONTAB - @provider.stub!(:popen4).and_yield(1234, StringIO.new, @stdout, StringIO.new).and_return(@status) + @provider.stub(:popen4).and_yield(1234, StringIO.new, @stdout, StringIO.new).and_return(@status) end it "should call crontab -l with the user" do @@ -69,14 +69,14 @@ CRONTAB end it "should return nil if the user has no crontab" do - status = mock("Status", :exitstatus => 1) - @provider.stub!(:popen4).and_return(status) + status = double("Status", :exitstatus => 1) + @provider.stub(:popen4).and_return(status) @provider.send(:read_crontab).should == nil end it "should raise an exception if another error occurs" do - status = mock("Status", :exitstatus => 2) - @provider.stub!(:popen4).and_return(status) + status = double("Status", :exitstatus => 2) + @provider.stub(:popen4).and_return(status) lambda do @provider.send(:read_crontab) end.should raise_error(Chef::Exceptions::Cron, "Error determining state of #{@new_resource.name}, exit: 2") @@ -85,10 +85,10 @@ CRONTAB describe "write_crontab" do before :each do - @status = mock("Status", :exitstatus => 0) - @provider.stub!(:run_command_and_return_stdout_stderr).and_return(@status, String.new, String.new) - @tempfile = mock("foo", :path => "/tmp/foo", :close => true) - Tempfile.stub!(:new).and_return(@tempfile) + @status = double("Status", :exitstatus => 0) + @provider.stub(:run_command_and_return_stdout_stderr).and_return(@status, String.new, String.new) + @tempfile = double("foo", :path => "/tmp/foo", :close => true) + Tempfile.stub(:new).and_return(@tempfile) @tempfile.should_receive(:flush) @tempfile.should_receive(:chmod).with(420) @tempfile.should_receive(:close!) @@ -112,7 +112,7 @@ CRONTAB it "should raise an exception if the command returns non-zero" do @tempfile.should_receive(:<<).with("Foo") - @status.stub!(:exitstatus).and_return(1) + @status.stub(:exitstatus).and_return(1) lambda do @provider.send(:write_crontab, "Foo") end.should raise_error(Chef::Exceptions::Cron, /Error updating state of #{@new_resource.name}, exit: 1/) diff --git a/spec/unit/provider/cron_spec.rb b/spec/unit/provider/cron_spec.rb index 35656e0ad6..3a7a96c549 100644 --- a/spec/unit/provider/cron_spec.rb +++ b/spec/unit/provider/cron_spec.rb @@ -34,7 +34,7 @@ describe Chef::Provider::Cron do describe "when examining the current system state" do context "with no crontab for the user" do before :each do - @provider.stub!(:read_crontab).and_return(nil) + @provider.stub(:read_crontab).and_return(nil) end it "should set cron_empty" do @@ -51,7 +51,7 @@ describe Chef::Provider::Cron do context "with no matching entry in the user's crontab" do before :each do - @provider.stub!(:read_crontab).and_return(<<-CRONTAB) + @provider.stub(:read_crontab).and_return(<<-CRONTAB) 0 2 * * * /some/other/command # Chef Name: something else @@ -73,7 +73,7 @@ CRONTAB end it "should not fail if there's an existing cron with a numerical argument" do - @provider.stub!(:read_crontab).and_return(<<-CRONTAB) + @provider.stub(:read_crontab).and_return(<<-CRONTAB) # Chef Name: foo[bar] (baz) 21 */4 * * * some_prog 1234567 CRONTAB @@ -85,7 +85,7 @@ CRONTAB context "with a matching entry in the user's crontab" do before :each do - @provider.stub!(:read_crontab).and_return(<<-CRONTAB) + @provider.stub(:read_crontab).and_return(<<-CRONTAB) 0 2 * * * /some/other/command # Chef Name: cronhole some stuff @@ -114,7 +114,7 @@ CRONTAB end it "should pull env vars out" do - @provider.stub!(:read_crontab).and_return(<<-CRONTAB) + @provider.stub(:read_crontab).and_return(<<-CRONTAB) 0 2 * * * /some/other/command # Chef Name: cronhole some stuff @@ -142,7 +142,7 @@ CRONTAB end it "should parse and load generic and standard environment variables from cron entry" do - @provider.stub!(:read_crontab).and_return(<<-CRONTAB) + @provider.stub(:read_crontab).and_return(<<-CRONTAB) # Chef Name: cronhole some stuff MAILTO=warn@example.com TEST=lol @@ -156,7 +156,7 @@ CRONTAB end it "should not break with variabels that match the cron resource internals" do - @provider.stub!(:read_crontab).and_return(<<-CRONTAB) + @provider.stub(:read_crontab).and_return(<<-CRONTAB) # Chef Name: cronhole some stuff MINUTE=40 HOUR=midnight @@ -179,7 +179,7 @@ CRONTAB context "with a matching entry in the user's crontab using month names and weekday names (#CHEF-3178)" do before :each do - @provider.stub!(:read_crontab).and_return(<<-CRONTAB) + @provider.stub(:read_crontab).and_return(<<-CRONTAB) 0 2 * * * /some/other/command # Chef Name: cronhole some stuff @@ -215,7 +215,7 @@ CRONTAB context "with a matching entry without a crontab line" do it "should set cron_exists and leave current_resource values at defaults" do - @provider.stub!(:read_crontab).and_return(<<-CRONTAB) + @provider.stub(:read_crontab).and_return(<<-CRONTAB) 0 2 * * * /some/other/command # Chef Name: cronhole some stuff @@ -231,7 +231,7 @@ CRONTAB end it "should not pick up a commented out crontab line" do - @provider.stub!(:read_crontab).and_return(<<-CRONTAB) + @provider.stub(:read_crontab).and_return(<<-CRONTAB) 0 2 * * * /some/other/command # Chef Name: cronhole some stuff @@ -248,7 +248,7 @@ CRONTAB end it "should not pick up a later crontab entry" do - @provider.stub!(:read_crontab).and_return(<<-CRONTAB) + @provider.stub(:read_crontab).and_return(<<-CRONTAB) 0 2 * * * /some/other/command # Chef Name: cronhole some stuff @@ -304,8 +304,8 @@ CRONTAB describe "action_create" do before :each do - @provider.stub!(:write_crontab) - @provider.stub!(:read_crontab).and_return(nil) + @provider.stub(:write_crontab) + @provider.stub(:read_crontab).and_return(nil) end context "when there is no existing crontab" do @@ -354,7 +354,7 @@ TEST=LOL context "when there is a crontab with no matching section" do before :each do @provider.cron_exists = false - @provider.stub!(:read_crontab).and_return(<<-CRONTAB) + @provider.stub(:read_crontab).and_return(<<-CRONTAB) 0 2 * * * /some/other/command # Chef Name: something else @@ -416,8 +416,8 @@ TEST=LOL context "when there is a crontab with a matching but different section" do before :each do @provider.cron_exists = true - @provider.stub!(:cron_different?).and_return(true) - @provider.stub!(:read_crontab).and_return(<<-CRONTAB) + @provider.stub(:cron_different?).and_return(true) + @provider.stub(:read_crontab).and_return(<<-CRONTAB) 0 2 * * * /some/other/command # Chef Name: cronhole some stuff @@ -481,11 +481,11 @@ TEST=LOL context "when there is a crontab with a matching section with no crontab line in it" do before :each do @provider.cron_exists = true - @provider.stub!(:cron_different?).and_return(true) + @provider.stub(:cron_different?).and_return(true) end it "should add the crontab to the entry" do - @provider.stub!(:read_crontab).and_return(<<-CRONTAB) + @provider.stub(:read_crontab).and_return(<<-CRONTAB) 0 2 * * * /some/other/command # Chef Name: cronhole some stuff @@ -500,7 +500,7 @@ TEST=LOL end it "should not blat any following entries" do - @provider.stub!(:read_crontab).and_return(<<-CRONTAB) + @provider.stub(:read_crontab).and_return(<<-CRONTAB) 0 2 * * * /some/other/command # Chef Name: cronhole some stuff @@ -525,7 +525,7 @@ TEST=LOL end it "should handle env vars with no crontab" do - @provider.stub!(:read_crontab).and_return(<<-CRONTAB) + @provider.stub(:read_crontab).and_return(<<-CRONTAB) 0 2 * * * /some/other/command # Chef Name: cronhole some stuff @@ -565,8 +565,8 @@ HOME=/home/foo context "when there is a crontab with a matching and identical section" do before :each do @provider.cron_exists = true - @provider.stub!(:cron_different?).and_return(false) - @provider.stub!(:read_crontab).and_return(<<-CRONTAB) + @provider.stub(:cron_different?).and_return(false) + @provider.stub(:read_crontab).and_return(<<-CRONTAB) 0 2 * * * /some/other/command # Chef Name: cronhole some stuff @@ -596,8 +596,8 @@ CRONTAB describe "action_delete" do before :each do - @provider.stub!(:write_crontab) - @provider.stub!(:read_crontab).and_return(nil) + @provider.stub(:write_crontab) + @provider.stub(:read_crontab).and_return(nil) end context "when the user's crontab has no matching section" do @@ -620,7 +620,7 @@ CRONTAB context "when the user has a crontab with a matching section" do before :each do @provider.cron_exists = true - @provider.stub!(:read_crontab).and_return(<<-CRONTAB) + @provider.stub(:read_crontab).and_return(<<-CRONTAB) 0 2 * * * /some/other/command # Chef Name: cronhole some stuff @@ -645,7 +645,7 @@ CRONTAB end it "should remove any env vars with the entry" do - @provider.stub!(:read_crontab).and_return(<<-CRONTAB) + @provider.stub(:read_crontab).and_return(<<-CRONTAB) 0 2 * * * /some/other/command # Chef Name: cronhole some stuff @@ -685,7 +685,7 @@ FOO=test end it "should remove the section" do - @provider.stub!(:read_crontab).and_return(<<-CRONTAB) + @provider.stub(:read_crontab).and_return(<<-CRONTAB) 0 2 * * * /some/other/command # Chef Name: cronhole some stuff @@ -698,7 +698,7 @@ FOO=test end it "should not blat following sections" do - @provider.stub!(:read_crontab).and_return(<<-CRONTAB) + @provider.stub(:read_crontab).and_return(<<-CRONTAB) 0 2 * * * /some/other/command # Chef Name: cronhole some stuff @@ -721,7 +721,7 @@ FOO=test end it "should remove any envvars with the section" do - @provider.stub!(:read_crontab).and_return(<<-CRONTAB) + @provider.stub(:read_crontab).and_return(<<-CRONTAB) 0 2 * * * /some/other/command # Chef Name: cronhole some stuff @@ -748,7 +748,7 @@ MAILTO=foo@example.com describe "read_crontab" do before :each do - @status = mock("Status", :exitstatus => 0) + @status = double("Status", :exitstatus => 0) @stdout = StringIO.new(<<-CRONTAB) 0 2 * * * /some/other/command @@ -757,7 +757,7 @@ MAILTO=foo@example.com # Another comment CRONTAB - @provider.stub!(:popen4).and_yield(1234, StringIO.new, @stdout, StringIO.new).and_return(@status) + @provider.stub(:popen4).and_yield(1234, StringIO.new, @stdout, StringIO.new).and_return(@status) end it "should call crontab -l with the user" do @@ -778,14 +778,14 @@ MAILTO=foo@example.com end it "should return nil if the user has no crontab" do - status = mock("Status", :exitstatus => 1) - @provider.stub!(:popen4).and_return(status) + status = double("Status", :exitstatus => 1) + @provider.stub(:popen4).and_return(status) @provider.send(:read_crontab).should == nil end it "should raise an exception if another error occurs" do - status = mock("Status", :exitstatus => 2) - @provider.stub!(:popen4).and_return(status) + status = double("Status", :exitstatus => 2) + @provider.stub(:popen4).and_return(status) lambda do @provider.send(:read_crontab) end.should raise_error(Chef::Exceptions::Cron, "Error determining state of #{@new_resource.name}, exit: 2") @@ -794,9 +794,9 @@ MAILTO=foo@example.com describe "write_crontab" do before :each do - @status = mock("Status", :exitstatus => 0) + @status = double("Status", :exitstatus => 0) @stdin = StringIO.new - @provider.stub!(:popen4).and_yield(1234, @stdin, StringIO.new, StringIO.new).and_return(@status) + @provider.stub(:popen4).and_yield(1234, @stdin, StringIO.new, StringIO.new).and_return(@status) end it "should call crontab for the user" do @@ -810,7 +810,7 @@ MAILTO=foo@example.com end it "should raise an exception if the command returns non-zero" do - @status.stub!(:exitstatus).and_return(1) + @status.stub(:exitstatus).and_return(1) lambda do @provider.send(:write_crontab, "Foo") end.should raise_error(Chef::Exceptions::Cron, "Error updating state of #{@new_resource.name}, exit: 1") @@ -822,8 +822,8 @@ MAILTO=foo@example.com raise Errno::EPIPE, "Test" end end - @status.stub!(:exitstatus).and_return(1) - @provider.stub!(:popen4).and_yield(1234, WriteErrPipe.new, StringIO.new, StringIO.new).and_return(@status) + @status.stub(:exitstatus).and_return(1) + @provider.stub(:popen4).and_yield(1234, WriteErrPipe.new, StringIO.new, StringIO.new).and_return(@status) Chef::Log.should_receive(:debug).with("Broken pipe - Test") diff --git a/spec/unit/provider/deploy/revision_spec.rb b/spec/unit/provider/deploy/revision_spec.rb index 13eaee6867..8d4590378e 100644 --- a/spec/unit/provider/deploy/revision_spec.rb +++ b/spec/unit/provider/deploy/revision_spec.rb @@ -30,20 +30,19 @@ describe Chef::Provider::Deploy::Revision do @run_context = Chef::RunContext.new(@node, {}, @events) @provider = Chef::Provider::Deploy::Revision.new(@resource, @run_context) @provider.load_current_resource - @runner = mock("runnah") - Chef::Runner.stub!(:new).and_return(@runner) + @runner = double("runnah") + Chef::Runner.stub(:new).and_return(@runner) @expected_release_dir = "/my/deploy/dir/releases/8a3195bf3efa246f743c5dfa83683201880f935c" end after do # Make sure we don't keep any state in our tests - FileUtils.rspec_reset FileUtils.rm_rf @temp_dir if File.directory?( @temp_dir ) end it "uses the resolved revision from the SCM as the release slug" do - @provider.scm_provider.stub!(:revision_slug).and_return("uglySlugly") + @provider.scm_provider.stub(:revision_slug).and_return("uglySlugly") @provider.send(:release_slug).should == "uglySlugly" end @@ -52,10 +51,10 @@ describe Chef::Provider::Deploy::Revision do end it "stores the release dir in the file cache in the cleanup step" do - FileUtils.stub!(:mkdir_p) - FileUtils.stub!(:cp_r) + FileUtils.stub(:mkdir_p) + FileUtils.stub(:cp_r) @provider.cleanup! - @provider.stub!(:release_slug).and_return("73219b87e977d9c7ba1aa57e9ad1d88fa91a0ec2") + @provider.stub(:release_slug).and_return("73219b87e977d9c7ba1aa57e9ad1d88fa91a0ec2") @provider.load_current_resource @provider.cleanup! second_release = "/my/deploy/dir/releases/73219b87e977d9c7ba1aa57e9ad1d88fa91a0ec2" @@ -64,17 +63,17 @@ describe Chef::Provider::Deploy::Revision do end it "removes a release from the file cache when it's used again in another release and append it to the end" do - FileUtils.stub!(:mkdir_p) - FileUtils.stub!(:cp_r) + FileUtils.stub(:mkdir_p) + FileUtils.stub(:cp_r) @provider.cleanup! - @provider.stub!(:release_slug).and_return("73219b87e977d9c7ba1aa57e9ad1d88fa91a0ec2") + @provider.stub(:release_slug).and_return("73219b87e977d9c7ba1aa57e9ad1d88fa91a0ec2") @provider.load_current_resource @provider.cleanup! second_release = "/my/deploy/dir/releases/73219b87e977d9c7ba1aa57e9ad1d88fa91a0ec2" @provider.all_releases.should == [@expected_release_dir,second_release] @provider.cleanup! - @provider.stub!(:release_slug).and_return("8a3195bf3efa246f743c5dfa83683201880f935c") + @provider.stub(:release_slug).and_return("8a3195bf3efa246f743c5dfa83683201880f935c") @provider.load_current_resource @provider.cleanup! @provider.all_releases.should == [second_release, @expected_release_dir] @@ -89,7 +88,7 @@ describe Chef::Provider::Deploy::Revision do end @provider.all_releases.should == release_paths - FileUtils.stub!(:rm_rf) + FileUtils.stub(:rm_rf) @provider.cleanup! expected_release_paths = (%w{second third fourth fifth} << @resource.revision).map do |release_name| diff --git a/spec/unit/provider/deploy/timestamped_spec.rb b/spec/unit/provider/deploy/timestamped_spec.rb index a9cea1142e..1d42abfc05 100644 --- a/spec/unit/provider/deploy/timestamped_spec.rb +++ b/spec/unit/provider/deploy/timestamped_spec.rb @@ -22,15 +22,15 @@ describe Chef::Provider::Deploy::Timestamped do before do @release_time = Time.utc( 2004, 8, 15, 16, 23, 42) - Time.stub!(:now).and_return(@release_time) + Time.stub(:now).and_return(@release_time) @expected_release_dir = "/my/deploy/dir/releases/20040815162342" @resource = Chef::Resource::Deploy.new("/my/deploy/dir") @node = Chef::Node.new @events = Chef::EventDispatch::Dispatcher.new @run_context = Chef::RunContext.new(@node, {}, @events) @timestamped_deploy = Chef::Provider::Deploy::Timestamped.new(@resource, @run_context) - @runner = mock("runnah") - Chef::Runner.stub!(:new).and_return(@runner) + @runner = double("runnah") + Chef::Runner.stub(:new).and_return(@runner) end it "gives a timestamp for release_slug" do diff --git a/spec/unit/provider/deploy_spec.rb b/spec/unit/provider/deploy_spec.rb index d9b1619d72..e6e4566011 100644 --- a/spec/unit/provider/deploy_spec.rb +++ b/spec/unit/provider/deploy_spec.rb @@ -22,15 +22,15 @@ describe Chef::Provider::Deploy do before do @release_time = Time.utc( 2004, 8, 15, 16, 23, 42) - Time.stub!(:now).and_return(@release_time) + Time.stub(:now).and_return(@release_time) @expected_release_dir = "/my/deploy/dir/releases/20040815162342" @resource = Chef::Resource::Deploy.new("/my/deploy/dir") @node = Chef::Node.new @events = Chef::EventDispatch::Dispatcher.new @run_context = Chef::RunContext.new(@node, {}, @events) @provider = Chef::Provider::Deploy.new(@resource, @run_context) - @provider.stub!(:release_slug) - @provider.stub!(:release_path).and_return(@expected_release_dir) + @provider.stub(:release_slug) + @provider.stub(:release_path).and_return(@expected_release_dir) end it "loads scm resource" do @@ -61,7 +61,7 @@ describe Chef::Provider::Deploy do before do FileUtils.should_receive(:mkdir_p).with(@resource.deploy_to).ordered FileUtils.should_receive(:mkdir_p).with(@resource.shared_path).ordered - ::File.stub!(:directory?).and_return(false) + ::File.stub(:directory?).and_return(false) @provider.stub(:symlink) @provider.stub(:migrate) @provider.stub(:copy_cached_repo) @@ -77,7 +77,7 @@ describe Chef::Provider::Deploy do end it "does not create deploy_to dir if it exists" do - ::File.stub!(:directory?).and_return(true) + ::File.stub(:directory?).and_return(true) ::Dir.should_receive(:chdir).with(@expected_release_dir).exactly(4).times FileUtils.should_not_receive(:mkdir_p).with(@resource.deploy_to) FileUtils.should_not_receive(:mkdir_p).with(@resource.shared_path) @@ -122,22 +122,22 @@ describe Chef::Provider::Deploy do end it "should not deploy if there is already a deploy at release_path, and it is the current release" do - @provider.stub!(:all_releases).and_return([@expected_release_dir]) - @provider.stub!(:current_release?).with(@expected_release_dir).and_return(true) + @provider.stub(:all_releases).and_return([@expected_release_dir]) + @provider.stub(:current_release?).with(@expected_release_dir).and_return(true) @provider.should_not_receive(:deploy) @provider.run_action(:deploy) end it "should call action_rollback if there is already a deploy of this revision at release_path, and it is not the current release" do - @provider.stub!(:all_releases).and_return([@expected_release_dir, "102021"]) - @provider.stub!(:current_release?).with(@expected_release_dir).and_return(false) + @provider.stub(:all_releases).and_return([@expected_release_dir, "102021"]) + @provider.stub(:current_release?).with(@expected_release_dir).and_return(false) @provider.should_receive(:rollback_to).with(@expected_release_dir) @provider.should_receive(:current_release?) @provider.run_action(:deploy) end it "calls deploy when deploying a new release" do - @provider.stub!(:all_releases).and_return([]) + @provider.stub(:all_releases).and_return([]) @provider.should_receive(:deploy) @provider.run_action(:deploy) end @@ -149,22 +149,22 @@ describe Chef::Provider::Deploy do end it "Removes the old release before deploying when force deploying over it" do - @provider.stub!(:all_releases).and_return([@expected_release_dir]) + @provider.stub(:all_releases).and_return([@expected_release_dir]) FileUtils.should_receive(:rm_rf).with(@expected_release_dir) @provider.should_receive(:deploy) @provider.run_action(:force_deploy) end it "deploys as normal when force deploying and there's no prior release at the same path" do - @provider.stub!(:all_releases).and_return([]) + @provider.stub(:all_releases).and_return([]) @provider.should_receive(:deploy) @provider.run_action(:force_deploy) end it "dont care by default if error happens on deploy" do - @provider.stub!(:all_releases).and_return(['previous_release']) - @provider.stub!(:deploy).and_return{ raise "Unexpected error" } - @provider.stub!(:previous_release_path).and_return('previous_release') + @provider.stub(:all_releases).and_return(['previous_release']) + @provider.stub(:deploy).and_return{ raise "Unexpected error" } + @provider.stub(:previous_release_path).and_return('previous_release') @provider.should_not_receive(:rollback) lambda { @provider.run_action(:deploy) @@ -173,9 +173,9 @@ describe Chef::Provider::Deploy do it "rollbacks to previous release if error happens on deploy" do @resource.rollback_on_error true - @provider.stub!(:all_releases).and_return(['previous_release']) - @provider.stub!(:deploy).and_return{ raise "Unexpected error" } - @provider.stub!(:previous_release_path).and_return('previous_release') + @provider.stub(:all_releases).and_return(['previous_release']) + @provider.stub(:deploy).and_return{ raise "Unexpected error" } + @provider.stub(:previous_release_path).and_return('previous_release') @provider.should_receive(:rollback) lambda { @provider.run_action(:deploy) @@ -184,9 +184,9 @@ describe Chef::Provider::Deploy do describe "on systems without broken Dir.glob results" do it "sets the release path to the penultimate release when one is not specified, symlinks, and rm's the last release on rollback" do - @provider.stub!(:release_path).and_return("/my/deploy/dir/releases/3") + @provider.stub(:release_path).and_return("/my/deploy/dir/releases/3") all_releases = ["/my/deploy/dir/releases/1", "/my/deploy/dir/releases/2", "/my/deploy/dir/releases/3", "/my/deploy/dir/releases/4", "/my/deploy/dir/releases/5"] - Dir.stub!(:glob).with("/my/deploy/dir/releases/*").and_return(all_releases) + Dir.stub(:glob).with("/my/deploy/dir/releases/*").and_return(all_releases) @provider.should_receive(:symlink) FileUtils.should_receive(:rm_rf).with("/my/deploy/dir/releases/4") FileUtils.should_receive(:rm_rf).with("/my/deploy/dir/releases/5") @@ -195,10 +195,10 @@ describe Chef::Provider::Deploy do end it "sets the release path to the specified release, symlinks, and rm's any newer releases on rollback" do - @provider.unstub!(:release_path) + @provider.unstub(:release_path) all_releases = ["/my/deploy/dir/releases/20040815162342", "/my/deploy/dir/releases/20040700000000", "/my/deploy/dir/releases/20040600000000", "/my/deploy/dir/releases/20040500000000"].sort! - Dir.stub!(:glob).with("/my/deploy/dir/releases/*").and_return(all_releases) + Dir.stub(:glob).with("/my/deploy/dir/releases/*").and_return(all_releases) @provider.should_receive(:symlink) FileUtils.should_receive(:rm_rf).with("/my/deploy/dir/releases/20040815162342") @provider.run_action(:rollback) @@ -206,12 +206,12 @@ describe Chef::Provider::Deploy do end it "sets the release path to the penultimate release, symlinks, and rm's the last release on rollback" do - @provider.unstub!(:release_path) + @provider.unstub(:release_path) all_releases = [ "/my/deploy/dir/releases/20040815162342", "/my/deploy/dir/releases/20040700000000", "/my/deploy/dir/releases/20040600000000", "/my/deploy/dir/releases/20040500000000"] - Dir.stub!(:glob).with("/my/deploy/dir/releases/*").and_return(all_releases) + Dir.stub(:glob).with("/my/deploy/dir/releases/*").and_return(all_releases) @provider.should_receive(:symlink) FileUtils.should_receive(:rm_rf).with("/my/deploy/dir/releases/20040815162342") @provider.run_action(:rollback) @@ -221,9 +221,9 @@ describe Chef::Provider::Deploy do describe "if there are no releases to fallback to" do it "an exception is raised when there is only 1 release" do - #@provider.unstub!(:release_path) -- unstub the release path on top to feed our own release path + #@provider.unstub(:release_path) -- unstub the release path on top to feed our own release path all_releases = [ "/my/deploy/dir/releases/20040815162342"] - Dir.stub!(:glob).with("/my/deploy/dir/releases/*").and_return(all_releases) + Dir.stub(:glob).with("/my/deploy/dir/releases/*").and_return(all_releases) #@provider.should_receive(:symlink) #FileUtils.should_receive(:rm_rf).with("/my/deploy/dir/releases/20040815162342") #@provider.run_action(:rollback) @@ -235,7 +235,7 @@ describe Chef::Provider::Deploy do it "an exception is raised when there are no releases" do all_releases = [] - Dir.stub!(:glob).with("/my/deploy/dir/releases/*").and_return(all_releases) + Dir.stub(:glob).with("/my/deploy/dir/releases/*").and_return(all_releases) lambda { @provider.run_action(:rollback) }.should raise_exception(RuntimeError, "There is no release to rollback to!") @@ -245,12 +245,12 @@ describe Chef::Provider::Deploy do describe "CHEF-628: on systems with broken Dir.glob results" do it "sets the release path to the penultimate release, symlinks, and rm's the last release on rollback" do - @provider.unstub!(:release_path) + @provider.unstub(:release_path) all_releases = [ "/my/deploy/dir/releases/20040500000000", "/my/deploy/dir/releases/20040600000000", "/my/deploy/dir/releases/20040700000000", "/my/deploy/dir/releases/20040815162342" ] - Dir.stub!(:glob).with("/my/deploy/dir/releases/*").and_return(all_releases) + Dir.stub(:glob).with("/my/deploy/dir/releases/*").and_return(all_releases) @provider.should_receive(:symlink) FileUtils.should_receive(:rm_rf).with("/my/deploy/dir/releases/20040815162342") @provider.run_action(:rollback) @@ -260,13 +260,13 @@ describe Chef::Provider::Deploy do it "raises a runtime error when there's no release to rollback to" do all_releases = [] - Dir.stub!(:glob).with("/my/deploy/dir/releases/*").and_return(all_releases) + Dir.stub(:glob).with("/my/deploy/dir/releases/*").and_return(all_releases) lambda {@provider.run_action(:rollback)}.should raise_error(RuntimeError) end it "runs the new resource collection in the runner during a callback" do - @runner = mock("Runner") - Chef::Runner.stub!(:new).and_return(@runner) + @runner = double("Runner") + Chef::Runner.stub(:new).and_return(@runner) @runner.should_receive(:converge) callback_code = Proc.new { :noop } @provider.callback(:whatevs, callback_code) @@ -342,8 +342,8 @@ describe Chef::Provider::Deploy do end it "calls the internal callback :release_created when cleaning up the releases" do - FileUtils.stub!(:mkdir_p) - FileUtils.stub!(:cp_r) + FileUtils.stub(:mkdir_p) + FileUtils.stub(:cp_r) @provider.should_receive(:release_created) @provider.cleanup! end @@ -371,8 +371,8 @@ describe Chef::Provider::Deploy do FileUtils.should_receive(:ln_sf).with("/my/deploy/dir/shared/config/database.yml", @expected_release_dir + "/config/database.yml") @provider.should_receive(:enforce_ownership) - STDOUT.stub!(:tty?).and_return(true) - Chef::Log.stub!(:info?).and_return(true) + STDOUT.stub(:tty?).and_return(true) + Chef::Log.stub(:info?).and_return(true) @provider.should_receive(:run_command).with(:command => "migration_foo", :cwd => @expected_release_dir, :user => "deployNinja", :group => "deployNinjas", :log_level => :info, :live_stream => STDOUT, @@ -462,7 +462,7 @@ describe Chef::Provider::Deploy do "/my/deploy/dir/20040600000000", "/my/deploy/dir/20040500000000", "/my/deploy/dir/20040400000000", "/my/deploy/dir/20040300000000", "/my/deploy/dir/20040200000000", "/my/deploy/dir/20040100000000"].sort! - @provider.stub!(:all_releases).and_return(all_releases) + @provider.stub(:all_releases).and_return(all_releases) FileUtils.should_receive(:rm_rf).with("/my/deploy/dir/20040100000000") FileUtils.should_receive(:rm_rf).with("/my/deploy/dir/20040200000000") FileUtils.should_receive(:rm_rf).with("/my/deploy/dir/20040300000000") @@ -475,7 +475,7 @@ describe Chef::Provider::Deploy do "/my/deploy/dir/20040600000000", "/my/deploy/dir/20040500000000", "/my/deploy/dir/20040400000000", "/my/deploy/dir/20040300000000", "/my/deploy/dir/20040200000000", "/my/deploy/dir/20040100000000"].sort! - @provider.stub!(:all_releases).and_return(all_releases) + @provider.stub(:all_releases).and_return(all_releases) FileUtils.should_receive(:rm_rf).with("/my/deploy/dir/20040100000000") @provider.cleanup! end @@ -484,8 +484,8 @@ describe Chef::Provider::Deploy do all_releases = ["/my/deploy/dir/20040815162342", "/my/deploy/dir/20040700000000", "/my/deploy/dir/20040600000000", "/my/deploy/dir/20040500000000", "/my/deploy/dir/20040400000000", "/my/deploy/dir/20040300000000"].sort! - @provider.stub!(:all_releases).and_return(all_releases) - FileUtils.stub!(:rm_rf) + @provider.stub(:all_releases).and_return(all_releases) + FileUtils.stub(:rm_rf) @provider.should_receive(:release_deleted).with("/my/deploy/dir/20040300000000") @provider.cleanup! end @@ -502,9 +502,9 @@ describe Chef::Provider::Deploy do end it "shouldn't give a no method error on migrate if the environment is nil" do - @provider.stub!(:enforce_ownership) - @provider.stub!(:run_symlinks_before_migrate) - @provider.stub!(:run_command) + @provider.stub(:enforce_ownership) + @provider.stub(:run_symlinks_before_migrate) + @provider.stub(:run_command) @provider.migrate end @@ -543,7 +543,7 @@ describe Chef::Provider::Deploy do end it "defines run as a forwarder to execute, setting the user, group, cwd and environment to new_resource.user" do - mock_execution = mock("Resource::Execute") + mock_execution = double("Resource::Execute") @provider.should_receive(:execute).with("iGoToHell4this").and_return(mock_execution) @resource.user("notCoolMan") @resource.group("Ggroup") @@ -572,7 +572,7 @@ describe Chef::Provider::Deploy do end it "defines run as a forwarder to execute, setting cwd and environment but not override" do - mock_execution = mock("Resource::Execute") + mock_execution = double("Resource::Execute") @provider.should_receive(:execute).with("iGoToHell4this").and_return(mock_execution) @resource.user("notCoolMan") mock_execution.should_receive(:user).with("notCoolMan") @@ -583,8 +583,8 @@ describe Chef::Provider::Deploy do it "converts sudo and run to exec resources in hooks" do - runner = mock("tehRunner") - Chef::Runner.stub!(:new).and_return(runner) + runner = double("tehRunner") + Chef::Runner.stub(:new).and_return(runner) snitch = nil @resource.user("tehCat") @@ -607,7 +607,7 @@ describe Chef::Provider::Deploy do describe "installing gems from a gems.yml" do before do - ::File.stub!(:exist?).with("#{@expected_release_dir}/gems.yml").and_return(true) + ::File.stub(:exist?).with("#{@expected_release_dir}/gems.yml").and_return(true) @gem_list = [{:name=>"eventmachine", :version=>"0.12.9"}] end @@ -623,8 +623,8 @@ describe Chef::Provider::Deploy do end it "takes a list of gem providers converges them" do - IO.stub!(:read) - YAML.stub!(:load).and_return(@gem_list) + IO.stub(:read) + YAML.stub(:load).and_return(@gem_list) expected_gem_resources = @provider.send(:gem_packages).map { |r| [r.name, r.version] } gem_runner = @provider.send(:gem_resource_collection_runner) # no one has heard of defining == to be meaningful so I have use this monstrosity diff --git a/spec/unit/provider/directory_spec.rb b/spec/unit/provider/directory_spec.rb index 61946d2664..25ca9e0175 100644 --- a/spec/unit/provider/directory_spec.rb +++ b/spec/unit/provider/directory_spec.rb @@ -48,18 +48,18 @@ describe Chef::Provider::Directory do describe "scanning file security metadata on unix" do before do - Chef::Platform.stub!(:windows?).and_return(false) + Chef::Platform.stub(:windows?).and_return(false) end let(:mock_stat) do - cstats = mock("stats") - cstats.stub!(:uid).and_return(500) - cstats.stub!(:gid).and_return(500) - cstats.stub!(:mode).and_return(0755) + cstats = double("stats") + cstats.stub(:uid).and_return(500) + cstats.stub(:gid).and_return(500) + cstats.stub(:mode).and_return(0755) cstats end it "describes the access mode as a String of octal integers" do - File.stub!(:exists?).and_return(true) + File.stub(:exists?).and_return(true) File.should_receive(:stat).and_return(mock_stat) @directory.load_current_resource @directory.current_resource.mode.should == "0755" @@ -67,7 +67,7 @@ describe Chef::Provider::Directory do context "when user and group are specified with UID/GID" do it "describes the current owner and group as UID and GID" do - File.stub!(:exists?).and_return(true) + File.stub(:exists?).and_return(true) File.should_receive(:stat).and_return(mock_stat) @directory.load_current_resource @directory.current_resource.path.should eql(@new_resource.path) @@ -91,7 +91,7 @@ describe Chef::Provider::Directory do Dir.should_receive(:mkdir).with(@new_resource.path).once.and_return(true) @directory.should_receive(:do_acl_changes) - @directory.stub!(:do_selinux) + @directory.stub(:do_selinux) @directory.run_action(:create) @directory.new_resource.should be_updated end @@ -117,7 +117,7 @@ describe Chef::Provider::Directory do FileUtils.should_receive(:mkdir_p).with(@new_resource.path).and_return(true) @directory.should_receive(:do_acl_changes) - @directory.stub!(:do_selinux) + @directory.stub(:do_selinux) @directory.run_action(:create) @new_resource.should be_updated end @@ -152,14 +152,14 @@ describe Chef::Provider::Directory do end it "should raise an exception if it cannot delete the directory due to bad permissions" do - File.stub!(:exists?).and_return(true) - File.stub!(:writable?).and_return(false) + File.stub(:exists?).and_return(true) + File.stub(:writable?).and_return(false) lambda { @directory.run_action(:delete) }.should raise_error(RuntimeError) end it "should take no action when deleting a target directory that does not exist" do @new_resource.path "/an/invalid/path" - File.stub!(:exists?).and_return(false) + File.stub(:exists?).and_return(false) Dir.should_not_receive(:delete).with(@new_resource.path) @directory.run_action(:delete) @directory.new_resource.should_not be_updated @@ -168,7 +168,7 @@ describe Chef::Provider::Directory do it "should raise an exception when deleting a directory when target directory is a file" do stub_file_cstats @new_resource.path "/an/invalid/path" - File.stub!(:exists?).and_return(true) + File.stub(:exists?).and_return(true) File.should_receive(:directory?).and_return(false) Dir.should_not_receive(:delete).with(@new_resource.path) lambda { @directory.run_action(:delete) }.should raise_error(RuntimeError) @@ -176,13 +176,13 @@ describe Chef::Provider::Directory do end def stub_file_cstats - cstats = mock("stats") - cstats.stub!(:uid).and_return(500) - cstats.stub!(:gid).and_return(500) - cstats.stub!(:mode).and_return(0755) + cstats = double("stats") + cstats.stub(:uid).and_return(500) + cstats.stub(:gid).and_return(500) + cstats.stub(:mode).and_return(0755) # File.stat is called in: # - Chef::Provider::File.load_current_resource_attrs # - Chef::ScanAccessControl via Chef::Provider::File.setup_acl - File.stub!(:stat).and_return(cstats) + File.stub(:stat).and_return(cstats) end end diff --git a/spec/unit/provider/env_spec.rb b/spec/unit/provider/env_spec.rb index 673ba9798a..0bc5117e48 100644 --- a/spec/unit/provider/env_spec.rb +++ b/spec/unit/provider/env_spec.rb @@ -36,10 +36,10 @@ describe Chef::Provider::Env do describe "when loading the current status" do before do #@current_resource = @new_resource.clone - #Chef::Resource::Env.stub!(:new).and_return(@current_resource) + #Chef::Resource::Env.stub(:new).and_return(@current_resource) @provider.current_resource = @current_resource - @provider.stub!(:env_value).with("FOO").and_return("bar") - @provider.stub!(:env_key_exists).and_return(true) + @provider.stub(:env_value).with("FOO").and_return("bar") + @provider.stub(:env_key_exists).and_return(true) end it "should create a current resource with the same name as the new resource" do @@ -72,8 +72,8 @@ describe Chef::Provider::Env do describe "action_create" do before do @provider.key_exists = false - @provider.stub!(:create_env).and_return(true) - @provider.stub!(:modify_env).and_return(true) + @provider.stub(:create_env).and_return(true) + @provider.stub(:modify_env).and_return(true) end it "should call create_env if the key does not exist" do @@ -94,15 +94,15 @@ describe Chef::Provider::Env do it "should call modify_env if the key exists and values are not equal" do @provider.key_exists = true - @provider.stub!(:compare_value).and_return(true) + @provider.stub(:compare_value).and_return(true) @provider.should_receive(:modify_env).and_return(true) @provider.action_create end it "should set the new_resources updated flag when it updates an existing value" do @provider.key_exists = true - @provider.stub!(:compare_value).and_return(true) - @provider.stub!(:modify_env).and_return(true) + @provider.stub(:compare_value).and_return(true) + @provider.stub(:modify_env).and_return(true) @provider.action_create @new_resource.should be_updated end @@ -112,8 +112,8 @@ describe Chef::Provider::Env do before(:each) do @provider.current_resource = @current_resource @provider.key_exists = false - @provider.stub!(:delete_element).and_return(false) - @provider.stub!(:delete_env).and_return(true) + @provider.stub(:delete_element).and_return(false) + @provider.stub(:delete_env).and_return(true) end it "should not call delete_env if the key does not exist" do @@ -143,7 +143,7 @@ describe Chef::Provider::Env do before(:each) do @provider.current_resource = @current_resource @provider.key_exists = true - @provider.stub!(:modify_env).and_return(true) + @provider.stub(:modify_env).and_return(true) end it "should call modify_group if the key exists and values are not equal" do @@ -153,8 +153,8 @@ describe Chef::Provider::Env do end it "should set the new resources updated flag to true if modify_env is called" do - @provider.stub!(:compare_value).and_return(true) - @provider.stub!(:modify_env).and_return(true) + @provider.stub(:compare_value).and_return(true) + @provider.stub(:modify_env).and_return(true) @provider.action_modify @new_resource.should be_updated end @@ -183,12 +183,12 @@ describe Chef::Provider::Env do end it "should return true if the element is not found" do - @new_resource.stub!(:value).and_return("C:/baz/bin") + @new_resource.stub(:value).and_return("C:/baz/bin") @provider.delete_element.should eql(true) end it "should return false if the delim not defined" do - @new_resource.stub!(:delim).and_return(nil) + @new_resource.stub(:delim).and_return(nil) @provider.delete_element.should eql(false) end diff --git a/spec/unit/provider/erl_call_spec.rb b/spec/unit/provider/erl_call_spec.rb index fa85b6cda7..19e16f282f 100644 --- a/spec/unit/provider/erl_call_spec.rb +++ b/spec/unit/provider/erl_call_spec.rb @@ -31,7 +31,7 @@ describe Chef::Provider::ErlCall do @provider = Chef::Provider::ErlCall.new(@new_resource, @run_context) - @provider.stub!(:popen4).and_return(@status) + @provider.stub(:popen4).and_return(@status) @stdin = StringIO.new @stdout = StringIO.new('{ok, woohoo}') @stderr = StringIO.new diff --git a/spec/unit/provider/execute_spec.rb b/spec/unit/provider/execute_spec.rb index 0d108f521d..78216a89fa 100644 --- a/spec/unit/provider/execute_spec.rb +++ b/spec/unit/provider/execute_spec.rb @@ -33,12 +33,12 @@ describe Chef::Provider::Execute do @provider.current_resource = @current_resource Chef::Log.level = :info # FIXME: There should be a test for how STDOUT.tty? changes the live_stream option being passed - STDOUT.stub!(:tty?).and_return(true) + STDOUT.stub(:tty?).and_return(true) end it "should execute foo_resource" do - @provider.stub!(:load_current_resource) + @provider.stub(:load_current_resource) opts = {} opts[:timeout] = @new_resource.timeout opts[:returns] = @new_resource.returns @@ -53,7 +53,7 @@ describe Chef::Provider::Execute do end it "should do nothing if the sentinel file exists" do - @provider.stub!(:load_current_resource) + @provider.stub(:load_current_resource) File.should_receive(:exists?).with(@new_resource.creates).and_return(true) @provider.should_not_receive(:shell_out!) Chef::Log.should_not_receive(:warn) @@ -65,7 +65,7 @@ describe Chef::Provider::Execute do it "should respect cwd options for 'creates'" do @new_resource.cwd "/tmp" @new_resource.creates "foo_resource" - @provider.stub!(:load_current_resource) + @provider.stub(:load_current_resource) File.should_receive(:exists?).with(@new_resource.creates).and_return(false) File.should_receive(:exists?).with(File.join("/tmp", @new_resource.creates)).and_return(true) Chef::Log.should_not_receive(:warn) @@ -77,7 +77,7 @@ describe Chef::Provider::Execute do it "should warn if user specified relative path without cwd" do @new_resource.creates "foo_resource" - @provider.stub!(:load_current_resource) + @provider.stub(:load_current_resource) Chef::Log.should_receive(:warn).with(/relative path/) File.should_receive(:exists?).with(@new_resource.creates).and_return(true) @provider.should_not_receive(:shell_out!) diff --git a/spec/unit/provider/file/content_spec.rb b/spec/unit/provider/file/content_spec.rb index 9262a35245..34d98b6619 100644 --- a/spec/unit/provider/file/content_spec.rb +++ b/spec/unit/provider/file/content_spec.rb @@ -25,7 +25,7 @@ describe Chef::Provider::File::Content do # let(:current_resource) do - mock("Chef::Provider::File::Resource (current)") + double("Chef::Provider::File::Resource (current)") end let(:enclosing_directory) { @@ -36,11 +36,11 @@ describe Chef::Provider::File::Content do } let(:new_resource) do - mock("Chef::Provider::File::Resource (new)", :name => "seattle.txt", :path => resource_path) + double("Chef::Provider::File::Resource (new)", :name => "seattle.txt", :path => resource_path) end let(:run_context) do - mock("Chef::RunContext") + double("Chef::RunContext") end # @@ -53,7 +53,7 @@ describe Chef::Provider::File::Content do describe "when the resource has a content attribute set" do before do - new_resource.stub!(:content).and_return("Do do do do, do do do do, do do do do, do do do do") + new_resource.stub(:content).and_return("Do do do do, do do do do, do do do do, do do do do") end it "returns a tempfile" do @@ -81,7 +81,7 @@ describe Chef::Provider::File::Content do describe "when the resource does not have a content attribute set" do before do - new_resource.stub!(:content).and_return(nil) + new_resource.stub(:content).and_return(nil) end it "should return nil instead of a tempfile" do diff --git a/spec/unit/provider/file_spec.rb b/spec/unit/provider/file_spec.rb index 6c401e3030..059f1722fb 100644 --- a/spec/unit/provider/file_spec.rb +++ b/spec/unit/provider/file_spec.rb @@ -29,7 +29,7 @@ describe Chef::Provider::File do end let(:content) do - content = mock('Chef::Provider::File::Content') + content = double('Chef::Provider::File::Content') end let(:node) { double('Chef::Node') } diff --git a/spec/unit/provider/git_spec.rb b/spec/unit/provider/git_spec.rb index 4c54a17958..b18a2a8996 100644 --- a/spec/unit/provider/git_spec.rb +++ b/spec/unit/provider/git_spec.rb @@ -21,7 +21,7 @@ require 'spec_helper' describe Chef::Provider::Git do before(:each) do - STDOUT.stub!(:tty?).and_return(true) + STDOUT.stub(:tty?).and_return(true) Chef::Log.level = :info @current_resource = Chef::Resource::Git.new("web2.0 app") @@ -41,9 +41,9 @@ describe Chef::Provider::Git do context "determining the revision of the currently deployed checkout" do before do - @stdout = mock("standard out") - @stderr = mock("standard error") - @exitstatus = mock("exitstatus") + @stdout = double("standard out") + @stderr = double("standard error") + @exitstatus = double("exitstatus") end it "sets the current revision to nil if the deploy dir does not exist" do @@ -54,7 +54,7 @@ describe Chef::Provider::Git do it "determines the current revision when there is one" do ::File.should_receive(:exist?).with("/my/deploy/dir/.git").and_return(true) @stdout = "9b4d8dc38dd471246e7cfb1c3c1ad14b0f2bee13\n" - @provider.should_receive(:shell_out!).with('git rev-parse HEAD', {:cwd => '/my/deploy/dir', :returns => [0,128]}).and_return(mock("ShellOut result", :stdout => @stdout)) + @provider.should_receive(:shell_out!).with('git rev-parse HEAD', {:cwd => '/my/deploy/dir', :returns => [0,128]}).and_return(double("ShellOut result", :stdout => @stdout)) @provider.find_current_revision.should eql("9b4d8dc38dd471246e7cfb1c3c1ad14b0f2bee13") end @@ -62,13 +62,13 @@ describe Chef::Provider::Git do ::File.should_receive(:exist?).with("/my/deploy/dir/.git").and_return(true) @stderr = "fatal: Not a git repository (or any of the parent directories): .git" @stdout = "" - @provider.should_receive(:shell_out!).with('git rev-parse HEAD', :cwd => '/my/deploy/dir', :returns => [0,128]).and_return(mock("ShellOut result", :stdout => "", :stderr => @stderr)) + @provider.should_receive(:shell_out!).with('git rev-parse HEAD', :cwd => '/my/deploy/dir', :returns => [0,128]).and_return(double("ShellOut result", :stdout => "", :stderr => @stderr)) @provider.find_current_revision.should be_nil end end it "creates a current_resource with the currently deployed revision when a clone exists in the destination dir" do - @provider.stub!(:find_current_revision).and_return("681c9802d1c62a45b490786c18f0b8216b309440") + @provider.stub(:find_current_revision).and_return("681c9802d1c62a45b490786c18f0b8216b309440") @provider.load_current_resource @provider.current_resource.name.should eql(@resource.name) @provider.current_resource.revision.should eql("681c9802d1c62a45b490786c18f0b8216b309440") @@ -93,7 +93,7 @@ describe Chef::Provider::Git do @resource.revision "v1.0" @stdout = ("d03c22a5e41f5ae3193460cca044ed1435029f53\trefs/heads/0.8-alpha\n" + "503c22a5e41f5ae3193460cca044ed1435029f53\trefs/heads/v1.0\n") - @provider.should_receive(:shell_out!).with(@git_ls_remote + "v1.0*", {:log_tag=>"git[web2.0 app]"}).and_return(mock("ShellOut result", :stdout => @stdout)) + @provider.should_receive(:shell_out!).with(@git_ls_remote + "v1.0*", {:log_tag=>"git[web2.0 app]"}).and_return(double("ShellOut result", :stdout => @stdout)) @provider.target_revision.should eql("503c22a5e41f5ae3193460cca044ed1435029f53") end @@ -102,7 +102,7 @@ describe Chef::Provider::Git do @stdout = ("d03c22a5e41f5ae3193460cca044ed1435029f53\trefs/heads/0.8-alpha\n" + "503c22a5e41f5ae3193460cca044ed1435029f53\trefs/heads/v1.0\n" + "663c22a5e41f5ae3193460cca044ed1435029f53\trefs/heads/v1.0^{}\n") - @provider.should_receive(:shell_out!).with(@git_ls_remote + "v1.0*", {:log_tag=>"git[web2.0 app]"}).and_return(mock("ShellOut result", :stdout => @stdout)) + @provider.should_receive(:shell_out!).with(@git_ls_remote + "v1.0*", {:log_tag=>"git[web2.0 app]"}).and_return(double("ShellOut result", :stdout => @stdout)) @provider.target_revision.should eql("663c22a5e41f5ae3193460cca044ed1435029f53") end @@ -110,32 +110,32 @@ describe Chef::Provider::Git do @resource.revision "origin/" @provider.action = :checkout @provider.define_resource_requirements - ::File.stub!(:directory?).with("/my/deploy").and_return(true) + ::File.stub(:directory?).with("/my/deploy").and_return(true) lambda {@provider.process_resource_requirements}.should raise_error(Chef::Exceptions::InvalidRemoteGitReference) end it "raises an unresolvable git reference error if the revision can't be resolved to any revision and assertions are run" do @resource.revision "FAIL, that's the revision I want" @provider.action = :checkout - @provider.should_receive(:shell_out!).and_return(mock("ShellOut result", :stdout => "\n")) + @provider.should_receive(:shell_out!).and_return(double("ShellOut result", :stdout => "\n")) @provider.define_resource_requirements lambda { @provider.process_resource_requirements }.should raise_error(Chef::Exceptions::UnresolvableGitReference) end it "does not raise an error if the revision can't be resolved when assertions are not run" do @resource.revision "FAIL, that's the revision I want" - @provider.should_receive(:shell_out!).and_return(mock("ShellOut result", :stdout => "\n")) + @provider.should_receive(:shell_out!).and_return(double("ShellOut result", :stdout => "\n")) @provider.target_revision.should == nil end it "does not raise an error when the revision is valid and assertions are run." do @resource.revision "0.8-alpha" @stdout = "503c22a5e41f5ae3193460cca044ed1435029f53\trefs/heads/0.8-alpha\n" - @provider.should_receive(:shell_out!).with(@git_ls_remote + "0.8-alpha*", {:log_tag=>"git[web2.0 app]"}).and_return(mock("ShellOut result", :stdout => @stdout)) + @provider.should_receive(:shell_out!).with(@git_ls_remote + "0.8-alpha*", {:log_tag=>"git[web2.0 app]"}).and_return(double("ShellOut result", :stdout => @stdout)) @provider.action = :checkout - ::File.stub!(:directory?).with("/my/deploy").and_return(true) + ::File.stub(:directory?).with("/my/deploy").and_return(true) @provider.define_resource_requirements - lambda { @provider.process_resource_requirements }.should_not raise_error(RuntimeError) + lambda { @provider.process_resource_requirements }.should_not raise_error end it "gives the latest HEAD revision SHA if nothing is specified" do @@ -156,7 +156,7 @@ b7d19519a1c15f1c1a324e2683bd728b6198ce5a\trefs/tags/0.7.8^{} ebc1b392fe7e8f0fbabc305c299b4d365d2b4d9b\trefs/tags/chef-server-package SHAS @resource.revision '' - @provider.should_receive(:shell_out!).with(@git_ls_remote + "HEAD", {:log_tag=>"git[web2.0 app]"}).and_return(mock("ShellOut result", :stdout => @stdout)) + @provider.should_receive(:shell_out!).with(@git_ls_remote + "HEAD", {:log_tag=>"git[web2.0 app]"}).and_return(double("ShellOut result", :stdout => @stdout)) @provider.target_revision.should eql("28af684d8460ba4793eda3e7ac238c864a5d029a") end end @@ -179,7 +179,7 @@ SHAS before do @resource.user deploy_user @resource.ssh_wrapper wrapper - Etc.stub!(:getpwnam).and_return(double("Struct::Passwd", :name => @resource.user, :dir => "/home/deployNinja")) + Etc.stub(:getpwnam).and_return(double("Struct::Passwd", :name => @resource.user, :dir => "/home/deployNinja")) end context "without a timeout set" do it "clones a repo with default git options" do @@ -199,7 +199,7 @@ SHAS it "runs a clone command with escaped destination" do @resource.user "deployNinja" - Etc.stub!(:getpwnam).and_return(double("Struct::Passwd", :name => @resource.user, :dir => "/home/deployNinja")) + Etc.stub(:getpwnam).and_return(double("Struct::Passwd", :name => @resource.user, :dir => "/home/deployNinja")) @resource.destination "/Application Support/with/space" @resource.ssh_wrapper "do_it_this_way.sh" expected_cmd = "git clone \"git://github.com/opscode/chef.git\" \"/Application Support/with/space\"" @@ -255,7 +255,7 @@ SHAS it "runs a sync command with the user and group specified in the resource" do @resource.user("whois") - Etc.stub!(:getpwnam).and_return(double("Struct::Passwd", :name => @resource.user, :dir => "/home/whois")) + Etc.stub(:getpwnam).and_return(double("Struct::Passwd", :name => @resource.user, :dir => "/home/whois")) @resource.group("thisis") @provider.should_receive(:setup_remote_tracking_branches).with(@resource.remote, @resource.repository) expected_cmd = "git fetch origin && git fetch origin --tags && git reset --hard d35af14d41ae22b19da05d7d03a0bafc321b244c" @@ -302,7 +302,7 @@ SHAS it "runs the config with the user and group specified in the resource" do @resource.user("whois") @resource.group("thisis") - Etc.stub!(:getpwnam).and_return(double("Struct::Passwd", :name => @resource.user, :dir => "/home/whois")) + Etc.stub(:getpwnam).and_return(double("Struct::Passwd", :name => @resource.user, :dir => "/home/whois")) command_response = double('shell_out') command_response.stub(:exitstatus) { 1 } expected_command = "git config --get remote.#{@resource.remote}.url" @@ -391,17 +391,17 @@ SHAS end it "raises an error if the git clone command would fail because the enclosing directory doesn't exist" do - @provider.stub!(:shell_out!) + @provider.stub(:shell_out!) lambda {@provider.run_action(:sync)}.should raise_error(Chef::Exceptions::MissingParentDirectory) end it "does a checkout by cloning the repo and then enabling submodules" do # will be invoked in load_current_resource - ::File.stub!(:exist?).with("/my/deploy/dir/.git").and_return(false) + ::File.stub(:exist?).with("/my/deploy/dir/.git").and_return(false) - ::File.stub!(:exist?).with("/my/deploy/dir").and_return(true) - ::File.stub!(:directory?).with("/my/deploy").and_return(true) - ::Dir.stub!(:entries).with("/my/deploy/dir").and_return(['.','..']) + ::File.stub(:exist?).with("/my/deploy/dir").and_return(true) + ::File.stub(:directory?).with("/my/deploy").and_return(true) + ::Dir.stub(:entries).with("/my/deploy/dir").and_return(['.','..']) @provider.should_receive(:clone) @provider.should_receive(:checkout) @provider.should_receive(:enable_submodules) @@ -413,11 +413,11 @@ SHAS it "does not call checkout if enable_checkout is false" do # will be invoked in load_current_resource - ::File.stub!(:exist?).with("/my/deploy/dir/.git").and_return(false) + ::File.stub(:exist?).with("/my/deploy/dir/.git").and_return(false) - ::File.stub!(:exist?).with("/my/deploy/dir").and_return(true) - ::File.stub!(:directory?).with("/my/deploy").and_return(true) - ::Dir.stub!(:entries).with("/my/deploy/dir").and_return(['.','..']) + ::File.stub(:exist?).with("/my/deploy/dir").and_return(true) + ::File.stub(:directory?).with("/my/deploy").and_return(true) + ::Dir.stub(:entries).with("/my/deploy/dir").and_return(['.','..']) @resource.enable_checkout false @provider.should_receive(:clone) @@ -429,10 +429,10 @@ SHAS # REGRESSION TEST: on some OSes, the entries from an empty directory will be listed as # ['..', '.'] but this shouldn't change the behavior it "does a checkout by cloning the repo and then enabling submodules when the directory entries are listed as %w{.. .}" do - ::File.stub!(:exist?).with("/my/deploy/dir/.git").and_return(false) - ::File.stub!(:exist?).with("/my/deploy/dir").and_return(false) - ::File.stub!(:directory?).with("/my/deploy").and_return(true) - ::Dir.stub!(:entries).with("/my/deploy/dir").and_return(['..','.']) + ::File.stub(:exist?).with("/my/deploy/dir/.git").and_return(false) + ::File.stub(:exist?).with("/my/deploy/dir").and_return(false) + ::File.stub(:directory?).with("/my/deploy").and_return(true) + ::Dir.stub(:entries).with("/my/deploy/dir").and_return(['..','.']) @provider.should_receive(:clone) @provider.should_receive(:checkout) @provider.should_receive(:enable_submodules) @@ -443,11 +443,11 @@ SHAS it "should not checkout if the destination exists or is a non empty directory" do # will be invoked in load_current_resource - ::File.stub!(:exist?).with("/my/deploy/dir/.git").and_return(false) + ::File.stub(:exist?).with("/my/deploy/dir/.git").and_return(false) - ::File.stub!(:exist?).with("/my/deploy/dir").and_return(true) - ::File.stub!(:directory?).with("/my/deploy").and_return(true) - ::Dir.stub!(:entries).with("/my/deploy/dir").and_return(['.','..','foo','bar']) + ::File.stub(:exist?).with("/my/deploy/dir").and_return(true) + ::File.stub(:directory?).with("/my/deploy").and_return(true) + ::Dir.stub(:entries).with("/my/deploy/dir").and_return(['.','..','foo','bar']) @provider.should_not_receive(:clone) @provider.should_not_receive(:checkout) @provider.should_not_receive(:enable_submodules) @@ -458,7 +458,7 @@ SHAS it "syncs the code by updating the source when the repo has already been checked out" do ::File.should_receive(:exist?).with("/my/deploy/dir/.git").and_return(true) - ::File.stub!(:directory?).with("/my/deploy").and_return(true) + ::File.stub(:directory?).with("/my/deploy").and_return(true) @provider.should_receive(:find_current_revision).exactly(2).and_return('d35af14d41ae22b19da05d7d03a0bafc321b244c') @provider.should_not_receive(:fetch_updates) @provider.should_receive(:add_remotes) @@ -468,10 +468,10 @@ SHAS it "marks the resource as updated when the repo is updated and gets a new version" do ::File.should_receive(:exist?).with("/my/deploy/dir/.git").and_return(true) - ::File.stub!(:directory?).with("/my/deploy").and_return(true) + ::File.stub(:directory?).with("/my/deploy").and_return(true) # invoked twice - first time from load_current_resource @provider.should_receive(:find_current_revision).exactly(2).and_return('d35af14d41ae22b19da05d7d03a0bafc321b244c') - @provider.stub!(:target_revision).and_return('28af684d8460ba4793eda3e7ac238c864a5d029a') + @provider.stub(:target_revision).and_return('28af684d8460ba4793eda3e7ac238c864a5d029a') @provider.should_receive(:fetch_updates) @provider.should_receive(:enable_submodules) @provider.should_receive(:add_remotes) @@ -481,9 +481,9 @@ SHAS it "does not fetch any updates if the remote revision matches the current revision" do ::File.should_receive(:exist?).with("/my/deploy/dir/.git").and_return(true) - ::File.stub!(:directory?).with("/my/deploy").and_return(true) - @provider.stub!(:find_current_revision).and_return('d35af14d41ae22b19da05d7d03a0bafc321b244c') - @provider.stub!(:target_revision).and_return('d35af14d41ae22b19da05d7d03a0bafc321b244c') + ::File.stub(:directory?).with("/my/deploy").and_return(true) + @provider.stub(:find_current_revision).and_return('d35af14d41ae22b19da05d7d03a0bafc321b244c') + @provider.stub(:target_revision).and_return('d35af14d41ae22b19da05d7d03a0bafc321b244c') @provider.should_not_receive(:fetch_updates) @provider.should_receive(:add_remotes) @provider.run_action(:sync) @@ -491,7 +491,7 @@ SHAS end it "clones the repo instead of fetching it if the deploy directory doesn't exist" do - ::File.stub!(:directory?).with("/my/deploy").and_return(true) + ::File.stub(:directory?).with("/my/deploy").and_return(true) ::File.should_receive(:exist?).with("/my/deploy/dir/.git").exactly(2).and_return(false) @provider.should_receive(:action_checkout) @provider.should_not_receive(:shell_out!) @@ -501,9 +501,9 @@ SHAS it "clones the repo instead of fetching updates if the deploy directory is empty" do ::File.should_receive(:exist?).with("/my/deploy/dir/.git").exactly(2).and_return(false) - ::File.stub!(:directory?).with("/my/deploy").and_return(true) - ::File.stub!(:directory?).with("/my/deploy/dir").and_return(true) - @provider.stub!(:sync_command).and_return("huzzah!") + ::File.stub(:directory?).with("/my/deploy").and_return(true) + ::File.stub(:directory?).with("/my/deploy/dir").and_return(true) + @provider.stub(:sync_command).and_return("huzzah!") @provider.should_receive(:action_checkout) @provider.should_not_receive(:shell_out!).with("huzzah!", :cwd => "/my/deploy/dir") @provider.run_action(:sync) diff --git a/spec/unit/provider/group/dscl_spec.rb b/spec/unit/provider/group/dscl_spec.rb index 360a799b5f..5a02ee8dfb 100644 --- a/spec/unit/provider/group/dscl_spec.rb +++ b/spec/unit/provider/group/dscl_spec.rb @@ -27,12 +27,12 @@ describe Chef::Provider::Group::Dscl do @current_resource = Chef::Resource::Group.new("aj") @provider = Chef::Provider::Group::Dscl.new(@new_resource, @run_context) @provider.current_resource = @current_resource - @status = mock("Process::Status", :exitstatus => 0) + @status = double("Process::Status", :exitstatus => 0) @pid = 2342 @stdin = StringIO.new @stdout = StringIO.new("\n") @stderr = StringIO.new("") - @provider.stub!(:popen4).and_yield(@pid,@stdin,@stdout,@stderr).and_return(@status) + @provider.stub(:popen4).and_yield(@pid,@stdin,@stdout,@stderr).and_return(@status) end it "should run popen4 with the supplied array of arguments appended to the dscl command" do @@ -50,7 +50,7 @@ describe Chef::Provider::Group::Dscl do before do @node = Chef::Node.new @provider = Chef::Provider::Group::Dscl.new(@node, @new_resource) - @provider.stub!(:dscl).and_return(["cmd", @status, "stdout", "stderr"]) + @provider.stub(:dscl).and_return(["cmd", @status, "stdout", "stderr"]) end it "should run dscl with the supplied cmd /Path args" do @@ -60,8 +60,8 @@ describe Chef::Provider::Group::Dscl do describe "with the dscl command returning a non zero exit status for a delete" do before do - @status = mock("Process::Status", :exitstatus => 1) - @provider.stub!(:dscl).and_return(["cmd", @status, "stdout", "stderr"]) + @status = double("Process::Status", :exitstatus => 1) + @provider.stub(:dscl).and_return(["cmd", @status, "stdout", "stderr"]) end it "should return an empty string of standard output for a delete" do @@ -77,7 +77,7 @@ describe Chef::Provider::Group::Dscl do describe "with the dscl command returning no such key" do before do - @provider.stub!(:dscl).and_return(["cmd", @status, "No such key: ", "stderr"]) + @provider.stub(:dscl).and_return(["cmd", @status, "No such key: ", "stderr"]) end it "should raise an exception" do @@ -98,7 +98,7 @@ describe Chef::Provider::Group::Dscl do before do @node = Chef::Node.new @provider = Chef::Provider::Group::Dscl.new(@node, @new_resource) - @provider.stub!(:safe_dscl).and_return("\naj 200\njt 201\n") + @provider.stub(:safe_dscl).and_return("\naj 200\njt 201\n") end it "should run safe_dscl with list /Groups gid" do @@ -120,7 +120,7 @@ describe Chef::Provider::Group::Dscl do before do @node = Chef::Node.new @provider = Chef::Provider::Group::Dscl.new(@node, @new_resource) - @provider.stub!(:safe_dscl).and_return("\naj 500\n") + @provider.stub(:safe_dscl).and_return("\naj 500\n") end it "should run safe_dscl with list /Groups gid" do @@ -144,7 +144,7 @@ describe Chef::Provider::Group::Dscl do describe "set_gid" do describe "with the new resource and a gid number which is already in use" do before do - @provider.stub!(:gid_used?).and_return(true) + @provider.stub(:gid_used?).and_return(true) end it "should raise an exception if the new resources gid is already in use" do @@ -162,7 +162,7 @@ describe Chef::Provider::Group::Dscl do describe "with blank gid number for the new resources" do before do @new_resource.instance_variable_set(:@gid, nil) - @new_resource.stub!(:safe_dscl) + @new_resource.stub(:safe_dscl) end it "should run get_free_gid and return a valid, unused gid number" do @@ -185,9 +185,9 @@ describe Chef::Provider::Group::Dscl do describe "with existing members in the current resource and append set to false in the new resource" do before do - @new_resource.stub!(:members).and_return([]) - @new_resource.stub!(:append).and_return(false) - @current_resource.stub!(:members).and_return(["all", "your", "base"]) + @new_resource.stub(:members).and_return([]) + @new_resource.stub(:append).and_return(false) + @current_resource.stub(:members).and_return(["all", "your", "base"]) end it "should log an appropriate message" do @@ -236,6 +236,7 @@ describe Chef::Provider::Group::Dscl do describe "when loading the current system state" do before (:each) do + @provider.action = :create @provider.load_current_resource @provider.define_resource_requirements end @@ -246,8 +247,8 @@ describe Chef::Provider::Group::Dscl do end it "doesn't raise an error if /usr/bin/dscl exists" do - File.stub!(:exists?).and_return(true) - lambda { @provider.process_resource_requirements }.should_not raise_error(Chef::Exceptions::Group) + File.stub(:exists?).and_return(true) + lambda { @provider.process_resource_requirements }.should_not raise_error end end diff --git a/spec/unit/provider/group/gpasswd_spec.rb b/spec/unit/provider/group/gpasswd_spec.rb index f765667300..5bd7fdc569 100644 --- a/spec/unit/provider/group/gpasswd_spec.rb +++ b/spec/unit/provider/group/gpasswd_spec.rb @@ -27,11 +27,12 @@ describe Chef::Provider::Group::Gpasswd, "modify_group_members" do @new_resource.members %w{lobster rage fist} @new_resource.append false @provider = Chef::Provider::Group::Gpasswd.new(@new_resource, @run_context) - #@provider.stub!(:run_command).and_return(true) + #@provider.stub(:run_command).and_return(true) end describe "when determining the current group state" do before (:each) do + @provider.action = :create @provider.load_current_resource @provider.define_resource_requirements end @@ -40,14 +41,14 @@ describe Chef::Provider::Group::Gpasswd, "modify_group_members" do # for Chef::Provider::Group - no need to repeat it here. We'll # include only what's specific to this provider. it "should raise an error if the required binary /usr/bin/gpasswd doesn't exist" do - File.stub!(:exists?).and_return(true) + File.stub(:exists?).and_return(true) File.should_receive(:exists?).with("/usr/bin/gpasswd").and_return(false) lambda { @provider.process_resource_requirements }.should raise_error(Chef::Exceptions::Group) end it "shouldn't raise an error if the required binaries exist" do - File.stub!(:exists?).and_return(true) - lambda { @provider.process_resource_requirements }.should_not raise_error(Chef::Exceptions::Group) + File.stub(:exists?).and_return(true) + lambda { @provider.process_resource_requirements }.should_not raise_error end end @@ -85,7 +86,7 @@ describe Chef::Provider::Group::Gpasswd, "modify_group_members" do describe "when the resource specifies group members" do it "should log an appropriate debug message" do Chef::Log.should_receive(:debug).with("group[wheel] setting group members to: lobster, rage, fist") - @provider.stub!(:shell_out!) + @provider.stub(:shell_out!) @provider.modify_group_members end diff --git a/spec/unit/provider/group/groupadd_spec.rb b/spec/unit/provider/group/groupadd_spec.rb index 91073727c8..793615d04c 100644 --- a/spec/unit/provider/group/groupadd_spec.rb +++ b/spec/unit/provider/group/groupadd_spec.rb @@ -48,7 +48,7 @@ describe Chef::Provider::Group::Groupadd, "set_options" do @provider.set_options end it "should set the option for #{attribute} if the new resources #{attribute} is not null" do - @new_resource.stub!(attribute).and_return("wowaweea") + @new_resource.stub(attribute).and_return("wowaweea") @provider.set_options.should eql(" #{option} '#{@new_resource.send(attribute)}' #{@new_resource.group_name}") end end @@ -56,7 +56,7 @@ describe Chef::Provider::Group::Groupadd, "set_options" do it "should combine all the possible options" do match_string = "" field_list.sort{ |a,b| a[0] <=> b[0] }.each do |attribute, option| - @new_resource.stub!(attribute).and_return("hola") + @new_resource.stub(attribute).and_return("hola") match_string << " #{option} 'hola'" end match_string << " aj" @@ -93,10 +93,10 @@ describe Chef::Provider::Group::Groupadd, "create_group" do @node = Chef::Node.new @new_resource = Chef::Resource::Group.new("aj") @provider = Chef::Provider::Group::Groupadd.new(@node, @new_resource) - @provider.stub!(:run_command).and_return(true) - @provider.stub!(:set_options).and_return(" monkey") - @provider.stub!(:groupadd_options).and_return("") - @provider.stub!(:modify_group_members).and_return(true) + @provider.stub(:run_command).and_return(true) + @provider.stub(:set_options).and_return(" monkey") + @provider.stub(:groupadd_options).and_return("") + @provider.stub(:modify_group_members).and_return(true) end it "should run groupadd with the return of set_options" do @@ -117,14 +117,14 @@ describe Chef::Provider::Group::Groupadd do @run_context = Chef::RunContext.new(@node, {}, @events) @new_resource = Chef::Resource::Group.new("aj") @provider = Chef::Provider::Group::Groupadd.new(@new_resource, @run_context) - @provider.stub!(:run_command).and_return(true) - @provider.stub!(:set_options).and_return(" monkey") + @provider.stub(:run_command).and_return(true) + @provider.stub(:set_options).and_return(" monkey") end describe "manage group" do it "should run groupmod with the return of set_options" do - @provider.stub!(:modify_group_members).and_return(true) + @provider.stub(:modify_group_members).and_return(true) @provider.should_receive(:run_command).with({ :command => "groupmod monkey" }).and_return(true) @provider.manage_group end @@ -151,7 +151,7 @@ describe Chef::Provider::Group::Groupadd do describe "load_current_resource" do before do - File.stub!(:exists?).and_return(false) + File.stub(:exists?).and_return(false) @provider.define_resource_requirements end it "should raise an error if the required binary /usr/sbin/groupadd doesn't exist" do diff --git a/spec/unit/provider/group/groupmod_spec.rb b/spec/unit/provider/group/groupmod_spec.rb index bfacfa5c26..001f9c66e8 100644 --- a/spec/unit/provider/group/groupmod_spec.rb +++ b/spec/unit/provider/group/groupmod_spec.rb @@ -43,8 +43,8 @@ describe Chef::Provider::Group::Groupmod do end it "shouldn't raise an error if the required binaries exist" do - File.stub!(:exists?).and_return(true) - lambda { @provider.load_current_resource }.should_not raise_error(Chef::Exceptions::Group) + File.stub(:exists?).and_return(true) + lambda { @provider.load_current_resource }.should_not raise_error end end @@ -89,7 +89,7 @@ describe Chef::Provider::Group::Groupmod do end it "updates group membership correctly" do - Chef::Log.stub!(:debug) + Chef::Log.stub(:debug) @provider.should_receive(:shell_out!).with("group mod -n wheel_bak wheel") @provider.should_receive(:shell_out!).with("user mod -G wheel lobster") @provider.should_receive(:shell_out!).with("group add -g '123' -o wheel") diff --git a/spec/unit/provider/group/pw_spec.rb b/spec/unit/provider/group/pw_spec.rb index a545f8ee70..af64a21fde 100644 --- a/spec/unit/provider/group/pw_spec.rb +++ b/spec/unit/provider/group/pw_spec.rb @@ -77,8 +77,8 @@ describe Chef::Provider::Group::Pw do describe "with an empty members array in both the new and current resource" do before do - @new_resource.stub!(:members).and_return([]) - @current_resource.stub!(:members).and_return([]) + @new_resource.stub(:members).and_return([]) + @current_resource.stub(:members).and_return([]) end it "should set no options" do @@ -88,8 +88,8 @@ describe Chef::Provider::Group::Pw do describe "with an empty members array in the new resource and existing members in the current resource" do before do - @new_resource.stub!(:members).and_return([]) - @current_resource.stub!(:members).and_return(["all", "your", "base"]) + @new_resource.stub(:members).and_return([]) + @current_resource.stub(:members).and_return(["all", "your", "base"]) end it "should log an appropriate message" do @@ -104,8 +104,8 @@ describe Chef::Provider::Group::Pw do describe "with supplied members array in the new resource and an empty members array in the current resource" do before do - @new_resource.stub!(:members).and_return(["all", "your", "base"]) - @current_resource.stub!(:members).and_return([]) + @new_resource.stub(:members).and_return(["all", "your", "base"]) + @current_resource.stub(:members).and_return([]) end it "should log an appropriate debug message" do @@ -121,6 +121,7 @@ describe Chef::Provider::Group::Pw do describe"load_current_resource" do before (:each) do + @provider.action = :create @provider.load_current_resource @provider.define_resource_requirements end @@ -130,8 +131,8 @@ describe Chef::Provider::Group::Pw do end it "shouldn't raise an error if /usr/sbin/pw exists" do - File.stub!(:exists?).and_return(true) - lambda { @provider.process_resource_requirements }.should_not raise_error(Chef::Exceptions::Group) + File.stub(:exists?).and_return(true) + lambda { @provider.process_resource_requirements }.should_not raise_error end end end diff --git a/spec/unit/provider/group/usermod_spec.rb b/spec/unit/provider/group/usermod_spec.rb index 1687cc0b65..c0178e5e57 100644 --- a/spec/unit/provider/group/usermod_spec.rb +++ b/spec/unit/provider/group/usermod_spec.rb @@ -27,15 +27,15 @@ describe Chef::Provider::Group::Usermod do @new_resource.members [ "all", "your", "base" ] @new_resource.excluded_members [ ] @provider = Chef::Provider::Group::Usermod.new(@new_resource, @run_context) - @provider.stub!(:run_command) + @provider.stub(:run_command) end describe "modify_group_members" do describe "with an empty members array" do before do - @new_resource.stub!(:append).and_return(true) - @new_resource.stub!(:members).and_return([]) + @new_resource.stub(:append).and_return(true) + @new_resource.stub(:members).and_return([]) end it "should log an appropriate message" do @@ -55,8 +55,8 @@ describe Chef::Provider::Group::Usermod do } before do - @new_resource.stub!(:members).and_return(["all", "your", "base"]) - File.stub!(:exists?).and_return(true) + @new_resource.stub(:members).and_return(["all", "your", "base"]) + File.stub(:exists?).and_return(true) end it "should raise an error when setting the entire group directly" do @@ -72,8 +72,8 @@ describe Chef::Provider::Group::Usermod do @provider.load_current_resource @provider.instance_variable_set("@group_exists", true) @provider.action = :modify - @new_resource.stub!(:append).and_return(true) - @new_resource.stub!(:excluded_members).and_return(["someone"]) + @new_resource.stub(:append).and_return(true) + @new_resource.stub(:excluded_members).and_return(["someone"]) lambda { @provider.run_action(@provider.process_resource_requirements) }.should raise_error(Chef::Exceptions::Group, "excluded_members is not supported by #{@provider.to_s}") end @@ -83,7 +83,7 @@ describe Chef::Provider::Group::Usermod do current_resource.members([ ]) @provider.current_resource = current_resource @node.automatic_attrs[:platform] = platform - @new_resource.stub!(:append).and_return(true) + @new_resource.stub(:append).and_return(true) @provider.should_receive(:shell_out!).with("usermod #{flags} wheel all") @provider.should_receive(:shell_out!).with("usermod #{flags} wheel your") @provider.should_receive(:shell_out!).with("usermod #{flags} wheel base") @@ -95,19 +95,20 @@ describe Chef::Provider::Group::Usermod do describe "when loading the current resource" do before(:each) do - File.stub!(:exists?).and_return(false) + File.stub(:exists?).and_return(false) + @provider.action = :create @provider.define_resource_requirements end it "should raise an error if the required binary /usr/sbin/usermod doesn't exist" do - File.stub!(:exists?).and_return(true) + File.stub(:exists?).and_return(true) File.should_receive(:exists?).with("/usr/sbin/usermod").and_return(false) lambda { @provider.process_resource_requirements }.should raise_error(Chef::Exceptions::Group) end it "shouldn't raise an error if the required binaries exist" do - File.stub!(:exists?).and_return(true) - lambda { @provider.process_resource_requirements }.should_not raise_error(Chef::Exceptions::Group) + File.stub(:exists?).and_return(true) + lambda { @provider.process_resource_requirements }.should_not raise_error end end end diff --git a/spec/unit/provider/group/windows_spec.rb b/spec/unit/provider/group/windows_spec.rb index e8c1243ce5..6888c750f5 100644 --- a/spec/unit/provider/group/windows_spec.rb +++ b/spec/unit/provider/group/windows_spec.rb @@ -33,8 +33,8 @@ describe Chef::Provider::Group::Windows do @events = Chef::EventDispatch::Dispatcher.new @run_context = Chef::RunContext.new(@node, {}, @events) @new_resource = Chef::Resource::Group.new("staff") - @net_group = mock("Chef::Util::Windows::NetGroup") - Chef::Util::Windows::NetGroup.stub!(:new).and_return(@net_group) + @net_group = double("Chef::Util::Windows::NetGroup") + Chef::Util::Windows::NetGroup.stub(:new).and_return(@net_group) @provider = Chef::Provider::Group::Windows.new(@new_resource, @run_context) end @@ -52,21 +52,21 @@ describe Chef::Provider::Group::Windows do @current_resource = Chef::Resource::Group.new("staff") @current_resource.members [ "all", "your", "base" ] - Chef::Util::Windows::NetGroup.stub!(:new).and_return(@net_group) - @net_group.stub!(:local_add_members) - @net_group.stub!(:local_set_members) + Chef::Util::Windows::NetGroup.stub(:new).and_return(@net_group) + @net_group.stub(:local_add_members) + @net_group.stub(:local_set_members) @provider.stub(:local_group_name_to_sid) @provider.current_resource = @current_resource end it "should call @net_group.local_set_members" do - @new_resource.stub!(:append).and_return(false) + @new_resource.stub(:append).and_return(false) @net_group.should_receive(:local_set_members).with(@new_resource.members) @provider.manage_group end it "should call @net_group.local_add_members" do - @new_resource.stub!(:append).and_return(true) + @new_resource.stub(:append).and_return(true) @net_group.should_receive(:local_add_members).with(@new_resource.members) @provider.manage_group end @@ -75,8 +75,8 @@ describe Chef::Provider::Group::Windows do describe "remove_group" do before do - Chef::Util::Windows::NetGroup.stub!(:new).and_return(@net_group) - @provider.stub!(:run_command).and_return(true) + Chef::Util::Windows::NetGroup.stub(:new).and_return(@net_group) + @provider.stub(:run_command).and_return(true) end it "should call @net_group.local_delete" do diff --git a/spec/unit/provider/group_spec.rb b/spec/unit/provider/group_spec.rb index a076593511..9ff9f85c7c 100644 --- a/spec/unit/provider/group_spec.rb +++ b/spec/unit/provider/group_spec.rb @@ -36,12 +36,12 @@ describe Chef::Provider::User do @provider.current_resource = @current_resource - @pw_group = mock("Struct::Group", + @pw_group = double("Struct::Group", :name => "wheel", :gid => 20, :mem => [ "root", "aj" ] ) - Etc.stub!(:getgrnam).with('wheel').and_return(@pw_group) + Etc.stub(:getgrnam).with('wheel').and_return(@pw_group) end it "assumes the group exists by default" do @@ -74,7 +74,7 @@ describe Chef::Provider::User do end it "should flip the value of exists if it cannot be found in /etc/group" do - Etc.stub!(:getgrnam).and_raise(ArgumentError) + Etc.stub(:getgrnam).and_raise(ArgumentError) @provider.load_current_resource @provider.group_exists.should be_false end @@ -87,7 +87,7 @@ describe Chef::Provider::User do describe "when determining if the system is already in the target state" do [ :gid, :members ].each do |attribute| it "should return true if #{attribute} doesn't match" do - @current_resource.stub!(attribute).and_return("looooooooooooooooooool") + @current_resource.stub(attribute).and_return("looooooooooooooooooool") @provider.compare_group.should be_true end end @@ -98,26 +98,26 @@ describe Chef::Provider::User do it "should return false if append is true and the group member(s) already exists" do @current_resource.members << "extra_user" - @new_resource.stub!(:append).and_return(true) + @new_resource.stub(:append).and_return(true) @provider.compare_group.should be_false end it "should return true if append is true and the group member(s) do not already exist" do @new_resource.members << "extra_user" - @new_resource.stub!(:append).and_return(true) + @new_resource.stub(:append).and_return(true) @provider.compare_group.should be_true end it "should return false if append is true and excluded_members include a non existing member" do @new_resource.excluded_members << "extra_user" - @new_resource.stub!(:append).and_return(true) + @new_resource.stub(:append).and_return(true) @provider.compare_group.should be_false end it "should return true if the append is true and excluded_members include an existing user" do @new_resource.members.each {|m| @new_resource.excluded_members << m } @new_resource.members.clear - @new_resource.stub!(:append).and_return(true) + @new_resource.stub(:append).and_return(true) @provider.compare_group.should be_true end @@ -132,32 +132,32 @@ describe Chef::Provider::User do it "should set the new_resources updated flag when it creates the group" do @provider.group_exists = false - @provider.stub!(:create_group) + @provider.stub(:create_group) @provider.run_action(:create) @provider.new_resource.should be_updated end it "should check to see if the group has mismatched attributes if the group exists" do @provider.group_exists = true - @provider.stub!(:compare_group).and_return(false) - @provider.stub!(:change_desc).and_return([ ]) + @provider.stub(:compare_group).and_return(false) + @provider.stub(:change_desc).and_return([ ]) @provider.run_action(:create) @provider.new_resource.should_not be_updated end it "should call manage_group if the group exists and has mismatched attributes" do @provider.group_exists = true - @provider.stub!(:compare_group).and_return(true) - @provider.stub!(:change_desc).and_return([ ]) + @provider.stub(:compare_group).and_return(true) + @provider.stub(:change_desc).and_return([ ]) @provider.should_receive(:manage_group).and_return(true) @provider.run_action(:create) end it "should set the new_resources updated flag when it creates the group if we call manage_group" do @provider.group_exists = true - @provider.stub!(:compare_group).and_return(true) - @provider.stub!(:change_desc).and_return(["Some changes are going to be done."]) - @provider.stub!(:manage_group).and_return(true) + @provider.stub(:compare_group).and_return(true) + @provider.stub(:change_desc).and_return(["Some changes are going to be done."]) + @provider.stub(:manage_group).and_return(true) @provider.run_action(:create) @new_resource.should be_updated end @@ -183,20 +183,20 @@ describe Chef::Provider::User do describe "when updating a group" do before(:each) do @provider.group_exists = true - @provider.stub!(:manage_group).and_return(true) + @provider.stub(:manage_group).and_return(true) end it "should run manage_group if the group exists and has mismatched attributes" do @provider.should_receive(:compare_group).and_return(true) - @provider.stub!(:change_desc).and_return(["Some changes are going to be done."]) + @provider.stub(:change_desc).and_return(["Some changes are going to be done."]) @provider.should_receive(:manage_group).and_return(true) @provider.run_action(:manage) end it "should set the new resources updated flag to true if manage_group is called" do - @provider.stub!(:compare_group).and_return(true) - @provider.stub!(:change_desc).and_return(["Some changes are going to be done."]) - @provider.stub!(:manage_group).and_return(true) + @provider.stub(:compare_group).and_return(true) + @provider.stub(:change_desc).and_return(["Some changes are going to be done."]) + @provider.stub(:manage_group).and_return(true) @provider.run_action(:manage) @new_resource.should be_updated end @@ -209,7 +209,7 @@ describe Chef::Provider::User do it "should not run manage_group if the group exists but has no differing attributes" do @provider.should_receive(:compare_group).and_return(false) - @provider.stub!(:change_desc).and_return(["Some changes are going to be done."]) + @provider.stub(:change_desc).and_return(["Some changes are going to be done."]) @provider.should_not_receive(:manage_group) @provider.run_action(:manage) end @@ -218,27 +218,27 @@ describe Chef::Provider::User do describe "when modifying the group" do before(:each) do @provider.group_exists = true - @provider.stub!(:manage_group).and_return(true) + @provider.stub(:manage_group).and_return(true) end it "should run manage_group if the group exists and has mismatched attributes" do @provider.should_receive(:compare_group).and_return(true) - @provider.stub!(:change_desc).and_return(["Some changes are going to be done."]) + @provider.stub(:change_desc).and_return(["Some changes are going to be done."]) @provider.should_receive(:manage_group).and_return(true) @provider.run_action(:modify) end it "should set the new resources updated flag to true if manage_group is called" do - @provider.stub!(:compare_group).and_return(true) - @provider.stub!(:change_desc).and_return(["Some changes are going to be done."]) - @provider.stub!(:manage_group).and_return(true) + @provider.stub(:compare_group).and_return(true) + @provider.stub(:change_desc).and_return(["Some changes are going to be done."]) + @provider.stub(:manage_group).and_return(true) @provider.run_action(:modify) @new_resource.should be_updated end it "should not run manage_group if the group exists but has no differing attributes" do @provider.should_receive(:compare_group).and_return(false) - @provider.stub!(:change_desc).and_return(["Some changes are going to be done."]) + @provider.stub(:change_desc).and_return(["Some changes are going to be done."]) @provider.should_not_receive(:manage_group) @provider.run_action(:modify) end @@ -253,20 +253,20 @@ describe Chef::Provider::User do it "should report which group members are missing if members are missing and appending to the group" do @new_resource.members << "user1" @new_resource.members << "user2" - @new_resource.stub!(:append).and_return true + @new_resource.stub(:append).and_return true @provider.compare_group.should be_true @provider.change_desc.should == [ "add missing member(s): user1, user2" ] end it "should report that the group members will be overwritten if not appending" do @new_resource.members << "user1" - @new_resource.stub!(:append).and_return false + @new_resource.stub(:append).and_return false @provider.compare_group.should be_true @provider.change_desc.should == [ "replace group members with new list of members" ] end it "should report the gid will be changed when it does not match" do - @current_resource.stub!(:gid).and_return("BADF00D") + @current_resource.stub(:gid).and_return("BADF00D") @provider.compare_group.should be_true @provider.change_desc.should == [ "change gid #{@current_resource.gid} to #{@new_resource.gid}" ] diff --git a/spec/unit/provider/http_request_spec.rb b/spec/unit/provider/http_request_spec.rb index 3efdd6c5fd..605287fcc3 100644 --- a/spec/unit/provider/http_request_spec.rb +++ b/spec/unit/provider/http_request_spec.rb @@ -44,8 +44,8 @@ describe Chef::Provider::HttpRequest do before(:each) do # run_action(x) forces load_current_resource to run; # that would overwrite our supplied mock Chef::Rest # object - @provider.stub!(:load_current_resource).and_return(true) - @http = mock("Chef::REST") + @provider.stub(:load_current_resource).and_return(true) + @http = double("Chef::REST") @provider.http = @http end @@ -73,7 +73,7 @@ describe Chef::Provider::HttpRequest do end it "should inflate a message block at runtime" do - @new_resource.stub!(:message).and_return(lambda { "return" }) + @new_resource.stub(:message).and_return(lambda { "return" }) @http.should_receive(:put).with("http://www.opscode.com/", "return", {}) @provider.run_action(:put) @new_resource.should be_updated diff --git a/spec/unit/provider/ifconfig/aix_spec.rb b/spec/unit/provider/ifconfig/aix_spec.rb index 39e9919740..24f5fb18f3 100644 --- a/spec/unit/provider/ifconfig/aix_spec.rb +++ b/spec/unit/provider/ifconfig/aix_spec.rb @@ -67,7 +67,7 @@ IFCONFIG it "should add an interface if it does not exist" do @new_resource.device "en10" - @provider.stub!(:load_current_resource) do + @provider.stub(:load_current_resource) do @provider.instance_variable_set("@status", double("Status", :exitstatus => 0)) @provider.instance_variable_set("@current_resource", Chef::Resource::Ifconfig.new("10.0.0.1", @run_context)) end @@ -81,7 +81,7 @@ IFCONFIG it "should raise exception if metric attribute is set" do @new_resource.device "en0" @new_resource.metric "1" - @provider.stub!(:load_current_resource) do + @provider.stub(:load_current_resource) do @provider.instance_variable_set("@status", double("Status", :exitstatus => 0)) @provider.instance_variable_set("@current_resource", Chef::Resource::Ifconfig.new("10.0.0.1", @run_context)) end @@ -93,7 +93,7 @@ IFCONFIG describe "#action_enable" do it "should enable an interface if it does not exist" do @new_resource.device "en10" - @provider.stub!(:load_current_resource) do + @provider.stub(:load_current_resource) do @provider.instance_variable_set("@status", double("Status", :exitstatus => 0)) @provider.instance_variable_set("@current_resource", Chef::Resource::Ifconfig.new("10.0.0.1", @run_context)) end @@ -109,7 +109,7 @@ IFCONFIG it "should not disable an interface if it does not exist" do @new_resource.device "en10" - @provider.stub!(:load_current_resource) do + @provider.stub(:load_current_resource) do @provider.instance_variable_set("@status", double("Status", :exitstatus => 0)) @provider.instance_variable_set("@current_resource", Chef::Resource::Ifconfig.new("10.0.0.1", @run_context)) end @@ -123,7 +123,7 @@ IFCONFIG context "interface exists" do before do @new_resource.device "en10" - @provider.stub!(:load_current_resource) do + @provider.stub(:load_current_resource) do @provider.instance_variable_set("@status", double("Status", :exitstatus => 0)) current_resource = Chef::Resource::Ifconfig.new("10.0.0.1", @run_context) current_resource.device @new_resource.device @@ -146,7 +146,7 @@ IFCONFIG it "should not delete an interface if it does not exist" do @new_resource.device "en10" - @provider.stub!(:load_current_resource) do + @provider.stub(:load_current_resource) do @provider.instance_variable_set("@status", double("Status", :exitstatus => 0)) @provider.instance_variable_set("@current_resource", Chef::Resource::Ifconfig.new("10.0.0.1", @run_context)) end @@ -160,7 +160,7 @@ IFCONFIG context "interface exists" do before do @new_resource.device "en10" - @provider.stub!(:load_current_resource) do + @provider.stub(:load_current_resource) do @provider.instance_variable_set("@status", double("Status", :exitstatus => 0)) current_resource = Chef::Resource::Ifconfig.new("10.0.0.1", @run_context) current_resource.device @new_resource.device diff --git a/spec/unit/provider/ifconfig/debian_spec.rb b/spec/unit/provider/ifconfig/debian_spec.rb index 617e840e1f..3f46d9df23 100644 --- a/spec/unit/provider/ifconfig/debian_spec.rb +++ b/spec/unit/provider/ifconfig/debian_spec.rb @@ -34,11 +34,11 @@ describe Chef::Provider::Ifconfig::Debian do @provider = Chef::Provider::Ifconfig::Debian.new(@new_resource, @run_context) @current_resource = Chef::Resource::Ifconfig.new("10.0.0.1", @run_context) - status = mock("Status", :exitstatus => 0) + status = double("Status", :exitstatus => 0) @provider.instance_variable_set("@status", status) @provider.current_resource = @current_resource - @provider.stub!(:load_current_resource) - @provider.stub!(:run_command) + @provider.stub(:load_current_resource) + @provider.stub(:run_command) @config_filename_ifaces = "/etc/network/interfaces" @config_filename_ifcfg = "/etc/network/interfaces.d/ifcfg-#{@new_resource.device}" diff --git a/spec/unit/provider/ifconfig/redhat_spec.rb b/spec/unit/provider/ifconfig/redhat_spec.rb index b6f83ffea9..f4b98dfc32 100644 --- a/spec/unit/provider/ifconfig/redhat_spec.rb +++ b/spec/unit/provider/ifconfig/redhat_spec.rb @@ -34,7 +34,7 @@ describe Chef::Provider::Ifconfig::Redhat do @provider = Chef::Provider::Ifconfig::Redhat.new(@new_resource, @run_context) @current_resource = Chef::Resource::Ifconfig.new("10.0.0.1", @run_context) - status = mock("Status", :exitstatus => 0) + status = double("Status", :exitstatus => 0) @provider.instance_variable_set("@status", status) @provider.current_resource = @current_resource end @@ -42,8 +42,8 @@ describe Chef::Provider::Ifconfig::Redhat do describe "generate_config for action_add" do it "should write network-script for centos" do - @provider.stub!(:load_current_resource) - @provider.stub!(:run_command) + @provider.stub(:load_current_resource) + @provider.stub(:run_command) config_filename = "/etc/sysconfig/network-scripts/ifcfg-#{@new_resource.device}" config_file = StringIO.new File.should_receive(:new).with(config_filename, "w").and_return(config_file) @@ -59,8 +59,8 @@ describe Chef::Provider::Ifconfig::Redhat do it "should delete network-script if it exists for centos" do @current_resource.device @new_resource.device - @provider.stub!(:load_current_resource) - @provider.stub!(:run_command) + @provider.stub(:load_current_resource) + @provider.stub(:run_command) config_filename = "/etc/sysconfig/network-scripts/ifcfg-#{@new_resource.device}" File.should_receive(:exist?).with(config_filename).and_return(true) FileUtils.should_receive(:rm_f).with(config_filename, :verbose => false) diff --git a/spec/unit/provider/ifconfig_spec.rb b/spec/unit/provider/ifconfig_spec.rb index f4fdc23353..fb8d0956d7 100644 --- a/spec/unit/provider/ifconfig_spec.rb +++ b/spec/unit/provider/ifconfig_spec.rb @@ -35,14 +35,14 @@ describe Chef::Provider::Ifconfig do @provider = Chef::Provider::Ifconfig.new(@new_resource, @run_context) @current_resource = Chef::Resource::Ifconfig.new("10.0.0.1", @run_context) - status = mock("Status", :exitstatus => 0) + status = double("Status", :exitstatus => 0) @provider.instance_variable_set("@status", status) @provider.current_resource = @current_resource end describe Chef::Provider::Ifconfig, "load_current_resource" do before do - status = mock("Status", :exitstatus => 1) + status = double("Status", :exitstatus => 1) @provider.should_receive(:popen4).and_return status @provider.load_current_resource end @@ -57,8 +57,8 @@ describe Chef::Provider::Ifconfig do describe Chef::Provider::Ifconfig, "action_add" do it "should add an interface if it does not exist" do - #@provider.stub!(:run_command).and_return(true) - @provider.stub!(:load_current_resource) + #@provider.stub(:run_command).and_return(true) + @provider.stub(:load_current_resource) @current_resource.inet_addr nil command = "ifconfig eth0 10.0.0.1 netmask 255.255.254.0 metric 1 mtu 1500" @provider.should_receive(:run_command).with(:command => command) @@ -69,7 +69,7 @@ describe Chef::Provider::Ifconfig do end it "should not add an interface if it already exists" do - @provider.stub!(:load_current_resource) + @provider.stub(:load_current_resource) @provider.should_not_receive(:run_command) @current_resource.inet_addr "10.0.0.1" @provider.should_not_receive(:generate_config) @@ -86,7 +86,7 @@ describe Chef::Provider::Ifconfig do describe Chef::Provider::Ifconfig, "action_enable" do it "should enable interface if does not exist" do - @provider.stub!(:load_current_resource) + @provider.stub(:load_current_resource) @current_resource.inet_addr nil command = "ifconfig eth0 10.0.0.1 netmask 255.255.254.0 metric 1 mtu 1500" @provider.should_receive(:run_command).with(:command => command) @@ -97,7 +97,7 @@ describe Chef::Provider::Ifconfig do end it "should not enable interface if it already exists" do - @provider.stub!(:load_current_resource) + @provider.stub(:load_current_resource) @provider.should_not_receive(:run_command) @current_resource.inet_addr "10.0.0.1" @provider.should_not_receive(:generate_config) @@ -110,7 +110,7 @@ describe Chef::Provider::Ifconfig do describe Chef::Provider::Ifconfig, "action_delete" do it "should delete interface if it exists" do - @provider.stub!(:load_current_resource) + @provider.stub(:load_current_resource) @current_resource.device "eth0" command = "ifconfig #{@new_resource.device} down" @provider.should_receive(:run_command).with(:command => command) @@ -121,7 +121,7 @@ describe Chef::Provider::Ifconfig do end it "should not delete interface if it does not exist" do - @provider.stub!(:load_current_resource) + @provider.stub(:load_current_resource) @provider.should_not_receive(:run_command) @provider.should_not_receive(:delete_config) @@ -133,7 +133,7 @@ describe Chef::Provider::Ifconfig do describe Chef::Provider::Ifconfig, "action_disable" do it "should disable interface if it exists" do - @provider.stub!(:load_current_resource) + @provider.stub(:load_current_resource) @current_resource.device "eth0" command = "ifconfig #{@new_resource.device} down" @provider.should_receive(:run_command).with(:command => command) @@ -144,7 +144,7 @@ describe Chef::Provider::Ifconfig do end it "should not delete interface if it does not exist" do - @provider.stub!(:load_current_resource) + @provider.stub(:load_current_resource) @provider.should_not_receive(:run_command) @provider.should_not_receive(:delete_config) @@ -156,7 +156,7 @@ describe Chef::Provider::Ifconfig do describe Chef::Provider::Ifconfig, "action_delete" do it "should delete interface of it exists" do - @provider.stub!(:load_current_resource) + @provider.stub(:load_current_resource) @current_resource.device "eth0" command = "ifconfig #{@new_resource.device} down" @provider.should_receive(:run_command).with(:command => command) @@ -168,7 +168,7 @@ describe Chef::Provider::Ifconfig do it "should not delete interface if it does not exist" do # This is so that our fake values do not get overwritten - @provider.stub!(:load_current_resource) + @provider.stub(:load_current_resource) # This is so that nothing actually runs @provider.should_not_receive(:run_command) @provider.should_not_receive(:delete_config) diff --git a/spec/unit/provider/link_spec.rb b/spec/unit/provider/link_spec.rb index bd3204510b..6052f5dd3b 100644 --- a/spec/unit/provider/link_spec.rb +++ b/spec/unit/provider/link_spec.rb @@ -44,13 +44,13 @@ describe Chef::Resource::Link, :not_supported_on_win2k3 do describe "when the target is a symlink" do before(:each) do - lstat = mock("stats", :ino => 5) - lstat.stub!(:uid).and_return(501) - lstat.stub!(:gid).and_return(501) - lstat.stub!(:mode).and_return(0777) - File.stub!(:lstat).with("#{CHEF_SPEC_DATA}/fofile-link").and_return(lstat) - provider.file_class.stub!(:symlink?).with("#{CHEF_SPEC_DATA}/fofile-link").and_return(true) - provider.file_class.stub!(:readlink).with("#{CHEF_SPEC_DATA}/fofile-link").and_return("#{CHEF_SPEC_DATA}/fofile") + lstat = double("stats", :ino => 5) + lstat.stub(:uid).and_return(501) + lstat.stub(:gid).and_return(501) + lstat.stub(:mode).and_return(0777) + File.stub(:lstat).with("#{CHEF_SPEC_DATA}/fofile-link").and_return(lstat) + provider.file_class.stub(:symlink?).with("#{CHEF_SPEC_DATA}/fofile-link").and_return(true) + provider.file_class.stub(:readlink).with("#{CHEF_SPEC_DATA}/fofile-link").and_return("#{CHEF_SPEC_DATA}/fofile") end describe "to a file that exists" do @@ -95,9 +95,9 @@ describe Chef::Resource::Link, :not_supported_on_win2k3 do describe "to a file that doesn't exist" do before do - File.stub!(:exist?).with("#{CHEF_SPEC_DATA}/fofile-link").and_return(false) - provider.file_class.stub!(:symlink?).with("#{CHEF_SPEC_DATA}/fofile-link").and_return(true) - provider.file_class.stub!(:readlink).with("#{CHEF_SPEC_DATA}/fofile-link").and_return("#{CHEF_SPEC_DATA}/fofile") + File.stub(:exist?).with("#{CHEF_SPEC_DATA}/fofile-link").and_return(false) + provider.file_class.stub(:symlink?).with("#{CHEF_SPEC_DATA}/fofile-link").and_return(true) + provider.file_class.stub(:readlink).with("#{CHEF_SPEC_DATA}/fofile-link").and_return("#{CHEF_SPEC_DATA}/fofile") new_resource.owner "501" # only loaded in current_resource if present in new new_resource.group "501" provider.load_current_resource @@ -123,8 +123,8 @@ describe Chef::Resource::Link, :not_supported_on_win2k3 do describe "when the target doesn't exist" do before do - File.stub!(:exists?).with("#{CHEF_SPEC_DATA}/fofile-link").and_return(false) - provider.file_class.stub!(:symlink?).with("#{CHEF_SPEC_DATA}/fofile-link").and_return(false) + File.stub(:exists?).with("#{CHEF_SPEC_DATA}/fofile-link").and_return(false) + provider.file_class.stub(:symlink?).with("#{CHEF_SPEC_DATA}/fofile-link").and_return(false) provider.load_current_resource end @@ -144,19 +144,19 @@ describe Chef::Resource::Link, :not_supported_on_win2k3 do describe "when the target is a regular old file" do before do - stat = mock("stats", :ino => 5) - stat.stub!(:uid).and_return(501) - stat.stub!(:gid).and_return(501) - stat.stub!(:mode).and_return(0755) - provider.file_class.stub!(:stat).with("#{CHEF_SPEC_DATA}/fofile-link").and_return(stat) - - File.stub!(:exists?).with("#{CHEF_SPEC_DATA}/fofile-link").and_return(true) - provider.file_class.stub!(:symlink?).with("#{CHEF_SPEC_DATA}/fofile-link").and_return(false) + stat = double("stats", :ino => 5) + stat.stub(:uid).and_return(501) + stat.stub(:gid).and_return(501) + stat.stub(:mode).and_return(0755) + provider.file_class.stub(:stat).with("#{CHEF_SPEC_DATA}/fofile-link").and_return(stat) + + File.stub(:exists?).with("#{CHEF_SPEC_DATA}/fofile-link").and_return(true) + provider.file_class.stub(:symlink?).with("#{CHEF_SPEC_DATA}/fofile-link").and_return(false) end describe "and the source does not exist" do before do - File.stub!(:exists?).with("#{CHEF_SPEC_DATA}/fofile").and_return(false) + File.stub(:exists?).with("#{CHEF_SPEC_DATA}/fofile").and_return(false) provider.load_current_resource end @@ -176,14 +176,14 @@ describe Chef::Resource::Link, :not_supported_on_win2k3 do describe "and the source exists" do before do - stat = mock("stats", :ino => 6) - stat.stub!(:uid).and_return(502) - stat.stub!(:gid).and_return(502) - stat.stub!(:mode).and_return(0644) + stat = double("stats", :ino => 6) + stat.stub(:uid).and_return(502) + stat.stub(:gid).and_return(502) + stat.stub(:mode).and_return(0644) - provider.file_class.stub!(:stat).with("#{CHEF_SPEC_DATA}/fofile").and_return(stat) + provider.file_class.stub(:stat).with("#{CHEF_SPEC_DATA}/fofile").and_return(stat) - File.stub!(:exists?).with("#{CHEF_SPEC_DATA}/fofile").and_return(true) + File.stub(:exists?).with("#{CHEF_SPEC_DATA}/fofile").and_return(true) provider.load_current_resource end @@ -203,14 +203,14 @@ describe Chef::Resource::Link, :not_supported_on_win2k3 do describe "and is hardlinked to the source" do before do - stat = mock("stats", :ino => 5) - stat.stub!(:uid).and_return(502) - stat.stub!(:gid).and_return(502) - stat.stub!(:mode).and_return(0644) + stat = double("stats", :ino => 5) + stat.stub(:uid).and_return(502) + stat.stub(:gid).and_return(502) + stat.stub(:mode).and_return(0644) - provider.file_class.stub!(:stat).with("#{CHEF_SPEC_DATA}/fofile").and_return(stat) + provider.file_class.stub(:stat).with("#{CHEF_SPEC_DATA}/fofile").and_return(stat) - File.stub!(:exists?).with("#{CHEF_SPEC_DATA}/fofile").and_return(true) + File.stub(:exists?).with("#{CHEF_SPEC_DATA}/fofile").and_return(true) provider.load_current_resource end diff --git a/spec/unit/provider/mdadm_spec.rb b/spec/unit/provider/mdadm_spec.rb index 25991e4732..6595728741 100644 --- a/spec/unit/provider/mdadm_spec.rb +++ b/spec/unit/provider/mdadm_spec.rb @@ -32,20 +32,20 @@ describe Chef::Provider::Mdadm do describe "when determining the current metadevice status" do it "should set the current resources mount point to the new resources mount point" do - @provider.stub!(:shell_out!).and_return(OpenStruct.new(:status => 0)) + @provider.stub(:shell_out!).and_return(OpenStruct.new(:status => 0)) @provider.load_current_resource @provider.current_resource.name.should == '/dev/md1' @provider.current_resource.raid_device.should == '/dev/md1' end it "determines that the metadevice exists when mdadm exit code is zero" do - @provider.stub!(:shell_out!).with("mdadm --detail --test /dev/md1", :returns => [0,4]).and_return(OpenStruct.new(:status => 0)) + @provider.stub(:shell_out!).with("mdadm --detail --test /dev/md1", :returns => [0,4]).and_return(OpenStruct.new(:status => 0)) @provider.load_current_resource @provider.current_resource.exists.should be_true end it "determines that the metadevice does not exist when mdadm exit code is 4" do - @provider.stub!(:shell_out!).with("mdadm --detail --test /dev/md1", :returns => [0,4]).and_return(OpenStruct.new(:status => 4)) + @provider.stub(:shell_out!).with("mdadm --detail --test /dev/md1", :returns => [0,4]).and_return(OpenStruct.new(:status => 4)) @provider.load_current_resource @provider.current_resource.exists.should be_false end @@ -55,7 +55,7 @@ describe Chef::Provider::Mdadm do before(:each) do @current_resource = Chef::Resource::Mdadm.new('/dev/md1') @new_resource.level 5 - @provider.stub!(:load_current_resource).and_return(true) + @provider.stub(:load_current_resource).and_return(true) @provider.current_resource = @current_resource end diff --git a/spec/unit/provider/mount/aix_spec.rb b/spec/unit/provider/mount/aix_spec.rb index 89de47038a..dcd9170e1f 100644 --- a/spec/unit/provider/mount/aix_spec.rb +++ b/spec/unit/provider/mount/aix_spec.rb @@ -60,8 +60,8 @@ ENABLED @provider = Chef::Provider::Mount::Aix.new(@new_resource, @run_context) - ::File.stub!(:exists?).with("/dev/sdz1").and_return true - ::File.stub!(:exists?).with("/tmp/foo").and_return true + ::File.stub(:exists?).with("/dev/sdz1").and_return true + ::File.stub(:exists?).with("/tmp/foo").and_return true end def stub_mounted(provider, mounted_output) @@ -179,7 +179,7 @@ ENABLED @new_resource.options("nodev,rw") stub_mounted_enabled(@provider, @mounted_output, "") filesystems = StringIO.new - ::File.stub!(:open).with("/etc/filesystems", "a").and_yield(filesystems) + ::File.stub(:open).with("/etc/filesystems", "a").and_yield(filesystems) @provider.run_action(:enable) @@ -200,7 +200,7 @@ ENABLED it "should disable mount if it is mounted and enabled" do stub_mounted_enabled(@provider, @mounted_output, @enabled_output) - ::File.stub!(:open).with("/etc/filesystems", "r").and_return(<<-ETCFILESYSTEMS) + ::File.stub(:open).with("/etc/filesystems", "r").and_return(<<-ETCFILESYSTEMS) /tmp/foo: dev = /dev/sdz1 vfs = jfs2 @@ -219,7 +219,7 @@ ENABLED ETCFILESYSTEMS filesystems = StringIO.new - ::File.stub!(:open).with("/etc/filesystems", "w").and_yield(filesystems) + ::File.stub(:open).with("/etc/filesystems", "w").and_yield(filesystems) @provider.run_action(:disable) diff --git a/spec/unit/provider/mount/mount_spec.rb b/spec/unit/provider/mount/mount_spec.rb index cf0e8791de..99e78590f1 100644 --- a/spec/unit/provider/mount/mount_spec.rb +++ b/spec/unit/provider/mount/mount_spec.rb @@ -34,16 +34,16 @@ describe Chef::Provider::Mount::Mount do @provider = Chef::Provider::Mount::Mount.new(@new_resource, @run_context) - ::File.stub!(:exists?).with("/dev/sdz1").and_return true - ::File.stub!(:exists?).with("/tmp/foo").and_return true - ::File.stub!(:realpath).with("/dev/sdz1").and_return "/dev/sdz1" - ::File.stub!(:realpath).with("/tmp/foo").and_return "/tmp/foo" + ::File.stub(:exists?).with("/dev/sdz1").and_return true + ::File.stub(:exists?).with("/tmp/foo").and_return true + ::File.stub(:realpath).with("/dev/sdz1").and_return "/dev/sdz1" + ::File.stub(:realpath).with("/tmp/foo").and_return "/tmp/foo" end describe "when discovering the current fs state" do before do - @provider.stub!(:shell_out!).and_return(OpenStruct.new(:stdout => '')) - ::File.stub!(:foreach).with("/etc/fstab") + @provider.stub(:shell_out!).and_return(OpenStruct.new(:stdout => '')) + ::File.stub(:foreach).with("/etc/fstab") end it "should create a current resource with the same mount point and device" do @@ -56,7 +56,7 @@ describe Chef::Provider::Mount::Mount do it "should accecpt device_type :uuid" do @new_resource.device_type :uuid @new_resource.device "d21afe51-a0fe-4dc6-9152-ac733763ae0a" - @stdout_findfs = mock("STDOUT", :first => "/dev/sdz1") + @stdout_findfs = double("STDOUT", :first => "/dev/sdz1") @provider.should_receive(:popen4).with("/sbin/findfs UUID=d21afe51-a0fe-4dc6-9152-ac733763ae0a").and_yield(@pid,@stdin,@stdout_findfs,@stderr).and_return(@status) @provider.load_current_resource() @provider.mountable? @@ -72,7 +72,7 @@ describe Chef::Provider::Mount::Mount do it "should ignore trailing slash and set mounted to true for network mount (#{type})" do @new_resource.device fs_spec - @provider.stub!(:shell_out!).and_return(OpenStruct.new(:stdout => "#{fs_spec}/ on /tmp/foo type #{type} (rw)\n")) + @provider.stub(:shell_out!).and_return(OpenStruct.new(:stdout => "#{fs_spec}/ on /tmp/foo type #{type} (rw)\n")) @provider.load_current_resource @provider.current_resource.mounted.should be_true end @@ -80,12 +80,12 @@ describe Chef::Provider::Mount::Mount do end it "should raise an error if the mount device does not exist" do - ::File.stub!(:exists?).with("/dev/sdz1").and_return false + ::File.stub(:exists?).with("/dev/sdz1").and_return false lambda { @provider.load_current_resource();@provider.mountable? }.should raise_error(Chef::Exceptions::Mount) end it "should not call mountable? with load_current_resource - CHEF-1565" do - ::File.stub!(:exists?).with("/dev/sdz1").and_return false + ::File.stub(:exists?).with("/dev/sdz1").and_return false @provider.should_receive(:mounted?).and_return(true) @provider.should_receive(:enabled?).and_return(true) @provider.should_not_receive(:mountable?) @@ -95,15 +95,15 @@ describe Chef::Provider::Mount::Mount do it "should raise an error if the mount device (uuid) does not exist" do @new_resource.device_type :uuid @new_resource.device "d21afe51-a0fe-4dc6-9152-ac733763ae0a" - status_findfs = mock("Status", :exitstatus => 1) - stdout_findfs = mock("STDOUT", :first => nil) + status_findfs = double("Status", :exitstatus => 1) + stdout_findfs = double("STDOUT", :first => nil) @provider.should_receive(:popen4).with("/sbin/findfs UUID=d21afe51-a0fe-4dc6-9152-ac733763ae0a").and_yield(@pid,@stdin,stdout_findfs,@stderr).and_return(status_findfs) ::File.should_receive(:exists?).with("").and_return(false) lambda { @provider.load_current_resource();@provider.mountable? }.should raise_error(Chef::Exceptions::Mount) end it "should raise an error if the mount point does not exist" do - ::File.stub!(:exists?).with("/tmp/foo").and_return false + ::File.stub(:exists?).with("/tmp/foo").and_return false lambda { @provider.load_current_resource();@provider.mountable? }.should raise_error(Chef::Exceptions::Mount) end @@ -125,7 +125,7 @@ describe Chef::Provider::Mount::Mount do end it "should set mounted true if the mount point is found in the mounts list" do - @provider.stub!(:shell_out!).and_return(OpenStruct.new(:stdout => '/dev/sdz1 on /tmp/foo')) + @provider.stub(:shell_out!).and_return(OpenStruct.new(:stdout => '/dev/sdz1 on /tmp/foo')) @provider.load_current_resource() @provider.current_resource.mounted.should be_true end @@ -133,10 +133,10 @@ describe Chef::Provider::Mount::Mount do it "should set mounted true if the symlink target of the device is found in the mounts list" do target = "/dev/mapper/target" - ::File.stub!(:symlink?).with("#{@new_resource.device}").and_return(true) - ::File.stub!(:readlink).with("#{@new_resource.device}").and_return(target) + ::File.stub(:symlink?).with("#{@new_resource.device}").and_return(true) + ::File.stub(:readlink).with("#{@new_resource.device}").and_return(target) - @provider.stub!(:shell_out!).and_return(OpenStruct.new(:stdout => "/dev/mapper/target on /tmp/foo type ext3 (rw)\n")) + @provider.stub(:shell_out!).and_return(OpenStruct.new(:stdout => "/dev/mapper/target on /tmp/foo type ext3 (rw)\n")) @provider.load_current_resource() @provider.current_resource.mounted.should be_true end @@ -145,7 +145,7 @@ describe Chef::Provider::Mount::Mount do mount = "/dev/sdy1 on #{@new_resource.mount_point} type ext3 (rw)\n" mount << "#{@new_resource.device} on #{@new_resource.mount_point} type ext3 (rw)\n" - @provider.stub!(:shell_out!).and_return(OpenStruct.new(:stdout => mount)) + @provider.stub(:shell_out!).and_return(OpenStruct.new(:stdout => mount)) @provider.load_current_resource() @provider.current_resource.mounted.should be_true end @@ -154,13 +154,13 @@ describe Chef::Provider::Mount::Mount do mount = "#{@new_resource.device} on #{@new_resource.mount_point} type ext3 (rw)\n" mount << "/dev/sdy1 on #{@new_resource.mount_point} type ext3 (rw)\n" - @provider.stub!(:shell_out!).and_return(OpenStruct.new(:stdout => mount)) + @provider.stub(:shell_out!).and_return(OpenStruct.new(:stdout => mount)) @provider.load_current_resource() @provider.current_resource.mounted.should be_false end it "mounted should be false if the mount point is not found in the mounts list" do - @provider.stub!(:shell_out!).and_return(OpenStruct.new(:stdout => "/dev/sdy1 on /tmp/foo type ext3 (rw)\n")) + @provider.stub(:shell_out!).and_return(OpenStruct.new(:stdout => "/dev/sdy1 on /tmp/foo type ext3 (rw)\n")) @provider.load_current_resource() @provider.current_resource.mounted.should be_false end @@ -169,7 +169,7 @@ describe Chef::Provider::Mount::Mount do fstab1 = "/dev/sdy1 /tmp/foo ext3 defaults 1 2\n" fstab2 = "#{@new_resource.device} #{@new_resource.mount_point} ext3 defaults 1 2\n" - ::File.stub!(:foreach).with("/etc/fstab").and_yield(fstab1).and_yield(fstab2) + ::File.stub(:foreach).with("/etc/fstab").and_yield(fstab1).and_yield(fstab2) @provider.load_current_resource @provider.current_resource.enabled.should be_true @@ -179,7 +179,7 @@ describe Chef::Provider::Mount::Mount do fstab1 = "#{@new_resource.device} #{@new_resource.mount_point} ext3 defaults 1 2\n" fstab2 = "/dev/sdy1 /tmp/foo/bar ext3 defaults 1 2\n" - ::File.stub!(:foreach).with("/etc/fstab").and_yield(fstab1).and_yield(fstab2) + ::File.stub(:foreach).with("/etc/fstab").and_yield(fstab1).and_yield(fstab2) @provider.load_current_resource @provider.current_resource.enabled.should be_true @@ -188,12 +188,12 @@ describe Chef::Provider::Mount::Mount do it "should set enabled to true if the symlink target is in fstab" do target = "/dev/mapper/target" - ::File.stub!(:symlink?).with("#{@new_resource.device}").and_return(true) - ::File.stub!(:readlink).with("#{@new_resource.device}").and_return(target) + ::File.stub(:symlink?).with("#{@new_resource.device}").and_return(true) + ::File.stub(:readlink).with("#{@new_resource.device}").and_return(target) fstab = "/dev/sdz1 /tmp/foo ext3 defaults 1 2\n" - ::File.stub!(:foreach).with("/etc/fstab").and_yield fstab + ::File.stub(:foreach).with("/etc/fstab").and_yield fstab @provider.load_current_resource @provider.current_resource.enabled.should be_true @@ -201,7 +201,7 @@ describe Chef::Provider::Mount::Mount do it "should set enabled to false if the mount point is not in fstab" do fstab = "/dev/sdy1 #{@new_resource.mount_point} ext3 defaults 1 2\n" - ::File.stub!(:foreach).with("/etc/fstab").and_yield fstab + ::File.stub(:foreach).with("/etc/fstab").and_yield fstab @provider.load_current_resource @provider.current_resource.enabled.should be_false @@ -209,7 +209,7 @@ describe Chef::Provider::Mount::Mount do it "should ignore commented lines in fstab " do fstab = "\# #{@new_resource.device} #{@new_resource.mount_point} ext3 defaults 1 2\n" - ::File.stub!(:foreach).with("/etc/fstab").and_yield fstab + ::File.stub(:foreach).with("/etc/fstab").and_yield fstab @provider.load_current_resource @provider.current_resource.enabled.should be_false @@ -218,7 +218,7 @@ describe Chef::Provider::Mount::Mount do it "should set enabled to false if the mount point is not last in fstab" do line_1 = "#{@new_resource.device} #{@new_resource.mount_point} ext3 defaults 1 2\n" line_2 = "/dev/sdy1 #{@new_resource.mount_point} ext3 defaults 1 2\n" - ::File.stub!(:foreach).with("/etc/fstab").and_yield(line_1).and_yield(line_2) + ::File.stub(:foreach).with("/etc/fstab").and_yield(line_1).and_yield(line_2) @provider.load_current_resource @provider.current_resource.enabled.should be_false @@ -228,11 +228,11 @@ describe Chef::Provider::Mount::Mount do target = "/dev/mapper/target" options = "rw,noexec,noauto" - ::File.stub!(:symlink?).with(@new_resource.device).and_return(true) - ::File.stub!(:readlink).with(@new_resource.device).and_return(target) + ::File.stub(:symlink?).with(@new_resource.device).and_return(true) + ::File.stub(:readlink).with(@new_resource.device).and_return(target) fstab = "#{@new_resource.device} #{@new_resource.mount_point} #{@new_resource.fstype} #{options} 1 2\n" - ::File.stub!(:foreach).with("/etc/fstab").and_yield fstab + ::File.stub(:foreach).with("/etc/fstab").and_yield fstab @provider.load_current_resource @provider.current_resource.options.should eq(options.split(',')) end @@ -241,11 +241,11 @@ describe Chef::Provider::Mount::Mount do target = "/dev/mapper/target" options = "rw,noexec,noauto" - ::File.stub!(:symlink?).with(@new_resource.device).and_return(true) - ::File.stub!(:readlink).with(@new_resource.device).and_return(target) + ::File.stub(:symlink?).with(@new_resource.device).and_return(true) + ::File.stub(:readlink).with(@new_resource.device).and_return(target) fstab = "#{target} #{@new_resource.mount_point} #{@new_resource.fstype} #{options} 1 2\n" - ::File.stub!(:foreach).with("/etc/fstab").and_yield fstab + ::File.stub(:foreach).with("/etc/fstab").and_yield fstab @provider.load_current_resource @provider.current_resource.options.should eq(options.split(',')) end @@ -263,7 +263,6 @@ describe Chef::Provider::Mount::Mount do describe "mount_fs" do it "should mount the filesystem if it is not mounted" do - @provider.rspec_reset @provider.should_receive(:shell_out!).with("mount -t ext3 -o defaults /dev/sdz1 /tmp/foo") @provider.mount_fs() end @@ -278,16 +277,16 @@ describe Chef::Provider::Mount::Mount do it "should mount the filesystem specified by uuid" do @new_resource.device "d21afe51-a0fe-4dc6-9152-ac733763ae0a" @new_resource.device_type :uuid - @stdout_findfs = mock("STDOUT", :first => "/dev/sdz1") - @provider.stub!(:popen4).with("/sbin/findfs UUID=d21afe51-a0fe-4dc6-9152-ac733763ae0a").and_yield(@pid,@stdin,@stdout_findfs,@stderr).and_return(@status) - @stdout_mock = mock('stdout mock') - @stdout_mock.stub!(:each).and_yield("#{@new_resource.device} on #{@new_resource.mount_point}") + @stdout_findfs = double("STDOUT", :first => "/dev/sdz1") + @provider.stub(:popen4).with("/sbin/findfs UUID=d21afe51-a0fe-4dc6-9152-ac733763ae0a").and_yield(@pid,@stdin,@stdout_findfs,@stderr).and_return(@status) + @stdout_mock = double('stdout mock') + @stdout_mock.stub(:each).and_yield("#{@new_resource.device} on #{@new_resource.mount_point}") @provider.should_receive(:shell_out!).with("mount -t #{@new_resource.fstype} -o defaults -U #{@new_resource.device} #{@new_resource.mount_point}").and_return(@stdout_mock) @provider.mount_fs() end it "should not mount the filesystem if it is mounted" do - @current_resource.stub!(:mounted).and_return(true) + @current_resource.stub(:mounted).and_return(true) @provider.should_not_receive(:shell_out!) @provider.mount_fs() end @@ -339,7 +338,7 @@ describe Chef::Provider::Mount::Mount do @current_resource.enabled(false) @fstab = StringIO.new - ::File.stub!(:open).with("/etc/fstab", "a").and_yield(@fstab) + ::File.stub(:open).with("/etc/fstab", "a").and_yield(@fstab) @provider.enable_fs @fstab.string.should match(%r{^/dev/sdz1\s+/tmp/foo\s+ext3\s+defaults\s+0\s+2\s*$}) end @@ -378,9 +377,9 @@ describe Chef::Provider::Mount::Mount do this_mount = "/dev/sdz1 /tmp/foo ext3 defaults 1 2\n" @fstab_read = [this_mount, other_mount] - ::File.stub!(:readlines).with("/etc/fstab").and_return(@fstab_read) + ::File.stub(:readlines).with("/etc/fstab").and_return(@fstab_read) @fstab_write = StringIO.new - ::File.stub!(:open).with("/etc/fstab", "w").and_yield(@fstab_write) + ::File.stub(:open).with("/etc/fstab", "w").and_yield(@fstab_write) @provider.disable_fs @fstab_write.string.should match(Regexp.escape(other_mount)) @@ -395,8 +394,8 @@ describe Chef::Provider::Mount::Mount do %q{#/dev/sdz1 /tmp/foo ext3 defaults 1 2}] fstab_write = StringIO.new - ::File.stub!(:readlines).with("/etc/fstab").and_return(fstab_read) - ::File.stub!(:open).with("/etc/fstab", "w").and_yield(fstab_write) + ::File.stub(:readlines).with("/etc/fstab").and_return(fstab_read) + ::File.stub(:open).with("/etc/fstab", "w").and_yield(fstab_write) @provider.disable_fs fstab_write.string.should match(%r{^/dev/sdy1 /tmp/foo ext3 defaults 1 2$}) @@ -405,23 +404,23 @@ describe Chef::Provider::Mount::Mount do end it "should disable only the last entry if enabled is true" do - @current_resource.stub!(:enabled).and_return(true) + @current_resource.stub(:enabled).and_return(true) fstab_read = ["/dev/sdz1 /tmp/foo ext3 defaults 1 2\n", "/dev/sdy1 /tmp/foo ext3 defaults 1 2\n", "/dev/sdz1 /tmp/foo ext3 defaults 1 2\n"] fstab_write = StringIO.new - ::File.stub!(:readlines).with("/etc/fstab").and_return(fstab_read) - ::File.stub!(:open).with("/etc/fstab", "w").and_yield(fstab_write) + ::File.stub(:readlines).with("/etc/fstab").and_return(fstab_read) + ::File.stub(:open).with("/etc/fstab", "w").and_yield(fstab_write) @provider.disable_fs fstab_write.string.should == "/dev/sdz1 /tmp/foo ext3 defaults 1 2\n/dev/sdy1 /tmp/foo ext3 defaults 1 2\n" end it "should not disable if enabled is false" do - @current_resource.stub!(:enabled).and_return(false) + @current_resource.stub(:enabled).and_return(false) - ::File.stub!(:readlines).with("/etc/fstab").and_return([]) + ::File.stub(:readlines).with("/etc/fstab").and_return([]) ::File.should_not_receive(:open).and_yield(@fstab) @provider.disable_fs diff --git a/spec/unit/provider/mount/windows_spec.rb b/spec/unit/provider/mount/windows_spec.rb index 4c9916ae87..80e7f1e695 100644 --- a/spec/unit/provider/mount/windows_spec.rb +++ b/spec/unit/provider/mount/windows_spec.rb @@ -40,12 +40,12 @@ describe Chef::Provider::Mount::Windows do @new_resource = Chef::Resource::Mount.new("X:") @new_resource.device GUID @current_resource = Chef::Resource::Mount.new("X:") - Chef::Resource::Mount.stub!(:new).and_return(@current_resource) + Chef::Resource::Mount.stub(:new).and_return(@current_resource) - @net_use = mock("Chef::Util::Windows::NetUse") - Chef::Util::Windows::NetUse.stub!(:new).and_return(@net_use) - @vol = mock("Chef::Util::Windows::Volume") - Chef::Util::Windows::Volume.stub!(:new).and_return(@vol) + @net_use = double("Chef::Util::Windows::NetUse") + Chef::Util::Windows::NetUse.stub(:new).and_return(@net_use) + @vol = double("Chef::Util::Windows::Volume") + Chef::Util::Windows::Volume.stub(:new).and_return(@vol) @provider = Chef::Provider::Mount::Windows.new(@new_resource, @run_context) @provider.current_resource = @current_resource @@ -53,13 +53,13 @@ describe Chef::Provider::Mount::Windows do describe "when loading the current resource" do it "should set mounted true if the mount point is found" do - @vol.stub!(:device).and_return(@new_resource.device) + @vol.stub(:device).and_return(@new_resource.device) @current_resource.should_receive(:mounted).with(true) @provider.load_current_resource end it "should set mounted false if the mount point is not found" do - @vol.stub!(:device).and_raise(ArgumentError) + @vol.stub(:device).and_raise(ArgumentError) @current_resource.should_receive(:mounted).with(false) @provider.load_current_resource end @@ -67,8 +67,8 @@ describe Chef::Provider::Mount::Windows do describe "with a local device" do before do @new_resource.device GUID - @vol.stub!(:device).and_return(@new_resource.device) - @net_use.stub!(:device).and_raise(ArgumentError) + @vol.stub(:device).and_return(@new_resource.device) + @net_use.stub(:device).and_raise(ArgumentError) end it "should determine the device is a volume GUID" do @@ -80,8 +80,8 @@ describe Chef::Provider::Mount::Windows do describe "with a remote device" do before do @new_resource.device REMOTE - @net_use.stub!(:device).and_return(@new_resource.device) - @vol.stub!(:device).and_raise(ArgumentError) + @net_use.stub(:device).and_return(@new_resource.device) + @vol.stub(:device).and_raise(ArgumentError) end it "should determine the device is remote" do @@ -93,8 +93,8 @@ describe Chef::Provider::Mount::Windows do describe "when mounting a file system" do before do @new_resource.device GUID - @vol.stub!(:add) - @vol.stub!(:device).and_raise(ArgumentError) + @vol.stub(:add) + @vol.stub(:device).and_raise(ArgumentError) @provider.load_current_resource end @@ -108,7 +108,7 @@ describe Chef::Provider::Mount::Windows do it "should not mount the filesystem if it is mounted" do @vol.should_not_receive(:add) - @current_resource.stub!(:mounted).and_return(true) + @current_resource.stub(:mounted).and_return(true) @provider.mount_fs end end @@ -116,19 +116,19 @@ describe Chef::Provider::Mount::Windows do describe "when unmounting a file system" do before do @new_resource.device GUID - @vol.stub!(:delete) - @vol.stub!(:device).and_raise(ArgumentError) + @vol.stub(:delete) + @vol.stub(:device).and_raise(ArgumentError) @provider.load_current_resource end it "should umount the filesystem if it is mounted" do - @current_resource.stub!(:mounted).and_return(true) + @current_resource.stub(:mounted).and_return(true) @vol.should_receive(:delete) @provider.umount_fs end it "should not umount the filesystem if it is not mounted" do - @current_resource.stub!(:mounted).and_return(false) + @current_resource.stub(:mounted).and_return(false) @vol.should_not_receive(:delete) @provider.umount_fs end diff --git a/spec/unit/provider/mount_spec.rb b/spec/unit/provider/mount_spec.rb index a44f9705ee..d9bfeb3e0f 100644 --- a/spec/unit/provider/mount_spec.rb +++ b/spec/unit/provider/mount_spec.rb @@ -43,14 +43,14 @@ describe Chef::Provider::Mount do describe "when the target state is a mounted filesystem" do it "should mount the filesystem if it isn't mounted" do - @current_resource.stub!(:mounted).and_return(false) + @current_resource.stub(:mounted).and_return(false) @provider.should_receive(:mount_fs).with.and_return(true) @provider.run_action(:mount) @new_resource.should be_updated_by_last_action end it "should not mount the filesystem if it is mounted" do - @current_resource.stub!(:mounted).and_return(true) + @current_resource.stub(:mounted).and_return(true) @provider.should_not_receive(:mount_fs) @provider.run_action(:mount) @new_resource.should_not be_updated_by_last_action @@ -60,14 +60,14 @@ describe Chef::Provider::Mount do describe "when the target state is an unmounted filesystem" do it "should umount the filesystem if it is mounted" do - @current_resource.stub!(:mounted).and_return(true) + @current_resource.stub(:mounted).and_return(true) @provider.should_receive(:umount_fs).with.and_return(true) @provider.run_action(:umount) @new_resource.should be_updated_by_last_action end it "should not umount the filesystem if it is not mounted" do - @current_resource.stub!(:mounted).and_return(false) + @current_resource.stub(:mounted).and_return(false) @provider.should_not_receive(:umount_fs) @provider.run_action(:umount) @new_resource.should_not be_updated_by_last_action @@ -80,14 +80,14 @@ describe Chef::Provider::Mount do end it "should remount the filesystem if it is mounted" do - @current_resource.stub!(:mounted).and_return(true) + @current_resource.stub(:mounted).and_return(true) @provider.should_receive(:remount_fs).and_return(true) @provider.run_action(:remount) @new_resource.should be_updated_by_last_action end it "should not remount the filesystem if it is not mounted" do - @current_resource.stub!(:mounted).and_return(false) + @current_resource.stub(:mounted).and_return(false) @provider.should_not_receive(:remount_fs) @provider.run_action(:remount) @new_resource.should_not be_updated_by_last_action @@ -107,7 +107,7 @@ describe Chef::Provider::Mount do end describe "when enabling the filesystem to be mounted" do it "should enable the mount if it isn't enable" do - @current_resource.stub!(:enabled).and_return(false) + @current_resource.stub(:enabled).and_return(false) @provider.should_not_receive(:mount_options_unchanged?) @provider.should_receive(:enable_fs).and_return(true) @provider.run_action(:enable) @@ -115,7 +115,7 @@ describe Chef::Provider::Mount do end it "should enable the mount if it is enabled and mount options have changed" do - @current_resource.stub!(:enabled).and_return(true) + @current_resource.stub(:enabled).and_return(true) @provider.should_receive(:mount_options_unchanged?).and_return(false) @provider.should_receive(:enable_fs).and_return(true) @provider.run_action(:enable) @@ -123,9 +123,9 @@ describe Chef::Provider::Mount do end it "should not enable the mount if it is enabled and mount options have not changed" do - @current_resource.stub!(:enabled).and_return(true) + @current_resource.stub(:enabled).and_return(true) @provider.should_receive(:mount_options_unchanged?).and_return(true) - @provider.should_not_receive(:enable_fs).and_return(true) + @provider.should_not_receive(:enable_fs) @provider.run_action(:enable) @new_resource.should_not be_updated_by_last_action end @@ -133,14 +133,14 @@ describe Chef::Provider::Mount do describe "when the target state is to disable the mount" do it "should disable the mount if it is enabled" do - @current_resource.stub!(:enabled).and_return(true) + @current_resource.stub(:enabled).and_return(true) @provider.should_receive(:disable_fs).with.and_return(true) @provider.run_action(:disable) @new_resource.should be_updated_by_last_action end it "should not disable the mount if it isn't enabled" do - @current_resource.stub!(:enabled).and_return(false) + @current_resource.stub(:enabled).and_return(false) @provider.should_not_receive(:disable_fs) @provider.run_action(:disable) @new_resource.should_not be_updated_by_last_action diff --git a/spec/unit/provider/ohai_spec.rb b/spec/unit/provider/ohai_spec.rb index 8402c92e97..8b8a6b5939 100644 --- a/spec/unit/provider/ohai_spec.rb +++ b/spec/unit/provider/ohai_spec.rb @@ -41,17 +41,17 @@ describe Chef::Provider::Ohai do :newdata => "somevalue" } } - mock_ohai.stub!(:all_plugins).and_return(true) - mock_ohai.stub!(:require_plugin).and_return(true) - mock_ohai.stub!(:data).and_return(mock_ohai[:data], + mock_ohai.stub(:all_plugins).and_return(true) + mock_ohai.stub(:require_plugin).and_return(true) + mock_ohai.stub(:data).and_return(mock_ohai[:data], mock_ohai[:data2]) - Ohai::System.stub!(:new).and_return(mock_ohai) - Chef::Platform.stub!(:find_platform_and_version).and_return({ "platform" => @platform, + Ohai::System.stub(:new).and_return(mock_ohai) + Chef::Platform.stub(:find_platform_and_version).and_return({ "platform" => @platform, "platform_version" => @platform_version}) # Fake node with a dummy save @node = Chef::Node.new @node.name(@fqdn) - @node.stub!(:save).and_return(@node) + @node.stub(:save).and_return(@node) @events = Chef::EventDispatch::Dispatcher.new @run_context = Chef::RunContext.new(@node, {}, @events) @new_resource = Chef::Resource::Ohai.new("ohai_reload") diff --git a/spec/unit/provider/package/aix_spec.rb b/spec/unit/provider/package/aix_spec.rb index 6e936156a0..35f85b628f 100644 --- a/spec/unit/provider/package/aix_spec.rb +++ b/spec/unit/provider/package/aix_spec.rb @@ -28,7 +28,7 @@ describe Chef::Provider::Package::Aix do @new_resource.source("/tmp/samba.base") @provider = Chef::Provider::Package::Aix.new(@new_resource, @run_context) - ::File.stub!(:exists?).and_return(true) + ::File.stub(:exists?).and_return(true) end describe "assessing the current package status" do @@ -36,24 +36,24 @@ describe Chef::Provider::Package::Aix do @bffinfo ="/usr/lib/objrepos:samba.base:3.3.12.0::COMMITTED:I:Samba for AIX: /etc/objrepos:samba.base:3.3.12.0::COMMITTED:I:Samba for AIX:" - @status = mock("Status", :exitstatus => 0) + @status = double("Status", :exitstatus => 0) end it "should create a current resource with the name of new_resource" do - @provider.stub!(:popen4).and_return(@status) + @provider.stub(:popen4).and_return(@status) @provider.load_current_resource @provider.current_resource.name.should == "samba.base" end it "should set the current resource bff package name to the new resource bff package name" do - @provider.stub!(:popen4).and_return(@status) + @provider.stub(:popen4).and_return(@status) @provider.load_current_resource @provider.current_resource.package_name.should == "samba.base" end it "should raise an exception if a source is supplied but not found" do - @provider.stub!(:popen4).and_return(@status) - ::File.stub!(:exists?).and_return(false) + @provider.stub(:popen4).and_return(@status) + ::File.stub(:exists?).and_return(false) @provider.define_resource_requirements @provider.load_current_resource lambda { @provider.process_resource_requirements }.should raise_error(Chef::Exceptions::Package) @@ -83,13 +83,13 @@ describe Chef::Provider::Package::Aix do it "should raise an exception if the source is not set but we are installing" do @new_resource = Chef::Resource::Package.new("samba.base") @provider = Chef::Provider::Package::Aix.new(@new_resource, @run_context) - @provider.stub!(:popen4).and_return(@status) + @provider.stub(:popen4).and_return(@status) lambda { @provider.run_action(:install) }.should raise_error(Chef::Exceptions::Package) end it "should raise an exception if installp/lslpp fails to run" do - @status = mock("Status", :exitstatus => -1) - @provider.stub!(:popen4).and_return(@status) + @status = double("Status", :exitstatus => -1) + @provider.stub(:popen4).and_return(@status) lambda { @provider.load_current_resource }.should raise_error(Chef::Exceptions::Package) end @@ -110,14 +110,14 @@ describe Chef::Provider::Package::Aix do end it "should lookup the candidate_version if the variable is not already set" do - @status = mock("Status", :exitstatus => 0) + @status = double("Status", :exitstatus => 0) @provider.should_receive(:popen4).and_return(@status) @provider.candidate_version end it "should throw and exception if the exitstatus is not 0" do - @status = mock("Status", :exitstatus => 1) - @provider.stub!(:popen4).and_return(@status) + @status = double("Status", :exitstatus => 1) + @provider.stub(:popen4).and_return(@status) lambda { @provider.candidate_version }.should raise_error(Chef::Exceptions::Package) end @@ -142,7 +142,7 @@ describe Chef::Provider::Package::Aix do end it "should run installp with -eLogfile option." do - @new_resource.stub!(:options).and_return("-e/tmp/installp.log") + @new_resource.stub(:options).and_return("-e/tmp/installp.log") @provider.should_receive(:run_command_with_systems_locale).with({ :command => "installp -aYF -e/tmp/installp.log -d /tmp/samba.base samba.base" }) @@ -159,7 +159,7 @@ describe Chef::Provider::Package::Aix do end it "should run installp -u -e/tmp/installp.log with options -e/tmp/installp.log" do - @new_resource.stub!(:options).and_return("-e/tmp/installp.log") + @new_resource.stub(:options).and_return("-e/tmp/installp.log") @provider.should_receive(:run_command_with_systems_locale).with({ :command => "installp -u -e/tmp/installp.log samba.base" }) diff --git a/spec/unit/provider/package/apt_spec.rb b/spec/unit/provider/package/apt_spec.rb index 32b55163b4..b8e23d8756 100644 --- a/spec/unit/provider/package/apt_spec.rb +++ b/spec/unit/provider/package/apt_spec.rb @@ -26,7 +26,7 @@ describe Chef::Provider::Package::Apt do @run_context = Chef::RunContext.new(@node, {}, @events) @new_resource = Chef::Resource::Package.new("irssi", @run_context) - @status = mock("Status", :exitstatus => 0) + @status = double("Status", :exitstatus => 0) @provider = Chef::Provider::Package::Apt.new(@new_resource, @run_context) @stdin = StringIO.new @stdout =<<-PKG_STATUS @@ -83,7 +83,7 @@ libmysqlclient15-dev: Candidate: (none) Version table: VPKG_STDOUT - virtual_package = mock(:stdout => virtual_package_out,:exitstatus => 0) + virtual_package = double(:stdout => virtual_package_out,:exitstatus => 0) @provider.should_receive(:shell_out!).with("apt-cache policy libmysqlclient15-dev").and_return(virtual_package) showpkg_out =<<-SHOWPKG_STDOUT Package: libmysqlclient15-dev @@ -103,7 +103,7 @@ libmysqlclient-dev 5.1.41-3ubuntu12.7 libmysqlclient-dev 5.1.41-3ubuntu12.10 libmysqlclient-dev 5.1.41-3ubuntu12 SHOWPKG_STDOUT - showpkg = mock(:stdout => showpkg_out,:exitstatus => 0) + showpkg = double(:stdout => showpkg_out,:exitstatus => 0) @provider.should_receive(:shell_out!).with("apt-cache showpkg libmysqlclient15-dev").and_return(showpkg) real_package_out=<<-RPKG_STDOUT libmysqlclient-dev: @@ -118,7 +118,7 @@ libmysqlclient-dev: 5.1.41-3ubuntu12 0 500 http://us.archive.ubuntu.com/ubuntu/ lucid/main Packages RPKG_STDOUT - real_package = mock(:stdout => real_package_out,:exitstatus => 0) + real_package = double(:stdout => real_package_out,:exitstatus => 0) @provider.should_receive(:shell_out!).with("apt-cache policy libmysqlclient-dev").and_return(real_package) @provider.load_current_resource end @@ -131,7 +131,7 @@ mp3-decoder: Candidate: (none) Version table: VPKG_STDOUT - virtual_package = mock(:stdout => virtual_package_out,:exitstatus => 0) + virtual_package = double(:stdout => virtual_package_out,:exitstatus => 0) @provider.should_receive(:shell_out!).with("apt-cache policy mp3-decoder").and_return(virtual_package) showpkg_out=<<-SHOWPKG_STDOUT Package: mp3-decoder @@ -154,7 +154,7 @@ opencubicplayer 1:0.1.17-2 mpg321 0.2.10.6 mpg123 1.12.1-0ubuntu1 SHOWPKG_STDOUT - showpkg = mock(:stdout => showpkg_out,:exitstatus => 0) + showpkg = double(:stdout => showpkg_out,:exitstatus => 0) @provider.should_receive(:shell_out!).with("apt-cache showpkg mp3-decoder").and_return(showpkg) lambda { @provider.load_current_resource }.should raise_error(Chef::Exceptions::Package) end @@ -163,8 +163,8 @@ SHOWPKG_STDOUT @new_resource = Chef::Resource::AptPackage.new("irssi", @run_context) @provider = Chef::Provider::Package::Apt.new(@new_resource, @run_context) - @new_resource.stub!(:default_release).and_return("lenny-backports") - @new_resource.stub!(:provider).and_return("Chef::Provider::Package::Apt") + @new_resource.stub(:default_release).and_return("lenny-backports") + @new_resource.stub(:provider).and_return("Chef::Provider::Package::Apt") @provider.should_receive(:shell_out!).with("apt-cache -o APT::Default-Release=lenny-backports policy irssi").and_return(@shell_out) @provider.load_current_resource end @@ -256,7 +256,7 @@ SHOWPKG_STDOUT describe "when preseeding a package" do before(:each) do - @provider.stub!(:get_preseed_file).and_return("/tmp/irssi-0.8.12-7.seed") + @provider.stub(:get_preseed_file).and_return("/tmp/irssi-0.8.12-7.seed") end it "should get the full path to the preseed response file" do @@ -282,7 +282,7 @@ SHOWPKG_STDOUT @provider.stub(:check_package_state) @current_resource.version "0.8.11" @new_resource.response_file "/tmp/file" - @provider.stub!(:get_preseed_file).and_return(false) + @provider.stub(:get_preseed_file).and_return(false) @provider.should_not_receive(:shell_out!) @provider.run_action(:reconfig) end diff --git a/spec/unit/provider/package/dpkg_spec.rb b/spec/unit/provider/package/dpkg_spec.rb index 30021e31f3..6ba7695a1e 100644 --- a/spec/unit/provider/package/dpkg_spec.rb +++ b/spec/unit/provider/package/dpkg_spec.rb @@ -30,12 +30,12 @@ describe Chef::Provider::Package::Dpkg do @stdin = StringIO.new @stdout = StringIO.new - @status = mock("Status", :exitstatus => 0) + @status = double("Status", :exitstatus => 0) @stderr = StringIO.new - @pid = mock("PID") - @provider.stub!(:popen4).and_return(@status) + @pid = double("PID") + @provider.stub(:popen4).and_return(@status) - ::File.stub!(:exists?).and_return(true) + ::File.stub(:exists?).and_return(true) end describe "when loading the current resource state" do @@ -48,14 +48,14 @@ describe Chef::Provider::Package::Dpkg do it "should raise an exception if a source is supplied but not found" do @provider.load_current_resource @provider.define_resource_requirements - ::File.stub!(:exists?).and_return(false) + ::File.stub(:exists?).and_return(false) lambda { @provider.run_action(:install) }.should raise_error(Chef::Exceptions::Package) end describe 'gets the source package version from dpkg-deb' do def check_version(version) @stdout = StringIO.new("wget\t#{version}") - @provider.stub!(:popen4).with("dpkg-deb -W #{@new_resource.source}").and_yield(@pid, @stdin, @stdout, @stderr).and_return(@status) + @provider.stub(:popen4).with("dpkg-deb -W #{@new_resource.source}").and_yield(@pid, @stdin, @stdout, @stderr).and_return(@status) @provider.load_current_resource @provider.current_resource.package_name.should == "wget" @new_resource.version.should == version @@ -76,7 +76,7 @@ describe Chef::Provider::Package::Dpkg do it "gets the source package name from dpkg-deb correctly when the package name has `-', `+' or `.' characters" do @stdout = StringIO.new("f.o.o-pkg++2\t1.11.4-1ubuntu1") - @provider.stub!(:popen4).and_yield(@pid, @stdin, @stdout, @stderr).and_return(@status) + @provider.stub(:popen4).and_yield(@pid, @stdin, @stdout, @stderr).and_return(@status) @provider.load_current_resource @provider.current_resource.package_name.should == "f.o.o-pkg++2" end @@ -103,15 +103,15 @@ Config-Version: 1.11.4-1ubuntu1 Depends: libc6 (>= 2.8~20080505), libssl0.9.8 (>= 0.9.8f-5) Conflicts: wget-ssl DPKG_S - @provider.stub!(:popen4).with("dpkg -s wget").and_yield(@pid, @stdin, @stdout, @stderr).and_return(@status) + @provider.stub(:popen4).with("dpkg -s wget").and_yield(@pid, @stdin, @stdout, @stderr).and_return(@status) @provider.load_current_resource @provider.current_resource.version.should == "1.11.4-1ubuntu1" end it "should raise an exception if dpkg fails to run" do - @status = mock("Status", :exitstatus => -1) - @provider.stub!(:popen4).and_return(@status) + @status = double("Status", :exitstatus => -1) + @provider.stub(:popen4).and_return(@status) lambda { @provider.load_current_resource }.should raise_error(Chef::Exceptions::Package) end end @@ -158,7 +158,7 @@ DPKG_S "DEBIAN_FRONTEND" => "noninteractive" } }) - @new_resource.stub!(:options).and_return("--force-yes") + @new_resource.stub(:options).and_return("--force-yes") @provider.install_package("wget", "1.11.4-1ubuntu1") end @@ -186,7 +186,7 @@ DPKG_S "DEBIAN_FRONTEND" => "noninteractive" } }) - @new_resource.stub!(:options).and_return("--force-yes") + @new_resource.stub(:options).and_return("--force-yes") @provider.remove_package("wget", "1.11.4-1ubuntu1") end @@ -208,7 +208,7 @@ DPKG_S "DEBIAN_FRONTEND" => "noninteractive" } }) - @new_resource.stub!(:options).and_return("--force-yes") + @new_resource.stub(:options).and_return("--force-yes") @provider.purge_package("wget", "1.11.4-1ubuntu1") end diff --git a/spec/unit/provider/package/easy_install_spec.rb b/spec/unit/provider/package/easy_install_spec.rb index 02f8399af8..87cbabcc19 100644 --- a/spec/unit/provider/package/easy_install_spec.rb +++ b/spec/unit/provider/package/easy_install_spec.rb @@ -30,14 +30,14 @@ describe Chef::Provider::Package::EasyInstall do @current_resource.version('1.8d') @provider = Chef::Provider::Package::EasyInstall.new(@new_resource, @run_context) - Chef::Resource::Package.stub!(:new).and_return(@current_resource) + Chef::Resource::Package.stub(:new).and_return(@current_resource) @stdin = StringIO.new @stdout = StringIO.new - @status = mock("Status", :exitstatus => 0) + @status = double("Status", :exitstatus => 0) @stderr = StringIO.new @pid = 2342 - @provider.stub!(:popen4).and_return(@status) + @provider.stub(:popen4).and_return(@status) end describe "easy_install_binary_path" do @@ -47,7 +47,7 @@ describe Chef::Provider::Package::EasyInstall do end it "should set the current resources package name to the new resources package name" do - $stdout.stub!(:write) + $stdout.stub(:write) @current_resource.should_receive(:package_name).with(@new_resource.package_name) @provider.load_current_resource end @@ -75,7 +75,7 @@ describe Chef::Provider::Package::EasyInstall do @provider.should_receive(:run_command).with({ :command => "easy_install --always-unzip \"boto==1.8d\"" }) - @new_resource.stub!(:options).and_return("--always-unzip") + @new_resource.stub(:options).and_return("--always-unzip") @provider.install_package("boto", "1.8d") end @@ -97,7 +97,7 @@ describe Chef::Provider::Package::EasyInstall do @provider.should_receive(:run_command).with({ :command => "easy_install -x -m boto" }) - @new_resource.stub!(:options).and_return("-x") + @new_resource.stub(:options).and_return("-x") @provider.remove_package("boto", "1.8d") end diff --git a/spec/unit/provider/package/freebsd_spec.rb b/spec/unit/provider/package/freebsd_spec.rb index 2901b84f49..962f9c23d1 100644 --- a/spec/unit/provider/package/freebsd_spec.rb +++ b/spec/unit/provider/package/freebsd_spec.rb @@ -30,12 +30,12 @@ describe Chef::Provider::Package::Freebsd, "load_current_resource" do @provider = Chef::Provider::Package::Freebsd.new(@new_resource, @run_context) @provider.current_resource = @current_resource - ::File.stub!(:exist?).with('/usr/ports/Makefile').and_return(false) + ::File.stub(:exist?).with('/usr/ports/Makefile').and_return(false) end describe "when determining the current package state" do before do - @provider.stub!(:ports_candidate_version).and_return("4.3.6") + @provider.stub(:ports_candidate_version).and_return("4.3.6") end it "should create a current resource with the name of the new_resource" do @@ -68,25 +68,25 @@ describe Chef::Provider::Package::Freebsd, "load_current_resource" do #@provider = Chef::Provider::Package::Freebsd.new(@node, @new_resource) - #@status = mock("Status", :exitstatus => 0) - #@stdin = mock("STDIN", :null_object => true) - #@stdout = mock("STDOUT", :null_object => true) - #@stderr = mock("STDERR", :null_object => true) - #@pid = mock("PID", :null_object => true) + #@status = double("Status", :exitstatus => 0) + #@stdin = double("STDIN", :null_object => true) + #@stdout = double("STDOUT", :null_object => true) + #@stderr = double("STDERR", :null_object => true) + #@pid = double("PID", :null_object => true) end it "should return the version number when it is installed" do pkg_info = OpenStruct.new(:stdout => "zsh-4.3.6_7") @provider.should_receive(:shell_out!).with('pkg_info -E "zsh*"', :env => nil, :returns => [0,1]).and_return(pkg_info) #@provider.should_receive(:popen4).with('pkg_info -E "zsh*"').and_yield(@pid, @stdin, ["zsh-4.3.6_7"], @stderr).and_return(@status) - @provider.stub!(:package_name).and_return("zsh") + @provider.stub(:package_name).and_return("zsh") @provider.current_installed_version.should == "4.3.6_7" end it "does not set the current version number when the package is not installed" do pkg_info = OpenStruct.new(:stdout => "") @provider.should_receive(:shell_out!).with('pkg_info -E "zsh*"', :env => nil, :returns => [0,1]).and_return(pkg_info) - @provider.stub!(:package_name).and_return("zsh") + @provider.stub(:package_name).and_return("zsh") @provider.current_installed_version.should be_nil end @@ -94,21 +94,21 @@ describe Chef::Provider::Package::Freebsd, "load_current_resource" do whereis = OpenStruct.new(:stdout => "zsh: /usr/ports/shells/zsh") @provider.should_receive(:shell_out!).with("whereis -s zsh", :env => nil).and_return(whereis) #@provider.should_receive(:popen4).with("whereis -s zsh").and_yield(@pid, @stdin, ["zsh: /usr/ports/shells/zsh"], @stderr).and_return(@status) - @provider.stub!(:port_name).and_return("zsh") + @provider.stub(:port_name).and_return("zsh") @provider.port_path.should == "/usr/ports/shells/zsh" end # Not happy with the form of these tests as they are far too closely tied to the implementation and so very fragile. it "should return the ports candidate version when given a valid port path" do - @provider.stub!(:port_path).and_return("/usr/ports/shells/zsh") + @provider.stub(:port_path).and_return("/usr/ports/shells/zsh") make_v = OpenStruct.new(:stdout => "4.3.6\n") @provider.should_receive(:shell_out!).with("make -V PORTVERSION", {:cwd=>"/usr/ports/shells/zsh", :returns=>[0, 1], :env=>nil}).and_return(make_v) @provider.ports_candidate_version.should == "4.3.6" end it "should figure out the package name when we have ports" do - ::File.stub!(:exist?).with('/usr/ports/Makefile').and_return(true) - @provider.stub!(:port_path).and_return("/usr/ports/shells/zsh") + ::File.stub(:exist?).with('/usr/ports/Makefile').and_return(true) + @provider.stub(:port_path).and_return("/usr/ports/shells/zsh") make_v = OpenStruct.new(:stdout => "zsh-4.3.6_7\n") @provider.should_receive(:shell_out!).with("make -V PKGNAME", {:cwd=>"/usr/ports/shells/zsh", :env=>nil, :returns=>[0, 1]}).and_return(make_v) #@provider.should_receive(:ports_makefile_variable_value).with("PKGNAME").and_return("zsh-4.3.6_7") @@ -121,9 +121,9 @@ describe Chef::Provider::Package::Freebsd, "load_current_resource" do @cmd_result = OpenStruct.new(:status => true) @provider.current_resource = @current_resource - @provider.stub!(:package_name).and_return("zsh") - @provider.stub!(:latest_link_name).and_return("zsh") - @provider.stub!(:port_path).and_return("/usr/ports/shells/zsh") + @provider.stub(:package_name).and_return("zsh") + @provider.stub(:latest_link_name).and_return("zsh") + @provider.stub(:port_path).and_return("/usr/ports/shells/zsh") end it "should run pkg_add -r with the package name" do @@ -132,7 +132,7 @@ describe Chef::Provider::Package::Freebsd, "load_current_resource" do end it "should run make install when installing from ports" do - @new_resource.stub!(:source).and_return("ports") + @new_resource.stub(:source).and_return("ports") @provider.should_not_receive(:shell_out!).with("make -DBATCH -f /usr/ports/shells/zsh/Makefile install", :timeout => 1200, :env=>nil) @provider.should_receive(:shell_out!).with("make -DBATCH install", :timeout => 1200, :env=>nil, :cwd => @provider.port_path).and_return(@cmd_result) @provider.install_package("zsh", "4.3.6_7") @@ -161,7 +161,7 @@ describe Chef::Provider::Package::Freebsd, "load_current_resource" do end it "should use the package_name as a relative path from /usr/ports when it contains / but doesn't start with it" do - # @new_resource = mock( "Chef::Resource::Package", + # @new_resource = double( "Chef::Resource::Package", # :package_name => "www/wordpress", # :cookbook_name => "xenoparadox") new_resource = Chef::Resource::Package.new("www/wordpress") @@ -177,9 +177,9 @@ describe Chef::Provider::Package::Freebsd, "load_current_resource" do @current_resource = Chef::Resource::Package.new("ruby-iconv") @provider = Chef::Provider::Package::Freebsd.new(@new_resource, @run_context) @provider.current_resource = @current_resource - @provider.stub!(:port_path).and_return("/usr/ports/converters/ruby-iconv") - @provider.stub!(:package_name).and_return("ruby18-iconv") - @provider.stub!(:latest_link_name).and_return("ruby18-iconv") + @provider.stub(:port_path).and_return("/usr/ports/converters/ruby-iconv") + @provider.stub(:package_name).and_return("ruby18-iconv") + @provider.stub(:latest_link_name).and_return("ruby18-iconv") @install_result = OpenStruct.new(:status => true) end @@ -190,7 +190,7 @@ describe Chef::Provider::Package::Freebsd, "load_current_resource" do end it "should run make install when installing from ports" do - @new_resource.stub!(:source).and_return("ports") + @new_resource.stub(:source).and_return("ports") @provider.should_receive(:shell_out!).with("make -DBATCH install", :timeout => 1200, :env=>nil, :cwd => @provider.port_path).and_return(@install_result) @provider.install_package("ruby-iconv", "1.0") end @@ -202,7 +202,7 @@ describe Chef::Provider::Package::Freebsd, "load_current_resource" do @new_resource.version "4.3.6_7" @current_resource.version "4.3.6_7" @provider.current_resource = @current_resource - @provider.stub!(:package_name).and_return("zsh") + @provider.stub(:package_name).and_return("zsh") end it "should run pkg_delete with the package name and version" do @@ -227,14 +227,14 @@ describe Chef::Provider::Package::Freebsd, "load_current_resource" do it "should return the port path for a valid port name" do whereis = OpenStruct.new(:stdout => "bonnie++: /usr/ports/benchmarks/bonnie++") @provider.should_receive(:shell_out!).with("whereis -s bonnie++", :env => nil).and_return(whereis) - @provider.stub!(:port_name).and_return("bonnie++") + @provider.stub(:port_name).and_return("bonnie++") @provider.port_path.should == "/usr/ports/benchmarks/bonnie++" end it "should return the version number when it is installed" do pkg_info = OpenStruct.new(:stdout => "bonnie++-1.96") @provider.should_receive(:shell_out!).with('pkg_info -E "bonnie++*"', :env => nil, :returns => [0,1]).and_return(pkg_info) - @provider.stub!(:package_name).and_return("bonnie++") + @provider.stub(:package_name).and_return("bonnie++") @provider.current_installed_version.should == "1.96" end end @@ -262,8 +262,8 @@ describe Chef::Provider::Package::Freebsd, "load_current_resource" do @current_resource = Chef::Resource::Package.new("perl5.8") @provider = Chef::Provider::Package::Freebsd.new(@new_resource, @run_context) @provider.current_resource = @current_resource - @provider.stub!(:package_name).and_return("perl") - @provider.stub!(:latest_link_name).and_return("perl") + @provider.stub(:package_name).and_return("perl") + @provider.stub(:latest_link_name).and_return("perl") cmd = OpenStruct.new(:status => true) @provider.should_receive(:shell_out!).with("pkg_add -r perl", :env => nil).and_return(cmd) @@ -276,8 +276,8 @@ describe Chef::Provider::Package::Freebsd, "load_current_resource" do @current_resource = Chef::Resource::Package.new("mysql50-server") @provider = Chef::Provider::Package::Freebsd.new(@new_resource, @run_context) @provider.current_resource = @current_resource - @provider.stub!(:package_name).and_return("mysql-server") - @provider.stub!(:latest_link_name).and_return("mysql50-server") + @provider.stub(:package_name).and_return("mysql-server") + @provider.stub(:latest_link_name).and_return("mysql50-server") cmd = OpenStruct.new(:status => true) @provider.should_receive(:shell_out!).with("pkg_add -r mysql50-server", :env=>nil).and_return(cmd) diff --git a/spec/unit/provider/package/ips_spec.rb b/spec/unit/provider/package/ips_spec.rb index 95839dbe89..53f8169623 100644 --- a/spec/unit/provider/package/ips_spec.rb +++ b/spec/unit/provider/package/ips_spec.rb @@ -28,7 +28,7 @@ describe Chef::Provider::Package::Ips do @run_context = Chef::RunContext.new(@node, {}, @events) @new_resource = Chef::Resource::Package.new("crypto/gnupg", @run_context) @current_resource = Chef::Resource::Package.new("crypto/gnupg", @run_context) - Chef::Resource::Package.stub!(:new).and_return(@current_resource) + Chef::Resource::Package.stub(:new).and_return(@current_resource) @provider = Chef::Provider::Package::Ips.new(@new_resource, @run_context) @stdin = StringIO.new @@ -117,7 +117,7 @@ INSTALLED @provider.should_receive(:run_command_with_systems_locale).with({ :command => "pkg --no-refresh install -q crypto/gnupg@2.0.17" }) - @new_resource.stub!(:options).and_return("--no-refresh") + @new_resource.stub(:options).and_return("--no-refresh") @provider.install_package("crypto/gnupg", "2.0.17") end @@ -168,7 +168,7 @@ PKG_STATUS context "when accept_license is true" do before do - @new_resource.stub!(:accept_license).and_return(true) + @new_resource.stub(:accept_license).and_return(true) end it "should run pkg install with the --accept flag" do @@ -202,7 +202,7 @@ PKG_STATUS @provider.should_receive(:run_command_with_systems_locale).with({ :command => "pkg --no-refresh uninstall -q crypto/gnupg@2.0.17" }) - @new_resource.stub!(:options).and_return("--no-refresh") + @new_resource.stub(:options).and_return("--no-refresh") @provider.remove_package("crypto/gnupg", "2.0.17") end end diff --git a/spec/unit/provider/package/macports_spec.rb b/spec/unit/provider/package/macports_spec.rb index 2f0db3f7a8..9ebf23860d 100644 --- a/spec/unit/provider/package/macports_spec.rb +++ b/spec/unit/provider/package/macports_spec.rb @@ -27,9 +27,9 @@ describe Chef::Provider::Package::Macports do @current_resource = Chef::Resource::Package.new("zsh") @provider = Chef::Provider::Package::Macports.new(@new_resource, @run_context) - Chef::Resource::Package.stub!(:new).and_return(@current_resource) + Chef::Resource::Package.stub(:new).and_return(@current_resource) - @status = mock("Status", :exitstatus => 0) + @status = double("Status", :exitstatus => 0) @stdin = StringIO.new @stdout = StringIO.new @stderr = StringIO.new @@ -121,7 +121,7 @@ EOF it "should add options to the port command when specified" do @current_resource.should_receive(:version).and_return("4.1.6") @provider.current_resource = @current_resource - @new_resource.stub!(:options).and_return("-f") + @new_resource.stub(:options).and_return("-f") @provider.should_receive(:run_command_with_systems_locale).with(:command => "port -f install zsh @4.2.7") @provider.install_package("zsh", "4.2.7") @@ -140,7 +140,7 @@ EOF end it "should add options to the port command when specified" do - @new_resource.stub!(:options).and_return("-f") + @new_resource.stub(:options).and_return("-f") @provider.should_receive(:run_command_with_systems_locale).with(:command => "port -f uninstall zsh @4.2.7") @provider.purge_package("zsh", "4.2.7") end @@ -158,7 +158,7 @@ EOF end it "should add options to the port command when specified" do - @new_resource.stub!(:options).and_return("-f") + @new_resource.stub(:options).and_return("-f") @provider.should_receive(:run_command_with_systems_locale).with(:command => "port -f deactivate zsh @4.2.7") @provider.remove_package("zsh", "4.2.7") end @@ -191,7 +191,7 @@ EOF end it "should add options to the port command when specified" do - @new_resource.stub!(:options).and_return("-f") + @new_resource.stub(:options).and_return("-f") @current_resource.should_receive(:version).at_least(:once).and_return("4.1.6") @provider.current_resource = @current_resource diff --git a/spec/unit/provider/package/pacman_spec.rb b/spec/unit/provider/package/pacman_spec.rb index 7e4abcb6d5..528f7097e8 100644 --- a/spec/unit/provider/package/pacman_spec.rb +++ b/spec/unit/provider/package/pacman_spec.rb @@ -26,10 +26,10 @@ describe Chef::Provider::Package::Pacman do @new_resource = Chef::Resource::Package.new("nano") @current_resource = Chef::Resource::Package.new("nano") - @status = mock("Status", :exitstatus => 0) + @status = double("Status", :exitstatus => 0) @provider = Chef::Provider::Package::Pacman.new(@new_resource, @run_context) - Chef::Resource::Package.stub!(:new).and_return(@current_resource) - @provider.stub!(:popen4).and_return(@status) + Chef::Resource::Package.stub(:new).and_return(@current_resource) + @provider.stub(:popen4).and_return(@status) @stdin = StringIO.new @stdout = StringIO.new(<<-ERR) error: package "nano" not found @@ -55,13 +55,13 @@ ERR end it "should read stdout on pacman" do - @provider.stub!(:popen4).and_yield(@pid, @stdin, @stdout, @stderr).and_return(@status) + @provider.stub(:popen4).and_yield(@pid, @stdin, @stdout, @stderr).and_return(@status) @stdout.should_receive(:each).and_return(true) @provider.load_current_resource end it "should set the installed version to nil on the current resource if pacman installed version not exists" do - @provider.stub!(:popen4).and_yield(@pid, @stdin, @stdout, @stderr).and_return(@status) + @provider.stub(:popen4).and_yield(@pid, @stdin, @stdout, @stderr).and_return(@status) @current_resource.should_receive(:version).with(nil).and_return(true) @provider.load_current_resource end @@ -88,17 +88,17 @@ Install Reason : Explicitly installed Install Script : Yes Description : Pico editor clone with enhancements PACMAN - @provider.stub!(:popen4).and_yield(@pid, @stdin, @stdout, @stderr).and_return(@status) + @provider.stub(:popen4).and_yield(@pid, @stdin, @stdout, @stderr).and_return(@status) @provider.load_current_resource @current_resource.version.should == "2.2.2-1" end it "should set the candidate version if pacman has one" do - @stdout.stub!(:each).and_yield("core/nano 2.2.3-1 (base)"). + @stdout.stub(:each).and_yield("core/nano 2.2.3-1 (base)"). and_yield(" Pico editor clone with enhancements"). and_yield("community/nanoblogger 3.4.1-1"). and_yield(" NanoBlogger is a small weblog engine written in Bash for the command line") - @provider.stub!(:popen4).and_yield(@pid, @stdin, @stdout, @stderr).and_return(@status) + @provider.stub(:popen4).and_yield(@pid, @stdin, @stdout, @stderr).and_return(@status) @provider.load_current_resource @provider.candidate_version.should eql("2.2.3-1") end @@ -122,11 +122,11 @@ Include = /etc/pacman.d/mirrorlist Include = /etc/pacman.d/mirrorlist PACMAN_CONF - ::File.stub!(:exists?).with("/etc/pacman.conf").and_return(true) - ::File.stub!(:read).with("/etc/pacman.conf").and_return(@pacman_conf) - @stdout.stub!(:each).and_yield("customrepo/nano 1.2.3-4"). + ::File.stub(:exists?).with("/etc/pacman.conf").and_return(true) + ::File.stub(:read).with("/etc/pacman.conf").and_return(@pacman_conf) + @stdout.stub(:each).and_yield("customrepo/nano 1.2.3-4"). and_yield(" My custom package") - @provider.stub!(:popen4).and_yield(@pid, @stdin, @stdout, @stderr).and_return(@status) + @provider.stub(:popen4).and_yield(@pid, @stdin, @stdout, @stderr).and_return(@status) @provider.load_current_resource @provider.candidate_version.should eql("1.2.3-4") @@ -139,12 +139,12 @@ PACMAN_CONF it "should not raise an exception if pacman succeeds" do @status.should_receive(:exitstatus).and_return(0) - lambda { @provider.load_current_resource }.should_not raise_error(Chef::Exceptions::Package) + lambda { @provider.load_current_resource }.should_not raise_error end it "should raise an exception if pacman does not return a candidate version" do - @stdout.stub!(:each).and_yield("") - @provider.stub!(:popen4).and_yield(@pid, @stdin, @stdout, @stderr).and_return(@status) + @stdout.stub(:each).and_yield("") + @provider.stub(:popen4).and_yield(@pid, @stdin, @stdout, @stderr).and_return(@status) lambda { @provider.candidate_version }.should raise_error(Chef::Exceptions::Package) end @@ -165,7 +165,7 @@ PACMAN_CONF @provider.should_receive(:run_command_with_systems_locale).with({ :command => "pacman --sync --noconfirm --noprogressbar --debug nano" }) - @new_resource.stub!(:options).and_return("--debug") + @new_resource.stub(:options).and_return("--debug") @provider.install_package("nano", "1.0") end @@ -190,7 +190,7 @@ PACMAN_CONF @provider.should_receive(:run_command_with_systems_locale).with({ :command => "pacman --remove --noconfirm --noprogressbar --debug nano" }) - @new_resource.stub!(:options).and_return("--debug") + @new_resource.stub(:options).and_return("--debug") @provider.remove_package("nano", "1.0") end diff --git a/spec/unit/provider/package/portage_spec.rb b/spec/unit/provider/package/portage_spec.rb index f44731b73a..6f22952da2 100644 --- a/spec/unit/provider/package/portage_spec.rb +++ b/spec/unit/provider/package/portage_spec.rb @@ -27,70 +27,70 @@ describe Chef::Provider::Package::Portage, "load_current_resource" do @current_resource = Chef::Resource::Package.new("dev-util/git") @provider = Chef::Provider::Package::Portage.new(@new_resource, @run_context) - Chef::Resource::Package.stub!(:new).and_return(@current_resource) + Chef::Resource::Package.stub(:new).and_return(@current_resource) end describe "when determining the current state of the package" do it "should create a current resource with the name of new_resource" do - ::Dir.stub!(:[]).with("/var/db/pkg/dev-util/git-*").and_return(["/var/db/pkg/dev-util/git-1.0.0"]) + ::Dir.stub(:[]).with("/var/db/pkg/dev-util/git-*").and_return(["/var/db/pkg/dev-util/git-1.0.0"]) Chef::Resource::Package.should_receive(:new).and_return(@current_resource) @provider.load_current_resource end it "should set the current resource package name to the new resource package name" do - ::Dir.stub!(:[]).with("/var/db/pkg/dev-util/git-*").and_return(["/var/db/pkg/dev-util/git-1.0.0"]) + ::Dir.stub(:[]).with("/var/db/pkg/dev-util/git-*").and_return(["/var/db/pkg/dev-util/git-1.0.0"]) @current_resource.should_receive(:package_name).with(@new_resource.package_name) @provider.load_current_resource end it "should return a current resource with the correct version if the package is found" do - ::Dir.stub!(:[]).with("/var/db/pkg/dev-util/git-*").and_return(["/var/db/pkg/dev-util/git-foobar-0.9", "/var/db/pkg/dev-util/git-1.0.0"]) + ::Dir.stub(:[]).with("/var/db/pkg/dev-util/git-*").and_return(["/var/db/pkg/dev-util/git-foobar-0.9", "/var/db/pkg/dev-util/git-1.0.0"]) @provider.load_current_resource @provider.current_resource.version.should == "1.0.0" end it "should return a current resource with the correct version if the package is found with revision" do - ::Dir.stub!(:[]).with("/var/db/pkg/dev-util/git-*").and_return(["/var/db/pkg/dev-util/git-1.0.0-r1"]) + ::Dir.stub(:[]).with("/var/db/pkg/dev-util/git-*").and_return(["/var/db/pkg/dev-util/git-1.0.0-r1"]) @provider.load_current_resource @provider.current_resource.version.should == "1.0.0-r1" end it "should return a current resource with a nil version if the package is not found" do - ::Dir.stub!(:[]).with("/var/db/pkg/dev-util/git-*").and_return(["/var/db/pkg/dev-util/notgit-1.0.0"]) + ::Dir.stub(:[]).with("/var/db/pkg/dev-util/git-*").and_return(["/var/db/pkg/dev-util/notgit-1.0.0"]) @provider.load_current_resource @provider.current_resource.version.should be_nil end it "should return a package name match from /var/db/pkg/* if a category isn't specified and a match is found" do - ::Dir.stub!(:[]).with("/var/db/pkg/*/git-*").and_return(["/var/db/pkg/dev-util/git-foobar-0.9", "/var/db/pkg/dev-util/git-1.0.0"]) + ::Dir.stub(:[]).with("/var/db/pkg/*/git-*").and_return(["/var/db/pkg/dev-util/git-foobar-0.9", "/var/db/pkg/dev-util/git-1.0.0"]) @provider = Chef::Provider::Package::Portage.new(@new_resource_without_category, @run_context) @provider.load_current_resource @provider.current_resource.version.should == "1.0.0" end it "should return a current resource with a nil version if a category isn't specified and a name match from /var/db/pkg/* is not found" do - ::Dir.stub!(:[]).with("/var/db/pkg/*/git-*").and_return(["/var/db/pkg/dev-util/notgit-1.0.0"]) + ::Dir.stub(:[]).with("/var/db/pkg/*/git-*").and_return(["/var/db/pkg/dev-util/notgit-1.0.0"]) @provider = Chef::Provider::Package::Portage.new(@new_resource_without_category, @run_context) @provider.load_current_resource @provider.current_resource.version.should be_nil end it "should throw an exception if a category isn't specified and multiple packages are found" do - ::Dir.stub!(:[]).with("/var/db/pkg/*/git-*").and_return(["/var/db/pkg/dev-util/git-1.0.0", "/var/db/pkg/funny-words/git-1.0.0"]) + ::Dir.stub(:[]).with("/var/db/pkg/*/git-*").and_return(["/var/db/pkg/dev-util/git-1.0.0", "/var/db/pkg/funny-words/git-1.0.0"]) @provider = Chef::Provider::Package::Portage.new(@new_resource_without_category, @run_context) lambda { @provider.load_current_resource }.should raise_error(Chef::Exceptions::Package) end it "should return a current resource with a nil version if a category is specified and multiple packages are found" do - ::Dir.stub!(:[]).with("/var/db/pkg/dev-util/git-*").and_return(["/var/db/pkg/dev-util/git-1.0.0", "/var/db/pkg/funny-words/git-1.0.0"]) + ::Dir.stub(:[]).with("/var/db/pkg/dev-util/git-*").and_return(["/var/db/pkg/dev-util/git-1.0.0", "/var/db/pkg/funny-words/git-1.0.0"]) @provider = Chef::Provider::Package::Portage.new(@new_resource, @run_context) @provider.load_current_resource @provider.current_resource.version.should be_nil end it "should return a current resource with a nil version if a category is not specified and multiple packages from the same category are found" do - ::Dir.stub!(:[]).with("/var/db/pkg/*/git-*").and_return(["/var/db/pkg/dev-util/git-1.0.0", "/var/db/pkg/dev-util/git-1.0.1"]) + ::Dir.stub(:[]).with("/var/db/pkg/*/git-*").and_return(["/var/db/pkg/dev-util/git-1.0.0", "/var/db/pkg/dev-util/git-1.0.1"]) @provider = Chef::Provider::Package::Portage.new(@new_resource_without_category, @run_context) @provider.load_current_resource @provider.current_resource.version.should be_nil @@ -107,8 +107,8 @@ describe Chef::Provider::Package::Portage, "load_current_resource" do end it "should throw an exception if the exitstatus is not 0" do - @status = mock("Status", :exitstatus => 1) - @provider.stub!(:popen4).and_return(@status) + @status = double("Status", :exitstatus => 1) + @provider.stub(:popen4).and_return(@status) lambda { @provider.candidate_version }.should raise_error(Chef::Exceptions::Package) end @@ -143,7 +143,7 @@ Searching... License: GPL-2 EOF - @status = mock("Status", :exitstatus => 0) + @status = double("Status", :exitstatus => 0) @provider.should_receive(:popen4).and_yield(nil, nil, StringIO.new(output), nil).and_return(@status) @provider.candidate_version.should == "1.6.0.6" end @@ -179,7 +179,7 @@ Searching... License: GPL-2 EOF - @status = mock("Status", :exitstatus => 0) + @status = double("Status", :exitstatus => 0) @provider = Chef::Provider::Package::Portage.new(@new_resource_without_category, @run_context) @provider.should_receive(:popen4).and_yield(nil, nil, StringIO.new(output), nil).and_return(@status) @provider.candidate_version.should == "1.6.0.6" @@ -224,7 +224,7 @@ Searching... License: GPL-2 EOF - @status = mock("Status", :exitstatus => 0) + @status = double("Status", :exitstatus => 0) @provider = Chef::Provider::Package::Portage.new(@new_resource_without_category, @run_context) @provider.should_receive(:popen4).and_yield(nil, nil, StringIO.new(output), nil).and_return(@status) lambda { @provider.candidate_version }.should raise_error(Chef::Exceptions::Package) @@ -269,7 +269,7 @@ Searching... License: GPL-2 EOF - @status = mock("Status", :exitstatus => 0) + @status = double("Status", :exitstatus => 0) @provider = Chef::Provider::Package::Portage.new(@new_resource, @run_context) @provider.should_receive(:popen4).and_yield(nil, nil, StringIO.new(output), nil).and_return(@status) @provider.candidate_version.should == "1.6.0.6" @@ -295,7 +295,7 @@ EOF @provider.should_receive(:run_command_with_systems_locale).with({ :command => "emerge -g --color n --nospinner --quiet --oneshot =dev-util/git-1.0.0" }) - @new_resource.stub!(:options).and_return("--oneshot") + @new_resource.stub(:options).and_return("--oneshot") @provider.install_package("dev-util/git", "1.0.0") end diff --git a/spec/unit/provider/package/rpm_spec.rb b/spec/unit/provider/package/rpm_spec.rb index 86327be42b..7126b06d66 100644 --- a/spec/unit/provider/package/rpm_spec.rb +++ b/spec/unit/provider/package/rpm_spec.rb @@ -29,26 +29,26 @@ describe Chef::Provider::Package::Rpm do @provider = Chef::Provider::Package::Rpm.new(@new_resource, @run_context) - @status = mock("Status", :exitstatus => 0) - ::File.stub!(:exists?).and_return(true) + @status = double("Status", :exitstatus => 0) + ::File.stub(:exists?).and_return(true) end describe "when determining the current state of the package" do it "should create a current resource with the name of new_resource" do - @provider.stub!(:popen4).and_return(@status) + @provider.stub(:popen4).and_return(@status) @provider.load_current_resource @provider.current_resource.name.should == "emacs" end it "should set the current reource package name to the new resource package name" do - @provider.stub!(:popen4).and_return(@status) + @provider.stub(:popen4).and_return(@status) @provider.load_current_resource @provider.current_resource.package_name.should == 'emacs' end it "should raise an exception if a source is supplied but not found" do - ::File.stub!(:exists?).and_return(false) + ::File.stub(:exists?).and_return(false) lambda { @provider.run_action(:any) }.should raise_error(Chef::Exceptions::Package) end @@ -76,8 +76,8 @@ describe Chef::Provider::Package::Rpm do end it "should raise an exception if rpm fails to run" do - status = mock("Status", :exitstatus => -1) - @provider.stub!(:popen4).and_return(status) + status = double("Status", :exitstatus => -1) + @provider.stub(:popen4).and_return(status) lambda { @provider.run_action(:any) }.should raise_error(Chef::Exceptions::Package) end end diff --git a/spec/unit/provider/package/rubygems_spec.rb b/spec/unit/provider/package/rubygems_spec.rb index 7d0567314a..d3cb9cf7fa 100644 --- a/spec/unit/provider/package/rubygems_spec.rb +++ b/spec/unit/provider/package/rubygems_spec.rb @@ -89,7 +89,7 @@ describe Chef::Provider::Package::Rubygems::CurrentGemEnvironment do it "finds a matching gem candidate version" do dep = Gem::Dependency.new('rspec', '>= 0') dep_installer = Gem::DependencyInstaller.new - @gem_env.stub!(:dependency_installer).and_return(dep_installer) + @gem_env.stub(:dependency_installer).and_return(dep_installer) latest = [[gemspec("rspec", Gem::Version.new("1.3.0")), "http://rubygems.org/"]] dep_installer.should_receive(:find_gems_with_sources).with(dep).and_return(latest) @gem_env.candidate_version_from_remote(Gem::Dependency.new('rspec', '>= 0')).should == Gem::Version.new('1.3.0') @@ -98,9 +98,9 @@ describe Chef::Provider::Package::Rubygems::CurrentGemEnvironment do it "finds a matching gem candidate version on rubygems 2.0.0+" do dep = Gem::Dependency.new('rspec', '>= 0') dep_installer = Gem::DependencyInstaller.new - @gem_env.stub!(:dependency_installer).and_return(dep_installer) - best_gem = mock("best gem match", :spec => gemspec("rspec", Gem::Version.new("1.3.0")), :source => "https://rubygems.org") - available_set = mock("Gem::AvailableSet test double") + @gem_env.stub(:dependency_installer).and_return(dep_installer) + best_gem = double("best gem match", :spec => gemspec("rspec", Gem::Version.new("1.3.0")), :source => "https://rubygems.org") + available_set = double("Gem::AvailableSet test double") available_set.should_receive(:pick_best!) available_set.should_receive(:set).and_return([best_gem]) dep_installer.should_receive(:find_gems_with_sources).with(dep).and_return(available_set) @@ -121,7 +121,7 @@ describe Chef::Provider::Package::Rubygems::CurrentGemEnvironment do Gem.const_set(:Format, Object.new) @remove_gem_format = true end - Gem::Package.stub!(:respond_to?).with(:open).and_return(false) + Gem::Package.stub(:respond_to?).with(:open).and_return(false) end after do @@ -131,7 +131,7 @@ describe Chef::Provider::Package::Rubygems::CurrentGemEnvironment do end it "finds a matching gem candidate version on rubygems 2.0+ with some rubygems 1.8 code loaded" do - package = mock("Gem::Package", :spec => "a gemspec from package") + package = double("Gem::Package", :spec => "a gemspec from package") Gem::Package.should_receive(:new).with("/path/to/package.gem").and_return(package) @gem_env.spec_from_file("/path/to/package.gem").should == "a gemspec from package" end @@ -142,7 +142,7 @@ describe Chef::Provider::Package::Rubygems::CurrentGemEnvironment do dep = Gem::Dependency.new('rspec', '>= 0') latest = [] dep_installer = Gem::DependencyInstaller.new - @gem_env.stub!(:dependency_installer).and_return(dep_installer) + @gem_env.stub(:dependency_installer).and_return(dep_installer) dep_installer.should_receive(:find_gems_with_sources).with(dep).and_return(latest) @gem_env.candidate_version_from_remote(Gem::Dependency.new('rspec', '>= 0')).should be_nil end @@ -159,7 +159,7 @@ describe Chef::Provider::Package::Rubygems::CurrentGemEnvironment do @gem_env.should_receive(:with_gem_sources).with('http://gems.example.com').and_yield dep_installer = Gem::DependencyInstaller.new - @gem_env.stub!(:dependency_installer).and_return(dep_installer) + @gem_env.stub(:dependency_installer).and_return(dep_installer) dep_installer.should_receive(:find_gems_with_sources).with(dep).and_return(latest) @gem_env.candidate_version_from_remote(Gem::Dependency.new('rspec', '>=0'), 'http://gems.example.com').should == Gem::Version.new('1.3.0') end @@ -180,14 +180,14 @@ describe Chef::Provider::Package::Rubygems::CurrentGemEnvironment do end it "uninstalls all versions of a gem" do - uninstaller = mock('gem uninstaller') + uninstaller = double('gem uninstaller') uninstaller.should_receive(:uninstall) @gem_env.should_receive(:uninstaller).with('rspec', :all => true).and_return(uninstaller) @gem_env.uninstall('rspec') end it "uninstalls a specific version of a gem" do - uninstaller = mock('gem uninstaller') + uninstaller = double('gem uninstaller') uninstaller.should_receive(:uninstall) @gem_env.should_receive(:uninstaller).with('rspec', :version => '1.2.3').and_return(uninstaller) @gem_env.uninstall('rspec', '1.2.3') @@ -230,7 +230,7 @@ describe Chef::Provider::Package::Rubygems::AlternateGemEnvironment do end it "builds the gems source index from the gem paths" do - @gem_env.stub!(:gem_paths).and_return(['/path/to/gems', '/another/path/to/gems']) + @gem_env.stub(:gem_paths).and_return(['/path/to/gems', '/another/path/to/gems']) if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.8.0') @gem_env.gem_specification Gem::Specification.dirs.should == [ '/path/to/gems/specifications', '/another/path/to/gems/specifications' ] @@ -244,17 +244,17 @@ describe Chef::Provider::Package::Rubygems::AlternateGemEnvironment do gems = [gemspec('rspec', Gem::Version.new('1.2.9')), gemspec('rspec', Gem::Version.new('1.3.0'))] rspec_dep = Gem::Dependency.new('rspec', nil) if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.8.0') - @gem_env.stub!(:gem_specification).and_return(Gem::Specification) + @gem_env.stub(:gem_specification).and_return(Gem::Specification) @gem_env.gem_specification.should_receive(:find_all_by_name).with(rspec_dep.name, rspec_dep.requirement).and_return(gems) else - @gem_env.stub!(:gem_source_index).and_return(Gem.source_index) + @gem_env.stub(:gem_source_index).and_return(Gem.source_index) @gem_env.gem_source_index.should_receive(:search).with(rspec_dep).and_return(gems) end @gem_env.installed_versions(Gem::Dependency.new('rspec', nil)).should == gems end it "determines the installed versions of gems from the source index (part2: the unmockening)" do - $stdout.stub!(:write) + $stdout.stub(:write) path_to_gem = if windows? `where gem`.split[1] else @@ -295,7 +295,7 @@ RubyGems Environment: - http://rubygems.org/ - http://gems.github.com/ JRUBY_GEM_ENV - @gem_env.should_receive(:shell_out!).with('/usr/weird/bin/gem env').and_return(mock('jruby_gem_env', :stdout => gem_env_out)) + @gem_env.should_receive(:shell_out!).with('/usr/weird/bin/gem env').and_return(double('jruby_gem_env', :stdout => gem_env_out)) expected = ['ruby', Gem::Platform.new('universal-java-1.6')] @gem_env.gem_platforms.should == expected # it should also cache the result @@ -337,7 +337,7 @@ RubyGems Environment: - http://rubygems.org/ - http://gems.github.com/ RBX_GEM_ENV - @gem_env.should_receive(:shell_out!).with('/usr/weird/bin/gem env').and_return(mock('rbx_gem_env', :stdout => gem_env_out)) + @gem_env.should_receive(:shell_out!).with('/usr/weird/bin/gem env').and_return(double('rbx_gem_env', :stdout => gem_env_out)) @gem_env.gem_platforms.should == Gem.platforms Chef::Provider::Package::Rubygems::AlternateGemEnvironment.platform_cache['/usr/weird/bin/gem'].should == Gem.platforms end @@ -367,7 +367,7 @@ describe Chef::Provider::Package::Rubygems do @run_context = Chef::RunContext.new(@node, {}, @events) # We choose detect omnibus via RbConfig::CONFIG['bindir'] in Chef::Provider::Package::Rubygems.new - RbConfig::CONFIG.stub!(:[]).with('bindir').and_return("/usr/bin/ruby") + RbConfig::CONFIG.stub(:[]).with('bindir').and_return("/usr/bin/ruby") @provider = Chef::Provider::Package::Rubygems.new(@new_resource, @run_context) end @@ -388,11 +388,11 @@ describe Chef::Provider::Package::Rubygems do it "searches for a gem binary when running on Omnibus on Unix" do platform_mock :unix do - RbConfig::CONFIG.stub!(:[]).with('bindir').and_return("/opt/chef/embedded/bin") - ENV.stub!(:[]).with('PATH').and_return("/usr/bin:/usr/sbin:/opt/chef/embedded/bin") - File.stub!(:exists?).with('/usr/bin/gem').and_return(false) - File.stub!(:exists?).with('/usr/sbin/gem').and_return(true) - File.stub!(:exists?).with('/opt/chef/embedded/bin/gem').and_return(true) # should not get here + RbConfig::CONFIG.stub(:[]).with('bindir').and_return("/opt/chef/embedded/bin") + ENV.stub(:[]).with('PATH').and_return("/usr/bin:/usr/sbin:/opt/chef/embedded/bin") + File.stub(:exists?).with('/usr/bin/gem').and_return(false) + File.stub(:exists?).with('/usr/sbin/gem').and_return(true) + File.stub(:exists?).with('/opt/chef/embedded/bin/gem').and_return(true) # should not get here provider = Chef::Provider::Package::Rubygems.new(@new_resource, @run_context) provider.gem_env.gem_binary_location.should == '/usr/sbin/gem' end @@ -400,13 +400,13 @@ describe Chef::Provider::Package::Rubygems do it "searches for a gem binary when running on Omnibus on Windows" do platform_mock :windows do - RbConfig::CONFIG.stub!(:[]).with('bindir').and_return("d:/opscode/chef/embedded/bin") - ENV.stub!(:[]).with('PATH').and_return('C:\windows\system32;C:\windows;C:\Ruby186\bin;d:\opscode\chef\embedded\bin') - File.stub!(:exists?).with('C:\\windows\\system32\\gem').and_return(false) - File.stub!(:exists?).with('C:\\windows\\gem').and_return(false) - File.stub!(:exists?).with('C:\\Ruby186\\bin\\gem').and_return(true) - File.stub!(:exists?).with('d:\\opscode\\chef\\bin\\gem').and_return(false) # should not get here - File.stub!(:exists?).with('d:\\opscode\\chef\\embedded\\bin\\gem').and_return(false) # should not get here + RbConfig::CONFIG.stub(:[]).with('bindir').and_return("d:/opscode/chef/embedded/bin") + ENV.stub(:[]).with('PATH').and_return('C:\windows\system32;C:\windows;C:\Ruby186\bin;d:\opscode\chef\embedded\bin') + File.stub(:exists?).with('C:\\windows\\system32\\gem').and_return(false) + File.stub(:exists?).with('C:\\windows\\gem').and_return(false) + File.stub(:exists?).with('C:\\Ruby186\\bin\\gem').and_return(true) + File.stub(:exists?).with('d:\\opscode\\chef\\bin\\gem').and_return(false) # should not get here + File.stub(:exists?).with('d:\\opscode\\chef\\embedded\\bin\\gem').and_return(false) # should not get here provider = Chef::Provider::Package::Rubygems.new(@new_resource, @run_context) provider.gem_env.gem_binary_location.should == 'C:\Ruby186\bin\gem' end @@ -475,7 +475,7 @@ describe Chef::Provider::Package::Rubygems do @current_resource = Chef::Resource::GemPackage.new('rspec-core') @provider.current_resource = @current_resource @gem_dep = Gem::Dependency.new('rspec-core', @spec_version) - @provider.stub!(:load_current_resource) + @provider.stub(:load_current_resource) end describe "in the current gem environment" do @@ -508,7 +508,7 @@ 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 - ::File.stub!(:exists?).and_return(true) + ::File.stub(:exists?).and_return(true) @new_resource.package_name('rspec-core') @provider.gem_env.should_receive(:install).with(@gem_dep, :sources => nil) @provider.action_install.should be_true diff --git a/spec/unit/provider/package/smartos_spec.rb b/spec/unit/provider/package/smartos_spec.rb index e5092f69d9..1c690acbf5 100644 --- a/spec/unit/provider/package/smartos_spec.rb +++ b/spec/unit/provider/package/smartos_spec.rb @@ -29,9 +29,9 @@ describe Chef::Provider::Package::SmartOS, "load_current_resource" do @current_resource = Chef::Resource::Package.new("varnish") - @status = mock("Status", :exitstatus => 0) + @status = double("Status", :exitstatus => 0) @provider = Chef::Provider::Package::SmartOS.new(@new_resource, @run_context) - Chef::Resource::Package.stub!(:new).and_return(@current_resource) + Chef::Resource::Package.stub(:new).and_return(@current_resource) @stdin = StringIO.new @stdout = "varnish-2.1.5nb2\n" @stderr = StringIO.new @@ -77,11 +77,11 @@ describe Chef::Provider::Package::SmartOS, "load_current_resource" do end it "should lookup the candidate_version if the variable is not already set" do - search = mock() + search = double() search.should_receive(:each_line). and_yield("something-varnish-1.1.1 something varnish like\n"). and_yield("varnish-2.3.4 actual varnish\n") - @shell_out = mock('shell_out!', :stdout => search) + @shell_out = double('shell_out!', :stdout => search) @provider.should_receive(:shell_out!).with('/opt/local/bin/pkgin se varnish', :env => nil, :returns => [0,1]).and_return(@shell_out) @provider.candidate_version.should == "2.3.4" end diff --git a/spec/unit/provider/package/solaris_spec.rb b/spec/unit/provider/package/solaris_spec.rb index dd7cea2aaa..086e327cce 100644 --- a/spec/unit/provider/package/solaris_spec.rb +++ b/spec/unit/provider/package/solaris_spec.rb @@ -27,7 +27,7 @@ describe Chef::Provider::Package::Solaris do @new_resource.source("/tmp/bash.pkg") @provider = Chef::Provider::Package::Solaris.new(@new_resource, @run_context) - ::File.stub!(:exists?).and_return(true) + ::File.stub(:exists?).and_return(true) end describe "assessing the current package status" do @@ -46,24 +46,24 @@ INSTDATE: Nov 04 2009 01:02 HOTLINE: Please contact your local service provider PKGINFO - @status = mock("Status", :exitstatus => 0) + @status = double("Status", :exitstatus => 0) end it "should create a current resource with the name of new_resource" do - @provider.stub!(:popen4).and_return(@status) + @provider.stub(:popen4).and_return(@status) @provider.load_current_resource @provider.current_resource.name.should == "SUNWbash" end it "should set the current reource package name to the new resource package name" do - @provider.stub!(:popen4).and_return(@status) + @provider.stub(:popen4).and_return(@status) @provider.load_current_resource @provider.current_resource.package_name.should == "SUNWbash" end it "should raise an exception if a source is supplied but not found" do - @provider.stub!(:popen4).and_return(@status) - ::File.stub!(:exists?).and_return(false) + @provider.stub(:popen4).and_return(@status) + ::File.stub(:exists?).and_return(false) @provider.define_resource_requirements @provider.load_current_resource lambda { @provider.process_resource_requirements }.should raise_error(Chef::Exceptions::Package) @@ -93,13 +93,13 @@ PKGINFO it "should raise an exception if the source is not set but we are installing" do @new_resource = Chef::Resource::Package.new("SUNWbash") @provider = Chef::Provider::Package::Solaris.new(@new_resource, @run_context) - @provider.stub!(:popen4).and_return(@status) + @provider.stub(:popen4).and_return(@status) lambda { @provider.run_action(:install) }.should raise_error(Chef::Exceptions::Package) end it "should raise an exception if pkginfo fails to run" do - @status = mock("Status", :exitstatus => -1) - @provider.stub!(:popen4).and_return(@status) + @status = double("Status", :exitstatus => -1) + @provider.stub(:popen4).and_return(@status) lambda { @provider.load_current_resource }.should raise_error(Chef::Exceptions::Package) end @@ -120,15 +120,15 @@ PKGINFO end it "should lookup the candidate_version if the variable is not already set" do - @status = mock("Status", :exitstatus => 0) - @provider.stub!(:popen4).and_return(@status) + @status = double("Status", :exitstatus => 0) + @provider.stub(:popen4).and_return(@status) @provider.should_receive(:popen4) @provider.candidate_version end it "should throw and exception if the exitstatus is not 0" do - @status = mock("Status", :exitstatus => 1) - @provider.stub!(:popen4).and_return(@status) + @status = double("Status", :exitstatus => 1) + @provider.stub(:popen4).and_return(@status) lambda { @provider.candidate_version }.should raise_error(Chef::Exceptions::Package) end @@ -153,7 +153,7 @@ PKGINFO end it "should run pkgadd -n -a /tmp/myadmin -d with the package options -a /tmp/myadmin" do - @new_resource.stub!(:options).and_return("-a /tmp/myadmin") + @new_resource.stub(:options).and_return("-a /tmp/myadmin") @provider.should_receive(:run_command_with_systems_locale).with({ :command => "pkgadd -n -a /tmp/myadmin -d /tmp/bash.pkg all" }) @@ -170,7 +170,7 @@ PKGINFO end it "should run pkgrm -n -a /tmp/myadmin with options -a /tmp/myadmin" do - @new_resource.stub!(:options).and_return("-a /tmp/myadmin") + @new_resource.stub(:options).and_return("-a /tmp/myadmin") @provider.should_receive(:run_command_with_systems_locale).with({ :command => "pkgrm -n -a /tmp/myadmin SUNWbash" }) diff --git a/spec/unit/provider/package/yum_spec.rb b/spec/unit/provider/package/yum_spec.rb index d2674f523d..adbcd86722 100644 --- a/spec/unit/provider/package/yum_spec.rb +++ b/spec/unit/provider/package/yum_spec.rb @@ -24,8 +24,8 @@ describe Chef::Provider::Package::Yum do @events = Chef::EventDispatch::Dispatcher.new @run_context = Chef::RunContext.new(@node, {}, @events) @new_resource = Chef::Resource::Package.new('cups') - @status = mock("Status", :exitstatus => 0) - @yum_cache = mock( + @status = double("Status", :exitstatus => 0) + @yum_cache = double( 'Chef::Provider::Yum::YumCache', :reload_installed => true, :reset => true, @@ -37,9 +37,9 @@ describe Chef::Provider::Package::Yum do :package_repository => "base", :disable_extra_repo_control => true ) - Chef::Provider::Package::Yum::YumCache.stub!(:instance).and_return(@yum_cache) + Chef::Provider::Package::Yum::YumCache.stub(:instance).and_return(@yum_cache) @provider = Chef::Provider::Package::Yum.new(@new_resource, @run_context) - @pid = mock("PID") + @pid = double("PID") end describe "when loading the current system state" do @@ -54,7 +54,7 @@ describe Chef::Provider::Package::Yum do end it "should set the installed version to nil on the current resource if no installed package" do - @yum_cache.stub!(:installed_version).and_return(nil) + @yum_cache.stub(:installed_version).and_return(nil) @provider.load_current_resource @provider.current_resource.version.should be_nil end @@ -76,14 +76,14 @@ describe Chef::Provider::Package::Yum do describe "when arch in package_name" do it "should set the arch if no existing package_name is found and new_package_name+new_arch is available" do @new_resource = Chef::Resource::YumPackage.new('testing.noarch') - @yum_cache = mock( + @yum_cache = double( 'Chef::Provider::Yum::YumCache' ) - @yum_cache.stub!(:installed_version) do |package_name, arch| + @yum_cache.stub(:installed_version) do |package_name, arch| # nothing installed for package_name/new_package_name nil end - @yum_cache.stub!(:candidate_version) do |package_name, arch| + @yum_cache.stub(:candidate_version) do |package_name, arch| if package_name == "testing.noarch" || package_name == "testing.more.noarch" nil # candidate for new_package_name @@ -91,9 +91,9 @@ describe Chef::Provider::Package::Yum do "1.1" end end - @yum_cache.stub!(:package_available?).and_return(true) - @yum_cache.stub!(:disable_extra_repo_control).and_return(true) - Chef::Provider::Package::Yum::YumCache.stub!(:instance).and_return(@yum_cache) + @yum_cache.stub(:package_available?).and_return(true) + @yum_cache.stub(:disable_extra_repo_control).and_return(true) + Chef::Provider::Package::Yum::YumCache.stub(:instance).and_return(@yum_cache) @provider = Chef::Provider::Package::Yum.new(@new_resource, @run_context) @provider.load_current_resource @provider.new_resource.package_name.should == "testing" @@ -110,10 +110,10 @@ describe Chef::Provider::Package::Yum do it "should not set the arch when an existing package_name is found" do @new_resource = Chef::Resource::YumPackage.new('testing.beta3') - @yum_cache = mock( + @yum_cache = double( 'Chef::Provider::Yum::YumCache' ) - @yum_cache.stub!(:installed_version) do |package_name, arch| + @yum_cache.stub(:installed_version) do |package_name, arch| # installed for package_name if package_name == "testing.beta3" || package_name == "testing.beta3.more" "1.1" @@ -121,13 +121,13 @@ describe Chef::Provider::Package::Yum do nil end end - @yum_cache.stub!(:candidate_version) do |package_name, arch| + @yum_cache.stub(:candidate_version) do |package_name, arch| # no candidate for package_name/new_package_name nil end - @yum_cache.stub!(:package_available?).and_return(true) - @yum_cache.stub!(:disable_extra_repo_control).and_return(true) - Chef::Provider::Package::Yum::YumCache.stub!(:instance).and_return(@yum_cache) + @yum_cache.stub(:package_available?).and_return(true) + @yum_cache.stub(:disable_extra_repo_control).and_return(true) + Chef::Provider::Package::Yum::YumCache.stub(:instance).and_return(@yum_cache) @provider = Chef::Provider::Package::Yum.new(@new_resource, @run_context) # annoying side effect of the fun stub'ing above @provider.load_current_resource @@ -145,20 +145,20 @@ describe Chef::Provider::Package::Yum do it "should not set the arch when no existing package_name or new_package_name+new_arch is found" do @new_resource = Chef::Resource::YumPackage.new('testing.beta3') - @yum_cache = mock( + @yum_cache = double( 'Chef::Provider::Yum::YumCache' ) - @yum_cache.stub!(:installed_version) do |package_name, arch| + @yum_cache.stub(:installed_version) do |package_name, arch| # nothing installed for package_name/new_package_name nil end - @yum_cache.stub!(:candidate_version) do |package_name, arch| + @yum_cache.stub(:candidate_version) do |package_name, arch| # no candidate for package_name/new_package_name nil end - @yum_cache.stub!(:package_available?).and_return(true) - @yum_cache.stub!(:disable_extra_repo_control).and_return(true) - Chef::Provider::Package::Yum::YumCache.stub!(:instance).and_return(@yum_cache) + @yum_cache.stub(:package_available?).and_return(true) + @yum_cache.stub(:disable_extra_repo_control).and_return(true) + Chef::Provider::Package::Yum::YumCache.stub(:instance).and_return(@yum_cache) @provider = Chef::Provider::Package::Yum.new(@new_resource, @run_context) @provider.load_current_resource @provider.new_resource.package_name.should == "testing.beta3" @@ -176,14 +176,14 @@ describe Chef::Provider::Package::Yum do it "should ensure it doesn't clobber an existing arch if passed" do @new_resource = Chef::Resource::YumPackage.new('testing.i386') @new_resource.arch("x86_64") - @yum_cache = mock( + @yum_cache = double( 'Chef::Provider::Yum::YumCache' ) - @yum_cache.stub!(:installed_version) do |package_name, arch| + @yum_cache.stub(:installed_version) do |package_name, arch| # nothing installed for package_name/new_package_name nil end - @yum_cache.stub!(:candidate_version) do |package_name, arch| + @yum_cache.stub(:candidate_version) do |package_name, arch| if package_name == "testing.noarch" nil # candidate for new_package_name @@ -191,9 +191,9 @@ describe Chef::Provider::Package::Yum do "1.1" end end.and_return("something") - @yum_cache.stub!(:package_available?).and_return(true) - @yum_cache.stub!(:disable_extra_repo_control).and_return(true) - Chef::Provider::Package::Yum::YumCache.stub!(:instance).and_return(@yum_cache) + @yum_cache.stub(:package_available?).and_return(true) + @yum_cache.stub(:disable_extra_repo_control).and_return(true) + Chef::Provider::Package::Yum::YumCache.stub(:instance).and_return(@yum_cache) @provider = Chef::Provider::Package::Yum.new(@new_resource, @run_context) @provider.load_current_resource @provider.new_resource.package_name.should == "testing.i386" @@ -202,37 +202,37 @@ describe Chef::Provider::Package::Yum do end it "should flush the cache if :before is true" do - @new_resource.stub!(:flush_cache).and_return({:after => false, :before => true}) + @new_resource.stub(:flush_cache).and_return({:after => false, :before => true}) @yum_cache.should_receive(:reload).once @provider.load_current_resource end it "should flush the cache if :before is false" do - @new_resource.stub!(:flush_cache).and_return({:after => false, :before => false}) + @new_resource.stub(:flush_cache).and_return({:after => false, :before => false}) @yum_cache.should_not_receive(:reload) @provider.load_current_resource end it "should detect --enablerepo or --disablerepo when passed among options, collect them preserving order and notify the yum cache" do - @new_resource.stub!(:options).and_return("--stuff --enablerepo=foo --otherthings --disablerepo=a,b,c --enablerepo=bar") + @new_resource.stub(:options).and_return("--stuff --enablerepo=foo --otherthings --disablerepo=a,b,c --enablerepo=bar") @yum_cache.should_receive(:enable_extra_repo_control).with("--enablerepo=foo --disablerepo=a,b,c --enablerepo=bar") @provider.load_current_resource end it "should let the yum cache know extra repos are disabled if --enablerepo or --disablerepo aren't among options" do - @new_resource.stub!(:options).and_return("--stuff --otherthings") + @new_resource.stub(:options).and_return("--stuff --otherthings") @yum_cache.should_receive(:disable_extra_repo_control) @provider.load_current_resource end it "should let the yum cache know extra repos are disabled if options aren't set" do - @new_resource.stub!(:options).and_return(nil) + @new_resource.stub(:options).and_return(nil) @yum_cache.should_receive(:disable_extra_repo_control) @provider.load_current_resource end it "should search provides if package name can't be found then set package_name to match" do - @yum_cache = mock( + @yum_cache = double( 'Chef::Provider::Yum::YumCache', :reload_installed => true, :reset => true, @@ -242,7 +242,7 @@ describe Chef::Provider::Package::Yum do :version_available? => true, :disable_extra_repo_control => true ) - Chef::Provider::Package::Yum::YumCache.stub!(:instance).and_return(@yum_cache) + Chef::Provider::Package::Yum::YumCache.stub(:instance).and_return(@yum_cache) pkg = Chef::Provider::Package::Yum::RPMPackage.new("test-package", "1.2.4-11.18.el5", "x86_64", []) @yum_cache.should_receive(:packages_from_require).and_return([pkg]) @provider = Chef::Provider::Package::Yum.new(@new_resource, @run_context) @@ -251,7 +251,7 @@ describe Chef::Provider::Package::Yum do end it "should search provides if package name can't be found, warn about multiple matches, but use the first one" do - @yum_cache = mock( + @yum_cache = double( 'Chef::Provider::Yum::YumCache', :reload_installed => true, :reset => true, @@ -261,7 +261,7 @@ describe Chef::Provider::Package::Yum do :version_available? => true, :disable_extra_repo_control => true ) - Chef::Provider::Package::Yum::YumCache.stub!(:instance).and_return(@yum_cache) + Chef::Provider::Package::Yum::YumCache.stub(:instance).and_return(@yum_cache) pkg_x = Chef::Provider::Package::Yum::RPMPackage.new("test-package-x", "1.2.4-11.18.el5", "x86_64", []) pkg_y = Chef::Provider::Package::Yum::RPMPackage.new("test-package-y", "1.2.6-11.3.el5", "i386", []) @yum_cache.should_receive(:packages_from_require).and_return([pkg_x, pkg_y]) @@ -272,7 +272,7 @@ describe Chef::Provider::Package::Yum do end it "should search provides if no package is available - if no match in installed provides then load the complete set" do - @yum_cache = mock( + @yum_cache = double( 'Chef::Provider::Yum::YumCache', :reload_installed => true, :reset => true, @@ -282,7 +282,7 @@ describe Chef::Provider::Package::Yum do :version_available? => true, :disable_extra_repo_control => true ) - Chef::Provider::Package::Yum::YumCache.stub!(:instance).and_return(@yum_cache) + Chef::Provider::Package::Yum::YumCache.stub(:instance).and_return(@yum_cache) @yum_cache.should_receive(:packages_from_require).twice.and_return([]) @yum_cache.should_receive(:reload_provides) @provider = Chef::Provider::Package::Yum.new(@new_resource, @run_context) @@ -290,7 +290,7 @@ describe Chef::Provider::Package::Yum do end it "should search provides if no package is available and not load the complete set if action is :remove or :purge" do - @yum_cache = mock( + @yum_cache = double( 'Chef::Provider::Yum::YumCache', :reload_installed => true, :reset => true, @@ -300,7 +300,7 @@ describe Chef::Provider::Package::Yum do :version_available? => true, :disable_extra_repo_control => true ) - Chef::Provider::Package::Yum::YumCache.stub!(:instance).and_return(@yum_cache) + Chef::Provider::Package::Yum::YumCache.stub(:instance).and_return(@yum_cache) @provider = Chef::Provider::Package::Yum.new(@new_resource, @run_context) @yum_cache.should_receive(:packages_from_require).once.and_return([]) @yum_cache.should_not_receive(:reload_provides) @@ -313,7 +313,7 @@ describe Chef::Provider::Package::Yum do end it "should search provides if no package is available - if no match in provides leave the name intact" do - @yum_cache = mock( + @yum_cache = double( 'Chef::Provider::Yum::YumCache', :reload_provides => true, :reload_installed => true, @@ -324,7 +324,7 @@ describe Chef::Provider::Package::Yum do :version_available? => true, :disable_extra_repo_control => true ) - Chef::Provider::Package::Yum::YumCache.stub!(:instance).and_return(@yum_cache) + Chef::Provider::Package::Yum::YumCache.stub(:instance).and_return(@yum_cache) @yum_cache.should_receive(:packages_from_require).twice.and_return([]) @provider = Chef::Provider::Package::Yum.new(@new_resource, @run_context) @provider.load_current_resource @@ -335,7 +335,7 @@ describe Chef::Provider::Package::Yum do describe "when installing a package" do it "should run yum install with the package name and version" do @provider.load_current_resource - Chef::Provider::Package::Yum::RPMUtils.stub!(:rpmvercmp).and_return(-1) + Chef::Provider::Package::Yum::RPMUtils.stub(:rpmvercmp).and_return(-1) @provider.should_receive(:yum_command).with( "yum -d0 -e0 -y install emacs-1.0" ) @@ -343,7 +343,7 @@ describe Chef::Provider::Package::Yum do end it "should run yum localinstall if given a path to an rpm" do - @new_resource.stub!(:source).and_return("/tmp/emacs-21.4-20.el5.i386.rpm") + @new_resource.stub(:source).and_return("/tmp/emacs-21.4-20.el5.i386.rpm") @provider.should_receive(:yum_command).with( "yum -d0 -e0 -y localinstall /tmp/emacs-21.4-20.el5.i386.rpm" ) @@ -352,7 +352,7 @@ describe Chef::Provider::Package::Yum do it "should run yum localinstall if given a path to an rpm as the package" do @new_resource = Chef::Resource::Package.new("/tmp/emacs-21.4-20.el5.i386.rpm") - ::File.stub!(:exists?).and_return(true) + ::File.stub(:exists?).and_return(true) @provider = Chef::Provider::Package::Yum.new(@new_resource, @run_context) @new_resource.source.should == "/tmp/emacs-21.4-20.el5.i386.rpm" @provider.should_receive(:yum_command).with( @@ -363,8 +363,8 @@ describe Chef::Provider::Package::Yum do it "should run yum install with the package name, version and arch" do @provider.load_current_resource - @new_resource.stub!(:arch).and_return("i386") - Chef::Provider::Package::Yum::RPMUtils.stub!(:rpmvercmp).and_return(-1) + @new_resource.stub(:arch).and_return("i386") + Chef::Provider::Package::Yum::RPMUtils.stub(:rpmvercmp).and_return(-1) @provider.should_receive(:yum_command).with( "yum -d0 -e0 -y install emacs-21.4-20.el5.i386" ) @@ -374,8 +374,8 @@ describe Chef::Provider::Package::Yum do it "installs the package with the options given in the resource" do @provider.load_current_resource @provider.candidate_version = '11' - @new_resource.stub!(:options).and_return("--disablerepo epmd") - Chef::Provider::Package::Yum::RPMUtils.stub!(:rpmvercmp).and_return(-1) + @new_resource.stub(:options).and_return("--disablerepo epmd") + Chef::Provider::Package::Yum::RPMUtils.stub(:rpmvercmp).and_return(-1) @provider.should_receive(:yum_command).with( "yum -d0 -e0 -y --disablerepo epmd install cups-11" ) @@ -383,7 +383,7 @@ describe Chef::Provider::Package::Yum do end it "should raise an exception if the package is not available" do - @yum_cache = mock( + @yum_cache = double( 'Chef::Provider::Yum::YumCache', :reload_from_cache => true, :reset => true, @@ -393,14 +393,14 @@ describe Chef::Provider::Package::Yum do :version_available? => nil, :disable_extra_repo_control => true ) - Chef::Provider::Package::Yum::YumCache.stub!(:instance).and_return(@yum_cache) + Chef::Provider::Package::Yum::YumCache.stub(:instance).and_return(@yum_cache) @provider = Chef::Provider::Package::Yum.new(@new_resource, @run_context) lambda { @provider.install_package("lolcats", "0.99") }.should raise_error(Chef::Exceptions::Package, %r{Version .* not found}) end it "should raise an exception if candidate version is older than the installed version and allow_downgrade is false" do - @new_resource.stub!(:allow_downgrade).and_return(false) - @yum_cache = mock( + @new_resource.stub(:allow_downgrade).and_return(false) + @yum_cache = double( 'Chef::Provider::Yum::YumCache', :reload_installed => true, :reset => true, @@ -411,14 +411,14 @@ describe Chef::Provider::Package::Yum do :allow_multi_install => [ "kernel" ], :disable_extra_repo_control => true ) - Chef::Provider::Package::Yum::YumCache.stub!(:instance).and_return(@yum_cache) + Chef::Provider::Package::Yum::YumCache.stub(:instance).and_return(@yum_cache) @provider = Chef::Provider::Package::Yum.new(@new_resource, @run_context) @provider.load_current_resource lambda { @provider.install_package("cups", "1.2.4-11.15.el5") }.should raise_error(Chef::Exceptions::Package, %r{is newer than candidate package}) end it "should not raise an exception if candidate version is older than the installed version and the package is list in yum's installonlypkg option" do - @yum_cache = mock( + @yum_cache = double( 'Chef::Provider::Yum::YumCache', :reload_installed => true, :reset => true, @@ -430,7 +430,7 @@ describe Chef::Provider::Package::Yum do :package_repository => "base", :disable_extra_repo_control => true ) - Chef::Provider::Package::Yum::YumCache.stub!(:instance).and_return(@yum_cache) + Chef::Provider::Package::Yum::YumCache.stub(:instance).and_return(@yum_cache) @provider = Chef::Provider::Package::Yum.new(@new_resource, @run_context) @provider.load_current_resource @provider.should_receive(:yum_command).with( @@ -440,8 +440,8 @@ describe Chef::Provider::Package::Yum do end it "should run yum downgrade if candidate version is older than the installed version and allow_downgrade is true" do - @new_resource.stub!(:allow_downgrade).and_return(true) - @yum_cache = mock( + @new_resource.stub(:allow_downgrade).and_return(true) + @yum_cache = double( 'Chef::Provider::Yum::YumCache', :reload_installed => true, :reset => true, @@ -453,7 +453,7 @@ describe Chef::Provider::Package::Yum do :package_repository => "base", :disable_extra_repo_control => true ) - Chef::Provider::Package::Yum::YumCache.stub!(:instance).and_return(@yum_cache) + Chef::Provider::Package::Yum::YumCache.stub(:instance).and_return(@yum_cache) @provider = Chef::Provider::Package::Yum.new(@new_resource, @run_context) @provider.load_current_resource @provider.should_receive(:yum_command).with( @@ -463,9 +463,9 @@ describe Chef::Provider::Package::Yum do end it "should run yum install then flush the cache if :after is true" do - @new_resource.stub!(:flush_cache).and_return({:after => true, :before => false}) + @new_resource.stub(:flush_cache).and_return({:after => true, :before => false}) @provider.load_current_resource - Chef::Provider::Package::Yum::RPMUtils.stub!(:rpmvercmp).and_return(-1) + Chef::Provider::Package::Yum::RPMUtils.stub(:rpmvercmp).and_return(-1) @provider.should_receive(:yum_command).with( "yum -d0 -e0 -y install emacs-1.0" ) @@ -474,9 +474,9 @@ describe Chef::Provider::Package::Yum do end it "should run yum install then not flush the cache if :after is false" do - @new_resource.stub!(:flush_cache).and_return({:after => false, :before => false}) + @new_resource.stub(:flush_cache).and_return({:after => false, :before => false}) @provider.load_current_resource - Chef::Provider::Package::Yum::RPMUtils.stub!(:rpmvercmp).and_return(-1) + Chef::Provider::Package::Yum::RPMUtils.stub(:rpmvercmp).and_return(-1) @provider.should_receive(:yum_command).with( "yum -d0 -e0 -y install emacs-1.0" ) @@ -489,7 +489,7 @@ describe Chef::Provider::Package::Yum do it "should run yum install if the package is installed and a version is given" do @provider.load_current_resource @provider.candidate_version = '11' - Chef::Provider::Package::Yum::RPMUtils.stub!(:rpmvercmp).and_return(-1) + Chef::Provider::Package::Yum::RPMUtils.stub(:rpmvercmp).and_return(-1) @provider.should_receive(:yum_command).with( "yum -d0 -e0 -y install cups-11" ) @@ -500,7 +500,7 @@ describe Chef::Provider::Package::Yum do @provider.load_current_resource @current_resource = Chef::Resource::Package.new('cups') @provider.candidate_version = '11' - Chef::Provider::Package::Yum::RPMUtils.stub!(:rpmvercmp).and_return(-1) + Chef::Provider::Package::Yum::RPMUtils.stub(:rpmvercmp).and_return(-1) @provider.should_receive(:yum_command).with( "yum -d0 -e0 -y install cups-11" ) @@ -508,7 +508,7 @@ describe Chef::Provider::Package::Yum do end it "should raise an exception if candidate version is older than the installed version" do - @yum_cache = mock( + @yum_cache = double( 'Chef::Provider::Yum::YumCache', :reload_installed => true, :reset => true, @@ -519,7 +519,7 @@ describe Chef::Provider::Package::Yum do :allow_multi_install => [ "kernel" ], :disable_extra_repo_control => true ) - Chef::Provider::Package::Yum::YumCache.stub!(:instance).and_return(@yum_cache) + Chef::Provider::Package::Yum::YumCache.stub(:instance).and_return(@yum_cache) @provider = Chef::Provider::Package::Yum.new(@new_resource, @run_context) @provider.load_current_resource lambda { @provider.upgrade_package("cups", "1.2.4-11.15.el5") }.should raise_error(Chef::Exceptions::Package, %r{is newer than candidate package}) @@ -527,7 +527,7 @@ describe Chef::Provider::Package::Yum do # Test our little workaround, some crossover into Chef::Provider::Package territory it "should call action_upgrade in the parent if the current resource version is nil" do - @yum_cache.stub!(:installed_version).and_return(nil) + @yum_cache.stub(:installed_version).and_return(nil) @provider.load_current_resource @current_resource = Chef::Resource::Package.new('cups') @provider.candidate_version = '11' @@ -558,7 +558,7 @@ describe Chef::Provider::Package::Yum do end it "should not call action_upgrade in the parent if the candidate is older" do - @yum_cache.stub!(:installed_version).and_return("12") + @yum_cache.stub(:installed_version).and_return("12") @provider.load_current_resource @current_resource = Chef::Resource::Package.new('cups') @provider.candidate_version = '11' @@ -576,7 +576,7 @@ describe Chef::Provider::Package::Yum do end it "should run yum remove with the package name and arch" do - @new_resource.stub!(:arch).and_return("x86_64") + @new_resource.stub(:arch).and_return("x86_64") @provider.should_receive(:yum_command).with( "yum -d0 -e0 -y remove emacs-1.0.x86_64" ) @@ -595,8 +595,8 @@ describe Chef::Provider::Package::Yum do describe "when running yum" do it "should run yum once if it exits with a return code of 0" do - @status = mock("Status", :exitstatus => 0) - @provider.stub!(:output_of_command).and_return([@status, "", ""]) + @status = double("Status", :exitstatus => 0) + @provider.stub(:output_of_command).and_return([@status, "", ""]) @provider.should_receive(:output_of_command).once.with( "yum -d0 -e0 -y install emacs-1.0", {:timeout => Chef::Config[:yum_timeout]} @@ -605,8 +605,8 @@ describe Chef::Provider::Package::Yum do end it "should run yum once if it exits with a return code > 0 and no scriptlet failures" do - @status = mock("Status", :exitstatus => 2) - @provider.stub!(:output_of_command).and_return([@status, "failure failure", "problem problem"]) + @status = double("Status", :exitstatus => 2) + @provider.stub(:output_of_command).and_return([@status, "failure failure", "problem problem"]) @provider.should_receive(:output_of_command).once.with( "yum -d0 -e0 -y install emacs-1.0", {:timeout => Chef::Config[:yum_timeout]} @@ -615,8 +615,8 @@ describe Chef::Provider::Package::Yum do end it "should run yum once if it exits with a return code of 1 and %pre scriptlet failures" do - @status = mock("Status", :exitstatus => 1) - @provider.stub!(:output_of_command).and_return([@status, "error: %pre(demo-1-1.el5.centos.x86_64) scriptlet failed, exit status 2", ""]) + @status = double("Status", :exitstatus => 1) + @provider.stub(:output_of_command).and_return([@status, "error: %pre(demo-1-1.el5.centos.x86_64) scriptlet failed, exit status 2", ""]) @provider.should_receive(:output_of_command).once.with( "yum -d0 -e0 -y install emacs-1.0", {:timeout => Chef::Config[:yum_timeout]} @@ -626,8 +626,8 @@ describe Chef::Provider::Package::Yum do end it "should run yum twice if it exits with a return code of 1 and %post scriptlet failures" do - @status = mock("Status", :exitstatus => 1) - @provider.stub!(:output_of_command).and_return([@status, "error: %post(demo-1-1.el5.centos.x86_64) scriptlet failed, exit status 2", ""]) + @status = double("Status", :exitstatus => 1) + @provider.stub(:output_of_command).and_return([@status, "error: %post(demo-1-1.el5.centos.x86_64) scriptlet failed, exit status 2", ""]) @provider.should_receive(:output_of_command).twice.with( "yum -d0 -e0 -y install emacs-1.0", {:timeout => Chef::Config[:yum_timeout]} @@ -1543,8 +1543,8 @@ describe Chef::Provider::Package::Yum::YumCache do end before(:each) do - @stdin = mock("STDIN", :nil_object => true) - @stdout = mock("STDOUT", :nil_object => true) + @stdin = double("STDIN", :nil_object => true) + @stdout = double("STDOUT", :nil_object => true) @stdout_good = <<EOF [option installonlypkgs] kernel kernel-bigmem kernel-enterprise @@ -1586,13 +1586,13 @@ yum-dump Config Error: File contains no section headers. file: file://///etc/yum.repos.d/CentOS-Base.repo, line: 12 'qeqwewe\n' EOF - @status = mock("Status", :exitstatus => 0, :stdin => @stdin, :stdout => @stdout_good, :stderr => @stderr) + @status = double("Status", :exitstatus => 0, :stdin => @stdin, :stdout => @stdout_good, :stderr => @stderr) # new singleton each time Chef::Provider::Package::Yum::YumCache.reset_instance @yc = Chef::Provider::Package::Yum::YumCache.instance # load valid data - @yc.stub!(:shell_out!).and_return(@status) + @yc.stub(:shell_out!).and_return(@status) end describe "initialize" do @@ -1642,29 +1642,29 @@ EOF end it "should warn about invalid data with too many separators" do - @status = mock("Status", :exitstatus => 0, :stdin => @stdin, :stdout => @stdout_bad_separators, :stderr => @stderr) - @yc.stub!(:shell_out!).and_return(@status) + @status = double("Status", :exitstatus => 0, :stdin => @stdin, :stdout => @stdout_bad_separators, :stderr => @stderr) + @yc.stub(:shell_out!).and_return(@status) Chef::Log.should_receive(:warn).exactly(3).times.with(%r{Problem parsing}) @yc.refresh end it "should warn about invalid data with an incorrect type" do - @status = mock("Status", :exitstatus => 0, :stdin => @stdin, :stdout => @stdout_bad_type, :stderr => @stderr) - @yc.stub!(:shell_out!).and_return(@status) + @status = double("Status", :exitstatus => 0, :stdin => @stdin, :stdout => @stdout_bad_type, :stderr => @stderr) + @yc.stub(:shell_out!).and_return(@status) Chef::Log.should_receive(:warn).exactly(2).times.with(%r{Problem parsing}) @yc.refresh end it "should warn about no output from yum-dump.py" do - @status = mock("Status", :exitstatus => 0, :stdin => @stdin, :stdout => @stdout_no_output, :stderr => @stderr) - @yc.stub!(:shell_out!).and_return(@status) + @status = double("Status", :exitstatus => 0, :stdin => @stdin, :stdout => @stdout_no_output, :stderr => @stderr) + @yc.stub(:shell_out!).and_return(@status) Chef::Log.should_receive(:warn).exactly(1).times.with(%r{no output from yum-dump.py}) @yc.refresh end it "should raise exception yum-dump.py exits with a non zero status" do - @status = mock("Status", :exitstatus => 1, :stdin => @stdin, :stdout => @stdout_no_output, :stderr => @stderr) - @yc.stub!(:shell_out!).and_return(@status) + @status = double("Status", :exitstatus => 1, :stdin => @stdin, :stdout => @stdout_no_output, :stderr => @stderr) + @yc.stub(:shell_out!).and_return(@status) lambda { @yc.refresh}.should raise_error(Chef::Exceptions::Package, %r{CentOS-Base.repo, line: 12}) end @@ -1690,8 +1690,8 @@ EOF describe "installed_version" do it "should take one or two arguments" do - lambda { @yc.installed_version("zip") }.should_not raise_error(ArgumentError) - lambda { @yc.installed_version("zip", "i386") }.should_not raise_error(ArgumentError) + lambda { @yc.installed_version("zip") }.should_not raise_error + lambda { @yc.installed_version("zip", "i386") }.should_not raise_error lambda { @yc.installed_version("zip", "i386", "extra") }.should raise_error(ArgumentError) end @@ -1714,8 +1714,8 @@ EOF describe "available_version" do it "should take one or two arguments" do - lambda { @yc.available_version("zisofs-tools") }.should_not raise_error(ArgumentError) - lambda { @yc.available_version("zisofs-tools", "i386") }.should_not raise_error(ArgumentError) + lambda { @yc.available_version("zisofs-tools") }.should_not raise_error + lambda { @yc.available_version("zisofs-tools", "i386") }.should_not raise_error lambda { @yc.available_version("zisofs-tools", "i386", "extra") }.should raise_error(ArgumentError) end @@ -1739,8 +1739,8 @@ EOF describe "version_available?" do it "should take two or three arguments" do lambda { @yc.version_available?("zisofs-tools") }.should raise_error(ArgumentError) - lambda { @yc.version_available?("zisofs-tools", "1.0.6-3.2.2") }.should_not raise_error(ArgumentError) - lambda { @yc.version_available?("zisofs-tools", "1.0.6-3.2.2", "x86_64") }.should_not raise_error(ArgumentError) + lambda { @yc.version_available?("zisofs-tools", "1.0.6-3.2.2") }.should_not raise_error + lambda { @yc.version_available?("zisofs-tools", "1.0.6-3.2.2", "x86_64") }.should_not raise_error end it "should return true if our package-version-arch is available" do @@ -1768,8 +1768,8 @@ EOF describe "package_repository" do it "should take two or three arguments" do lambda { @yc.package_repository("zisofs-tools") }.should raise_error(ArgumentError) - lambda { @yc.package_repository("zisofs-tools", "1.0.6-3.2.2") }.should_not raise_error(ArgumentError) - lambda { @yc.package_repository("zisofs-tools", "1.0.6-3.2.2", "x86_64") }.should_not raise_error(ArgumentError) + lambda { @yc.package_repository("zisofs-tools", "1.0.6-3.2.2") }.should_not raise_error + lambda { @yc.package_repository("zisofs-tools", "1.0.6-3.2.2", "x86_64") }.should_not raise_error end it "should return repoid for package-version-arch" do diff --git a/spec/unit/provider/package/zypper_spec.rb b/spec/unit/provider/package/zypper_spec.rb index cf0193993d..c437631309 100644 --- a/spec/unit/provider/package/zypper_spec.rb +++ b/spec/unit/provider/package/zypper_spec.rb @@ -27,15 +27,15 @@ describe Chef::Provider::Package::Zypper do @current_resource = Chef::Resource::Package.new("cups") - @status = mock("Status", :exitstatus => 0) + @status = double("Status", :exitstatus => 0) @provider = Chef::Provider::Package::Zypper.new(@new_resource, @run_context) - Chef::Resource::Package.stub!(:new).and_return(@current_resource) - @provider.stub!(:popen4).and_return(@status) + Chef::Resource::Package.stub(:new).and_return(@current_resource) + @provider.stub(:popen4).and_return(@status) @stderr = StringIO.new @stdout = StringIO.new - @pid = mock("PID") - @provider.stub!(:`).and_return("2.0") + @pid = double("PID") + @provider.stub(:`).and_return("2.0") end describe "when loading the current package state" do @@ -55,14 +55,14 @@ describe Chef::Provider::Package::Zypper do end it "should set the installed version to nil on the current resource if zypper info installed version is (none)" do - @provider.stub!(:popen4).and_yield(@pid, @stdin, @stdout, @stderr).and_return(@status) + @provider.stub(:popen4).and_yield(@pid, @stdin, @stdout, @stderr).and_return(@status) @current_resource.should_receive(:version).with(nil).and_return(true) @provider.load_current_resource end it "should set the installed version if zypper info has one" do @stdout = StringIO.new("Version: 1.0\nInstalled: Yes\n") - @provider.stub!(:popen4).and_yield(@pid, @stdin, @stdout, @stderr).and_return(@status) + @provider.stub(:popen4).and_yield(@pid, @stdin, @stdout, @stderr).and_return(@status) @current_resource.should_receive(:version).with("1.0").and_return(true) @provider.load_current_resource end @@ -70,7 +70,7 @@ describe Chef::Provider::Package::Zypper do it "should set the candidate version if zypper info has one" do @stdout = StringIO.new("Version: 1.0\nInstalled: No\nStatus: out-of-date (version 0.9 installed)") - @provider.stub!(:popen4).and_yield(@pid, @stdin, @stdout, @stderr).and_return(@status) + @provider.stub(:popen4).and_yield(@pid, @stdin, @stdout, @stderr).and_return(@status) @provider.load_current_resource @provider.candidate_version.should eql("1.0") end @@ -82,7 +82,7 @@ describe Chef::Provider::Package::Zypper do it "should not raise an exception if zypper info succeeds" do @status.should_receive(:exitstatus).and_return(0) - lambda { @provider.load_current_resource }.should_not raise_error(Chef::Exceptions::Package) + lambda { @provider.load_current_resource }.should_not raise_error end it "should return the current resouce" do @@ -191,7 +191,7 @@ describe Chef::Provider::Package::Zypper do describe "on an older zypper" do before(:each) do - @provider.stub!(:`).and_return("0.11.6") + @provider.stub(:`).and_return("0.11.6") end describe "install_package" do diff --git a/spec/unit/provider/package_spec.rb b/spec/unit/provider/package_spec.rb index f80eed17bd..33b4f8186a 100644 --- a/spec/unit/provider/package_spec.rb +++ b/spec/unit/provider/package_spec.rb @@ -34,7 +34,7 @@ describe Chef::Provider::Package do describe "when installing a package" do before(:each) do @provider.current_resource = @current_resource - @provider.stub!(:install_package).and_return(true) + @provider.stub(:install_package).and_return(true) end it "should raise a Chef::Exceptions::Package if no version is specified, and no candidate is available" do @@ -81,7 +81,7 @@ describe Chef::Provider::Package do it "should install the package at the version specified if a different version is installed" do @new_resource.version("1.0") - @current_resource.stub!(:version).and_return("0.99") + @current_resource.stub(:version).and_return("0.99") @provider.should_receive(:install_package).with( @new_resource.name, @new_resource.version @@ -107,7 +107,7 @@ describe Chef::Provider::Package do it "should call the candidate_version accessor only once if the package is already installed and no version is specified" do @current_resource.version("1.0") - @provider.stub!(:candidate_version).and_return("1.0") + @provider.stub(:candidate_version).and_return("1.0") @provider.run_action(:install) end @@ -126,7 +126,7 @@ describe Chef::Provider::Package do describe "when upgrading the package" do before(:each) do - @provider.stub!(:upgrade_package).and_return(true) + @provider.stub(:upgrade_package).and_return(true) end it "should upgrade the package if the current version is not the candidate version" do @@ -151,14 +151,14 @@ describe Chef::Provider::Package do end it "should print the word 'uninstalled' if there was no original version" do - @current_resource.stub!(:version).and_return(nil) + @current_resource.stub(:version).and_return(nil) Chef::Log.should_receive(:info).with("package[emacs] upgraded from uninstalled to 1.0") @provider.run_action(:upgrade) @new_resource.should be_updated_by_last_action end it "should raise a Chef::Exceptions::Package if current version and candidate are nil" do - @current_resource.stub!(:version).and_return(nil) + @current_resource.stub(:version).and_return(nil) @provider.candidate_version = nil lambda { @provider.run_action(:upgrade) }.should raise_error(Chef::Exceptions::Package) end @@ -174,7 +174,7 @@ describe Chef::Provider::Package do describe "When removing the package" do before(:each) do - @provider.stub!(:remove_package).and_return(true) + @provider.stub(:remove_package).and_return(true) @current_resource.version '1.4.2' end @@ -204,7 +204,7 @@ describe Chef::Provider::Package do it "should not remove the package if it is not installed" do @provider.should_not_receive(:remove_package) - @current_resource.stub!(:version).and_return(nil) + @current_resource.stub(:version).and_return(nil) @provider.run_action(:remove) @new_resource.should_not be_updated_by_last_action end @@ -218,7 +218,7 @@ describe Chef::Provider::Package do describe "When purging the package" do before(:each) do - @provider.stub!(:purge_package).and_return(true) + @provider.stub(:purge_package).and_return(true) @current_resource.version '1.4.2' end @@ -264,15 +264,15 @@ describe Chef::Provider::Package do describe "when reconfiguring the package" do before(:each) do - @provider.stub!(:reconfig_package).and_return(true) + @provider.stub(:reconfig_package).and_return(true) end it "should info log, reconfigure the package and update the resource" do - @current_resource.stub!(:version).and_return('1.0') - @new_resource.stub!(:response_file).and_return(true) + @current_resource.stub(:version).and_return('1.0') + @new_resource.stub(:response_file).and_return(true) @provider.should_receive(:get_preseed_file).and_return('/var/cache/preseed-test') - @provider.stub!(:preseed_package).and_return(true) - @provider.stub!(:reconfig_package).and_return(true) + @provider.stub(:preseed_package).and_return(true) + @provider.stub(:reconfig_package).and_return(true) Chef::Log.should_receive(:info).with("package[emacs] reconfigured") @provider.should_receive(:reconfig_package) @provider.run_action(:reconfig) @@ -281,7 +281,7 @@ describe Chef::Provider::Package do end it "should debug log and not reconfigure the package if the package is not installed" do - @current_resource.stub!(:version).and_return(nil) + @current_resource.stub(:version).and_return(nil) Chef::Log.should_receive(:debug).with("package[emacs] is NOT installed - nothing to do") @provider.should_not_receive(:reconfig_package) @provider.run_action(:reconfig) @@ -289,8 +289,8 @@ describe Chef::Provider::Package do end it "should debug log and not reconfigure the package if no response_file is given" do - @current_resource.stub!(:version).and_return('1.0') - @new_resource.stub!(:response_file).and_return(nil) + @current_resource.stub(:version).and_return('1.0') + @new_resource.stub(:response_file).and_return(nil) Chef::Log.should_receive(:debug).with("package[emacs] no response_file provided - nothing to do") @provider.should_not_receive(:reconfig_package) @provider.run_action(:reconfig) @@ -298,10 +298,10 @@ describe Chef::Provider::Package do end it "should debug log and not reconfigure the package if the response_file has not changed" do - @current_resource.stub!(:version).and_return('1.0') - @new_resource.stub!(:response_file).and_return(true) + @current_resource.stub(:version).and_return('1.0') + @new_resource.stub(:response_file).and_return(true) @provider.should_receive(:get_preseed_file).and_return(false) - @provider.stub!(:preseed_package).and_return(false) + @provider.stub(:preseed_package).and_return(false) Chef::Log.should_receive(:debug).with("package[emacs] preseeding has not changed - nothing to do") @provider.should_not_receive(:reconfig_package) @provider.run_action(:reconfig) @@ -362,7 +362,7 @@ describe Chef::Provider::Package do end it "sets the preseed resource's runcontext to its own run context" do - Chef::FileCache.stub!(:create_cache_path).and_return("/tmp/preseed/java") + Chef::FileCache.stub(:create_cache_path).and_return("/tmp/preseed/java") @provider.preseed_resource('java', '6').run_context.should_not be_nil @provider.preseed_resource('java', '6').run_context.should equal(@provider.run_context) end diff --git a/spec/unit/provider/registry_key_spec.rb b/spec/unit/provider/registry_key_spec.rb index 2f6f8179e6..f88d4c0a87 100644 --- a/spec/unit/provider/registry_key_spec.rb +++ b/spec/unit/provider/registry_key_spec.rb @@ -38,9 +38,9 @@ describe Chef::Provider::RegistryKey do @provider = Chef::Provider::RegistryKey.new(@new_resource, @run_context) - @provider.stub!(:running_on_windows!).and_return(true) + @provider.stub(:running_on_windows!).and_return(true) @double_registry = double(Chef::Win32::Registry) - @provider.stub!(:registry).and_return(@double_registry) + @provider.stub(:registry).and_return(@double_registry) end describe "when first created" do diff --git a/spec/unit/provider/remote_file/content_spec.rb b/spec/unit/provider/remote_file/content_spec.rb index 36ecfe1c8d..0f311dc0ec 100644 --- a/spec/unit/provider/remote_file/content_spec.rb +++ b/spec/unit/provider/remote_file/content_spec.rb @@ -36,7 +36,7 @@ describe Chef::Provider::RemoteFile::Content do r end - let(:run_context) { mock("Chef::RunContext") } + let(:run_context) { double("Chef::RunContext") } # # subject @@ -47,8 +47,8 @@ describe Chef::Provider::RemoteFile::Content do describe "when the checksum of the current_resource matches the checksum set on the resource" do before do - new_resource.stub!(:checksum).and_return("0fd012fdc96e96f8f7cf2046522a54aed0ce470224513e45da6bc1a17a4924aa") - current_resource.stub!(:checksum).and_return("0fd012fdc96e96f8f7cf2046522a54aed0ce470224513e45da6bc1a17a4924aa") + new_resource.stub(:checksum).and_return("0fd012fdc96e96f8f7cf2046522a54aed0ce470224513e45da6bc1a17a4924aa") + current_resource.stub(:checksum).and_return("0fd012fdc96e96f8f7cf2046522a54aed0ce470224513e45da6bc1a17a4924aa") end it "should return nil for the tempfile" do @@ -62,8 +62,8 @@ describe Chef::Provider::RemoteFile::Content do describe "when the checksum of the current_resource is a partial match for the checksum set on the resource" do before do - new_resource.stub!(:checksum).and_return("0fd012fd") - current_resource.stub!(:checksum).and_return("0fd012fdc96e96f8f7cf2046522a54aed0ce470224513e45da6bc1a17a4924aa") + new_resource.stub(:checksum).and_return("0fd012fd") + current_resource.stub(:checksum).and_return("0fd012fdc96e96f8f7cf2046522a54aed0ce470224513e45da6bc1a17a4924aa") end it "should return nil for the tempfile" do @@ -78,13 +78,13 @@ describe Chef::Provider::RemoteFile::Content do shared_examples_for "the resource needs fetching" do before do # FIXME: test one or the other nil, test both not nil and not equal, abuse the regexp a little - @uri = mock("URI") + @uri = double("URI") URI.should_receive(:parse).with(new_resource.source[0]).and_return(@uri) end describe "when the fetcher returns nil for the tempfile" do before do - http_fetcher = mock("Chef::Provider::RemoteFile::HTTP", :fetch => nil) + http_fetcher = double("Chef::Provider::RemoteFile::HTTP", :fetch => nil) Chef::Provider::RemoteFile::Fetcher.should_receive(:for_resource).with(@uri, new_resource, current_resource).and_return(http_fetcher) end @@ -96,8 +96,8 @@ describe Chef::Provider::RemoteFile::Content do describe "when the fetcher returns a valid tempfile" do let(:mtime) { Time.now } - let(:tempfile) { mock("Tempfile") } - let(:http_fetcher) { mock("Chef::Provider::RemoteFile::HTTP", :fetch => tempfile) } + let(:tempfile) { double("Tempfile") } + let(:http_fetcher) { double("Chef::Provider::RemoteFile::HTTP", :fetch => tempfile) } before do Chef::Provider::RemoteFile::Fetcher.should_receive(:for_resource).with(@uri, new_resource, current_resource).and_return(http_fetcher) @@ -119,24 +119,24 @@ describe Chef::Provider::RemoteFile::Content do describe "when the current_resource checksum is nil" do before do - new_resource.stub!(:checksum).and_return("fd012fd") - current_resource.stub!(:checksum).and_return(nil) + new_resource.stub(:checksum).and_return("fd012fd") + current_resource.stub(:checksum).and_return(nil) end it_behaves_like "the resource needs fetching" end describe "when the new_resource checksum is nil" do before do - new_resource.stub!(:checksum).and_return(nil) - current_resource.stub!(:checksum).and_return("0fd012fdc96e96f8f7cf2046522a54aed0ce470224513e45da6bc1a17a4924aa") + new_resource.stub(:checksum).and_return(nil) + current_resource.stub(:checksum).and_return("0fd012fdc96e96f8f7cf2046522a54aed0ce470224513e45da6bc1a17a4924aa") end it_behaves_like "the resource needs fetching" end describe "when the checksums are a partial match, but not to the leading portion" do before do - new_resource.stub!(:checksum).and_return("fd012fd") - current_resource.stub!(:checksum).and_return("0fd012fdc96e96f8f7cf2046522a54aed0ce470224513e45da6bc1a17a4924aa") + new_resource.stub(:checksum).and_return("fd012fd") + current_resource.stub(:checksum).and_return("0fd012fdc96e96f8f7cf2046522a54aed0ce470224513e45da6bc1a17a4924aa") end it_behaves_like "the resource needs fetching" end @@ -144,11 +144,11 @@ describe Chef::Provider::RemoteFile::Content do describe "when the fetcher throws an exception" do before do - new_resource.stub!(:checksum).and_return(nil) - current_resource.stub!(:checksum).and_return(nil) - @uri = mock("URI") + new_resource.stub(:checksum).and_return(nil) + current_resource.stub(:checksum).and_return(nil) + @uri = double("URI") URI.should_receive(:parse).with(new_resource.source[0]).and_return(@uri) - http_fetcher = mock("Chef::Provider::RemoteFile::HTTP") + http_fetcher = double("Chef::Provider::RemoteFile::HTTP") http_fetcher.should_receive(:fetch).and_raise(Errno::ECONNREFUSED) Chef::Provider::RemoteFile::Fetcher.should_receive(:for_resource).with(@uri, new_resource, current_resource).and_return(http_fetcher) end @@ -162,22 +162,22 @@ describe Chef::Provider::RemoteFile::Content do let(:source) { [ "http://opscode.com/seattle.txt", "http://opscode.com/nyc.txt" ] } before do - new_resource.stub!(:checksum).and_return(nil) - current_resource.stub!(:checksum).and_return(nil) - @uri0 = mock("URI0") - @uri1 = mock("URI1") + new_resource.stub(:checksum).and_return(nil) + current_resource.stub(:checksum).and_return(nil) + @uri0 = double("URI0") + @uri1 = double("URI1") URI.should_receive(:parse).with(new_resource.source[0]).and_return(@uri0) URI.should_receive(:parse).with(new_resource.source[1]).and_return(@uri1) - @http_fetcher_throws_exception = mock("Chef::Provider::RemoteFile::HTTP") + @http_fetcher_throws_exception = double("Chef::Provider::RemoteFile::HTTP") @http_fetcher_throws_exception.should_receive(:fetch).at_least(:once).and_raise(Errno::ECONNREFUSED) Chef::Provider::RemoteFile::Fetcher.should_receive(:for_resource).with(@uri0, new_resource, current_resource).and_return(@http_fetcher_throws_exception) end describe "when the second url succeeds" do before do - @tempfile = mock("Tempfile") + @tempfile = double("Tempfile") mtime = Time.now - http_fetcher_works = mock("Chef::Provider::RemoteFile::HTTP", :fetch => @tempfile) + http_fetcher_works = double("Chef::Provider::RemoteFile::HTTP", :fetch => @tempfile) Chef::Provider::RemoteFile::Fetcher.should_receive(:for_resource).with(@uri1, new_resource, current_resource).and_return(http_fetcher_works) end @@ -205,14 +205,14 @@ describe Chef::Provider::RemoteFile::Content do describe "when there is an array of sources and the first succeeds" do let(:source) { [ "http://opscode.com/seattle.txt", "http://opscode.com/nyc.txt" ] } before do - new_resource.stub!(:checksum).and_return(nil) - current_resource.stub!(:checksum).and_return(nil) - @uri0 = mock("URI0") + new_resource.stub(:checksum).and_return(nil) + current_resource.stub(:checksum).and_return(nil) + @uri0 = double("URI0") URI.should_receive(:parse).with(new_resource.source[0]).and_return(@uri0) URI.should_not_receive(:parse).with(new_resource.source[1]) - @tempfile = mock("Tempfile") + @tempfile = double("Tempfile") mtime = Time.now - http_fetcher_works = mock("Chef::Provider::RemoteFile::HTTP", :fetch => @tempfile) + http_fetcher_works = double("Chef::Provider::RemoteFile::HTTP", :fetch => @tempfile) Chef::Provider::RemoteFile::Fetcher.should_receive(:for_resource).with(@uri0, new_resource, current_resource).and_return(http_fetcher_works) end diff --git a/spec/unit/provider/remote_file/fetcher_spec.rb b/spec/unit/provider/remote_file/fetcher_spec.rb index 68802fb83c..b5594b50e6 100644 --- a/spec/unit/provider/remote_file/fetcher_spec.rb +++ b/spec/unit/provider/remote_file/fetcher_spec.rb @@ -20,12 +20,12 @@ require 'spec_helper' describe Chef::Provider::RemoteFile::Fetcher do - let(:current_resource) { mock("current resource") } - let(:new_resource) { mock("new resource") } - let(:fetcher_instance) { mock("fetcher") } + let(:current_resource) { double("current resource") } + let(:new_resource) { double("new resource") } + let(:fetcher_instance) { double("fetcher") } describe "when passed an http url" do - let(:uri) { mock("uri", :scheme => "http" ) } + let(:uri) { double("uri", :scheme => "http" ) } before do Chef::Provider::RemoteFile::HTTP.should_receive(:new).and_return(fetcher_instance) end @@ -35,7 +35,7 @@ describe Chef::Provider::RemoteFile::Fetcher do end describe "when passed an https url" do - let(:uri) { mock("uri", :scheme => "https" ) } + let(:uri) { double("uri", :scheme => "https" ) } before do Chef::Provider::RemoteFile::HTTP.should_receive(:new).and_return(fetcher_instance) end @@ -45,7 +45,7 @@ describe Chef::Provider::RemoteFile::Fetcher do end describe "when passed an ftp url" do - let(:uri) { mock("uri", :scheme => "ftp" ) } + let(:uri) { double("uri", :scheme => "ftp" ) } before do Chef::Provider::RemoteFile::FTP.should_receive(:new).and_return(fetcher_instance) end @@ -55,7 +55,7 @@ describe Chef::Provider::RemoteFile::Fetcher do end describe "when passed a file url" do - let(:uri) { mock("uri", :scheme => "file" ) } + let(:uri) { double("uri", :scheme => "file" ) } before do Chef::Provider::RemoteFile::LocalFile.should_receive(:new).and_return(fetcher_instance) end @@ -65,7 +65,7 @@ describe Chef::Provider::RemoteFile::Fetcher do end describe "when passed a url we do not recognize" do - let(:uri) { mock("uri", :scheme => "xyzzy" ) } + let(:uri) { double("uri", :scheme => "xyzzy" ) } it "throws an ArgumentError exception" do lambda { described_class.for_resource(uri, new_resource, current_resource) }.should raise_error(ArgumentError) end diff --git a/spec/unit/provider/remote_file/ftp_spec.rb b/spec/unit/provider/remote_file/ftp_spec.rb index 8dd1ef248e..b393912ef9 100644 --- a/spec/unit/provider/remote_file/ftp_spec.rb +++ b/spec/unit/provider/remote_file/ftp_spec.rb @@ -38,14 +38,14 @@ describe Chef::Provider::RemoteFile::FTP do end let(:ftp) do - ftp = mock(Net::FTP, { }) - ftp.stub!(:connect) - ftp.stub!(:login) - ftp.stub!(:voidcmd) - ftp.stub!(:mtime).and_return(Time.now) - ftp.stub!(:getbinaryfile) - ftp.stub!(:close) - ftp.stub!(:passive=) + ftp = double(Net::FTP, { }) + ftp.stub(:connect) + ftp.stub(:login) + ftp.stub(:voidcmd) + ftp.stub(:mtime).and_return(Time.now) + ftp.stub(:getbinaryfile) + ftp.stub(:close) + ftp.stub(:passive=) ftp end @@ -60,8 +60,8 @@ describe Chef::Provider::RemoteFile::FTP do let(:uri) { URI.parse("ftp://opscode.com/seattle.txt") } before(:each) do - Net::FTP.stub!(:new).with().and_return(ftp) - Tempfile.stub!(:new).and_return(tempfile) + Net::FTP.stub(:new).with().and_return(ftp) + Tempfile.stub(:new).and_return(tempfile) end describe "when first created" do diff --git a/spec/unit/provider/remote_file/http_spec.rb b/spec/unit/provider/remote_file/http_spec.rb index e763a60e6f..951d9f0a05 100644 --- a/spec/unit/provider/remote_file/http_spec.rb +++ b/spec/unit/provider/remote_file/http_spec.rb @@ -159,14 +159,14 @@ describe Chef::Provider::RemoteFile::HTTP do let(:tempfile_path) { "/tmp/chef-mock-tempfile-abc123" } - let(:tempfile) { mock(Tempfile, :path => tempfile_path, :close => nil) } + let(:tempfile) { double(Tempfile, :path => tempfile_path, :close => nil) } let(:last_response) { {} } let(:rest) do - rest = mock(Chef::HTTP::Simple) - rest.stub!(:streaming_request).and_return(tempfile) - rest.stub!(:last_response).and_return(last_response) + rest = double(Chef::HTTP::Simple) + rest.stub(:streaming_request).and_return(tempfile) + rest.stub(:last_response).and_return(last_response) rest end diff --git a/spec/unit/provider/remote_file/local_file_spec.rb b/spec/unit/provider/remote_file/local_file_spec.rb index 00634f50eb..0020a03210 100644 --- a/spec/unit/provider/remote_file/local_file_spec.rb +++ b/spec/unit/provider/remote_file/local_file_spec.rb @@ -40,8 +40,8 @@ describe Chef::Provider::RemoteFile::LocalFile do describe "when fetching the object" do - let(:tempfile) { mock("Tempfile", :path => "/tmp/foo/bar/nyan.png", :close => nil) } - let(:chef_tempfile) { mock("Chef::FileContentManagement::Tempfile", :tempfile => tempfile) } + let(:tempfile) { double("Tempfile", :path => "/tmp/foo/bar/nyan.png", :close => nil) } + let(:chef_tempfile) { double("Chef::FileContentManagement::Tempfile", :tempfile => tempfile) } before do current_resource.source("file:///nyan_cat.png") diff --git a/spec/unit/provider/remote_file_spec.rb b/spec/unit/provider/remote_file_spec.rb index 4562083e7e..3fa3866743 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 = mock('Chef::Provider::File::Content::RemoteFile') + content = double('Chef::Provider::File::Content::RemoteFile') end let(:node) { double('Chef::Node') } diff --git a/spec/unit/provider/route_spec.rb b/spec/unit/provider/route_spec.rb index 863f12641c..2a6d48c79e 100644 --- a/spec/unit/provider/route_spec.rb +++ b/spec/unit/provider/route_spec.rb @@ -55,13 +55,13 @@ describe Chef::Provider::Route do routing_table = "Iface Destination Gateway Flags RefCnt Use Metric Mask MTU Window IRTT\n" + "eth0 0064A8C0 0984A8C0 0003 0 0 0 00FFFFFF 0 0 0\n" route_file = StringIO.new(routing_table) - File.stub!(:open).with("/proc/net/route", "r").and_return(route_file) + File.stub(:open).with("/proc/net/route", "r").and_return(route_file) end it "should set is_running to false when a route is not detected" do resource = Chef::Resource::Route.new('10.10.10.0/24') - resource.stub!(:gateway).and_return("10.0.0.1") - resource.stub!(:device).and_return("eth0") + resource.stub(:gateway).and_return("10.0.0.1") + resource.stub(:device).and_return("eth0") provider = Chef::Provider::Route.new(resource, @run_context) provider.load_current_resource @@ -70,8 +70,8 @@ describe Chef::Provider::Route do it "should detect existing routes and set is_running attribute correctly" do resource = Chef::Resource::Route.new('192.168.100.0/24') - resource.stub!(:gateway).and_return("192.168.132.9") - resource.stub!(:device).and_return("eth0") + resource.stub(:gateway).and_return("192.168.132.9") + resource.stub(:device).and_return("eth0") provider = Chef::Provider::Route.new(resource, @run_context) provider.load_current_resource @@ -80,8 +80,8 @@ describe Chef::Provider::Route do it "should use gateway value when matching routes" do resource = Chef::Resource::Route.new('192.168.100.0/24') - resource.stub!(:gateway).and_return("10.10.10.10") - resource.stub!(:device).and_return("eth0") + resource.stub(:gateway).and_return("10.10.10.10") + resource.stub(:device).and_return("eth0") provider = Chef::Provider::Route.new(resource, @run_context) provider.load_current_resource @@ -92,8 +92,8 @@ describe Chef::Provider::Route do describe Chef::Provider::Route, "action_add" do it "should add the route if it does not exist" do - @provider.stub!(:run_command).and_return(true) - @current_resource.stub!(:gateway).and_return(nil) + @provider.stub(:run_command).and_return(true) + @current_resource.stub(:gateway).and_return(nil) @provider.should_receive(:generate_command).once.with(:add) @provider.should_receive(:generate_config) @provider.run_action(:add) @@ -101,8 +101,8 @@ describe Chef::Provider::Route do end it "should not add the route if it exists" do - @provider.stub!(:run_command).and_return(true) - @provider.stub!(:is_running).and_return(true) + @provider.stub(:run_command).and_return(true) + @provider.stub(:is_running).and_return(true) @provider.should_not_receive(:generate_command).with(:add) @provider.should_receive(:generate_config) @provider.run_action(:add) @@ -116,7 +116,7 @@ describe Chef::Provider::Route do File.should_receive(:new).and_return(route_file) @resource_add = Chef::Resource::Route.new('192.168.1.0/24 via 192.168.0.1') @run_context.resource_collection << @resource_add - @provider.stub!(:run_command).and_return(true) + @provider.stub(:run_command).and_return(true) @resource_add.action(:add) @provider.run_action(:add) @@ -127,16 +127,16 @@ describe Chef::Provider::Route do describe Chef::Provider::Route, "action_delete" do it "should delete the route if it exists" do - @provider.stub!(:run_command).and_return(true) + @provider.stub(:run_command).and_return(true) @provider.should_receive(:generate_command).once.with(:delete) - @provider.stub!(:is_running).and_return(true) + @provider.stub(:is_running).and_return(true) @provider.run_action(:delete) @new_resource.should be_updated end it "should not delete the route if it does not exist" do - @current_resource.stub!(:gateway).and_return(nil) - @provider.stub!(:run_command).and_return(true) + @current_resource.stub(:gateway).and_return(nil) + @provider.stub(:run_command).and_return(true) @provider.should_not_receive(:generate_command).with(:add) @provider.run_action(:delete) @new_resource.should_not be_updated @@ -145,12 +145,12 @@ describe Chef::Provider::Route do describe Chef::Provider::Route, "generate_command for action_add" do it "should include a netmask when a one is specified" do - @new_resource.stub!(:netmask).and_return('255.255.0.0') + @new_resource.stub(:netmask).and_return('255.255.0.0') @provider.generate_command(:add).should match(/\/\d{1,2}\s/) end it "should not include a netmask when a one is specified" do - @new_resource.stub!(:netmask).and_return(nil) + @new_resource.stub(:netmask).and_return(nil) @provider.generate_command(:add).should_not match(/\/\d{1,2}\s/) end @@ -159,19 +159,19 @@ describe Chef::Provider::Route do end it "should not include ' via $gateway ' when a gateway is not specified" do - @new_resource.stub!(:gateway).and_return(nil) + @new_resource.stub(:gateway).and_return(nil) @provider.generate_command(:add).should_not match(/\svia\s#{Regexp.escape(@new_resource.gateway.to_s)}\s/) end end describe Chef::Provider::Route, "generate_command for action_delete" do it "should include a netmask when a one is specified" do - @new_resource.stub!(:netmask).and_return('255.255.0.0') + @new_resource.stub(:netmask).and_return('255.255.0.0') @provider.generate_command(:delete).should match(/\/\d{1,2}\s/) end it "should not include a netmask when a one is specified" do - @new_resource.stub!(:netmask).and_return(nil) + @new_resource.stub(:netmask).and_return(nil) @provider.generate_command(:delete).should_not match(/\/\d{1,2}\s/) end @@ -180,14 +180,14 @@ describe Chef::Provider::Route do end it "should not include ' via $gateway ' when a gateway is not specified" do - @new_resource.stub!(:gateway).and_return(nil) + @new_resource.stub(:gateway).and_return(nil) @provider.generate_command(:delete).should_not match(/\svia\s#{Regexp.escape(@new_resource.gateway.to_s)}\s/) end end describe Chef::Provider::Route, "config_file_contents for action_add" do it "should include a netmask when a one is specified" do - @new_resource.stub!(:netmask).and_return('255.255.0.0') + @new_resource.stub(:netmask).and_return('255.255.0.0') @provider.config_file_contents(:add, { :target => @new_resource.target, :netmask => @new_resource.netmask}).should match(/\/\d{1,2}.*\n$/) end diff --git a/spec/unit/provider/script_spec.rb b/spec/unit/provider/script_spec.rb index 5111a94578..d072eddd04 100644 --- a/spec/unit/provider/script_spec.rb +++ b/spec/unit/provider/script_spec.rb @@ -30,9 +30,9 @@ describe Chef::Provider::Script, "action_run" do @provider = Chef::Provider::Script.new(@new_resource, @run_context) @script_file = StringIO.new - @script_file.stub!(:path).and_return('/tmp/the_script_file') + @script_file.stub(:path).and_return('/tmp/the_script_file') - @provider.stub!(:shell_out!).and_return(true) + @provider.stub(:shell_out!).and_return(true) end it "creates a temporary file to store the script" do @@ -48,15 +48,15 @@ describe Chef::Provider::Script, "action_run" do it "sets the owner and group for the script file" do @new_resource.user 'toor' @new_resource.group 'wheel' - @provider.stub!(:script_file).and_return(@script_file) + @provider.stub(:script_file).and_return(@script_file) FileUtils.should_receive(:chown).with('toor', 'wheel', "/tmp/the_script_file") @provider.set_owner_and_group end context "with the script file set to the correct owner and group" do before do - @provider.stub!(:set_owner_and_group) - @provider.stub!(:script_file).and_return(@script_file) + @provider.stub(:set_owner_and_group) + @provider.stub(:script_file).and_return(@script_file) end describe "when writing the script to the file" do it "should put the contents of the script in the temp file" do diff --git a/spec/unit/provider/service/arch_service_spec.rb b/spec/unit/provider/service/arch_service_spec.rb index 0865fdae86..b267915e44 100644 --- a/spec/unit/provider/service/arch_service_spec.rb +++ b/spec/unit/provider/service/arch_service_spec.rb @@ -39,8 +39,8 @@ describe Chef::Provider::Service::Arch, "load_current_resource" do @provider = Chef::Provider::Service::Arch.new(@new_resource, @run_context) - ::File.stub!(:exists?).with("/etc/rc.conf").and_return(true) - ::File.stub!(:read).with("/etc/rc.conf").and_return("DAEMONS=(network apache sshd)") + ::File.stub(:exists?).with("/etc/rc.conf").and_return(true) + ::File.stub(:read).with("/etc/rc.conf").and_return("DAEMONS=(network apache sshd)") end describe "when first created" do @@ -63,19 +63,19 @@ describe Chef::Provider::Service::Arch, "load_current_resource" do end it "should set running to true if the status command returns 0" do - @provider.stub!(:shell_out).with("/etc/rc.d/chef status").and_return(OpenStruct.new(:exitstatus => 0)) + @provider.stub(:shell_out).with("/etc/rc.d/chef status").and_return(OpenStruct.new(:exitstatus => 0)) @provider.load_current_resource @provider.current_resource.running.should be_true end it "should set running to false if the status command returns anything except 0" do - @provider.stub!(:shell_out).with("/etc/rc.d/chef status").and_return(OpenStruct.new(:exitstatus => 1)) + @provider.stub(:shell_out).with("/etc/rc.d/chef status").and_return(OpenStruct.new(:exitstatus => 1)) @provider.load_current_resource @provider.current_resource.running.should be_false end it "should set running to false if the status command raises" do - @provider.stub!(:shell_out).with("/etc/rc.d/chef status").and_raise(Mixlib::ShellOut::ShellCommandFailed) + @provider.stub(:shell_out).with("/etc/rc.d/chef status").and_raise(Mixlib::ShellOut::ShellCommandFailed) @provider.load_current_resource @provider.current_resource.running.should be_false end @@ -111,12 +111,12 @@ describe Chef::Provider::Service::Arch, "load_current_resource" do it "should fail if file /etc/rc.conf does not exist" do - ::File.stub!(:exists?).with("/etc/rc.conf").and_return(false) + ::File.stub(:exists?).with("/etc/rc.conf").and_return(false) lambda { @provider.load_current_resource }.should raise_error(Chef::Exceptions::Service) end it "should fail if file /etc/rc.conf does not contain DAEMONS array" do - ::File.stub!(:read).with("/etc/rc.conf").and_return("") + ::File.stub(:read).with("/etc/rc.conf").and_return("") lambda { @provider.load_current_resource }.should raise_error(Chef::Exceptions::Service) end @@ -127,8 +127,8 @@ aj 7842 5057 0 21:26 pts/2 00:00:06 vi init.rb aj 7903 5016 0 21:26 pts/5 00:00:00 /bin/bash aj 8119 6041 0 21:34 pts/3 00:00:03 vi init_service_spec.rb DEFAULT_PS - @status = mock("Status", :exitstatus => 0, :stdout => @stdout) - @provider.stub!(:shell_out!).and_return(@status) + @status = double("Status", :exitstatus => 0, :stdout => @stdout) + @provider.stub(:shell_out!).and_return(@status) @node.automatic_attrs[:command] = {:ps => "ps -ef"} end @@ -138,19 +138,19 @@ DEFAULT_PS aj 7842 5057 0 21:26 pts/2 00:00:06 chef aj 7842 5057 0 21:26 pts/2 00:00:06 poos RUNNING_PS - @status.stub!(:stdout).and_return(@stdout) + @status.stub(:stdout).and_return(@stdout) @provider.load_current_resource @provider.current_resource.running.should be_true end it "determines the service is not running when it does not appear in ps" do - @provider.stub!(:shell_out!).and_return(@status) + @provider.stub(:shell_out!).and_return(@status) @provider.load_current_resource @provider.current_resource.running.should be_false end it "should raise an exception if ps fails" do - @provider.stub!(:shell_out!).and_raise(Mixlib::ShellOut::ShellCommandFailed) + @provider.stub(:shell_out!).and_raise(Mixlib::ShellOut::ShellCommandFailed) @provider.load_current_resource @provider.action = :start @provider.define_resource_requirements @@ -159,7 +159,7 @@ RUNNING_PS end it "should return existing entries in DAEMONS array" do - ::File.stub!(:read).with("/etc/rc.conf").and_return("DAEMONS=(network !apache ssh)") + ::File.stub(:read).with("/etc/rc.conf").and_return("DAEMONS=(network !apache ssh)") @provider.daemons.should == ['network', '!apache', 'ssh'] end @@ -171,20 +171,20 @@ RUNNING_PS describe Chef::Provider::Service::Arch, "enable_service" do # before(:each) do - # @new_resource = mock("Chef::Resource::Service", + # @new_resource = double("Chef::Resource::Service", # :null_object => true, # :name => "chef", # :service_name => "chef", # :running => false # ) - # @new_resource.stub!(:start_command).and_return(false) + # @new_resource.stub(:start_command).and_return(false) # # @provider = Chef::Provider::Service::Arch.new(@node, @new_resource) - # Chef::Resource::Service.stub!(:new).and_return(@current_resource) + # Chef::Resource::Service.stub(:new).and_return(@current_resource) # end it "should add chef to DAEMONS array" do - ::File.stub!(:read).with("/etc/rc.conf").and_return("DAEMONS=(network)") + ::File.stub(:read).with("/etc/rc.conf").and_return("DAEMONS=(network)") @provider.should_receive(:update_daemons).with(['network', 'chef']) @provider.enable_service() end @@ -192,20 +192,20 @@ RUNNING_PS describe Chef::Provider::Service::Arch, "disable_service" do # before(:each) do - # @new_resource = mock("Chef::Resource::Service", + # @new_resource = double("Chef::Resource::Service", # :null_object => true, # :name => "chef", # :service_name => "chef", # :running => false # ) - # @new_resource.stub!(:start_command).and_return(false) + # @new_resource.stub(:start_command).and_return(false) # # @provider = Chef::Provider::Service::Arch.new(@node, @new_resource) - # Chef::Resource::Service.stub!(:new).and_return(@current_resource) + # Chef::Resource::Service.stub(:new).and_return(@current_resource) # end it "should remove chef from DAEMONS array" do - ::File.stub!(:read).with("/etc/rc.conf").and_return("DAEMONS=(network chef)") + ::File.stub(:read).with("/etc/rc.conf").and_return("DAEMONS=(network chef)") @provider.should_receive(:update_daemons).with(['network', '!chef']) @provider.disable_service() end @@ -214,20 +214,20 @@ RUNNING_PS describe Chef::Provider::Service::Arch, "start_service" do # before(:each) do - # @new_resource = mock("Chef::Resource::Service", + # @new_resource = double("Chef::Resource::Service", # :null_object => true, # :name => "chef", # :service_name => "chef", # :running => false # ) - # @new_resource.stub!(:start_command).and_return(false) + # @new_resource.stub(:start_command).and_return(false) # # @provider = Chef::Provider::Service::Arch.new(@node, @new_resource) - # Chef::Resource::Service.stub!(:new).and_return(@current_resource) + # Chef::Resource::Service.stub(:new).and_return(@current_resource) # end it "should call the start command if one is specified" do - @new_resource.stub!(:start_command).and_return("/etc/rc.d/chef startyousillysally") + @new_resource.stub(:start_command).and_return("/etc/rc.d/chef startyousillysally") @provider.should_receive(:shell_out!).with("/etc/rc.d/chef startyousillysally") @provider.start_service() end @@ -240,20 +240,20 @@ RUNNING_PS describe Chef::Provider::Service::Arch, "stop_service" do # before(:each) do - # @new_resource = mock("Chef::Resource::Service", + # @new_resource = double("Chef::Resource::Service", # :null_object => true, # :name => "chef", # :service_name => "chef", # :running => false # ) - # @new_resource.stub!(:stop_command).and_return(false) + # @new_resource.stub(:stop_command).and_return(false) # # @provider = Chef::Provider::Service::Arch.new(@node, @new_resource) - # Chef::Resource::Service.stub!(:new).and_return(@current_resource) + # Chef::Resource::Service.stub(:new).and_return(@current_resource) # end it "should call the stop command if one is specified" do - @new_resource.stub!(:stop_command).and_return("/etc/rc.d/chef itoldyoutostop") + @new_resource.stub(:stop_command).and_return("/etc/rc.d/chef itoldyoutostop") @provider.should_receive(:shell_out!).with("/etc/rc.d/chef itoldyoutostop") @provider.stop_service() end @@ -266,27 +266,27 @@ RUNNING_PS describe Chef::Provider::Service::Arch, "restart_service" do # before(:each) do - # @new_resource = mock("Chef::Resource::Service", + # @new_resource = double("Chef::Resource::Service", # :null_object => true, # :name => "chef", # :service_name => "chef", # :running => false # ) - # @new_resource.stub!(:restart_command).and_return(false) - # @new_resource.stub!(:supports).and_return({:restart => false}) + # @new_resource.stub(:restart_command).and_return(false) + # @new_resource.stub(:supports).and_return({:restart => false}) # # @provider = Chef::Provider::Service::Arch.new(@node, @new_resource) - # Chef::Resource::Service.stub!(:new).and_return(@current_resource) + # Chef::Resource::Service.stub(:new).and_return(@current_resource) # end it "should call 'restart' on the service_name if the resource supports it" do - @new_resource.stub!(:supports).and_return({:restart => true}) + @new_resource.stub(:supports).and_return({:restart => true}) @provider.should_receive(:shell_out!).with("/etc/rc.d/#{@new_resource.service_name} restart") @provider.restart_service() end it "should call the restart_command if one has been specified" do - @new_resource.stub!(:restart_command).and_return("/etc/rc.d/chef restartinafire") + @new_resource.stub(:restart_command).and_return("/etc/rc.d/chef restartinafire") @provider.should_receive(:shell_out!).with("/etc/rc.d/#{@new_resource.service_name} restartinafire") @provider.restart_service() end @@ -301,27 +301,27 @@ RUNNING_PS describe Chef::Provider::Service::Arch, "reload_service" do # before(:each) do - # @new_resource = mock("Chef::Resource::Service", + # @new_resource = double("Chef::Resource::Service", # :null_object => true, # :name => "chef", # :service_name => "chef", # :running => false # ) - # @new_resource.stub!(:reload_command).and_return(false) - # @new_resource.stub!(:supports).and_return({:reload => false}) + # @new_resource.stub(:reload_command).and_return(false) + # @new_resource.stub(:supports).and_return({:reload => false}) # # @provider = Chef::Provider::Service::Arch.new(@node, @new_resource) - # Chef::Resource::Service.stub!(:new).and_return(@current_resource) + # Chef::Resource::Service.stub(:new).and_return(@current_resource) # end it "should call 'reload' on the service if it supports it" do - @new_resource.stub!(:supports).and_return({:reload => true}) + @new_resource.stub(:supports).and_return({:reload => true}) @provider.should_receive(:shell_out!).with("/etc/rc.d/#{@new_resource.service_name} reload") @provider.reload_service() end it "should should run the user specified reload command if one is specified and the service doesn't support reload" do - @new_resource.stub!(:reload_command).and_return("/etc/rc.d/chef lollerpants") + @new_resource.stub(:reload_command).and_return("/etc/rc.d/chef lollerpants") @provider.should_receive(:shell_out!).with("/etc/rc.d/#{@new_resource.service_name} lollerpants") @provider.reload_service() end diff --git a/spec/unit/provider/service/debian_service_spec.rb b/spec/unit/provider/service/debian_service_spec.rb index 7d05b403de..567eb6744a 100644 --- a/spec/unit/provider/service/debian_service_spec.rb +++ b/spec/unit/provider/service/debian_service_spec.rb @@ -46,7 +46,7 @@ describe Chef::Provider::Service::Debian do context "when update-rc.d shows init linked to rc*.d/" do before do - @provider.stub!(:assert_update_rcd_available) + @provider.stub(:assert_update_rcd_available) result = <<-UPDATE_RC_D_SUCCESS Removing any system startup links for /etc/init.d/chef ... @@ -61,9 +61,9 @@ describe Chef::Provider::Service::Debian do @stdout = StringIO.new(result) @stderr = StringIO.new - @status = mock("Status", :exitstatus => 0, :stdout => @stdout) - @provider.stub!(:shell_out!).and_return(@status) - @provider.stub!(:popen4).and_yield(@pid, @stdin, @stdout, @stderr).and_return(@status) + @status = double("Status", :exitstatus => 0, :stdout => @stdout) + @provider.stub(:shell_out!).and_return(@status) + @provider.stub(:popen4).and_yield(@pid, @stdin, @stdout, @stderr).and_return(@status) end it "says the service is enabled" do @@ -71,7 +71,7 @@ describe Chef::Provider::Service::Debian do end it "stores the 'enabled' state" do - Chef::Resource::Service.stub!(:new).and_return(@current_resource) + Chef::Resource::Service.stub(:new).and_return(@current_resource) @provider.load_current_resource.should equal(@current_resource) @current_resource.enabled.should be_true end @@ -79,14 +79,14 @@ describe Chef::Provider::Service::Debian do context "when update-rc.d shows init isn't linked to rc*.d/" do before do - @provider.stub!(:assert_update_rcd_available) - @status = mock("Status", :exitstatus => 0) + @provider.stub(:assert_update_rcd_available) + @status = double("Status", :exitstatus => 0) @stdout = StringIO.new( " Removing any system startup links for /etc/init.d/chef ...") @stderr = StringIO.new - @status = mock("Status", :exitstatus => 0, :stdout => @stdout) - @provider.stub!(:shell_out!).and_return(@status) - @provider.stub!(:popen4).and_yield(@pid, @stdin, @stdout, @stderr).and_return(@status) + @status = double("Status", :exitstatus => 0, :stdout => @stdout) + @provider.stub(:shell_out!).and_return(@status) + @provider.stub(:popen4).and_yield(@pid, @stdin, @stdout, @stderr).and_return(@status) end it "says the service is disabled" do @@ -94,7 +94,7 @@ describe Chef::Provider::Service::Debian do end it "stores the 'disabled' state" do - Chef::Resource::Service.stub!(:new).and_return(@current_resource) + Chef::Resource::Service.stub(:new).and_return(@current_resource) @provider.load_current_resource.should equal(@current_resource) @current_resource.enabled.should be_false end @@ -102,8 +102,8 @@ describe Chef::Provider::Service::Debian do context "when update-rc.d fails" do before do - @status = mock("Status", :exitstatus => -1) - @provider.stub!(:popen4).and_return(@status) + @status = double("Status", :exitstatus => -1) + @provider.stub(:popen4).and_return(@status) end it "raises an error" do @@ -196,13 +196,13 @@ 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 - @provider.stub!(:assert_update_rcd_available) + @provider.stub(:assert_update_rcd_available) @stdout = StringIO.new(expected_results["linked"]["stdout"]) @stderr = StringIO.new(expected_results["linked"]["stderr"]) - @status = mock("Status", :exitstatus => 0, :stdout => @stdout) - @provider.stub!(:shell_out!).and_return(@status) - @provider.stub!(:popen4).and_yield(@pid, @stdin, @stdout, @stderr).and_return(@status) + @status = double("Status", :exitstatus => 0, :stdout => @stdout) + @provider.stub(:shell_out!).and_return(@status) + @provider.stub(:popen4).and_yield(@pid, @stdin, @stdout, @stderr).and_return(@status) end it "says the service is enabled" do @@ -210,7 +210,7 @@ insserv: dryrun, not creating .depend.boot, .depend.start, and .depend.stop end it "stores the 'enabled' state" do - Chef::Resource::Service.stub!(:new).and_return(@current_resource) + Chef::Resource::Service.stub(:new).and_return(@current_resource) @provider.load_current_resource.should equal(@current_resource) @current_resource.enabled.should be_true end @@ -223,12 +223,12 @@ 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 - @provider.stub!(:assert_update_rcd_available) + @provider.stub(:assert_update_rcd_available) @stdout = StringIO.new(expected_results["not linked"]["stdout"]) @stderr = StringIO.new(expected_results["not linked"]["stderr"]) - @status = mock("Status", :exitstatus => 0, :stdout => @stdout) - @provider.stub!(:shell_out!).and_return(@status) - @provider.stub!(:popen4).and_yield(@pid, @stdin, @stdout, @stderr).and_return(@status) + @status = double("Status", :exitstatus => 0, :stdout => @stdout) + @provider.stub(:shell_out!).and_return(@status) + @provider.stub(:popen4).and_yield(@pid, @stdin, @stdout, @stderr).and_return(@status) end it "says the service is disabled" do @@ -236,7 +236,7 @@ insserv: dryrun, not creating .depend.boot, .depend.start, and .depend.stop end it "stores the 'disabled' state" do - Chef::Resource::Service.stub!(:new).and_return(@current_resource) + Chef::Resource::Service.stub(:new).and_return(@current_resource) @provider.load_current_resource.should equal(@current_resource) @current_resource.enabled.should be_false end diff --git a/spec/unit/provider/service/freebsd_service_spec.rb b/spec/unit/provider/service/freebsd_service_spec.rb index 7861764309..820dfb8dc7 100644 --- a/spec/unit/provider/service/freebsd_service_spec.rb +++ b/spec/unit/provider/service/freebsd_service_spec.rb @@ -34,7 +34,7 @@ describe Chef::Provider::Service::Freebsd do @provider = Chef::Provider::Service::Freebsd.new(@new_resource,@run_context) @provider.action = :start @init_command = "/usr/local/etc/rc.d/apache22" - Chef::Resource::Service.stub!(:new).and_return(@current_resource) + Chef::Resource::Service.stub(:new).and_return(@current_resource) end describe "load_current_resource" do @@ -44,21 +44,21 @@ describe Chef::Provider::Service::Freebsd do 539 ?? Is 0:00.14 /usr/sbin/sshd 545 ?? Ss 0:17.53 sendmail: accepting connections (sendmail) PS_SAMPLE - @status = mock(:stdout => @stdout, :exitstatus => 0) - @provider.stub!(:shell_out!).with(@node[:command][:ps]).and_return(@status) + @status = double(:stdout => @stdout, :exitstatus => 0) + @provider.stub(:shell_out!).with(@node[:command][:ps]).and_return(@status) - ::File.stub!(:exists?).and_return(false) - ::File.stub!(:exists?).with("/usr/local/etc/rc.d/#{@new_resource.service_name}").and_return(true) - @lines = mock("lines") - @lines.stub!(:each).and_yield("sshd_enable=\"YES\""). + ::File.stub(:exists?).and_return(false) + ::File.stub(:exists?).with("/usr/local/etc/rc.d/#{@new_resource.service_name}").and_return(true) + @lines = double("lines") + @lines.stub(:each).and_yield("sshd_enable=\"YES\""). and_yield("#{@new_resource.name}_enable=\"YES\"") - ::File.stub!(:open).and_return(@lines) + ::File.stub(:open).and_return(@lines) @rc_with_name = StringIO.new(<<-RC_SAMPLE) name="apache22" rcvar=`set_rcvar` RC_SAMPLE - ::File.stub!(:open).with("/usr/local/etc/rc.d/#{@new_resource.service_name}").and_return(@rc_with_name) + ::File.stub(:open).with("/usr/local/etc/rc.d/#{@new_resource.service_name}").and_return(@rc_with_name) @provider.stub(:service_enable_variable_name).and_return nil end @@ -75,7 +75,7 @@ RC_SAMPLE it "should not raise an exception if the rcscript have a name variable" do @provider.load_current_resource - lambda { @provider.service_enable_variable_name }.should_not raise_error(Chef::Exceptions::Service) + lambda { @provider.service_enable_variable_name }.should_not raise_error end describe "when the service supports status" do @@ -129,14 +129,14 @@ RC_SAMPLE describe "when executing assertions" do it "should verify that /etc/rc.conf exists" do ::File.should_receive(:exists?).with("/etc/rc.conf") - @provider.stub!(:service_enable_variable_name).and_return("#{@current_resource.service_name}_enable") + @provider.stub(:service_enable_variable_name).and_return("#{@current_resource.service_name}_enable") @provider.load_current_resource end context "and the init script is not found" do [ "start", "reload", "restart", "enable" ].each do |action| it "should raise an exception when the action is #{action}" do - ::File.stub!(:exists?).and_return(false) + ::File.stub(:exists?).and_return(false) @provider.load_current_resource @provider.define_resource_requirements @provider.instance_variable_get("@rcd_script_found").should be_false @@ -160,7 +160,7 @@ RC_SAMPLE end it "update state when current resource enabled state could be determined" do - ::File.stub!(:exist?).with("/usr/local/etc/rc.d/#{@new_resource.service_name}").and_return(true) + ::File.stub(:exist?).with("/usr/local/etc/rc.d/#{@new_resource.service_name}").and_return(true) ::File.should_receive(:exists?).with("/etc/rc.conf").and_return true @provider.load_current_resource @provider.instance_variable_get("@enabled_state_found").should be_false @@ -189,26 +189,26 @@ RC_SAMPLE end it "should read stdout of the ps command" do - @provider.stub!(:shell_out!).and_return(@status) + @provider.stub(:shell_out!).and_return(@status) @stdout.should_receive(:each_line).and_return(true) @provider.load_current_resource end it "should set running to true if the regex matches the output" do - @stdout.stub!(:each_line).and_yield("555 ?? Ss 0:05.16 /usr/sbin/cron -s"). + @stdout.stub(:each_line).and_yield("555 ?? Ss 0:05.16 /usr/sbin/cron -s"). and_yield(" 9881 ?? Ss 0:06.67 /usr/local/sbin/httpd -DNOHTTPACCEPT") @provider.load_current_resource @current_resource.running.should be_true end it "should set running to false if the regex doesn't match" do - @provider.stub!(:shell_out!).and_return(@status) + @provider.stub(:shell_out!).and_return(@status) @provider.load_current_resource @current_resource.running.should be_false end it "should raise an exception if ps fails" do - @provider.stub!(:shell_out!).and_raise(Mixlib::ShellOut::ShellCommandFailed) + @provider.stub(:shell_out!).and_raise(Mixlib::ShellOut::ShellCommandFailed) @provider.load_current_resource @provider.define_resource_requirements lambda { @provider.process_resource_requirements }.should raise_error(Chef::Exceptions::Service) @@ -270,7 +270,7 @@ RC_SAMPLE @rc_without_name = StringIO.new(<<-RC_SAMPLE) rcvar=`set_rcvar` RC_SAMPLE - ::File.stub!(:open).with("/usr/local/etc/rc.d/#{@current_resource.service_name}").and_return(@rc_with_noname) + ::File.stub(:open).with("/usr/local/etc/rc.d/#{@current_resource.service_name}").and_return(@rc_with_noname) @provider.current_resource = @current_resource end @@ -282,19 +282,19 @@ RC_SAMPLE # #{@current_resource.service_name}_enable="YES" # (default: "") RCVAR_SAMPLE - @status = mock(:stdout => @rcvar_stdout, :exitstatus => 0) - @provider.stub!(:shell_out!).with("/usr/local/etc/rc.d/#{@current_resource.service_name} rcvar").and_return(@status) + @status = double(:stdout => @rcvar_stdout, :exitstatus => 0) + @provider.stub(:shell_out!).with("/usr/local/etc/rc.d/#{@current_resource.service_name} rcvar").and_return(@status) end it "should get the service name from rcvar if the rcscript does not have a name variable" do @provider.load_current_resource - @provider.unstub!(:service_enable_variable_name) + @provider.unstub(:service_enable_variable_name) @provider.service_enable_variable_name.should == "#{@current_resource.service_name}_enable" end it "should not raise an exception if the rcscript does not have a name variable" do @provider.load_current_resource - lambda { @provider.service_enable_variable_name }.should_not raise_error(Chef::Exceptions::Service) + lambda { @provider.service_enable_variable_name }.should_not raise_error end end @@ -304,8 +304,8 @@ RCVAR_SAMPLE # service_with_noname # RCVAR_SAMPLE - @status = mock(:stdout => @rcvar_stdout, :exitstatus => 0) - @provider.stub!(:shell_out!).with("/usr/local/etc/rc.d/#{@current_resource.service_name} rcvar").and_return(@status) + @status = double(:stdout => @rcvar_stdout, :exitstatus => 0) + @provider.stub(:shell_out!).with("/usr/local/etc/rc.d/#{@current_resource.service_name} rcvar").and_return(@status) end [ "start", "reload", "restart", "enable" ].each do |action| @@ -319,11 +319,11 @@ RCVAR_SAMPLE [ "stop", "disable" ].each do |action| it "should not raise an error when the action is #{action}" do - ::File.stub!(:exist?).with("/usr/local/etc/rc.d/#{@new_resource.service_name}").and_return(true) + ::File.stub(:exist?).with("/usr/local/etc/rc.d/#{@new_resource.service_name}").and_return(true) @provider.action = action @provider.load_current_resource @provider.define_resource_requirements - lambda { @provider.process_resource_requirements }.should_not raise_error(Chef::Exceptions::Service) + lambda { @provider.process_resource_requirements }.should_not raise_error end end end @@ -333,25 +333,25 @@ RCVAR_SAMPLE describe Chef::Provider::Service::Freebsd, "enable_service" do before do @provider.current_resource = @current_resource - @provider.stub!(:service_enable_variable_name).and_return("#{@current_resource.service_name}_enable") + @provider.stub(:service_enable_variable_name).and_return("#{@current_resource.service_name}_enable") end it "should enable the service if it is not enabled" do - @current_resource.stub!(:enabled).and_return(false) + @current_resource.stub(:enabled).and_return(false) @provider.should_receive(:read_rc_conf).and_return([ "foo", "#{@current_resource.service_name}_enable=\"NO\"", "bar" ]) @provider.should_receive(:write_rc_conf).with(["foo", "bar", "#{@current_resource.service_name}_enable=\"YES\""]) @provider.enable_service() end it "should enable the service if it is not enabled and not already specified in the rc.conf file" do - @current_resource.stub!(:enabled).and_return(false) + @current_resource.stub(:enabled).and_return(false) @provider.should_receive(:read_rc_conf).and_return([ "foo", "bar" ]) @provider.should_receive(:write_rc_conf).with(["foo", "bar", "#{@current_resource.service_name}_enable=\"YES\""]) @provider.enable_service() end it "should not enable the service if it is already enabled" do - @current_resource.stub!(:enabled).and_return(true) + @current_resource.stub(:enabled).and_return(true) @provider.should_not_receive(:write_rc_conf) @provider.enable_service end @@ -360,18 +360,18 @@ RCVAR_SAMPLE describe Chef::Provider::Service::Freebsd, "disable_service" do before do @provider.current_resource = @current_resource - @provider.stub!(:service_enable_variable_name).and_return("#{@current_resource.service_name}_enable") + @provider.stub(:service_enable_variable_name).and_return("#{@current_resource.service_name}_enable") end it "should should disable the service if it is not disabled" do - @current_resource.stub!(:enabled).and_return(true) + @current_resource.stub(:enabled).and_return(true) @provider.should_receive(:read_rc_conf).and_return([ "foo", "#{@current_resource.service_name}_enable=\"YES\"", "bar" ]) @provider.should_receive(:write_rc_conf).with(["foo", "bar", "#{@current_resource.service_name}_enable=\"NO\""]) @provider.disable_service() end it "should not disable the service if it is already disabled" do - @current_resource.stub!(:enabled).and_return(false) + @current_resource.stub(:enabled).and_return(false) @provider.should_not_receive(:write_rc_conf) @provider.disable_service() end diff --git a/spec/unit/provider/service/gentoo_service_spec.rb b/spec/unit/provider/service/gentoo_service_spec.rb index b658cab4d8..95dc04108d 100644 --- a/spec/unit/provider/service/gentoo_service_spec.rb +++ b/spec/unit/provider/service/gentoo_service_spec.rb @@ -29,13 +29,13 @@ describe Chef::Provider::Service::Gentoo do @current_resource = Chef::Resource::Service.new("chef") @provider = Chef::Provider::Service::Gentoo.new(@new_resource, @run_context) - Chef::Resource::Service.stub!(:new).and_return(@current_resource) - @status = mock("Status", :exitstatus => 0, :stdout => @stdout) - @provider.stub!(:shell_out).and_return(@status) - File.stub!(:exists?).with("/etc/init.d/chef").and_return(true) - File.stub!(:exists?).with("/sbin/rc-update").and_return(true) - File.stub!(:exists?).with("/etc/runlevels/default/chef").and_return(false) - File.stub!(:readable?).with("/etc/runlevels/default/chef").and_return(false) + Chef::Resource::Service.stub(:new).and_return(@current_resource) + @status = double("Status", :exitstatus => 0, :stdout => @stdout) + @provider.stub(:shell_out).and_return(@status) + File.stub(:exists?).with("/etc/init.d/chef").and_return(true) + File.stub(:exists?).with("/sbin/rc-update").and_return(true) + File.stub(:exists?).with("/etc/runlevels/default/chef").and_return(false) + File.stub(:readable?).with("/etc/runlevels/default/chef").and_return(false) end # new test: found_enabled state # @@ -52,7 +52,7 @@ describe Chef::Provider::Service::Gentoo do end it "should track when service file is found in /etc/runlevels/**/" do - Dir.stub!(:glob).with("/etc/runlevels/**/chef").and_return(["/etc/runlevels/default/chef"]) + Dir.stub(:glob).with("/etc/runlevels/**/chef").and_return(["/etc/runlevels/default/chef"]) @provider.load_current_resource @provider.instance_variable_get("@found_script").should be_true end @@ -60,13 +60,13 @@ describe Chef::Provider::Service::Gentoo do describe "when detecting the service enable state" do describe "and the glob returns a default service script file" do before do - Dir.stub!(:glob).with("/etc/runlevels/**/chef").and_return(["/etc/runlevels/default/chef"]) + Dir.stub(:glob).with("/etc/runlevels/**/chef").and_return(["/etc/runlevels/default/chef"]) end describe "and the file exists and is readable" do before do - File.stub!(:exists?).with("/etc/runlevels/default/chef").and_return(true) - File.stub!(:readable?).with("/etc/runlevels/default/chef").and_return(true) + File.stub(:exists?).with("/etc/runlevels/default/chef").and_return(true) + File.stub(:readable?).with("/etc/runlevels/default/chef").and_return(true) end it "should set enabled to true" do @provider.load_current_resource @@ -76,8 +76,8 @@ describe Chef::Provider::Service::Gentoo do describe "and the file exists but is not readable" do before do - File.stub!(:exists?).with("/etc/runlevels/default/chef").and_return(true) - File.stub!(:readable?).with("/etc/runlevels/default/chef").and_return(false) + File.stub(:exists?).with("/etc/runlevels/default/chef").and_return(true) + File.stub(:readable?).with("/etc/runlevels/default/chef").and_return(false) end it "should set enabled to false" do @@ -88,8 +88,8 @@ describe Chef::Provider::Service::Gentoo do describe "and the file does not exist" do before do - File.stub!(:exists?).with("/etc/runlevels/default/chef").and_return(false) - File.stub!(:readable?).with("/etc/runlevels/default/chef").and_return("foobarbaz") + File.stub(:exists?).with("/etc/runlevels/default/chef").and_return(false) + File.stub(:readable?).with("/etc/runlevels/default/chef").and_return("foobarbaz") end it "should set enabled to false" do @@ -124,7 +124,7 @@ describe Chef::Provider::Service::Gentoo do end describe "action_methods" do - before(:each) { @provider.stub!(:load_current_resource).and_return(@current_resource) } + before(:each) { @provider.stub(:load_current_resource).and_return(@current_resource) } describe Chef::Provider::Service::Gentoo, "enable_service" do it "should call rc-update add *service* default" do diff --git a/spec/unit/provider/service/init_service_spec.rb b/spec/unit/provider/service/init_service_spec.rb index c7d47e6281..ad887c84a5 100644 --- a/spec/unit/provider/service/init_service_spec.rb +++ b/spec/unit/provider/service/init_service_spec.rb @@ -30,15 +30,15 @@ describe Chef::Provider::Service::Init, "load_current_resource" do @current_resource = Chef::Resource::Service.new("chef") @provider = Chef::Provider::Service::Init.new(@new_resource, @run_context) - Chef::Resource::Service.stub!(:new).and_return(@current_resource) + Chef::Resource::Service.stub(:new).and_return(@current_resource) @stdout = StringIO.new(<<-PS) aj 7842 5057 0 21:26 pts/2 00:00:06 vi init.rb aj 7903 5016 0 21:26 pts/5 00:00:00 /bin/bash aj 8119 6041 0 21:34 pts/3 00:00:03 vi init_service_spec.rb PS - @status = mock("Status", :exitstatus => 0, :stdout => @stdout) - @provider.stub!(:shell_out!).and_return(@status) + @status = double("Status", :exitstatus => 0, :stdout => @stdout) + @provider.stub(:shell_out!).and_return(@status) end it "should create a current resource with the name of the new resource" do @@ -62,20 +62,20 @@ PS end it "should set running to true if the status command returns 0" do - @provider.stub!(:shell_out).with("/etc/init.d/#{@current_resource.service_name} status").and_return(@status) + @provider.stub(:shell_out).with("/etc/init.d/#{@current_resource.service_name} status").and_return(@status) @provider.load_current_resource @current_resource.running.should be_true end it "should set running to false if the status command returns anything except 0" do - @status.stub!(:exitstatus).and_return(1) - @provider.stub!(:shell_out).with("/etc/init.d/#{@current_resource.service_name} status").and_return(@status) + @status.stub(:exitstatus).and_return(1) + @provider.stub(:shell_out).with("/etc/init.d/#{@current_resource.service_name} status").and_return(@status) @provider.load_current_resource @current_resource.running.should be_false end it "should set running to false if the status command raises" do - @provider.stub!(:shell_out).and_raise(Mixlib::ShellOut::ShellCommandFailed) + @provider.stub(:shell_out).and_raise(Mixlib::ShellOut::ShellCommandFailed) @provider.load_current_resource @current_resource.running.should be_false end @@ -83,7 +83,7 @@ PS describe "when a status command has been specified" do before do - @new_resource.stub!(:status_command).and_return("/etc/init.d/chefhasmonkeypants status") + @new_resource.stub(:status_command).and_return("/etc/init.d/chefhasmonkeypants status") end it "should run the services status command if one has been specified" do @@ -95,7 +95,7 @@ PS describe "when an init command has been specified" do before do - @new_resource.stub!(:init_command).and_return("/opt/chef-server/service/erchef") + @new_resource.stub(:init_command).and_return("/opt/chef-server/service/erchef") @provider = Chef::Provider::Service::Init.new(@new_resource, @run_context) end @@ -138,19 +138,19 @@ PS aj 7842 5057 0 21:26 pts/2 00:00:06 chef aj 7842 5057 0 21:26 pts/2 00:00:06 poos RUNNING_PS - @status.stub!(:stdout).and_return(@stdout) + @status.stub(:stdout).and_return(@stdout) @provider.load_current_resource @current_resource.running.should be_true end it "should set running to false if the regex doesn't match" do - @provider.stub!(:shell_out!).and_return(@status) + @provider.stub(:shell_out!).and_return(@status) @provider.load_current_resource @current_resource.running.should be_false end it "should raise an exception if ps fails" do - @provider.stub!(:shell_out!).and_raise(Mixlib::ShellOut::ShellCommandFailed) + @provider.stub(:shell_out!).and_raise(Mixlib::ShellOut::ShellCommandFailed) @provider.load_current_resource @provider.action = :start @provider.define_resource_requirements @@ -229,7 +229,7 @@ RUNNING_PS end it "should still pass all why run assertions" do - lambda { @provider.run_action(:start) }.should_not raise_error(Chef::Exceptions::Service) + lambda { @provider.run_action(:start) }.should_not raise_error end end end diff --git a/spec/unit/provider/service/insserv_service_spec.rb b/spec/unit/provider/service/insserv_service_spec.rb index 8b5f09e78c..04e63458a0 100644 --- a/spec/unit/provider/service/insserv_service_spec.rb +++ b/spec/unit/provider/service/insserv_service_spec.rb @@ -29,14 +29,14 @@ describe Chef::Provider::Service::Insserv do @current_resource = Chef::Resource::Service.new("initgrediant") @provider = Chef::Provider::Service::Insserv.new(@new_resource, @run_context) - @status = mock("Process::Status mock", :exitstatus => 0, :stdout => "") - @provider.stub!(:shell_out!).and_return(@status) + @status = double("Process::Status mock", :exitstatus => 0, :stdout => "") + @provider.stub(:shell_out!).and_return(@status) end describe "load_current_resource" do describe "when startup links exist" do before do - Dir.stub!(:glob).with("/etc/rc**/S*initgrediant").and_return(["/etc/rc5.d/S18initgrediant", "/etc/rc2.d/S18initgrediant", "/etc/rc4.d/S18initgrediant", "/etc/rc3.d/S18initgrediant"]) + Dir.stub(:glob).with("/etc/rc**/S*initgrediant").and_return(["/etc/rc5.d/S18initgrediant", "/etc/rc2.d/S18initgrediant", "/etc/rc4.d/S18initgrediant", "/etc/rc3.d/S18initgrediant"]) end it "sets the current enabled status to true" do @@ -47,7 +47,7 @@ describe Chef::Provider::Service::Insserv do describe "when startup links do not exist" do before do - Dir.stub!(:glob).with("/etc/rc**/S*initgrediant").and_return([]) + Dir.stub(:glob).with("/etc/rc**/S*initgrediant").and_return([]) end it "sets the current enabled status to false" do diff --git a/spec/unit/provider/service/invokercd_service_spec.rb b/spec/unit/provider/service/invokercd_service_spec.rb index ca20657405..b638b08b72 100644 --- a/spec/unit/provider/service/invokercd_service_spec.rb +++ b/spec/unit/provider/service/invokercd_service_spec.rb @@ -30,15 +30,15 @@ describe Chef::Provider::Service::Invokercd, "load_current_resource" do @current_resource = Chef::Resource::Service.new("chef") @provider = Chef::Provider::Service::Invokercd.new(@new_resource, @run_context) - Chef::Resource::Service.stub!(:new).and_return(@current_resource) + Chef::Resource::Service.stub(:new).and_return(@current_resource) @stdout = StringIO.new(<<-PS) aj 7842 5057 0 21:26 pts/2 00:00:06 vi init.rb aj 7903 5016 0 21:26 pts/5 00:00:00 /bin/bash aj 8119 6041 0 21:34 pts/3 00:00:03 vi init_service_spec.rb PS - @status = mock("Status", :exitstatus => 0, :stdout => @stdout) - @provider.stub!(:shell_out!).and_return(@status) + @status = double("Status", :exitstatus => 0, :stdout => @stdout) + @provider.stub(:shell_out!).and_return(@status) end it "should create a current resource with the name of the new resource" do @@ -62,20 +62,20 @@ PS end it "should set running to true if the status command returns 0" do - @provider.stub!(:shell_out).with("/usr/sbin/invoke-rc.d #{@current_resource.service_name} status").and_return(@status) + @provider.stub(:shell_out).with("/usr/sbin/invoke-rc.d #{@current_resource.service_name} status").and_return(@status) @provider.load_current_resource @current_resource.running.should be_true end it "should set running to false if the status command returns anything except 0" do - @status.stub!(:exitstatus).and_return(1) - @provider.stub!(:shell_out).with("/usr/sbin/invoke-rc.d #{@current_resource.service_name} status").and_return(@status) + @status.stub(:exitstatus).and_return(1) + @provider.stub(:shell_out).with("/usr/sbin/invoke-rc.d #{@current_resource.service_name} status").and_return(@status) @provider.load_current_resource @current_resource.running.should be_false end it "should set running to false if the status command raises" do - @provider.stub!(:shell_out).with("/usr/sbin/invoke-rc.d #{@current_resource.service_name} status").and_raise(Mixlib::ShellOut::ShellCommandFailed) + @provider.stub(:shell_out).with("/usr/sbin/invoke-rc.d #{@current_resource.service_name} status").and_raise(Mixlib::ShellOut::ShellCommandFailed) @provider.load_current_resource @current_resource.running.should be_false end @@ -83,7 +83,7 @@ PS describe "when a status command has been specified" do before do - @new_resource.stub!(:status_command).and_return("/usr/sbin/invoke-rc.d chefhasmonkeypants status") + @new_resource.stub(:status_command).and_return("/usr/sbin/invoke-rc.d chefhasmonkeypants status") end it "should run the services status command if one has been specified" do @@ -113,7 +113,7 @@ PS describe "when we have a 'ps' attribute" do it "should shell_out! the node's ps command" do - @status = mock("Status", :exitstatus => 0, :stdout => @stdout) + @status = double("Status", :exitstatus => 0, :stdout => @stdout) @provider.should_receive(:shell_out!).with(@node[:command][:ps]).and_return(@status) @provider.load_current_resource end @@ -123,21 +123,21 @@ PS aj 7842 5057 0 21:26 pts/2 00:00:06 chef aj 7842 5057 0 21:26 pts/2 00:00:06 poos RUNNING_PS - @status = mock("Status", :exitstatus => 0, :stdout => @stdout) + @status = double("Status", :exitstatus => 0, :stdout => @stdout) @provider.should_receive(:shell_out!).and_return(@status) @provider.load_current_resource @current_resource.running.should be_true end it "should set running to false if the regex doesn't match" do - @status = mock("Status", :exitstatus => 0, :stdout => @stdout) + @status = double("Status", :exitstatus => 0, :stdout => @stdout) @provider.should_receive(:shell_out!).and_return(@status) @provider.load_current_resource @current_resource.running.should be_false end it "should raise an exception if ps fails" do - @provider.stub!(:shell_out!).and_raise(Mixlib::ShellOut::ShellCommandFailed) + @provider.stub(:shell_out!).and_raise(Mixlib::ShellOut::ShellCommandFailed) @provider.action = :start @provider.load_current_resource @provider.define_resource_requirements diff --git a/spec/unit/provider/service/macosx_spec.rb b/spec/unit/provider/service/macosx_spec.rb index 61bd5583e1..65639f2084 100644 --- a/spec/unit/provider/service/macosx_spec.rb +++ b/spec/unit/provider/service/macosx_spec.rb @@ -50,12 +50,12 @@ describe Chef::Provider::Service::Macosx do ["redis-server", "io.redis.redis-server"].each do |service_name| before do - Dir.stub!(:glob).and_return(["/Users/igor/Library/LaunchAgents/io.redis.redis-server.plist"], []) - provider.stub!(:shell_out!). + Dir.stub(:glob).and_return(["/Users/igor/Library/LaunchAgents/io.redis.redis-server.plist"], []) + provider.stub(:shell_out!). with("launchctl list", {:group => 1001, :user => 101}). - and_return(mock("ouput", :stdout => stdout)) + and_return(double("ouput", :stdout => stdout)) - File.stub!(:stat).and_return(mock("stat", :gid => 1001, :uid => 101)) + File.stub(:stat).and_return(double("stat", :gid => 1001, :uid => 101)) end context "#{service_name}" do @@ -85,7 +85,7 @@ describe Chef::Provider::Service::Macosx do describe "running unsupported actions" do before do - Dir.stub!(:glob).and_return(["/Users/igor/Library/LaunchAgents/io.redis.redis-server.plist"], []) + Dir.stub(:glob).and_return(["/Users/igor/Library/LaunchAgents/io.redis.redis-server.plist"], []) end it "should throw an exception when enable action is attempted" do lambda {provider.run_action(:enable)}.should raise_error(Chef::Exceptions::UnsupportedAction) @@ -130,7 +130,7 @@ describe Chef::Provider::Service::Macosx do context "and plist for service is not available" do before do - Dir.stub!(:glob).and_return([]) + Dir.stub(:glob).and_return([]) provider.load_current_resource end @@ -141,7 +141,7 @@ describe Chef::Provider::Service::Macosx do context "and plist for service is available" do before do - Dir.stub!(:glob).and_return(["/Users/igor/Library/LaunchAgents/io.redis.redis-server.plist"], []) + Dir.stub(:glob).and_return(["/Users/igor/Library/LaunchAgents/io.redis.redis-server.plist"], []) provider.load_current_resource end @@ -152,7 +152,7 @@ describe Chef::Provider::Service::Macosx do describe "and several plists match service name" do it "throws exception" do - Dir.stub!(:glob).and_return(["/Users/igor/Library/LaunchAgents/io.redis.redis-server.plist", + Dir.stub(:glob).and_return(["/Users/igor/Library/LaunchAgents/io.redis.redis-server.plist", "/Users/wtf/something.plist"]) provider.load_current_resource provider.define_resource_requirements @@ -163,20 +163,20 @@ describe Chef::Provider::Service::Macosx do end describe "#start_service" do before do - Chef::Resource::Service.stub!(:new).and_return(current_resource) + Chef::Resource::Service.stub(:new).and_return(current_resource) provider.load_current_resource - current_resource.stub!(:running).and_return(false) + current_resource.stub(:running).and_return(false) end it "calls the start command if one is specified and service is not running" do - new_resource.stub!(:start_command).and_return("cowsay dirty") + new_resource.stub(:start_command).and_return("cowsay dirty") provider.should_receive(:shell_out!).with("cowsay dirty") provider.start_service end it "shows warning message if service is already running" do - current_resource.stub!(:running).and_return(true) + current_resource.stub(:running).and_return(true) Chef::Log.should_receive(:debug).with("service[#{service_name}] already running, not starting") provider.start_service @@ -194,21 +194,21 @@ describe Chef::Provider::Service::Macosx do describe "#stop_service" do before do - Chef::Resource::Service.stub!(:new).and_return(current_resource) + Chef::Resource::Service.stub(:new).and_return(current_resource) provider.load_current_resource - current_resource.stub!(:running).and_return(true) + current_resource.stub(:running).and_return(true) end it "calls the stop command if one is specified and service is running" do - new_resource.stub!(:stop_command).and_return("kill -9 123") + new_resource.stub(:stop_command).and_return("kill -9 123") provider.should_receive(:shell_out!).with("kill -9 123") provider.stop_service end it "shows warning message if service is not running" do - current_resource.stub!(:running).and_return(false) + current_resource.stub(:running).and_return(false) Chef::Log.should_receive(:debug).with("service[#{service_name}] not running, not stopping") provider.stop_service @@ -226,15 +226,15 @@ describe Chef::Provider::Service::Macosx do describe "#restart_service" do before do - Chef::Resource::Service.stub!(:new).and_return(current_resource) + Chef::Resource::Service.stub(:new).and_return(current_resource) provider.load_current_resource - current_resource.stub!(:running).and_return(true) - provider.stub!(:sleep) + current_resource.stub(:running).and_return(true) + provider.stub(:sleep) end it "issues a command if given" do - new_resource.stub!(:restart_command).and_return("reload that thing") + new_resource.stub(:restart_command).and_return("reload that thing") provider.should_receive(:shell_out!).with("reload that thing") provider.restart_service diff --git a/spec/unit/provider/service/redhat_spec.rb b/spec/unit/provider/service/redhat_spec.rb index 3ce4301026..8cc6fb6549 100644 --- a/spec/unit/provider/service/redhat_spec.rb +++ b/spec/unit/provider/service/redhat_spec.rb @@ -21,18 +21,18 @@ require 'ostruct' shared_examples_for "define_resource_requirements_common" do it "should raise an error if /sbin/chkconfig does not exist" do - File.stub!(:exists?).with("/sbin/chkconfig").and_return(false) - @provider.stub!(:shell_out).with("/sbin/service chef status").and_raise(Errno::ENOENT) - @provider.stub!(:shell_out!).with("/sbin/chkconfig --list chef", :returns => [0,1]).and_raise(Errno::ENOENT) + File.stub(:exists?).with("/sbin/chkconfig").and_return(false) + @provider.stub(:shell_out).with("/sbin/service chef status").and_raise(Errno::ENOENT) + @provider.stub(:shell_out!).with("/sbin/chkconfig --list chef", :returns => [0,1]).and_raise(Errno::ENOENT) @provider.load_current_resource @provider.define_resource_requirements lambda { @provider.process_resource_requirements }.should raise_error(Chef::Exceptions::Service) end it "should not raise an error if the service exists but is not added to any runlevels" do - status = mock("Status", :exitstatus => 0, :stdout => "" , :stderr => "") + status = double("Status", :exitstatus => 0, :stdout => "" , :stderr => "") @provider.should_receive(:shell_out).with("/sbin/service chef status").and_return(status) - chkconfig = mock("Chkconfig", :exitstatus => 0, :stdout => "", :stderr => "service chef supports chkconfig, but is not referenced in any runlevel (run 'chkconfig --add chef')") + chkconfig = double("Chkconfig", :exitstatus => 0, :stdout => "", :stderr => "service chef supports chkconfig, but is not referenced in any runlevel (run 'chkconfig --add chef')") @provider.should_receive(:shell_out!).with("/sbin/chkconfig --list chef", :returns => [0,1]).and_return(chkconfig) @provider.load_current_resource @provider.define_resource_requirements @@ -54,8 +54,8 @@ describe "Chef::Provider::Service::Redhat" do @provider = Chef::Provider::Service::Redhat.new(@new_resource, @run_context) @provider.action = :start - Chef::Resource::Service.stub!(:new).and_return(@current_resource) - File.stub!(:exists?).with("/sbin/chkconfig").and_return(true) + Chef::Resource::Service.stub(:new).and_return(@current_resource) + File.stub(:exists?).with("/sbin/chkconfig").and_return(true) end describe "while not in why run mode" do @@ -65,9 +65,9 @@ describe "Chef::Provider::Service::Redhat" do describe "load current resource" do it "sets the current enabled status to true if the service is enabled for any run level" do - status = mock("Status", :exitstatus => 0, :stdout => "" , :stderr => "") + status = double("Status", :exitstatus => 0, :stdout => "" , :stderr => "") @provider.should_receive(:shell_out).with("/sbin/service chef status").and_return(status) - chkconfig = mock("Chkconfig", :exitstatus => 0, :stdout => "chef 0:off 1:off 2:off 3:off 4:off 5:on 6:off", :stderr => "") + chkconfig = double("Chkconfig", :exitstatus => 0, :stdout => "chef 0:off 1:off 2:off 3:off 4:off 5:on 6:off", :stderr => "") @provider.should_receive(:shell_out!).with("/sbin/chkconfig --list chef", :returns => [0,1]).and_return(chkconfig) @provider.instance_variable_get("@service_missing").should be_false @provider.load_current_resource @@ -75,9 +75,9 @@ describe "Chef::Provider::Service::Redhat" do end it "sets the current enabled status to false if the regex does not match" do - status = mock("Status", :exitstatus => 0, :stdout => "" , :stderr => "") + status = double("Status", :exitstatus => 0, :stdout => "" , :stderr => "") @provider.should_receive(:shell_out).with("/sbin/service chef status").and_return(status) - chkconfig = mock("Chkconfig", :exitstatus => 0, :stdout => "chef 0:off 1:off 2:off 3:off 4:off 5:off 6:off", :stderr => "") + chkconfig = double("Chkconfig", :exitstatus => 0, :stdout => "chef 0:off 1:off 2:off 3:off 4:off 5:off 6:off", :stderr => "") @provider.should_receive(:shell_out!).with("/sbin/chkconfig --list chef", :returns => [0,1]).and_return(chkconfig) @provider.instance_variable_get("@service_missing").should be_false @provider.load_current_resource.should eql(@current_resource) @@ -90,9 +90,9 @@ describe "Chef::Provider::Service::Redhat" do context "when the service does not exist" do before do - status = mock("Status", :exitstatus => 1, :stdout => "", :stderr => "chef: unrecognized service") + status = double("Status", :exitstatus => 1, :stdout => "", :stderr => "chef: unrecognized service") @provider.should_receive(:shell_out).with("/sbin/service chef status").and_return(status) - chkconfig = mock("Chkconfig", :existatus=> 1, :stdout => "", :stderr => "error reading information on service chef: No such file or directory") + chkconfig = double("Chkconfig", :existatus=> 1, :stdout => "", :stderr => "error reading information on service chef: No such file or directory") @provider.should_receive(:shell_out!).with("/sbin/chkconfig --list chef", :returns => [0,1]).and_return(chkconfig) @provider.load_current_resource @provider.define_resource_requirements @@ -128,9 +128,9 @@ describe "Chef::Provider::Service::Redhat" do it_should_behave_like "define_resource_requirements_common" it "should not raise an error if the service does not exist" do - status = mock("Status", :exitstatus => 1, :stdout => "", :stderr => "chef: unrecognized service") + status = double("Status", :exitstatus => 1, :stdout => "", :stderr => "chef: unrecognized service") @provider.should_receive(:shell_out).with("/sbin/service chef status").and_return(status) - chkconfig = mock("Chkconfig", :existatus=> 1, :stdout => "", :stderr => "error reading information on service chef: No such file or directory") + chkconfig = double("Chkconfig", :existatus=> 1, :stdout => "", :stderr => "error reading information on service chef: No such file or directory") @provider.should_receive(:shell_out!).with("/sbin/chkconfig --list chef", :returns => [0,1]).and_return(chkconfig) @provider.load_current_resource @provider.define_resource_requirements diff --git a/spec/unit/provider/service/simple_service_spec.rb b/spec/unit/provider/service/simple_service_spec.rb index 73cb3766d2..1d94534320 100644 --- a/spec/unit/provider/service/simple_service_spec.rb +++ b/spec/unit/provider/service/simple_service_spec.rb @@ -29,15 +29,15 @@ describe Chef::Provider::Service::Simple, "load_current_resource" do @current_resource = Chef::Resource::Service.new("chef") @provider = Chef::Provider::Service::Simple.new(@new_resource, @run_context) - Chef::Resource::Service.stub!(:new).and_return(@current_resource) + Chef::Resource::Service.stub(:new).and_return(@current_resource) @stdout = StringIO.new(<<-NOMOCKINGSTRINGSPLZ) aj 7842 5057 0 21:26 pts/2 00:00:06 vi init.rb aj 7903 5016 0 21:26 pts/5 00:00:00 /bin/bash aj 8119 6041 0 21:34 pts/3 00:00:03 vi simple_service_spec.rb NOMOCKINGSTRINGSPLZ - @status = mock("Status", :exitstatus => 0, :stdout => @stdout) - @provider.stub!(:shell_out!).and_return(@status) + @status = double("Status", :exitstatus => 0, :stdout => @stdout) + @provider.stub(:shell_out!).and_return(@status) end it "should create a current resource with the name of the new resource" do @@ -69,7 +69,7 @@ NOMOCKINGSTRINGSPLZ end it "should read stdout of the ps command" do - @provider.stub!(:shell_out!).and_return(@status) + @provider.stub(:shell_out!).and_return(@status) @stdout.should_receive(:each_line).and_return(true) @provider.load_current_resource end @@ -79,20 +79,20 @@ NOMOCKINGSTRINGSPLZ aj 7842 5057 0 21:26 pts/2 00:00:06 chef aj 7842 5057 0 21:26 pts/2 00:00:06 poos NOMOCKINGSTRINGSPLZ - @status = mock("Status", :exitstatus => 0, :stdout => @stdout) - @provider.stub!(:shell_out!).and_return(@status) + @status = double("Status", :exitstatus => 0, :stdout => @stdout) + @provider.stub(:shell_out!).and_return(@status) @provider.load_current_resource @current_resource.running.should be_true end it "should set running to false if the regex doesn't match" do - @provider.stub!(:shell_out!).and_return(@status) + @provider.stub(:shell_out!).and_return(@status) @provider.load_current_resource @current_resource.running.should be_false end it "should raise an exception if ps fails" do - @provider.stub!(:shell_out!).and_raise(Mixlib::ShellOut::ShellCommandFailed) + @provider.stub(:shell_out!).and_raise(Mixlib::ShellOut::ShellCommandFailed) @provider.action = :start @provider.load_current_resource @provider.define_resource_requirements @@ -108,7 +108,7 @@ NOMOCKINGSTRINGSPLZ describe "when starting the service" do it "should call the start command if one is specified" do - @new_resource.stub!(:start_command).and_return("#{@new_resource.start_command}") + @new_resource.stub(:start_command).and_return("#{@new_resource.start_command}") @provider.should_receive(:shell_out!).with("#{@new_resource.start_command}") @provider.start_service() end diff --git a/spec/unit/provider/service/solaris_smf_service_spec.rb b/spec/unit/provider/service/solaris_smf_service_spec.rb index 64afee078c..887c1f6b5f 100644 --- a/spec/unit/provider/service/solaris_smf_service_spec.rb +++ b/spec/unit/provider/service/solaris_smf_service_spec.rb @@ -29,16 +29,16 @@ describe Chef::Provider::Service::Solaris do @current_resource = Chef::Resource::Service.new('chef') @provider = Chef::Provider::Service::Solaris.new(@new_resource, @run_context) - Chef::Resource::Service.stub!(:new).and_return(@current_resource) + Chef::Resource::Service.stub(:new).and_return(@current_resource) @stdin = StringIO.new @stdout = StringIO.new @stderr = StringIO.new @pid = 2342 @stdout_string = "state disabled" - @stdout.stub!(:gets).and_return(@stdout_string) - @status = mock("Status", :exitstatus => 0, :stdout => @stdout) - @provider.stub!(:shell_out!).and_return(@status) + @stdout.stub(:gets).and_return(@stdout_string) + @status = double("Status", :exitstatus => 0, :stdout => @stdout) + @provider.stub(:shell_out!).and_return(@status) end it "should raise an error if /bin/svcs does not exist" do @@ -49,19 +49,19 @@ describe Chef::Provider::Service::Solaris do describe "on a host with /bin/svcs" do before do - File.stub!(:exists?).with('/bin/svcs').and_return(true) + File.stub(:exists?).with('/bin/svcs').and_return(true) end describe "when discovering the current service state" do it "should create a current resource with the name of the new resource" do - @provider.stub!(:popen4).with("/bin/svcs -l chef").and_return(@status) + @provider.stub(:popen4).with("/bin/svcs -l chef").and_return(@status) Chef::Resource::Service.should_receive(:new).and_return(@current_resource) @provider.load_current_resource end it "should return the current resource" do - @provider.stub!(:popen4).with("/bin/svcs -l chef").and_return(@status) + @provider.stub(:popen4).with("/bin/svcs -l chef").and_return(@status) @provider.load_current_resource.should eql(@current_resource) end @@ -71,14 +71,14 @@ describe Chef::Provider::Service::Solaris do end it "should mark service as not running" do - @provider.stub!(:popen4).and_yield(@pid, @stdin, @stdout, @stderr).and_return(@status) + @provider.stub(:popen4).and_yield(@pid, @stdin, @stdout, @stderr).and_return(@status) @current_resource.should_receive(:running).with(false) @provider.load_current_resource end it "should mark service as running" do - @stdout.stub!(:each).and_yield("state online") - @provider.stub!(:popen4).and_yield(@pid, @stdin, @stdout, @stderr).and_return(@status) + @stdout.stub(:each).and_yield("state online") + @provider.stub(:popen4).and_yield(@pid, @stdin, @stdout, @stderr).and_return(@status) @current_resource.should_receive(:running).with(true) @provider.load_current_resource end @@ -91,14 +91,14 @@ describe Chef::Provider::Service::Solaris do end it "should call svcadm enable -s chef" do - @new_resource.stub!(:enable_command).and_return("#{@new_resource.enable_command}") + @new_resource.stub(:enable_command).and_return("#{@new_resource.enable_command}") @provider.should_receive(:shell_out!).with("/usr/sbin/svcadm enable -s #{@current_resource.service_name}").and_return(@status) @provider.enable_service.should be_true @current_resource.enabled.should be_true end it "should call svcadm enable -s chef for start_service" do - @new_resource.stub!(:start_command).and_return("#{@new_resource.start_command}") + @new_resource.stub(:start_command).and_return("#{@new_resource.start_command}") @provider.should_receive(:shell_out!).with("/usr/sbin/svcadm enable -s #{@current_resource.service_name}").and_return(@status) @provider.start_service.should be_true @current_resource.enabled.should be_true @@ -129,7 +129,7 @@ describe Chef::Provider::Service::Solaris do describe "when reloading the service" do before(:each) do - @status = mock("Process::Status", :exitstatus => 0) + @status = double("Process::Status", :exitstatus => 0) @provider.current_resource = @current_resource end diff --git a/spec/unit/provider/service/systemd_service_spec.rb b/spec/unit/provider/service/systemd_service_spec.rb index a107888b0b..f631bfc31d 100644 --- a/spec/unit/provider/service/systemd_service_spec.rb +++ b/spec/unit/provider/service/systemd_service_spec.rb @@ -30,10 +30,10 @@ describe Chef::Provider::Service::Systemd do describe "load_current_resource" do before(:each) do @current_resource = Chef::Resource::Service.new('rsyslog.service') - Chef::Resource::Service.stub!(:new).and_return(@current_resource) + Chef::Resource::Service.stub(:new).and_return(@current_resource) - @provider.stub!(:is_active?).and_return(false) - @provider.stub!(:is_enabled?).and_return(false) + @provider.stub(:is_active?).and_return(false) + @provider.stub(:is_enabled?).and_return(false) end it "should create a current resource with the name of the new resource" do @@ -52,42 +52,42 @@ describe Chef::Provider::Service::Systemd do end it "should set running to true if the service is running" do - @provider.stub!(:is_active?).and_return(true) + @provider.stub(:is_active?).and_return(true) @current_resource.should_receive(:running).with(true) @provider.load_current_resource end it "should set running to false if the service is not running" do - @provider.stub!(:is_active?).and_return(false) + @provider.stub(:is_active?).and_return(false) @current_resource.should_receive(:running).with(false) @provider.load_current_resource end describe "when a status command has been specified" do before do - @new_resource.stub!(:status_command).and_return("/bin/chefhasmonkeypants status") + @new_resource.stub(:status_command).and_return("/bin/chefhasmonkeypants status") end it "should run the services status command if one has been specified" do - @provider.stub!(:run_command_with_systems_locale).with({:command => "/bin/chefhasmonkeypants status"}).and_return(0) + @provider.stub(:run_command_with_systems_locale).with({:command => "/bin/chefhasmonkeypants status"}).and_return(0) @current_resource.should_receive(:running).with(true) @provider.load_current_resource end it "should run the services status command if one has been specified and properly set status check state" do - @provider.stub!(:run_command_with_systems_locale).with({:command => "/bin/chefhasmonkeypants status"}).and_return(0) + @provider.stub(:run_command_with_systems_locale).with({:command => "/bin/chefhasmonkeypants status"}).and_return(0) @provider.load_current_resource @provider.instance_variable_get("@status_check_success").should be_true end it "should set running to false if it catches a Chef::Exceptions::Exec when using a status command" do - @provider.stub!(:run_command_with_systems_locale).and_raise(Chef::Exceptions::Exec) + @provider.stub(:run_command_with_systems_locale).and_raise(Chef::Exceptions::Exec) @current_resource.should_receive(:running).with(false) @provider.load_current_resource end it "should update state to indicate status check failed when an exception is thrown using a status command" do - @provider.stub!(:run_command_with_systems_locale).and_raise(Chef::Exceptions::Exec) + @provider.stub(:run_command_with_systems_locale).and_raise(Chef::Exceptions::Exec) @provider.load_current_resource @provider.instance_variable_get("@status_check_success").should be_false end @@ -99,13 +99,13 @@ describe Chef::Provider::Service::Systemd do end it "should set enabled to true if the service is enabled" do - @provider.stub!(:is_enabled?).and_return(true) + @provider.stub(:is_enabled?).and_return(true) @current_resource.should_receive(:enabled).with(true) @provider.load_current_resource end it "should set enabled to false if the service is not enabled" do - @provider.stub!(:is_enabled?).and_return(false) + @provider.stub(:is_enabled?).and_return(false) @current_resource.should_receive(:enabled).with(false) @provider.load_current_resource end @@ -118,12 +118,12 @@ describe Chef::Provider::Service::Systemd do describe "start and stop service" do before(:each) do @current_resource = Chef::Resource::Service.new('rsyslog.service') - Chef::Resource::Service.stub!(:new).and_return(@current_resource) + Chef::Resource::Service.stub(:new).and_return(@current_resource) @provider.current_resource = @current_resource end it "should call the start command if one is specified" do - @new_resource.stub!(:start_command).and_return("/sbin/rsyslog startyousillysally") + @new_resource.stub(:start_command).and_return("/sbin/rsyslog startyousillysally") @provider.should_receive(:shell_out!).with("/sbin/rsyslog startyousillysally") @provider.start_service end @@ -134,52 +134,52 @@ describe Chef::Provider::Service::Systemd do end it "should not call '/bin/systemctl start service_name' if it is already running" do - @current_resource.stub!(:running).and_return(true) + @current_resource.stub(:running).and_return(true) @provider.should_not_receive(:run_command_with_systems_locale).with({:command => "/bin/systemctl start #{@new_resource.service_name}"}) @provider.start_service end it "should call the restart command if one is specified" do - @current_resource.stub!(:running).and_return(true) - @new_resource.stub!(:restart_command).and_return("/sbin/rsyslog restartyousillysally") + @current_resource.stub(:running).and_return(true) + @new_resource.stub(:restart_command).and_return("/sbin/rsyslog restartyousillysally") @provider.should_receive(:shell_out!).with("/sbin/rsyslog restartyousillysally") @provider.restart_service end it "should call '/bin/systemctl restart service_name' if no restart command is specified" do - @current_resource.stub!(:running).and_return(true) + @current_resource.stub(:running).and_return(true) @provider.should_receive(:run_command_with_systems_locale).with({:command => "/bin/systemctl restart #{@new_resource.service_name}"}).and_return(0) @provider.restart_service end it "should call the reload command if one is specified" do - @current_resource.stub!(:running).and_return(true) - @new_resource.stub!(:reload_command).and_return("/sbin/rsyslog reloadyousillysally") + @current_resource.stub(:running).and_return(true) + @new_resource.stub(:reload_command).and_return("/sbin/rsyslog reloadyousillysally") @provider.should_receive(:shell_out!).with("/sbin/rsyslog reloadyousillysally") @provider.reload_service end it "should call '/bin/systemctl reload service_name' if no reload command is specified" do - @current_resource.stub!(:running).and_return(true) + @current_resource.stub(:running).and_return(true) @provider.should_receive(:run_command_with_systems_locale).with({:command => "/bin/systemctl reload #{@new_resource.service_name}"}).and_return(0) @provider.reload_service end it "should call the stop command if one is specified" do - @current_resource.stub!(:running).and_return(true) - @new_resource.stub!(:stop_command).and_return("/sbin/rsyslog stopyousillysally") + @current_resource.stub(:running).and_return(true) + @new_resource.stub(:stop_command).and_return("/sbin/rsyslog stopyousillysally") @provider.should_receive(:shell_out!).with("/sbin/rsyslog stopyousillysally") @provider.stop_service end it "should call '/bin/systemctl stop service_name' if no stop command is specified" do - @current_resource.stub!(:running).and_return(true) + @current_resource.stub(:running).and_return(true) @provider.should_receive(:run_command_with_systems_locale).with({:command => "/bin/systemctl stop #{@new_resource.service_name}"}).and_return(0) @provider.stop_service end it "should not call '/bin/systemctl stop service_name' if it is already stopped" do - @current_resource.stub!(:running).and_return(false) + @current_resource.stub(:running).and_return(false) @provider.should_not_receive(:run_command_with_systems_locale).with({:command => "/bin/systemctl stop #{@new_resource.service_name}"}) @provider.stop_service end @@ -188,7 +188,7 @@ describe Chef::Provider::Service::Systemd do describe "enable and disable service" do before(:each) do @current_resource = Chef::Resource::Service.new('rsyslog.service') - Chef::Resource::Service.stub!(:new).and_return(@current_resource) + Chef::Resource::Service.stub(:new).and_return(@current_resource) @provider.current_resource = @current_resource end @@ -206,7 +206,7 @@ describe Chef::Provider::Service::Systemd do describe "is_active?" do before(:each) do @current_resource = Chef::Resource::Service.new('rsyslog.service') - Chef::Resource::Service.stub!(:new).and_return(@current_resource) + Chef::Resource::Service.stub(:new).and_return(@current_resource) end it "should return true if '/bin/systemctl is-active service_name' returns 0" do @@ -223,7 +223,7 @@ describe Chef::Provider::Service::Systemd do describe "is_enabled?" do before(:each) do @current_resource = Chef::Resource::Service.new('rsyslog.service') - Chef::Resource::Service.stub!(:new).and_return(@current_resource) + Chef::Resource::Service.stub(:new).and_return(@current_resource) end it "should return true if '/bin/systemctl is-enabled service_name' returns 0" do diff --git a/spec/unit/provider/service/upstart_service_spec.rb b/spec/unit/provider/service/upstart_service_spec.rb index 8628a4eaf7..154527a7da 100644 --- a/spec/unit/provider/service/upstart_service_spec.rb +++ b/spec/unit/provider/service/upstart_service_spec.rb @@ -39,7 +39,7 @@ describe Chef::Provider::Service::Upstart do it "should return /etc/event.d as the upstart job directory when running on Ubuntu 9.04" do @node.automatic_attrs[:platform_version] = '9.04' - #Chef::Platform.stub!(:find_platform_and_version).and_return([ "ubuntu", "9.04" ]) + #Chef::Platform.stub(:find_platform_and_version).and_return([ "ubuntu", "9.04" ]) @provider = Chef::Provider::Service::Upstart.new(@new_resource, @run_context) @provider.instance_variable_get(:@upstart_job_dir).should == "/etc/event.d" @provider.instance_variable_get(:@upstart_conf_suffix).should == "" @@ -65,17 +65,17 @@ describe Chef::Provider::Service::Upstart do @node.automatic_attrs[:command] = {:ps => "ps -ax"} @current_resource = Chef::Resource::Service.new("rsyslog") - Chef::Resource::Service.stub!(:new).and_return(@current_resource) + Chef::Resource::Service.stub(:new).and_return(@current_resource) - @status = mock("Status", :exitstatus => 0) - @provider.stub!(:popen4).and_return(@status) + @status = double("Status", :exitstatus => 0) + @provider.stub(:popen4).and_return(@status) @stdin = StringIO.new @stdout = StringIO.new @stderr = StringIO.new - @pid = mock("PID") + @pid = double("PID") - ::File.stub!(:exists?).and_return(true) - ::File.stub!(:open).and_return(true) + ::File.stub(:exists?).and_return(true) + ::File.stub(:open).and_return(true) end it "should create a current resource with the name of the new resource" do @@ -99,14 +99,14 @@ describe Chef::Provider::Service::Upstart do it "should set running to true if the status command returns 0" do @stdout = StringIO.new("rsyslog start/running") - @provider.stub!(:popen4).and_yield(@pid, @stdin, @stdout, @stderr).and_return(@status) + @provider.stub(:popen4).and_yield(@pid, @stdin, @stdout, @stderr).and_return(@status) @provider.load_current_resource @current_resource.running.should be_true end it "should set running to false if the status command returns anything except 0" do @stdout = StringIO.new("rsyslog stop/waiting") - @provider.stub!(:popen4).and_yield(@pid, @stdin, @stdout, @stderr).and_return(@status) + @provider.stub(:popen4).and_yield(@pid, @stdin, @stdout, @stderr).and_return(@status) @provider.load_current_resource @current_resource.running.should be_false end @@ -115,41 +115,41 @@ describe Chef::Provider::Service::Upstart do describe "when the status command uses the old format" do it "should set running to true if the status command returns 0" do @stdout = StringIO.new("rsyslog (start) running, process 32225") - @provider.stub!(:popen4).and_yield(@pid, @stdin, @stdout, @stderr).and_return(@status) + @provider.stub(:popen4).and_yield(@pid, @stdin, @stdout, @stderr).and_return(@status) @provider.load_current_resource @current_resource.running.should be_true end it "should set running to false if the status command returns anything except 0" do @stdout = StringIO.new("rsyslog (stop) waiting") - @provider.stub!(:popen4).and_yield(@pid, @stdin, @stdout, @stderr).and_return(@status) + @provider.stub(:popen4).and_yield(@pid, @stdin, @stdout, @stderr).and_return(@status) @provider.load_current_resource @current_resource.running.should be_false end end it "should set running to false if it catches a Chef::Exceptions::Exec" do - @provider.stub!(:popen4).and_yield(@pid, @stdin, @stdout, @stderr).and_raise(Chef::Exceptions::Exec) + @provider.stub(:popen4).and_yield(@pid, @stdin, @stdout, @stderr).and_raise(Chef::Exceptions::Exec) @current_resource.should_receive(:running).with(false) @provider.load_current_resource end it "should set enabled to true when it finds 'starts on'" do - @lines = mock("start on filesystem", :gets => "start on filesystem") - ::File.stub!(:open).and_yield(@lines) + @lines = double("start on filesystem", :gets => "start on filesystem") + ::File.stub(:open).and_yield(@lines) @current_resource.should_receive(:running).with(false) @provider.load_current_resource end it "should set enabled to false when it finds '#starts on'" do - @lines = mock("start on filesystem", :gets => "#start on filesystem") - ::File.stub!(:open).and_yield(@lines) + @lines = double("start on filesystem", :gets => "#start on filesystem") + ::File.stub(:open).and_yield(@lines) @current_resource.should_receive(:running).with(false) @provider.load_current_resource end it "should assume disable when no job configuration file is found" do - ::File.stub!(:exists?).and_return(false) + ::File.stub(:exists?).and_return(false) @current_resource.should_receive(:running).with(false) @provider.load_current_resource end @@ -163,23 +163,23 @@ describe Chef::Provider::Service::Upstart do describe "when a status command has been specified" do before do - @new_resource.stub!(:status_command).and_return("/bin/chefhasmonkeypants status") + @new_resource.stub(:status_command).and_return("/bin/chefhasmonkeypants status") end it "should run the services status command if one has been specified" do - @provider.stub!(:run_command_with_systems_locale).with({:command => "/bin/chefhasmonkeypants status"}).and_return(0) + @provider.stub(:run_command_with_systems_locale).with({:command => "/bin/chefhasmonkeypants status"}).and_return(0) @current_resource.should_receive(:running).with(true) @provider.load_current_resource end it "should track state when the user-provided status command fails" do - @provider.stub!(:popen4).and_yield(@pid, @stdin, @stdout, @stderr).and_raise(Chef::Exceptions::Exec) + @provider.stub(:popen4).and_yield(@pid, @stdin, @stdout, @stderr).and_raise(Chef::Exceptions::Exec) @provider.load_current_resource @provider.instance_variable_get("@command_success").should == false end it "should set running to false if it catches a Chef::Exceptions::Exec when using a status command" do - @provider.stub!(:popen4).and_yield(@pid, @stdin, @stdout, @stderr).and_raise(Chef::Exceptions::Exec) + @provider.stub(:popen4).and_yield(@pid, @stdin, @stdout, @stderr).and_raise(Chef::Exceptions::Exec) @current_resource.should_receive(:running).with(false) @provider.load_current_resource end @@ -201,15 +201,15 @@ describe Chef::Provider::Service::Upstart do describe "enable and disable service" do before(:each) do @current_resource = Chef::Resource::Service.new('rsyslog') - Chef::Resource::Service.stub!(:new).and_return(@current_resource) + Chef::Resource::Service.stub(:new).and_return(@current_resource) @provider.current_resource = @current_resource - Chef::Util::FileEdit.stub!(:new) + Chef::Util::FileEdit.stub(:new) end it "should enable the service if it is not enabled" do @file = Object.new - Chef::Util::FileEdit.stub!(:new).and_return(@file) - @current_resource.stub!(:enabled).and_return(false) + Chef::Util::FileEdit.stub(:new).and_return(@file) + @current_resource.stub(:enabled).and_return(false) @file.should_receive(:search_file_replace) @file.should_receive(:write_file) @provider.enable_service() @@ -217,8 +217,8 @@ describe Chef::Provider::Service::Upstart do it "should disable the service if it is enabled" do @file = Object.new - Chef::Util::FileEdit.stub!(:new).and_return(@file) - @current_resource.stub!(:enabled).and_return(true) + Chef::Util::FileEdit.stub(:new).and_return(@file) + @current_resource.stub(:enabled).and_return(true) @file.should_receive(:search_file_replace) @file.should_receive(:write_file) @provider.disable_service() @@ -230,12 +230,12 @@ describe Chef::Provider::Service::Upstart do before(:each) do @current_resource = Chef::Resource::Service.new('rsyslog') - Chef::Resource::Service.stub!(:new).and_return(@current_resource) + Chef::Resource::Service.stub(:new).and_return(@current_resource) @provider.current_resource = @current_resource end it "should call the start command if one is specified" do - @new_resource.stub!(:start_command).and_return("/sbin/rsyslog startyousillysally") + @new_resource.stub(:start_command).and_return("/sbin/rsyslog startyousillysally") @provider.should_receive(:shell_out!).with("/sbin/rsyslog startyousillysally") @provider.start_service() end @@ -246,7 +246,7 @@ describe Chef::Provider::Service::Upstart do end it "should not call '/sbin/start service_name' if it is already running" do - @current_resource.stub!(:running).and_return(true) + @current_resource.stub(:running).and_return(true) @provider.should_not_receive(:run_command_with_systems_locale).with({:command => "/sbin/start #{@new_resource.service_name}"}) @provider.start_service() end @@ -261,52 +261,52 @@ describe Chef::Provider::Service::Upstart do end it "should call the restart command if one is specified" do - @current_resource.stub!(:running).and_return(true) - @new_resource.stub!(:restart_command).and_return("/sbin/rsyslog restartyousillysally") + @current_resource.stub(:running).and_return(true) + @new_resource.stub(:restart_command).and_return("/sbin/rsyslog restartyousillysally") @provider.should_receive(:shell_out!).with("/sbin/rsyslog restartyousillysally") @provider.restart_service() end it "should call '/sbin/restart service_name' if no restart command is specified" do - @current_resource.stub!(:running).and_return(true) + @current_resource.stub(:running).and_return(true) @provider.should_receive(:run_command_with_systems_locale).with({:command => "/sbin/restart #{@new_resource.service_name}"}).and_return(0) @provider.restart_service() end it "should call '/sbin/start service_name' if restart_service is called for a stopped service" do - @current_resource.stub!(:running).and_return(false) + @current_resource.stub(:running).and_return(false) @provider.should_receive(:run_command_with_systems_locale).with({:command => "/sbin/start #{@new_resource.service_name}"}).and_return(0) @provider.restart_service() end it "should call the reload command if one is specified" do - @current_resource.stub!(:running).and_return(true) - @new_resource.stub!(:reload_command).and_return("/sbin/rsyslog reloadyousillysally") + @current_resource.stub(:running).and_return(true) + @new_resource.stub(:reload_command).and_return("/sbin/rsyslog reloadyousillysally") @provider.should_receive(:shell_out!).with("/sbin/rsyslog reloadyousillysally") @provider.reload_service() end it "should call '/sbin/reload service_name' if no reload command is specified" do - @current_resource.stub!(:running).and_return(true) + @current_resource.stub(:running).and_return(true) @provider.should_receive(:run_command_with_systems_locale).with({:command => "/sbin/reload #{@new_resource.service_name}"}).and_return(0) @provider.reload_service() end it "should call the stop command if one is specified" do - @current_resource.stub!(:running).and_return(true) - @new_resource.stub!(:stop_command).and_return("/sbin/rsyslog stopyousillysally") + @current_resource.stub(:running).and_return(true) + @new_resource.stub(:stop_command).and_return("/sbin/rsyslog stopyousillysally") @provider.should_receive(:shell_out!).with("/sbin/rsyslog stopyousillysally") @provider.stop_service() end it "should call '/sbin/stop service_name' if no stop command is specified" do - @current_resource.stub!(:running).and_return(true) + @current_resource.stub(:running).and_return(true) @provider.should_receive(:run_command_with_systems_locale).with({:command => "/sbin/stop #{@new_resource.service_name}"}).and_return(0) @provider.stop_service() end it "should not call '/sbin/stop service_name' if it is already stopped" do - @current_resource.stub!(:running).and_return(false) + @current_resource.stub(:running).and_return(false) @provider.should_not_receive(:run_command_with_systems_locale).with({:command => "/sbin/stop #{@new_resource.service_name}"}) @provider.stop_service() end diff --git a/spec/unit/provider/service/windows_spec.rb b/spec/unit/provider/service/windows_spec.rb index 7ec4ccf96a..08f5a81a9d 100644 --- a/spec/unit/provider/service/windows_spec.rb +++ b/spec/unit/provider/service/windows_spec.rb @@ -31,11 +31,11 @@ describe Chef::Provider::Service::Windows, "load_current_resource" do Win32::Service = Class.new Win32::Service::AUTO_START = 0x00000002 Win32::Service::DISABLED = 0x00000004 - Win32::Service.stub!(:status).with(@new_resource.service_name).and_return( - mock("StatusStruct", :current_state => "running")) - Win32::Service.stub!(:config_info).with(@new_resource.service_name).and_return( - mock("ConfigStruct", :start_type => "auto start")) - Win32::Service.stub!(:exists?).and_return(true) + Win32::Service.stub(:status).with(@new_resource.service_name).and_return( + double("StatusStruct", :current_state => "running")) + Win32::Service.stub(:config_info).with(@new_resource.service_name).and_return( + double("ConfigStruct", :start_type => "auto start")) + Win32::Service.stub(:exists?).and_return(true) end it "should set the current resources service name to the new resources service name" do @@ -59,9 +59,9 @@ describe Chef::Provider::Service::Windows, "load_current_resource" do describe Chef::Provider::Service::Windows, "start_service" do before(:each) do - Win32::Service.stub!(:status).with(@new_resource.service_name).and_return( - mock("StatusStruct", :current_state => "stopped"), - mock("StatusStruct", :current_state => "running")) + Win32::Service.stub(:status).with(@new_resource.service_name).and_return( + double("StatusStruct", :current_state => "stopped"), + double("StatusStruct", :current_state => "running")) end it "should call the start command if one is specified" do @@ -78,15 +78,15 @@ describe Chef::Provider::Service::Windows, "load_current_resource" do end it "should do nothing if the service does not exist" do - Win32::Service.stub!(:exists?).with(@new_resource.service_name).and_return(false) + Win32::Service.stub(:exists?).with(@new_resource.service_name).and_return(false) Win32::Service.should_not_receive(:start).with(@new_resource.service_name) @provider.start_service @new_resource.updated_by_last_action?.should be_false end it "should do nothing if the service is running" do - Win32::Service.stub!(:status).with(@new_resource.service_name).and_return( - mock("StatusStruct", :current_state => "running")) + Win32::Service.stub(:status).with(@new_resource.service_name).and_return( + double("StatusStruct", :current_state => "running")) @provider.load_current_resource Win32::Service.should_not_receive(:start).with(@new_resource.service_name) @provider.start_service @@ -97,9 +97,9 @@ describe Chef::Provider::Service::Windows, "load_current_resource" do describe Chef::Provider::Service::Windows, "stop_service" do before(:each) do - Win32::Service.stub!(:status).with(@new_resource.service_name).and_return( - mock("StatusStruct", :current_state => "running"), - mock("StatusStruct", :current_state => "stopped")) + Win32::Service.stub(:status).with(@new_resource.service_name).and_return( + double("StatusStruct", :current_state => "running"), + double("StatusStruct", :current_state => "stopped")) end it "should call the stop command if one is specified" do @@ -116,15 +116,15 @@ describe Chef::Provider::Service::Windows, "load_current_resource" do end it "should do nothing if the service does not exist" do - Win32::Service.stub!(:exists?).with(@new_resource.service_name).and_return(false) + Win32::Service.stub(:exists?).with(@new_resource.service_name).and_return(false) Win32::Service.should_not_receive(:stop).with(@new_resource.service_name) @provider.stop_service @new_resource.updated_by_last_action?.should be_false end it "should do nothing if the service is stopped" do - Win32::Service.stub!(:status).with(@new_resource.service_name).and_return( - mock("StatusStruct", :current_state => "stopped")) + Win32::Service.stub(:status).with(@new_resource.service_name).and_return( + double("StatusStruct", :current_state => "stopped")) @provider.load_current_resource Win32::Service.should_not_receive(:stop).with(@new_resource.service_name) @provider.stop_service @@ -142,11 +142,11 @@ describe Chef::Provider::Service::Windows, "load_current_resource" do end it "should stop then start the service if it is running" do - Win32::Service.stub!(:status).with(@new_resource.service_name).and_return( - mock("StatusStruct", :current_state => "running"), - mock("StatusStruct", :current_state => "stopped"), - mock("StatusStruct", :current_state => "stopped"), - mock("StatusStruct", :current_state => "running")) + Win32::Service.stub(:status).with(@new_resource.service_name).and_return( + double("StatusStruct", :current_state => "running"), + double("StatusStruct", :current_state => "stopped"), + double("StatusStruct", :current_state => "stopped"), + double("StatusStruct", :current_state => "running")) Win32::Service.should_receive(:stop).with(@new_resource.service_name) Win32::Service.should_receive(:start).with(@new_resource.service_name) @provider.restart_service @@ -154,17 +154,17 @@ describe Chef::Provider::Service::Windows, "load_current_resource" do end it "should just start the service if it is stopped" do - Win32::Service.stub!(:status).with(@new_resource.service_name).and_return( - mock("StatusStruct", :current_state => "stopped"), - mock("StatusStruct", :current_state => "stopped"), - mock("StatusStruct", :current_state => "running")) + Win32::Service.stub(:status).with(@new_resource.service_name).and_return( + double("StatusStruct", :current_state => "stopped"), + double("StatusStruct", :current_state => "stopped"), + double("StatusStruct", :current_state => "running")) Win32::Service.should_receive(:start).with(@new_resource.service_name) @provider.restart_service @new_resource.updated_by_last_action?.should be_true end it "should do nothing if the service does not exist" do - Win32::Service.stub!(:exists?).with(@new_resource.service_name).and_return(false) + Win32::Service.stub(:exists?).with(@new_resource.service_name).and_return(false) Win32::Service.should_not_receive(:stop).with(@new_resource.service_name) Win32::Service.should_not_receive(:start).with(@new_resource.service_name) @provider.restart_service @@ -176,8 +176,8 @@ describe Chef::Provider::Service::Windows, "load_current_resource" do describe Chef::Provider::Service::Windows, "enable_service" do before(:each) do - Win32::Service.stub!(:config_info).with(@new_resource.service_name).and_return( - mock("ConfigStruct", :start_type => "disabled")) + Win32::Service.stub(:config_info).with(@new_resource.service_name).and_return( + double("ConfigStruct", :start_type => "disabled")) end it "should enable service" do @@ -187,15 +187,15 @@ describe Chef::Provider::Service::Windows, "load_current_resource" do end it "should do nothing if the service does not exist" do - Win32::Service.stub!(:exists?).with(@new_resource.service_name).and_return(false) + Win32::Service.stub(:exists?).with(@new_resource.service_name).and_return(false) Win32::Service.should_not_receive(:configure) @provider.enable_service @new_resource.updated_by_last_action?.should be_false end it "should do nothing if the service is enabled" do - Win32::Service.stub!(:config_info).with(@new_resource.service_name).and_return( - mock("ConfigStruct", :start_type => "auto start")) + Win32::Service.stub(:config_info).with(@new_resource.service_name).and_return( + double("ConfigStruct", :start_type => "auto start")) Win32::Service.should_not_receive(:configure) @provider.enable_service @new_resource.updated_by_last_action?.should be_false @@ -205,8 +205,8 @@ describe Chef::Provider::Service::Windows, "load_current_resource" do describe Chef::Provider::Service::Windows, "disable_service" do before(:each) do - Win32::Service.stub!(:config_info).with(@new_resource.service_name).and_return( - mock("ConfigStruct", :start_type => "auto start")) + Win32::Service.stub(:config_info).with(@new_resource.service_name).and_return( + double("ConfigStruct", :start_type => "auto start")) end it "should disable service" do @@ -216,15 +216,15 @@ describe Chef::Provider::Service::Windows, "load_current_resource" do end it "should do nothing if the service does not exist" do - Win32::Service.stub!(:exists?).with(@new_resource.service_name).and_return(false) + Win32::Service.stub(:exists?).with(@new_resource.service_name).and_return(false) Win32::Service.should_not_receive(:configure) @provider.disable_service @new_resource.updated_by_last_action?.should be_false end it "should do nothing if the service is disabled" do - Win32::Service.stub!(:config_info).with(@new_resource.service_name).and_return( - mock("ConfigStruct", :start_type => "disabled")) + Win32::Service.stub(:config_info).with(@new_resource.service_name).and_return( + double("ConfigStruct", :start_type => "disabled")) @provider.load_current_resource Win32::Service.should_not_receive(:configure) @provider.disable_service diff --git a/spec/unit/provider/service_spec.rb b/spec/unit/provider/service_spec.rb index 3719af56f2..7ddc01ff0b 100644 --- a/spec/unit/provider/service_spec.rb +++ b/spec/unit/provider/service_spec.rb @@ -28,7 +28,7 @@ describe Chef::Provider::Service do @provider = Chef::Provider::Service.new(@new_resource, @run_context) @provider.current_resource = @current_resource - @provider.stub!(:load_current_resource) + @provider.stub(:load_current_resource) end describe "when enabling the service" do @@ -52,14 +52,14 @@ describe Chef::Provider::Service do describe "when disabling the service" do it "should disable the service if enabled and set the resource as updated" do - @current_resource.stub!(:enabled).and_return(true) + @current_resource.stub(:enabled).and_return(true) @provider.should_receive(:disable_service).and_return(true) @provider.run_action(:disable) @provider.new_resource.should be_updated end it "should not disable the service if already disabled" do - @current_resource.stub!(:enabled).and_return(false) + @current_resource.stub(:enabled).and_return(false) @provider.should_not_receive(:disable_service) @provider.run_action(:disable) @provider.new_resource.should_not be_updated @@ -84,14 +84,14 @@ describe Chef::Provider::Service do describe "action_stop" do it "should stop the service if it is running and set the resource as updated" do - @current_resource.stub!(:running).and_return(true) + @current_resource.stub(:running).and_return(true) @provider.should_receive(:stop_service).and_return(true) @provider.run_action(:stop) @provider.new_resource.should be_updated end it "should not stop the service if it's already stopped" do - @current_resource.stub!(:running).and_return(false) + @current_resource.stub(:running).and_return(false) @provider.should_not_receive(:stop_service) @provider.run_action(:stop) @provider.new_resource.should_not be_updated @@ -110,7 +110,7 @@ describe Chef::Provider::Service do end it "should restart the service even if it isn't running and set the resource as updated" do - @current_resource.stub!(:running).and_return(false) + @current_resource.stub(:running).and_return(false) @provider.should_receive(:restart_service).and_return(true) @provider.run_action(:restart) @provider.new_resource.should be_updated @@ -124,19 +124,19 @@ describe Chef::Provider::Service do it "should raise an exception if reload isn't supported" do @new_resource.supports(:reload => false) - @new_resource.stub!(:reload_command).and_return(false) + @new_resource.stub(:reload_command).and_return(false) lambda { @provider.run_action(:reload) }.should raise_error(Chef::Exceptions::UnsupportedAction) end it "should reload the service if it is running and set the resource as updated" do - @current_resource.stub!(:running).and_return(true) + @current_resource.stub(:running).and_return(true) @provider.should_receive(:reload_service).and_return(true) @provider.run_action(:reload) @provider.new_resource.should be_updated end it "should not reload the service if it's stopped" do - @current_resource.stub!(:running).and_return(false) + @current_resource.stub(:running).and_return(false) @provider.should_not_receive(:reload_service) @provider.run_action(:stop) @provider.new_resource.should_not be_updated diff --git a/spec/unit/provider/subversion_spec.rb b/spec/unit/provider/subversion_spec.rb index dd020d4597..f37a42d235 100644 --- a/spec/unit/provider/subversion_spec.rb +++ b/spec/unit/provider/subversion_spec.rb @@ -43,9 +43,9 @@ describe Chef::Provider::Subversion do context "determining the revision of the currently deployed code" do before do - @stdout = mock("stdout") - @stderr = mock("stderr") - @exitstatus = mock("exitstatus") + @stdout = double("stdout") + @stderr = double("stderr") + @exitstatus = double("exitstatus") end it "sets the revision to nil if there isn't any deployed code yet" do @@ -66,9 +66,9 @@ describe Chef::Provider::Subversion do ::File.should_receive(:exist?).at_least(1).times.with("/my/deploy/dir/.svn").and_return(true) ::File.should_receive(:directory?).with("/my/deploy/dir").and_return(true) ::Dir.should_receive(:chdir).with("/my/deploy/dir").and_yield - @stdout.stub!(:string).and_return(example_svn_info) - @stderr.stub!(:string).and_return("") - @exitstatus.stub!(:exitstatus).and_return(0) + @stdout.stub(:string).and_return(example_svn_info) + @stderr.stub(:string).and_return("") + @exitstatus.stub(:exitstatus).and_return(0) expected_command = ["svn info", {:cwd=>"/my/deploy/dir"}] @provider.should_receive(:popen4).with(*expected_command). and_yield("no-pid", "no-stdin", @stdout,@stderr). @@ -81,9 +81,9 @@ describe Chef::Provider::Subversion do ::File.should_receive(:exist?).with("/my/deploy/dir/.svn").and_return(true) ::File.should_receive(:directory?).with("/my/deploy/dir").and_return(true) ::Dir.should_receive(:chdir).with("/my/deploy/dir").and_yield - @stdout.stub!(:string).and_return(example_svn_info) - @stderr.stub!(:string).and_return("") - @exitstatus.stub!(:exitstatus).and_return(1) + @stdout.stub(:string).and_return(example_svn_info) + @stderr.stub(:string).and_return("") + @exitstatus.stub(:exitstatus).and_return(1) @provider.should_receive(:popen4).and_yield("no-pid", "no-stdin", @stdout,@stderr). and_return(@exitstatus) @provider.find_current_revision.should be_nil @@ -99,7 +99,7 @@ describe Chef::Provider::Subversion do end it "creates the current_resource object and sets its revision to the current deployment's revision as long as we're not exporting" do - @provider.stub!(:find_current_revision).and_return("11410") + @provider.stub(:find_current_revision).and_return("11410") @provider.new_resource.instance_variable_set :@action, [:checkout] @provider.load_current_resource @provider.current_resource.name.should eql(@resource.name) @@ -109,8 +109,8 @@ describe Chef::Provider::Subversion do context "resolving revisions to an integer" do before do - @stdout = mock("stdout") - @stderr = mock("stderr") + @stdout = double("stdout") + @stderr = double("stderr") @resource.svn_info_args "--no-auth-cache" end @@ -128,11 +128,11 @@ describe Chef::Provider::Subversion do "Last Changed Author: codeninja\n" + "Last Changed Rev: 11410\n" + # Last Changed Rev is preferred to Revision "Last Changed Date: 2009-03-25 06:09:56 -0600 (Wed, 25 Mar 2009)\n\n" - exitstatus = mock("exitstatus") - exitstatus.stub!(:exitstatus).and_return(0) + exitstatus = double("exitstatus") + exitstatus.stub(:exitstatus).and_return(0) @resource.revision "HEAD" - @stdout.stub!(:string).and_return(example_svn_info) - @stderr.stub!(:string).and_return("") + @stdout.stub(:string).and_return(example_svn_info) + @stderr.stub(:string).and_return("") expected_command = ["svn info http://svn.example.org/trunk/ --no-auth-cache -rHEAD", {:cwd=>Dir.tmpdir}] @provider.should_receive(:popen4).with(*expected_command). and_yield("no-pid","no-stdin",@stdout,@stderr). @@ -142,11 +142,11 @@ describe Chef::Provider::Subversion do it "returns a helpful message if data from `svn info` can't be parsed" do example_svn_info = "some random text from an error message\n" - exitstatus = mock("exitstatus") - exitstatus.stub!(:exitstatus).and_return(0) + exitstatus = double("exitstatus") + exitstatus.stub(:exitstatus).and_return(0) @resource.revision "HEAD" - @stdout.stub!(:string).and_return(example_svn_info) - @stderr.stub!(:string).and_return("") + @stdout.stub(:string).and_return(example_svn_info) + @stderr.stub(:string).and_return("") @provider.should_receive(:popen4).and_yield("no-pid","no-stdin",@stdout,@stderr). and_return(exitstatus) lambda {@provider.revision_int}.should raise_error(RuntimeError, "Could not parse `svn info` data: some random text from an error message") @@ -197,7 +197,7 @@ describe Chef::Provider::Subversion do end it "runs an export with the --force option" do - ::File.stub!(:directory?).with("/my/deploy").and_return(true) + ::File.stub(:directory?).with("/my/deploy").and_return(true) expected_cmd = "svn export --force -q -r12345 http://svn.example.org/trunk/ /my/deploy/dir" @provider.should_receive(:run_command).with(:command => expected_cmd) @provider.run_action(:force_export) @@ -205,7 +205,7 @@ describe Chef::Provider::Subversion do end it "runs the checkout command for action_checkout" do - ::File.stub!(:directory?).with("/my/deploy").and_return(true) + ::File.stub(:directory?).with("/my/deploy").and_return(true) expected_cmd = "svn checkout -q -r12345 http://svn.example.org/trunk/ /my/deploy/dir" @provider.should_receive(:run_command).with(:command => expected_cmd) @provider.run_action(:checkout) @@ -217,17 +217,17 @@ describe Chef::Provider::Subversion do end it "should not checkout if the destination exists or is a non empty directory" do - ::File.stub!(:exist?).with("/my/deploy/dir/.svn").and_return(false) - ::File.stub!(:exist?).with("/my/deploy/dir").and_return(true) - ::File.stub!(:directory?).with("/my/deploy").and_return(true) - ::Dir.stub!(:entries).with("/my/deploy/dir").and_return(['.','..','foo','bar']) + ::File.stub(:exist?).with("/my/deploy/dir/.svn").and_return(false) + ::File.stub(:exist?).with("/my/deploy/dir").and_return(true) + ::File.stub(:directory?).with("/my/deploy").and_return(true) + ::Dir.stub(:entries).with("/my/deploy/dir").and_return(['.','..','foo','bar']) @provider.should_not_receive(:checkout_command) @provider.run_action(:checkout) @resource.should_not be_updated end it "runs commands with the user and group specified in the resource" do - ::File.stub!(:directory?).with("/my/deploy").and_return(true) + ::File.stub(:directory?).with("/my/deploy").and_return(true) @resource.user "whois" @resource.group "thisis" expected_cmd = "svn checkout -q -r12345 http://svn.example.org/trunk/ /my/deploy/dir" @@ -237,24 +237,24 @@ describe Chef::Provider::Subversion do end it "does a checkout for action_sync if there's no deploy dir" do - ::File.stub!(:directory?).with("/my/deploy").and_return(true) + ::File.stub(:directory?).with("/my/deploy").and_return(true) ::File.should_receive(:exist?).with("/my/deploy/dir/.svn").twice.and_return(false) @provider.should_receive(:action_checkout) @provider.run_action(:sync) end it "does a checkout for action_sync if the deploy dir exists but is empty" do - ::File.stub!(:directory?).with("/my/deploy").and_return(true) + ::File.stub(:directory?).with("/my/deploy").and_return(true) ::File.should_receive(:exist?).with("/my/deploy/dir/.svn").twice.and_return(false) @provider.should_receive(:action_checkout) @provider.run_action(:sync) end it "runs the sync_command on action_sync if the deploy dir exists and isn't empty" do - ::File.stub!(:directory?).with("/my/deploy").and_return(true) + ::File.stub(:directory?).with("/my/deploy").and_return(true) ::File.should_receive(:exist?).with("/my/deploy/dir/.svn").and_return(true) - @provider.stub!(:find_current_revision).and_return("11410") - @provider.stub!(:current_revision_matches_target_revision?).and_return(false) + @provider.stub(:find_current_revision).and_return("11410") + @provider.stub(:current_revision_matches_target_revision?).and_return(false) expected_cmd = "svn update -q -r12345 /my/deploy/dir" @provider.should_receive(:run_command).with(:command => expected_cmd) @provider.run_action(:sync) @@ -262,16 +262,16 @@ describe Chef::Provider::Subversion do end it "does not fetch any updates if the remote revision matches the current revision" do - ::File.stub!(:directory?).with("/my/deploy").and_return(true) + ::File.stub(:directory?).with("/my/deploy").and_return(true) ::File.should_receive(:exist?).with("/my/deploy/dir/.svn").and_return(true) - @provider.stub!(:find_current_revision).and_return('12345') - @provider.stub!(:current_revision_matches_target_revision?).and_return(true) + @provider.stub(:find_current_revision).and_return('12345') + @provider.stub(:current_revision_matches_target_revision?).and_return(true) @provider.run_action(:sync) @resource.should_not be_updated end it "runs the export_command on action_export" do - ::File.stub!(:directory?).with("/my/deploy").and_return(true) + ::File.stub(:directory?).with("/my/deploy").and_return(true) expected_cmd = "svn export --force -q -r12345 http://svn.example.org/trunk/ /my/deploy/dir" @provider.should_receive(:run_command).with(:command => expected_cmd) @provider.run_action(:export) diff --git a/spec/unit/provider/template/content_spec.rb b/spec/unit/provider/template/content_spec.rb index 4061d99d7b..dfc5d21c2a 100644 --- a/spec/unit/provider/template/content_spec.rb +++ b/spec/unit/provider/template/content_spec.rb @@ -21,7 +21,7 @@ require 'spec_helper' describe Chef::Provider::Template::Content do let(:new_resource) do - mock("Chef::Resource::Template (new)", + double("Chef::Resource::Template (new)", :cookbook_name => 'openldap', :source => 'openldap_stuff.conf.erb', :local => false, @@ -41,11 +41,11 @@ describe Chef::Provider::Template::Content do cl.load_cookbooks cookbook_collection = Chef::CookbookCollection.new(cl) node = Chef::Node.new - mock("Chef::Resource::RunContext", :node => node, :cookbook_collection => cookbook_collection) + double("Chef::Resource::RunContext", :node => node, :cookbook_collection => cookbook_collection) end let(:content) do - current_resource = mock("Chef::Resource::Template (current)") + current_resource = double("Chef::Resource::Template (current)") Chef::Provider::Template::Content.new(new_resource, current_resource, run_context) end @@ -58,15 +58,15 @@ describe Chef::Provider::Template::Content do end it "finds the template file locally if it is local" do - new_resource.stub!(:local).and_return(true) - new_resource.stub!(:source).and_return('/tmp/its_on_disk.erb') + new_resource.stub(:local).and_return(true) + new_resource.stub(:source).and_return('/tmp/its_on_disk.erb') content.template_location.should == '/tmp/its_on_disk.erb' end it "should use the cookbook name if defined in the template resource" do - new_resource.stub!(:cookbook_name).and_return('apache2') - new_resource.stub!(:cookbook).and_return('openldap') - new_resource.stub!(:source).and_return("test.erb") + new_resource.stub(:cookbook_name).and_return('apache2') + new_resource.stub(:cookbook).and_return('openldap') + new_resource.stub(:source).and_return("test.erb") content.template_location.should == CHEF_SPEC_DATA + '/cookbooks/openldap/templates/default/test.erb' end diff --git a/spec/unit/provider/template_spec.rb b/spec/unit/provider/template_spec.rb index 78d924aa41..514bdc12ff 100644 --- a/spec/unit/provider/template_spec.rb +++ b/spec/unit/provider/template_spec.rb @@ -50,7 +50,7 @@ describe Chef::Provider::Template do end let(:content) do - content = mock('Chef::Provider::File::Content::Template', :template_location => "/foo/bar/baz") + content = double('Chef::Provider::File::Content::Template', :template_location => "/foo/bar/baz") File.stub(:exists?).with("/foo/bar/baz").and_return(true) content end diff --git a/spec/unit/provider/user/dscl_spec.rb b/spec/unit/provider/user/dscl_spec.rb index dd98c55bd1..c7657aa6e5 100644 --- a/spec/unit/provider/user/dscl_spec.rb +++ b/spec/unit/provider/user/dscl_spec.rb @@ -64,7 +64,7 @@ describe Chef::Provider::User::Dscl do describe "get_free_uid" do before do - @provider.stub!(:safe_dscl).and_return("\nwheel 200\nstaff 201\n") + @provider.stub(:safe_dscl).and_return("\nwheel 200\nstaff 201\n") end it "should run safe_dscl with list /Users uid" do @@ -84,7 +84,7 @@ describe Chef::Provider::User::Dscl do describe "uid_used?" do before do - @provider.stub!(:safe_dscl).and_return("\naj 500\n") + @provider.stub(:safe_dscl).and_return("\naj 500\n") end it "should run safe_dscl with list /Users uid" do @@ -107,7 +107,7 @@ describe Chef::Provider::User::Dscl do describe "when determining the uid to set" do it "raises RequestedUIDUnavailable if the requested uid is already in use" do - @provider.stub!(:uid_used?).and_return(true) + @provider.stub(:uid_used?).and_return(true) @provider.should_receive(:get_free_uid).and_return(501) lambda { @provider.set_uid }.should raise_error(Chef::Exceptions::RequestedUIDUnavailable) end @@ -156,8 +156,8 @@ describe Chef::Provider::User::Dscl do current_home_files = [current_home + '/my-dot-emacs', current_home + '/my-dot-vim'] @current_resource.home(current_home) @new_resource.gid(23) - ::File.stub!(:exists?).with('/old/home/toor').and_return(true) - ::File.stub!(:exists?).with('/Users/toor').and_return(true) + ::File.stub(:exists?).with('/old/home/toor').and_return(true) + ::File.stub(:exists?).with('/Users/toor').and_return(true) FileUtils.should_receive(:mkdir_p).with('/Users/toor').and_return(true) FileUtils.should_receive(:rmdir).with(current_home) @@ -170,7 +170,7 @@ describe Chef::Provider::User::Dscl do end it "should raise an exception when the systems user template dir (skel) cannot be found" do - ::File.stub!(:exists?).and_return(false,false,false) + ::File.stub(:exists?).and_return(false,false,false) lambda { @provider.modify_home }.should raise_error(Chef::Exceptions::User) end @@ -284,7 +284,7 @@ describe Chef::Provider::User::Dscl do uuid = "B398449E-CEE0-45E0-80F8-B0B5B1BFDEAA" File.should_receive(:open).with('/var/db/shadow/hash/B398449E-CEE0-45E0-80F8-B0B5B1BFDEAA', "w", 384).and_yield(@output) @new_resource.password("password") - OpenSSL::Random.stub!(:random_bytes).and_return("\377\377\377\377\377\377\377\377") + OpenSSL::Random.stub(:random_bytes).and_return("\377\377\377\377\377\377\377\377") expected_salted_sha1 = "F"*8+"SHA1-"*8 expected_shadow_hash = "00000000"*155 expected_shadow_hash[168] = expected_salted_sha1 @@ -324,8 +324,8 @@ describe Chef::Provider::User::Dscl do end it "shouldn't raise an error if /usr/bin/dscl exists" do - ::File.stub!(:exists?).and_return(true) - lambda { @provider.load_current_resource }.should_not raise_error(Chef::Exceptions::User) + ::File.stub(:exists?).and_return(true) + lambda { @provider.load_current_resource }.should_not raise_error end end diff --git a/spec/unit/provider/user/pw_spec.rb b/spec/unit/provider/user/pw_spec.rb index ea5bcfe740..1d5ad38c9c 100644 --- a/spec/unit/provider/user/pw_spec.rb +++ b/spec/unit/provider/user/pw_spec.rb @@ -62,13 +62,13 @@ describe Chef::Provider::User::Pw do end it "should set the option for #{attribute} if the new resources #{attribute} is not null" do - @new_resource.stub!(attribute).and_return("hola") + @new_resource.stub(attribute).and_return("hola") @provider.set_options.should eql(" #{@new_resource.username} #{option} '#{@new_resource.send(attribute)}' -m") end it "should set the option for #{attribute} if the new resources #{attribute} is not null, without homedir management" do - @new_resource.stub!(:supports).and_return({:manage_home => false}) - @new_resource.stub!(attribute).and_return("hola") + @new_resource.stub(:supports).and_return({:manage_home => false}) + @new_resource.stub(attribute).and_return("hola") @provider.set_options.should eql(" #{@new_resource.username} #{option} '#{@new_resource.send(attribute)}'") end end @@ -76,7 +76,7 @@ describe Chef::Provider::User::Pw do it "should combine all the possible options" do match_string = " adam" field_list.sort{ |a,b| a[0] <=> b[0] }.each do |attribute, option| - @new_resource.stub!(attribute).and_return("hola") + @new_resource.stub(attribute).and_return("hola") match_string << " #{option} 'hola'" end match_string << " -m" @@ -86,8 +86,8 @@ describe Chef::Provider::User::Pw do describe "create_user" do before(:each) do - @provider.stub!(:run_command).and_return(true) - @provider.stub!(:modify_password).and_return(true) + @provider.stub(:run_command).and_return(true) + @provider.stub(:modify_password).and_return(true) end it "should run pw useradd with the return of set_options" do @@ -103,8 +103,8 @@ describe Chef::Provider::User::Pw do describe "manage_user" do before(:each) do - @provider.stub!(:run_command).and_return(true) - @provider.stub!(:modify_password).and_return(true) + @provider.stub(:run_command).and_return(true) + @provider.stub(:modify_password).and_return(true) end it "should run pw usermod with the return of set_options" do @@ -133,12 +133,12 @@ describe Chef::Provider::User::Pw do describe "determining if the user is locked" do it "should return true if user is locked" do - @current_resource.stub!(:password).and_return("*LOCKED*abracadabra") + @current_resource.stub(:password).and_return("*LOCKED*abracadabra") @provider.check_lock.should eql(true) end it "should return false if user is not locked" do - @current_resource.stub!(:password).and_return("abracadabra") + @current_resource.stub(:password).and_return("abracadabra") @provider.check_lock.should eql(false) end end @@ -159,8 +159,8 @@ describe Chef::Provider::User::Pw do describe "when modifying the password" do before(:each) do - @status = mock("Status", :exitstatus => 0) - @provider.stub!(:popen4).and_return(@status) + @status = double("Status", :exitstatus => 0) + @provider.stub(:popen4).and_return(@status) @pid, @stdin, @stdout, @stderr = nil, nil, nil, nil end @@ -172,8 +172,8 @@ describe Chef::Provider::User::Pw do describe "and the passwords are identical" do before(:each) do - @new_resource.stub!(:password).and_return("abracadabra") - @current_resource.stub!(:password).and_return("abracadabra") + @new_resource.stub(:password).and_return("abracadabra") + @current_resource.stub(:password).and_return("abracadabra") end it "logs an appropriate message" do @@ -184,8 +184,8 @@ describe Chef::Provider::User::Pw do describe "and the passwords are different" do before(:each) do - @new_resource.stub!(:password).and_return("abracadabra") - @current_resource.stub!(:password).and_return("sesame") + @new_resource.stub(:password).and_return("abracadabra") + @current_resource.stub(:password).and_return("sesame") end it "should log an appropriate message" do @@ -200,7 +200,7 @@ describe Chef::Provider::User::Pw do it "should send the new password to the stdin of pw usermod" do @stdin = StringIO.new - @provider.stub!(:popen4).and_yield(@pid, @stdin, @stdout, @stderr).and_return(@status) + @provider.stub(:popen4).and_yield(@pid, @stdin, @stdout, @stderr).and_return(@status) @provider.modify_password @stdin.string.should == "abracadabra\n" end @@ -212,7 +212,7 @@ describe Chef::Provider::User::Pw do it "should not raise an exception if pw usermod succeeds" do @status.should_receive(:exitstatus).and_return(0) - lambda { @provider.modify_password }.should_not raise_error(Chef::Exceptions::User) + lambda { @provider.modify_password }.should_not raise_error end end end @@ -228,8 +228,8 @@ describe Chef::Provider::User::Pw do end it "shouldn't raise an error if /usr/sbin/pw exists" do - File.stub!(:exists?).and_return(true) - lambda { @provider.load_current_resource }.should_not raise_error(Chef::Exceptions::User) + File.stub(:exists?).and_return(true) + lambda { @provider.load_current_resource }.should_not raise_error end end end diff --git a/spec/unit/provider/user/solaris_spec.rb b/spec/unit/provider/user/solaris_spec.rb index 5500eac812..d8bd0f9e75 100644 --- a/spec/unit/provider/user/solaris_spec.rb +++ b/spec/unit/provider/user/solaris_spec.rb @@ -27,7 +27,7 @@ describe Chef::Provider::User::Solaris do p.current_resource = @current_resource # Prevent the useradd-based provider tests from trying to write /etc/shadow - p.stub!(:write_shadow_file) + p.stub(:write_shadow_file) p end @@ -52,12 +52,12 @@ describe Chef::Provider::User::Solaris do @new_resource.password "hocus-pocus" # Let these tests run #write_shadow_file - provider.unstub!(:write_shadow_file) + provider.unstub(:write_shadow_file) end it "should use its own shadow file writer to set the password" do provider.should_receive(:write_shadow_file) - provider.stub!(:shell_out!).and_return(true) + provider.stub(:shell_out!).and_return(true) provider.manage_user end @@ -66,10 +66,10 @@ describe Chef::Provider::User::Solaris do password_file.puts "adam:existingpassword:15441::::::" password_file.close provider.password_file = password_file.path - provider.stub!(:shell_out!).and_return(true) + provider.stub(:shell_out!).and_return(true) # may not be able to write to /etc for tests... temp_file = Tempfile.new("shadow") - Tempfile.stub!(:new).with("shadow", "/etc").and_return(temp_file) + Tempfile.stub(:new).with("shadow", "/etc").and_return(temp_file) @new_resource.password "verysecurepassword" provider.manage_user ::File.open(password_file.path, "r").read.should =~ /adam:verysecurepassword:/ diff --git a/spec/unit/provider/user/windows_spec.rb b/spec/unit/provider/user/windows_spec.rb index b11eeaebe5..70adb8025a 100644 --- a/spec/unit/provider/user/windows_spec.rb +++ b/spec/unit/provider/user/windows_spec.rb @@ -35,8 +35,8 @@ describe Chef::Provider::User::Windows do @run_context = Chef::RunContext.new(@node, {}, @events) @current_resource = Chef::Resource::User.new("monkey") - @net_user = mock("Chef::Util::Windows::NetUser") - Chef::Util::Windows::NetUser.stub!(:new).and_return(@net_user) + @net_user = double("Chef::Util::Windows::NetUser") + Chef::Util::Windows::NetUser.stub(:new).and_return(@net_user) @provider = Chef::Provider::User::Windows.new(@new_resource, @run_context) @provider.current_resource = @current_resource @@ -120,7 +120,7 @@ describe Chef::Provider::User::Windows do describe "when creating the user" do it "should call @net_user.add with the return of set_options" do - @provider.stub!(:set_options).and_return(:name=> "monkey") + @provider.stub(:set_options).and_return(:name=> "monkey") @net_user.should_receive(:add).with(:name=> "monkey") @provider.create_user end @@ -128,7 +128,7 @@ describe Chef::Provider::User::Windows do describe "manage_user" do before(:each) do - @provider.stub!(:set_options).and_return(:name=> "monkey") + @provider.stub(:set_options).and_return(:name=> "monkey") end it "should call @net_user.update with the return of set_options" do @@ -150,19 +150,19 @@ describe Chef::Provider::User::Windows do end it "should return true if user is locked" do - @net_user.stub!(:check_enabled).and_return(true) + @net_user.stub(:check_enabled).and_return(true) @provider.check_lock.should eql(true) end it "should return false if user is not locked" do - @net_user.stub!(:check_enabled).and_return(false) + @net_user.stub(:check_enabled).and_return(false) @provider.check_lock.should eql(false) end end describe "locking the user" do it "should call @net_user.disable_account" do - @net_user.stub!(:check_enabled).and_return(true) + @net_user.stub(:check_enabled).and_return(true) @net_user.should_receive(:disable_account) @provider.lock_user end @@ -170,7 +170,7 @@ describe Chef::Provider::User::Windows do describe "unlocking the user" do it "should call @net_user.enable_account" do - @net_user.stub!(:check_enabled).and_return(false) + @net_user.stub(:check_enabled).and_return(false) @net_user.should_receive(:enable_account) @provider.unlock_user end diff --git a/spec/unit/provider/user_spec.rb b/spec/unit/provider/user_spec.rb index d5e694b79c..153db6f283 100644 --- a/spec/unit/provider/user_spec.rb +++ b/spec/unit/provider/user_spec.rb @@ -58,7 +58,7 @@ describe Chef::Provider::User do describe "executing load_current_resource" do before(:each) do @node = Chef::Node.new - #@new_resource = mock("Chef::Resource::User", + #@new_resource = double("Chef::Resource::User", # :null_object => true, # :username => "adam", # :comment => "Adam Jacob", @@ -69,7 +69,7 @@ describe Chef::Provider::User do # :password => nil, # :updated => nil #) - Chef::Resource::User.stub!(:new).and_return(@current_resource) + Chef::Resource::User.stub(:new).and_return(@current_resource) @pw_user = EtcPwnamIsh.new @pw_user.name = "adam" @pw_user.gid = 1000 @@ -78,7 +78,7 @@ describe Chef::Provider::User do @pw_user.dir = "/home/adam" @pw_user.shell = "/usr/bin/zsh" @pw_user.passwd = "*" - Etc.stub!(:getpwnam).and_return(@pw_user) + Etc.stub(:getpwnam).and_return(@pw_user) end it "should create a current resource with the same name as the new resource" do @@ -129,7 +129,7 @@ describe Chef::Provider::User do end it "shouldn't try and convert the group gid if none has been supplied" do - @new_resource.stub!(:gid).and_return(nil) + @new_resource.stub(:gid).and_return(nil) @provider.should_not_receive(:convert_group_name) @provider.load_current_resource end @@ -156,7 +156,7 @@ describe Chef::Provider::User do user.name = "root" user.passwd = "x" @new_resource.password "some new password" - Etc.stub!(:getpwnam).and_return(user) + Etc.stub(:getpwnam).and_return(user) end unless shadow_lib_unavail? @@ -225,8 +225,8 @@ describe Chef::Provider::User do describe "action_create" do before(:each) do - @provider.stub!(:load_current_resource) - # @current_resource = mock("Chef::Resource::User", + @provider.stub(:load_current_resource) + # @current_resource = double("Chef::Resource::User", # :null_object => true, # :username => "adam", # :comment => "Adam Jacob", @@ -240,8 +240,8 @@ describe Chef::Provider::User do # @provider = Chef::Provider::User.new(@node, @new_resource) # @provider.current_resource = @current_resource # @provider.user_exists = false - # @provider.stub!(:create_user).and_return(true) - # @provider.stub!(:manage_user).and_return(true) + # @provider.stub(:create_user).and_return(true) + # @provider.stub(:manage_user).and_return(true) end it "should call create_user if the user does not exist" do @@ -254,15 +254,15 @@ describe Chef::Provider::User do it "should call manage_user if the user exists and has mismatched attributes" do @provider.user_exists = true - @provider.stub!(:compare_user).and_return(true) + @provider.stub(:compare_user).and_return(true) @provider.should_receive(:manage_user).and_return(true) @provider.action_create end it "should set the new_resources updated flag when it creates the user if we call manage_user" do @provider.user_exists = true - @provider.stub!(:compare_user).and_return(true) - @provider.stub!(:manage_user).and_return(true) + @provider.stub(:compare_user).and_return(true) + @provider.stub(:manage_user).and_return(true) @provider.action_create @provider.set_updated_status @new_resource.should be_updated @@ -271,7 +271,7 @@ describe Chef::Provider::User do describe "action_remove" do before(:each) do - @provider.stub!(:load_current_resource) + @provider.stub(:load_current_resource) end it "should not call remove_user if the user does not exist" do @@ -297,18 +297,18 @@ describe Chef::Provider::User do describe "action_manage" do before(:each) do - @provider.stub!(:load_current_resource) + @provider.stub(:load_current_resource) # @node = Chef::Node.new - # @new_resource = mock("Chef::Resource::User", + # @new_resource = double("Chef::Resource::User", # :null_object => true # ) - # @current_resource = mock("Chef::Resource::User", + # @current_resource = double("Chef::Resource::User", # :null_object => true # ) # @provider = Chef::Provider::User.new(@node, @new_resource) # @provider.current_resource = @current_resource # @provider.user_exists = true - # @provider.stub!(:manage_user).and_return(true) + # @provider.stub(:manage_user).and_return(true) end it "should run manage_user if the user exists and has mismatched attributes" do @@ -318,8 +318,8 @@ describe Chef::Provider::User do end it "should set the new resources updated flag to true if manage_user is called" do - @provider.stub!(:compare_user).and_return(true) - @provider.stub!(:manage_user).and_return(true) + @provider.stub(:compare_user).and_return(true) + @provider.stub(:manage_user).and_return(true) @provider.action_manage @provider.set_updated_status @new_resource.should be_updated @@ -340,18 +340,18 @@ describe Chef::Provider::User do describe "action_modify" do before(:each) do - @provider.stub!(:load_current_resource) + @provider.stub(:load_current_resource) # @node = Chef::Node.new - # @new_resource = mock("Chef::Resource::User", + # @new_resource = double("Chef::Resource::User", # :null_object => true # ) - # @current_resource = mock("Chef::Resource::User", + # @current_resource = double("Chef::Resource::User", # :null_object => true # ) # @provider = Chef::Provider::User.new(@node, @new_resource) # @provider.current_resource = @current_resource # @provider.user_exists = true - # @provider.stub!(:manage_user).and_return(true) + # @provider.stub(:manage_user).and_return(true) end it "should run manage_user if the user exists and has mismatched attributes" do @@ -361,8 +361,8 @@ describe Chef::Provider::User do end it "should set the new resources updated flag to true if manage_user is called" do - @provider.stub!(:compare_user).and_return(true) - @provider.stub!(:manage_user).and_return(true) + @provider.stub(:compare_user).and_return(true) + @provider.stub(:manage_user).and_return(true) @provider.action_modify @provider.set_updated_status @new_resource.should be_updated @@ -383,16 +383,16 @@ describe Chef::Provider::User do describe "action_lock" do before(:each) do - @provider.stub!(:load_current_resource) + @provider.stub(:load_current_resource) end it "should lock the user if it exists and is unlocked" do - @provider.stub!(:check_lock).and_return(false) + @provider.stub(:check_lock).and_return(false) @provider.should_receive(:lock_user).and_return(true) @provider.action_lock end it "should set the new resources updated flag to true if lock_user is called" do - @provider.stub!(:check_lock).and_return(false) + @provider.stub(:check_lock).and_return(false) @provider.should_receive(:lock_user) @provider.action_lock @provider.set_updated_status @@ -409,23 +409,23 @@ describe Chef::Provider::User do describe "action_unlock" do before(:each) do - @provider.stub!(:load_current_resource) + @provider.stub(:load_current_resource) # @node = Chef::Node.new - # @new_resource = mock("Chef::Resource::User", + # @new_resource = double("Chef::Resource::User", # :null_object => true # ) - # @current_resource = mock("Chef::Resource::User", + # @current_resource = double("Chef::Resource::User", # :null_object => true # ) # @provider = Chef::Provider::User.new(@node, @new_resource) # @provider.current_resource = @current_resource # @provider.user_exists = true - # @provider.stub!(:check_lock).and_return(true) - # @provider.stub!(:unlock_user).and_return(true) + # @provider.stub(:check_lock).and_return(true) + # @provider.stub(:unlock_user).and_return(true) end it "should unlock the user if it exists and is locked" do - @provider.stub!(:check_lock).and_return(true) + @provider.stub(:check_lock).and_return(true) @provider.should_receive(:unlock_user).and_return(true) @provider.action_unlock @provider.set_updated_status diff --git a/spec/unit/provider_spec.rb b/spec/unit/provider_spec.rb index 7873be0f28..363649ec46 100644 --- a/spec/unit/provider_spec.rb +++ b/spec/unit/provider_spec.rb @@ -93,15 +93,15 @@ describe Chef::Provider do it "does not re-load recipes when creating the temporary run context" do # we actually want to test that RunContext#load is never called, but we # can't stub all instances of an object with rspec's mocks. :/ - Chef::RunContext.stub!(:new).and_raise("not supposed to happen") + Chef::RunContext.stub(:new).and_raise("not supposed to happen") snitch = Proc.new {temporary_collection = @run_context.resource_collection} @provider.send(:recipe_eval, &snitch) end context "when no converge actions are queued" do before do - @provider.stub!(:whyrun_supported?).and_return(true) - @provider.stub!(:load_current_resource) + @provider.stub(:whyrun_supported?).and_return(true) + @provider.stub(:load_current_resource) end it "does not mark the new resource as updated" do diff --git a/spec/unit/recipe_spec.rb b/spec/unit/recipe_spec.rb index 3240739dd7..a2c6e4b4cb 100644 --- a/spec/unit/recipe_spec.rb +++ b/spec/unit/recipe_spec.rb @@ -36,7 +36,7 @@ describe Chef::Recipe do # Shell/ext.rb is on the run path, and it defines # Chef::Recipe#resources to call pp, which we don't want when # we're running tests. - @recipe.stub!(:pp) + @recipe.stub(:pp) end describe "method_missing" do @@ -46,7 +46,7 @@ describe Chef::Recipe do @recipe.zen_master "monkey" do peace true end - end.should_not raise_error(ArgumentError) + end.should_not raise_error end it "should load a one word (cat) resource" do @@ -54,7 +54,7 @@ describe Chef::Recipe do @recipe.cat "loulou" do pretty_kitty true end - end.should_not raise_error(ArgumentError) + end.should_not raise_error end it "should load a four word (one_two_three_four) resource" do @@ -62,7 +62,7 @@ describe Chef::Recipe do @recipe.one_two_three_four "numbers" do i_can_count true end - end.should_not raise_error(ArgumentError) + end.should_not raise_error end it "should throw an error if you access a resource that we can't find" do diff --git a/spec/unit/registry_helper_spec.rb b/spec/unit/registry_helper_spec.rb index 49469b27e6..444a82dc7c 100644 --- a/spec/unit/registry_helper_spec.rb +++ b/spec/unit/registry_helper_spec.rb @@ -43,8 +43,8 @@ describe Chef::Provider::RegistryKey do Win32::Registry::Error = Class.new(RuntimeError) - @hive_mock = mock("::Win32::Registry::HKEY_CURRENT_USER") - @reg_mock = mock("reg") + @hive_mock = double("::Win32::Registry::HKEY_CURRENT_USER") + @reg_mock = double("reg") end describe "get_values" do diff --git a/spec/unit/resource/cron_spec.rb b/spec/unit/resource/cron_spec.rb index 7f294fae11..355a7f09ba 100644 --- a/spec/unit/resource/cron_spec.rb +++ b/spec/unit/resource/cron_spec.rb @@ -39,8 +39,8 @@ describe Chef::Resource::Cron do end it "should accept create or delete for action" do - lambda { @resource.action :create }.should_not raise_error(ArgumentError) - lambda { @resource.action :delete }.should_not raise_error(ArgumentError) + lambda { @resource.action :create }.should_not raise_error + lambda { @resource.action :delete }.should_not raise_error lambda { @resource.action :lolcat }.should raise_error(ArgumentError) end diff --git a/spec/unit/resource/directory_spec.rb b/spec/unit/resource/directory_spec.rb index dc042c5a77..a42383c49e 100644 --- a/spec/unit/resource/directory_spec.rb +++ b/spec/unit/resource/directory_spec.rb @@ -39,8 +39,8 @@ describe Chef::Resource::Directory do end it "should accept create or delete for action" do - lambda { @resource.action :create }.should_not raise_error(ArgumentError) - lambda { @resource.action :delete }.should_not raise_error(ArgumentError) + lambda { @resource.action :create }.should_not raise_error + lambda { @resource.action :delete }.should_not raise_error lambda { @resource.action :blues }.should raise_error(ArgumentError) end @@ -49,14 +49,14 @@ describe Chef::Resource::Directory do end it "should accept a string as the path" do - lambda { @resource.path "/tmp" }.should_not raise_error(ArgumentError) + lambda { @resource.path "/tmp" }.should_not raise_error @resource.path.should eql("/tmp") lambda { @resource.path Hash.new }.should raise_error(ArgumentError) end it "should allow you to have specify whether the action is recursive with true/false" do - lambda { @resource.recursive true }.should_not raise_error(ArgumentError) - lambda { @resource.recursive false }.should_not raise_error(ArgumentError) + lambda { @resource.recursive true }.should_not raise_error + lambda { @resource.recursive false }.should_not raise_error lambda { @resource.recursive "monkey" }.should raise_error(ArgumentError) end diff --git a/spec/unit/resource/env_spec.rb b/spec/unit/resource/env_spec.rb index b53cbe478f..a1f599400b 100644 --- a/spec/unit/resource/env_spec.rb +++ b/spec/unit/resource/env_spec.rb @@ -43,7 +43,7 @@ describe Chef::Resource::Env do if bad_value lambda { @resource.action action }.should raise_error(ArgumentError) else - lambda { @resource.action action }.should_not raise_error(ArgumentError) + lambda { @resource.action action }.should_not raise_error end end end @@ -53,7 +53,7 @@ describe Chef::Resource::Env do end it "should accept a string as the env value via 'value'" do - lambda { @resource.value "bar" }.should_not raise_error(ArgumentError) + lambda { @resource.value "bar" }.should_not raise_error end it "should not accept a Hash for the env value via 'to'" do diff --git a/spec/unit/resource/erl_call_spec.rb b/spec/unit/resource/erl_call_spec.rb index 49df9639d1..3efbdca9a0 100644 --- a/spec/unit/resource/erl_call_spec.rb +++ b/spec/unit/resource/erl_call_spec.rb @@ -39,7 +39,7 @@ describe Chef::Resource::ErlCall do end it "should accept run as an action" do - lambda { @resource.action :run }.should_not raise_error(ArgumentError) + lambda { @resource.action :run }.should_not raise_error end it "should allow you to set the code attribute" do diff --git a/spec/unit/resource/file_spec.rb b/spec/unit/resource/file_spec.rb index f937d0035b..9c6365f6d3 100644 --- a/spec/unit/resource/file_spec.rb +++ b/spec/unit/resource/file_spec.rb @@ -44,25 +44,25 @@ describe Chef::Resource::File do lambda { @resource.content 5 }.should raise_error(ArgumentError) lambda { @resource.content :foo }.should raise_error(ArgumentError) lambda { @resource.content "hello" => "there" }.should raise_error(ArgumentError) - lambda { @resource.content "hi" }.should_not raise_error(ArgumentError) + lambda { @resource.content "hi" }.should_not raise_error end it "should only accept false or a number for backup" do lambda { @resource.backup true }.should raise_error(ArgumentError) - lambda { @resource.backup false }.should_not raise_error(ArgumentError) - lambda { @resource.backup 10 }.should_not raise_error(ArgumentError) + lambda { @resource.backup false }.should_not raise_error + lambda { @resource.backup 10 }.should_not raise_error lambda { @resource.backup "blues" }.should raise_error(ArgumentError) end it "should accept a sha256 for checksum" do - lambda { @resource.checksum "0fd012fdc96e96f8f7cf2046522a54aed0ce470224513e45da6bc1a17a4924aa" }.should_not raise_error(ArgumentError) + lambda { @resource.checksum "0fd012fdc96e96f8f7cf2046522a54aed0ce470224513e45da6bc1a17a4924aa" }.should_not raise_error lambda { @resource.checksum "monkey!" }.should raise_error(ArgumentError) end it "should accept create, delete or touch for action" do - lambda { @resource.action :create }.should_not raise_error(ArgumentError) - lambda { @resource.action :delete }.should_not raise_error(ArgumentError) - lambda { @resource.action :touch }.should_not raise_error(ArgumentError) + lambda { @resource.action :create }.should_not raise_error + lambda { @resource.action :delete }.should_not raise_error + lambda { @resource.action :touch }.should_not raise_error lambda { @resource.action :blues }.should raise_error(ArgumentError) end @@ -71,7 +71,7 @@ describe Chef::Resource::File do end it "should accept a string as the path" do - lambda { @resource.path "/tmp" }.should_not raise_error(ArgumentError) + lambda { @resource.path "/tmp" }.should_not raise_error @resource.path.should eql("/tmp") lambda { @resource.path Hash.new }.should raise_error(ArgumentError) end diff --git a/spec/unit/resource/group_spec.rb b/spec/unit/resource/group_spec.rb index df68c5691f..0c3cf4f67f 100644 --- a/spec/unit/resource/group_spec.rb +++ b/spec/unit/resource/group_spec.rb @@ -60,11 +60,11 @@ describe Chef::Resource::Group, "initialize" do end it "should accept domain groups (@ or \ separator) on non-windows" do - lambda { @resource.group_name "domain\@group" }.should_not raise_error(ArgumentError) + lambda { @resource.group_name "domain\@group" }.should_not raise_error @resource.group_name.should == "domain\@group" - lambda { @resource.group_name "domain\\group" }.should_not raise_error(ArgumentError) + lambda { @resource.group_name "domain\\group" }.should_not raise_error @resource.group_name.should == "domain\\group" - lambda { @resource.group_name "domain\\group^name" }.should_not raise_error(ArgumentError) + lambda { @resource.group_name "domain\\group^name" }.should_not raise_error @resource.group_name.should == "domain\\group^name" end end diff --git a/spec/unit/resource/link_spec.rb b/spec/unit/resource/link_spec.rb index fc3f7ff41c..221617f9b3 100644 --- a/spec/unit/resource/link_spec.rb +++ b/spec/unit/resource/link_spec.rb @@ -44,7 +44,7 @@ describe Chef::Resource::Link do if bad_value lambda { @resource.action action }.should raise_error(ArgumentError) else - lambda { @resource.action action }.should_not raise_error(ArgumentError) + lambda { @resource.action action }.should_not raise_error end end end @@ -54,7 +54,7 @@ describe Chef::Resource::Link do end it "should accept a string as the link source via 'to'" do - lambda { @resource.to "/tmp" }.should_not raise_error(ArgumentError) + lambda { @resource.to "/tmp" }.should_not raise_error end it "should not accept a Hash for the link source via 'to'" do @@ -85,15 +85,15 @@ describe Chef::Resource::Link do end it "should accept a group name or id for group" do - lambda { @resource.group "root" }.should_not raise_error(ArgumentError) - lambda { @resource.group 123 }.should_not raise_error(ArgumentError) - lambda { @resource.group "root*goo" }.should raise_error(ArgumentError) + lambda { @resource.group "root" }.should_not raise_error + lambda { @resource.group 123 }.should_not raise_error + lambda { @resource.group "root:goo" }.should raise_error(ArgumentError) end it "should accept a user name or id for owner" do - lambda { @resource.owner "root" }.should_not raise_error(ArgumentError) - lambda { @resource.owner 123 }.should_not raise_error(ArgumentError) - lambda { @resource.owner "root*goo" }.should raise_error(ArgumentError) + lambda { @resource.owner "root" }.should_not raise_error + lambda { @resource.owner 123 }.should_not raise_error + lambda { @resource.owner "root:goo" }.should raise_error(ArgumentError) end describe "when it has to, link_type, owner, and group" do diff --git a/spec/unit/resource/mdadm_spec.rb b/spec/unit/resource/mdadm_spec.rb index 310f420659..daf10bcfea 100644 --- a/spec/unit/resource/mdadm_spec.rb +++ b/spec/unit/resource/mdadm_spec.rb @@ -39,9 +39,9 @@ describe Chef::Resource::Mdadm do end it "should accept create, assemble, stop as actions" do - lambda { @resource.action :create }.should_not raise_error(ArgumentError) - lambda { @resource.action :assemble }.should_not raise_error(ArgumentError) - lambda { @resource.action :stop }.should_not raise_error(ArgumentError) + lambda { @resource.action :create }.should_not raise_error + lambda { @resource.action :assemble }.should_not raise_error + lambda { @resource.action :stop }.should_not raise_error end it "should allow you to set the raid_device attribute" do diff --git a/spec/unit/resource/mount_spec.rb b/spec/unit/resource/mount_spec.rb index fb414018ba..c80f6971f1 100644 --- a/spec/unit/resource/mount_spec.rb +++ b/spec/unit/resource/mount_spec.rb @@ -42,9 +42,9 @@ describe Chef::Resource::Mount do end it "should accept mount, umount and remount as actions" do - lambda { @resource.action :mount }.should_not raise_error(ArgumentError) - lambda { @resource.action :umount }.should_not raise_error(ArgumentError) - lambda { @resource.action :remount }.should_not raise_error(ArgumentError) + lambda { @resource.action :mount }.should_not raise_error + lambda { @resource.action :umount }.should_not raise_error + lambda { @resource.action :remount }.should_not raise_error lambda { @resource.action :brooklyn }.should raise_error(ArgumentError) end diff --git a/spec/unit/resource/route_spec.rb b/spec/unit/resource/route_spec.rb index bca42f1101..4522438402 100644 --- a/spec/unit/resource/route_spec.rb +++ b/spec/unit/resource/route_spec.rb @@ -39,8 +39,8 @@ describe Chef::Resource::Route do end it "should accept add or delete for action" do - lambda { @resource.action :add }.should_not raise_error(ArgumentError) - lambda { @resource.action :delete }.should_not raise_error(ArgumentError) + lambda { @resource.action :add }.should_not raise_error + lambda { @resource.action :delete }.should_not raise_error lambda { @resource.action :lolcat }.should raise_error(ArgumentError) end diff --git a/spec/unit/resource/user_spec.rb b/spec/unit/resource/user_spec.rb index caf12aa416..9972ddbba1 100644 --- a/spec/unit/resource/user_spec.rb +++ b/spec/unit/resource/user_spec.rb @@ -61,9 +61,9 @@ describe Chef::Resource::User, "initialize" do end it "should accept domain users (@ or \ separator) on non-windows" do - lambda { @resource.username "domain\@user" }.should_not raise_error(ArgumentError) + lambda { @resource.username "domain\@user" }.should_not raise_error @resource.username.should == "domain\@user" - lambda { @resource.username "domain\\user" }.should_not raise_error(ArgumentError) + lambda { @resource.username "domain\\user" }.should_not raise_error @resource.username.should == "domain\\user" end end diff --git a/spec/unit/resource/yum_package_spec.rb b/spec/unit/resource/yum_package_spec.rb index 783a539eb2..57ab4dfcd9 100644 --- a/spec/unit/resource/yum_package_spec.rb +++ b/spec/unit/resource/yum_package_spec.rb @@ -78,8 +78,8 @@ describe Chef::Resource::YumPackage, "allow_downgrade" do end it "should allow you to specify whether allow_downgrade is true or false" do - lambda { @resource.allow_downgrade true }.should_not raise_error(ArgumentError) - lambda { @resource.allow_downgrade false }.should_not raise_error(ArgumentError) + lambda { @resource.allow_downgrade true }.should_not raise_error + lambda { @resource.allow_downgrade false }.should_not raise_error lambda { @resource.allow_downgrade "monkey" }.should raise_error(ArgumentError) end end diff --git a/spec/unit/resource_collection_spec.rb b/spec/unit/resource_collection_spec.rb index d8fc0db8e0..cf62f5ff40 100644 --- a/spec/unit/resource_collection_spec.rb +++ b/spec/unit/resource_collection_spec.rb @@ -118,7 +118,7 @@ describe Chef::ResourceCollection do @rc.each_index do |i| results << @rc[i].name end - }.should_not raise_error() + }.should_not raise_error results.each_index do |i| case i when 0 diff --git a/spec/unit/resource_definition_spec.rb b/spec/unit/resource_definition_spec.rb index abac4c1163..f24254cfce 100644 --- a/spec/unit/resource_definition_spec.rb +++ b/spec/unit/resource_definition_spec.rb @@ -58,7 +58,7 @@ describe Chef::ResourceDefinition do lambda { @def.define :smoke do end - }.should_not raise_error(ArgumentError) + }.should_not raise_error lambda { @def.define "george washington" do end @@ -70,7 +70,7 @@ describe Chef::ResourceDefinition do lambda { @def.define :smoke, :cigar => "cuban", :cigarette => "marlboro" do end - }.should_not raise_error(ArgumentError) + }.should_not raise_error end it "should expose the prototype hash params in the params hash" do diff --git a/spec/unit/resource_reporter_spec.rb b/spec/unit/resource_reporter_spec.rb index e2ecde212f..c6f41156a4 100644 --- a/spec/unit/resource_reporter_spec.rb +++ b/spec/unit/resource_reporter_spec.rb @@ -35,21 +35,21 @@ describe Chef::ResourceReporter do before do @node = Chef::Node.new @node.name("spitfire") - @rest_client = mock("Chef::REST (mock)") - @rest_client.stub!(:post_rest).and_return(true) + @rest_client = double("Chef::REST (mock)") + @rest_client.stub(:post_rest).and_return(true) @resource_reporter = Chef::ResourceReporter.new(@rest_client) @run_id = @resource_reporter.run_id @new_resource = Chef::Resource::File.new("/tmp/a-file.txt") @new_resource.cookbook_name = "monkey" - @cookbook_version = mock("Cookbook::Version", :version => "1.2.3") - @new_resource.stub!(:cookbook_version).and_return(@cookbook_version) + @cookbook_version = double("Cookbook::Version", :version => "1.2.3") + @new_resource.stub(:cookbook_version).and_return(@cookbook_version) @current_resource = Chef::Resource::File.new("/tmp/a-file.txt") @start_time = Time.new @end_time = Time.new + 20 @events = Chef::EventDispatch::Dispatcher.new @run_context = Chef::RunContext.new(@node, {}, @events) @run_status = Chef::RunStatus.new(@node, @events) - Time.stub!(:now).and_return(@start_time, @end_time) + Time.stub(:now).and_return(@start_time, @end_time) end context "when first created" do @@ -87,9 +87,9 @@ describe Chef::ResourceReporter do context "when chef fails" do before do - @rest_client.stub!(:create_url).and_return("reports/nodes/spitfire/runs/#{@run_id}"); - @rest_client.stub!(:raw_http_request).and_return({"result"=>"ok"}); - @rest_client.stub!(:post_rest).and_return({"uri"=>"https://example.com/reports/nodes/spitfire/runs/#{@run_id}"}); + @rest_client.stub(:create_url).and_return("reports/nodes/spitfire/runs/#{@run_id}"); + @rest_client.stub(:raw_http_request).and_return({"result"=>"ok"}); + @rest_client.stub(:post_rest).and_return({"uri"=>"https://example.com/reports/nodes/spitfire/runs/#{@run_id}"}); end @@ -255,9 +255,9 @@ describe Chef::ResourceReporter do describe "when generating a report for the server" do before do - @rest_client.stub!(:create_url).and_return("reports/nodes/spitfire/runs/#{@run_id}"); - @rest_client.stub!(:raw_http_request).and_return({"result"=>"ok"}); - @rest_client.stub!(:post_rest).and_return({"uri"=>"https://example.com/reports/nodes/spitfire/runs/#{@run_id}"}); + @rest_client.stub(:create_url).and_return("reports/nodes/spitfire/runs/#{@run_id}"); + @rest_client.stub(:raw_http_request).and_return({"result"=>"ok"}); + @rest_client.stub(:post_rest).and_return({"uri"=>"https://example.com/reports/nodes/spitfire/runs/#{@run_id}"}); @resource_reporter.run_started(@run_status) end @@ -381,10 +381,10 @@ describe Chef::ResourceReporter do @backtrace = ["foo.rb:1 in `foo!'","bar.rb:2 in `bar!","'baz.rb:3 in `baz!'"] @node = Chef::Node.new @node.name("spitfire") - @exception = mock("ArgumentError") - @exception.stub!(:inspect).and_return("Net::HTTPServerException") - @exception.stub!(:message).and_return("Object not found") - @exception.stub!(:backtrace).and_return(@backtrace) + @exception = double("ArgumentError") + @exception.stub(:inspect).and_return("Net::HTTPServerException") + @exception.stub(:message).and_return("Object not found") + @exception.stub(:backtrace).and_return(@backtrace) @resource_reporter.run_list_expand_failed(@node, @exception) @resource_reporter.run_failed(@exception) @report = @resource_reporter.prepare_run_data @@ -602,7 +602,7 @@ describe Chef::ResourceReporter do @resource_reporter.resource_current_state_loaded(@new_resource, :create, @current_resource) @resource_reporter.resource_updated(@new_resource, :create) - @resource_reporter.stub!(:end_time).and_return(@end_time) + @resource_reporter.stub(:end_time).and_return(@end_time) @expected_data = @resource_reporter.prepare_run_data post_url = "https://chef_server/example_url" diff --git a/spec/unit/resource_spec.rb b/spec/unit/resource_spec.rb index dd1a0259e4..e9a60c9861 100644 --- a/spec/unit/resource_spec.rb +++ b/spec/unit/resource_spec.rb @@ -205,8 +205,8 @@ describe Chef::Resource do describe "noop" do it "should accept true or false for noop" do - lambda { @resource.noop true }.should_not raise_error(ArgumentError) - lambda { @resource.noop false }.should_not raise_error(ArgumentError) + lambda { @resource.noop true }.should_not raise_error + lambda { @resource.noop false }.should_not raise_error lambda { @resource.noop "eat it" }.should raise_error(ArgumentError) end end @@ -589,7 +589,7 @@ describe Chef::Resource do it "should print \"skipped due to action :nothing\" message for doc formatter when action is :nothing" do fdoc = Chef::Formatters.new(:doc, STDOUT, STDERR) - @run_context.stub!(:events).and_return(fdoc) + @run_context.stub(:events).and_return(fdoc) fdoc.should_receive(:puts).with(" (skipped due to action :nothing)") @resource.should_skip?(:nothing) end diff --git a/spec/unit/rest/auth_credentials_spec.rb b/spec/unit/rest/auth_credentials_spec.rb index 2c84c1e1bb..477da0faec 100644 --- a/spec/unit/rest/auth_credentials_spec.rb +++ b/spec/unit/rest/auth_credentials_spec.rb @@ -84,7 +84,7 @@ describe Chef::REST::AuthCredentials do end it "generates signature headers for the request" do - Time.stub!(:now).and_return(@request_time) + Time.stub(:now).and_return(@request_time) actual = @auth_credentials.signature_headers(@request_params) actual["HOST"].should == "localhost" actual["X-OPS-AUTHORIZATION-1"].should == "kBssX1ENEwKtNYFrHElN9vYGWS7OeowepN9EsYc9csWfh8oUovryPKDxytQ/" @@ -110,7 +110,7 @@ describe Chef::REST::AuthCredentials do end it "generates the correct signature for version 1.1" do - Time.stub!(:now).and_return(@request_time) + Time.stub(:now).and_return(@request_time) actual = @auth_credentials.signature_headers(@request_params) actual["HOST"].should == "localhost" actual["X-OPS-CONTENT-HASH"].should == "1tuzs5XKztM1ANrkGNPah6rW9GY=" diff --git a/spec/unit/rest_spec.rb b/spec/unit/rest_spec.rb index 86e447a66f..a53b4c9507 100644 --- a/spec/unit/rest_spec.rb +++ b/spec/unit/rest_spec.rb @@ -578,13 +578,13 @@ describe Chef::REST do it "does not raise a divide by zero exception if the content's actual size is 0" do http_response['Content-Length'] = "5" http_response.stub(:read_body).and_yield('') - expect { rest.streaming_request(url, {}) }.to_not raise_error(ZeroDivisionError) + expect { rest.streaming_request(url, {}) }.to raise_error(Chef::Exceptions::ContentLengthMismatch) end it "does not raise a divide by zero exception when the Content-Length is 0" do http_response['Content-Length'] = "0" http_response.stub(:read_body).and_yield("ninja") - expect { rest.streaming_request(url, {}) }.to_not raise_error(ZeroDivisionError) + expect { rest.streaming_request(url, {}) }.to raise_error(Chef::Exceptions::ContentLengthMismatch) end it "it raises an exception when the download is truncated" do diff --git a/spec/unit/run_list/run_list_expansion_spec.rb b/spec/unit/run_list/run_list_expansion_spec.rb index 012ee9ea31..907e3d3985 100644 --- a/spec/unit/run_list/run_list_expansion_spec.rb +++ b/spec/unit/run_list/run_list_expansion_spec.rb @@ -66,7 +66,7 @@ describe Chef::RunList::RunListExpansion do describe "after applying a role" do before do - @expansion.stub!(:fetch_role).and_return(Chef::Role.new) + @expansion.stub(:fetch_role).and_return(Chef::Role.new) @expansion.inflate_role('rage', "role[base]") end @@ -89,7 +89,7 @@ describe Chef::RunList::RunListExpansion do @second_role.run_list('recipe[crabrevenge]') @second_role.default_attributes({'foo' => 'boo'}) @second_role.override_attributes({'baz' => 'bux'}) - @expansion.stub!(:fetch_role).and_return(@first_role, @second_role) + @expansion.stub(:fetch_role).and_return(@first_role, @second_role) @expansion.expand end @@ -111,7 +111,7 @@ describe Chef::RunList::RunListExpansion do describe "after expanding a run list with a non existant role" do before do - @expansion.stub!(:fetch_role) { @expansion.role_not_found('crabrevenge', "role[base]") } + @expansion.stub(:fetch_role) { @expansion.role_not_found('crabrevenge', "role[base]") } @expansion.expand end diff --git a/spec/unit/run_list_spec.rb b/spec/unit/run_list_spec.rb index f18f21a82b..220e4ea4a6 100644 --- a/spec/unit/run_list_spec.rb +++ b/spec/unit/run_list_spec.rb @@ -173,9 +173,9 @@ describe Chef::RunList do @role.default_attributes :one => :two @role.override_attributes :three => :four - Chef::Role.stub!(:load).and_return(@role) - @rest = mock("Chef::REST", { :get_rest => @role, :url => "/" }) - Chef::REST.stub!(:new).and_return(@rest) + Chef::Role.stub(:load).and_return(@role) + @rest = double("Chef::REST", { :get_rest => @role, :url => "/" }) + Chef::REST.stub(:new).and_return(@rest) @run_list << "role[stubby]" @run_list << "kitty" @@ -188,7 +188,7 @@ describe Chef::RunList do end it "should log a helpful error if the role is not available" do - Chef::Role.stub!(:from_disk).and_raise(Chef::Exceptions::RoleNotFound) + Chef::Role.stub(:from_disk).and_raise(Chef::Exceptions::RoleNotFound) Chef::Log.should_receive(:error).with("Role stubby (included by 'top level') is in the runlist but does not exist. Skipping expand.") @run_list.expand("_default", "disk") end @@ -218,7 +218,7 @@ describe Chef::RunList do describe "and multiply nested roles" do before do - @multiple_rest_requests = mock("Chef::REST") + @multiple_rest_requests = double("Chef::REST") @role.env_run_list["production"] << "role[prod-base]" @@ -233,7 +233,7 @@ describe Chef::RunList do end it "expands the run list using the specified environment for all nested roles" do - Chef::REST.stub!(:new).and_return(@multiple_rest_requests) + Chef::REST.stub(:new).and_return(@multiple_rest_requests) @multiple_rest_requests.should_receive(:get_rest).with("roles/stubby").and_return(@role) @multiple_rest_requests.should_receive(:get_rest).with("roles/prod-base").and_return(@role_prod_base) @multiple_rest_requests.should_receive(:get_rest).with("roles/nested-deeper").and_return(@role_nested_deeper) @@ -270,8 +270,8 @@ describe Chef::RunList do dog.default_attributes :seven => :nine dog.run_list "three" @role.run_list << "role[dog]" - Chef::Role.stub!(:from_disk).with("stubby").and_return(@role) - Chef::Role.stub!(:from_disk).with("dog").and_return(dog) + Chef::Role.stub(:from_disk).with("stubby").and_return(@role) + Chef::Role.stub(:from_disk).with("dog").and_return(dog) expansion = @run_list.expand("_default", 'disk') expansion.recipes[2].should == "three" @@ -284,7 +284,7 @@ describe Chef::RunList do dog.default_attributes :seven => :nine dog.run_list "role[dog]", "three" @role.run_list << "role[dog]" - Chef::Role.stub!(:from_disk).with("stubby").and_return(@role) + Chef::Role.stub(:from_disk).with("stubby").and_return(@role) Chef::Role.should_receive(:from_disk).with("dog").once.and_return(dog) expansion = @run_list.expand("_default", 'disk') diff --git a/spec/unit/run_status_spec.rb b/spec/unit/run_status_spec.rb index 049b86cf54..6c85364871 100644 --- a/spec/unit/run_status_spec.rb +++ b/spec/unit/run_status_spec.rb @@ -55,7 +55,7 @@ describe Chef::RunStatus do before do @start_time = Time.new @end_time = @start_time + 23 - Time.stub!(:now).and_return(@start_time, @end_time) + Time.stub(:now).and_return(@start_time, @end_time) @run_status.start_clock @run_status.stop_clock end diff --git a/spec/unit/runner_spec.rb b/spec/unit/runner_spec.rb index 28082078c2..68d8b0e011 100644 --- a/spec/unit/runner_spec.rb +++ b/spec/unit/runner_spec.rb @@ -125,24 +125,24 @@ describe Chef::Runner do it "should raise exceptions as thrown by a provider" do provider = Chef::Provider::SnakeOil.new(@run_context.resource_collection[0], @run_context) - Chef::Provider::SnakeOil.stub!(:new).once.and_return(provider) - provider.stub!(:action_sell).once.and_raise(ArgumentError) + Chef::Provider::SnakeOil.stub(:new).once.and_return(provider) + provider.stub(:action_sell).once.and_raise(ArgumentError) lambda { @runner.converge }.should raise_error(ArgumentError) end it "should not raise exceptions thrown by providers if the resource has ignore_failure set to true" do - @run_context.resource_collection[0].stub!(:ignore_failure).and_return(true) + @run_context.resource_collection[0].stub(:ignore_failure).and_return(true) provider = Chef::Provider::SnakeOil.new(@run_context.resource_collection[0], @run_context) - Chef::Provider::SnakeOil.stub!(:new).once.and_return(provider) - provider.stub!(:action_sell).once.and_raise(ArgumentError) - lambda { @runner.converge }.should_not raise_error(ArgumentError) + Chef::Provider::SnakeOil.stub(:new).once.and_return(provider) + provider.stub(:action_sell).once.and_raise(ArgumentError) + lambda { @runner.converge }.should_not raise_error end it "should retry with the specified delay if retries are specified" do @first_resource.retries 3 provider = Chef::Provider::SnakeOil.new(@run_context.resource_collection[0], @run_context) - Chef::Provider::SnakeOil.stub!(:new).once.and_return(provider) - provider.stub!(:action_sell).and_raise(ArgumentError) + Chef::Provider::SnakeOil.stub(:new).once.and_return(provider) + provider.stub(:action_sell).and_raise(ArgumentError) @first_resource.should_receive(:sleep).with(2).exactly(3).times lambda { @runner.converge }.should raise_error(ArgumentError) end diff --git a/spec/unit/scan_access_control_spec.rb b/spec/unit/scan_access_control_spec.rb index 3cfecfaa35..48f820ff85 100644 --- a/spec/unit/scan_access_control_spec.rb +++ b/spec/unit/scan_access_control_spec.rb @@ -49,7 +49,7 @@ describe Chef::ScanAccessControl do describe "when the fs entity exists" do before do - @stat = mock("File::Stat for #{@new_resource.path}", :uid => 0, :gid => 0, :mode => 00100644) + @stat = double("File::Stat for #{@new_resource.path}", :uid => 0, :gid => 0, :mode => 00100644) File.should_receive(:realpath).with(@new_resource.path).and_return(@real_file) File.should_receive(:stat).with(@real_file).and_return(@stat) File.should_receive(:exist?).with(@new_resource.path).and_return(true) @@ -128,7 +128,7 @@ describe Chef::ScanAccessControl do end it "sets the owner of current_resource to the username of the current owner" do - @root_passwd = mock("Struct::Passwd for uid 0", :name => "root") + @root_passwd = double("Struct::Passwd for uid 0", :name => "root") Etc.should_receive(:getpwuid).with(0).and_return(@root_passwd) @scanner.set_all! @@ -163,7 +163,7 @@ describe Chef::ScanAccessControl do end it "sets the group of the current resource to the group name" do - @group_entry = mock("Struct::Group for wheel", :name => "wheel") + @group_entry = double("Struct::Group for wheel", :name => "wheel") Etc.should_receive(:getgrgid).with(0).and_return(@group_entry) @scanner.set_all! diff --git a/spec/unit/search/query_spec.rb b/spec/unit/search/query_spec.rb index 3f41c142ee..7463e3bb3c 100644 --- a/spec/unit/search/query_spec.rb +++ b/spec/unit/search/query_spec.rb @@ -21,8 +21,8 @@ require 'chef/search/query' describe Chef::Search::Query do before(:each) do - @rest = mock("Chef::REST") - Chef::REST.stub!(:new).and_return(@rest) + @rest = double("Chef::REST") + Chef::REST.stub(:new).and_return(@rest) @query = Chef::Search::Query.new end @@ -38,12 +38,12 @@ describe Chef::Search::Query do "start" => 0, "total" => 4 } - @rest.stub!(:get_rest).and_return(@response) + @rest.stub(:get_rest).and_return(@response) end it "should accept a type as the first argument" do - lambda { @query.search("foo") }.should_not raise_error(ArgumentError) - lambda { @query.search(:foo) }.should_not raise_error(ArgumentError) + lambda { @query.search("foo") }.should_not raise_error + lambda { @query.search(:foo) }.should_not raise_error lambda { @query.search(Hash.new) }.should raise_error(ArgumentError) end @@ -85,13 +85,13 @@ describe Chef::Search::Query do end it "should call a block for each object in the response" do - @call_me = mock("blocky") + @call_me = double("blocky") @response["rows"].each { |r| @call_me.should_receive(:do).with(r) } @query.search(:foo) { |r| @call_me.do(r) } end it "should page through the responses" do - @call_me = mock("blocky") + @call_me = double("blocky") @response["rows"].each { |r| @call_me.should_receive(:do).with(r) } @query.search(:foo, "*:*", nil, 0, 1) { |r| @call_me.do(r) } end diff --git a/spec/unit/shell/model_wrapper_spec.rb b/spec/unit/shell/model_wrapper_spec.rb index 35dc591edc..eae3b2b581 100644 --- a/spec/unit/shell/model_wrapper_spec.rb +++ b/spec/unit/shell/model_wrapper_spec.rb @@ -71,8 +71,8 @@ describe Shell::ModelWrapper do @wrapper = Shell::ModelWrapper.new(Chef::Node) # Creating a Chef::Search::Query object tries to read the private key... - @searcher = mock("Chef::Search::Query #{__FILE__}:#{__LINE__}") - Chef::Search::Query.stub!(:new).and_return(@searcher) + @searcher = double("Chef::Search::Query #{__FILE__}:#{__LINE__}") + Chef::Search::Query.stub(:new).and_return(@searcher) end it "falls back to listing the objects when the 'query' is :all" do diff --git a/spec/unit/shell/shell_ext_spec.rb b/spec/unit/shell/shell_ext_spec.rb index 22e9ae674b..c24acbca3e 100644 --- a/spec/unit/shell/shell_ext_spec.rb +++ b/spec/unit/shell/shell_ext_spec.rb @@ -23,21 +23,21 @@ describe Shell::Extensions do before do @shell_client = TestableShellSession.instance - Shell.stub!(:session).and_return(@shell_client) + Shell.stub(:session).and_return(@shell_client) @job_manager = TestJobManager.new @root_context = Object.new @root_context.instance_eval(&ObjectTestHarness) Shell::Extensions.extend_context_object(@root_context) - @root_context.conf = mock("irbconf") + @root_context.conf = double("irbconf") end it "finds a subsession in irb for an object" do target_context_obj = Chef::Node.new - irb_context = mock("context", :main => target_context_obj) - irb_session = mock("irb session", :context => irb_context) + irb_context = double("context", :main => target_context_obj) + irb_session = double("irb session", :context => irb_context) @job_manager.jobs = [[:thread, irb_session]] - @root_context.stub!(:jobs).and_return(@job_manager) + @root_context.stub(:jobs).and_return(@job_manager) @root_context.ensure_session_select_defined @root_context.jobs.select_shell_session(target_context_obj).should == irb_session @root_context.jobs.select_shell_session(:idontexist).should be_nil @@ -45,8 +45,8 @@ describe Shell::Extensions do it "finds, then switches to a session" do @job_manager.jobs = [] - @root_context.stub!(:ensure_session_select_defined) - @root_context.stub!(:jobs).and_return(@job_manager) + @root_context.stub(:ensure_session_select_defined) + @root_context.stub(:jobs).and_return(@job_manager) @job_manager.should_receive(:select_shell_session).and_return(:the_shell_session) @job_manager.should_receive(:switch).with(:the_shell_session) @root_context.find_or_create_session_for(:foo) @@ -54,8 +54,8 @@ describe Shell::Extensions do it "creates a new session if an existing one isn't found" do @job_manager.jobs = [] - @root_context.stub!(:jobs).and_return(@job_manager) - @job_manager.stub!(:select_shell_session).and_return(nil) + @root_context.stub(:jobs).and_return(@job_manager) + @job_manager.stub(:select_shell_session).and_return(nil) @root_context.should_receive(:irb).with(:foo) @root_context.find_or_create_session_for(:foo) end @@ -81,18 +81,18 @@ describe Shell::Extensions do it "turns irb tracing on and off" do @root_context.should respond_to(:trace) @root_context.conf.should_receive(:use_tracer=).with(true) - @root_context.stub!(:tracing?) + @root_context.stub(:tracing?) @root_context.tracing :on end it "says if tracing is on or off" do - @root_context.conf.stub!(:use_tracer).and_return(true) + @root_context.conf.stub(:use_tracer).and_return(true) @root_context.should_receive(:puts).with("tracing is on") @root_context.tracing? end it "prints node attributes" do - node = mock("node", :attribute => {:foo => :bar}) + node = double("node", :attribute => {:foo => :bar}) @shell_client.node = node @root_context.should_receive(:pp).with({:foo => :bar}) @root_context.ohai @@ -111,14 +111,14 @@ describe Shell::Extensions do end it "says if echo is on or off" do - @root_context.conf.stub!(:echo).and_return(true) + @root_context.conf.stub(:echo).and_return(true) @root_context.should_receive(:puts).with("echo is on") @root_context.echo? end it "gives access to the stepable iterator" do - Shell::StandAloneSession.instance.stub!(:reset!) - Shell.session.stub!(:rebuild_context) + Shell::StandAloneSession.instance.stub(:reset!) + Shell.session.stub(:rebuild_context) events = Chef::EventDispatch::Dispatcher.new run_context = Chef::RunContext.new(Chef::Node.new, {}, events) run_context.resource_collection.instance_variable_set(:@iterator, :the_iterator) diff --git a/spec/unit/shell/shell_session_spec.rb b/spec/unit/shell/shell_session_spec.rb index a0fc3028f6..e5fc46e945 100644 --- a/spec/unit/shell/shell_session_spec.rb +++ b/spec/unit/shell/shell_session_spec.rb @@ -52,7 +52,7 @@ describe Shell::ClientSession do @session = Shell::ClientSession.instance @node = Chef::Node.build("foo") @session.node = @node - @session.instance_variable_set(:@client, stub(:sync_cookbooks => {})) + @session.instance_variable_set(:@client, double(:sync_cookbooks => {})) @expansion = Chef::RunList::RunListExpansion.new(@node.chef_environment, []) @node.run_list.should_receive(:expand).with(@node.chef_environment).and_return(@expansion) @@ -87,9 +87,9 @@ describe Shell::StandAloneSession do end it "runs chef with the standalone recipe" do - @session.stub!(:node_built?).and_return(true) - Chef::Log.stub!(:level) - chef_runner = mock("Chef::Runner.new", :converge => :converged) + @session.stub(:node_built?).and_return(true) + Chef::Log.stub(:level) + chef_runner = double("Chef::Runner.new", :converge => :converged) # pre-heat resource collection cache @session.resource_collection @@ -116,7 +116,7 @@ describe Shell::SoloSession do end it "returns a collection based on it's compilation object and the extra recipe provided by chef-shell" do - @session.stub!(:node_built?).and_return(true) + @session.stub(:node_built?).and_return(true) kitteh = Chef::Resource::Cat.new("keyboard") @recipe.run_context.resource_collection << kitteh @session.resource_collection.should include(kitteh) @@ -133,7 +133,7 @@ describe Shell::SoloSession do end it "generates its resource collection from the compiled cookbooks and the ad hoc recipe" do - @session.stub!(:node_built?).and_return(true) + @session.stub(:node_built?).and_return(true) kitteh_cat = Chef::Resource::Cat.new("kitteh") @run_context.resource_collection << kitteh_cat keyboard_cat = Chef::Resource::Cat.new("keyboard_cat") @@ -143,9 +143,9 @@ describe Shell::SoloSession do end it "runs chef with a resource collection from the compiled cookbooks" do - @session.stub!(:node_built?).and_return(true) - Chef::Log.stub!(:level) - chef_runner = mock("Chef::Runner.new", :converge => :converged) + @session.stub(:node_built?).and_return(true) + Chef::Log.stub(:level) + chef_runner = double("Chef::Runner.new", :converge => :converged) Chef::Runner.should_receive(:new).with(an_instance_of(Chef::RunContext)).and_return(chef_runner) @recipe.run_chef.should == :converged diff --git a/spec/unit/shell_spec.rb b/spec/unit/shell_spec.rb index fd4241732f..cce743873f 100644 --- a/spec/unit/shell_spec.rb +++ b/spec/unit/shell_spec.rb @@ -42,8 +42,7 @@ describe Shell do before do Shell.irb_conf = {} - Shell::ShellSession.instance.rspec_reset - Shell::ShellSession.instance.stub!(:reset!) + Shell::ShellSession.instance.stub(:reset!) end describe "reporting its status" do diff --git a/spec/unit/user_spec.rb b/spec/unit/user_spec.rb index 9121babeed..c535e4172b 100644 --- a/spec/unit/user_spec.rb +++ b/spec/unit/user_spec.rb @@ -196,8 +196,8 @@ describe Chef::User do before (:each) do @user = Chef::User.new @user.name "foobar" - @http_client = mock("Chef::REST mock") - Chef::REST.stub!(:new).and_return(@http_client) + @http_client = double("Chef::REST mock") + Chef::REST.stub(:new).and_return(@http_client) end describe "list" do @@ -208,12 +208,12 @@ describe Chef::User do end it "lists all clients on an OSC server" do - @http_client.stub!(:get_rest).with("users").and_return(@osc_response) + @http_client.stub(:get_rest).with("users").and_return(@osc_response) Chef::User.list.should == @osc_response end it "lists all clients on an OHC/OPC server" do - @http_client.stub!(:get_rest).with("users").and_return(@ohc_response) + @http_client.stub(:get_rest).with("users").and_return(@ohc_response) # We expect that Chef::User.list will give a consistent response # so OHC API responses should be transformed to OSC-style output. Chef::User.list.should == @osc_response diff --git a/spec/unit/util/backup_spec.rb b/spec/unit/util/backup_spec.rb index c49694f924..617886cede 100644 --- a/spec/unit/util/backup_spec.rb +++ b/spec/unit/util/backup_spec.rb @@ -27,7 +27,7 @@ describe Chef::Util::Backup do end before(:each) do - @new_resource = mock("new_resource") + @new_resource = double("new_resource") @new_resource.should_receive(:path).at_least(:once).and_return(tempfile.path) @backup = Chef::Util::Backup.new(@new_resource) end diff --git a/spec/unit/util/selinux_spec.rb b/spec/unit/util/selinux_spec.rb index 710380e6fc..d87cebf95c 100644 --- a/spec/unit/util/selinux_spec.rb +++ b/spec/unit/util/selinux_spec.rb @@ -53,7 +53,7 @@ describe Chef::Util::Selinux do describe "when selinuxenabled binary exists" do before do @selinux_enabled_path = File.join("/sbin", "selinuxenabled") - File.stub!(:executable?) do |file_path| + File.stub(:executable?) do |file_path| file_path.end_with?("selinuxenabled").should be_true file_path == @selinux_enabled_path end @@ -61,7 +61,7 @@ describe Chef::Util::Selinux do describe "when selinux is enabled" do before do - cmd_result = mock("Cmd Result", :exitstatus => 0) + cmd_result = double("Cmd Result", :exitstatus => 0) @test_instance.should_receive(:shell_out!).once.with(@selinux_enabled_path, {:returns=>[0, 1]}).and_return(cmd_result) end @@ -74,7 +74,7 @@ describe Chef::Util::Selinux do describe "when selinux is disabled" do before do - cmd_result = mock("Cmd Result", :exitstatus => 1) + cmd_result = double("Cmd Result", :exitstatus => 1) @test_instance.should_receive(:shell_out!).once.with(@selinux_enabled_path, {:returns=>[0, 1]}).and_return(cmd_result) end @@ -87,7 +87,7 @@ describe Chef::Util::Selinux do describe "when selinux gives an unexpected status" do before do - cmd_result = mock("Cmd Result", :exitstatus => 101) + cmd_result = double("Cmd Result", :exitstatus => 101) @test_instance.should_receive(:shell_out!).once.with(@selinux_enabled_path, {:returns=>[0, 1]}).and_return(cmd_result) end @@ -99,7 +99,7 @@ describe Chef::Util::Selinux do describe "when selinuxenabled binary doesn't exist" do before do - File.stub!(:executable?) do |file_path| + File.stub(:executable?) do |file_path| file_path.end_with?("selinuxenabled").should be_true false end @@ -118,7 +118,7 @@ describe Chef::Util::Selinux do before do @restorecon_enabled_path = File.join("/sbin", "restorecon") - File.stub!(:executable?) do |file_path| + File.stub(:executable?) do |file_path| file_path.end_with?("restorecon").should be_true file_path == @restorecon_enabled_path end @@ -150,7 +150,7 @@ describe Chef::Util::Selinux do describe "when restorecon doesn't exist on the system" do before do - File.stub!(:executable?) do |file_path| + File.stub(:executable?) do |file_path| file_path.end_with?("restorecon").should be_true false end |