diff options
author | Lamont Granquist <lamont@scriptkiddie.org> | 2014-01-29 14:17:47 -0800 |
---|---|---|
committer | Lamont Granquist <lamont@scriptkiddie.org> | 2014-01-29 14:17:47 -0800 |
commit | b19b7d000887209f9d8dc1dc6aa468a0497a7391 (patch) | |
tree | 68d1eb6c136df20c2800f1dddb4e2c1ed5d75a42 /spec/unit | |
parent | b5c9c6afdfd83fe3f1bf4c991daffeff94b49750 (diff) | |
download | chef-b19b7d000887209f9d8dc1dc6aa468a0497a7391.tar.gz |
s/stub!/stub/g
fix deprecation warnings
Diffstat (limited to 'spec/unit')
185 files changed, 1580 insertions, 1580 deletions
diff --git a/spec/unit/api_client/registration_spec.rb b/spec/unit/api_client/registration_spec.rb index 0d21730664..be98c86e55 100644 --- a/spec/unit/api_client/registration_spec.rb +++ b/spec/unit/api_client/registration_spec.rb @@ -53,7 +53,7 @@ describe Chef::ApiClient::Registration do let(:http_mock) { mock("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 @@ -128,7 +128,7 @@ describe Chef::ApiClient::Registration do let(:http_mock) { mock("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..945e5ed70f 100644 --- a/spec/unit/api_client_spec.rb +++ b/spec/unit/api_client_spec.rb @@ -190,7 +190,7 @@ 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) + 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..4ada2b521c 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 @@ -37,9 +37,9 @@ describe Chef::Application::Apply 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) + @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..e96be3e54f 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 @@ -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 diff --git a/spec/unit/application/solo_spec.rb b/spec/unit/application/solo_spec.rb index 41e0cf3b2b..cc32577218 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::Daemon.stub(:change_privilege) @chef_client = mock("Chef::Client") - Chef::Client.stub!(:new).and_return(@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/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..724b8ba451 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 @@ -254,14 +254,14 @@ shared_examples_for Chef::Client do 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) + Chef::RunLock.stub(:new).and_return(@run_lock) @events = mock("Chef::EventDispatch::Dispatcher").as_null_object - Chef::EventDispatch::Dispatcher.stub!(:new).and_return(@events) + 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 @@ -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 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/synchronizer_spec.rb b/spec/unit/cookbook/synchronizer_spec.rb index 31f30c5bf4..3e015058c1 100644 --- a/spec/unit/cookbook/synchronizer_spec.rb +++ b/spec/unit/cookbook/synchronizer_spec.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 @@ -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,12 +103,12 @@ 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) + @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", @@ -167,9 +167,9 @@ 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", :path => "/tmp/cookbook_a_file_default_tempfile") diff --git a/spec/unit/daemon_spec.rb b/spec/unit/daemon_spec.rb index 69ca2ed321..d972fa7a4a 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,9 +73,9 @@ 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 @@ -117,25 +117,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) - 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 +156,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..7a0d3575fb 100644 --- a/spec/unit/data_bag_item_spec.rb +++ b/spec/unit/data_bag_item_spec.rb @@ -204,7 +204,7 @@ describe Chef::DataBagItem do describe "save" do before do @rest = mock("Chef::REST") - Chef::REST.stub!(:new).and_return(@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 @@ -248,7 +248,7 @@ 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) + 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..8b3c0d71ad 100644 --- a/spec/unit/data_bag_spec.rb +++ b/spec/unit/data_bag_spec.rb @@ -79,7 +79,7 @@ describe Chef::DataBag do before do @data_bag.name('piggly_wiggly') @rest = mock("Chef::REST") - Chef::REST.stub!(:new).and_return(@rest) + Chef::REST.stub(:new).and_return(@rest) end it "should silently proceed when the data bag already exists" 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..c0c4feee19 100644 --- a/spec/unit/environment_spec.rb +++ b/spec/unit/environment_spec.rb @@ -356,9 +356,9 @@ describe Chef::Environment do describe "api model" do before(:each) do @rest = mock("Chef::REST") - Chef::REST.stub!(:new).and_return(@rest) + Chef::REST.stub(:new).and_return(@rest) @query = mock("Chef::Search::Query") - Chef::Search::Query.stub!(:new).and_return(@query) + Chef::Search::Query.stub(:new).and_return(@query) end describe "list" do diff --git a/spec/unit/file_access_control_spec.rb b/spec/unit/file_access_control_spec.rb index 609bd826b6..add56bcb6d 100644 --- a/spec/unit/file_access_control_spec.rb +++ b/spec/unit/file_access_control_spec.rb @@ -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/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..16e9c6584c 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 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..8ddc5200b0 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,7 +62,7 @@ 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" }) + @client.stub(:save).and_return({ 'private_key' => "woot" }) filehandle = mock("Filehandle") filehandle.should_receive(:print).with('woot') File.should_receive(:open).with("/tmp/monkeypants", "w").and_yield(filehandle) diff --git a/spec/unit/knife/client_reregister_spec.rb b/spec/unit/knife/client_reregister_spec.rb index d84978c497..b03071b973 100644 --- a/spec/unit/knife/client_reregister_spec.rb +++ b/spec/unit/knife/client_reregister_spec.rb @@ -24,7 +24,7 @@ describe Chef::Knife::ClientReregister do @knife.name_args = [ 'adam' ] @client_mock = mock('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/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..d6842ca2c6 100644 --- a/spec/unit/knife/configure_spec.rb +++ b/spec/unit/knife/configure_spec.rb @@ -7,19 +7,19 @@ 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) + @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..2dcc276ad2 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.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..79ec6769ec 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 @@ -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..96b5a860b3 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 @@ -67,17 +67,17 @@ 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.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 @@ -88,7 +88,7 @@ describe Chef::Knife::CookbookDownload do @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].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..5482d5d33c 100644 --- a/spec/unit/knife/cookbook_list_spec.rb +++ b/spec/unit/knife/cookbook_list_spec.rb @@ -22,7 +22,7 @@ describe Chef::Knife::CookbookList do before do @knife = Chef::Knife::CookbookList.new @rest_mock = mock('rest') - @knife.stub!(:rest).and_return(@rest_mock) + @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..11d8613590 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 @@ -110,7 +110,7 @@ describe Chef::Knife::CookbookMetadata do 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..44f7064a64 100644 --- a/spec/unit/knife/cookbook_show_spec.rb +++ b/spec/unit/knife/cookbook_show_spec.rb @@ -26,9 +26,9 @@ describe Chef::Knife::CookbookShow do @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) + @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_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..b89223b1eb 100644 --- a/spec/unit/knife/cookbook_site_share_spec.rb +++ b/spec/unit/knife/cookbook_site_share_spec.rb @@ -30,24 +30,24 @@ 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.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 @@ -99,43 +99,43 @@ describe Chef::Knife::CookbookSiteShare do before(:each) do @upload_response = mock('Net::HTTPResponse') - Chef::CookbookSiteStreamingUploader.stub!(:post).and_return(@upload_response) + 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..65318f03e0 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.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 @@ -56,7 +56,7 @@ describe Chef::Knife::CookbookSiteUnshare do 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)) + @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 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..e1fa5c975a 100644 --- a/spec/unit/knife/cookbook_upload_spec.rb +++ b/spec/unit/knife/cookbook_upload_spec.rb @@ -30,14 +30,14 @@ 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 @@ -46,8 +46,8 @@ describe Chef::Knife::CookbookUpload do 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 @@ -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,12 +130,12 @@ 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 @@ -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..f550b82835 100644 --- a/spec/unit/knife/core/ui_spec.rb +++ b/spec/unit/knife/core/ui_spec.rb @@ -412,28 +412,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 +449,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..534bc18f5c 100644 --- a/spec/unit/knife/data_bag_edit_spec.rb +++ b/spec/unit/knife/data_bag_edit_spec.rb @@ -30,10 +30,10 @@ describe Chef::Knife::DataBagEdit do @knife = Chef::Knife::DataBagEdit.new @rest = mock('chef-rest-mock') - @knife.stub!(:rest).and_return(@rest) + @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..aa1c16d0f4 100644 --- a/spec/unit/knife/data_bag_from_file_spec.rb +++ b/spec/unit/knife/data_bag_from_file_spec.rb @@ -30,9 +30,9 @@ describe Chef::Knife::DataBagFromFile do Chef::Config[:node_name] = "webmonkey.example.com" @knife = Chef::Knife::DataBagFromFile.new @rest = mock("Chef::REST") - @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) @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..669dfeb5cc 100644 --- a/spec/unit/knife/data_bag_show_spec.rb +++ b/spec/unit/knife/data_bag_show_spec.rb @@ -30,9 +30,9 @@ describe Chef::Knife::DataBagShow do @knife = Chef::Knife::DataBagShow.new @knife.config[:format] = 'json' @rest = mock("Chef::REST") - @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 @@ -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..251b525da1 100644 --- a/spec/unit/knife/index_rebuild_spec.rb +++ b/spec/unit/knife/index_rebuild_spec.rb @@ -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..680868d53c 100644 --- a/spec/unit/knife/status_spec.rb +++ b/spec/unit/knife/status_spec.rb @@ -26,11 +26,11 @@ describe Chef::Knife::Status do 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.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..00a570e4c8 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 diff --git a/spec/unit/knife/user_reregister_spec.rb b/spec/unit/knife/user_reregister_spec.rb index fddab57467..16d57042f0 100644 --- a/spec/unit/knife/user_reregister_spec.rb +++ b/spec/unit/knife/user_reregister_spec.rb @@ -24,9 +24,9 @@ describe Chef::Knife::UserReregister do @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) + 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_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..79f22852ae 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 diff --git a/spec/unit/mixin/checksum_spec.rb b/spec/unit/mixin/checksum_spec.rb index c0f0acdeb4..b701dd6a50 100644 --- a/spec/unit/mixin/checksum_spec.rb +++ b/spec/unit/mixin/checksum_spec.rb @@ -30,7 +30,7 @@ describe Chef::Mixin::Checksum do @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) + 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/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/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_spec.rb b/spec/unit/node_spec.rb index 1cc40979cc..d21059c9dd 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 @@ -765,9 +765,9 @@ describe Chef::Node do describe "api model" do before(:each) do @rest = mock("Chef::REST") - Chef::REST.stub!(:new).and_return(@rest) + Chef::REST.stub(:new).and_return(@rest) @query = mock("Chef::Search::Query") - Chef::Search::Query.stub!(:new).and_return(@query) + Chef::Search::Query.stub(:new).and_return(@query) end describe "list" do 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..ebdefd9bea 100644 --- a/spec/unit/provider/breakpoint_spec.rb +++ b/spec/unit/provider/breakpoint_spec.rb @@ -26,7 +26,7 @@ describe Chef::Provider::Breakpoint do @events = Chef::EventDispatch::Dispatcher.new @run_context = Chef::RunContext.new(@node, {}, @events) @collection = mock("resource collection") - @run_context.stub!(:resource_collection).and_return(@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) + Shell.stub(:running?).and_return(true) @iterator = mock("stepable_iterator") - @collection.stub!(:iterator).and_return(@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) + Shell.stub(:running?).and_return(false) @iterator = mock("stepable_iterator") - @collection.stub!(:iterator).and_return(@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..d2f1d3aef2 100644 --- a/spec/unit/provider/cookbook_file/content_spec.rb +++ b/spec/unit/provider/cookbook_file/content_spec.rb @@ -28,7 +28,7 @@ describe Chef::Provider::CookbookFile::Content do 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/cron/unix_spec.rb b/spec/unit/provider/cron/unix_spec.rb index ffdfa198b6..1683fad7a1 100644 --- a/spec/unit/provider/cron/unix_spec.rb +++ b/spec/unit/provider/cron/unix_spec.rb @@ -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 @@ -70,13 +70,13 @@ CRONTAB it "should return nil if the user has no crontab" do status = mock("Status", :exitstatus => 1) - @provider.stub!(:popen4).and_return(status) + @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) + @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") @@ -86,9 +86,9 @@ 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) + @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) + 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..ce5f0b7bf9 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 @@ -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 @@ -779,13 +779,13 @@ MAILTO=foo@example.com it "should return nil if the user has no crontab" do status = mock("Status", :exitstatus => 1) - @provider.stub!(:popen4).and_return(status) + @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) + @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") @@ -796,7 +796,7 @@ MAILTO=foo@example.com before :each do @status = mock("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 e7be723d28..4f38f77762 100644 --- a/spec/unit/provider/deploy/revision_spec.rb +++ b/spec/unit/provider/deploy/revision_spec.rb @@ -31,7 +31,7 @@ describe Chef::Provider::Deploy::Revision do @provider = Chef::Provider::Deploy::Revision.new(@resource, @run_context) @provider.load_current_resource @runner = mock("runnah") - Chef::Runner.stub!(:new).and_return(@runner) + Chef::Runner.stub(:new).and_return(@runner) @expected_release_dir = "/my/deploy/dir/releases/8a3195bf3efa246f743c5dfa83683201880f935c" end @@ -43,7 +43,7 @@ describe Chef::Provider::Deploy::Revision do 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 +52,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 +64,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 +89,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..5e3d07d3d9 100644 --- a/spec/unit/provider/deploy/timestamped_spec.rb +++ b/spec/unit/provider/deploy/timestamped_spec.rb @@ -22,7 +22,7 @@ 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 @@ -30,7 +30,7 @@ describe Chef::Provider::Deploy::Timestamped do @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) + 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..cec971c31b 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) + 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 @@ -584,7 +584,7 @@ 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) + 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..62e9816340 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.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) @@ -177,12 +177,12 @@ describe Chef::Provider::Directory do 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.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..ca5a94afe3 100644 --- a/spec/unit/provider/file/content_spec.rb +++ b/spec/unit/provider/file/content_spec.rb @@ -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/git_spec.rb b/spec/unit/provider/git_spec.rb index 4c54a17958..1f62ab1b03 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") @@ -68,7 +68,7 @@ describe Chef::Provider::Git do 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") @@ -110,7 +110,7 @@ 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 @@ -133,7 +133,7 @@ describe Chef::Provider::Git do @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.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) 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..5890ee43a1 100644 --- a/spec/unit/provider/group/dscl_spec.rb +++ b/spec/unit/provider/group/dscl_spec.rb @@ -32,7 +32,7 @@ describe Chef::Provider::Group::Dscl do @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 @@ -61,7 +61,7 @@ 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"]) + @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 @@ -246,7 +246,7 @@ 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) + File.stub(:exists?).and_return(true) lambda { @provider.process_resource_requirements }.should_not raise_error(Chef::Exceptions::Group) end end diff --git a/spec/unit/provider/group/gpasswd_spec.rb b/spec/unit/provider/group/gpasswd_spec.rb index f765667300..0436812501 100644 --- a/spec/unit/provider/group/gpasswd_spec.rb +++ b/spec/unit/provider/group/gpasswd_spec.rb @@ -27,7 +27,7 @@ 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 @@ -40,13 +40,13 @@ 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) + File.stub(:exists?).and_return(true) lambda { @provider.process_resource_requirements }.should_not raise_error(Chef::Exceptions::Group) end end @@ -85,7 +85,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..3d49f667d4 100644 --- a/spec/unit/provider/group/groupmod_spec.rb +++ b/spec/unit/provider/group/groupmod_spec.rb @@ -43,7 +43,7 @@ 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) + File.stub(:exists?).and_return(true) lambda { @provider.load_current_resource }.should_not raise_error(Chef::Exceptions::Group) 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..103bc33bd4 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 @@ -130,7 +130,7 @@ 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) + File.stub(:exists?).and_return(true) lambda { @provider.process_resource_requirements }.should_not raise_error(Chef::Exceptions::Group) end end diff --git a/spec/unit/provider/group/usermod_spec.rb b/spec/unit/provider/group/usermod_spec.rb index 1687cc0b65..cc3a28fb74 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,18 +95,18 @@ 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.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) + File.stub(:exists?).and_return(true) lambda { @provider.process_resource_requirements }.should_not raise_error(Chef::Exceptions::Group) end end diff --git a/spec/unit/provider/group/windows_spec.rb b/spec/unit/provider/group/windows_spec.rb index e8c1243ce5..b395ed96d8 100644 --- a/spec/unit/provider/group/windows_spec.rb +++ b/spec/unit/provider/group/windows_spec.rb @@ -34,7 +34,7 @@ describe Chef::Provider::Group::Windows do @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) + 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..ad6cfbff7c 100644 --- a/spec/unit/provider/group_spec.rb +++ b/spec/unit/provider/group_spec.rb @@ -41,7 +41,7 @@ describe Chef::Provider::User do :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..d1ee5163a1 100644 --- a/spec/unit/provider/http_request_spec.rb +++ b/spec/unit/provider/http_request_spec.rb @@ -44,7 +44,7 @@ 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) + @provider.stub(:load_current_resource).and_return(true) @http = mock("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..93504b4096 100644 --- a/spec/unit/provider/ifconfig/debian_spec.rb +++ b/spec/unit/provider/ifconfig/debian_spec.rb @@ -37,8 +37,8 @@ describe Chef::Provider::Ifconfig::Debian do status = mock("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..fc7ace5398 100644 --- a/spec/unit/provider/ifconfig/redhat_spec.rb +++ b/spec/unit/provider/ifconfig/redhat_spec.rb @@ -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..80f623302f 100644 --- a/spec/unit/provider/ifconfig_spec.rb +++ b/spec/unit/provider/ifconfig_spec.rb @@ -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..869796219d 100644 --- a/spec/unit/provider/link_spec.rb +++ b/spec/unit/provider/link_spec.rb @@ -45,12 +45,12 @@ 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.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 @@ -145,18 +145,18 @@ 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) + 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) + 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 @@ -177,13 +177,13 @@ 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.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 @@ -204,13 +204,13 @@ 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.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 38b907749e..2c304980d8 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 @@ -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?) @@ -103,7 +103,7 @@ describe Chef::Provider::Mount::Mount do 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 @@ -279,15 +279,15 @@ describe Chef::Provider::Mount::Mount 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) + @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_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 +339,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 +378,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 +395,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 +405,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..5a5cda6d7a 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) + 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) + 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 451ab30a0e..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,7 +123,7 @@ 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) @provider.run_action(:enable) @@ -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..83f4763664 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 @@ -40,20 +40,20 @@ describe Chef::Provider::Package::Aix do 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) + @provider.stub(:popen4).and_return(@status) lambda { @provider.load_current_resource }.should raise_error(Chef::Exceptions::Package) end @@ -117,7 +117,7 @@ describe Chef::Provider::Package::Aix do it "should throw and exception if the exitstatus is not 0" do @status = mock("Status", :exitstatus => 1) - @provider.stub!(:popen4).and_return(@status) + @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..5f0c823b7e 100644 --- a/spec/unit/provider/package/apt_spec.rb +++ b/spec/unit/provider/package/apt_spec.rb @@ -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..03786ff00b 100644 --- a/spec/unit/provider/package/dpkg_spec.rb +++ b/spec/unit/provider/package/dpkg_spec.rb @@ -33,9 +33,9 @@ describe Chef::Provider::Package::Dpkg do @status = mock("Status", :exitstatus => 0) @stderr = StringIO.new @pid = mock("PID") - @provider.stub!(:popen4).and_return(@status) + @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,7 +103,7 @@ 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" @@ -111,7 +111,7 @@ DPKG_S it "should raise an exception if dpkg fails to run" do @status = mock("Status", :exitstatus => -1) - @provider.stub!(:popen4).and_return(@status) + @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..8625619860 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) @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..037d559bc2 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 @@ -79,14 +79,14 @@ describe Chef::Provider::Package::Freebsd, "load_current_resource" 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") @@ -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..79025f912b 100644 --- a/spec/unit/provider/package/macports_spec.rb +++ b/spec/unit/provider/package/macports_spec.rb @@ -27,7 +27,7 @@ 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) @stdin = 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..7dae87b799 100644 --- a/spec/unit/provider/package/pacman_spec.rb +++ b/spec/unit/provider/package/pacman_spec.rb @@ -28,8 +28,8 @@ describe Chef::Provider::Package::Pacman do @status = mock("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") @@ -143,8 +143,8 @@ PACMAN_CONF 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..684d776b37 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 @@ -108,7 +108,7 @@ describe Chef::Provider::Package::Portage, "load_current_resource" do it "should throw an exception if the exitstatus is not 0" do @status = mock("Status", :exitstatus => 1) - @provider.stub!(:popen4).and_return(@status) + @provider.stub(:popen4).and_return(@status) lambda { @provider.candidate_version }.should raise_error(Chef::Exceptions::Package) end @@ -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..ab8447b3e1 100644 --- a/spec/unit/provider/package/rpm_spec.rb +++ b/spec/unit/provider/package/rpm_spec.rb @@ -30,25 +30,25 @@ 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) + ::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 @@ -77,7 +77,7 @@ describe Chef::Provider::Package::Rpm do it "should raise an exception if rpm fails to run" do status = mock("Status", :exitstatus => -1) - @provider.stub!(:popen4).and_return(status) + @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..b6807f1b70 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,7 +98,7 @@ 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) + @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") available_set.should_receive(:pick_best!) @@ -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 @@ -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 @@ -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 @@ -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..86ac159f69 100644 --- a/spec/unit/provider/package/smartos_spec.rb +++ b/spec/unit/provider/package/smartos_spec.rb @@ -31,7 +31,7 @@ describe Chef::Provider::Package::SmartOS, "load_current_resource" do @status = mock("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 diff --git a/spec/unit/provider/package/solaris_spec.rb b/spec/unit/provider/package/solaris_spec.rb index dd7cea2aaa..be07eeb45f 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 @@ -50,20 +50,20 @@ PKGINFO 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) + @provider.stub(:popen4).and_return(@status) lambda { @provider.load_current_resource }.should raise_error(Chef::Exceptions::Package) end @@ -121,14 +121,14 @@ PKGINFO 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) + @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) + @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..0e417aae0d 100644 --- a/spec/unit/provider/package/yum_spec.rb +++ b/spec/unit/provider/package/yum_spec.rb @@ -37,7 +37,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) @pid = mock("PID") end @@ -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 @@ -79,11 +79,11 @@ describe Chef::Provider::Package::Yum do @yum_cache = mock( '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" @@ -113,7 +113,7 @@ describe Chef::Provider::Package::Yum do @yum_cache = mock( '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 @@ -148,17 +148,17 @@ describe Chef::Provider::Package::Yum do @yum_cache = mock( '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" @@ -179,11 +179,11 @@ describe Chef::Provider::Package::Yum do @yum_cache = mock( '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,31 +202,31 @@ 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 @@ -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) @@ -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]) @@ -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) @@ -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) @@ -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" ) @@ -393,13 +393,13 @@ 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) + @new_resource.stub(:allow_downgrade).and_return(false) @yum_cache = mock( 'Chef::Provider::Yum::YumCache', :reload_installed => true, @@ -411,7 +411,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.install_package("cups", "1.2.4-11.15.el5") }.should raise_error(Chef::Exceptions::Package, %r{is newer than candidate package}) @@ -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,7 +440,7 @@ 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) + @new_resource.stub(:allow_downgrade).and_return(true) @yum_cache = mock( 'Chef::Provider::Yum::YumCache', :reload_installed => 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" ) @@ -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" ) @@ -596,7 +596,7 @@ 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, "", ""]) + @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]} @@ -606,7 +606,7 @@ describe Chef::Provider::Package::Yum do 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"]) + @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]} @@ -616,7 +616,7 @@ describe Chef::Provider::Package::Yum do 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", ""]) + @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]} @@ -627,7 +627,7 @@ describe Chef::Provider::Package::Yum do 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", ""]) + @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]} @@ -1592,7 +1592,7 @@ EOF 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 @@ -1643,28 +1643,28 @@ EOF 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) + @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) + @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) + @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) + @yc.stub(:shell_out!).and_return(@status) lambda { @yc.refresh}.should raise_error(Chef::Exceptions::Package, %r{CentOS-Base.repo, line: 12}) end diff --git a/spec/unit/provider/package/zypper_spec.rb b/spec/unit/provider/package/zypper_spec.rb index cf0193993d..63f235a05c 100644 --- a/spec/unit/provider/package/zypper_spec.rb +++ b/spec/unit/provider/package/zypper_spec.rb @@ -30,12 +30,12 @@ describe Chef::Provider::Package::Zypper do @status = mock("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") + @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 @@ -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..00999fc307 100644 --- a/spec/unit/provider/remote_file/content_spec.rb +++ b/spec/unit/provider/remote_file/content_spec.rb @@ -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 @@ -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,8 +144,8 @@ 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) + new_resource.stub(:checksum).and_return(nil) + current_resource.stub(:checksum).and_return(nil) @uri = mock("URI") URI.should_receive(:parse).with(new_resource.source[0]).and_return(@uri) http_fetcher = mock("Chef::Provider::RemoteFile::HTTP") @@ -162,8 +162,8 @@ 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) + new_resource.stub(:checksum).and_return(nil) + current_resource.stub(:checksum).and_return(nil) @uri0 = mock("URI0") @uri1 = mock("URI1") URI.should_receive(:parse).with(new_resource.source[0]).and_return(@uri0) @@ -205,8 +205,8 @@ 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) + new_resource.stub(:checksum).and_return(nil) + current_resource.stub(:checksum).and_return(nil) @uri0 = mock("URI0") URI.should_receive(:parse).with(new_resource.source[0]).and_return(@uri0) URI.should_not_receive(:parse).with(new_resource.source[1]) diff --git a/spec/unit/provider/remote_file/ftp_spec.rb b/spec/unit/provider/remote_file/ftp_spec.rb index 8dd1ef248e..524405bb06 100644 --- a/spec/unit/provider/remote_file/ftp_spec.rb +++ b/spec/unit/provider/remote_file/ftp_spec.rb @@ -39,13 +39,13 @@ describe Chef::Provider::RemoteFile::FTP do 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.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..4411bff9cf 100644 --- a/spec/unit/provider/remote_file/http_spec.rb +++ b/spec/unit/provider/remote_file/http_spec.rb @@ -165,8 +165,8 @@ describe Chef::Provider::RemoteFile::HTTP do let(:rest) do rest = mock(Chef::HTTP::Simple) - rest.stub!(:streaming_request).and_return(tempfile) - rest.stub!(:last_response).and_return(last_response) + rest.stub(:streaming_request).and_return(tempfile) + rest.stub(:last_response).and_return(last_response) rest end 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..cb0ea50e09 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 @@ -128,7 +128,7 @@ 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) + @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 @@ -177,14 +177,14 @@ RUNNING_PS # :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 @@ -198,14 +198,14 @@ RUNNING_PS # :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 @@ -220,14 +220,14 @@ RUNNING_PS # :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 @@ -246,14 +246,14 @@ RUNNING_PS # :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 @@ -272,21 +272,21 @@ RUNNING_PS # :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 @@ -307,21 +307,21 @@ RUNNING_PS # :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..ecc59e5e96 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 ... @@ -62,8 +62,8 @@ 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) + @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) + @provider.stub(:assert_update_rcd_available) @status = mock("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) + @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 @@ -103,7 +103,7 @@ 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) + @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) + @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) + @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..327aff1707 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 @@ -45,20 +45,20 @@ describe Chef::Provider::Service::Freebsd do 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) + @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) + ::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\""). + @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 @@ -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 @@ -283,12 +283,12 @@ RC_SAMPLE # (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) + @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 @@ -305,7 +305,7 @@ RCVAR_SAMPLE # 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) + @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,7 +319,7 @@ 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 @@ -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..274c0f72fc 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) + 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) + @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..2fcddb82e3 100644 --- a/spec/unit/provider/service/init_service_spec.rb +++ b/spec/unit/provider/service/init_service_spec.rb @@ -30,7 +30,7 @@ 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 @@ -38,7 +38,7 @@ 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) + @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 diff --git a/spec/unit/provider/service/insserv_service_spec.rb b/spec/unit/provider/service/insserv_service_spec.rb index 8b5f09e78c..e0c0d9682a 100644 --- a/spec/unit/provider/service/insserv_service_spec.rb +++ b/spec/unit/provider/service/insserv_service_spec.rb @@ -30,13 +30,13 @@ describe Chef::Provider::Service::Insserv do @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) + @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..3df6f002c7 100644 --- a/spec/unit/provider/service/invokercd_service_spec.rb +++ b/spec/unit/provider/service/invokercd_service_spec.rb @@ -30,7 +30,7 @@ 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 @@ -38,7 +38,7 @@ 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) + @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 @@ -137,7 +137,7 @@ RUNNING_PS 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..814320f64f 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)) - File.stub!(:stat).and_return(mock("stat", :gid => 1001, :uid => 101)) + File.stub(:stat).and_return(mock("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..0de93fe430 100644 --- a/spec/unit/provider/service/redhat_spec.rb +++ b/spec/unit/provider/service/redhat_spec.rb @@ -21,9 +21,9 @@ 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) @@ -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 diff --git a/spec/unit/provider/service/simple_service_spec.rb b/spec/unit/provider/service/simple_service_spec.rb index 73cb3766d2..7265399f58 100644 --- a/spec/unit/provider/service/simple_service_spec.rb +++ b/spec/unit/provider/service/simple_service_spec.rb @@ -29,7 +29,7 @@ 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 @@ -37,7 +37,7 @@ 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) + @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 @@ -80,19 +80,19 @@ 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) + @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..7dd6d7161c 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) + @stdout.stub(:gets).and_return(@stdout_string) @status = mock("Status", :exitstatus => 0, :stdout => @stdout) - @provider.stub!(:shell_out!).and_return(@status) + @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 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..1c9a94af2e 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) + @provider.stub(:popen4).and_return(@status) @stdin = StringIO.new @stdout = StringIO.new @stderr = StringIO.new @pid = mock("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) + ::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) + ::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..5f4d9ca7d6 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( + 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( + 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(:exists?).and_return(true) end it "should set the current resources service name to the new resources service name" do @@ -59,7 +59,7 @@ 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( + Win32::Service.stub(:status).with(@new_resource.service_name).and_return( mock("StatusStruct", :current_state => "stopped"), mock("StatusStruct", :current_state => "running")) end @@ -78,14 +78,14 @@ 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( + Win32::Service.stub(:status).with(@new_resource.service_name).and_return( mock("StatusStruct", :current_state => "running")) @provider.load_current_resource Win32::Service.should_not_receive(:start).with(@new_resource.service_name) @@ -97,7 +97,7 @@ 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( + Win32::Service.stub(:status).with(@new_resource.service_name).and_return( mock("StatusStruct", :current_state => "running"), mock("StatusStruct", :current_state => "stopped")) end @@ -116,14 +116,14 @@ 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( + Win32::Service.stub(:status).with(@new_resource.service_name).and_return( mock("StatusStruct", :current_state => "stopped")) @provider.load_current_resource Win32::Service.should_not_receive(:stop).with(@new_resource.service_name) @@ -142,7 +142,7 @@ 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( + 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"), @@ -154,7 +154,7 @@ 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( + 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")) @@ -164,7 +164,7 @@ 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) Win32::Service.should_not_receive(:start).with(@new_resource.service_name) @provider.restart_service @@ -176,7 +176,7 @@ 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( + Win32::Service.stub(:config_info).with(@new_resource.service_name).and_return( mock("ConfigStruct", :start_type => "disabled")) end @@ -187,14 +187,14 @@ 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( + Win32::Service.stub(:config_info).with(@new_resource.service_name).and_return( mock("ConfigStruct", :start_type => "auto start")) Win32::Service.should_not_receive(:configure) @provider.enable_service @@ -205,7 +205,7 @@ 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( + Win32::Service.stub(:config_info).with(@new_resource.service_name).and_return( mock("ConfigStruct", :start_type => "auto start")) end @@ -216,14 +216,14 @@ 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( + Win32::Service.stub(:config_info).with(@new_resource.service_name).and_return( mock("ConfigStruct", :start_type => "disabled")) @provider.load_current_resource Win32::Service.should_not_receive(:configure) 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..123ce1cf35 100644 --- a/spec/unit/provider/subversion_spec.rb +++ b/spec/unit/provider/subversion_spec.rb @@ -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) @@ -129,10 +129,10 @@ describe Chef::Provider::Subversion do "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.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). @@ -143,10 +143,10 @@ 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.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..1251f96bd3 100644 --- a/spec/unit/provider/template/content_spec.rb +++ b/spec/unit/provider/template/content_spec.rb @@ -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/user/dscl_spec.rb b/spec/unit/provider/user/dscl_spec.rb index dd98c55bd1..2e0de1364c 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,7 +324,7 @@ 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) + ::File.stub(:exists?).and_return(true) lambda { @provider.load_current_resource }.should_not raise_error(Chef::Exceptions::User) end end diff --git a/spec/unit/provider/user/pw_spec.rb b/spec/unit/provider/user/pw_spec.rb index ea5bcfe740..ed22984c62 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 @@ -160,7 +160,7 @@ 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) + @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 @@ -228,7 +228,7 @@ 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) + File.stub(:exists?).and_return(true) lambda { @provider.load_current_resource }.should_not raise_error(Chef::Exceptions::User) 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..9cdb2b5d79 100644 --- a/spec/unit/provider/user/windows_spec.rb +++ b/spec/unit/provider/user/windows_spec.rb @@ -36,7 +36,7 @@ describe Chef::Provider::User::Windows do @current_resource = Chef::Resource::User.new("monkey") @net_user = mock("Chef::Util::Windows::NetUser") - Chef::Util::Windows::NetUser.stub!(:new).and_return(@net_user) + 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..7b29e51c3f 100644 --- a/spec/unit/provider/user_spec.rb +++ b/spec/unit/provider/user_spec.rb @@ -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,7 +225,7 @@ describe Chef::Provider::User do describe "action_create" do before(:each) do - @provider.stub!(:load_current_resource) + @provider.stub(:load_current_resource) # @current_resource = mock("Chef::Resource::User", # :null_object => true, # :username => "adam", @@ -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,7 +297,7 @@ 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", # :null_object => true @@ -308,7 +308,7 @@ describe Chef::Provider::User do # @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,7 +340,7 @@ 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", # :null_object => true @@ -351,7 +351,7 @@ describe Chef::Provider::User do # @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,7 +409,7 @@ 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", # :null_object => true @@ -420,12 +420,12 @@ describe Chef::Provider::User do # @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..3d79f33264 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 diff --git a/spec/unit/resource_reporter_spec.rb b/spec/unit/resource_reporter_spec.rb index e2ecde212f..1910eb2ec9 100644 --- a/spec/unit/resource_reporter_spec.rb +++ b/spec/unit/resource_reporter_spec.rb @@ -36,20 +36,20 @@ describe Chef::ResourceReporter do @node = Chef::Node.new @node.name("spitfire") @rest_client = mock("Chef::REST (mock)") - @rest_client.stub!(:post_rest).and_return(true) + @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) + @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 @@ -382,9 +382,9 @@ describe Chef::ResourceReporter do @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.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..a75d1f0285 100644 --- a/spec/unit/resource_spec.rb +++ b/spec/unit/resource_spec.rb @@ -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/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..b45ad1df3f 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) + Chef::Role.stub(:load).and_return(@role) @rest = mock("Chef::REST", { :get_rest => @role, :url => "/" }) - Chef::REST.stub!(:new).and_return(@rest) + 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 @@ -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..1e449bd1c0 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) + 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) 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/search/query_spec.rb b/spec/unit/search/query_spec.rb index 3f41c142ee..bebb69f111 100644 --- a/spec/unit/search/query_spec.rb +++ b/spec/unit/search/query_spec.rb @@ -22,7 +22,7 @@ require 'chef/search/query' describe Chef::Search::Query do before(:each) do @rest = mock("Chef::REST") - Chef::REST.stub!(:new).and_return(@rest) + Chef::REST.stub(:new).and_return(@rest) @query = Chef::Search::Query.new end @@ -38,7 +38,7 @@ 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 diff --git a/spec/unit/shell/model_wrapper_spec.rb b/spec/unit/shell/model_wrapper_spec.rb index 35dc591edc..17e4227a75 100644 --- a/spec/unit/shell/model_wrapper_spec.rb +++ b/spec/unit/shell/model_wrapper_spec.rb @@ -72,7 +72,7 @@ describe Shell::ModelWrapper do # 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) + 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..4710fd9c4b 100644 --- a/spec/unit/shell/shell_ext_spec.rb +++ b/spec/unit/shell/shell_ext_spec.rb @@ -23,7 +23,7 @@ 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) @@ -37,7 +37,7 @@ describe Shell::Extensions do irb_context = mock("context", :main => target_context_obj) irb_session = mock("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,12 +81,12 @@ 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 @@ -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..2ad24d05ce 100644 --- a/spec/unit/shell/shell_session_spec.rb +++ b/spec/unit/shell/shell_session_spec.rb @@ -87,8 +87,8 @@ describe Shell::StandAloneSession do end it "runs chef with the standalone recipe" do - @session.stub!(:node_built?).and_return(true) - Chef::Log.stub!(:level) + @session.stub(:node_built?).and_return(true) + Chef::Log.stub(:level) chef_runner = mock("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,8 +143,8 @@ 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) + @session.stub(:node_built?).and_return(true) + Chef::Log.stub(:level) chef_runner = mock("Chef::Runner.new", :converge => :converged) Chef::Runner.should_receive(:new).with(an_instance_of(Chef::RunContext)).and_return(chef_runner) diff --git a/spec/unit/shell_spec.rb b/spec/unit/shell_spec.rb index 969c526ef4..6f155c46ad 100644 --- a/spec/unit/shell_spec.rb +++ b/spec/unit/shell_spec.rb @@ -43,7 +43,7 @@ describe Shell do before do Shell.irb_conf = {} reset Shell::ShellSession.instance - 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..2363ce67ae 100644 --- a/spec/unit/user_spec.rb +++ b/spec/unit/user_spec.rb @@ -197,7 +197,7 @@ describe Chef::User do @user = Chef::User.new @user.name "foobar" @http_client = mock("Chef::REST mock") - Chef::REST.stub!(:new).and_return(@http_client) + 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/selinux_spec.rb b/spec/unit/util/selinux_spec.rb index 710380e6fc..a69e236240 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 @@ -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 |