diff options
author | Lamont Granquist <lamont@scriptkiddie.org> | 2014-10-26 11:10:56 -0700 |
---|---|---|
committer | Lamont Granquist <lamont@scriptkiddie.org> | 2014-10-26 11:10:56 -0700 |
commit | e2b4608af453e2bfb8c3ae4a2ed63c9d281980e8 (patch) | |
tree | bf7b5b51fc9b84429fa390565e9a6d481897c04d | |
parent | bdce1c5619fde7d277262df9336e06f73e4fc3f8 (diff) | |
parent | eab0fe62c048834f556492bf180cb78afcf06194 (diff) | |
download | chef-e2b4608af453e2bfb8c3ae4a2ed63c9d281980e8.tar.gz |
Merge pull request #2300 from opscode/lcg/rspec3-updates
updating resources/providers unit tests to rpsec3
146 files changed, 4779 insertions, 4782 deletions
diff --git a/spec/unit/provider/breakpoint_spec.rb b/spec/unit/provider/breakpoint_spec.rb index 05f3e8e0ed..386e5a1d17 100644 --- a/spec/unit/provider/breakpoint_spec.rb +++ b/spec/unit/provider/breakpoint_spec.rb @@ -26,28 +26,28 @@ describe Chef::Provider::Breakpoint do @events = Chef::EventDispatch::Dispatcher.new @run_context = Chef::RunContext.new(@node, {}, @events) @collection = double("resource collection") - @run_context.stub(:resource_collection).and_return(@collection) + allow(@run_context).to receive(:resource_collection).and_return(@collection) @provider = Chef::Provider::Breakpoint.new(@resource, @run_context) end it "responds to load_current_resource" do - @provider.should respond_to(:load_current_resource) + expect(@provider).to respond_to(:load_current_resource) end it "gets the iterator from @collection and pauses it" do - Shell.stub(:running?).and_return(true) + allow(Shell).to receive(:running?).and_return(true) @iterator = double("stepable_iterator") - @collection.stub(:iterator).and_return(@iterator) - @iterator.should_receive(:pause) + allow(@collection).to receive(:iterator).and_return(@iterator) + expect(@iterator).to receive(:pause) @provider.action_break - @resource.should be_updated + expect(@resource).to be_updated end it "doesn't pause the iterator if chef-shell isn't running" do - Shell.stub(:running?).and_return(false) + allow(Shell).to receive(:running?).and_return(false) @iterator = double("stepable_iterator") - @collection.stub(:iterator).and_return(@iterator) - @iterator.should_not_receive(:pause) + allow(@collection).to receive(:iterator).and_return(@iterator) + expect(@iterator).not_to 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 ed8942aaf2..6946966153 100644 --- a/spec/unit/provider/cookbook_file/content_spec.rb +++ b/spec/unit/provider/cookbook_file/content_spec.rb @@ -28,12 +28,12 @@ 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') - content.send(:resource_cookbook).should == 'nginx' + allow(new_resource).to receive(:cookbook).and_return('nginx') + expect(content.send(:resource_cookbook)).to eq('nginx') end it "falls back to the implicit cookbook name on the resource" do - content.send(:resource_cookbook).should == 'apache2' + expect(content.send(:resource_cookbook)).to eq('apache2') end end diff --git a/spec/unit/provider/cookbook_file_spec.rb b/spec/unit/provider/cookbook_file_spec.rb index 131fca2ba6..a7cbba97cb 100644 --- a/spec/unit/provider/cookbook_file_spec.rb +++ b/spec/unit/provider/cookbook_file_spec.rb @@ -37,7 +37,7 @@ describe Chef::Provider::CookbookFile do let(:provider) do provider = described_class.new(resource, run_context) - provider.stub(:content).and_return(content) + allow(provider).to receive(:content).and_return(content) provider end diff --git a/spec/unit/provider/cron_spec.rb b/spec/unit/provider/cron_spec.rb index 460fb0ca6a..7a917a4f27 100644 --- a/spec/unit/provider/cron_spec.rb +++ b/spec/unit/provider/cron_spec.rb @@ -35,7 +35,7 @@ describe Chef::Provider::Cron do context "with a matching entry in the user's crontab" do before :each do - @provider.stub(:read_crontab).and_return(<<-CRONTAB) + allow(@provider).to receive(:read_crontab).and_return(<<-CRONTAB) 0 2 * * * /some/other/command # Chef Name: cronhole some stuff @@ -49,18 +49,18 @@ CRONTAB it "should set cron_exists" do @provider.load_current_resource - @provider.cron_exists.should == true - @provider.cron_empty.should == false + expect(@provider.cron_exists).to eq(true) + expect(@provider.cron_empty).to eq(false) end it "should pull the details out of the cron line" do cron = @provider.load_current_resource - cron.time.should == :reboot - cron.command.should == '/bin/true param1 param2' + expect(cron.time).to eq(:reboot) + expect(cron.command).to eq('/bin/true param1 param2') end it "should pull env vars out" do - @provider.stub(:read_crontab).and_return(<<-CRONTAB) + allow(@provider).to receive(:read_crontab).and_return(<<-CRONTAB) 0 2 * * * /some/other/command # Chef Name: cronhole some stuff @@ -75,16 +75,16 @@ HOME=/home/foo # Another comment CRONTAB cron = @provider.load_current_resource - cron.mailto.should == 'foo@example.com' - cron.shell.should == '/bin/foosh' - cron.path.should == '/bin:/foo' - cron.home.should == '/home/foo' - cron.time.should == :reboot - cron.command.should == '/bin/true param1 param2' + expect(cron.mailto).to eq('foo@example.com') + expect(cron.shell).to eq('/bin/foosh') + expect(cron.path).to eq('/bin:/foo') + expect(cron.home).to eq('/home/foo') + expect(cron.time).to eq(:reboot) + expect(cron.command).to eq('/bin/true param1 param2') end it "should parse and load generic and standard environment variables from cron entry" do - @provider.stub(:read_crontab).and_return(<<-CRONTAB) + allow(@provider).to receive(:read_crontab).and_return(<<-CRONTAB) # Chef Name: cronhole some stuff MAILTO=warn@example.com TEST=lol @@ -93,12 +93,12 @@ FLAG=1 CRONTAB cron = @provider.load_current_resource - cron.mailto.should == "warn@example.com" - cron.environment.should == {"TEST" => "lol", "FLAG" => "1"} + expect(cron.mailto).to eq("warn@example.com") + expect(cron.environment).to eq({"TEST" => "lol", "FLAG" => "1"}) end it "should not break with variables that match the cron resource internals" do - @provider.stub(:read_crontab).and_return(<<-CRONTAB) + allow(@provider).to receive(:read_crontab).and_return(<<-CRONTAB) # Chef Name: cronhole some stuff MINUTE=40 REBOOT=midnight @@ -108,19 +108,19 @@ ENVIRONMENT=production CRONTAB cron = @provider.load_current_resource - cron.time.should == :reboot - cron.environment.should == {"MINUTE" => "40", "REBOOT" => "midnight", "TEST" => "lol", "ENVIRONMENT" => "production"} + expect(cron.time).to eq(:reboot) + expect(cron.environment).to eq({"MINUTE" => "40", "REBOOT" => "midnight", "TEST" => "lol", "ENVIRONMENT" => "production"}) end it "should report the match" do - Chef::Log.should_receive(:debug).with("Found cron '#{@new_resource.name}'") + expect(Chef::Log).to receive(:debug).with("Found cron '#{@new_resource.name}'") @provider.load_current_resource end describe "action_create" do before :each do - @provider.stub(:write_crontab) - @provider.stub(:read_crontab).and_return(nil) + allow(@provider).to receive(:write_crontab) + allow(@provider).to receive(:read_crontab).and_return(nil) end context "when there is no existing crontab" do @@ -130,7 +130,7 @@ CRONTAB end it "should create a crontab with the entry" do - @provider.should_receive(:write_crontab).with(<<-ENDCRON) + expect(@provider).to receive(:write_crontab).with(<<-ENDCRON) # Chef Name: cronhole some stuff @reboot /bin/true ENDCRON @@ -156,24 +156,24 @@ CRONTAB 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) + allow(@provider).to receive(:read_crontab).and_return(nil) end it "should set cron_empty" do @provider.load_current_resource - @provider.cron_empty.should == true - @provider.cron_exists.should == false + expect(@provider.cron_empty).to eq(true) + expect(@provider.cron_exists).to eq(false) end it "should report an empty crontab" do - Chef::Log.should_receive(:debug).with("Cron empty for '#{@new_resource.user}'") + expect(Chef::Log).to receive(:debug).with("Cron empty for '#{@new_resource.user}'") @provider.load_current_resource end end context "with no matching entry in the user's crontab" do before :each do - @provider.stub(:read_crontab).and_return(<<-CRONTAB) + allow(@provider).to receive(:read_crontab).and_return(<<-CRONTAB) 0 2 * * * /some/other/command # Chef Name: something else @@ -185,29 +185,29 @@ CRONTAB it "should not set cron_exists or cron_empty" do @provider.load_current_resource - @provider.cron_exists.should == false - @provider.cron_empty.should == false + expect(@provider.cron_exists).to eq(false) + expect(@provider.cron_empty).to eq(false) end it "should report no entry found" do - Chef::Log.should_receive(:debug).with("Cron '#{@new_resource.name}' not found") + expect(Chef::Log).to receive(:debug).with("Cron '#{@new_resource.name}' not found") @provider.load_current_resource end it "should not fail if there's an existing cron with a numerical argument" do - @provider.stub(:read_crontab).and_return(<<-CRONTAB) + allow(@provider).to receive(:read_crontab).and_return(<<-CRONTAB) # Chef Name: foo[bar] (baz) 21 */4 * * * some_prog 1234567 CRONTAB - lambda { + expect { @provider.load_current_resource - }.should_not raise_error + }.not_to raise_error end end context "with a matching entry in the user's crontab" do before :each do - @provider.stub(:read_crontab).and_return(<<-CRONTAB) + allow(@provider).to receive(:read_crontab).and_return(<<-CRONTAB) 0 2 * * * /some/other/command # Chef Name: cronhole some stuff @@ -221,23 +221,23 @@ CRONTAB it "should set cron_exists" do @provider.load_current_resource - @provider.cron_exists.should == true - @provider.cron_empty.should == false + expect(@provider.cron_exists).to eq(true) + expect(@provider.cron_empty).to eq(false) end it "should pull the details out of the cron line" do cron = @provider.load_current_resource - cron.minute.should == '*' - cron.hour.should == '5' - cron.day.should == '*' - cron.month.should == '1' - cron.weekday.should == '*' - cron.time.should == nil - cron.command.should == '/bin/true param1 param2' + expect(cron.minute).to eq('*') + expect(cron.hour).to eq('5') + expect(cron.day).to eq('*') + expect(cron.month).to eq('1') + expect(cron.weekday).to eq('*') + expect(cron.time).to eq(nil) + expect(cron.command).to eq('/bin/true param1 param2') end it "should pull env vars out" do - @provider.stub(:read_crontab).and_return(<<-CRONTAB) + allow(@provider).to receive(:read_crontab).and_return(<<-CRONTAB) 0 2 * * * /some/other/command # Chef Name: cronhole some stuff @@ -252,21 +252,21 @@ HOME=/home/foo # Another comment CRONTAB cron = @provider.load_current_resource - cron.mailto.should == 'foo@example.com' - cron.shell.should == '/bin/foosh' - cron.path.should == '/bin:/foo' - cron.home.should == '/home/foo' - cron.minute.should == '*' - cron.hour.should == '5' - cron.day.should == '*' - cron.month.should == '1' - cron.weekday.should == '*' - cron.time.should == nil - cron.command.should == '/bin/true param1 param2' + expect(cron.mailto).to eq('foo@example.com') + expect(cron.shell).to eq('/bin/foosh') + expect(cron.path).to eq('/bin:/foo') + expect(cron.home).to eq('/home/foo') + expect(cron.minute).to eq('*') + expect(cron.hour).to eq('5') + expect(cron.day).to eq('*') + expect(cron.month).to eq('1') + expect(cron.weekday).to eq('*') + expect(cron.time).to eq(nil) + expect(cron.command).to eq('/bin/true param1 param2') end it "should parse and load generic and standard environment variables from cron entry" do - @provider.stub(:read_crontab).and_return(<<-CRONTAB) + allow(@provider).to receive(:read_crontab).and_return(<<-CRONTAB) # Chef Name: cronhole some stuff MAILTO=warn@example.com TEST=lol @@ -275,12 +275,12 @@ FLAG=1 CRONTAB cron = @provider.load_current_resource - cron.mailto.should == "warn@example.com" - cron.environment.should == {"TEST" => "lol", "FLAG" => "1"} + expect(cron.mailto).to eq("warn@example.com") + expect(cron.environment).to eq({"TEST" => "lol", "FLAG" => "1"}) end it "should not break with variabels that match the cron resource internals" do - @provider.stub(:read_crontab).and_return(<<-CRONTAB) + allow(@provider).to receive(:read_crontab).and_return(<<-CRONTAB) # Chef Name: cronhole some stuff MINUTE=40 HOUR=midnight @@ -290,20 +290,20 @@ ENVIRONMENT=production CRONTAB cron = @provider.load_current_resource - cron.minute.should == '*' - cron.hour.should == '5' - cron.environment.should == {"MINUTE" => "40", "HOUR" => "midnight", "TEST" => "lol", "ENVIRONMENT" => "production"} + expect(cron.minute).to eq('*') + expect(cron.hour).to eq('5') + expect(cron.environment).to eq({"MINUTE" => "40", "HOUR" => "midnight", "TEST" => "lol", "ENVIRONMENT" => "production"}) end it "should report the match" do - Chef::Log.should_receive(:debug).with("Found cron '#{@new_resource.name}'") + expect(Chef::Log).to receive(:debug).with("Found cron '#{@new_resource.name}'") @provider.load_current_resource end end 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) + allow(@provider).to receive(:read_crontab).and_return(<<-CRONTAB) 0 2 * * * /some/other/command # Chef Name: cronhole some stuff @@ -317,64 +317,64 @@ CRONTAB it "should set cron_exists" do @provider.load_current_resource - @provider.cron_exists.should == true - @provider.cron_empty.should == false + expect(@provider.cron_exists).to eq(true) + expect(@provider.cron_empty).to eq(false) end it "should pull the details out of the cron line" do cron = @provider.load_current_resource - cron.minute.should == '*' - cron.hour.should == '5' - cron.day.should == '*' - cron.month.should == 'Jan' - cron.weekday.should == 'Mon' - cron.command.should == '/bin/true param1 param2' + expect(cron.minute).to eq('*') + expect(cron.hour).to eq('5') + expect(cron.day).to eq('*') + expect(cron.month).to eq('Jan') + expect(cron.weekday).to eq('Mon') + expect(cron.command).to eq('/bin/true param1 param2') end it "should report the match" do - Chef::Log.should_receive(:debug).with("Found cron '#{@new_resource.name}'") + expect(Chef::Log).to receive(:debug).with("Found cron '#{@new_resource.name}'") @provider.load_current_resource end end 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) + allow(@provider).to receive(:read_crontab).and_return(<<-CRONTAB) 0 2 * * * /some/other/command # Chef Name: cronhole some stuff CRONTAB cron = @provider.load_current_resource - @provider.cron_exists.should == true - cron.minute.should == '*' - cron.hour.should == '*' - cron.day.should == '*' - cron.month.should == '*' - cron.weekday.should == '*' - cron.time.should == nil - cron.command.should == nil + expect(@provider.cron_exists).to eq(true) + expect(cron.minute).to eq('*') + expect(cron.hour).to eq('*') + expect(cron.day).to eq('*') + expect(cron.month).to eq('*') + expect(cron.weekday).to eq('*') + expect(cron.time).to eq(nil) + expect(cron.command).to eq(nil) end it "should not pick up a commented out crontab line" do - @provider.stub(:read_crontab).and_return(<<-CRONTAB) + allow(@provider).to receive(:read_crontab).and_return(<<-CRONTAB) 0 2 * * * /some/other/command # Chef Name: cronhole some stuff #* 5 * 1 * /bin/true param1 param2 CRONTAB cron = @provider.load_current_resource - @provider.cron_exists.should == true - cron.minute.should == '*' - cron.hour.should == '*' - cron.day.should == '*' - cron.month.should == '*' - cron.weekday.should == '*' - cron.time.should == nil - cron.command.should == nil + expect(@provider.cron_exists).to eq(true) + expect(cron.minute).to eq('*') + expect(cron.hour).to eq('*') + expect(cron.day).to eq('*') + expect(cron.month).to eq('*') + expect(cron.weekday).to eq('*') + expect(cron.time).to eq(nil) + expect(cron.command).to eq(nil) end it "should not pick up a later crontab entry" do - @provider.stub(:read_crontab).and_return(<<-CRONTAB) + allow(@provider).to receive(:read_crontab).and_return(<<-CRONTAB) 0 2 * * * /some/other/command # Chef Name: cronhole some stuff @@ -385,14 +385,14 @@ CRONTAB # Another comment CRONTAB cron = @provider.load_current_resource - @provider.cron_exists.should == true - cron.minute.should == '*' - cron.hour.should == '*' - cron.day.should == '*' - cron.month.should == '*' - cron.weekday.should == '*' - cron.time.should == nil - cron.command.should == nil + expect(@provider.cron_exists).to eq(true) + expect(cron.minute).to eq('*') + expect(cron.hour).to eq('*') + expect(cron.day).to eq('*') + expect(cron.month).to eq('*') + expect(cron.weekday).to eq('*') + expect(cron.time).to eq(nil) + expect(cron.command).to eq(nil) end end end @@ -409,35 +409,35 @@ CRONTAB [:minute, :hour, :day, :month, :weekday, :command, :mailto, :path, :shell, :home].each do |attribute| it "should return true if #{attribute} doesn't match" do @new_resource.send(attribute, "something_else") - @provider.cron_different?.should eql(true) + expect(@provider.cron_different?).to eql(true) end end it "should return true if special time string doesn't match" do @new_resource.send(:time, :reboot) - @provider.cron_different?.should eql(true) + expect(@provider.cron_different?).to eql(true) end it "should return true if environment doesn't match" do @new_resource.environment "FOO" => "something_else" - @provider.cron_different?.should eql(true) + expect(@provider.cron_different?).to eql(true) end it "should return true if mailto doesn't match" do @current_resource.mailto "foo@bar.com" @new_resource.mailto(nil) - @provider.cron_different?.should eql(true) + expect(@provider.cron_different?).to eql(true) end it "should return false if the objects are identical" do - @provider.cron_different?.should == false + expect(@provider.cron_different?).to eq(false) end end describe "action_create" do before :each do - @provider.stub(:write_crontab) - @provider.stub(:read_crontab).and_return(nil) + allow(@provider).to receive(:write_crontab) + allow(@provider).to receive(:read_crontab).and_return(nil) end context "when there is no existing crontab" do @@ -447,7 +447,7 @@ CRONTAB end it "should create a crontab with the entry" do - @provider.should_receive(:write_crontab).with(<<-ENDCRON) + expect(@provider).to receive(:write_crontab).with(<<-ENDCRON) # Chef Name: cronhole some stuff 30 * * * * /bin/true ENDCRON @@ -460,7 +460,7 @@ CRONTAB @new_resource.shell '/bin/foosh' @new_resource.home '/home/foo' @new_resource.environment "TEST" => "LOL" - @provider.should_receive(:write_crontab).with(<<-ENDCRON) + expect(@provider).to receive(:write_crontab).with(<<-ENDCRON) # Chef Name: cronhole some stuff MAILTO=foo@example.com PATH=/usr/bin:/my/custom/path @@ -474,11 +474,11 @@ TEST=LOL it "should mark the resource as updated" do @provider.run_action(:create) - @new_resource.should be_updated_by_last_action + expect(@new_resource).to be_updated_by_last_action end it "should log the action" do - Chef::Log.should_receive(:info).with("cron[cronhole some stuff] added crontab entry") + expect(Chef::Log).to receive(:info).with("cron[cronhole some stuff] added crontab entry") @provider.run_action(:create) end end @@ -486,7 +486,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) + allow(@provider).to receive(:read_crontab).and_return(<<-CRONTAB) 0 2 * * * /some/other/command # Chef Name: something else @@ -497,7 +497,7 @@ TEST=LOL end it "should add the entry to the crontab" do - @provider.should_receive(:write_crontab).with(<<-ENDCRON) + expect(@provider).to receive(:write_crontab).with(<<-ENDCRON) 0 2 * * * /some/other/command # Chef Name: something else @@ -516,7 +516,7 @@ TEST=LOL @new_resource.shell '/bin/foosh' @new_resource.home '/home/foo' @new_resource.environment "TEST" => "LOL" - @provider.should_receive(:write_crontab).with(<<-ENDCRON) + expect(@provider).to receive(:write_crontab).with(<<-ENDCRON) 0 2 * * * /some/other/command # Chef Name: something else @@ -536,11 +536,11 @@ TEST=LOL it "should mark the resource as updated" do @provider.run_action(:create) - @new_resource.should be_updated_by_last_action + expect(@new_resource).to be_updated_by_last_action end it "should log the action" do - Chef::Log.should_receive(:info).with("cron[cronhole some stuff] added crontab entry") + expect(Chef::Log).to receive(:info).with("cron[cronhole some stuff] added crontab entry") @provider.run_action(:create) end end @@ -548,8 +548,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) + allow(@provider).to receive(:cron_different?).and_return(true) + allow(@provider).to receive(:read_crontab).and_return(<<-CRONTAB) 0 2 * * * /some/other/command # Chef Name: cronhole some stuff @@ -562,7 +562,7 @@ TEST=LOL end it "should update the crontab entry" do - @provider.should_receive(:write_crontab).with(<<-ENDCRON) + expect(@provider).to receive(:write_crontab).with(<<-ENDCRON) 0 2 * * * /some/other/command # Chef Name: cronhole some stuff @@ -581,7 +581,7 @@ TEST=LOL @new_resource.shell '/bin/foosh' @new_resource.home '/home/foo' @new_resource.environment "TEST" => "LOL" - @provider.should_receive(:write_crontab).with(<<-ENDCRON) + expect(@provider).to receive(:write_crontab).with(<<-ENDCRON) 0 2 * * * /some/other/command # Chef Name: cronhole some stuff @@ -601,11 +601,11 @@ TEST=LOL it "should mark the resource as updated" do @provider.run_action(:create) - @new_resource.should be_updated_by_last_action + expect(@new_resource).to be_updated_by_last_action end it "should log the action" do - Chef::Log.should_receive(:info).with("cron[cronhole some stuff] updated crontab entry") + expect(Chef::Log).to receive(:info).with("cron[cronhole some stuff] updated crontab entry") @provider.run_action(:create) end end @@ -613,16 +613,16 @@ 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) + allow(@provider).to receive(:cron_different?).and_return(true) end it "should add the crontab to the entry" do - @provider.stub(:read_crontab).and_return(<<-CRONTAB) + allow(@provider).to receive(:read_crontab).and_return(<<-CRONTAB) 0 2 * * * /some/other/command # Chef Name: cronhole some stuff CRONTAB - @provider.should_receive(:write_crontab).with(<<-ENDCRON) + expect(@provider).to receive(:write_crontab).with(<<-ENDCRON) 0 2 * * * /some/other/command # Chef Name: cronhole some stuff @@ -632,7 +632,7 @@ TEST=LOL end it "should not blat any following entries" do - @provider.stub(:read_crontab).and_return(<<-CRONTAB) + allow(@provider).to receive(:read_crontab).and_return(<<-CRONTAB) 0 2 * * * /some/other/command # Chef Name: cronhole some stuff @@ -642,7 +642,7 @@ TEST=LOL # Another comment CRONTAB - @provider.should_receive(:write_crontab).with(<<-ENDCRON) + expect(@provider).to receive(:write_crontab).with(<<-ENDCRON) 0 2 * * * /some/other/command # Chef Name: cronhole some stuff @@ -657,7 +657,7 @@ TEST=LOL end it "should handle env vars with no crontab" do - @provider.stub(:read_crontab).and_return(<<-CRONTAB) + allow(@provider).to receive(:read_crontab).and_return(<<-CRONTAB) 0 2 * * * /some/other/command # Chef Name: cronhole some stuff @@ -675,7 +675,7 @@ HOME=/home/foo @new_resource.path '/usr/bin:/my/custom/path' @new_resource.shell '/bin/foosh' @new_resource.home '/home/foo' - @provider.should_receive(:write_crontab).with(<<-ENDCRON) + expect(@provider).to receive(:write_crontab).with(<<-ENDCRON) 0 2 * * * /some/other/command # Chef Name: cronhole some stuff @@ -697,8 +697,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) + allow(@provider).to receive(:cron_different?).and_return(false) + allow(@provider).to receive(:read_crontab).and_return(<<-CRONTAB) 0 2 * * * /some/other/command # Chef Name: cronhole some stuff @@ -709,18 +709,18 @@ CRONTAB end it "should not update the crontab" do - @provider.should_not_receive(:write_crontab) + expect(@provider).not_to receive(:write_crontab) @provider.run_action(:create) end it "should not mark the resource as updated" do @provider.run_action(:create) - @new_resource.should_not be_updated_by_last_action + expect(@new_resource).not_to be_updated_by_last_action end it "should log nothing changed" do - Chef::Log.should_receive(:debug).with("Found cron '#{@new_resource.name}'") - Chef::Log.should_receive(:debug).with("Skipping existing cron entry '#{@new_resource.name}'") + expect(Chef::Log).to receive(:debug).with("Found cron '#{@new_resource.name}'") + expect(Chef::Log).to receive(:debug).with("Skipping existing cron entry '#{@new_resource.name}'") @provider.run_action(:create) end end @@ -728,8 +728,8 @@ CRONTAB describe "action_delete" do before :each do - @provider.stub(:write_crontab) - @provider.stub(:read_crontab).and_return(nil) + allow(@provider).to receive(:write_crontab) + allow(@provider).to receive(:read_crontab).and_return(nil) end context "when the user's crontab has no matching section" do @@ -738,21 +738,21 @@ CRONTAB end it "should do nothing" do - @provider.should_not_receive(:write_crontab) - Chef::Log.should_not_receive(:info) + expect(@provider).not_to receive(:write_crontab) + expect(Chef::Log).not_to receive(:info) @provider.run_action(:delete) end it "should not mark the resource as updated" do @provider.run_action(:delete) - @new_resource.should_not be_updated_by_last_action + expect(@new_resource).not_to be_updated_by_last_action end end 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) + allow(@provider).to receive(:read_crontab).and_return(<<-CRONTAB) 0 2 * * * /some/other/command # Chef Name: cronhole some stuff @@ -765,7 +765,7 @@ CRONTAB end it "should remove the entry" do - @provider.should_receive(:write_crontab).with(<<-ENDCRON) + expect(@provider).to receive(:write_crontab).with(<<-ENDCRON) 0 2 * * * /some/other/command # Chef Name: something else @@ -777,7 +777,7 @@ CRONTAB end it "should remove any env vars with the entry" do - @provider.stub(:read_crontab).and_return(<<-CRONTAB) + allow(@provider).to receive(:read_crontab).and_return(<<-CRONTAB) 0 2 * * * /some/other/command # Chef Name: cronhole some stuff @@ -789,7 +789,7 @@ FOO=test # Another comment CRONTAB - @provider.should_receive(:write_crontab).with(<<-ENDCRON) + expect(@provider).to receive(:write_crontab).with(<<-ENDCRON) 0 2 * * * /some/other/command # Chef Name: something else @@ -802,11 +802,11 @@ FOO=test it "should mark the resource as updated" do @provider.run_action(:delete) - @new_resource.should be_updated_by_last_action + expect(@new_resource).to be_updated_by_last_action end it "should log the action" do - Chef::Log.should_receive(:info).with("#{@new_resource} deleted crontab entry") + expect(Chef::Log).to receive(:info).with("#{@new_resource} deleted crontab entry") @provider.run_action(:delete) end end @@ -817,12 +817,12 @@ FOO=test end it "should remove the section" do - @provider.stub(:read_crontab).and_return(<<-CRONTAB) + allow(@provider).to receive(:read_crontab).and_return(<<-CRONTAB) 0 2 * * * /some/other/command # Chef Name: cronhole some stuff CRONTAB - @provider.should_receive(:write_crontab).with(<<-ENDCRON) + expect(@provider).to receive(:write_crontab).with(<<-ENDCRON) 0 2 * * * /some/other/command ENDCRON @@ -830,7 +830,7 @@ FOO=test end it "should not blat following sections" do - @provider.stub(:read_crontab).and_return(<<-CRONTAB) + allow(@provider).to receive(:read_crontab).and_return(<<-CRONTAB) 0 2 * * * /some/other/command # Chef Name: cronhole some stuff @@ -840,7 +840,7 @@ FOO=test # Another comment CRONTAB - @provider.should_receive(:write_crontab).with(<<-ENDCRON) + expect(@provider).to receive(:write_crontab).with(<<-ENDCRON) 0 2 * * * /some/other/command #30 * * 3 * /bin/true @@ -853,7 +853,7 @@ FOO=test end it "should remove any envvars with the section" do - @provider.stub(:read_crontab).and_return(<<-CRONTAB) + allow(@provider).to receive(:read_crontab).and_return(<<-CRONTAB) 0 2 * * * /some/other/command # Chef Name: cronhole some stuff @@ -864,7 +864,7 @@ MAILTO=foo@example.com # Another comment CRONTAB - @provider.should_receive(:write_crontab).with(<<-ENDCRON) + expect(@provider).to receive(:write_crontab).with(<<-ENDCRON) 0 2 * * * /some/other/command #30 * * 3 * /bin/true @@ -889,17 +889,17 @@ MAILTO=foo@example.com # Another comment CRONTAB - @provider.stub(:popen4).and_yield(1234, StringIO.new, @stdout, StringIO.new).and_return(@status) + allow(@provider).to receive(:popen4).and_yield(1234, StringIO.new, @stdout, StringIO.new).and_return(@status) end it "should call crontab -l with the user" do - @provider.should_receive(:popen4).with("crontab -l -u #{@new_resource.user}").and_return(@status) + expect(@provider).to receive(:popen4).with("crontab -l -u #{@new_resource.user}").and_return(@status) @provider.send(:read_crontab) end it "should return the contents of the crontab" do crontab = @provider.send(:read_crontab) - crontab.should == <<-CRONTAB + expect(crontab).to eq <<-CRONTAB 0 2 * * * /some/other/command # Chef Name: something else @@ -911,16 +911,16 @@ MAILTO=foo@example.com it "should return nil if the user has no crontab" do status = double("Status", :exitstatus => 1) - @provider.stub(:popen4).and_return(status) - @provider.send(:read_crontab).should == nil + allow(@provider).to receive(:popen4).and_return(status) + expect(@provider.send(:read_crontab)).to eq(nil) end it "should raise an exception if another error occurs" do status = double("Status", :exitstatus => 2) - @provider.stub(:popen4).and_return(status) - lambda do + allow(@provider).to receive(:popen4).and_return(status) + expect do @provider.send(:read_crontab) - end.should raise_error(Chef::Exceptions::Cron, "Error determining state of #{@new_resource.name}, exit: 2") + end.to raise_error(Chef::Exceptions::Cron, "Error determining state of #{@new_resource.name}, exit: 2") end end @@ -928,24 +928,24 @@ MAILTO=foo@example.com before :each do @status = double("Status", :exitstatus => 0) @stdin = StringIO.new - @provider.stub(:popen4).and_yield(1234, @stdin, StringIO.new, StringIO.new).and_return(@status) + allow(@provider).to receive(:popen4).and_yield(1234, @stdin, StringIO.new, StringIO.new).and_return(@status) end it "should call crontab for the user" do - @provider.should_receive(:popen4).with("crontab -u #{@new_resource.user} -", :waitlast => true).and_return(@status) + expect(@provider).to receive(:popen4).with("crontab -u #{@new_resource.user} -", :waitlast => true).and_return(@status) @provider.send(:write_crontab, "Foo") end it "should write the given string to the crontab command" do @provider.send(:write_crontab, "Foo\n# wibble\n wah!!") - @stdin.string.should == "Foo\n# wibble\n wah!!" + expect(@stdin.string).to eq("Foo\n# wibble\n wah!!") end it "should raise an exception if the command returns non-zero" do - @status.stub(:exitstatus).and_return(1) - lambda do + allow(@status).to receive(:exitstatus).and_return(1) + expect do @provider.send(:write_crontab, "Foo") - end.should raise_error(Chef::Exceptions::Cron, "Error updating state of #{@new_resource.name}, exit: 1") + end.to raise_error(Chef::Exceptions::Cron, "Error updating state of #{@new_resource.name}, exit: 1") end it "should raise an exception if the command die's and parent tries to write" do @@ -954,14 +954,14 @@ 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) + allow(@status).to receive(:exitstatus).and_return(1) + allow(@provider).to receive(:popen4).and_yield(1234, WriteErrPipe.new, StringIO.new, StringIO.new).and_return(@status) - Chef::Log.should_receive(:debug).with("Broken pipe - Test") + expect(Chef::Log).to receive(:debug).with("Broken pipe - Test") - lambda do + expect do @provider.send(:write_crontab, "Foo") - end.should raise_error(Chef::Exceptions::Cron, "Error updating state of #{@new_resource.name}, exit: 1") + end.to raise_error(Chef::Exceptions::Cron, "Error updating state of #{@new_resource.name}, exit: 1") end end @@ -970,7 +970,7 @@ MAILTO=foo@example.com context "when weekday is symbol" do it "should return weekday in crontab format" do @new_resource.weekday :wednesday - @provider.send(:weekday_in_crontab).should eq("3") + expect(@provider.send(:weekday_in_crontab)).to eq("3") end it "should raise an error with an unknown weekday" do @@ -981,7 +981,7 @@ MAILTO=foo@example.com context "when weekday is a number in a string" do it "should return the string" do @new_resource.weekday "3" - @provider.send(:weekday_in_crontab).should eq("3") + expect(@provider.send(:weekday_in_crontab)).to eq("3") end it "should raise an error with an out of range number" do @@ -992,14 +992,14 @@ MAILTO=foo@example.com context "when weekday is string with the name of the week" do it "should return the string" do @new_resource.weekday "mon" - @provider.send(:weekday_in_crontab).should eq("mon") + expect(@provider.send(:weekday_in_crontab)).to eq("mon") end end context "when weekday is an integer" do it "should return the integer" do @new_resource.weekday 1 - @provider.send(:weekday_in_crontab).should eq("1") + expect(@provider.send(:weekday_in_crontab)).to eq("1") end it "should raise an error with an out of range integer" do diff --git a/spec/unit/provider/deploy/revision_spec.rb b/spec/unit/provider/deploy/revision_spec.rb index 9fa8bdf826..4ca64e3445 100644 --- a/spec/unit/provider/deploy/revision_spec.rb +++ b/spec/unit/provider/deploy/revision_spec.rb @@ -21,7 +21,7 @@ require 'spec_helper' describe Chef::Provider::Deploy::Revision do before do - Chef::Platform.stub(:windows?) { false } + allow(Chef::Platform).to receive(:windows?) { false } @temp_dir = Dir.mktmpdir Chef::Config[:file_cache_path] = @temp_dir @resource = Chef::Resource::Deploy.new("/my/deploy/dir") @@ -32,7 +32,7 @@ describe Chef::Provider::Deploy::Revision do @provider = Chef::Provider::Deploy::Revision.new(@resource, @run_context) @provider.load_current_resource @runner = double("runnah") - Chef::Runner.stub(:new).and_return(@runner) + allow(Chef::Runner).to receive(:new).and_return(@runner) @expected_release_dir = "/my/deploy/dir/releases/8a3195bf3efa246f743c5dfa83683201880f935c" end @@ -43,41 +43,41 @@ 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.send(:release_slug).should == "uglySlugly" + allow(@provider.scm_provider).to receive(:revision_slug).and_return("uglySlugly") + expect(@provider.send(:release_slug)).to eq("uglySlugly") end it "deploys to a dir named after the revision" do - @provider.release_path.should == @expected_release_dir + expect(@provider.release_path).to eq(@expected_release_dir) end it "stores the release dir in the file cache in the cleanup step" do - FileUtils.stub(:mkdir_p) - FileUtils.stub(:cp_r) + allow(FileUtils).to receive(:mkdir_p) + allow(FileUtils).to receive(:cp_r) @provider.cleanup! - @provider.stub(:release_slug).and_return("73219b87e977d9c7ba1aa57e9ad1d88fa91a0ec2") + allow(@provider).to receive(: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] + expect(@provider.all_releases).to eq([@expected_release_dir,second_release]) 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) + allow(FileUtils).to receive(:mkdir_p) + allow(FileUtils).to receive(:cp_r) @provider.cleanup! - @provider.stub(:release_slug).and_return("73219b87e977d9c7ba1aa57e9ad1d88fa91a0ec2") + allow(@provider).to receive(: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] + expect(@provider.all_releases).to eq([@expected_release_dir,second_release]) @provider.cleanup! - @provider.stub(:release_slug).and_return("8a3195bf3efa246f743c5dfa83683201880f935c") + allow(@provider).to receive(:release_slug).and_return("8a3195bf3efa246f743c5dfa83683201880f935c") @provider.load_current_resource @provider.cleanup! - @provider.all_releases.should == [second_release, @expected_release_dir] + expect(@provider.all_releases).to eq([second_release, @expected_release_dir]) end it "removes a release from the file cache when it's deleted by :cleanup!" do @@ -87,25 +87,25 @@ describe Chef::Provider::Deploy::Revision do release_paths.each do |release_path| @provider.send(:release_created, release_path) end - @provider.all_releases.should == release_paths + expect(@provider.all_releases).to eq(release_paths) - FileUtils.stub(:rm_rf) + allow(FileUtils).to receive(:rm_rf) @provider.cleanup! expected_release_paths = (%w{second third fourth fifth} << @resource.revision).map do |release_name| "/my/deploy/dir/releases/#{release_name}" end - @provider.all_releases.should == expected_release_paths + expect(@provider.all_releases).to eq(expected_release_paths) end it "regenerates the file cache if it's not available" do oldest = "/my/deploy/dir/releases/oldest" latest = "/my/deploy/dir/releases/latest" - Dir.should_receive(:glob).with("/my/deploy/dir/releases/*").and_return([latest, oldest]) - ::File.should_receive(:ctime).with(oldest).and_return(Time.now - 10) - ::File.should_receive(:ctime).with(latest).and_return(Time.now - 1) - @provider.all_releases.should == [oldest, latest] + expect(Dir).to receive(:glob).with("/my/deploy/dir/releases/*").and_return([latest, oldest]) + expect(::File).to receive(:ctime).with(oldest).and_return(Time.now - 10) + expect(::File).to receive(:ctime).with(latest).and_return(Time.now - 1) + expect(@provider.all_releases).to eq([oldest, latest]) end end diff --git a/spec/unit/provider/deploy/timestamped_spec.rb b/spec/unit/provider/deploy/timestamped_spec.rb index 1d42abfc05..b189d33502 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) + allow(Time).to receive(: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,11 +30,11 @@ describe Chef::Provider::Deploy::Timestamped do @run_context = Chef::RunContext.new(@node, {}, @events) @timestamped_deploy = Chef::Provider::Deploy::Timestamped.new(@resource, @run_context) @runner = double("runnah") - Chef::Runner.stub(:new).and_return(@runner) + allow(Chef::Runner).to receive(:new).and_return(@runner) end it "gives a timestamp for release_slug" do - @timestamped_deploy.send(:release_slug).should == "20040815162342" + expect(@timestamped_deploy.send(:release_slug)).to eq("20040815162342") end end diff --git a/spec/unit/provider/deploy_spec.rb b/spec/unit/provider/deploy_spec.rb index d85ee4c7fd..c95a9b3d57 100644 --- a/spec/unit/provider/deploy_spec.rb +++ b/spec/unit/provider/deploy_spec.rb @@ -21,205 +21,205 @@ require 'spec_helper' describe Chef::Provider::Deploy do before do - Chef::Platform.stub(:windows?) { false } + allow(Chef::Platform).to receive(:windows?) { false } @release_time = Time.utc( 2004, 8, 15, 16, 23, 42) - Time.stub(:now).and_return(@release_time) + allow(Time).to receive(: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) + allow(@provider).to receive(:release_slug) + allow(@provider).to receive(:release_path).and_return(@expected_release_dir) end it "loads scm resource" do - @provider.scm_provider.should_receive(:load_current_resource) + expect(@provider.scm_provider).to receive(:load_current_resource) @provider.load_current_resource end it "supports :deploy and :rollback actions" do - @provider.should respond_to(:action_deploy) - @provider.should respond_to(:action_rollback) + expect(@provider).to respond_to(:action_deploy) + expect(@provider).to respond_to(:action_rollback) end context "when the deploy resource has a timeout attribute" do let(:ten_seconds) { 10 } before { @resource.timeout(ten_seconds) } it "relays the timeout to the scm resource" do - @provider.scm_provider.new_resource.timeout.should == ten_seconds + expect(@provider.scm_provider.new_resource.timeout).to eq(ten_seconds) end end context "when the deploy resource has no timeout attribute" do it "should not set a timeout on the scm resource" do - @provider.scm_provider.new_resource.timeout.should be_nil + expect(@provider.scm_provider.new_resource.timeout).to be_nil end end context "when the deploy_to dir does not exist yet" 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) - @provider.stub(:symlink) - @provider.stub(:migrate) - @provider.stub(:copy_cached_repo) + expect(FileUtils).to receive(:mkdir_p).with(@resource.deploy_to).ordered + expect(FileUtils).to receive(:mkdir_p).with(@resource.shared_path).ordered + allow(::File).to receive(:directory?).and_return(false) + allow(@provider).to receive(:symlink) + allow(@provider).to receive(:migrate) + allow(@provider).to receive(:copy_cached_repo) end it "creates deploy_to dir" do - ::Dir.should_receive(:chdir).with(@expected_release_dir).exactly(4).times - @provider.should_receive(:enforce_ownership).twice - @provider.stub(:update_cached_repo) + expect(::Dir).to receive(:chdir).with(@expected_release_dir).exactly(4).times + expect(@provider).to receive(:enforce_ownership).twice + allow(@provider).to receive(:update_cached_repo) @provider.deploy end end it "does not create deploy_to dir if it exists" do - ::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) - @provider.should_receive(:enforce_ownership).twice - @provider.stub(:copy_cached_repo) - @provider.stub(:update_cached_repo) - @provider.stub(:symlink) - @provider.stub(:migrate) + allow(::File).to receive(:directory?).and_return(true) + expect(::Dir).to receive(:chdir).with(@expected_release_dir).exactly(4).times + expect(FileUtils).not_to receive(:mkdir_p).with(@resource.deploy_to) + expect(FileUtils).not_to receive(:mkdir_p).with(@resource.shared_path) + expect(@provider).to receive(:enforce_ownership).twice + allow(@provider).to receive(:copy_cached_repo) + allow(@provider).to receive(:update_cached_repo) + allow(@provider).to receive(:symlink) + allow(@provider).to receive(:migrate) @provider.deploy end it "ensures the deploy_to dir ownership after the verfication that it exists" do - ::Dir.should_receive(:chdir).with(@expected_release_dir).exactly(4).times - @provider.should_receive(:verify_directories_exist).ordered - @provider.should_receive(:enforce_ownership).ordered - @provider.stub(:copy_cached_repo) - @provider.stub(:update_cached_repo) - @provider.stub(:install_gems) - @provider.should_receive(:enforce_ownership).ordered - @provider.stub(:enforce_ownership) - @provider.stub(:symlink) - @provider.stub(:migrate) + expect(::Dir).to receive(:chdir).with(@expected_release_dir).exactly(4).times + expect(@provider).to receive(:verify_directories_exist).ordered + expect(@provider).to receive(:enforce_ownership).ordered + allow(@provider).to receive(:copy_cached_repo) + allow(@provider).to receive(:update_cached_repo) + allow(@provider).to receive(:install_gems) + expect(@provider).to receive(:enforce_ownership).ordered + allow(@provider).to receive(:enforce_ownership) + allow(@provider).to receive(:symlink) + allow(@provider).to receive(:migrate) @provider.deploy end it "updates and copies the repo, then does a migrate, symlink, restart, restart, cleanup on deploy" do - FileUtils.stub(:mkdir_p).with("/my/deploy/dir") - FileUtils.stub(:mkdir_p).with("/my/deploy/dir/shared") - @provider.should_receive(:enforce_ownership).twice - @provider.should_receive(:update_cached_repo) - @provider.should_receive(:copy_cached_repo) - @provider.should_receive(:install_gems) - @provider.should_receive(:callback).with(:before_migrate, nil) - @provider.should_receive(:migrate) - @provider.should_receive(:callback).with(:before_symlink, nil) - @provider.should_receive(:symlink) - @provider.should_receive(:callback).with(:before_restart, nil) - @provider.should_receive(:restart) - @provider.should_receive(:callback).with(:after_restart, nil) - @provider.should_receive(:cleanup!) + allow(FileUtils).to receive(:mkdir_p).with("/my/deploy/dir") + allow(FileUtils).to receive(:mkdir_p).with("/my/deploy/dir/shared") + expect(@provider).to receive(:enforce_ownership).twice + expect(@provider).to receive(:update_cached_repo) + expect(@provider).to receive(:copy_cached_repo) + expect(@provider).to receive(:install_gems) + expect(@provider).to receive(:callback).with(:before_migrate, nil) + expect(@provider).to receive(:migrate) + expect(@provider).to receive(:callback).with(:before_symlink, nil) + expect(@provider).to receive(:symlink) + expect(@provider).to receive(:callback).with(:before_restart, nil) + expect(@provider).to receive(:restart) + expect(@provider).to receive(:callback).with(:after_restart, nil) + expect(@provider).to receive(:cleanup!) @provider.deploy 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.should_not_receive(:deploy) + allow(@provider).to receive(:all_releases).and_return([@expected_release_dir]) + allow(@provider).to receive(:current_release?).with(@expected_release_dir).and_return(true) + expect(@provider).not_to 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.should_receive(:rollback_to).with(@expected_release_dir) - @provider.should_receive(:current_release?) + allow(@provider).to receive(:all_releases).and_return([@expected_release_dir, "102021"]) + allow(@provider).to receive(:current_release?).with(@expected_release_dir).and_return(false) + expect(@provider).to receive(:rollback_to).with(@expected_release_dir) + expect(@provider).to receive(:current_release?) @provider.run_action(:deploy) end it "calls deploy when deploying a new release" do - @provider.stub(:all_releases).and_return([]) - @provider.should_receive(:deploy) + allow(@provider).to receive(:all_releases).and_return([]) + expect(@provider).to receive(:deploy) @provider.run_action(:deploy) end it "runs action svn_force_export when new_resource.svn_force_export is true" do @resource.svn_force_export true - @provider.scm_provider.should_receive(:run_action).with(:force_export) + expect(@provider.scm_provider).to receive(:run_action).with(:force_export) @provider.update_cached_repo end it "Removes the old release before deploying when force deploying over it" do - @provider.stub(:all_releases).and_return([@expected_release_dir]) - FileUtils.should_receive(:rm_rf).with(@expected_release_dir) - @provider.should_receive(:deploy) + allow(@provider).to receive(:all_releases).and_return([@expected_release_dir]) + expect(FileUtils).to receive(:rm_rf).with(@expected_release_dir) + expect(@provider).to 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.should_receive(:deploy) + allow(@provider).to receive(:all_releases).and_return([]) + expect(@provider).to 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.should_not_receive(:rollback) - lambda { + allow(@provider).to receive(:all_releases).and_return(['previous_release']) + allow(@provider).to receive(:deploy){ raise "Unexpected error" } + allow(@provider).to receive(:previous_release_path).and_return('previous_release') + expect(@provider).not_to receive(:rollback) + expect { @provider.run_action(:deploy) - }.should raise_exception(RuntimeError, "Unexpected error") + }.to raise_exception(RuntimeError, "Unexpected error") end 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.should_receive(:rollback) - lambda { + allow(@provider).to receive(:all_releases).and_return(['previous_release']) + allow(@provider).to receive(:deploy){ raise "Unexpected error" } + allow(@provider).to receive(:previous_release_path).and_return('previous_release') + expect(@provider).to receive(:rollback) + expect { @provider.run_action(:deploy) - }.should raise_exception(RuntimeError, "Unexpected error") + }.to raise_exception(RuntimeError, "Unexpected error") end 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") + allow(@provider).to receive(: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) - @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") + allow(Dir).to receive(:glob).with("/my/deploy/dir/releases/*").and_return(all_releases) + expect(@provider).to receive(:symlink) + expect(FileUtils).to receive(:rm_rf).with("/my/deploy/dir/releases/4") + expect(FileUtils).to receive(:rm_rf).with("/my/deploy/dir/releases/5") @provider.run_action(:rollback) - @provider.release_path.should eql("/my/deploy/dir/releases/3") - @provider.shared_path.should eql("/my/deploy/dir/shared") + expect(@provider.release_path).to eql("/my/deploy/dir/releases/3") + expect(@provider.shared_path).to eql("/my/deploy/dir/shared") end it "sets the release path to the specified release, symlinks, and rm's any newer releases on rollback" do - @provider.unstub(:release_path) + allow(@provider).to receive(:release_path).and_call_original 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) - @provider.should_receive(:symlink) - FileUtils.should_receive(:rm_rf).with("/my/deploy/dir/releases/20040815162342") + allow(Dir).to receive(:glob).with("/my/deploy/dir/releases/*").and_return(all_releases) + expect(@provider).to receive(:symlink) + expect(FileUtils).to receive(:rm_rf).with("/my/deploy/dir/releases/20040815162342") @provider.run_action(:rollback) - @provider.release_path.should eql("/my/deploy/dir/releases/20040700000000") - @provider.shared_path.should eql("/my/deploy/dir/shared") + expect(@provider.release_path).to eql("/my/deploy/dir/releases/20040700000000") + expect(@provider.shared_path).to eql("/my/deploy/dir/shared") end it "sets the release path to the penultimate release, symlinks, and rm's the last release on rollback" do - @provider.unstub(:release_path) + allow(@provider).to receive(:release_path).and_call_original 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) - @provider.should_receive(:symlink) - FileUtils.should_receive(:rm_rf).with("/my/deploy/dir/releases/20040815162342") + allow(Dir).to receive(:glob).with("/my/deploy/dir/releases/*").and_return(all_releases) + expect(@provider).to receive(:symlink) + expect(FileUtils).to receive(:rm_rf).with("/my/deploy/dir/releases/20040815162342") @provider.run_action(:rollback) - @provider.release_path.should eql("/my/deploy/dir/releases/20040700000000") - @provider.shared_path.should eql("/my/deploy/dir/shared") + expect(@provider.release_path).to eql("/my/deploy/dir/releases/20040700000000") + expect(@provider.shared_path).to eql("/my/deploy/dir/shared") end describe "if there are no releases to fallback to" do @@ -227,143 +227,143 @@ describe Chef::Provider::Deploy 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 all_releases = [ "/my/deploy/dir/releases/20040815162342"] - Dir.stub(:glob).with("/my/deploy/dir/releases/*").and_return(all_releases) + allow(Dir).to receive(: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) #@provider.release_path.should eql(NIL) -- no check needed since assertions will fail - lambda { + expect { @provider.run_action(:rollback) - }.should raise_exception(RuntimeError, "There is no release to rollback to!") + }.to raise_exception(RuntimeError, "There is no release to rollback to!") end 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) - lambda { + allow(Dir).to receive(:glob).with("/my/deploy/dir/releases/*").and_return(all_releases) + expect { @provider.run_action(:rollback) - }.should raise_exception(RuntimeError, "There is no release to rollback to!") + }.to raise_exception(RuntimeError, "There is no release to rollback to!") end end end 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) + allow(@provider).to receive(:release_path).and_call_original 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) - @provider.should_receive(:symlink) - FileUtils.should_receive(:rm_rf).with("/my/deploy/dir/releases/20040815162342") + allow(Dir).to receive(:glob).with("/my/deploy/dir/releases/*").and_return(all_releases) + expect(@provider).to receive(:symlink) + expect(FileUtils).to receive(:rm_rf).with("/my/deploy/dir/releases/20040815162342") @provider.run_action(:rollback) - @provider.release_path.should eql("/my/deploy/dir/releases/20040700000000") - @provider.shared_path.should eql("/my/deploy/dir/shared") + expect(@provider.release_path).to eql("/my/deploy/dir/releases/20040700000000") + expect(@provider.shared_path).to eql("/my/deploy/dir/shared") end end 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) - lambda {@provider.run_action(:rollback)}.should raise_error(RuntimeError) + allow(Dir).to receive(:glob).with("/my/deploy/dir/releases/*").and_return(all_releases) + expect {@provider.run_action(:rollback)}.to raise_error(RuntimeError) end it "runs the new resource collection in the runner during a callback" do @runner = double("Runner") - Chef::Runner.stub(:new).and_return(@runner) - @runner.should_receive(:converge) + allow(Chef::Runner).to receive(:new).and_return(@runner) + expect(@runner).to receive(:converge) callback_code = Proc.new { :noop } @provider.callback(:whatevs, callback_code) end it "loads callback files from the release/ dir if the file exists" do foo_callback = @expected_release_dir + "/deploy/foo.rb" - ::File.should_receive(:exist?).with(foo_callback).once.and_return(true) - ::Dir.should_receive(:chdir).with(@expected_release_dir).and_yield - @provider.should_receive(:from_file).with(foo_callback) + expect(::File).to receive(:exist?).with(foo_callback).once.and_return(true) + expect(::Dir).to receive(:chdir).with(@expected_release_dir).and_yield + expect(@provider).to receive(:from_file).with(foo_callback) @provider.callback(:foo, "deploy/foo.rb") end it "raises a runtime error if a callback file is explicitly specified but does not exist" do baz_callback = "/deploy/baz.rb" - ::File.should_receive(:exist?).with("#{@expected_release_dir}/#{baz_callback}").and_return(false) + expect(::File).to receive(:exist?).with("#{@expected_release_dir}/#{baz_callback}").and_return(false) @resource.before_migrate baz_callback @provider.define_resource_requirements @provider.action = :deploy - lambda {@provider.process_resource_requirements}.should raise_error(RuntimeError) + expect {@provider.process_resource_requirements}.to raise_error(RuntimeError) end it "runs a default callback if the callback code is nil" do bar_callback = @expected_release_dir + "/deploy/bar.rb" - ::File.should_receive(:exist?).with(bar_callback).and_return(true) - ::Dir.should_receive(:chdir).with(@expected_release_dir).and_yield - @provider.should_receive(:from_file).with(bar_callback) + expect(::File).to receive(:exist?).with(bar_callback).and_return(true) + expect(::Dir).to receive(:chdir).with(@expected_release_dir).and_yield + expect(@provider).to receive(:from_file).with(bar_callback) @provider.callback(:bar, nil) end it "skips an eval callback if the file doesn't exist" do barbaz_callback = @expected_release_dir + "/deploy/barbaz.rb" - ::File.should_receive(:exist?).with(barbaz_callback).and_return(false) - ::Dir.should_receive(:chdir).with(@expected_release_dir).and_yield - @provider.should_not_receive(:from_file) + expect(::File).to receive(:exist?).with(barbaz_callback).and_return(false) + expect(::Dir).to receive(:chdir).with(@expected_release_dir).and_yield + expect(@provider).not_to receive(:from_file) @provider.callback(:barbaz, nil) end # CHEF-3449 #converge_by is called in #recipe_eval and must happen in sequence # with the other calls to #converge_by to keep the train on the tracks it "evaluates a callback file before the corresponding step" do - @provider.should_receive(:verify_directories_exist) - @provider.should_receive(:update_cached_repo) - @provider.should_receive(:enforce_ownership) - @provider.should_receive(:copy_cached_repo) - @provider.should_receive(:install_gems) - @provider.should_receive(:enforce_ownership) - @provider.should_receive(:converge_by).ordered # before_migrate - @provider.should_receive(:migrate).ordered - @provider.should_receive(:converge_by).ordered # before_symlink - @provider.should_receive(:symlink).ordered - @provider.should_receive(:converge_by).ordered # before_restart - @provider.should_receive(:restart).ordered - @provider.should_receive(:converge_by).ordered # after_restart - @provider.should_receive(:cleanup!) + expect(@provider).to receive(:verify_directories_exist) + expect(@provider).to receive(:update_cached_repo) + expect(@provider).to receive(:enforce_ownership) + expect(@provider).to receive(:copy_cached_repo) + expect(@provider).to receive(:install_gems) + expect(@provider).to receive(:enforce_ownership) + expect(@provider).to receive(:converge_by).ordered # before_migrate + expect(@provider).to receive(:migrate).ordered + expect(@provider).to receive(:converge_by).ordered # before_symlink + expect(@provider).to receive(:symlink).ordered + expect(@provider).to receive(:converge_by).ordered # before_restart + expect(@provider).to receive(:restart).ordered + expect(@provider).to receive(:converge_by).ordered # after_restart + expect(@provider).to receive(:cleanup!) @provider.deploy end it "gets a SCM provider as specified by its resource" do - @provider.scm_provider.should be_an_instance_of(Chef::Provider::Git) - @provider.scm_provider.new_resource.destination.should eql("/my/deploy/dir/shared/cached-copy") + expect(@provider.scm_provider).to be_an_instance_of(Chef::Provider::Git) + expect(@provider.scm_provider.new_resource.destination).to eql("/my/deploy/dir/shared/cached-copy") end it "syncs the cached copy of the repo" do - @provider.scm_provider.should_receive(:run_action).with(:sync) + expect(@provider.scm_provider).to receive(:run_action).with(:sync) @provider.update_cached_repo end it "makes a copy of the cached repo in releases dir" do - FileUtils.should_receive(:mkdir_p).with("/my/deploy/dir/releases") - FileUtils.should_receive(:cp_r).with("/my/deploy/dir/shared/cached-copy/.", @expected_release_dir, :preserve => true) + expect(FileUtils).to receive(:mkdir_p).with("/my/deploy/dir/releases") + expect(FileUtils).to receive(:cp_r).with("/my/deploy/dir/shared/cached-copy/.", @expected_release_dir, :preserve => true) @provider.copy_cached_repo end it "calls the internal callback :release_created when cleaning up the releases" do - FileUtils.stub(:mkdir_p) - FileUtils.stub(:cp_r) - @provider.should_receive(:release_created) + allow(FileUtils).to receive(:mkdir_p) + allow(FileUtils).to receive(:cp_r) + expect(@provider).to receive(:release_created) @provider.cleanup! end it "chowns the whole release dir to user and group specified in the resource" do @resource.user "foo" @resource.group "bar" - FileUtils.should_receive(:chown_R).with("foo", "bar", "/my/deploy/dir") + expect(FileUtils).to receive(:chown_R).with("foo", "bar", "/my/deploy/dir") @provider.enforce_ownership end it "skips the migration when resource.migrate => false but runs symlinks before migration" do @resource.migrate false - @provider.should_not_receive :run_command - @provider.should_receive :run_symlinks_before_migrate + expect(@provider).not_to receive :run_command + expect(@provider).to receive :run_symlinks_before_migrate @provider.migrate end @@ -373,12 +373,12 @@ describe Chef::Provider::Deploy do @resource.user "deployNinja" @resource.group "deployNinjas" @resource.environment "RAILS_ENV" => "production" - FileUtils.should_receive(:ln_sf).with("/my/deploy/dir/shared/config/database.yml", @expected_release_dir + "/config/database.yml") - @provider.should_receive(:enforce_ownership) + expect(FileUtils).to receive(:ln_sf).with("/my/deploy/dir/shared/config/database.yml", @expected_release_dir + "/config/database.yml") + expect(@provider).to receive(:enforce_ownership) - 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, + allow(STDOUT).to receive(:tty?).and_return(true) + allow(Chef::Log).to receive(:info?).and_return(true) + expect(@provider).to receive(:run_command).with(:command => "migration_foo", :cwd => @expected_release_dir, :user => "deployNinja", :group => "deployNinjas", :log_level => :info, :live_stream => STDOUT, :log_tag => "deploy[/my/deploy/dir]", @@ -387,31 +387,31 @@ describe Chef::Provider::Deploy do end it "purges the current release's /log /tmp/pids/ and /public/system directories" do - FileUtils.should_receive(:rm_rf).with(@expected_release_dir + "/log") - FileUtils.should_receive(:rm_rf).with(@expected_release_dir + "/tmp/pids") - FileUtils.should_receive(:rm_rf).with(@expected_release_dir + "/public/system") + expect(FileUtils).to receive(:rm_rf).with(@expected_release_dir + "/log") + expect(FileUtils).to receive(:rm_rf).with(@expected_release_dir + "/tmp/pids") + expect(FileUtils).to receive(:rm_rf).with(@expected_release_dir + "/public/system") @provider.purge_tempfiles_from_current_release end it "symlinks temporary files and logs from the shared dir into the current release" do - FileUtils.stub(:mkdir_p).with(@resource.shared_path + "/system") - FileUtils.stub(:mkdir_p).with(@resource.shared_path + "/pids") - FileUtils.stub(:mkdir_p).with(@resource.shared_path + "/log") - FileUtils.should_receive(:mkdir_p).with(@expected_release_dir + "/tmp") - FileUtils.should_receive(:mkdir_p).with(@expected_release_dir + "/public") - FileUtils.should_receive(:mkdir_p).with(@expected_release_dir + "/config") - FileUtils.should_receive(:ln_sf).with("/my/deploy/dir/shared/system", @expected_release_dir + "/public/system") - FileUtils.should_receive(:ln_sf).with("/my/deploy/dir/shared/pids", @expected_release_dir + "/tmp/pids") - FileUtils.should_receive(:ln_sf).with("/my/deploy/dir/shared/log", @expected_release_dir + "/log") - FileUtils.should_receive(:ln_sf).with("/my/deploy/dir/shared/config/database.yml", @expected_release_dir + "/config/database.yml") - @provider.should_receive(:enforce_ownership) + allow(FileUtils).to receive(:mkdir_p).with(@resource.shared_path + "/system") + allow(FileUtils).to receive(:mkdir_p).with(@resource.shared_path + "/pids") + allow(FileUtils).to receive(:mkdir_p).with(@resource.shared_path + "/log") + expect(FileUtils).to receive(:mkdir_p).with(@expected_release_dir + "/tmp") + expect(FileUtils).to receive(:mkdir_p).with(@expected_release_dir + "/public") + expect(FileUtils).to receive(:mkdir_p).with(@expected_release_dir + "/config") + expect(FileUtils).to receive(:ln_sf).with("/my/deploy/dir/shared/system", @expected_release_dir + "/public/system") + expect(FileUtils).to receive(:ln_sf).with("/my/deploy/dir/shared/pids", @expected_release_dir + "/tmp/pids") + expect(FileUtils).to receive(:ln_sf).with("/my/deploy/dir/shared/log", @expected_release_dir + "/log") + expect(FileUtils).to receive(:ln_sf).with("/my/deploy/dir/shared/config/database.yml", @expected_release_dir + "/config/database.yml") + expect(@provider).to receive(:enforce_ownership) @provider.link_tempfiles_to_current_release end it "symlinks the current release dir into production" do - FileUtils.should_receive(:rm_f).with("/my/deploy/dir/current") - FileUtils.should_receive(:ln_sf).with(@expected_release_dir, "/my/deploy/dir/current") - @provider.should_receive(:enforce_ownership) + expect(FileUtils).to receive(:rm_f).with("/my/deploy/dir/current") + expect(FileUtils).to receive(:ln_sf).with(@expected_release_dir, "/my/deploy/dir/current") + expect(@provider).to receive(:enforce_ownership) @provider.link_current_release_to_production end @@ -425,41 +425,41 @@ describe Chef::Provider::Deploy do end it "purges the purge_before_symlink directories" do - FileUtils.should_receive(:rm_rf).with(@expected_release_dir + "/foo") - FileUtils.should_receive(:rm_rf).with(@expected_release_dir + "/bar") + expect(FileUtils).to receive(:rm_rf).with(@expected_release_dir + "/foo") + expect(FileUtils).to receive(:rm_rf).with(@expected_release_dir + "/bar") @provider.purge_tempfiles_from_current_release end it "symlinks files from the shared directory to the current release directory" do - FileUtils.should_receive(:mkdir_p).with(@expected_release_dir + "/baz") - FileUtils.should_receive(:mkdir_p).with(@expected_release_dir + "/qux") - FileUtils.stub(:mkdir_p).with(@resource.shared_path + "/foo/bar") - FileUtils.stub(:mkdir_p).with(@resource.shared_path + "/baz") - FileUtils.should_receive(:ln_sf).with("/my/deploy/dir/shared/foo/bar", @expected_release_dir + "/foo/bar") - FileUtils.should_receive(:ln_sf).with("/my/deploy/dir/shared/baz", @expected_release_dir + "/qux/baz") - FileUtils.should_receive(:ln_sf).with("/my/deploy/dir/shared/radiohead/in_rainbows.yml", @expected_release_dir + "/awesome") - @provider.should_receive(:enforce_ownership) + expect(FileUtils).to receive(:mkdir_p).with(@expected_release_dir + "/baz") + expect(FileUtils).to receive(:mkdir_p).with(@expected_release_dir + "/qux") + allow(FileUtils).to receive(:mkdir_p).with(@resource.shared_path + "/foo/bar") + allow(FileUtils).to receive(:mkdir_p).with(@resource.shared_path + "/baz") + expect(FileUtils).to receive(:ln_sf).with("/my/deploy/dir/shared/foo/bar", @expected_release_dir + "/foo/bar") + expect(FileUtils).to receive(:ln_sf).with("/my/deploy/dir/shared/baz", @expected_release_dir + "/qux/baz") + expect(FileUtils).to receive(:ln_sf).with("/my/deploy/dir/shared/radiohead/in_rainbows.yml", @expected_release_dir + "/awesome") + expect(@provider).to receive(:enforce_ownership) @provider.link_tempfiles_to_current_release end end it "does nothing for restart if restart_command is empty" do - @provider.should_not_receive(:run_command) + expect(@provider).not_to receive(:run_command) @provider.restart end it "runs the restart command in the current application dir when the resource has a restart_command" do @resource.restart_command "restartcmd" - @provider.should_receive(:run_command).with(:command => "restartcmd", :cwd => "/my/deploy/dir/current", :log_tag => "deploy[/my/deploy/dir]", :log_level => :debug) + expect(@provider).to receive(:run_command).with(:command => "restartcmd", :cwd => "/my/deploy/dir/current", :log_tag => "deploy[/my/deploy/dir]", :log_level => :debug) @provider.restart end it "lists all available releases" do all_releases = ["/my/deploy/dir/20040815162342", "/my/deploy/dir/20040700000000", "/my/deploy/dir/20040600000000", "/my/deploy/dir/20040500000000"].sort! - Dir.should_receive(:glob).with("/my/deploy/dir/releases/*").and_return(all_releases) - @provider.all_releases.should eql(all_releases) + expect(Dir).to receive(:glob).with("/my/deploy/dir/releases/*").and_return(all_releases) + expect(@provider.all_releases).to eql(all_releases) end it "removes all but the 5 newest releases" do @@ -467,10 +467,10 @@ 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) - 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") + allow(@provider).to receive(:all_releases).and_return(all_releases) + expect(FileUtils).to receive(:rm_rf).with("/my/deploy/dir/20040100000000") + expect(FileUtils).to receive(:rm_rf).with("/my/deploy/dir/20040200000000") + expect(FileUtils).to receive(:rm_rf).with("/my/deploy/dir/20040300000000") @provider.cleanup! end @@ -480,8 +480,8 @@ 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) - FileUtils.should_receive(:rm_rf).with("/my/deploy/dir/20040100000000") + allow(@provider).to receive(:all_releases).and_return(all_releases) + expect(FileUtils).to receive(:rm_rf).with("/my/deploy/dir/20040100000000") @provider.cleanup! end @@ -489,27 +489,27 @@ 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.should_receive(:release_deleted).with("/my/deploy/dir/20040300000000") + allow(@provider).to receive(:all_releases).and_return(all_releases) + allow(FileUtils).to receive(:rm_rf) + expect(@provider).to receive(:release_deleted).with("/my/deploy/dir/20040300000000") @provider.cleanup! end it "puts resource.to_hash in @configuration for backwards compat with capistano-esque deploy hooks" do - @provider.instance_variable_get(:@configuration).should == @resource.to_hash + expect(@provider.instance_variable_get(:@configuration)).to eq(@resource.to_hash) end it "sets @configuration[:environment] to the value of RAILS_ENV for backwards compat reasons" do resource = Chef::Resource::Deploy.new("/my/deploy/dir") resource.environment "production" provider = Chef::Provider::Deploy.new(resource, @run_context) - provider.instance_variable_get(:@configuration)[:environment].should eql("production") + expect(provider.instance_variable_get(:@configuration)[:environment]).to eql("production") 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) + allow(@provider).to receive(:enforce_ownership) + allow(@provider).to receive(:run_symlinks_before_migrate) + allow(@provider).to receive(:run_command) @provider.migrate end @@ -521,13 +521,13 @@ describe Chef::Provider::Deploy do recipe_code = Proc.new {snitch = 42} #@provider.should_receive(:instance_eval).with(&recipe_code) @provider.callback(:whateverz, recipe_code) - snitch.should == 42 + expect(snitch).to eq(42) end it "loads a recipe file from the specified path and from_file evals it" do - ::File.should_receive(:exist?).with(@expected_release_dir + "/chefz/foobar_callback.rb").once.and_return(true) - ::Dir.should_receive(:chdir).with(@expected_release_dir).and_yield - @provider.should_receive(:from_file).with(@expected_release_dir + "/chefz/foobar_callback.rb") + expect(::File).to receive(:exist?).with(@expected_release_dir + "/chefz/foobar_callback.rb").once.and_return(true) + expect(::Dir).to receive(:chdir).with(@expected_release_dir).and_yield + expect(@provider).to receive(:from_file).with(@expected_release_dir + "/chefz/foobar_callback.rb") @provider.callback(:whateverz, "chefz/foobar_callback.rb") end @@ -536,40 +536,40 @@ describe Chef::Provider::Deploy do restart_cmd = Proc.new {snitch = 42} @resource.restart(&restart_cmd) @provider.restart - snitch.should == 42 + expect(snitch).to eq(42) end end describe "API bridge to capistrano" do it "defines sudo as a forwarder to execute" do - @provider.should_receive(:execute).with("the moon, fool") + expect(@provider).to receive(:execute).with("the moon, fool") @provider.sudo("the moon, fool") end it "defines run as a forwarder to execute, setting the user, group, cwd and environment to new_resource.user" do mock_execution = double("Resource::Execute") - @provider.should_receive(:execute).with("iGoToHell4this").and_return(mock_execution) + expect(@provider).to receive(:execute).with("iGoToHell4this").and_return(mock_execution) @resource.user("notCoolMan") @resource.group("Ggroup") @resource.environment("APP_ENV" => 'staging') @resource.deploy_to("/my/app") - mock_execution.should_receive(:user).with("notCoolMan") - mock_execution.should_receive(:group).with("Ggroup") - mock_execution.should_receive(:cwd){|*args| + expect(mock_execution).to receive(:user).with("notCoolMan") + expect(mock_execution).to receive(:group).with("Ggroup") + expect(mock_execution).to receive(:cwd){|*args| if args.empty? nil else - args.size.should == 1 - args.first.should == @provider.release_path + expect(args.size).to eq(1) + expect(args.first).to eq(@provider.release_path) end }.twice - mock_execution.should_receive(:environment){ |*args| + expect(mock_execution).to receive(:environment){ |*args| if args.empty? nil else - args.size.should == 1 - args.first.should == {"APP_ENV" => "staging"} + expect(args.size).to eq(1) + expect(args.first).to eq({"APP_ENV" => "staging"}) end }.twice @provider.run("iGoToHell4this") @@ -578,18 +578,18 @@ describe Chef::Provider::Deploy do it "defines run as a forwarder to execute, setting cwd and environment but not override" do mock_execution = double("Resource::Execute") - @provider.should_receive(:execute).with("iGoToHell4this").and_return(mock_execution) + expect(@provider).to receive(:execute).with("iGoToHell4this").and_return(mock_execution) @resource.user("notCoolMan") - mock_execution.should_receive(:user).with("notCoolMan") - mock_execution.should_receive(:cwd).with(no_args()).and_return("/some/value") - mock_execution.should_receive(:environment).with(no_args()).and_return({}) + expect(mock_execution).to receive(:user).with("notCoolMan") + expect(mock_execution).to receive(:cwd).with(no_args()).and_return("/some/value") + expect(mock_execution).to receive(:environment).with(no_args()).and_return({}) @provider.run("iGoToHell4this") end it "converts sudo and run to exec resources in hooks" do runner = double("tehRunner") - Chef::Runner.stub(:new).and_return(runner) + allow(Chef::Runner).to receive(:new).and_return(runner) snitch = nil @resource.user("tehCat") @@ -601,40 +601,40 @@ describe Chef::Provider::Deploy do snitch = temp_collection.lookup("execute[tehMice]") end - runner.should_receive(:converge) + expect(runner).to receive(:converge) # @provider.callback(:phony, callback_code) - snitch.should be_an_instance_of(Chef::Resource::Execute) - snitch.user.should == "tehCat" + expect(snitch).to be_an_instance_of(Chef::Resource::Execute) + expect(snitch.user).to eq("tehCat") end end describe "installing gems from a gems.yml" do before do - ::File.stub(:exist?).with("#{@expected_release_dir}/gems.yml").and_return(true) + allow(::File).to receive(:exist?).with("#{@expected_release_dir}/gems.yml").and_return(true) @gem_list = [{:name=>"eventmachine", :version=>"0.12.9"}] end it "reads a gems.yml file, creating gem providers for each with action :upgrade" do - IO.should_receive(:read).with("#{@expected_release_dir}/gems.yml").and_return("cookie") - YAML.should_receive(:load).with("cookie").and_return(@gem_list) + expect(IO).to receive(:read).with("#{@expected_release_dir}/gems.yml").and_return("cookie") + expect(YAML).to receive(:load).with("cookie").and_return(@gem_list) gems = @provider.send(:gem_packages) - gems.map { |g| g.action }.should == [[:install]] - gems.map { |g| g.name }.should == %w{eventmachine} - gems.map { |g| g.version }.should == %w{0.12.9} + expect(gems.map { |g| g.action }).to eq([[:install]]) + expect(gems.map { |g| g.name }).to eq(%w{eventmachine}) + expect(gems.map { |g| g.version }).to eq(%w{0.12.9}) end it "takes a list of gem providers converges them" do - IO.stub(:read) - YAML.stub(:load).and_return(@gem_list) + allow(IO).to receive(:read) + allow(YAML).to receive(: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 actual = gem_runner.run_context.resource_collection.all_resources.map { |r| [r.name, r.version] } - actual.should == expected_gem_resources + expect(actual).to eq(expected_gem_resources) end end diff --git a/spec/unit/provider/directory_spec.rb b/spec/unit/provider/directory_spec.rb index 25ca9e0175..33df776ed4 100644 --- a/spec/unit/provider/directory_spec.rb +++ b/spec/unit/provider/directory_spec.rb @@ -48,31 +48,31 @@ describe Chef::Provider::Directory do describe "scanning file security metadata on unix" do before do - Chef::Platform.stub(:windows?).and_return(false) + allow(Chef::Platform).to receive(:windows?).and_return(false) end let(:mock_stat) do cstats = double("stats") - cstats.stub(:uid).and_return(500) - cstats.stub(:gid).and_return(500) - cstats.stub(:mode).and_return(0755) + allow(cstats).to receive(:uid).and_return(500) + allow(cstats).to receive(:gid).and_return(500) + allow(cstats).to receive(: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.should_receive(:stat).and_return(mock_stat) + allow(File).to receive(:exists?).and_return(true) + expect(File).to receive(:stat).and_return(mock_stat) @directory.load_current_resource - @directory.current_resource.mode.should == "0755" + expect(@directory.current_resource.mode).to eq("0755") end 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.should_receive(:stat).and_return(mock_stat) + allow(File).to receive(:exists?).and_return(true) + expect(File).to receive(:stat).and_return(mock_stat) @directory.load_current_resource - @directory.current_resource.path.should eql(@new_resource.path) - @directory.current_resource.owner.should eql(500) - @directory.current_resource.group.should eql(500) + expect(@directory.current_resource.path).to eql(@new_resource.path) + expect(@directory.current_resource.owner).to eql(500) + expect(@directory.current_resource.group).to eql(500) end end @@ -86,20 +86,20 @@ describe Chef::Provider::Directory do it "should create a new directory on create, setting updated to true", :unix_only do @new_resource.path "/tmp/foo" - File.should_receive(:exists?).at_least(:once).and_return(false) - File.should_receive(:directory?).with("/tmp").and_return(true) - Dir.should_receive(:mkdir).with(@new_resource.path).once.and_return(true) + expect(File).to receive(:exists?).at_least(:once).and_return(false) + expect(File).to receive(:directory?).with("/tmp").and_return(true) + expect(Dir).to receive(:mkdir).with(@new_resource.path).once.and_return(true) - @directory.should_receive(:do_acl_changes) - @directory.stub(:do_selinux) + expect(@directory).to receive(:do_acl_changes) + allow(@directory).to receive(:do_selinux) @directory.run_action(:create) - @directory.new_resource.should be_updated + expect(@directory.new_resource).to be_updated end it "should raise an exception if the parent directory does not exist and recursive is false" do @new_resource.path "/tmp/some/dir" @new_resource.recursive false - lambda { @directory.run_action(:create) }.should raise_error(Chef::Exceptions::EnclosingDirectoryDoesNotExist) + expect { @directory.run_action(:create) }.to raise_error(Chef::Exceptions::EnclosingDirectoryDoesNotExist) end # Unix only for now. While file security attribute reporting for windows is @@ -108,26 +108,26 @@ describe Chef::Provider::Directory do it "should create a new directory when parent directory does not exist if recursive is true and permissions are correct", :unix_only do @new_resource.path "/path/to/dir" @new_resource.recursive true - File.should_receive(:exists?).with(@new_resource.path).ordered.and_return(false) + expect(File).to receive(:exists?).with(@new_resource.path).ordered.and_return(false) - File.should_receive(:exists?).with('/path/to').ordered.and_return(false) - File.should_receive(:exists?).with('/path').ordered.and_return(true) - File.should_receive(:writable?).with('/path').ordered.and_return(true) - File.should_receive(:exists?).with(@new_resource.path).ordered.and_return(false) + expect(File).to receive(:exists?).with('/path/to').ordered.and_return(false) + expect(File).to receive(:exists?).with('/path').ordered.and_return(true) + expect(File).to receive(:writable?).with('/path').ordered.and_return(true) + expect(File).to receive(:exists?).with(@new_resource.path).ordered.and_return(false) - FileUtils.should_receive(:mkdir_p).with(@new_resource.path).and_return(true) - @directory.should_receive(:do_acl_changes) - @directory.stub(:do_selinux) + expect(FileUtils).to receive(:mkdir_p).with(@new_resource.path).and_return(true) + expect(@directory).to receive(:do_acl_changes) + allow(@directory).to receive(:do_selinux) @directory.run_action(:create) - @new_resource.should be_updated + expect(@new_resource).to be_updated end it "should raise an error when creating a directory when parent directory is a file" do - File.should_receive(:directory?).and_return(false) - Dir.should_not_receive(:mkdir).with(@new_resource.path) - lambda { @directory.run_action(:create) }.should raise_error(Chef::Exceptions::EnclosingDirectoryDoesNotExist) - @directory.new_resource.should_not be_updated + expect(File).to receive(:directory?).and_return(false) + expect(Dir).not_to receive(:mkdir).with(@new_resource.path) + expect { @directory.run_action(:create) }.to raise_error(Chef::Exceptions::EnclosingDirectoryDoesNotExist) + expect(@directory.new_resource).not_to be_updated end # Unix only for now. While file security attribute reporting for windows is @@ -136,53 +136,53 @@ describe Chef::Provider::Directory do it "should not create the directory if it already exists", :unix_only do stub_file_cstats @new_resource.path "/tmp/foo" - File.should_receive(:directory?).at_least(:once).and_return(true) - File.should_receive(:writable?).with("/tmp").and_return(true) - File.should_receive(:exists?).at_least(:once).and_return(true) - Dir.should_not_receive(:mkdir).with(@new_resource.path) - @directory.should_receive(:do_acl_changes) + expect(File).to receive(:directory?).at_least(:once).and_return(true) + expect(File).to receive(:writable?).with("/tmp").and_return(true) + expect(File).to receive(:exists?).at_least(:once).and_return(true) + expect(Dir).not_to receive(:mkdir).with(@new_resource.path) + expect(@directory).to receive(:do_acl_changes) @directory.run_action(:create) end it "should delete the directory if it exists, and is writable with action_delete" do - File.should_receive(:directory?).and_return(true) - File.should_receive(:writable?).once.and_return(true) - Dir.should_receive(:delete).with(@new_resource.path).once.and_return(true) + expect(File).to receive(:directory?).and_return(true) + expect(File).to receive(:writable?).once.and_return(true) + expect(Dir).to receive(:delete).with(@new_resource.path).once.and_return(true) @directory.run_action(:delete) 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) - lambda { @directory.run_action(:delete) }.should raise_error(RuntimeError) + allow(File).to receive(:exists?).and_return(true) + allow(File).to receive(:writable?).and_return(false) + expect { @directory.run_action(:delete) }.to 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) - Dir.should_not_receive(:delete).with(@new_resource.path) + allow(File).to receive(:exists?).and_return(false) + expect(Dir).not_to receive(:delete).with(@new_resource.path) @directory.run_action(:delete) - @directory.new_resource.should_not be_updated + expect(@directory.new_resource).not_to be_updated end 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.should_receive(:directory?).and_return(false) - Dir.should_not_receive(:delete).with(@new_resource.path) - lambda { @directory.run_action(:delete) }.should raise_error(RuntimeError) - @directory.new_resource.should_not be_updated + allow(File).to receive(:exists?).and_return(true) + expect(File).to receive(:directory?).and_return(false) + expect(Dir).not_to receive(:delete).with(@new_resource.path) + expect { @directory.run_action(:delete) }.to raise_error(RuntimeError) + expect(@directory.new_resource).not_to be_updated end def stub_file_cstats cstats = double("stats") - cstats.stub(:uid).and_return(500) - cstats.stub(:gid).and_return(500) - cstats.stub(:mode).and_return(0755) + allow(cstats).to receive(:uid).and_return(500) + allow(cstats).to receive(:gid).and_return(500) + allow(cstats).to receive(: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) + allow(File).to receive(:stat).and_return(cstats) end end diff --git a/spec/unit/provider/dsc_script_spec.rb b/spec/unit/provider/dsc_script_spec.rb index d8fbee3ff9..dab2007920 100644 --- a/spec/unit/provider/dsc_script_spec.rb +++ b/spec/unit/provider/dsc_script_spec.rb @@ -39,21 +39,21 @@ describe Chef::Provider::DscScript do it "describes the resource as converged if there were 0 DSC resources" do allow(provider).to receive(:run_configuration).with(:test).and_return([]) provider.load_current_resource - provider.instance_variable_get('@resource_converged').should be_true + expect(provider.instance_variable_get('@resource_converged')).to be_true end it "describes the resource as not converged if there is 1 DSC resources that is converged" do dsc_resource_info = Chef::Util::DSC::ResourceInfo.new('resource', false, ['nothing will change something']) allow(provider).to receive(:run_configuration).with(:test).and_return([dsc_resource_info]) provider.load_current_resource - provider.instance_variable_get('@resource_converged').should be_true + expect(provider.instance_variable_get('@resource_converged')).to be_true end it "describes the resource as not converged if there is 1 DSC resources that is not converged" do dsc_resource_info = Chef::Util::DSC::ResourceInfo.new('resource', true, ['will change something']) allow(provider).to receive(:run_configuration).with(:test).and_return([dsc_resource_info]) provider.load_current_resource - provider.instance_variable_get('@resource_converged').should be_false + expect(provider.instance_variable_get('@resource_converged')).to be_false end it "describes the resource as not converged if there are any DSC resources that are not converged" do @@ -62,7 +62,7 @@ describe Chef::Provider::DscScript do allow(provider).to receive(:run_configuration).with(:test).and_return([dsc_resource_info1, dsc_resource_info2]) provider.load_current_resource - provider.instance_variable_get('@resource_converged').should be_false + expect(provider.instance_variable_get('@resource_converged')).to be_false end it "describes the resource as converged if all DSC resources that are converged" do @@ -71,7 +71,7 @@ describe Chef::Provider::DscScript do allow(provider).to receive(:run_configuration).with(:test).and_return([dsc_resource_info1, dsc_resource_info2]) provider.load_current_resource - provider.instance_variable_get('@resource_converged').should be_true + expect(provider.instance_variable_get('@resource_converged')).to be_true end end @@ -82,7 +82,7 @@ describe Chef::Provider::DscScript do allow(provider).to receive(:load_current_resource) resource.command("path_to_script") generator = double('Chef::Util::DSC::ConfigurationGenerator') - generator.should_receive(:configuration_document_from_script_path) + expect(generator).to receive(:configuration_document_from_script_path) allow(Chef::Util::DSC::ConfigurationGenerator).to receive(:new).and_return(generator) provider.send(:generate_configuration_document, 'tmp', nil) end @@ -91,7 +91,7 @@ describe Chef::Provider::DscScript do allow(provider).to receive(:load_current_resource) resource.code("ImADSCResource{}") generator = double('Chef::Util::DSC::ConfigurationGenerator') - generator.should_receive(:configuration_document_from_script_code) + expect(generator).to receive(:configuration_document_from_script_code) allow(Chef::Util::DSC::ConfigurationGenerator).to receive(:new).and_return(generator) provider.send(:generate_configuration_document, 'tmp', nil) end @@ -99,7 +99,7 @@ describe Chef::Provider::DscScript do it 'should noop if neither code or command are provided' do allow(provider).to receive(:load_current_resource) generator = double('Chef::Util::DSC::ConfigurationGenerator') - generator.should_receive(:configuration_document_from_script_code).with('', anything(), anything()) + expect(generator).to receive(:configuration_document_from_script_code).with('', anything(), anything()) allow(Chef::Util::DSC::ConfigurationGenerator).to receive(:new).and_return(generator) provider.send(:generate_configuration_document, 'tmp', nil) end @@ -112,14 +112,14 @@ describe Chef::Provider::DscScript do allow(provider).to receive(:run_configuration).with(:set) provider.run_action(:run) - resource.should be_updated + expect(resource).to be_updated end it 'should not converge if the script is already converged' do allow(provider).to receive(:run_configuration).with(:test).and_return([]) provider.run_action(:run) - resource.should_not be_updated + expect(resource).not_to be_updated end end @@ -127,19 +127,19 @@ describe Chef::Provider::DscScript do it 'removes the resource name from the beginning of any log line from the LCM' do dsc_resource_info = Chef::Util::DSC::ResourceInfo.new('resourcename', true, ['resourcename doing something', 'lastline']) provider.instance_variable_set('@dsc_resources_info', [dsc_resource_info]) - provider.send(:generate_description)[1].should match(/converge DSC resource resourcename by doing something/) + expect(provider.send(:generate_description)[1]).to match(/converge DSC resource resourcename by doing something/) end it 'ignores the last line' do dsc_resource_info = Chef::Util::DSC::ResourceInfo.new('resourcename', true, ['resourcename doing something', 'lastline']) provider.instance_variable_set('@dsc_resources_info', [dsc_resource_info]) - provider.send(:generate_description)[1].should_not match(/lastline/) + expect(provider.send(:generate_description)[1]).not_to match(/lastline/) end it 'reports a dsc resource has not been changed if the LCM reported no change was required' do dsc_resource_info = Chef::Util::DSC::ResourceInfo.new('resourcename', false, ['resourcename does nothing', 'lastline']) provider.instance_variable_set('@dsc_resources_info', [dsc_resource_info]) - provider.send(:generate_description)[1].should match(/converge DSC resource resourcename by doing nothing/) + expect(provider.send(:generate_description)[1]).to match(/converge DSC resource resourcename by doing nothing/) end end end diff --git a/spec/unit/provider/env/windows_spec.rb b/spec/unit/provider/env/windows_spec.rb index 84582d8b4d..99f33d392a 100644 --- a/spec/unit/provider/env/windows_spec.rb +++ b/spec/unit/provider/env/windows_spec.rb @@ -31,7 +31,7 @@ describe Chef::Provider::Env::Windows, :windows_only do } let(:provider) { provider = Chef::Provider::Env::Windows.new(new_resource, run_context) - provider.stub(:env_obj).and_return(double('null object').as_null_object) + allow(provider).to receive(:env_obj).and_return(double('null object').as_null_object) provider } @@ -53,7 +53,7 @@ describe Chef::Provider::Env::Windows, :windows_only do end it "should update the ruby ENV object when it updates the value" do - provider.should_receive(:requires_modify_or_create?).and_return(true) + expect(provider).to receive(:requires_modify_or_create?).and_return(true) new_resource.value("foobar") provider.action_modify expect(ENV['CHEF_WINDOWS_ENV_TEST']).to eql('foobar') @@ -83,7 +83,7 @@ describe Chef::Provider::Env::Windows, :windows_only do } let(:provider) { provider = Chef::Provider::Env::Windows.new(new_resource, run_context) - provider.stub(:env_obj).and_return(double('null object').as_null_object) + allow(provider).to receive(:env_obj).and_return(double('null object').as_null_object) provider } @@ -92,8 +92,8 @@ describe Chef::Provider::Env::Windows, :windows_only do end it "replaces Windows system variables" do - provider.should_receive(:requires_modify_or_create?).and_return(true) - provider.should_receive(:expand_path).with(system_root).and_return(system_root_value) + expect(provider).to receive(:requires_modify_or_create?).and_return(true) + expect(provider).to receive(:expand_path).with(system_root).and_return(system_root_value) provider.action_modify expect(ENV['PATH']).to eql(system_root_value) end diff --git a/spec/unit/provider/env_spec.rb b/spec/unit/provider/env_spec.rb index f8803f9bb6..22fed4b7ac 100644 --- a/spec/unit/provider/env_spec.rb +++ b/spec/unit/provider/env_spec.rb @@ -30,7 +30,7 @@ describe Chef::Provider::Env do end it "assumes the key_name exists by default" do - @provider.key_exists.should be_true + expect(@provider.key_exists).to be_true end describe "when loading the current status" do @@ -38,73 +38,73 @@ describe Chef::Provider::Env do #@current_resource = @new_resource.clone #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) + allow(@provider).to receive(:env_value).with("FOO").and_return("bar") + allow(@provider).to receive(:env_key_exists).and_return(true) end it "should create a current resource with the same name as the new resource" do @provider.load_current_resource - @provider.new_resource.name.should == "FOO" + expect(@provider.new_resource.name).to eq("FOO") end it "should set the key_name to the key name of the new resource" do @provider.load_current_resource - @provider.current_resource.key_name.should == "FOO" + expect(@provider.current_resource.key_name).to eq("FOO") end it "should check if the key_name exists" do - @provider.should_receive(:env_key_exists).with("FOO").and_return(true) + expect(@provider).to receive(:env_key_exists).with("FOO").and_return(true) @provider.load_current_resource - @provider.key_exists.should be_true + expect(@provider.key_exists).to be_true end it "should flip the value of exists if the key does not exist" do - @provider.should_receive(:env_key_exists).with("FOO").and_return(false) + expect(@provider).to receive(:env_key_exists).with("FOO").and_return(false) @provider.load_current_resource - @provider.key_exists.should be_false + expect(@provider.key_exists).to be_false end it "should return the current resource" do - @provider.load_current_resource.should be_a_kind_of(Chef::Resource::Env) + expect(@provider.load_current_resource).to be_a_kind_of(Chef::Resource::Env) end end describe "action_create" do before do @provider.key_exists = false - @provider.stub(:create_env).and_return(true) - @provider.stub(:modify_env).and_return(true) + allow(@provider).to receive(:create_env).and_return(true) + allow(@provider).to receive(:modify_env).and_return(true) end it "should call create_env if the key does not exist" do - @provider.should_receive(:create_env).and_return(true) + expect(@provider).to receive(:create_env).and_return(true) @provider.action_create end it "should set the new_resources updated flag when it creates the key" do @provider.action_create - @new_resource.should be_updated + expect(@new_resource).to be_updated end it "should check to see if the values are the same if the key exists" do @provider.key_exists = true - @provider.should_receive(:requires_modify_or_create?).and_return(false) + expect(@provider).to receive(:requires_modify_or_create?).and_return(false) @provider.action_create end it "should call modify_env if the key exists and values are not equal" do @provider.key_exists = true - @provider.stub(:requires_modify_or_create?).and_return(true) - @provider.should_receive(:modify_env).and_return(true) + allow(@provider).to receive(:requires_modify_or_create?).and_return(true) + expect(@provider).to 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(:requires_modify_or_create?).and_return(true) - @provider.stub(:modify_env).and_return(true) + allow(@provider).to receive(:requires_modify_or_create?).and_return(true) + allow(@provider).to receive(:modify_env).and_return(true) @provider.action_create - @new_resource.should be_updated + expect(@new_resource).to be_updated end end @@ -112,30 +112,30 @@ 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) + allow(@provider).to receive(:delete_element).and_return(false) + allow(@provider).to receive(:delete_env).and_return(true) end it "should not call delete_env if the key does not exist" do - @provider.should_not_receive(:delete_env) + expect(@provider).not_to receive(:delete_env) @provider.action_delete end it "should not call delete_element if the key does not exist" do - @provider.should_not_receive(:delete_element) + expect(@provider).not_to receive(:delete_element) @provider.action_delete end it "should call delete_env if the key exists" do @provider.key_exists = true - @provider.should_receive(:delete_env) + expect(@provider).to receive(:delete_env) @provider.action_delete end it "should set the new_resources updated flag to true if the key is deleted" do @provider.key_exists = true @provider.action_delete - @new_resource.should be_updated + expect(@new_resource).to be_updated end end @@ -143,31 +143,31 @@ describe Chef::Provider::Env do before(:each) do @provider.current_resource = @current_resource @provider.key_exists = true - @provider.stub(:modify_env).and_return(true) + allow(@provider).to receive(:modify_env).and_return(true) end it "should call modify_group if the key exists and values are not equal" do - @provider.should_receive(:requires_modify_or_create?).and_return(true) - @provider.should_receive(:modify_env).and_return(true) + expect(@provider).to receive(:requires_modify_or_create?).and_return(true) + expect(@provider).to receive(:modify_env).and_return(true) @provider.action_modify end it "should set the new resources updated flag to true if modify_env is called" do - @provider.stub(:requires_modify_or_create?).and_return(true) - @provider.stub(:modify_env).and_return(true) + allow(@provider).to receive(:requires_modify_or_create?).and_return(true) + allow(@provider).to receive(:modify_env).and_return(true) @provider.action_modify - @new_resource.should be_updated + expect(@new_resource).to be_updated end it "should not call modify_env if the key exists but the values are equal" do - @provider.should_receive(:requires_modify_or_create?).and_return(false) - @provider.should_not_receive(:modify_env) + expect(@provider).to receive(:requires_modify_or_create?).and_return(false) + expect(@provider).not_to receive(:modify_env) @provider.action_modify end it "should raise a Chef::Exceptions::Env if the key doesn't exist" do @provider.key_exists = false - lambda { @provider.action_modify }.should raise_error(Chef::Exceptions::Env) + expect { @provider.action_modify }.to raise_error(Chef::Exceptions::Env) end end @@ -183,41 +183,41 @@ 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") - @provider.delete_element.should eql(true) + allow(@new_resource).to receive(:value).and_return("C:/baz/bin") + expect(@provider.delete_element).to eql(true) end it "should return false if the delim not defined" do - @new_resource.stub(:delim).and_return(nil) - @provider.delete_element.should eql(false) + allow(@new_resource).to receive(:delim).and_return(nil) + expect(@provider.delete_element).to eql(false) end it "should return true if the element is deleted" do @new_resource.value("C:/foo/bin") - @provider.should_receive(:create_env) - @provider.delete_element.should eql(true) - @new_resource.should be_updated + expect(@provider).to receive(:create_env) + expect(@provider.delete_element).to eql(true) + expect(@new_resource).to be_updated end context "when new_resource's value contains the delimiter" do it "should return false if all the elements are deleted" do # This indicates that the entire key needs to be deleted @new_resource.value("C:/foo/bin;C:/bar/bin") - @provider.delete_element.should eql(false) - @new_resource.should_not be_updated # This will be updated in action_delete + expect(@provider.delete_element).to eql(false) + expect(@new_resource).not_to be_updated # This will be updated in action_delete end it "should return true if any, but not all, of the elements are deleted" do @new_resource.value("C:/foo/bin;C:/notbaz/bin") - @provider.should_receive(:create_env) - @provider.delete_element.should eql(true) - @new_resource.should be_updated + expect(@provider).to receive(:create_env) + expect(@provider.delete_element).to eql(true) + expect(@new_resource).to be_updated end it "should return true if none of the elements are deleted" do @new_resource.value("C:/notfoo/bin;C:/notbaz/bin") - @provider.delete_element.should eql(true) - @new_resource.should_not be_updated + expect(@provider.delete_element).to eql(true) + expect(@new_resource).not_to be_updated end end end @@ -230,25 +230,25 @@ describe Chef::Provider::Env do end it "should return false if the values are equal" do - @provider.requires_modify_or_create?.should be_false + expect(@provider.requires_modify_or_create?).to be_false end it "should return true if the values not are equal" do @new_resource.value("C:/elsewhere") - @provider.requires_modify_or_create?.should be_true + expect(@provider.requires_modify_or_create?).to be_true end it "should return false if the current value contains the element" do @new_resource.delim(";") @current_resource.value("C:/bar;C:/foo;C:/baz") - @provider.requires_modify_or_create?.should be_false + expect(@provider.requires_modify_or_create?).to be_false end it "should return true if the current value does not contain the element" do @new_resource.delim(";") @current_resource.value("C:/biz;C:/foo/bin;C:/baz") - @provider.requires_modify_or_create?.should be_true + expect(@provider.requires_modify_or_create?).to be_true end context "when new_resource's value contains the delimiter" do @@ -256,21 +256,21 @@ describe Chef::Provider::Env do @new_resource.value("C:/biz;C:/baz") @new_resource.delim(";") @current_resource.value("C:/biz;C:/foo/bin;C:/baz") - @provider.requires_modify_or_create?.should be_false + expect(@provider.requires_modify_or_create?).to be_false end it "should return true if any of the new values are not contained" do @new_resource.value("C:/biz;C:/baz;C:/bin") @new_resource.delim(";") @current_resource.value("C:/biz;C:/foo/bin;C:/baz") - @provider.requires_modify_or_create?.should be_true + expect(@provider.requires_modify_or_create?).to be_true end end end describe "modify_env" do before(:each) do - @provider.stub(:create_env).and_return(true) + allow(@provider).to receive(:create_env).and_return(true) @new_resource.delim ";" @current_resource = Chef::Resource::Env.new("FOO") @@ -283,7 +283,7 @@ describe Chef::Provider::Env do passed_value = new_value.dup @new_resource.value(passed_value) @provider.modify_env - passed_value.should == new_value + expect(passed_value).to eq(new_value) end it "should only add values not already contained when a delimiter is provided" do @@ -291,7 +291,7 @@ describe Chef::Provider::Env do @new_resource.delim(";") @current_resource.value("C:/foo/bar;C:/bar;C:/baz") @provider.modify_env - @new_resource.value.should eq("C:/foo;C:/foo/bar;C:/bar;C:/baz") + expect(@new_resource.value).to eq("C:/foo;C:/foo/bar;C:/bar;C:/baz") end end end diff --git a/spec/unit/provider/erl_call_spec.rb b/spec/unit/provider/erl_call_spec.rb index 19e16f282f..2fb7e5b737 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) + allow(@provider).to receive(:popen4).and_return(@status) @stdin = StringIO.new @stdout = StringIO.new('{ok, woohoo}') @stderr = StringIO.new @@ -40,11 +40,11 @@ describe Chef::Provider::ErlCall do it "should return a Chef::Provider::ErlCall object" do provider = Chef::Provider::ErlCall.new(@new_resource, @run_context) - provider.should be_a_kind_of(Chef::Provider::ErlCall) + expect(provider).to be_a_kind_of(Chef::Provider::ErlCall) end it "should return true" do - @provider.load_current_resource.should eql(true) + expect(@provider.load_current_resource).to eql(true) end describe "when running a distributed erl call resource" do @@ -56,12 +56,12 @@ describe Chef::Provider::ErlCall do it "should write to stdin of the erl_call command" do expected_cmd = "erl_call -e -s -sname chef@localhost -c nomnomnom" - @provider.should_receive(:popen4).with(expected_cmd, :waitlast => true).and_return([@pid, @stdin, @stdout, @stderr]) - Process.should_receive(:wait).with(@pid) + expect(@provider).to receive(:popen4).with(expected_cmd, :waitlast => true).and_return([@pid, @stdin, @stdout, @stderr]) + expect(Process).to receive(:wait).with(@pid) @provider.action_run - @stdin.string.should == "#{@new_resource.code}\n" + expect(@stdin.string).to eq("#{@new_resource.code}\n") end end @@ -73,12 +73,12 @@ describe Chef::Provider::ErlCall do end it "should write to stdin of the erl_call command" do - @provider.should_receive(:popen4).with("erl_call -e -name chef@localhost ", :waitlast => true).and_return([@pid, @stdin, @stdout, @stderr]) - Process.should_receive(:wait).with(@pid) + expect(@provider).to receive(:popen4).with("erl_call -e -name chef@localhost ", :waitlast => true).and_return([@pid, @stdin, @stdout, @stderr]) + expect(Process).to receive(:wait).with(@pid) @provider.action_run - @stdin.string.should == "#{@new_resource.code}\n" + expect(@stdin.string).to eq("#{@new_resource.code}\n") end end diff --git a/spec/unit/provider/execute_spec.rb b/spec/unit/provider/execute_spec.rb index 6aa48f1e2a..ea16d8cf54 100644 --- a/spec/unit/provider/execute_spec.rb +++ b/spec/unit/provider/execute_spec.rb @@ -33,7 +33,7 @@ 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) + allow(STDOUT).to receive(:tty?).and_return(true) end let(:opts) do @@ -47,59 +47,59 @@ describe Chef::Provider::Execute do end it "should execute foo_resource" do - @provider.stub(:load_current_resource) - @provider.should_receive(:shell_out!).with(@new_resource.command, opts) - @provider.should_receive(:converge_by).with("execute foo_resource").and_call_original - Chef::Log.should_not_receive(:warn) + allow(@provider).to receive(:load_current_resource) + expect(@provider).to receive(:shell_out!).with(@new_resource.command, opts) + expect(@provider).to receive(:converge_by).with("execute foo_resource").and_call_original + expect(Chef::Log).not_to receive(:warn) @provider.run_action(:run) - @new_resource.should be_updated + expect(@new_resource).to be_updated end it "should honor sensitive attribute" do @new_resource.sensitive true @provider = Chef::Provider::Execute.new(@new_resource, @run_context) - @provider.stub(:load_current_resource) + allow(@provider).to receive(:load_current_resource) # Since the resource is sensitive, it should not have :live_stream set - @provider.should_receive(:shell_out!).with(@new_resource.command, opts.reject { |k| k == :live_stream }) - Chef::Log.should_not_receive(:warn) - @provider.should_receive(:converge_by).with("execute sensitive resource").and_call_original + expect(@provider).to receive(:shell_out!).with(@new_resource.command, opts.reject { |k| k == :live_stream }) + expect(Chef::Log).not_to receive(:warn) + expect(@provider).to receive(:converge_by).with("execute sensitive resource").and_call_original @provider.run_action(:run) - @new_resource.should be_updated + expect(@new_resource).to be_updated end it "should do nothing if the sentinel file exists" do - @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) + allow(@provider).to receive(:load_current_resource) + expect(File).to receive(:exists?).with(@new_resource.creates).and_return(true) + expect(@provider).not_to receive(:shell_out!) + expect(Chef::Log).not_to receive(:warn) @provider.run_action(:run) - @new_resource.should_not be_updated + expect(@new_resource).not_to be_updated end it "should respect cwd options for 'creates'" do @new_resource.cwd "/tmp" @new_resource.creates "foo_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) - @provider.should_not_receive(:shell_out!) + allow(@provider).to receive(:load_current_resource) + expect(File).to receive(:exists?).with(@new_resource.creates).and_return(false) + expect(File).to receive(:exists?).with(File.join("/tmp", @new_resource.creates)).and_return(true) + expect(Chef::Log).not_to receive(:warn) + expect(@provider).not_to receive(:shell_out!) @provider.run_action(:run) - @new_resource.should_not be_updated + expect(@new_resource).not_to be_updated end it "should warn if user specified relative path without cwd" do @new_resource.creates "foo_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!) + allow(@provider).to receive(:load_current_resource) + expect(Chef::Log).to receive(:warn).with(/relative path/) + expect(File).to receive(:exists?).with(@new_resource.creates).and_return(true) + expect(@provider).not_to receive(:shell_out!) @provider.run_action(:run) - @new_resource.should_not be_updated + expect(@new_resource).not_to be_updated end end diff --git a/spec/unit/provider/file/content_spec.rb b/spec/unit/provider/file/content_spec.rb index 34d98b6619..0f2fd6632c 100644 --- a/spec/unit/provider/file/content_spec.rb +++ b/spec/unit/provider/file/content_spec.rb @@ -53,27 +53,27 @@ 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") + allow(new_resource).to receive(: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 - content.tempfile.should be_a_kind_of(Tempfile) + expect(content.tempfile).to be_a_kind_of(Tempfile) end it "the tempfile contents should match the resource contents" do - IO.read(content.tempfile.path).should == new_resource.content + expect(IO.read(content.tempfile.path)).to eq(new_resource.content) end it "returns a tempfile in the tempdir when :file_staging_uses_destdir is not set" do Chef::Config[:file_staging_uses_destdir] = false - content.tempfile.path.start_with?(Dir::tmpdir).should be_true - canonicalize_path(content.tempfile.path).start_with?(enclosing_directory).should be_false + expect(content.tempfile.path.start_with?(Dir::tmpdir)).to be_true + expect(canonicalize_path(content.tempfile.path).start_with?(enclosing_directory)).to be_false end it "returns a tempfile in the destdir when :file_desployment_uses_destdir is not set" do Chef::Config[:file_staging_uses_destdir] = true - content.tempfile.path.start_with?(Dir::tmpdir).should be_false - canonicalize_path(content.tempfile.path).start_with?(enclosing_directory).should be_true + expect(content.tempfile.path.start_with?(Dir::tmpdir)).to be_false + expect(canonicalize_path(content.tempfile.path).start_with?(enclosing_directory)).to be_true end end @@ -81,11 +81,11 @@ 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) + allow(new_resource).to receive(:content).and_return(nil) end it "should return nil instead of a tempfile" do - content.tempfile.should be_nil + expect(content.tempfile).to be_nil end end diff --git a/spec/unit/provider/file_spec.rb b/spec/unit/provider/file_spec.rb index 059f1722fb..504ae045d9 100644 --- a/spec/unit/provider/file_spec.rb +++ b/spec/unit/provider/file_spec.rb @@ -46,7 +46,7 @@ describe Chef::Provider::File do let(:provider) do provider = described_class.new(resource, run_context) - provider.stub(:content).and_return(content) + allow(provider).to receive(:content).and_return(content) provider end diff --git a/spec/unit/provider/git_spec.rb b/spec/unit/provider/git_spec.rb index 02d155efbd..bfbf531389 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) + allow(STDOUT).to receive(:tty?).and_return(true) Chef::Log.level = :info @current_resource = Chef::Resource::Git.new("web2.0 app") @@ -47,36 +47,36 @@ describe Chef::Provider::Git do end it "sets the current revision to nil if the deploy dir does not exist" do - ::File.should_receive(:exist?).with("/my/deploy/dir/.git").and_return(false) - @provider.find_current_revision.should be_nil + expect(::File).to receive(:exist?).with("/my/deploy/dir/.git").and_return(false) + expect(@provider.find_current_revision).to be_nil end it "determines the current revision when there is one" do - ::File.should_receive(:exist?).with("/my/deploy/dir/.git").and_return(true) + expect(::File).to receive(:exist?).with("/my/deploy/dir/.git").and_return(true) @stdout = "9b4d8dc38dd471246e7cfb1c3c1ad14b0f2bee13\n" - @provider.should_receive(:shell_out!).with('git rev-parse HEAD', {:cwd => '/my/deploy/dir', :returns => [0,128]}).and_return(double("ShellOut result", :stdout => @stdout)) - @provider.find_current_revision.should eql("9b4d8dc38dd471246e7cfb1c3c1ad14b0f2bee13") + expect(@provider).to receive(:shell_out!).with('git rev-parse HEAD', {:cwd => '/my/deploy/dir', :returns => [0,128]}).and_return(double("ShellOut result", :stdout => @stdout)) + expect(@provider.find_current_revision).to eql("9b4d8dc38dd471246e7cfb1c3c1ad14b0f2bee13") end it "gives the current revision as nil when there is no current revision" do - ::File.should_receive(:exist?).with("/my/deploy/dir/.git").and_return(true) + expect(::File).to receive(:exist?).with("/my/deploy/dir/.git").and_return(true) @stderr = "fatal: Not a git repository (or any of the parent directories): .git" @stdout = "" - @provider.should_receive(:shell_out!).with('git rev-parse HEAD', :cwd => '/my/deploy/dir', :returns => [0,128]).and_return(double("ShellOut result", :stdout => "", :stderr => @stderr)) - @provider.find_current_revision.should be_nil + expect(@provider).to receive(:shell_out!).with('git rev-parse HEAD', :cwd => '/my/deploy/dir', :returns => [0,128]).and_return(double("ShellOut result", :stdout => "", :stderr => @stderr)) + expect(@provider.find_current_revision).to be_nil end end it "creates a current_resource with the currently deployed revision when a clone exists in the destination dir" do - @provider.stub(:find_current_revision).and_return("681c9802d1c62a45b490786c18f0b8216b309440") + allow(@provider).to receive(: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") + expect(@provider.current_resource.name).to eql(@resource.name) + expect(@provider.current_resource.revision).to eql("681c9802d1c62a45b490786c18f0b8216b309440") end it "keeps the node and resource passed to it on initialize" do - @provider.node.should equal(@node) - @provider.new_resource.should equal(@resource) + expect(@provider.node).to equal(@node) + expect(@provider.new_resource).to equal(@resource) end context "resolving revisions to a SHA" do @@ -86,15 +86,15 @@ describe Chef::Provider::Git do end it "returns resource.revision as is if revision is already a full SHA" do - @provider.target_revision.should eql("d35af14d41ae22b19da05d7d03a0bafc321b244c") + expect(@provider.target_revision).to eql("d35af14d41ae22b19da05d7d03a0bafc321b244c") end it "converts resource.revision from a tag to a SHA" do @resource.revision "v1.0" @stdout = ("d03c22a5e41f5ae3193460cca044ed1435029f53\trefs/heads/0.8-alpha\n" + "503c22a5e41f5ae3193460cca044ed1435029f53\trefs/heads/v1.0\n") - @provider.should_receive(:shell_out!).with(@git_ls_remote + "\"v1.0*\"", {:log_tag=>"git[web2.0 app]"}).and_return(double("ShellOut result", :stdout => @stdout)) - @provider.target_revision.should eql("503c22a5e41f5ae3193460cca044ed1435029f53") + expect(@provider).to receive(:shell_out!).with(@git_ls_remote + "\"v1.0*\"", {:log_tag=>"git[web2.0 app]"}).and_return(double("ShellOut result", :stdout => @stdout)) + expect(@provider.target_revision).to eql("503c22a5e41f5ae3193460cca044ed1435029f53") end it "converts resource.revision from an annotated tag to the tagged SHA (not SHA of tag)" do @@ -102,8 +102,8 @@ describe Chef::Provider::Git do @stdout = ("d03c22a5e41f5ae3193460cca044ed1435029f53\trefs/heads/0.8-alpha\n" + "503c22a5e41f5ae3193460cca044ed1435029f53\trefs/heads/v1.0\n" + "663c22a5e41f5ae3193460cca044ed1435029f53\trefs/heads/v1.0^{}\n") - @provider.should_receive(:shell_out!).with(@git_ls_remote + "\"v1.0*\"", {:log_tag=>"git[web2.0 app]"}).and_return(double("ShellOut result", :stdout => @stdout)) - @provider.target_revision.should eql("663c22a5e41f5ae3193460cca044ed1435029f53") + expect(@provider).to receive(:shell_out!).with(@git_ls_remote + "\"v1.0*\"", {:log_tag=>"git[web2.0 app]"}).and_return(double("ShellOut result", :stdout => @stdout)) + expect(@provider.target_revision).to eql("663c22a5e41f5ae3193460cca044ed1435029f53") end it "converts resource.revision from a tag to a SHA using an exact match" do @@ -111,8 +111,8 @@ describe Chef::Provider::Git do @stdout = ("d03c22a5e41f5ae3193460cca044ed1435029f53\trefs/heads/0.8-alpha\n" + "663c22a5e41f5ae3193460cca044ed1435029f53\trefs/tags/releases/v1.0\n" + "503c22a5e41f5ae3193460cca044ed1435029f53\trefs/tags/v1.0\n") - @provider.should_receive(:shell_out!).with(@git_ls_remote + "\"v1.0*\"", {:log_tag=>"git[web2.0 app]"}).and_return(double("ShellOut result", :stdout => @stdout)) - @provider.target_revision.should eql("503c22a5e41f5ae3193460cca044ed1435029f53") + expect(@provider).to receive(:shell_out!).with(@git_ls_remote + "\"v1.0*\"", {:log_tag=>"git[web2.0 app]"}).and_return(double("ShellOut result", :stdout => @stdout)) + expect(@provider.target_revision).to eql("503c22a5e41f5ae3193460cca044ed1435029f53") end it "converts resource.revision from a tag to a SHA, matching tags first, then heads" do @@ -120,8 +120,8 @@ describe Chef::Provider::Git do @stdout = ("d03c22a5e41f5ae3193460cca044ed1435029f53\trefs/heads/0.8-alpha\n" + "663c22a5e41f5ae3193460cca044ed1435029f53\trefs/tags/v1.0\n" + "503c22a5e41f5ae3193460cca044ed1435029f53\trefs/heads/v1.0\n") - @provider.should_receive(:shell_out!).with(@git_ls_remote + "\"v1.0*\"", {:log_tag=>"git[web2.0 app]"}).and_return(double("ShellOut result", :stdout => @stdout)) - @provider.target_revision.should eql("663c22a5e41f5ae3193460cca044ed1435029f53") + expect(@provider).to receive(:shell_out!).with(@git_ls_remote + "\"v1.0*\"", {:log_tag=>"git[web2.0 app]"}).and_return(double("ShellOut result", :stdout => @stdout)) + expect(@provider.target_revision).to eql("663c22a5e41f5ae3193460cca044ed1435029f53") end it "converts resource.revision from a tag to a SHA, matching heads if no tags match" do @@ -129,8 +129,8 @@ describe Chef::Provider::Git do @stdout = ("d03c22a5e41f5ae3193460cca044ed1435029f53\trefs/heads/0.8-alpha\n" + "663c22a5e41f5ae3193460cca044ed1435029f53\trefs/tags/v1.1\n" + "503c22a5e41f5ae3193460cca044ed1435029f53\trefs/heads/v1.0\n") - @provider.should_receive(:shell_out!).with(@git_ls_remote + "\"v1.0*\"", {:log_tag=>"git[web2.0 app]"}).and_return(double("ShellOut result", :stdout => @stdout)) - @provider.target_revision.should eql("503c22a5e41f5ae3193460cca044ed1435029f53") + expect(@provider).to receive(:shell_out!).with(@git_ls_remote + "\"v1.0*\"", {:log_tag=>"git[web2.0 app]"}).and_return(double("ShellOut result", :stdout => @stdout)) + expect(@provider.target_revision).to eql("503c22a5e41f5ae3193460cca044ed1435029f53") end it "converts resource.revision from a tag to a SHA, matching tags first, then heads, then revision" do @@ -139,8 +139,8 @@ describe Chef::Provider::Git do "663c22a5e41f5ae3193460cca044ed1435029f53\trefs/tags/v1.0\n" + "805c22a5e41f5ae3193460cca044ed1435029f53\trefs/pulls/v1.0\n" + "503c22a5e41f5ae3193460cca044ed1435029f53\trefs/heads/v1.0\n") - @provider.should_receive(:shell_out!).with(@git_ls_remote + "\"refs/pulls/v1.0*\"", {:log_tag=>"git[web2.0 app]"}).and_return(double("ShellOut result", :stdout => @stdout)) - @provider.target_revision.should eql("805c22a5e41f5ae3193460cca044ed1435029f53") + expect(@provider).to receive(:shell_out!).with(@git_ls_remote + "\"refs/pulls/v1.0*\"", {:log_tag=>"git[web2.0 app]"}).and_return(double("ShellOut result", :stdout => @stdout)) + expect(@provider.target_revision).to eql("805c22a5e41f5ae3193460cca044ed1435029f53") end it "converts resource.revision from a tag to a SHA, using full path if provided" do @@ -148,40 +148,40 @@ describe Chef::Provider::Git do @stdout = ("d03c22a5e41f5ae3193460cca044ed1435029f53\trefs/heads/0.8-alpha\n" + "663c22a5e41f5ae3193460cca044ed1435029f53\trefs/tags/v1.0\n" + "503c22a5e41f5ae3193460cca044ed1435029f53\trefs/heads/v1.0\n") - @provider.should_receive(:shell_out!).with(@git_ls_remote + "\"refs/heads/v1.0*\"", {:log_tag=>"git[web2.0 app]"}).and_return(double("ShellOut result", :stdout => @stdout)) - @provider.target_revision.should eql("503c22a5e41f5ae3193460cca044ed1435029f53") + expect(@provider).to receive(:shell_out!).with(@git_ls_remote + "\"refs/heads/v1.0*\"", {:log_tag=>"git[web2.0 app]"}).and_return(double("ShellOut result", :stdout => @stdout)) + expect(@provider.target_revision).to eql("503c22a5e41f5ae3193460cca044ed1435029f53") end it "raises an invalid remote reference error if you try to deploy from ``origin'' and assertions are run" do @resource.revision "origin/" @provider.action = :checkout @provider.define_resource_requirements - ::File.stub(:directory?).with("/my/deploy").and_return(true) - lambda {@provider.process_resource_requirements}.should raise_error(Chef::Exceptions::InvalidRemoteGitReference) + allow(::File).to receive(:directory?).with("/my/deploy").and_return(true) + expect {@provider.process_resource_requirements}.to raise_error(Chef::Exceptions::InvalidRemoteGitReference) end it "raises an unresolvable git reference error if the revision can't be resolved to any revision and assertions are run" do @resource.revision "FAIL, that's the revision I want" @provider.action = :checkout - @provider.should_receive(:shell_out!).and_return(double("ShellOut result", :stdout => "\n")) + expect(@provider).to receive(:shell_out!).and_return(double("ShellOut result", :stdout => "\n")) @provider.define_resource_requirements - lambda { @provider.process_resource_requirements }.should raise_error(Chef::Exceptions::UnresolvableGitReference) + expect { @provider.process_resource_requirements }.to raise_error(Chef::Exceptions::UnresolvableGitReference) end it "does not raise an error if the revision can't be resolved when assertions are not run" do @resource.revision "FAIL, that's the revision I want" - @provider.should_receive(:shell_out!).and_return(double("ShellOut result", :stdout => "\n")) - @provider.target_revision.should == nil + expect(@provider).to receive(:shell_out!).and_return(double("ShellOut result", :stdout => "\n")) + expect(@provider.target_revision).to eq(nil) end it "does not raise an error when the revision is valid and assertions are run." do @resource.revision "0.8-alpha" @stdout = "503c22a5e41f5ae3193460cca044ed1435029f53\trefs/heads/0.8-alpha\n" - @provider.should_receive(:shell_out!).with(@git_ls_remote + "\"0.8-alpha*\"", {:log_tag=>"git[web2.0 app]"}).and_return(double("ShellOut result", :stdout => @stdout)) + expect(@provider).to receive(:shell_out!).with(@git_ls_remote + "\"0.8-alpha*\"", {:log_tag=>"git[web2.0 app]"}).and_return(double("ShellOut result", :stdout => @stdout)) @provider.action = :checkout - ::File.stub(:directory?).with("/my/deploy").and_return(true) + allow(::File).to receive(:directory?).with("/my/deploy").and_return(true) @provider.define_resource_requirements - lambda { @provider.process_resource_requirements }.should_not raise_error + expect { @provider.process_resource_requirements }.not_to raise_error end it "gives the latest HEAD revision SHA if nothing is specified" do @@ -202,13 +202,13 @@ b7d19519a1c15f1c1a324e2683bd728b6198ce5a\trefs/tags/0.7.8^{} ebc1b392fe7e8f0fbabc305c299b4d365d2b4d9b\trefs/tags/chef-server-package SHAS @resource.revision '' - @provider.should_receive(:shell_out!).with(@git_ls_remote + "\"HEAD\"", {:log_tag=>"git[web2.0 app]"}).and_return(double("ShellOut result", :stdout => @stdout)) - @provider.target_revision.should eql("28af684d8460ba4793eda3e7ac238c864a5d029a") + expect(@provider).to receive(:shell_out!).with(@git_ls_remote + "\"HEAD\"", {:log_tag=>"git[web2.0 app]"}).and_return(double("ShellOut result", :stdout => @stdout)) + expect(@provider.target_revision).to eql("28af684d8460ba4793eda3e7ac238c864a5d029a") end end it "responds to :revision_slug as an alias for target_revision" do - @provider.should respond_to(:revision_slug) + expect(@provider).to respond_to(:revision_slug) end context "with an ssh wrapper" do @@ -225,11 +225,11 @@ 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")) + allow(Etc).to receive(: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 - @provider.should_receive(:shell_out!).with(expected_cmd, default_options) + expect(@provider).to receive(:shell_out!).with(expected_cmd, default_options) @provider.clone end end @@ -237,7 +237,7 @@ SHAS let (:seconds) { 10 } before { @resource.timeout(seconds) } it "clones a repo with amended git options" do - @provider.should_receive(:shell_out!).with(expected_cmd, default_options.merge(:timeout => seconds)) + expect(@provider).to receive(:shell_out!).with(expected_cmd, default_options.merge(:timeout => seconds)) @provider.clone end end @@ -257,7 +257,7 @@ SHAS end before { @resource.environment(override_home) } it "clones a repo with amended git options with specific home" do - @provider.should_receive(:shell_out!).with(expected_cmd, overrided_options) + expect(@provider).to receive(:shell_out!).with(expected_cmd, overrided_options) @provider.clone end end @@ -265,11 +265,11 @@ 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")) + allow(Etc).to receive(: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\"" - @provider.should_receive(:shell_out!).with(expected_cmd, :user => "deployNinja", + expect(@provider).to receive(:shell_out!).with(expected_cmd, :user => "deployNinja", :environment =>{"GIT_SSH"=>"do_it_this_way.sh", "HOME" => "/home/deployNinja"}, :log_tag => "git[web2.0 app]") @@ -280,10 +280,10 @@ SHAS @resource.depth 5 expected_cmd = "git clone --depth 5 \"git://github.com/opscode/chef.git\" \"/my/deploy/dir\"" version_response = double('shell_out') - version_response.stub(:stdout) { 'git version 1.7.9' } - @provider.should_receive(:shell_out!).with("git --version", + allow(version_response).to receive(:stdout) { 'git version 1.7.9' } + expect(@provider).to receive(:shell_out!).with("git --version", :log_tag => "git[web2.0 app]").and_return(version_response) - @provider.should_receive(:shell_out!).with(expected_cmd, :log_tag => "git[web2.0 app]") + expect(@provider).to receive(:shell_out!).with(expected_cmd, :log_tag => "git[web2.0 app]") @provider.clone end @@ -291,24 +291,24 @@ SHAS @resource.depth 5 expected_cmd = "git clone --depth 5 --no-single-branch \"git://github.com/opscode/chef.git\" \"/my/deploy/dir\"" version_response = double('shell_out') - version_response.stub(:stdout) { 'git version 1.7.10' } - @provider.should_receive(:shell_out!).with("git --version", + allow(version_response).to receive(:stdout) { 'git version 1.7.10' } + expect(@provider).to receive(:shell_out!).with("git --version", :log_tag => "git[web2.0 app]").and_return(version_response) - @provider.should_receive(:shell_out!).with(expected_cmd, :log_tag => "git[web2.0 app]") + expect(@provider).to receive(:shell_out!).with(expected_cmd, :log_tag => "git[web2.0 app]") @provider.clone end it "compiles a clone command with a remote other than ``origin''" do @resource.remote "opscode" expected_cmd = "git clone -o opscode \"git://github.com/opscode/chef.git\" \"/my/deploy/dir\"" - @provider.should_receive(:shell_out!).with(expected_cmd, :log_tag => "git[web2.0 app]") + expect(@provider).to receive(:shell_out!).with(expected_cmd, :log_tag => "git[web2.0 app]") @provider.clone end it "runs a checkout command with default options" do - @provider.should_receive(:shell_out!).with('git branch -f deploy d35af14d41ae22b19da05d7d03a0bafc321b244c', :cwd => "/my/deploy/dir", + expect(@provider).to receive(:shell_out!).with('git branch -f deploy d35af14d41ae22b19da05d7d03a0bafc321b244c', :cwd => "/my/deploy/dir", :log_tag => "git[web2.0 app]").ordered - @provider.should_receive(:shell_out!).with('git checkout deploy', :cwd => "/my/deploy/dir", + expect(@provider).to receive(:shell_out!).with('git checkout deploy', :cwd => "/my/deploy/dir", :log_tag => "git[web2.0 app]").ordered @provider.checkout end @@ -316,32 +316,32 @@ SHAS it "runs an enable_submodule command" do @resource.enable_submodules true expected_cmd = "git submodule sync" - @provider.should_receive(:shell_out!).with(expected_cmd, :cwd => "/my/deploy/dir", + expect(@provider).to receive(:shell_out!).with(expected_cmd, :cwd => "/my/deploy/dir", :log_tag => "git[web2.0 app]") expected_cmd = "git submodule update --init --recursive" - @provider.should_receive(:shell_out!).with(expected_cmd, :cwd => "/my/deploy/dir", :log_tag => "git[web2.0 app]") + expect(@provider).to receive(:shell_out!).with(expected_cmd, :cwd => "/my/deploy/dir", :log_tag => "git[web2.0 app]") @provider.enable_submodules end it "does nothing for enable_submodules if resource.enable_submodules #=> false" do - @provider.should_not_receive(:shell_out!) + expect(@provider).not_to receive(:shell_out!) @provider.enable_submodules end it "runs a sync command with default options" do - @provider.should_receive(:setup_remote_tracking_branches).with(@resource.remote, @resource.repository) + expect(@provider).to receive(:setup_remote_tracking_branches).with(@resource.remote, @resource.repository) expected_cmd = "git fetch origin && git fetch origin --tags && git reset --hard d35af14d41ae22b19da05d7d03a0bafc321b244c" - @provider.should_receive(:shell_out!).with(expected_cmd, :cwd=> "/my/deploy/dir", :log_tag => "git[web2.0 app]") + expect(@provider).to receive(:shell_out!).with(expected_cmd, :cwd=> "/my/deploy/dir", :log_tag => "git[web2.0 app]") @provider.fetch_updates end 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")) + allow(Etc).to receive(: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) + expect(@provider).to receive(:setup_remote_tracking_branches).with(@resource.remote, @resource.repository) expected_cmd = "git fetch origin && git fetch origin --tags && git reset --hard d35af14d41ae22b19da05d7d03a0bafc321b244c" - @provider.should_receive(:shell_out!).with(expected_cmd, :cwd => "/my/deploy/dir", + expect(@provider).to receive(:shell_out!).with(expected_cmd, :cwd => "/my/deploy/dir", :user => "whois", :group => "thisis", :log_tag => "git[web2.0 app]", :environment=>{"HOME"=>"/home/whois"}) @@ -350,17 +350,17 @@ SHAS it "configures remote tracking branches when remote is ``origin''" do @resource.remote "origin" - @provider.should_receive(:setup_remote_tracking_branches).with(@resource.remote, @resource.repository) + expect(@provider).to receive(:setup_remote_tracking_branches).with(@resource.remote, @resource.repository) fetch_command = "git fetch origin && git fetch origin --tags && git reset --hard d35af14d41ae22b19da05d7d03a0bafc321b244c" - @provider.should_receive(:shell_out!).with(fetch_command, :cwd => "/my/deploy/dir", :log_tag => "git[web2.0 app]") + expect(@provider).to receive(:shell_out!).with(fetch_command, :cwd => "/my/deploy/dir", :log_tag => "git[web2.0 app]") @provider.fetch_updates end it "configures remote tracking branches when remote is not ``origin''" do @resource.remote "opscode" - @provider.should_receive(:setup_remote_tracking_branches).with(@resource.remote, @resource.repository) + expect(@provider).to receive(:setup_remote_tracking_branches).with(@resource.remote, @resource.repository) fetch_command = "git fetch opscode && git fetch opscode --tags && git reset --hard d35af14d41ae22b19da05d7d03a0bafc321b244c" - @provider.should_receive(:shell_out!).with(fetch_command, :cwd => "/my/deploy/dir", :log_tag => "git[web2.0 app]") + expect(@provider).to receive(:shell_out!).with(fetch_command, :cwd => "/my/deploy/dir", :log_tag => "git[web2.0 app]") @provider.fetch_updates end @@ -368,14 +368,14 @@ SHAS it "checks if a remote with this name already exists" do command_response = double('shell_out') - command_response.stub(:exitstatus) { 1 } + allow(command_response).to receive(:exitstatus) { 1 } expected_command = "git config --get remote.#{@resource.remote}.url" - @provider.should_receive(:shell_out!).with(expected_command, + expect(@provider).to receive(:shell_out!).with(expected_command, :cwd => "/my/deploy/dir", :log_tag => "git[web2.0 app]", :returns => [0,1,2]).and_return(command_response) add_remote_command = "git remote add #{@resource.remote} #{@resource.repository}" - @provider.should_receive(:shell_out!).with(add_remote_command, + expect(@provider).to receive(:shell_out!).with(add_remote_command, :cwd => "/my/deploy/dir", :log_tag => "git[web2.0 app]") @provider.setup_remote_tracking_branches(@resource.remote, @resource.repository) @@ -384,11 +384,11 @@ 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")) + allow(Etc).to receive(:getpwnam).and_return(double("Struct::Passwd", :name => @resource.user, :dir => "/home/whois")) command_response = double('shell_out') - command_response.stub(:exitstatus) { 1 } + allow(command_response).to receive(:exitstatus) { 1 } expected_command = "git config --get remote.#{@resource.remote}.url" - @provider.should_receive(:shell_out!).with(expected_command, + expect(@provider).to receive(:shell_out!).with(expected_command, :cwd => "/my/deploy/dir", :log_tag => "git[web2.0 app]", :user => "whois", @@ -396,7 +396,7 @@ SHAS :environment=>{"HOME"=>"/home/whois"}, :returns => [0,1,2]).and_return(command_response) add_remote_command = "git remote add #{@resource.remote} #{@resource.repository}" - @provider.should_receive(:shell_out!).with(add_remote_command, + expect(@provider).to receive(:shell_out!).with(add_remote_command, :cwd => "/my/deploy/dir", :log_tag => "git[web2.0 app]", :user => "whois", @@ -408,14 +408,14 @@ SHAS describe "when a remote with a given name hasn't been configured yet" do it "adds a new remote " do command_response = double('shell_out') - command_response.stub(:exitstatus) { 1 } + allow(command_response).to receive(:exitstatus) { 1 } check_remote_command = "git config --get remote.#{@resource.remote}.url" - @provider.should_receive(:shell_out!).with(check_remote_command, + expect(@provider).to receive(:shell_out!).with(check_remote_command, :cwd => "/my/deploy/dir", :log_tag => "git[web2.0 app]", :returns => [0,1,2]).and_return(command_response) expected_command = "git remote add #{@resource.remote} #{@resource.repository}" - @provider.should_receive(:shell_out!).with(expected_command, + expect(@provider).to receive(:shell_out!).with(expected_command, :cwd => "/my/deploy/dir", :log_tag => "git[web2.0 app]") @provider.setup_remote_tracking_branches(@resource.remote, @resource.repository) @@ -425,15 +425,15 @@ SHAS describe "when a remote with a given name has already been configured" do it "updates remote url when the url is different" do command_response = double('shell_out') - command_response.stub(:exitstatus) { 0 } - command_response.stub(:stdout) { "some_other_url" } + allow(command_response).to receive(:exitstatus) { 0 } + allow(command_response).to receive(:stdout) { "some_other_url" } check_remote_command = "git config --get remote.#{@resource.remote}.url" - @provider.should_receive(:shell_out!).with(check_remote_command, + expect(@provider).to receive(:shell_out!).with(check_remote_command, :cwd => "/my/deploy/dir", :log_tag => "git[web2.0 app]", :returns => [0,1,2]).and_return(command_response) expected_command = "git config --replace-all remote.#{@resource.remote}.url #{@resource.repository}" - @provider.should_receive(:shell_out!).with(expected_command, + expect(@provider).to receive(:shell_out!).with(expected_command, :cwd => "/my/deploy/dir", :log_tag => "git[web2.0 app]") @provider.setup_remote_tracking_branches(@resource.remote, @resource.repository) @@ -441,15 +441,15 @@ SHAS it "doesn't update remote url when the url is the same" do command_response = double('shell_out') - command_response.stub(:exitstatus) { 0 } - command_response.stub(:stdout) { @resource.repository } + allow(command_response).to receive(:exitstatus) { 0 } + allow(command_response).to receive(:stdout) { @resource.repository } check_remote_command = "git config --get remote.#{@resource.remote}.url" - @provider.should_receive(:shell_out!).with(check_remote_command, + expect(@provider).to receive(:shell_out!).with(check_remote_command, :cwd => "/my/deploy/dir", :log_tag => "git[web2.0 app]", :returns => [0,1,2]).and_return(command_response) unexpected_command = "git config --replace-all remote.#{@resource.remote}.url #{@resource.repository}" - @provider.should_not_receive(:shell_out!).with(unexpected_command, + expect(@provider).not_to receive(:shell_out!).with(unexpected_command, :cwd => "/my/deploy/dir", :log_tag => "git[web2.0 app]") @provider.setup_remote_tracking_branches(@resource.remote, @resource.repository) @@ -457,14 +457,14 @@ SHAS it "resets remote url when it has multiple values" do command_response = double('shell_out') - command_response.stub(:exitstatus) { 2 } + allow(command_response).to receive(:exitstatus) { 2 } check_remote_command = "git config --get remote.#{@resource.remote}.url" - @provider.should_receive(:shell_out!).with(check_remote_command, + expect(@provider).to receive(:shell_out!).with(check_remote_command, :cwd => "/my/deploy/dir", :log_tag => "git[web2.0 app]", :returns => [0,1,2]).and_return(command_response) expected_command = "git config --replace-all remote.#{@resource.remote}.url #{@resource.repository}" - @provider.should_receive(:shell_out!).with(expected_command, + expect(@provider).to receive(:shell_out!).with(expected_command, :cwd => "/my/deploy/dir", :log_tag => "git[web2.0 app]") @provider.setup_remote_tracking_branches(@resource.remote, @resource.repository) @@ -473,20 +473,20 @@ 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!) - lambda {@provider.run_action(:sync)}.should raise_error(Chef::Exceptions::MissingParentDirectory) + allow(@provider).to receive(:shell_out!) + expect {@provider.run_action(:sync)}.to 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").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) + allow(::File).to receive(:exist?).with("/my/deploy/dir/.git").and_return(false) + + allow(::File).to receive(:exist?).with("/my/deploy/dir").and_return(true) + allow(::File).to receive(:directory?).with("/my/deploy").and_return(true) + allow(::Dir).to receive(:entries).with("/my/deploy/dir").and_return(['.','..']) + expect(@provider).to receive(:clone) + expect(@provider).to receive(:checkout) + expect(@provider).to receive(:enable_submodules) @provider.run_action(:checkout) # Even though an actual run will cause an update to occur, the fact that we've stubbed out # the actions above will prevent updates from registering @@ -495,119 +495,119 @@ 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) + allow(::File).to receive(: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(['.','..']) + allow(::File).to receive(:exist?).with("/my/deploy/dir").and_return(true) + allow(::File).to receive(:directory?).with("/my/deploy").and_return(true) + allow(::Dir).to receive(:entries).with("/my/deploy/dir").and_return(['.','..']) @resource.enable_checkout false - @provider.should_receive(:clone) - @provider.should_not_receive(:checkout) - @provider.should_receive(:enable_submodules) + expect(@provider).to receive(:clone) + expect(@provider).not_to receive(:checkout) + expect(@provider).to receive(:enable_submodules) @provider.run_action(:checkout) end # 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(['..','.']) - @provider.should_receive(:clone) - @provider.should_receive(:checkout) - @provider.should_receive(:enable_submodules) - @provider.should_receive(:add_remotes) + allow(::File).to receive(:exist?).with("/my/deploy/dir/.git").and_return(false) + allow(::File).to receive(:exist?).with("/my/deploy/dir").and_return(false) + allow(::File).to receive(:directory?).with("/my/deploy").and_return(true) + allow(::Dir).to receive(:entries).with("/my/deploy/dir").and_return(['..','.']) + expect(@provider).to receive(:clone) + expect(@provider).to receive(:checkout) + expect(@provider).to receive(:enable_submodules) + expect(@provider).to receive(:add_remotes) @provider.run_action(:checkout) # @resource.should be_updated end 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").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) - @provider.should_not_receive(:add_remotes) + allow(::File).to receive(:exist?).with("/my/deploy/dir/.git").and_return(false) + + allow(::File).to receive(:exist?).with("/my/deploy/dir").and_return(true) + allow(::File).to receive(:directory?).with("/my/deploy").and_return(true) + allow(::Dir).to receive(:entries).with("/my/deploy/dir").and_return(['.','..','foo','bar']) + expect(@provider).not_to receive(:clone) + expect(@provider).not_to receive(:checkout) + expect(@provider).not_to receive(:enable_submodules) + expect(@provider).not_to receive(:add_remotes) @provider.run_action(:checkout) - @resource.should_not be_updated + expect(@resource).not_to be_updated end 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) - @provider.should_receive(:find_current_revision).exactly(1).and_return('d35af14d41ae22b19da05d7d03a0bafc321b244c') - @provider.should_not_receive(:fetch_updates) - @provider.should_receive(:add_remotes) + expect(::File).to receive(:exist?).with("/my/deploy/dir/.git").and_return(true) + allow(::File).to receive(:directory?).with("/my/deploy").and_return(true) + expect(@provider).to receive(:find_current_revision).exactly(1).and_return('d35af14d41ae22b19da05d7d03a0bafc321b244c') + expect(@provider).not_to receive(:fetch_updates) + expect(@provider).to receive(:add_remotes) @provider.run_action(:sync) - @resource.should_not be_updated + expect(@resource).not_to be_updated end 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) + expect(::File).to receive(:exist?).with("/my/deploy/dir/.git").and_return(true) + allow(::File).to receive(:directory?).with("/my/deploy").and_return(true) # invoked twice - first time from load_current_resource - @provider.should_receive(:find_current_revision).exactly(1).and_return('d35af14d41ae22b19da05d7d03a0bafc321b244c') - @provider.stub(:target_revision).and_return('28af684d8460ba4793eda3e7ac238c864a5d029a') - @provider.should_receive(:fetch_updates) - @provider.should_receive(:enable_submodules) - @provider.should_receive(:add_remotes) + expect(@provider).to receive(:find_current_revision).exactly(1).and_return('d35af14d41ae22b19da05d7d03a0bafc321b244c') + allow(@provider).to receive(:target_revision).and_return('28af684d8460ba4793eda3e7ac238c864a5d029a') + expect(@provider).to receive(:fetch_updates) + expect(@provider).to receive(:enable_submodules) + expect(@provider).to receive(:add_remotes) @provider.run_action(:sync) # @resource.should be_updated end 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') - @provider.should_not_receive(:fetch_updates) - @provider.should_receive(:add_remotes) + expect(::File).to receive(:exist?).with("/my/deploy/dir/.git").and_return(true) + allow(::File).to receive(:directory?).with("/my/deploy").and_return(true) + allow(@provider).to receive(:find_current_revision).and_return('d35af14d41ae22b19da05d7d03a0bafc321b244c') + allow(@provider).to receive(:target_revision).and_return('d35af14d41ae22b19da05d7d03a0bafc321b244c') + expect(@provider).not_to receive(:fetch_updates) + expect(@provider).to receive(:add_remotes) @provider.run_action(:sync) - @resource.should_not be_updated + expect(@resource).not_to be_updated 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.should_receive(:exist?).with("/my/deploy/dir/.git").exactly(2).and_return(false) - @provider.should_receive(:action_checkout) - @provider.should_not_receive(:shell_out!) + allow(::File).to receive(:directory?).with("/my/deploy").and_return(true) + expect(::File).to receive(:exist?).with("/my/deploy/dir/.git").exactly(2).and_return(false) + expect(@provider).to receive(:action_checkout) + expect(@provider).not_to receive(:shell_out!) @provider.run_action(:sync) # @resource.should be_updated end 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!") - @provider.should_receive(:action_checkout) - @provider.should_not_receive(:shell_out!).with("huzzah!", :cwd => "/my/deploy/dir") + expect(::File).to receive(:exist?).with("/my/deploy/dir/.git").exactly(2).and_return(false) + allow(::File).to receive(:directory?).with("/my/deploy").and_return(true) + allow(::File).to receive(:directory?).with("/my/deploy/dir").and_return(true) + allow(@provider).to receive(:sync_command).and_return("huzzah!") + expect(@provider).to receive(:action_checkout) + expect(@provider).not_to receive(:shell_out!).with("huzzah!", :cwd => "/my/deploy/dir") @provider.run_action(:sync) #@resource.should be_updated end it "does an export by cloning the repo then removing the .git directory" do - @provider.should_receive(:action_checkout) - FileUtils.should_receive(:rm_rf).with(@resource.destination + "/.git") + expect(@provider).to receive(:action_checkout) + expect(FileUtils).to receive(:rm_rf).with(@resource.destination + "/.git") @provider.run_action(:export) - @resource.should be_updated + expect(@resource).to be_updated end describe "calling add_remotes" do it "adds a new remote for each entry in additional remotes hash" do @resource.additional_remotes({:opscode => "opscode_repo_url", :another_repo => "some_other_repo_url"}) - STDOUT.stub(:tty?).and_return(false) + allow(STDOUT).to receive(:tty?).and_return(false) command_response = double('shell_out') - command_response.stub(:exitstatus) { 0 } + allow(command_response).to receive(:exitstatus) { 0 } @resource.additional_remotes.each_pair do |remote_name, remote_url| - @provider.should_receive(:setup_remote_tracking_branches).with(remote_name, remote_url) + expect(@provider).to receive(:setup_remote_tracking_branches).with(remote_name, remote_url) end @provider.add_remotes end @@ -620,22 +620,22 @@ SHAS describe "when check remote command returns with status 2" do it "returns true" do - @command_response.stub(:exitstatus) { 2 } - @provider.multiple_remotes?(@command_response).should be_true + allow(@command_response).to receive(:exitstatus) { 2 } + expect(@provider.multiple_remotes?(@command_response)).to be_true end end describe "when check remote command returns with status 0" do it "returns false" do - @command_response.stub(:exitstatus) { 0 } - @provider.multiple_remotes?(@command_response).should be_false + allow(@command_response).to receive(:exitstatus) { 0 } + expect(@provider.multiple_remotes?(@command_response)).to be_false end end describe "when check remote command returns with status 0" do it "returns false" do - @command_response.stub(:exitstatus) { 1 } - @provider.multiple_remotes?(@command_response).should be_false + allow(@command_response).to receive(:exitstatus) { 1 } + expect(@provider.multiple_remotes?(@command_response)).to be_false end end end @@ -647,17 +647,17 @@ SHAS describe "when output of the check remote command matches the repository url" do it "returns true" do - @command_response.stub(:exitstatus) { 0 } - @command_response.stub(:stdout) { @resource.repository } - @provider.remote_matches?(@resource.repository, @command_response).should be_true + allow(@command_response).to receive(:exitstatus) { 0 } + allow(@command_response).to receive(:stdout) { @resource.repository } + expect(@provider.remote_matches?(@resource.repository, @command_response)).to be_true end end describe "when output of the check remote command doesn't match the repository url" do it "returns false" do - @command_response.stub(:exitstatus) { 0 } - @command_response.stub(:stdout) { @resource.repository + "test" } - @provider.remote_matches?(@resource.repository, @command_response).should be_false + allow(@command_response).to receive(:exitstatus) { 0 } + allow(@command_response).to receive(:stdout) { @resource.repository + "test" } + expect(@provider.remote_matches?(@resource.repository, @command_response)).to be_false end end end diff --git a/spec/unit/provider/group/dscl_spec.rb b/spec/unit/provider/group/dscl_spec.rb index f2b602ee97..acd1ba3859 100644 --- a/spec/unit/provider/group/dscl_spec.rb +++ b/spec/unit/provider/group/dscl_spec.rb @@ -32,64 +32,64 @@ 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) + allow(@provider).to receive(: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 - @provider.should_receive(:popen4).with("dscl . -cmd /Path arg1 arg2") + expect(@provider).to receive(:popen4).with("dscl . -cmd /Path arg1 arg2") @provider.dscl("cmd", "/Path", "arg1", "arg2") end it "should return an array of four elements - cmd, status, stdout, stderr" do dscl_retval = @provider.dscl("cmd /Path args") - dscl_retval.should be_a_kind_of(Array) - dscl_retval.should == ["dscl . -cmd /Path args",@status,"\n",""] + expect(dscl_retval).to be_a_kind_of(Array) + expect(dscl_retval).to eq(["dscl . -cmd /Path args",@status,"\n",""]) end describe "safe_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"]) + allow(@provider).to receive(:dscl).and_return(["cmd", @status, "stdout", "stderr"]) end it "should run dscl with the supplied cmd /Path args" do - @provider.should_receive(:dscl).with("cmd /Path args") + expect(@provider).to receive(:dscl).with("cmd /Path args") @provider.safe_dscl("cmd /Path args") end describe "with the dscl command returning a non zero exit status for a delete" do before do @status = double("Process::Status", :exitstatus => 1) - @provider.stub(:dscl).and_return(["cmd", @status, "stdout", "stderr"]) + allow(@provider).to receive(:dscl).and_return(["cmd", @status, "stdout", "stderr"]) end it "should return an empty string of standard output for a delete" do safe_dscl_retval = @provider.safe_dscl("delete /Path args") - safe_dscl_retval.should be_a_kind_of(String) - safe_dscl_retval.should == "" + expect(safe_dscl_retval).to be_a_kind_of(String) + expect(safe_dscl_retval).to eq("") end it "should raise an exception for any other command" do - lambda { @provider.safe_dscl("cmd /Path arguments") }.should raise_error(Chef::Exceptions::Group) + expect { @provider.safe_dscl("cmd /Path arguments") }.to raise_error(Chef::Exceptions::Group) end end describe "with the dscl command returning no such key" do before do - @provider.stub(:dscl).and_return(["cmd", @status, "No such key: ", "stderr"]) + allow(@provider).to receive(:dscl).and_return(["cmd", @status, "No such key: ", "stderr"]) end it "should raise an exception" do - lambda { @provider.safe_dscl("cmd /Path arguments") }.should raise_error(Chef::Exceptions::Group) + expect { @provider.safe_dscl("cmd /Path arguments") }.to raise_error(Chef::Exceptions::Group) end end describe "with the dscl command returning a zero exit status" do it "should return the third array element, the string of standard output" do safe_dscl_retval = @provider.safe_dscl("cmd /Path args") - safe_dscl_retval.should be_a_kind_of(String) - safe_dscl_retval.should == "stdout" + expect(safe_dscl_retval).to be_a_kind_of(String) + expect(safe_dscl_retval).to eq("stdout") end end end @@ -98,21 +98,21 @@ 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") + allow(@provider).to receive(:safe_dscl).and_return("\naj 200\njt 201\n") end it "should run safe_dscl with list /Groups gid" do - @provider.should_receive(:safe_dscl).with("list /Groups gid") + expect(@provider).to receive(:safe_dscl).with("list /Groups gid") @provider.get_free_gid end it "should return the first unused gid number on or above 200" do - @provider.get_free_gid.should equal(202) + expect(@provider.get_free_gid).to equal(202) end it "should raise an exception when the search limit is exhausted" do search_limit = 1 - lambda { @provider.get_free_gid(search_limit) }.should raise_error(RuntimeError) + expect { @provider.get_free_gid(search_limit) }.to raise_error(RuntimeError) end end @@ -120,41 +120,41 @@ 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") + allow(@provider).to receive(:safe_dscl).and_return("\naj 500\n") end it "should run safe_dscl with list /Groups gid" do - @provider.should_receive(:safe_dscl).with("list /Groups gid") + expect(@provider).to receive(:safe_dscl).with("list /Groups gid") @provider.gid_used?(500) end it "should return true for a used gid number" do - @provider.gid_used?(500).should be_true + expect(@provider.gid_used?(500)).to be_true end it "should return false for an unused gid number" do - @provider.gid_used?(501).should be_false + expect(@provider.gid_used?(501)).to be_false end it "should return false if not given any valid gid number" do - @provider.gid_used?(nil).should be_false + expect(@provider.gid_used?(nil)).to be_false end end 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) + allow(@provider).to receive(:gid_used?).and_return(true) end it "should raise an exception if the new resources gid is already in use" do - lambda { @provider.set_gid }.should raise_error(Chef::Exceptions::Group) + expect { @provider.set_gid }.to raise_error(Chef::Exceptions::Group) end end describe "with no gid number for the new resources" do it "should run get_free_gid and return a valid, unused gid number" do - @provider.should_receive(:get_free_gid).and_return(501) + expect(@provider).to receive(:get_free_gid).and_return(501) @provider.set_gid end end @@ -162,20 +162,20 @@ 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) + allow(@new_resource).to receive(:safe_dscl) end it "should run get_free_gid and return a valid, unused gid number" do - @provider.should_receive(:get_free_gid).and_return(501) + expect(@provider).to receive(:get_free_gid).and_return(501) @provider.set_gid end end describe "with a valid gid number which is not already in use" do it "should run safe_dscl with create /Groups/group PrimaryGroupID gid" do - @provider.stub(:get_free_gid).and_return(50) - @provider.should_receive(:safe_dscl).with("list /Groups gid") - @provider.should_receive(:safe_dscl).with("create /Groups/aj PrimaryGroupID 50").and_return(true) + allow(@provider).to receive(:get_free_gid).and_return(50) + expect(@provider).to receive(:safe_dscl).with("list /Groups gid") + expect(@provider).to receive(:safe_dscl).with("create /Groups/aj PrimaryGroupID 50").and_return(true) @provider.set_gid end end @@ -185,19 +185,19 @@ 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"]) + allow(@new_resource).to receive(:members).and_return([]) + allow(@new_resource).to receive(:append).and_return(false) + allow(@current_resource).to receive(:members).and_return(["all", "your", "base"]) end it "should log an appropriate message" do - Chef::Log.should_receive(:debug).with("group[aj] removing group members all your base") + expect(Chef::Log).to receive(:debug).with("group[aj] removing group members all your base") @provider.set_members end it "should run safe_dscl with create /Groups/group GroupMembership to clear the Group's UID list" do - @provider.should_receive(:safe_dscl).with("create /Groups/aj GroupMembers ''").and_return(true) - @provider.should_receive(:safe_dscl).with("create /Groups/aj GroupMembership ''").and_return(true) + expect(@provider).to receive(:safe_dscl).with("create /Groups/aj GroupMembers ''").and_return(true) + expect(@provider).to receive(:safe_dscl).with("create /Groups/aj GroupMembership ''").and_return(true) @provider.set_members end end @@ -209,14 +209,14 @@ describe Chef::Provider::Group::Dscl do end it "should log an appropriate debug message" do - Chef::Log.should_receive(:debug).with("group[aj] setting group members all, your, base") + expect(Chef::Log).to receive(:debug).with("group[aj] setting group members all, your, base") @provider.set_members end it "should run safe_dscl with append /Groups/group GroupMembership and group members all, your, base" do - @provider.should_receive(:safe_dscl).with("create /Groups/aj GroupMembers ''").and_return(true) - @provider.should_receive(:safe_dscl).with("append /Groups/aj GroupMembership all your base").and_return(true) - @provider.should_receive(:safe_dscl).with("create /Groups/aj GroupMembership ''").and_return(true) + expect(@provider).to receive(:safe_dscl).with("create /Groups/aj GroupMembers ''").and_return(true) + expect(@provider).to receive(:safe_dscl).with("append /Groups/aj GroupMembership all your base").and_return(true) + expect(@provider).to receive(:safe_dscl).with("create /Groups/aj GroupMembership ''").and_return(true) @provider.set_members end end @@ -228,7 +228,7 @@ describe Chef::Provider::Group::Dscl do end it "should not call safe_dscl" do - @provider.should_not_receive(:safe_dscl) + expect(@provider).not_to receive(:safe_dscl) @provider.set_members end end @@ -242,23 +242,23 @@ describe Chef::Provider::Group::Dscl do end it "raises an error if the required binary /usr/bin/dscl doesn't exist" do - File.should_receive(:exists?).with("/usr/bin/dscl").and_return(false) + expect(File).to receive(:exists?).with("/usr/bin/dscl").and_return(false) - lambda { @provider.process_resource_requirements }.should raise_error(Chef::Exceptions::Group) + expect { @provider.process_resource_requirements }.to raise_error(Chef::Exceptions::Group) end it "doesn't raise an error if /usr/bin/dscl exists" do - File.stub(:exists?).and_return(true) - lambda { @provider.process_resource_requirements }.should_not raise_error + allow(File).to receive(:exists?).and_return(true) + expect { @provider.process_resource_requirements }.not_to raise_error end end describe "when creating the group" do it "creates the group, password field, gid, and sets group membership" do - @provider.should_receive(:set_gid).and_return(true) - @provider.should_receive(:set_members).and_return(true) - @provider.should_receive(:safe_dscl).with("create /Groups/aj Password '*'") - @provider.should_receive(:safe_dscl).with("create /Groups/aj") + expect(@provider).to receive(:set_gid).and_return(true) + expect(@provider).to receive(:set_members).and_return(true) + expect(@provider).to receive(:safe_dscl).with("create /Groups/aj Password '*'") + expect(@provider).to receive(:safe_dscl).with("create /Groups/aj") @provider.create_group end end @@ -267,30 +267,30 @@ describe Chef::Provider::Group::Dscl do it "should manage the group_name if it changed and the new resources group_name is not null" do @current_resource.group_name("oldval") @new_resource.group_name("newname") - @provider.should_receive(:set_members).and_return(true) - @provider.should_receive(:safe_dscl).with("create /Groups/newname") - @provider.should_receive(:safe_dscl).with("create /Groups/newname Password '*'") + expect(@provider).to receive(:set_members).and_return(true) + expect(@provider).to receive(:safe_dscl).with("create /Groups/newname") + expect(@provider).to receive(:safe_dscl).with("create /Groups/newname Password '*'") @provider.manage_group end it "should manage the gid if it changed and the new resources gid is not null" do @current_resource.gid(23) @new_resource.gid(42) - @provider.should_receive(:set_gid) + expect(@provider).to receive(:set_gid) @provider.manage_group end it "should manage the members if it changed and the new resources members is not null" do @current_resource.members(%{charlie root}) @new_resource.members(%{crab revenge}) - @provider.should_receive(:set_members) + expect(@provider).to receive(:set_members) @provider.manage_group end end describe "remove_group" do it "should run safe_dscl with delete /Groups/group and with the new resources group name" do - @provider.should_receive(:safe_dscl).with("delete /Groups/aj").and_return(true) + expect(@provider).to receive(:safe_dscl).with("delete /Groups/aj").and_return(true) @provider.remove_group end end @@ -318,17 +318,17 @@ RecordName: com.apple.aj RecordType: dsRecTypeStandard:Groups GroupMembership: waka bar EOF - @provider.stub(:safe_dscl).with("read /Groups/aj").and_return(@output) + allow(@provider).to receive(:safe_dscl).with("read /Groups/aj").and_return(@output) @current_resource = @provider.load_current_resource end it 'should parse gid properly' do - File.stub(:exists?).and_return(true) - @current_resource.gid.should eq("999") + allow(File).to receive(:exists?).and_return(true) + expect(@current_resource.gid).to eq("999") end it 'should parse members properly' do - File.stub(:exists?).and_return(true) - @current_resource.members.should eq(['waka', 'bar']) + allow(File).to receive(:exists?).and_return(true) + expect(@current_resource.members).to eq(['waka', 'bar']) end end diff --git a/spec/unit/provider/group/gpasswd_spec.rb b/spec/unit/provider/group/gpasswd_spec.rb index 5bd7fdc569..55d978fa7e 100644 --- a/spec/unit/provider/group/gpasswd_spec.rb +++ b/spec/unit/provider/group/gpasswd_spec.rb @@ -41,14 +41,14 @@ describe Chef::Provider::Group::Gpasswd, "modify_group_members" do # for Chef::Provider::Group - no need to repeat it here. We'll # include only what's specific to this provider. it "should raise an error if the required binary /usr/bin/gpasswd doesn't exist" do - File.stub(:exists?).and_return(true) - File.should_receive(:exists?).with("/usr/bin/gpasswd").and_return(false) - lambda { @provider.process_resource_requirements }.should raise_error(Chef::Exceptions::Group) + allow(File).to receive(:exists?).and_return(true) + expect(File).to receive(:exists?).with("/usr/bin/gpasswd").and_return(false) + expect { @provider.process_resource_requirements }.to raise_error(Chef::Exceptions::Group) end it "shouldn't raise an error if the required binaries exist" do - File.stub(:exists?).and_return(true) - lambda { @provider.process_resource_requirements }.should_not raise_error + allow(File).to receive(:exists?).and_return(true) + expect { @provider.process_resource_requirements }.not_to raise_error end end @@ -65,8 +65,8 @@ describe Chef::Provider::Group::Gpasswd, "modify_group_members" do end it "logs a message and sets group's members to 'none'" do - Chef::Log.should_receive(:debug).with("group[wheel] setting group members to: none") - @provider.should_receive(:shell_out!).with("gpasswd -M \"\" wheel") + expect(Chef::Log).to receive(:debug).with("group[wheel] setting group members to: none") + expect(@provider).to receive(:shell_out!).with("gpasswd -M \"\" wheel") @provider.modify_group_members end end @@ -78,20 +78,20 @@ describe Chef::Provider::Group::Gpasswd, "modify_group_members" do end it "does not modify group membership" do - @provider.should_not_receive(:shell_out!) + expect(@provider).not_to receive(:shell_out!) @provider.modify_group_members end end 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!) + expect(Chef::Log).to receive(:debug).with("group[wheel] setting group members to: lobster, rage, fist") + allow(@provider).to receive(:shell_out!) @provider.modify_group_members end it "should run gpasswd with the members joined by ',' followed by the target group" do - @provider.should_receive(:shell_out!).with("gpasswd -M lobster,rage,fist wheel") + expect(@provider).to receive(:shell_out!).with("gpasswd -M lobster,rage,fist wheel") @provider.modify_group_members end @@ -104,9 +104,9 @@ describe Chef::Provider::Group::Gpasswd, "modify_group_members" do it "should run gpasswd individually for each user when the append option is set" do @new_resource.append(true) - @provider.should_receive(:shell_out!).with("gpasswd -a lobster wheel") - @provider.should_receive(:shell_out!).with("gpasswd -a rage wheel") - @provider.should_receive(:shell_out!).with("gpasswd -a fist wheel") + expect(@provider).to receive(:shell_out!).with("gpasswd -a lobster wheel") + expect(@provider).to receive(:shell_out!).with("gpasswd -a rage wheel") + expect(@provider).to receive(:shell_out!).with("gpasswd -a fist wheel") @provider.modify_group_members end end diff --git a/spec/unit/provider/group/groupadd_spec.rb b/spec/unit/provider/group/groupadd_spec.rb index 793615d04c..94150b7a88 100644 --- a/spec/unit/provider/group/groupadd_spec.rb +++ b/spec/unit/provider/group/groupadd_spec.rb @@ -43,47 +43,47 @@ describe Chef::Provider::Group::Groupadd, "set_options" do field_list.each do |attribute, option| it "should check for differences in #{attribute.to_s} between the current and new resources" do - @new_resource.should_receive(attribute) - @current_resource.should_receive(attribute) + expect(@new_resource).to receive(attribute) + expect(@current_resource).to receive(attribute) @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") - @provider.set_options.should eql(" #{option} '#{@new_resource.send(attribute)}' #{@new_resource.group_name}") + allow(@new_resource).to receive(attribute).and_return("wowaweea") + expect(@provider.set_options).to eql(" #{option} '#{@new_resource.send(attribute)}' #{@new_resource.group_name}") end end 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") + allow(@new_resource).to receive(attribute).and_return("hola") match_string << " #{option} 'hola'" end match_string << " aj" - @provider.set_options.should eql(match_string) + expect(@provider.set_options).to eql(match_string) end describe "when we want to create a system group" do it "should not set groupadd_options '-r' when system is false" do @new_resource.system(false) - @provider.groupadd_options.should_not =~ /-r/ + expect(@provider.groupadd_options).not_to match(/-r/) end it "should set groupadd -r if system is true" do @new_resource.system(true) - @provider.groupadd_options.should == " -r" + expect(@provider.groupadd_options).to eq(" -r") end end describe "when we want to create a non_unique gid group" do it "should not set groupadd_options '-o' when non_unique is false" do @new_resource.non_unique(false) - @provider.groupadd_options.should_not =~ /-o/ + expect(@provider.groupadd_options).not_to match(/-o/) end it "should set groupadd -o if non_unique is true" do @new_resource.non_unique(true) - @provider.groupadd_options.should == " -o" + expect(@provider.groupadd_options).to eq(" -o") end end end @@ -93,19 +93,19 @@ 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) + allow(@provider).to receive(:run_command).and_return(true) + allow(@provider).to receive(:set_options).and_return(" monkey") + allow(@provider).to receive(:groupadd_options).and_return("") + allow(@provider).to receive(:modify_group_members).and_return(true) end it "should run groupadd with the return of set_options" do - @provider.should_receive(:run_command).with({ :command => "groupadd monkey" }).and_return(true) + expect(@provider).to receive(:run_command).with({ :command => "groupadd monkey" }).and_return(true) @provider.create_group end it "should modify the group members" do - @provider.should_receive(:modify_group_members).and_return(true) + expect(@provider).to receive(:modify_group_members).and_return(true) @provider.create_group end end @@ -117,20 +117,20 @@ 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") + allow(@provider).to receive(:run_command).and_return(true) + allow(@provider).to receive(: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.should_receive(:run_command).with({ :command => "groupmod monkey" }).and_return(true) + allow(@provider).to receive(:modify_group_members).and_return(true) + expect(@provider).to receive(:run_command).with({ :command => "groupmod monkey" }).and_return(true) @provider.manage_group end it "should modify the group members" do - @provider.should_receive(:modify_group_members).and_return(true) + expect(@provider).to receive(:modify_group_members).and_return(true) @provider.manage_group end end @@ -138,36 +138,36 @@ describe Chef::Provider::Group::Groupadd do describe "remove_group" do it "should run groupdel with the new resources group name" do - @provider.should_receive(:run_command).with({ :command => "groupdel aj" }).and_return(true) + expect(@provider).to receive(:run_command).with({ :command => "groupdel aj" }).and_return(true) @provider.remove_group end end [:add_member, :remove_member, :set_members].each do |m| it "should raise an error when calling #{m}" do - lambda { @provider.send(m, [ ]) }.should raise_error(Chef::Exceptions::Group, "you must override #{m} in #{@provider.to_s}") + expect { @provider.send(m, [ ]) }.to raise_error(Chef::Exceptions::Group, "you must override #{m} in #{@provider.to_s}") end end describe "load_current_resource" do before do - File.stub(:exists?).and_return(false) + allow(File).to receive(: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 - File.should_receive(:exists?).with("/usr/sbin/groupadd").and_return(false) - lambda { @provider.process_resource_requirements }.should raise_error(Chef::Exceptions::Group) + expect(File).to receive(:exists?).with("/usr/sbin/groupadd").and_return(false) + expect { @provider.process_resource_requirements }.to raise_error(Chef::Exceptions::Group) end it "should raise an error if the required binary /usr/sbin/groupmod doesn't exist" do - File.should_receive(:exists?).with("/usr/sbin/groupadd").and_return(true) - File.should_receive(:exists?).with("/usr/sbin/groupmod").and_return(false) - lambda { @provider.process_resource_requirements }.should raise_error(Chef::Exceptions::Group) + expect(File).to receive(:exists?).with("/usr/sbin/groupadd").and_return(true) + expect(File).to receive(:exists?).with("/usr/sbin/groupmod").and_return(false) + expect { @provider.process_resource_requirements }.to raise_error(Chef::Exceptions::Group) end it "should raise an error if the required binary /usr/sbin/groupdel doesn't exist" do - File.should_receive(:exists?).with("/usr/sbin/groupadd").and_return(true) - File.should_receive(:exists?).with("/usr/sbin/groupmod").and_return(true) - File.should_receive(:exists?).with("/usr/sbin/groupdel").and_return(false) - lambda { @provider.process_resource_requirements }.should raise_error(Chef::Exceptions::Group) + expect(File).to receive(:exists?).with("/usr/sbin/groupadd").and_return(true) + expect(File).to receive(:exists?).with("/usr/sbin/groupmod").and_return(true) + expect(File).to receive(:exists?).with("/usr/sbin/groupdel").and_return(false) + expect { @provider.process_resource_requirements }.to raise_error(Chef::Exceptions::Group) end end diff --git a/spec/unit/provider/group/groupmod_spec.rb b/spec/unit/provider/group/groupmod_spec.rb index 001f9c66e8..496d1e28fa 100644 --- a/spec/unit/provider/group/groupmod_spec.rb +++ b/spec/unit/provider/group/groupmod_spec.rb @@ -33,18 +33,18 @@ describe Chef::Provider::Group::Groupmod do describe "manage_group" do describe "when determining the current group state" do it "should raise an error if the required binary /usr/sbin/group doesn't exist" do - File.should_receive(:exists?).with("/usr/sbin/group").and_return(false) - lambda { @provider.load_current_resource }.should raise_error(Chef::Exceptions::Group) + expect(File).to receive(:exists?).with("/usr/sbin/group").and_return(false) + expect { @provider.load_current_resource }.to raise_error(Chef::Exceptions::Group) end it "should raise an error if the required binary /usr/sbin/user doesn't exist" do - File.should_receive(:exists?).with("/usr/sbin/group").and_return(true) - File.should_receive(:exists?).with("/usr/sbin/user").and_return(false) - lambda { @provider.load_current_resource }.should raise_error(Chef::Exceptions::Group) + expect(File).to receive(:exists?).with("/usr/sbin/group").and_return(true) + expect(File).to receive(:exists?).with("/usr/sbin/user").and_return(false) + expect { @provider.load_current_resource }.to raise_error(Chef::Exceptions::Group) end it "shouldn't raise an error if the required binaries exist" do - File.stub(:exists?).and_return(true) - lambda { @provider.load_current_resource }.should_not raise_error + allow(File).to receive(:exists?).and_return(true) + expect { @provider.load_current_resource }.not_to raise_error end end @@ -61,10 +61,10 @@ describe Chef::Provider::Group::Groupmod do end it "logs a message and sets group's members to 'none', then removes existing group members" do - Chef::Log.should_receive(:debug).with("group[wheel] setting group members to: none") - @provider.should_receive(:shell_out!).with("group mod -n wheel_bak wheel") - @provider.should_receive(:shell_out!).with("group add -g '123' -o wheel") - @provider.should_receive(:shell_out!).with("group del wheel_bak") + expect(Chef::Log).to receive(:debug).with("group[wheel] setting group members to: none") + expect(@provider).to receive(:shell_out!).with("group mod -n wheel_bak wheel") + expect(@provider).to receive(:shell_out!).with("group add -g '123' -o wheel") + expect(@provider).to receive(:shell_out!).with("group del wheel_bak") @provider.manage_group end end @@ -76,8 +76,8 @@ describe Chef::Provider::Group::Groupmod do end it "logs a message and does not modify group membership" do - Chef::Log.should_receive(:debug).with("group[wheel] not changing group members, the group has no members to add") - @provider.should_not_receive(:shell_out!) + expect(Chef::Log).to receive(:debug).with("group[wheel] not changing group members, the group has no members to add") + expect(@provider).not_to receive(:shell_out!) @provider.manage_group end end @@ -89,11 +89,11 @@ describe Chef::Provider::Group::Groupmod do end it "updates group membership correctly" do - 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") - @provider.should_receive(:shell_out!).with("group del wheel_bak") + allow(Chef::Log).to receive(:debug) + expect(@provider).to receive(:shell_out!).with("group mod -n wheel_bak wheel") + expect(@provider).to receive(:shell_out!).with("user mod -G wheel lobster") + expect(@provider).to receive(:shell_out!).with("group add -g '123' -o wheel") + expect(@provider).to receive(:shell_out!).with("group del wheel_bak") @provider.manage_group end end @@ -108,10 +108,10 @@ describe Chef::Provider::Group::Groupmod do end it "should run a group add command and some user mod commands" do - @provider.should_receive(:shell_out!).with("group add -g '123' wheel") - @provider.should_receive(:shell_out!).with("user mod -G wheel lobster") - @provider.should_receive(:shell_out!).with("user mod -G wheel rage") - @provider.should_receive(:shell_out!).with("user mod -G wheel fist") + expect(@provider).to receive(:shell_out!).with("group add -g '123' wheel") + expect(@provider).to receive(:shell_out!).with("user mod -G wheel lobster") + expect(@provider).to receive(:shell_out!).with("user mod -G wheel rage") + expect(@provider).to receive(:shell_out!).with("user mod -G wheel fist") @provider.create_group end end @@ -125,7 +125,7 @@ describe Chef::Provider::Group::Groupmod do end it "should run a group del command" do - @provider.should_receive(:shell_out!).with("group del wheel") + expect(@provider).to receive(:shell_out!).with("group del wheel") @provider.remove_group end end diff --git a/spec/unit/provider/group/pw_spec.rb b/spec/unit/provider/group/pw_spec.rb index fdc2e35746..af74b3b2ce 100644 --- a/spec/unit/provider/group/pw_spec.rb +++ b/spec/unit/provider/group/pw_spec.rb @@ -37,19 +37,19 @@ describe Chef::Provider::Group::Pw do describe "when setting options for the pw command" do it "does not set the gid option if gids match or are unmanaged" do - @provider.set_options.should == " wheel" + expect(@provider.set_options).to eq(" wheel") end it "sets the option for gid if it is not nil" do @new_resource.gid(42) - @provider.set_options.should eql(" wheel -g '42'") + expect(@provider.set_options).to eql(" wheel -g '42'") end end describe "when creating a group" do it "should run pw groupadd with the return of set_options and set_members_option" do @new_resource.gid(23) - @provider.should_receive(:run_command).with({ :command => "pw groupadd wheel -g '23' -M root,aj" }).and_return(true) + expect(@provider).to receive(:run_command).with({ :command => "pw groupadd wheel -g '23' -M root,aj" }).and_return(true) @provider.create_group end end @@ -59,8 +59,8 @@ describe Chef::Provider::Group::Pw do it "should run pw groupmod with the return of set_options" do @new_resource.gid(42) @new_resource.members(["someone"]) - @provider.should_receive(:run_command).with({ :command => "pw groupmod wheel -g '42' -m someone" }).and_return(true) - @provider.should_receive(:run_command).with({ :command => "pw groupmod wheel -g '42' -d root,aj" }).and_return(true) + expect(@provider).to receive(:run_command).with({ :command => "pw groupmod wheel -g '42' -m someone" }).and_return(true) + expect(@provider).to receive(:run_command).with({ :command => "pw groupmod wheel -g '42' -d root,aj" }).and_return(true) @provider.manage_group end @@ -68,7 +68,7 @@ describe Chef::Provider::Group::Pw do describe "when removing the group" do it "should run pw groupdel with the new resources group name" do - @provider.should_receive(:run_command).with({ :command => "pw groupdel wheel" }).and_return(true) + expect(@provider).to receive(:run_command).with({ :command => "pw groupdel wheel" }).and_return(true) @provider.remove_group end end @@ -77,44 +77,44 @@ 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([]) + allow(@new_resource).to receive(:members).and_return([]) + allow(@current_resource).to receive(:members).and_return([]) end it "should set no options" do - @provider.set_members_options.should eql([ ]) + expect(@provider.set_members_options).to eql([ ]) end end 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"]) + allow(@new_resource).to receive(:members).and_return([]) + allow(@current_resource).to receive(:members).and_return(["all", "your", "base"]) end it "should log an appropriate message" do - Chef::Log.should_receive(:debug).with("group[wheel] removing group members: all,your,base") + expect(Chef::Log).to receive(:debug).with("group[wheel] removing group members: all,your,base") @provider.set_members_options end it "should set the -d option with the members joined by ','" do - @provider.set_members_options.should eql([ " -d all,your,base" ]) + expect(@provider.set_members_options).to eql([ " -d all,your,base" ]) end end 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([]) + allow(@new_resource).to receive(:members).and_return(["all", "your", "base"]) + allow(@current_resource).to receive(:members).and_return([]) end it "should log an appropriate debug message" do - Chef::Log.should_receive(:debug).with("group[wheel] adding group members: all,your,base") + expect(Chef::Log).to receive(:debug).with("group[wheel] adding group members: all,your,base") @provider.set_members_options end it "should set the -m option with the members joined by ','" do - @provider.set_members_options.should eql([ " -m all,your,base" ]) + expect(@provider.set_members_options).to eql([ " -m all,your,base" ]) end end end @@ -126,13 +126,13 @@ describe Chef::Provider::Group::Pw do @provider.define_resource_requirements end it "should raise an error if the required binary /usr/sbin/pw doesn't exist" do - File.should_receive(:exists?).with("/usr/sbin/pw").and_return(false) - lambda { @provider.process_resource_requirements }.should raise_error(Chef::Exceptions::Group) + expect(File).to receive(:exists?).with("/usr/sbin/pw").and_return(false) + expect { @provider.process_resource_requirements }.to raise_error(Chef::Exceptions::Group) end it "shouldn't raise an error if /usr/sbin/pw exists" do - File.stub(:exists?).and_return(true) - lambda { @provider.process_resource_requirements }.should_not raise_error + allow(File).to receive(:exists?).and_return(true) + expect { @provider.process_resource_requirements }.not_to raise_error end end end diff --git a/spec/unit/provider/group/usermod_spec.rb b/spec/unit/provider/group/usermod_spec.rb index bd9eac4ede..3f06e9ebf1 100644 --- a/spec/unit/provider/group/usermod_spec.rb +++ b/spec/unit/provider/group/usermod_spec.rb @@ -27,19 +27,19 @@ 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) + allow(@provider).to receive(: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([]) + allow(@new_resource).to receive(:append).and_return(true) + allow(@new_resource).to receive(:members).and_return([]) end it "should log an appropriate message" do - @provider.should_not_receive(:shell_out!) + expect(@provider).not_to receive(:shell_out!) @provider.modify_group_members end end @@ -56,8 +56,8 @@ describe Chef::Provider::Group::Usermod do } before do - @new_resource.stub(:members).and_return(["all", "your", "base"]) - File.stub(:exists?).and_return(true) + allow(@new_resource).to receive(:members).and_return(["all", "your", "base"]) + allow(File).to receive(:exists?).and_return(true) end it "should raise an error when setting the entire group directly" do @@ -65,7 +65,7 @@ describe Chef::Provider::Group::Usermod do @provider.load_current_resource @provider.instance_variable_set("@group_exists", true) @provider.action = :modify - lambda { @provider.run_action(@provider.process_resource_requirements) }.should raise_error(Chef::Exceptions::Group, "setting group members directly is not supported by #{@provider.to_s}, must set append true in group") + expect { @provider.run_action(@provider.process_resource_requirements) }.to raise_error(Chef::Exceptions::Group, "setting group members directly is not supported by #{@provider.to_s}, must set append true in group") end it "should raise an error when excluded_members are set" do @@ -73,9 +73,9 @@ 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"]) - lambda { @provider.run_action(@provider.process_resource_requirements) }.should raise_error(Chef::Exceptions::Group, "excluded_members is not supported by #{@provider.to_s}") + allow(@new_resource).to receive(:append).and_return(true) + allow(@new_resource).to receive(:excluded_members).and_return(["someone"]) + expect { @provider.run_action(@provider.process_resource_requirements) }.to raise_error(Chef::Exceptions::Group, "excluded_members is not supported by #{@provider.to_s}") end platforms.each do |platform, flags| @@ -84,10 +84,10 @@ 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) - @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") + allow(@new_resource).to receive(:append).and_return(true) + expect(@provider).to receive(:shell_out!).with("usermod #{flags} wheel all") + expect(@provider).to receive(:shell_out!).with("usermod #{flags} wheel your") + expect(@provider).to receive(:shell_out!).with("usermod #{flags} wheel base") @provider.modify_group_members end end @@ -96,20 +96,20 @@ describe Chef::Provider::Group::Usermod do describe "when loading the current resource" do before(:each) do - File.stub(:exists?).and_return(false) + allow(File).to receive(:exists?).and_return(false) @provider.action = :create @provider.define_resource_requirements end it "should raise an error if the required binary /usr/sbin/usermod doesn't exist" do - File.stub(:exists?).and_return(true) - File.should_receive(:exists?).with("/usr/sbin/usermod").and_return(false) - lambda { @provider.process_resource_requirements }.should raise_error(Chef::Exceptions::Group) + allow(File).to receive(:exists?).and_return(true) + expect(File).to receive(:exists?).with("/usr/sbin/usermod").and_return(false) + expect { @provider.process_resource_requirements }.to raise_error(Chef::Exceptions::Group) end it "shouldn't raise an error if the required binaries exist" do - File.stub(:exists?).and_return(true) - lambda { @provider.process_resource_requirements }.should_not raise_error + allow(File).to receive(:exists?).and_return(true) + expect { @provider.process_resource_requirements }.not_to raise_error end end end diff --git a/spec/unit/provider/group/windows_spec.rb b/spec/unit/provider/group/windows_spec.rb index 6888c750f5..23dfa8315f 100644 --- a/spec/unit/provider/group/windows_spec.rb +++ b/spec/unit/provider/group/windows_spec.rb @@ -34,14 +34,14 @@ describe Chef::Provider::Group::Windows do @run_context = Chef::RunContext.new(@node, {}, @events) @new_resource = Chef::Resource::Group.new("staff") @net_group = double("Chef::Util::Windows::NetGroup") - Chef::Util::Windows::NetGroup.stub(:new).and_return(@net_group) + allow(Chef::Util::Windows::NetGroup).to receive(:new).and_return(@net_group) @provider = Chef::Provider::Group::Windows.new(@new_resource, @run_context) end describe "when creating the group" do it "should call @net_group.local_add" do - @net_group.should_receive(:local_set_members).with([]) - @net_group.should_receive(:local_add) + expect(@net_group).to receive(:local_set_members).with([]) + expect(@net_group).to receive(:local_add) @provider.create_group end end @@ -52,22 +52,22 @@ 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) - @provider.stub(:local_group_name_to_sid) + allow(Chef::Util::Windows::NetGroup).to receive(:new).and_return(@net_group) + allow(@net_group).to receive(:local_add_members) + allow(@net_group).to receive(:local_set_members) + allow(@provider).to receive(: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) - @net_group.should_receive(:local_set_members).with(@new_resource.members) + allow(@new_resource).to receive(:append).and_return(false) + expect(@net_group).to 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) - @net_group.should_receive(:local_add_members).with(@new_resource.members) + allow(@new_resource).to receive(:append).and_return(true) + expect(@net_group).to receive(:local_add_members).with(@new_resource.members) @provider.manage_group end @@ -75,12 +75,12 @@ 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) + allow(Chef::Util::Windows::NetGroup).to receive(:new).and_return(@net_group) + allow(@provider).to receive(:run_command).and_return(true) end it "should call @net_group.local_delete" do - @net_group.should_receive(:local_delete) + expect(@net_group).to receive(:local_delete) @provider.remove_group end end @@ -95,7 +95,7 @@ describe Chef::Provider::Group::Windows, "NetGroup" do @new_resource.group_name "Remote Desktop Users" end it 'sets group_name correctly' do - Chef::Util::Windows::NetGroup.should_receive(:new).with("Remote Desktop Users") + expect(Chef::Util::Windows::NetGroup).to receive(:new).with("Remote Desktop Users") Chef::Provider::Group::Windows.new(@new_resource, @run_context) end end diff --git a/spec/unit/provider/group_spec.rb b/spec/unit/provider/group_spec.rb index e467da751f..e20486fd4a 100644 --- a/spec/unit/provider/group_spec.rb +++ b/spec/unit/provider/group_spec.rb @@ -41,89 +41,89 @@ describe Chef::Provider::User do :gid => 20, :mem => [ "root", "aj" ] ) - Etc.stub(:getgrnam).with('wheel').and_return(@pw_group) + allow(Etc).to receive(:getgrnam).with('wheel').and_return(@pw_group) end it "assumes the group exists by default" do - @provider.group_exists.should be_true + expect(@provider.group_exists).to be_true end describe "when establishing the current state of the group" do it "sets the group name of the current resource to the group name of the new resource" do @provider.load_current_resource - @provider.current_resource.group_name.should == 'wheel' + expect(@provider.current_resource.group_name).to eq('wheel') end it "does not modify the desired gid if set" do @provider.load_current_resource - @new_resource.gid.should == 500 + expect(@new_resource.gid).to eq(500) end it "sets the desired gid to the current gid if none is set" do @new_resource.instance_variable_set(:@gid, nil) @provider.load_current_resource - @new_resource.gid.should == 20 + expect(@new_resource.gid).to eq(20) end it "looks up the group in /etc/group with getgrnam" do - Etc.should_receive(:getgrnam).with(@new_resource.group_name).and_return(@pw_group) + expect(Etc).to receive(:getgrnam).with(@new_resource.group_name).and_return(@pw_group) @provider.load_current_resource - @provider.current_resource.gid.should == 20 - @provider.current_resource.members.should == %w{root aj} + expect(@provider.current_resource.gid).to eq(20) + expect(@provider.current_resource.members).to eq(%w{root aj}) end it "should flip the value of exists if it cannot be found in /etc/group" do - Etc.stub(:getgrnam).and_raise(ArgumentError) + allow(Etc).to receive(:getgrnam).and_raise(ArgumentError) @provider.load_current_resource - @provider.group_exists.should be_false + expect(@provider.group_exists).to be_false end it "should return the current resource" do - @provider.load_current_resource.should equal(@provider.current_resource) + expect(@provider.load_current_resource).to equal(@provider.current_resource) end end 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") - @provider.compare_group.should be_true + allow(@current_resource).to receive(attribute).and_return("looooooooooooooooooool") + expect(@provider.compare_group).to be_true end end it "should return false if gid and members are equal" do - @provider.compare_group.should be_false + expect(@provider.compare_group).to be_false end it "should coerce an integer to a string for comparison" do - @current_resource.stub(:gid).and_return("500") - @provider.compare_group.should be_false + allow(@current_resource).to receive(:gid).and_return("500") + expect(@provider.compare_group).to be_false end 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) - @provider.compare_group.should be_false + allow(@new_resource).to receive(:append).and_return(true) + expect(@provider.compare_group).to 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) - @provider.compare_group.should be_true + allow(@new_resource).to receive(:append).and_return(true) + expect(@provider.compare_group).to 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) - @provider.compare_group.should be_false + allow(@new_resource).to receive(:append).and_return(true) + expect(@provider.compare_group).to 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) - @provider.compare_group.should be_true + allow(@new_resource).to receive(:append).and_return(true) + expect(@provider.compare_group).to be_true end end @@ -131,40 +131,40 @@ describe Chef::Provider::User do describe "when creating a group" do it "should call create_group if the group does not exist" do @provider.group_exists = false - @provider.should_receive(:create_group).and_return(true) + expect(@provider).to receive(:create_group).and_return(true) @provider.run_action(:create) end it "should set the new_resources updated flag when it creates the group" do @provider.group_exists = false - @provider.stub(:create_group) + allow(@provider).to receive(:create_group) @provider.run_action(:create) - @provider.new_resource.should be_updated + expect(@provider.new_resource).to 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([ ]) + allow(@provider).to receive(:compare_group).and_return(false) + allow(@provider).to receive(:change_desc).and_return([ ]) @provider.run_action(:create) - @provider.new_resource.should_not be_updated + expect(@provider.new_resource).not_to 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.should_receive(:manage_group).and_return(true) + allow(@provider).to receive(:compare_group).and_return(true) + allow(@provider).to receive(:change_desc).and_return([ ]) + expect(@provider).to 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) + allow(@provider).to receive(:compare_group).and_return(true) + allow(@provider).to receive(:change_desc).and_return(["Some changes are going to be done."]) + allow(@provider).to receive(:manage_group).and_return(true) @provider.run_action(:create) - @new_resource.should be_updated + expect(@new_resource).to be_updated end end @@ -172,50 +172,50 @@ describe Chef::Provider::User do it "should not call remove_group if the group does not exist" do @provider.group_exists = false - @provider.should_not_receive(:remove_group) + expect(@provider).not_to receive(:remove_group) @provider.run_action(:remove) - @provider.new_resource.should_not be_updated + expect(@provider.new_resource).not_to be_updated end it "should call remove_group if the group exists" do @provider.group_exists = true - @provider.should_receive(:remove_group) + expect(@provider).to receive(:remove_group) @provider.run_action(:remove) - @provider.new_resource.should be_updated + expect(@provider.new_resource).to be_updated end end describe "when updating a group" do before(:each) do @provider.group_exists = true - @provider.stub(:manage_group).and_return(true) + allow(@provider).to receive(: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.should_receive(:manage_group).and_return(true) + expect(@provider).to receive(:compare_group).and_return(true) + allow(@provider).to receive(:change_desc).and_return(["Some changes are going to be done."]) + expect(@provider).to 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) + allow(@provider).to receive(:compare_group).and_return(true) + allow(@provider).to receive(:change_desc).and_return(["Some changes are going to be done."]) + allow(@provider).to receive(:manage_group).and_return(true) @provider.run_action(:manage) - @new_resource.should be_updated + expect(@new_resource).to be_updated end it "should not run manage_group if the group does not exist" do @provider.group_exists = false - @provider.should_not_receive(:manage_group) + expect(@provider).not_to receive(:manage_group) @provider.run_action(:manage) 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.should_not_receive(:manage_group) + expect(@provider).to receive(:compare_group).and_return(false) + allow(@provider).to receive(:change_desc).and_return(["Some changes are going to be done."]) + expect(@provider).not_to receive(:manage_group) @provider.run_action(:manage) end end @@ -223,34 +223,34 @@ 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) + allow(@provider).to receive(: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.should_receive(:manage_group).and_return(true) + expect(@provider).to receive(:compare_group).and_return(true) + allow(@provider).to receive(:change_desc).and_return(["Some changes are going to be done."]) + expect(@provider).to 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) + allow(@provider).to receive(:compare_group).and_return(true) + allow(@provider).to receive(:change_desc).and_return(["Some changes are going to be done."]) + allow(@provider).to receive(:manage_group).and_return(true) @provider.run_action(:modify) - @new_resource.should be_updated + expect(@new_resource).to 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.should_not_receive(:manage_group) + expect(@provider).to receive(:compare_group).and_return(false) + allow(@provider).to receive(:change_desc).and_return(["Some changes are going to be done."]) + expect(@provider).not_to receive(:manage_group) @provider.run_action(:modify) end it "should raise a Chef::Exceptions::Group if the group doesn't exist" do @provider.group_exists = false - lambda { @provider.run_action(:modify) }.should raise_error(Chef::Exceptions::Group) + expect { @provider.run_action(:modify) }.to raise_error(Chef::Exceptions::Group) end end @@ -258,28 +258,28 @@ 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 - @provider.compare_group.should be_true - @provider.change_desc.should == [ "add missing member(s): user1, user2" ] + allow(@new_resource).to receive(:append).and_return true + expect(@provider.compare_group).to be_true + expect(@provider.change_desc).to eq([ "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 - @provider.compare_group.should be_true - @provider.change_desc.should == [ "replace group members with new list of members" ] + allow(@new_resource).to receive(:append).and_return false + expect(@provider.compare_group).to be_true + expect(@provider.change_desc).to eq([ "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") - @provider.compare_group.should be_true - @provider.change_desc.should == [ "change gid #{@current_resource.gid} to #{@new_resource.gid}" ] + allow(@current_resource).to receive(:gid).and_return("BADF00D") + expect(@provider.compare_group).to be_true + expect(@provider.change_desc).to eq([ "change gid #{@current_resource.gid} to #{@new_resource.gid}" ]) end it "should report no change reason when no change is required" do - @provider.compare_group.should be_false - @provider.change_desc.should == [ ] + expect(@provider.compare_group).to be_false + expect(@provider.change_desc).to eq([ ]) end end diff --git a/spec/unit/provider/http_request_spec.rb b/spec/unit/provider/http_request_spec.rb index 3077685b97..a84dd5e2a0 100644 --- a/spec/unit/provider/http_request_spec.rb +++ b/spec/unit/provider/http_request_spec.rb @@ -35,7 +35,7 @@ describe Chef::Provider::HttpRequest do describe "load_current_resource" do it "should set up a Chef::REST client, with no authentication" do - Chef::HTTP::Simple.should_receive(:new).with(@new_resource.url) + expect(Chef::HTTP::Simple).to receive(:new).with(@new_resource.url) @provider.load_current_resource end end @@ -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) + allow(@provider).to receive(:load_current_resource).and_return(true) @http = double("Chef::REST") @provider.http = @http end @@ -53,53 +53,53 @@ describe Chef::Provider::HttpRequest do it "should inflate a message block at runtime" do @new_resource.message { "return" } - @http.should_receive(:get).with("http://www.opscode.com/", {}) + expect(@http).to receive(:get).with("http://www.opscode.com/", {}) @provider.run_action(:get) - @new_resource.should be_updated + expect(@new_resource).to be_updated end it "should run a GET request" do - @http.should_receive(:get).with("http://www.opscode.com/", {}) + expect(@http).to receive(:get).with("http://www.opscode.com/", {}) @provider.run_action(:get) - @new_resource.should be_updated + expect(@new_resource).to be_updated end end describe "action_put" do it "should run a PUT request with the message as the payload" do - @http.should_receive(:put).with("http://www.opscode.com/", @new_resource.message, {}) + expect(@http).to receive(:put).with("http://www.opscode.com/", @new_resource.message, {}) @provider.run_action(:put) - @new_resource.should be_updated + expect(@new_resource).to be_updated end it "should inflate a message block at runtime" do - @new_resource.stub(:message).and_return(lambda { "return" }) - @http.should_receive(:put).with("http://www.opscode.com/", "return", {}) + allow(@new_resource).to receive(:message).and_return(lambda { "return" }) + expect(@http).to receive(:put).with("http://www.opscode.com/", "return", {}) @provider.run_action(:put) - @new_resource.should be_updated + expect(@new_resource).to be_updated end end describe "action_post" do it "should run a PUT request with the message as the payload" do - @http.should_receive(:post).with("http://www.opscode.com/", @new_resource.message, {}) + expect(@http).to receive(:post).with("http://www.opscode.com/", @new_resource.message, {}) @provider.run_action(:post) - @new_resource.should be_updated + expect(@new_resource).to be_updated end it "should inflate a message block at runtime" do @new_resource.message { "return" } - @http.should_receive(:post).with("http://www.opscode.com/", "return", {}) + expect(@http).to receive(:post).with("http://www.opscode.com/", "return", {}) @provider.run_action(:post) - @new_resource.should be_updated + expect(@new_resource).to be_updated end end describe "action_delete" do it "should run a DELETE request" do - @http.should_receive(:delete).with("http://www.opscode.com/", {}) + expect(@http).to receive(:delete).with("http://www.opscode.com/", {}) @provider.run_action(:delete) - @new_resource.should be_updated + expect(@new_resource).to be_updated end end @@ -112,46 +112,46 @@ describe Chef::Provider::HttpRequest do it "should inflate a message block at runtime" do @new_resource.message { "return" } - @http.should_receive(:head).with("http://www.opscode.com/", {}).and_return(nil) + expect(@http).to receive(:head).with("http://www.opscode.com/", {}).and_return(nil) @provider.run_action(:head) - @new_resource.should be_updated + expect(@new_resource).to be_updated end it "should run a HEAD request" do - @http.should_receive(:head).with("http://www.opscode.com/", {}).and_return(nil) + expect(@http).to receive(:head).with("http://www.opscode.com/", {}).and_return(nil) @provider.run_action(:head) - @new_resource.should be_updated + expect(@new_resource).to be_updated end it "should update a HEAD request with empty string response body (CHEF-4762)" do - @http.should_receive(:head).with("http://www.opscode.com/", {}).and_return("") + expect(@http).to receive(:head).with("http://www.opscode.com/", {}).and_return("") @provider.run_action(:head) - @new_resource.should be_updated + expect(@new_resource).to be_updated end it "should update a HEAD request with nil response body (CHEF-4762)" do - @http.should_receive(:head).with("http://www.opscode.com/", {}).and_return(nil) + expect(@http).to receive(:head).with("http://www.opscode.com/", {}).and_return(nil) @provider.run_action(:head) - @new_resource.should be_updated + expect(@new_resource).to be_updated end it "should not update a HEAD request if a not modified response (CHEF-4762)" do if_modified_since = File.mtime(__FILE__).httpdate @new_resource.headers "If-Modified-Since" => if_modified_since - @http.should_receive(:head).with("http://www.opscode.com/", {"If-Modified-Since" => if_modified_since}).and_return(false) + expect(@http).to receive(:head).with("http://www.opscode.com/", {"If-Modified-Since" => if_modified_since}).and_return(false) @provider.run_action(:head) - @new_resource.should_not be_updated + expect(@new_resource).not_to be_updated end it "should run a HEAD request with If-Modified-Since header" do @new_resource.headers "If-Modified-Since" => File.mtime(__FILE__).httpdate - @http.should_receive(:head).with("http://www.opscode.com/", @new_resource.headers) + expect(@http).to receive(:head).with("http://www.opscode.com/", @new_resource.headers) @provider.run_action(:head) end it "doesn't call converge_by if HEAD does not return modified" do - @http.should_receive(:head).and_return(false) - @provider.should_not_receive(:converge_by) + expect(@http).to receive(:head).and_return(false) + expect(@provider).not_to receive(:converge_by) @provider.run_action(:head) end end diff --git a/spec/unit/provider/ifconfig/aix_spec.rb b/spec/unit/provider/ifconfig/aix_spec.rb index 24f5fb18f3..6e685823ac 100644 --- a/spec/unit/provider/ifconfig/aix_spec.rb +++ b/spec/unit/provider/ifconfig/aix_spec.rb @@ -50,7 +50,7 @@ IFCONFIG describe "#load_current_resource" do before do status = double("Status", :exitstatus => 0) - @provider.should_receive(:popen4).with("ifconfig -a").and_yield(@pid,@stdin,StringIO.new(@ifconfig_output),@stderr).and_return(status) + expect(@provider).to receive(:popen4).with("ifconfig -a").and_yield(@pid,@stdin,StringIO.new(@ifconfig_output),@stderr).and_return(status) @new_resource.device "en0" end it "should load given interface with attributes." do @@ -67,21 +67,21 @@ IFCONFIG it "should add an interface if it does not exist" do @new_resource.device "en10" - @provider.stub(:load_current_resource) do + allow(@provider).to receive(: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 command = "chdev -l #{@new_resource.device} -a netaddr=#{@new_resource.name}" - @provider.should_receive(:run_command).with(:command => command) + expect(@provider).to receive(:run_command).with(:command => command) @provider.run_action(:add) - @new_resource.should be_updated + expect(@new_resource).to be_updated end it "should raise exception if metric attribute is set" do @new_resource.device "en0" @new_resource.metric "1" - @provider.stub(:load_current_resource) do + allow(@provider).to receive(: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,15 +93,15 @@ 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 + allow(@provider).to receive(: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 command = "ifconfig #{@new_resource.device} #{@new_resource.name}" - @provider.should_receive(:run_command).with(:command => command) + expect(@provider).to receive(:run_command).with(:command => command) @provider.run_action(:enable) - @new_resource.should be_updated + expect(@new_resource).to be_updated end end @@ -109,21 +109,21 @@ IFCONFIG it "should not disable an interface if it does not exist" do @new_resource.device "en10" - @provider.stub(:load_current_resource) do + allow(@provider).to receive(: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 - @provider.should_not_receive(:run_command) + expect(@provider).not_to receive(:run_command) @provider.run_action(:disable) - @new_resource.should_not be_updated + expect(@new_resource).not_to be_updated end context "interface exists" do before do @new_resource.device "en10" - @provider.stub(:load_current_resource) do + allow(@provider).to receive(: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 @@ -133,10 +133,10 @@ IFCONFIG it "should disable an interface if it exists" do command = "ifconfig #{@new_resource.device} down" - @provider.should_receive(:run_command).with(:command => command) + expect(@provider).to receive(:run_command).with(:command => command) @provider.run_action(:disable) - @new_resource.should be_updated + expect(@new_resource).to be_updated end end @@ -146,21 +146,21 @@ IFCONFIG it "should not delete an interface if it does not exist" do @new_resource.device "en10" - @provider.stub(:load_current_resource) do + allow(@provider).to receive(: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 - @provider.should_not_receive(:run_command) + expect(@provider).not_to receive(:run_command) @provider.run_action(:delete) - @new_resource.should_not be_updated + expect(@new_resource).not_to be_updated end context "interface exists" do before do @new_resource.device "en10" - @provider.stub(:load_current_resource) do + allow(@provider).to receive(: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 @@ -170,10 +170,10 @@ IFCONFIG it "should delete an interface if it exists" do command = "chdev -l #{@new_resource.device} -a state=down" - @provider.should_receive(:run_command).with(:command => command) + expect(@provider).to receive(:run_command).with(:command => command) @provider.run_action(:delete) - @new_resource.should be_updated + expect(@new_resource).to be_updated end end end diff --git a/spec/unit/provider/ifconfig/debian_spec.rb b/spec/unit/provider/ifconfig/debian_spec.rb index ebb16e22af..160a0ed4eb 100644 --- a/spec/unit/provider/ifconfig/debian_spec.rb +++ b/spec/unit/provider/ifconfig/debian_spec.rb @@ -340,10 +340,10 @@ source #{tempdir_path}/* current_resource.device new_resource.device # belt and suspenders testing? - Chef::Util::Backup.any_instance.should_receive(:do_backup).and_call_original + expect_any_instance_of(Chef::Util::Backup).to receive(:do_backup).and_call_original # internal implementation detail of Ifconfig. - Chef::Provider::File.any_instance.should_receive(:action_delete).and_call_original + expect_any_instance_of(Chef::Provider::File).to receive(:action_delete).and_call_original expect(File.exist?(config_filename_ifcfg)).to be_true provider.run_action(:delete) diff --git a/spec/unit/provider/ifconfig/redhat_spec.rb b/spec/unit/provider/ifconfig/redhat_spec.rb index 138c2a389d..620fd341d7 100644 --- a/spec/unit/provider/ifconfig/redhat_spec.rb +++ b/spec/unit/provider/ifconfig/redhat_spec.rb @@ -40,21 +40,21 @@ describe Chef::Provider::Ifconfig::Redhat do config_filename = "/etc/sysconfig/network-scripts/ifcfg-#{@new_resource.device}" @config = double("chef-resource-file") - @provider.should_receive(:resource_for_config).with(config_filename).and_return(@config) + expect(@provider).to receive(:resource_for_config).with(config_filename).and_return(@config) end describe "generate_config for action_add" do it "should write network-script for centos" do - @provider.stub(:load_current_resource) - @provider.stub(:run_command) - @config.should_receive(:content) do |arg| - arg.should match(/^\s*DEVICE=eth0\s*$/) - arg.should match(/^\s*IPADDR=10\.0\.0\.1\s*$/) - arg.should match(/^\s*NETMASK=255\.255\.254\.0\s*$/) + allow(@provider).to receive(:load_current_resource) + allow(@provider).to receive(:run_command) + expect(@config).to receive(:content) do |arg| + expect(arg).to match(/^\s*DEVICE=eth0\s*$/) + expect(arg).to match(/^\s*IPADDR=10\.0\.0\.1\s*$/) + expect(arg).to match(/^\s*NETMASK=255\.255\.254\.0\s*$/) end - @config.should_receive(:run_action).with(:create) - @config.should_receive(:updated?).and_return(true) + expect(@config).to receive(:run_action).with(:create) + expect(@config).to receive(:updated?).and_return(true) @provider.run_action(:add) end end @@ -63,10 +63,10 @@ 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) - @config.should_receive(:run_action).with(:delete) - @config.should_receive(:updated?).and_return(true) + allow(@provider).to receive(:load_current_resource) + allow(@provider).to receive(:run_command) + expect(@config).to receive(:run_action).with(:delete) + expect(@config).to receive(:updated?).and_return(true) @provider.run_action(:delete) end end diff --git a/spec/unit/provider/ifconfig_spec.rb b/spec/unit/provider/ifconfig_spec.rb index b09e365c65..126112dd43 100644 --- a/spec/unit/provider/ifconfig_spec.rb +++ b/spec/unit/provider/ifconfig_spec.rb @@ -43,39 +43,39 @@ describe Chef::Provider::Ifconfig do describe Chef::Provider::Ifconfig, "load_current_resource" do before do status = double("Status", :exitstatus => 1) - @provider.should_receive(:popen4).and_return status + expect(@provider).to receive(:popen4).and_return status @provider.load_current_resource end it "should track state of ifconfig failure." do - @provider.instance_variable_get("@status").exitstatus.should_not == 0 + expect(@provider.instance_variable_get("@status").exitstatus).not_to eq(0) end it "should thrown an exception when ifconfig fails" do @provider.define_resource_requirements - lambda { @provider.process_resource_requirements }.should raise_error Chef::Exceptions::Ifconfig + expect { @provider.process_resource_requirements }.to raise_error Chef::Exceptions::Ifconfig end end 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) + allow(@provider).to receive(: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) - @provider.should_receive(:generate_config) + expect(@provider).to receive(:run_command).with(:command => command) + expect(@provider).to receive(:generate_config) @provider.run_action(:add) - @new_resource.should be_updated + expect(@new_resource).to be_updated end it "should not add an interface if it already exists" do - @provider.stub(:load_current_resource) - @provider.should_not_receive(:run_command) + allow(@provider).to receive(:load_current_resource) + expect(@provider).not_to receive(:run_command) @current_resource.inet_addr "10.0.0.1" - @provider.should_receive(:generate_config) + expect(@provider).to receive(:generate_config) @provider.run_action(:add) - @new_resource.should_not be_updated + expect(@new_resource).not_to be_updated end #We are not testing this case with the assumption that anyone writing the cookbook would not make a typo == lo @@ -86,95 +86,95 @@ 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) + allow(@provider).to receive(: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) - @provider.should_not_receive(:generate_config) + expect(@provider).to receive(:run_command).with(:command => command) + expect(@provider).not_to receive(:generate_config) @provider.run_action(:enable) - @new_resource.should be_updated + expect(@new_resource).to be_updated end it "should not enable interface if it already exists" do - @provider.stub(:load_current_resource) - @provider.should_not_receive(:run_command) + allow(@provider).to receive(:load_current_resource) + expect(@provider).not_to receive(:run_command) @current_resource.inet_addr "10.0.0.1" - @provider.should_not_receive(:generate_config) + expect(@provider).not_to receive(:generate_config) @provider.run_action(:enable) - @new_resource.should_not be_updated + expect(@new_resource).not_to be_updated end end describe Chef::Provider::Ifconfig, "action_delete" do it "should delete interface if it exists" do - @provider.stub(:load_current_resource) + allow(@provider).to receive(:load_current_resource) @current_resource.device "eth0" command = "ifconfig #{@new_resource.device} down" - @provider.should_receive(:run_command).with(:command => command) - @provider.should_receive(:delete_config) + expect(@provider).to receive(:run_command).with(:command => command) + expect(@provider).to receive(:delete_config) @provider.run_action(:delete) - @new_resource.should be_updated + expect(@new_resource).to be_updated end it "should not delete interface if it does not exist" do - @provider.stub(:load_current_resource) - @provider.should_not_receive(:run_command) - @provider.should_receive(:delete_config) + allow(@provider).to receive(:load_current_resource) + expect(@provider).not_to receive(:run_command) + expect(@provider).to receive(:delete_config) @provider.run_action(:delete) - @new_resource.should_not be_updated + expect(@new_resource).not_to be_updated end end describe Chef::Provider::Ifconfig, "action_disable" do it "should disable interface if it exists" do - @provider.stub(:load_current_resource) + allow(@provider).to receive(:load_current_resource) @current_resource.device "eth0" command = "ifconfig #{@new_resource.device} down" - @provider.should_receive(:run_command).with(:command => command) - @provider.should_not_receive(:delete_config) + expect(@provider).to receive(:run_command).with(:command => command) + expect(@provider).not_to receive(:delete_config) @provider.run_action(:disable) - @new_resource.should be_updated + expect(@new_resource).to be_updated end it "should not delete interface if it does not exist" do - @provider.stub(:load_current_resource) - @provider.should_not_receive(:run_command) - @provider.should_not_receive(:delete_config) + allow(@provider).to receive(:load_current_resource) + expect(@provider).not_to receive(:run_command) + expect(@provider).not_to receive(:delete_config) @provider.run_action(:disable) - @new_resource.should_not be_updated + expect(@new_resource).not_to be_updated end end describe Chef::Provider::Ifconfig, "action_delete" do it "should delete interface of it exists" do - @provider.stub(:load_current_resource) + allow(@provider).to receive(:load_current_resource) @current_resource.device "eth0" command = "ifconfig #{@new_resource.device} down" - @provider.should_receive(:run_command).with(:command => command) - @provider.should_receive(:delete_config) + expect(@provider).to receive(:run_command).with(:command => command) + expect(@provider).to receive(:delete_config) @provider.run_action(:delete) - @new_resource.should be_updated + expect(@new_resource).to be_updated end 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) + allow(@provider).to receive(:load_current_resource) # This is so that nothing actually runs - @provider.should_not_receive(:run_command) - @provider.should_receive(:delete_config) + expect(@provider).not_to receive(:run_command) + expect(@provider).to receive(:delete_config) @provider.run_action(:delete) - @new_resource.should_not be_updated + expect(@new_resource).not_to be_updated end end end diff --git a/spec/unit/provider/link_spec.rb b/spec/unit/provider/link_spec.rb index 2f0a5f2020..3ae8a71cff 100644 --- a/spec/unit/provider/link_spec.rb +++ b/spec/unit/provider/link_spec.rb @@ -45,36 +45,36 @@ describe Chef::Resource::Link, :not_supported_on_win2k3 do describe "when the target is a symlink" do before(:each) do lstat = double("stats", :ino => 5) - lstat.stub(:uid).and_return(501) - lstat.stub(:gid).and_return(501) - lstat.stub(:mode).and_return(0777) - File.stub(:lstat).with("#{CHEF_SPEC_DATA}/fofile-link").and_return(lstat) - provider.file_class.stub(:symlink?).with("#{CHEF_SPEC_DATA}/fofile-link").and_return(true) - provider.file_class.stub(:readlink).with("#{CHEF_SPEC_DATA}/fofile-link").and_return("#{CHEF_SPEC_DATA}/fofile") + allow(lstat).to receive(:uid).and_return(501) + allow(lstat).to receive(:gid).and_return(501) + allow(lstat).to receive(:mode).and_return(0777) + allow(File).to receive(:lstat).with("#{CHEF_SPEC_DATA}/fofile-link").and_return(lstat) + allow(provider.file_class).to receive(:symlink?).with("#{CHEF_SPEC_DATA}/fofile-link").and_return(true) + allow(provider.file_class).to receive(:readlink).with("#{CHEF_SPEC_DATA}/fofile-link").and_return("#{CHEF_SPEC_DATA}/fofile") end describe "to a file that exists" do before do - File.stub(:exist?).with("#{CHEF_SPEC_DATA}/fofile-link").and_return(true) + allow(File).to receive(:exist?).with("#{CHEF_SPEC_DATA}/fofile-link").and_return(true) new_resource.owner 501 # only loaded in current_resource if present in new new_resource.group 501 provider.load_current_resource end it "should set the symlink target" do - provider.current_resource.target_file.should == "#{CHEF_SPEC_DATA}/fofile-link" + expect(provider.current_resource.target_file).to eq("#{CHEF_SPEC_DATA}/fofile-link") end it "should set the link type" do - provider.current_resource.link_type.should == :symbolic + expect(provider.current_resource.link_type).to eq(:symbolic) end it "should update the source of the existing link with the links target" do - paths_eql?(provider.current_resource.to, "#{CHEF_SPEC_DATA}/fofile").should be_true + expect(paths_eql?(provider.current_resource.to, "#{CHEF_SPEC_DATA}/fofile")).to be_true end it "should set the owner" do - provider.current_resource.owner.should == 501 + expect(provider.current_resource.owner).to eq(501) end it "should set the group" do - provider.current_resource.group.should == 501 + expect(provider.current_resource.group).to eq(501) end # We test create in unit tests because there is no other way to ensure @@ -87,7 +87,7 @@ describe Chef::Resource::Link, :not_supported_on_win2k3 do result end it 'create does no work' do - provider.access_controls.should_not_receive(:set_all) + expect(provider.access_controls).not_to receive(:set_all) provider.run_action(:create) end end @@ -95,139 +95,139 @@ 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") + allow(File).to receive(:exist?).with("#{CHEF_SPEC_DATA}/fofile-link").and_return(false) + allow(provider.file_class).to receive(:symlink?).with("#{CHEF_SPEC_DATA}/fofile-link").and_return(true) + allow(provider.file_class).to receive(: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 end it "should set the symlink target" do - provider.current_resource.target_file.should == "#{CHEF_SPEC_DATA}/fofile-link" + expect(provider.current_resource.target_file).to eq("#{CHEF_SPEC_DATA}/fofile-link") end it "should set the link type" do - provider.current_resource.link_type.should == :symbolic + expect(provider.current_resource.link_type).to eq(:symbolic) end it "should update the source of the existing link to the link's target" do - paths_eql?(provider.current_resource.to, "#{CHEF_SPEC_DATA}/fofile").should be_true + expect(paths_eql?(provider.current_resource.to, "#{CHEF_SPEC_DATA}/fofile")).to be_true end it "should not set the owner" do - provider.current_resource.owner.should be_nil + expect(provider.current_resource.owner).to be_nil end it "should not set the group" do - provider.current_resource.group.should be_nil + expect(provider.current_resource.group).to be_nil end end end 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) + allow(File).to receive(:exists?).with("#{CHEF_SPEC_DATA}/fofile-link").and_return(false) + allow(provider.file_class).to receive(:symlink?).with("#{CHEF_SPEC_DATA}/fofile-link").and_return(false) provider.load_current_resource end it "should set the symlink target" do - provider.current_resource.target_file.should == "#{CHEF_SPEC_DATA}/fofile-link" + expect(provider.current_resource.target_file).to eq("#{CHEF_SPEC_DATA}/fofile-link") end it "should update the source of the existing link to nil" do - provider.current_resource.to.should be_nil + expect(provider.current_resource.to).to be_nil end it "should not set the owner" do - provider.current_resource.owner.should == nil + expect(provider.current_resource.owner).to eq(nil) end it "should not set the group" do - provider.current_resource.group.should == nil + expect(provider.current_resource.group).to eq(nil) end end describe "when the target is a regular old file" do before do stat = double("stats", :ino => 5) - stat.stub(:uid).and_return(501) - stat.stub(:gid).and_return(501) - stat.stub(:mode).and_return(0755) - provider.file_class.stub(:stat).with("#{CHEF_SPEC_DATA}/fofile-link").and_return(stat) + allow(stat).to receive(:uid).and_return(501) + allow(stat).to receive(:gid).and_return(501) + allow(stat).to receive(:mode).and_return(0755) + allow(provider.file_class).to receive(: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) + allow(File).to receive(:exists?).with("#{CHEF_SPEC_DATA}/fofile-link").and_return(true) + allow(provider.file_class).to receive(: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) + allow(File).to receive(:exists?).with("#{CHEF_SPEC_DATA}/fofile").and_return(false) provider.load_current_resource end it "should set the symlink target" do - provider.current_resource.target_file.should == "#{CHEF_SPEC_DATA}/fofile-link" + expect(provider.current_resource.target_file).to eq("#{CHEF_SPEC_DATA}/fofile-link") end it "should update the current source of the existing link with an empty string" do - provider.current_resource.to.should == '' + expect(provider.current_resource.to).to eq('') end it "should not set the owner" do - provider.current_resource.owner.should == nil + expect(provider.current_resource.owner).to eq(nil) end it "should not set the group" do - provider.current_resource.group.should == nil + expect(provider.current_resource.group).to eq(nil) end end describe "and the source exists" do before do stat = double("stats", :ino => 6) - stat.stub(:uid).and_return(502) - stat.stub(:gid).and_return(502) - stat.stub(:mode).and_return(0644) + allow(stat).to receive(:uid).and_return(502) + allow(stat).to receive(:gid).and_return(502) + allow(stat).to receive(:mode).and_return(0644) - provider.file_class.stub(:stat).with("#{CHEF_SPEC_DATA}/fofile").and_return(stat) + allow(provider.file_class).to receive(:stat).with("#{CHEF_SPEC_DATA}/fofile").and_return(stat) - File.stub(:exists?).with("#{CHEF_SPEC_DATA}/fofile").and_return(true) + allow(File).to receive(:exists?).with("#{CHEF_SPEC_DATA}/fofile").and_return(true) provider.load_current_resource end it "should set the symlink target" do - provider.current_resource.target_file.should == "#{CHEF_SPEC_DATA}/fofile-link" + expect(provider.current_resource.target_file).to eq("#{CHEF_SPEC_DATA}/fofile-link") end it "should update the current source of the existing link with an empty string" do - provider.current_resource.to.should == '' + expect(provider.current_resource.to).to eq('') end it "should not set the owner" do - provider.current_resource.owner.should == nil + expect(provider.current_resource.owner).to eq(nil) end it "should not set the group" do - provider.current_resource.group.should == nil + expect(provider.current_resource.group).to eq(nil) end end describe "and is hardlinked to the source" do before do stat = double("stats", :ino => 5) - stat.stub(:uid).and_return(502) - stat.stub(:gid).and_return(502) - stat.stub(:mode).and_return(0644) + allow(stat).to receive(:uid).and_return(502) + allow(stat).to receive(:gid).and_return(502) + allow(stat).to receive(:mode).and_return(0644) - provider.file_class.stub(:stat).with("#{CHEF_SPEC_DATA}/fofile").and_return(stat) + allow(provider.file_class).to receive(:stat).with("#{CHEF_SPEC_DATA}/fofile").and_return(stat) - File.stub(:exists?).with("#{CHEF_SPEC_DATA}/fofile").and_return(true) + allow(File).to receive(:exists?).with("#{CHEF_SPEC_DATA}/fofile").and_return(true) provider.load_current_resource end it "should set the symlink target" do - provider.current_resource.target_file.should == "#{CHEF_SPEC_DATA}/fofile-link" + expect(provider.current_resource.target_file).to eq("#{CHEF_SPEC_DATA}/fofile-link") end it "should set the link type" do - provider.current_resource.link_type.should == :hard + expect(provider.current_resource.link_type).to eq(:hard) end it "should update the source of the existing link to the link's target" do - paths_eql?(provider.current_resource.to, "#{CHEF_SPEC_DATA}/fofile").should be_true + expect(paths_eql?(provider.current_resource.to, "#{CHEF_SPEC_DATA}/fofile")).to be_true end it "should not set the owner" do - provider.current_resource.owner.should == nil + expect(provider.current_resource.owner).to eq(nil) end it "should not set the group" do - provider.current_resource.group.should == nil + expect(provider.current_resource.group).to eq(nil) end # We test create in unit tests because there is no other way to ensure @@ -241,9 +241,9 @@ describe Chef::Resource::Link, :not_supported_on_win2k3 do result end it 'create does no work' do - provider.file_class.should_not_receive(:symlink) - provider.file_class.should_not_receive(:link) - provider.access_controls.should_not_receive(:set_all) + expect(provider.file_class).not_to receive(:symlink) + expect(provider.file_class).not_to receive(:link) + expect(provider.access_controls).not_to receive(:set_all) provider.run_action(:create) end end diff --git a/spec/unit/provider/mdadm_spec.rb b/spec/unit/provider/mdadm_spec.rb index 6595728741..ddff49da13 100644 --- a/spec/unit/provider/mdadm_spec.rb +++ b/spec/unit/provider/mdadm_spec.rb @@ -32,22 +32,22 @@ 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)) + allow(@provider).to receive(: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' + expect(@provider.current_resource.name).to eq('/dev/md1') + expect(@provider.current_resource.raid_device).to eq('/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)) + allow(@provider).to receive(: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 + expect(@provider.current_resource.exists).to 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)) + allow(@provider).to receive(: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 + expect(@provider.current_resource.exists).to be_false end 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) + allow(@provider).to receive(:load_current_resource).and_return(true) @provider.current_resource = @current_resource end @@ -63,7 +63,7 @@ describe Chef::Provider::Mdadm do it "should create the raid device if it doesnt exist" do @current_resource.exists(false) expected_command = "yes | mdadm --create /dev/md1 --level 5 --chunk=16 --metadata=0.90 --raid-devices 3 /dev/sdz1 /dev/sdz2 /dev/sdz3" - @provider.should_receive(:shell_out!).with(expected_command) + expect(@provider).to receive(:shell_out!).with(expected_command) @provider.run_action(:create) end @@ -71,25 +71,25 @@ describe Chef::Provider::Mdadm do @current_resource.exists(false) @new_resource.bitmap('grow') expected_command = "yes | mdadm --create /dev/md1 --level 5 --chunk=16 --metadata=0.90 --bitmap=grow --raid-devices 3 /dev/sdz1 /dev/sdz2 /dev/sdz3" - @provider.should_receive(:shell_out!).with(expected_command) + expect(@provider).to receive(:shell_out!).with(expected_command) @provider.run_action(:create) - @new_resource.should be_updated_by_last_action + expect(@new_resource).to be_updated_by_last_action end it "should not specify a chunksize if raid level 1" do @current_resource.exists(false) @new_resource.level 1 expected_command = "yes | mdadm --create /dev/md1 --level 1 --metadata=0.90 --raid-devices 3 /dev/sdz1 /dev/sdz2 /dev/sdz3" - @provider.should_receive(:shell_out!).with(expected_command) + expect(@provider).to receive(:shell_out!).with(expected_command) @provider.run_action(:create) - @new_resource.should be_updated_by_last_action + expect(@new_resource).to be_updated_by_last_action end it "should not create the raid device if it does exist" do @current_resource.exists(true) - @provider.should_not_receive(:shell_out!) + expect(@provider).not_to receive(:shell_out!) @provider.run_action(:create) - @new_resource.should_not be_updated_by_last_action + expect(@new_resource).not_to be_updated_by_last_action end end @@ -97,16 +97,16 @@ describe Chef::Provider::Mdadm do it "should assemble the raid device if it doesnt exist" do @current_resource.exists(false) expected_mdadm_cmd = "yes | mdadm --assemble /dev/md1 /dev/sdz1 /dev/sdz2 /dev/sdz3" - @provider.should_receive(:shell_out!).with(expected_mdadm_cmd) + expect(@provider).to receive(:shell_out!).with(expected_mdadm_cmd) @provider.run_action(:assemble) - @new_resource.should be_updated_by_last_action + expect(@new_resource).to be_updated_by_last_action end it "should not assemble the raid device if it doesnt exist" do @current_resource.exists(true) - @provider.should_not_receive(:shell_out!) + expect(@provider).not_to receive(:shell_out!) @provider.run_action(:assemble) - @new_resource.should_not be_updated_by_last_action + expect(@new_resource).not_to be_updated_by_last_action end end @@ -115,16 +115,16 @@ describe Chef::Provider::Mdadm do it "should stop the raid device if it exists" do @current_resource.exists(true) expected_mdadm_cmd = "yes | mdadm --stop /dev/md1" - @provider.should_receive(:shell_out!).with(expected_mdadm_cmd) + expect(@provider).to receive(:shell_out!).with(expected_mdadm_cmd) @provider.run_action(:stop) - @new_resource.should be_updated_by_last_action + expect(@new_resource).to be_updated_by_last_action end it "should not attempt to stop the raid device if it does not exist" do @current_resource.exists(false) - @provider.should_not_receive(:shell_out!) + expect(@provider).not_to receive(:shell_out!) @provider.run_action(:stop) - @new_resource.should_not be_updated_by_last_action + expect(@new_resource).not_to be_updated_by_last_action end end end diff --git a/spec/unit/provider/mount/aix_spec.rb b/spec/unit/provider/mount/aix_spec.rb index dcd9170e1f..cdf4e0555d 100644 --- a/spec/unit/provider/mount/aix_spec.rb +++ b/spec/unit/provider/mount/aix_spec.rb @@ -60,18 +60,18 @@ 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 + allow(::File).to receive(:exists?).with("/dev/sdz1").and_return true + allow(::File).to receive(:exists?).with("/tmp/foo").and_return true end def stub_mounted(provider, mounted_output) response = double("Mixlib::ShellOut command", :exitstatus => 0, :stdout => mounted_output, :stderr => "") - provider.should_receive(:shell_out!).with("mount").and_return(response) + expect(provider).to receive(:shell_out!).with("mount").and_return(response) end def stub_enabled(provider, enabled_output) response = double("Mixlib::ShellOut command", :exitstatus => 0, :stdout => enabled_output, :stderr => "") - provider.should_receive(:shell_out).with("lsfs -c #{@new_resource.mount_point}").and_return(response) + expect(provider).to receive(:shell_out).with("lsfs -c #{@new_resource.mount_point}").and_return(response) end def stub_mounted_enabled(provider, mounted_output, enabled_output) @@ -121,7 +121,7 @@ ENABLED it "should mount resource if it is not mounted" do stub_mounted_enabled(@provider, @unmounted_output, "") - @provider.should_receive(:shell_out!).with("mount -v #{@new_resource.fstype} #{@new_resource.device} #{@new_resource.mount_point}") + expect(@provider).to receive(:shell_out!).with("mount -v #{@new_resource.fstype} #{@new_resource.device} #{@new_resource.mount_point}") @provider.run_action(:mount) end @@ -129,7 +129,7 @@ ENABLED it "should not mount resource if it is already mounted" do stub_mounted_enabled(@provider, @mounted_output, "") - @provider.should_not_receive(:mount_fs) + expect(@provider).not_to receive(:mount_fs) @provider.run_action(:mount) end @@ -139,7 +139,7 @@ ENABLED it "should umount resource if it is already mounted" do stub_mounted_enabled(@provider, @mounted_output, "") - @provider.should_receive(:shell_out!).with("umount #{@new_resource.mount_point}") + expect(@provider).to receive(:shell_out!).with("umount #{@new_resource.mount_point}") @provider.run_action(:umount) end @@ -147,7 +147,7 @@ ENABLED it "should not umount resource if it is not mounted" do stub_mounted_enabled(@provider, @unmounted_output, "") - @provider.should_not_receive(:umount_fs) + expect(@provider).not_to receive(:umount_fs) @provider.run_action(:umount) end @@ -158,7 +158,7 @@ ENABLED @new_resource.supports({:remount => true}) stub_mounted_enabled(@provider, @mounted_output, "") - @provider.should_receive(:shell_out!).with("mount -o remount #{@new_resource.device} #{@new_resource.mount_point}") + expect(@provider).to receive(:shell_out!).with("mount -o remount #{@new_resource.device} #{@new_resource.mount_point}") @provider.run_action(:remount) end @@ -168,7 +168,7 @@ ENABLED @new_resource.options("nodev,rw") stub_mounted_enabled(@provider, @mounted_output, "") - @provider.should_receive(:shell_out!).with("mount -o remount,nodev,rw #{@new_resource.device} #{@new_resource.mount_point}") + expect(@provider).to receive(:shell_out!).with("mount -o remount,nodev,rw #{@new_resource.device} #{@new_resource.mount_point}") @provider.run_action(:remount) end @@ -179,18 +179,18 @@ 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) + allow(::File).to receive(:open).with("/etc/filesystems", "a").and_yield(filesystems) @provider.run_action(:enable) - filesystems.string.should match(%r{^/tmp/foo:\n\tdev\t\t= /dev/sdz1\n\tvfs\t\t= jfs2\n\tmount\t\t= false\n\toptions\t\t= nodev,rw\n$}) + expect(filesystems.string).to match(%r{^/tmp/foo:\n\tdev\t\t= /dev/sdz1\n\tvfs\t\t= jfs2\n\tmount\t\t= false\n\toptions\t\t= nodev,rw\n$}) end it "should not enable mount if it is mounted and already enabled and mount options are unchanged" do stub_mounted_enabled(@provider, @mounted_output, @enabled_output) @new_resource.options "rw" - @provider.should_not_receive(:enable_fs) + expect(@provider).not_to receive(:enable_fs) @provider.run_action(:enable) end @@ -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) + allow(::File).to receive(:open).with("/etc/filesystems", "r").and_return(<<-ETCFILESYSTEMS) /tmp/foo: dev = /dev/sdz1 vfs = jfs2 @@ -219,17 +219,17 @@ ENABLED ETCFILESYSTEMS filesystems = StringIO.new - ::File.stub(:open).with("/etc/filesystems", "w").and_yield(filesystems) + allow(::File).to receive(:open).with("/etc/filesystems", "w").and_yield(filesystems) @provider.run_action(:disable) - filesystems.string.should match(%r{^/tmp/abc:\s+dev\s+= /dev/sdz2\s+vfs\s+= jfs2\s+mount\s+= true\s+options\s+= rw\n$}) + expect(filesystems.string).to match(%r{^/tmp/abc:\s+dev\s+= /dev/sdz2\s+vfs\s+= jfs2\s+mount\s+= true\s+options\s+= rw\n$}) end it "should not disable mount if it is not mounted" do stub_mounted_enabled(@provider, @unmounted_output, "") - @provider.should_not_receive(:disable_fs) + expect(@provider).not_to receive(:disable_fs) @provider.run_action(:disable) end diff --git a/spec/unit/provider/mount/mount_spec.rb b/spec/unit/provider/mount/mount_spec.rb index abab7640c0..40cfbcaf39 100644 --- a/spec/unit/provider/mount/mount_spec.rb +++ b/spec/unit/provider/mount/mount_spec.rb @@ -34,30 +34,30 @@ 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" + allow(::File).to receive(:exists?).with("/dev/sdz1").and_return true + allow(::File).to receive(:exists?).with("/tmp/foo").and_return true + allow(::File).to receive(:realpath).with("/dev/sdz1").and_return "/dev/sdz1" + allow(::File).to receive(: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") + allow(@provider).to receive(:shell_out!).and_return(OpenStruct.new(:stdout => '')) + allow(::File).to receive(:foreach).with("/etc/fstab") end it "should create a current resource with the same mount point and device" do @provider.load_current_resource - @provider.current_resource.name.should == '/tmp/foo' - @provider.current_resource.mount_point.should == '/tmp/foo' - @provider.current_resource.device.should == '/dev/sdz1' + expect(@provider.current_resource.name).to eq('/tmp/foo') + expect(@provider.current_resource.mount_point).to eq('/tmp/foo') + expect(@provider.current_resource.device).to eq('/dev/sdz1') end it "should accecpt device_type :uuid", :not_supported_on_solaris do @new_resource.device_type :uuid @new_resource.device "d21afe51-a0fe-4dc6-9152-ac733763ae0a" @stdout_findfs = double("STDOUT", :first => "/dev/sdz1") - @provider.should_receive(:popen4).with("/sbin/findfs UUID=d21afe51-a0fe-4dc6-9152-ac733763ae0a").and_yield(@pid,@stdin,@stdout_findfs,@stderr).and_return(@status) + expect(@provider).to receive(:popen4).with("/sbin/findfs UUID=d21afe51-a0fe-4dc6-9152-ac733763ae0a").and_yield(@pid,@stdin,@stdout_findfs,@stderr).and_return(@status) @provider.load_current_resource() @provider.mountable? end @@ -67,28 +67,28 @@ describe Chef::Provider::Mount::Mount do "cifs" => "//cifsserver/share" }.each do |type, fs_spec| it "should detect network fs_spec (#{type})" do @new_resource.device fs_spec - @provider.network_device?.should be_true + expect(@provider.network_device?).to be_true end 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")) + allow(@provider).to receive(: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 + expect(@provider.current_resource.mounted).to be_true end end end it "should raise an error if the mount device does not exist" do - ::File.stub(:exists?).with("/dev/sdz1").and_return false - lambda { @provider.load_current_resource();@provider.mountable? }.should raise_error(Chef::Exceptions::Mount) + allow(::File).to receive(:exists?).with("/dev/sdz1").and_return false + expect { @provider.load_current_resource();@provider.mountable? }.to 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 - @provider.should_receive(:mounted?).and_return(true) - @provider.should_receive(:enabled?).and_return(true) - @provider.should_not_receive(:mountable?) + allow(::File).to receive(:exists?).with("/dev/sdz1").and_return false + expect(@provider).to receive(:mounted?).and_return(true) + expect(@provider).to receive(:enabled?).and_return(true) + expect(@provider).not_to receive(:mountable?) @provider.load_current_resource end @@ -97,51 +97,51 @@ describe Chef::Provider::Mount::Mount do @new_resource.device "d21afe51-a0fe-4dc6-9152-ac733763ae0a" status_findfs = double("Status", :exitstatus => 1) stdout_findfs = double("STDOUT", :first => nil) - @provider.should_receive(:popen4).with("/sbin/findfs UUID=d21afe51-a0fe-4dc6-9152-ac733763ae0a").and_yield(@pid,@stdin,stdout_findfs,@stderr).and_return(status_findfs) - ::File.should_receive(:exists?).with("").and_return(false) - lambda { @provider.load_current_resource();@provider.mountable? }.should raise_error(Chef::Exceptions::Mount) + expect(@provider).to receive(:popen4).with("/sbin/findfs UUID=d21afe51-a0fe-4dc6-9152-ac733763ae0a").and_yield(@pid,@stdin,stdout_findfs,@stderr).and_return(status_findfs) + expect(::File).to receive(:exists?).with("").and_return(false) + expect { @provider.load_current_resource();@provider.mountable? }.to raise_error(Chef::Exceptions::Mount) end it "should raise an error if the mount point does not exist" do - ::File.stub(:exists?).with("/tmp/foo").and_return false - lambda { @provider.load_current_resource();@provider.mountable? }.should raise_error(Chef::Exceptions::Mount) + allow(::File).to receive(:exists?).with("/tmp/foo").and_return false + expect { @provider.load_current_resource();@provider.mountable? }.to raise_error(Chef::Exceptions::Mount) end [ "tmpfs", "fuse", "cgroup" ].each do |fstype| it "does not expect the device to exist for #{fstype}" do @new_resource.fstype(fstype) @new_resource.device("whatever") - lambda { @provider.load_current_resource();@provider.mountable? }.should_not raise_error + expect { @provider.load_current_resource();@provider.mountable? }.not_to raise_error end end it "does not expect the device to exist if it's none" do @new_resource.device("none") - lambda { @provider.load_current_resource();@provider.mountable? }.should_not raise_error + expect { @provider.load_current_resource();@provider.mountable? }.not_to raise_error 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 type ext3 (rw)\n")) + allow(@provider).to receive(:shell_out!).and_return(OpenStruct.new(:stdout => "/dev/sdz1 on /tmp/foo type ext3 (rw)\n")) @provider.load_current_resource() - @provider.current_resource.mounted.should be_true + expect(@provider.current_resource.mounted).to be_true end it "should set mounted false if another mount point beginning with the same path is found in the mounts list" do - @provider.stub(:shell_out!).and_return(OpenStruct.new(:stdout => "/dev/sdz1 on /tmp/foobar type ext3 (rw)\n")) + allow(@provider).to receive(:shell_out!).and_return(OpenStruct.new(:stdout => "/dev/sdz1 on /tmp/foobar type ext3 (rw)\n")) @provider.load_current_resource() - @provider.current_resource.mounted.should be_false + expect(@provider.current_resource.mounted).to be_false end it "should set mounted true if the symlink target of the device is found in the mounts list" do # expand the target path to correct specs on Windows target = ::File.expand_path('/dev/mapper/target') - ::File.stub(:symlink?).with("#{@new_resource.device}").and_return(true) - ::File.stub(:readlink).with("#{@new_resource.device}").and_return(target) + allow(::File).to receive(:symlink?).with("#{@new_resource.device}").and_return(true) + allow(::File).to receive(:readlink).with("#{@new_resource.device}").and_return(target) - @provider.stub(:shell_out!).and_return(OpenStruct.new(:stdout => "#{target} on /tmp/foo type ext3 (rw)\n")) + allow(@provider).to receive(:shell_out!).and_return(OpenStruct.new(:stdout => "#{target} on /tmp/foo type ext3 (rw)\n")) @provider.load_current_resource() - @provider.current_resource.mounted.should be_true + expect(@provider.current_resource.mounted).to be_true end it "should set mounted true if the symlink target of the device is relative and is found in the mounts list - CHEF-4957" do @@ -150,109 +150,109 @@ describe Chef::Provider::Mount::Mount do # expand the target path to correct specs on Windows absolute_target = ::File.expand_path("/dev/xsdz1") - ::File.stub(:symlink?).with("#{@new_resource.device}").and_return(true) - ::File.stub(:readlink).with("#{@new_resource.device}").and_return(target) + allow(::File).to receive(:symlink?).with("#{@new_resource.device}").and_return(true) + allow(::File).to receive(:readlink).with("#{@new_resource.device}").and_return(target) - @provider.stub(:shell_out!).and_return(OpenStruct.new(:stdout => "#{absolute_target} on /tmp/foo type ext3 (rw)\n")) + allow(@provider).to receive(:shell_out!).and_return(OpenStruct.new(:stdout => "#{absolute_target} on /tmp/foo type ext3 (rw)\n")) @provider.load_current_resource() - @provider.current_resource.mounted.should be_true + expect(@provider.current_resource.mounted).to be_true end it "should set mounted true if the mount point is found last in the mounts list" 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)) + allow(@provider).to receive(:shell_out!).and_return(OpenStruct.new(:stdout => mount)) @provider.load_current_resource() - @provider.current_resource.mounted.should be_true + expect(@provider.current_resource.mounted).to be_true end it "should set mounted false if the mount point is not last in the mounts list" 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)) + allow(@provider).to receive(:shell_out!).and_return(OpenStruct.new(:stdout => mount)) @provider.load_current_resource() - @provider.current_resource.mounted.should be_false + expect(@provider.current_resource.mounted).to 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")) + allow(@provider).to receive(: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 + expect(@provider.current_resource.mounted).to be_false end it "should set enabled to true if the mount point is last in fstab" 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) + allow(::File).to receive(:foreach).with("/etc/fstab").and_yield(fstab1).and_yield(fstab2) @provider.load_current_resource - @provider.current_resource.enabled.should be_true + expect(@provider.current_resource.enabled).to be_true end it "should set enabled to true if the mount point is not last in fstab and mount_point is a substring of another 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) + allow(::File).to receive(:foreach).with("/etc/fstab").and_yield(fstab1).and_yield(fstab2) @provider.load_current_resource - @provider.current_resource.enabled.should be_true + expect(@provider.current_resource.enabled).to be_true end 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) + allow(::File).to receive(:symlink?).with("#{@new_resource.device}").and_return(true) + allow(::File).to receive(: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 + allow(::File).to receive(:foreach).with("/etc/fstab").and_yield fstab @provider.load_current_resource - @provider.current_resource.enabled.should be_true + expect(@provider.current_resource.enabled).to be_true end it "should set enabled to true if the symlink target is relative and is in fstab - CHEF-4957" do target = "xsdz1" - ::File.stub(:symlink?).with("#{@new_resource.device}").and_return(true) - ::File.stub(:readlink).with("#{@new_resource.device}").and_return(target) + allow(::File).to receive(:symlink?).with("#{@new_resource.device}").and_return(true) + allow(::File).to receive(: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 + allow(::File).to receive(:foreach).with("/etc/fstab").and_yield fstab @provider.load_current_resource - @provider.current_resource.enabled.should be_true + expect(@provider.current_resource.enabled).to be_true end 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 + allow(::File).to receive(:foreach).with("/etc/fstab").and_yield fstab @provider.load_current_resource - @provider.current_resource.enabled.should be_false + expect(@provider.current_resource.enabled).to be_false end 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 + allow(::File).to receive(:foreach).with("/etc/fstab").and_yield fstab @provider.load_current_resource - @provider.current_resource.enabled.should be_false + expect(@provider.current_resource.enabled).to be_false end 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) + allow(::File).to receive(:foreach).with("/etc/fstab").and_yield(line_1).and_yield(line_2) @provider.load_current_resource - @provider.current_resource.enabled.should be_false + expect(@provider.current_resource.enabled).to be_false end it "should not mangle the mount options if the device in fstab is a symlink" do @@ -260,26 +260,26 @@ 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) + allow(::File).to receive(:symlink?).with(@new_resource.device).and_return(true) + allow(::File).to receive(: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 + allow(::File).to receive(:foreach).with("/etc/fstab").and_yield fstab @provider.load_current_resource - @provider.current_resource.options.should eq(options.split(',')) + expect(@provider.current_resource.options).to eq(options.split(',')) end it "should not mangle the mount options if the symlink target is in fstab" do target = ::File.expand_path("/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) + allow(::File).to receive(:symlink?).with(@new_resource.device).and_return(true) + allow(::File).to receive(: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 + allow(::File).to receive(:foreach).with("/etc/fstab").and_yield fstab @provider.load_current_resource - @provider.current_resource.options.should eq(options.split(',')) + expect(@provider.current_resource.options).to eq(options.split(',')) end end @@ -295,14 +295,14 @@ describe Chef::Provider::Mount::Mount do describe "mount_fs" do it "should mount the filesystem if it is not mounted" do - @provider.should_receive(:shell_out!).with("mount -t ext3 -o defaults /dev/sdz1 /tmp/foo") + expect(@provider).to receive(:shell_out!).with("mount -t ext3 -o defaults /dev/sdz1 /tmp/foo") @provider.mount_fs() end it "should mount the filesystem with options if options were passed" do options = "rw,noexec,noauto" @new_resource.options(%w{rw noexec noauto}) - @provider.should_receive(:shell_out!).with("mount -t ext3 -o rw,noexec,noauto /dev/sdz1 /tmp/foo") + expect(@provider).to receive(:shell_out!).with("mount -t ext3 -o rw,noexec,noauto /dev/sdz1 /tmp/foo") @provider.mount_fs() end @@ -310,16 +310,16 @@ describe Chef::Provider::Mount::Mount do @new_resource.device "d21afe51-a0fe-4dc6-9152-ac733763ae0a" @new_resource.device_type :uuid @stdout_findfs = double("STDOUT", :first => "/dev/sdz1") - @provider.stub(:popen4).with("/sbin/findfs UUID=d21afe51-a0fe-4dc6-9152-ac733763ae0a").and_yield(@pid,@stdin,@stdout_findfs,@stderr).and_return(@status) + allow(@provider).to receive(:popen4).with("/sbin/findfs UUID=d21afe51-a0fe-4dc6-9152-ac733763ae0a").and_yield(@pid,@stdin,@stdout_findfs,@stderr).and_return(@status) @stdout_mock = double('stdout mock') - @stdout_mock.stub(:each).and_yield("#{@new_resource.device} on #{@new_resource.mount_point}") - @provider.should_receive(:shell_out!).with("mount -t #{@new_resource.fstype} -o defaults -U #{@new_resource.device} #{@new_resource.mount_point}").and_return(@stdout_mock) + allow(@stdout_mock).to receive(:each).and_yield("#{@new_resource.device} on #{@new_resource.mount_point}") + expect(@provider).to 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) - @provider.should_not_receive(:shell_out!) + allow(@current_resource).to receive(:mounted).and_return(true) + expect(@provider).not_to receive(:shell_out!) @provider.mount_fs() end @@ -328,13 +328,13 @@ describe Chef::Provider::Mount::Mount do describe "umount_fs" do it "should umount the filesystem if it is mounted" do @current_resource.mounted(true) - @provider.should_receive(:shell_out!).with("umount /tmp/foo") + expect(@provider).to receive(:shell_out!).with("umount /tmp/foo") @provider.umount_fs() end it "should not umount the filesystem if it is not mounted" do @current_resource.mounted(false) - @provider.should_not_receive(:shell_out!) + expect(@provider).not_to receive(:shell_out!) @provider.umount_fs() end end @@ -343,7 +343,7 @@ describe Chef::Provider::Mount::Mount do it "should use mount -o remount if remount is supported" do @new_resource.supports({:remount => true}) @current_resource.mounted(true) - @provider.should_receive(:shell_out!).with("mount -o remount,defaults #{@new_resource.mount_point}") + expect(@provider).to receive(:shell_out!).with("mount -o remount,defaults #{@new_resource.mount_point}") @provider.remount_fs end @@ -352,24 +352,24 @@ describe Chef::Provider::Mount::Mount do options = "rw,noexec,noauto" @new_resource.options(%w{rw noexec noauto}) @current_resource.mounted(true) - @provider.should_receive(:shell_out!).with("mount -o remount,rw,noexec,noauto #{@new_resource.mount_point}") + expect(@provider).to receive(:shell_out!).with("mount -o remount,rw,noexec,noauto #{@new_resource.mount_point}") @provider.remount_fs end it "should umount and mount if remount is not supported" do @new_resource.supports({:remount => false}) @current_resource.mounted(true) - @provider.should_receive(:umount_fs) - @provider.should_receive(:sleep).with(1) - @provider.should_receive(:mount_fs) + expect(@provider).to receive(:umount_fs) + expect(@provider).to receive(:sleep).with(1) + expect(@provider).to receive(:mount_fs) @provider.remount_fs() end it "should not try to remount at all if mounted is false" do @current_resource.mounted(false) - @provider.should_not_receive(:shell_out!) - @provider.should_not_receive(:umount_fs) - @provider.should_not_receive(:mount_fs) + expect(@provider).not_to receive(:shell_out!) + expect(@provider).not_to receive(:umount_fs) + expect(@provider).not_to receive(:mount_fs) @provider.remount_fs() end end @@ -379,9 +379,9 @@ describe Chef::Provider::Mount::Mount do @current_resource.enabled(false) @fstab = StringIO.new - ::File.stub(:open).with("/etc/fstab", "a").and_yield(@fstab) + allow(::File).to receive(: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*$}) + expect(@fstab.string).to match(%r{^/dev/sdz1\s+/tmp/foo\s+ext3\s+defaults\s+0\s+2\s*$}) end it "should not enable if enabled is true and resources match" do @@ -390,7 +390,7 @@ describe Chef::Provider::Mount::Mount do @current_resource.options(["defaults"]) @current_resource.dump(0) @current_resource.pass(2) - ::File.should_not_receive(:open).with("/etc/fstab", "a") + expect(::File).not_to receive(:open).with("/etc/fstab", "a") @provider.enable_fs end @@ -402,9 +402,9 @@ describe Chef::Provider::Mount::Mount do @current_resource.dump(0) @current_resource.pass(2) @fstab = StringIO.new - ::File.stub(:readlines).and_return([]) - ::File.should_receive(:open).once.with("/etc/fstab", "w").and_yield(@fstab) - ::File.should_receive(:open).once.with("/etc/fstab", "a").and_yield(@fstab) + allow(::File).to receive(:readlines).and_return([]) + expect(::File).to receive(:open).once.with("/etc/fstab", "w").and_yield(@fstab) + expect(::File).to receive(:open).once.with("/etc/fstab", "a").and_yield(@fstab) @provider.enable_fs end @@ -418,13 +418,13 @@ 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) + allow(::File).to receive(:readlines).with("/etc/fstab").and_return(@fstab_read) @fstab_write = StringIO.new - ::File.stub(:open).with("/etc/fstab", "w").and_yield(@fstab_write) + allow(::File).to receive(:open).with("/etc/fstab", "w").and_yield(@fstab_write) @provider.disable_fs - @fstab_write.string.should match(Regexp.escape(other_mount)) - @fstab_write.string.should_not match(Regexp.escape(this_mount)) + expect(@fstab_write.string).to match(Regexp.escape(other_mount)) + expect(@fstab_write.string).not_to match(Regexp.escape(this_mount)) end it "should disable if enabled is true and ignore commented lines" do @@ -435,37 +435,37 @@ 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) + allow(::File).to receive(:readlines).with("/etc/fstab").and_return(fstab_read) + allow(::File).to receive(: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$}) - fstab_write.string.should match(%r{^#/dev/sdz1 /tmp/foo ext3 defaults 1 2$}) - fstab_write.string.should_not match(%r{^/dev/sdz1 /tmp/foo ext3 defaults 1 2$}) + expect(fstab_write.string).to match(%r{^/dev/sdy1 /tmp/foo ext3 defaults 1 2$}) + expect(fstab_write.string).to match(%r{^#/dev/sdz1 /tmp/foo ext3 defaults 1 2$}) + expect(fstab_write.string).not_to match(%r{^/dev/sdz1 /tmp/foo ext3 defaults 1 2$}) end it "should disable only the last entry if enabled is true" do - @current_resource.stub(:enabled).and_return(true) + allow(@current_resource).to receive(: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", "/dev/sdz1 /tmp/foobar 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) + allow(::File).to receive(:readlines).with("/etc/fstab").and_return(fstab_read) + allow(::File).to receive(: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" + + expect(fstab_write.string).to eq("/dev/sdz1 /tmp/foo ext3 defaults 1 2\n" + "/dev/sdy1 /tmp/foo ext3 defaults 1 2\n" + - "/dev/sdz1 /tmp/foobar ext3 defaults 1 2\n" + "/dev/sdz1 /tmp/foobar ext3 defaults 1 2\n") end it "should not disable if enabled is false" do - @current_resource.stub(:enabled).and_return(false) + allow(@current_resource).to receive(:enabled).and_return(false) - ::File.stub(:readlines).with("/etc/fstab").and_return([]) - ::File.should_not_receive(:open).and_yield(@fstab) + allow(::File).to receive(:readlines).with("/etc/fstab").and_return([]) + expect(::File).not_to receive(:open).and_yield(@fstab) @provider.disable_fs end diff --git a/spec/unit/provider/mount/solaris_spec.rb b/spec/unit/provider/mount/solaris_spec.rb index 50ddfaa28d..93321a8ad6 100644 --- a/spec/unit/provider/mount/solaris_spec.rb +++ b/spec/unit/provider/mount/solaris_spec.rb @@ -92,37 +92,37 @@ describe Chef::Provider::Mount::Solaris, :unix_only do before do stub_const("Chef::Provider::Mount::Solaris::VFSTAB", vfstab_file.path ) - provider.stub(:shell_out!).with("mount -v").and_return(OpenStruct.new(:stdout => mount_output)) - File.stub(:symlink?).with(device).and_return(false) - File.stub(:exist?).and_call_original # Tempfile.open on ruby 1.8.7 calls File.exist? - File.stub(:exist?).with(device).and_return(true) - File.stub(:exist?).with(mountpoint).and_return(true) + allow(provider).to receive(:shell_out!).with("mount -v").and_return(OpenStruct.new(:stdout => mount_output)) + allow(File).to receive(:symlink?).with(device).and_return(false) + allow(File).to receive(:exist?).and_call_original # Tempfile.open on ruby 1.8.7 calls File.exist? + allow(File).to receive(:exist?).with(device).and_return(true) + allow(File).to receive(:exist?).with(mountpoint).and_return(true) expect(File).to_not receive(:exists?) end describe "#define_resource_requirements" do before do # we're not testing the actual actions so stub them all out - [:mount_fs, :umount_fs, :remount_fs, :enable_fs, :disable_fs].each {|m| provider.stub(m) } + [:mount_fs, :umount_fs, :remount_fs, :enable_fs, :disable_fs].each {|m| allow(provider).to receive(m) } end it "run_action(:mount) should raise an error if the device does not exist" do - File.stub(:exist?).with(device).and_return(false) + allow(File).to receive(:exist?).with(device).and_return(false) expect { provider.run_action(:mount) }.to raise_error(Chef::Exceptions::Mount) end it "run_action(:remount) should raise an error if the device does not exist" do - File.stub(:exist?).with(device).and_return(false) + allow(File).to receive(:exist?).with(device).and_return(false) expect { provider.run_action(:remount) }.to raise_error(Chef::Exceptions::Mount) end it "run_action(:mount) should raise an error if the mountpoint does not exist" do - File.stub(:exist?).with(mountpoint).and_return false + allow(File).to receive(:exist?).with(mountpoint).and_return false expect { provider.run_action(:mount) }.to raise_error(Chef::Exceptions::Mount) end it "run_action(:remount) should raise an error if the mountpoint does not exist" do - File.stub(:exist?).with(mountpoint).and_return false + allow(File).to receive(:exist?).with(mountpoint).and_return false expect { provider.run_action(:remount) }.to raise_error(Chef::Exceptions::Mount) end @@ -160,23 +160,23 @@ describe Chef::Provider::Mount::Solaris, :unix_only do end it "should set the name on the current_resource" do - provider.current_resource.name.should == mountpoint + expect(provider.current_resource.name).to eq(mountpoint) end it "should set the mount_point on the current_resource" do - provider.current_resource.mount_point.should == mountpoint + expect(provider.current_resource.mount_point).to eq(mountpoint) end it "should set the device on the current_resource" do - provider.current_resource.device.should == device + expect(provider.current_resource.device).to eq(device) end it "should set the fsck_device on the current_resource" do - provider.current_resource.fsck_device.should == fsck_device + expect(provider.current_resource.fsck_device).to eq(fsck_device) end it "should set the device_type on the current_resource" do - provider.current_resource.device_type.should == device_type + expect(provider.current_resource.device_type).to eq(device_type) end it "should set the mounted status on the current_resource" do @@ -200,12 +200,12 @@ describe Chef::Provider::Mount::Solaris, :unix_only do end it "should not throw an exception when the device does not exist - CHEF-1565" do - File.stub(:exist?).with(device).and_return(false) + allow(File).to receive(:exist?).with(device).and_return(false) expect { provider.load_current_resource }.to_not raise_error end it "should not throw an exception when the mount point does not exist" do - File.stub(:exist?).with(mountpoint).and_return false + allow(File).to receive(:exist?).with(mountpoint).and_return false expect { provider.load_current_resource }.to_not raise_error end end @@ -288,19 +288,19 @@ describe Chef::Provider::Mount::Solaris, :unix_only do end it "should set the name on the current_resource" do - provider.current_resource.name.should == mountpoint + expect(provider.current_resource.name).to eq(mountpoint) end it "should set the mount_point on the current_resource" do - provider.current_resource.mount_point.should == mountpoint + expect(provider.current_resource.mount_point).to eq(mountpoint) end it "should set the device on the current_resource" do - provider.current_resource.device.should == device + expect(provider.current_resource.device).to eq(device) end it "should set the device_type on the current_resource" do - provider.current_resource.device_type.should == device_type + expect(provider.current_resource.device_type).to eq(device_type) end it "should set the mounted status on the current_resource" do @@ -347,8 +347,8 @@ describe Chef::Provider::Mount::Solaris, :unix_only do } before do - File.should_receive(:symlink?).with(device).at_least(:once).and_return(true) - File.should_receive(:readlink).with(device).at_least(:once).and_return(target) + expect(File).to receive(:symlink?).with(device).at_least(:once).and_return(true) + expect(File).to receive(:readlink).with(device).at_least(:once).and_return(target) provider.load_current_resource() end @@ -384,8 +384,8 @@ describe Chef::Provider::Mount::Solaris, :unix_only do } before do - File.should_receive(:symlink?).with(device).at_least(:once).and_return(true) - File.should_receive(:readlink).with(device).at_least(:once).and_return(target) + expect(File).to receive(:symlink?).with(device).at_least(:once).and_return(true) + expect(File).to receive(:readlink).with(device).at_least(:once).and_return(target) provider.load_current_resource() end @@ -412,7 +412,7 @@ describe Chef::Provider::Mount::Solaris, :unix_only do } it "should set mounted true" do provider.load_current_resource() - provider.current_resource.mounted.should be_true + expect(provider.current_resource.mounted).to be_true end end @@ -425,7 +425,7 @@ describe Chef::Provider::Mount::Solaris, :unix_only do } it "should set mounted false" do provider.load_current_resource() - provider.current_resource.mounted.should be_false + expect(provider.current_resource.mounted).to be_false end end @@ -437,7 +437,7 @@ describe Chef::Provider::Mount::Solaris, :unix_only do } it "should set mounted false" do provider.load_current_resource() - provider.current_resource.mounted.should be_false + expect(provider.current_resource.mounted).to be_false end end @@ -449,7 +449,7 @@ describe Chef::Provider::Mount::Solaris, :unix_only do } it "should set mounted false" do provider.load_current_resource() - provider.current_resource.mounted.should be_false + expect(provider.current_resource.mounted).to be_false end end @@ -463,7 +463,7 @@ describe Chef::Provider::Mount::Solaris, :unix_only do it "should set enabled to true" do provider.load_current_resource - provider.current_resource.enabled.should be_true + expect(provider.current_resource.enabled).to be_true end end @@ -477,7 +477,7 @@ describe Chef::Provider::Mount::Solaris, :unix_only do it "should set enabled to true" do provider.load_current_resource - provider.current_resource.enabled.should be_true + expect(provider.current_resource.enabled).to be_true end end @@ -491,7 +491,7 @@ describe Chef::Provider::Mount::Solaris, :unix_only do it "should set enabled to false" do provider.load_current_resource - provider.current_resource.enabled.should be_false + expect(provider.current_resource.enabled).to be_false end end @@ -504,7 +504,7 @@ describe Chef::Provider::Mount::Solaris, :unix_only do it "should set enabled to false" do provider.load_current_resource - provider.current_resource.enabled.should be_false + expect(provider.current_resource.enabled).to be_false end end @@ -517,7 +517,7 @@ describe Chef::Provider::Mount::Solaris, :unix_only do it "should set enabled to false" do provider.load_current_resource - provider.current_resource.enabled.should be_false + expect(provider.current_resource.enabled).to be_false end end @@ -530,7 +530,7 @@ describe Chef::Provider::Mount::Solaris, :unix_only do it "should set enabled to false" do provider.load_current_resource - provider.current_resource.enabled.should be_false + expect(provider.current_resource.enabled).to be_false end end end @@ -538,28 +538,28 @@ describe Chef::Provider::Mount::Solaris, :unix_only do context "after the mount's state has been discovered" do describe "mount_fs" do it "should mount the filesystem" do - provider.should_receive(:shell_out!).with("mount -F #{fstype} -o defaults #{device} #{mountpoint}") + expect(provider).to receive(:shell_out!).with("mount -F #{fstype} -o defaults #{device} #{mountpoint}") provider.mount_fs() end it "should mount the filesystem with options if options were passed" do options = "logging,noatime,largefiles,nosuid,rw,quota" new_resource.options(options.split(/,/)) - provider.should_receive(:shell_out!).with("mount -F #{fstype} -o #{options} #{device} #{mountpoint}") + expect(provider).to receive(:shell_out!).with("mount -F #{fstype} -o #{options} #{device} #{mountpoint}") provider.mount_fs() end it "should delete the 'noauto' magic option" do options = "rw,noauto" new_resource.options(%w{rw noauto}) - provider.should_receive(:shell_out!).with("mount -F #{fstype} -o rw #{device} #{mountpoint}") + expect(provider).to receive(:shell_out!).with("mount -F #{fstype} -o rw #{device} #{mountpoint}") provider.mount_fs() end end describe "umount_fs" do it "should umount the filesystem if it is mounted" do - provider.should_receive(:shell_out!).with("umount #{mountpoint}") + expect(provider).to receive(:shell_out!).with("umount #{mountpoint}") provider.umount_fs() end end @@ -567,7 +567,7 @@ describe Chef::Provider::Mount::Solaris, :unix_only do describe "remount_fs without options and do not mount at boot" do it "should use mount -o remount" do new_resource.options(%w{noauto}) - provider.should_receive(:shell_out!).with("mount -o remount #{new_resource.mount_point}") + expect(provider).to receive(:shell_out!).with("mount -o remount #{new_resource.mount_point}") provider.remount_fs end end @@ -575,7 +575,7 @@ describe Chef::Provider::Mount::Solaris, :unix_only do describe "remount_fs with options and do not mount at boot" do it "should use mount -o remount,rw" do new_resource.options(%w{rw noauto}) - provider.should_receive(:shell_out!).with("mount -o remount,rw #{new_resource.mount_point}") + expect(provider).to receive(:shell_out!).with("mount -o remount,rw #{new_resource.mount_point}") provider.remount_fs end end @@ -583,7 +583,7 @@ describe Chef::Provider::Mount::Solaris, :unix_only do describe "remount_fs with options and mount at boot" do it "should use mount -o remount,rw" do new_resource.options(%w{rw}) - provider.should_receive(:shell_out!).with("mount -o remount,rw #{new_resource.mount_point}") + expect(provider).to receive(:shell_out!).with("mount -o remount,rw #{new_resource.mount_point}") provider.remount_fs end end @@ -591,7 +591,7 @@ describe Chef::Provider::Mount::Solaris, :unix_only do describe "remount_fs without options and mount at boot" do it "should use mount -o remount" do new_resource.options([]) - provider.should_receive(:shell_out!).with("mount -o remount #{new_resource.mount_point}") + expect(provider).to receive(:shell_out!).with("mount -o remount #{new_resource.mount_point}") provider.remount_fs end end @@ -605,17 +605,17 @@ describe Chef::Provider::Mount::Solaris, :unix_only do let(:vfstab_file_contents) { [other_mount].join("\n") } before do - provider.stub(:etc_tempfile).and_yield(Tempfile.open("vfstab")) + allow(provider).to receive(:etc_tempfile).and_yield(Tempfile.open("vfstab")) provider.load_current_resource provider.enable_fs end it "should leave the other mountpoint alone" do - IO.read(vfstab_file.path).should match(/^#{Regexp.escape(other_mount)}/) + expect(IO.read(vfstab_file.path)).to match(/^#{Regexp.escape(other_mount)}/) end it "should enable the mountpoint we care about" do - IO.read(vfstab_file.path).should match(/^#{Regexp.escape(this_mount)}/) + expect(IO.read(vfstab_file.path)).to match(/^#{Regexp.escape(this_mount)}/) end end @@ -629,17 +629,17 @@ describe Chef::Provider::Mount::Solaris, :unix_only do let(:vfstab_file_contents) { [other_mount].join("\n") } before do - provider.stub(:etc_tempfile).and_yield(Tempfile.open("vfstab")) + allow(provider).to receive(:etc_tempfile).and_yield(Tempfile.open("vfstab")) provider.load_current_resource provider.enable_fs end it "should leave the other mountpoint alone" do - IO.read(vfstab_file.path).should match(/^#{Regexp.escape(other_mount)}/) + expect(IO.read(vfstab_file.path)).to match(/^#{Regexp.escape(other_mount)}/) end it "should enable the mountpoint we care about" do - IO.read(vfstab_file.path).should match(/^#{Regexp.escape(this_mount)}/) + expect(IO.read(vfstab_file.path)).to match(/^#{Regexp.escape(this_mount)}/) end end @@ -653,18 +653,18 @@ describe Chef::Provider::Mount::Solaris, :unix_only do let(:vfstab_file_contents) { [existing_mount].join("\n") } before do - provider.stub(:etc_tempfile).and_yield(Tempfile.open("vfstab")) + allow(provider).to receive(:etc_tempfile).and_yield(Tempfile.open("vfstab")) provider.load_current_resource provider.mount_options_unchanged? provider.send(:vfstab_entry) end it "should detect a changed entry" do - provider.mount_options_unchanged?.should == false + expect(provider.mount_options_unchanged?).to eq(false) end it "should change mount at boot to no" do - provider.send(:vfstab_entry).should match(/^#{Regexp.escape(this_mount)}/) + expect(provider.send(:vfstab_entry)).to match(/^#{Regexp.escape(this_mount)}/) end end @@ -678,18 +678,18 @@ describe Chef::Provider::Mount::Solaris, :unix_only do let(:vfstab_file_contents) { [existing_mount].join("\n") } before do - provider.stub(:etc_tempfile).and_yield(Tempfile.open("vfstab")) + allow(provider).to receive(:etc_tempfile).and_yield(Tempfile.open("vfstab")) provider.load_current_resource provider.mount_options_unchanged? provider.send(:vfstab_entry) end it "should detect a changed entry" do - provider.mount_options_unchanged?.should == false + expect(provider.mount_options_unchanged?).to eq(false) end it "should change mount at boot to yes" do - provider.send(:vfstab_entry).should match(/^#{Regexp.escape(this_mount)}/) + expect(provider.send(:vfstab_entry)).to match(/^#{Regexp.escape(this_mount)}/) end end @@ -703,18 +703,18 @@ describe Chef::Provider::Mount::Solaris, :unix_only do let(:vfstab_file_contents) { [existing_mount].join("\n") } before do - provider.stub(:etc_tempfile).and_yield(Tempfile.open("vfstab")) + allow(provider).to receive(:etc_tempfile).and_yield(Tempfile.open("vfstab")) provider.load_current_resource provider.mount_options_unchanged? provider.send(:vfstab_entry) end it "should detect an unchanged entry" do - provider.mount_options_unchanged?.should == true + expect(provider.mount_options_unchanged?).to eq(true) end it "should not change mount at boot" do - provider.send(:vfstab_entry).should match(/^#{Regexp.escape(this_mount)}/) + expect(provider.send(:vfstab_entry)).to match(/^#{Regexp.escape(this_mount)}/) end end @@ -728,18 +728,18 @@ describe Chef::Provider::Mount::Solaris, :unix_only do let(:vfstab_file_contents) { [existing_mount].join("\n") } before do - provider.stub(:etc_tempfile).and_yield(Tempfile.open("vfstab")) + allow(provider).to receive(:etc_tempfile).and_yield(Tempfile.open("vfstab")) provider.load_current_resource provider.mount_options_unchanged? provider.send(:vfstab_entry) end it "should detect an unchanged entry" do - provider.mount_options_unchanged?.should == true + expect(provider.mount_options_unchanged?).to eq(true) end it "should not change mount at boot" do - provider.send(:vfstab_entry).should match(/^#{Regexp.escape(this_mount)}/) + expect(provider.send(:vfstab_entry)).to match(/^#{Regexp.escape(this_mount)}/) end end end @@ -753,16 +753,16 @@ describe Chef::Provider::Mount::Solaris, :unix_only do let(:vfstab_file_contents) { [other_mount, this_mount].join("\n") } before do - provider.stub(:etc_tempfile).and_yield(Tempfile.open("vfstab")) + allow(provider).to receive(:etc_tempfile).and_yield(Tempfile.open("vfstab")) provider.disable_fs end it "should leave the other mountpoint alone" do - IO.read(vfstab_file.path).should match(/^#{Regexp.escape(other_mount)}/) + expect(IO.read(vfstab_file.path)).to match(/^#{Regexp.escape(other_mount)}/) end it "should disable the mountpoint we care about" do - IO.read(vfstab_file.path).should_not match(/^#{Regexp.escape(this_mount)}/) + expect(IO.read(vfstab_file.path)).not_to match(/^#{Regexp.escape(this_mount)}/) end end @@ -776,20 +776,20 @@ describe Chef::Provider::Mount::Solaris, :unix_only do let(:vfstab_file_contents) { [other_mount, this_mount, comment].join("\n") } before do - provider.stub(:etc_tempfile).and_yield(Tempfile.open("vfstab")) + allow(provider).to receive(:etc_tempfile).and_yield(Tempfile.open("vfstab")) provider.disable_fs end it "should leave the other mountpoint alone" do - IO.read(vfstab_file.path).should match(/^#{Regexp.escape(other_mount)}/) + expect(IO.read(vfstab_file.path)).to match(/^#{Regexp.escape(other_mount)}/) end it "should disable the mountpoint we care about" do - IO.read(vfstab_file.path).should_not match(/^#{Regexp.escape(this_mount)}/) + expect(IO.read(vfstab_file.path)).not_to match(/^#{Regexp.escape(this_mount)}/) end it "should keep the comment" do - IO.read(vfstab_file.path).should match(/^#{Regexp.escape(comment)}/) + expect(IO.read(vfstab_file.path)).to match(/^#{Regexp.escape(comment)}/) end end @@ -801,20 +801,20 @@ describe Chef::Provider::Mount::Solaris, :unix_only do let(:vfstab_file_contents) { [this_mount, other_mount, this_mount].join("\n") } before do - provider.stub(:etc_tempfile).and_yield(Tempfile.open("vfstab")) + allow(provider).to receive(:etc_tempfile).and_yield(Tempfile.open("vfstab")) provider.disable_fs end it "should leave the other mountpoint alone" do - IO.read(vfstab_file.path).should match(/^#{Regexp.escape(other_mount)}/) + expect(IO.read(vfstab_file.path)).to match(/^#{Regexp.escape(other_mount)}/) end it "should still match the duplicated mountpoint" do - IO.read(vfstab_file.path).should match(/^#{Regexp.escape(this_mount)}/) + expect(IO.read(vfstab_file.path)).to match(/^#{Regexp.escape(this_mount)}/) end it "should have removed the last line" do - IO.read(vfstab_file.path).should eql( "#{this_mount}\n#{other_mount}\n" ) + expect(IO.read(vfstab_file.path)).to eql( "#{this_mount}\n#{other_mount}\n" ) end end end diff --git a/spec/unit/provider/mount/windows_spec.rb b/spec/unit/provider/mount/windows_spec.rb index 80e7f1e695..467d923c6a 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) + allow(Chef::Resource::Mount).to receive(:new).and_return(@current_resource) @net_use = double("Chef::Util::Windows::NetUse") - Chef::Util::Windows::NetUse.stub(:new).and_return(@net_use) + allow(Chef::Util::Windows::NetUse).to receive(:new).and_return(@net_use) @vol = double("Chef::Util::Windows::Volume") - Chef::Util::Windows::Volume.stub(:new).and_return(@vol) + allow(Chef::Util::Windows::Volume).to receive(:new).and_return(@vol) @provider = Chef::Provider::Mount::Windows.new(@new_resource, @run_context) @provider.current_resource = @current_resource @@ -53,26 +53,26 @@ 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) - @current_resource.should_receive(:mounted).with(true) + allow(@vol).to receive(:device).and_return(@new_resource.device) + expect(@current_resource).to 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) - @current_resource.should_receive(:mounted).with(false) + allow(@vol).to receive(:device).and_raise(ArgumentError) + expect(@current_resource).to receive(:mounted).with(false) @provider.load_current_resource end 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) + allow(@vol).to receive(:device).and_return(@new_resource.device) + allow(@net_use).to receive(:device).and_raise(ArgumentError) end it "should determine the device is a volume GUID" do - @provider.should_receive(:is_volume).with(@new_resource.device).and_return(true) + expect(@provider).to receive(:is_volume).with(@new_resource.device).and_return(true) @provider.load_current_resource end end @@ -80,12 +80,12 @@ 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) + allow(@net_use).to receive(:device).and_return(@new_resource.device) + allow(@vol).to receive(:device).and_raise(ArgumentError) end it "should determine the device is remote" do - @provider.should_receive(:is_volume).with(@new_resource.device).and_return(false) + expect(@provider).to receive(:is_volume).with(@new_resource.device).and_return(false) @provider.load_current_resource end end @@ -93,13 +93,13 @@ 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) + allow(@vol).to receive(:add) + allow(@vol).to receive(:device).and_raise(ArgumentError) @provider.load_current_resource end it "should mount the filesystem if it is not mounted" do - @vol.should_receive(:add).with(:remote => @new_resource.device, + expect(@vol).to receive(:add).with(:remote => @new_resource.device, :username => @new_resource.username, :domainname => @new_resource.domain, :password => @new_resource.password) @@ -107,8 +107,8 @@ describe Chef::Provider::Mount::Windows do end it "should not mount the filesystem if it is mounted" do - @vol.should_not_receive(:add) - @current_resource.stub(:mounted).and_return(true) + expect(@vol).not_to receive(:add) + allow(@current_resource).to receive(:mounted).and_return(true) @provider.mount_fs end end @@ -116,20 +116,20 @@ 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) + allow(@vol).to receive(:delete) + allow(@vol).to receive(: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) - @vol.should_receive(:delete) + allow(@current_resource).to receive(:mounted).and_return(true) + expect(@vol).to 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) - @vol.should_not_receive(:delete) + allow(@current_resource).to receive(:mounted).and_return(false) + expect(@vol).not_to receive(:delete) @provider.umount_fs end end diff --git a/spec/unit/provider/ohai_spec.rb b/spec/unit/provider/ohai_spec.rb index 29c32e2690..45688cedb7 100644 --- a/spec/unit/provider/ohai_spec.rb +++ b/spec/unit/provider/ohai_spec.rb @@ -41,16 +41,16 @@ describe Chef::Provider::Ohai do :newdata => "somevalue" } } - mock_ohai.stub(:all_plugins).and_return(true) - mock_ohai.stub(:data).and_return(mock_ohai[:data], + allow(mock_ohai).to receive(:all_plugins).and_return(true) + allow(mock_ohai).to receive(: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, + allow(Ohai::System).to receive(:new).and_return(mock_ohai) + allow(Chef::Platform).to receive(: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) + allow(@node).to receive(:save).and_return(@node) @events = Chef::EventDispatch::Dispatcher.new @run_context = Chef::RunContext.new(@node, {}, @events) @new_resource = Chef::Resource::Ohai.new("ohai_reload") @@ -67,18 +67,18 @@ describe Chef::Provider::Ohai do end it "applies updated ohai data to the node" do - @node[:origdata].should == 'somevalue' - @node[:newdata].should be_nil + expect(@node[:origdata]).to eq('somevalue') + expect(@node[:newdata]).to be_nil @provider.run_action(:reload) - @node[:origdata].should == 'somevalue' - @node[:newdata].should == 'somevalue' + expect(@node[:origdata]).to eq('somevalue') + expect(@node[:newdata]).to eq('somevalue') end it "should reload a specific plugin and cause node to pick up new values" do @new_resource.plugin "someplugin" @provider.run_action(:reload) - @node[:origdata].should == 'somevalue' - @node[:newdata].should == 'somevalue' + expect(@node[:origdata]).to eq('somevalue') + expect(@node[:newdata]).to eq('somevalue') end end end diff --git a/spec/unit/provider/package/aix_spec.rb b/spec/unit/provider/package/aix_spec.rb index 5d6e23302f..6908b1288d 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) + allow(::File).to receive(:exists?).and_return(true) end describe "assessing the current package status" do @@ -40,118 +40,118 @@ 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) + allow(@provider).to receive(:popen4).and_return(@status) @provider.load_current_resource - @provider.current_resource.name.should == "samba.base" + expect(@provider.current_resource.name).to eq("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) + allow(@provider).to receive(:popen4).and_return(@status) @provider.load_current_resource - @provider.current_resource.package_name.should == "samba.base" + expect(@provider.current_resource.package_name).to eq("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) + allow(@provider).to receive(:popen4).and_return(@status) + allow(::File).to receive(:exists?).and_return(false) @provider.define_resource_requirements @provider.load_current_resource - lambda { @provider.process_resource_requirements }.should raise_error(Chef::Exceptions::Package) + expect { @provider.process_resource_requirements }.to raise_error(Chef::Exceptions::Package) end it "should get the source package version from lslpp if provided" do @stdout = StringIO.new(@bffinfo) @stdin, @stderr = StringIO.new, StringIO.new - @provider.should_receive(:popen4).with("installp -L -d /tmp/samba.base").and_yield(@pid, @stdin, @stdout, @stderr).and_return(@status) - @provider.should_receive(:popen4).with("lslpp -lcq samba.base").and_return(@status) + expect(@provider).to receive(:popen4).with("installp -L -d /tmp/samba.base").and_yield(@pid, @stdin, @stdout, @stderr).and_return(@status) + expect(@provider).to receive(:popen4).with("lslpp -lcq samba.base").and_return(@status) @provider.load_current_resource - @provider.current_resource.package_name.should == "samba.base" - @new_resource.version.should == "3.3.12.0" + expect(@provider.current_resource.package_name).to eq("samba.base") + expect(@new_resource.version).to eq("3.3.12.0") end it "should return the current version installed if found by lslpp" do @stdout = StringIO.new(@bffinfo) @stdin, @stderr = StringIO.new, StringIO.new - @provider.should_receive(:popen4).with("installp -L -d /tmp/samba.base").and_return(@status) - @provider.should_receive(:popen4).with("lslpp -lcq samba.base").and_yield(@pid, @stdin, @stdout, @stderr).and_return(@status) + expect(@provider).to receive(:popen4).with("installp -L -d /tmp/samba.base").and_return(@status) + expect(@provider).to receive(:popen4).with("lslpp -lcq samba.base").and_yield(@pid, @stdin, @stdout, @stderr).and_return(@status) @provider.load_current_resource - @provider.current_resource.version.should == "3.3.12.0" + expect(@provider.current_resource.version).to eq("3.3.12.0") end 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) - lambda { @provider.run_action(:install) }.should raise_error(Chef::Exceptions::Package) + allow(@provider).to receive(:popen4).and_return(@status) + expect { @provider.run_action(:install) }.to raise_error(Chef::Exceptions::Package) end it "should raise an exception if installp/lslpp fails to run" do @status = double("Status", :exitstatus => -1) - @provider.stub(:popen4).and_return(@status) - lambda { @provider.load_current_resource }.should raise_error(Chef::Exceptions::Package) + allow(@provider).to receive(:popen4).and_return(@status) + expect { @provider.load_current_resource }.to raise_error(Chef::Exceptions::Package) end it "should return a current resource with a nil version if the package is not found" do @stdout = StringIO.new - @provider.should_receive(:popen4).with("installp -L -d /tmp/samba.base").and_return(@status) - @provider.should_receive(:popen4).with("lslpp -lcq samba.base").and_yield(@pid, @stdin, @stdout, @stderr).and_return(@status) + expect(@provider).to receive(:popen4).with("installp -L -d /tmp/samba.base").and_return(@status) + expect(@provider).to receive(:popen4).with("lslpp -lcq samba.base").and_yield(@pid, @stdin, @stdout, @stderr).and_return(@status) @provider.load_current_resource - @provider.current_resource.version.should be_nil + expect(@provider.current_resource.version).to be_nil end end describe "candidate_version" do it "should return the candidate_version variable if already setup" do @provider.candidate_version = "3.3.12.0" - @provider.should_not_receive(:popen4) + expect(@provider).not_to receive(:popen4) @provider.candidate_version end it "should lookup the candidate_version if the variable is not already set" do @status = double("Status", :exitstatus => 0) - @provider.should_receive(:popen4).and_return(@status) + expect(@provider).to receive(:popen4).and_return(@status) @provider.candidate_version end it "should throw and exception if the exitstatus is not 0" do @status = double("Status", :exitstatus => 1) - @provider.stub(:popen4).and_return(@status) - lambda { @provider.candidate_version }.should raise_error(Chef::Exceptions::Package) + allow(@provider).to receive(:popen4).and_return(@status) + expect { @provider.candidate_version }.to raise_error(Chef::Exceptions::Package) end end describe "install and upgrade" do it "should run installp -aYF -d with the package source to install" do - @provider.should_receive(:shell_out!).with("installp -aYF -d /tmp/samba.base samba.base") + expect(@provider).to receive(:shell_out!).with("installp -aYF -d /tmp/samba.base samba.base") @provider.install_package("samba.base", "3.3.12.0") end it "should run when the package is a path to install" do @new_resource = Chef::Resource::Package.new("/tmp/samba.base") @provider = Chef::Provider::Package::Aix.new(@new_resource, @run_context) - @new_resource.source.should == "/tmp/samba.base" - @provider.should_receive(:shell_out!).with("installp -aYF -d /tmp/samba.base /tmp/samba.base") + expect(@new_resource.source).to eq("/tmp/samba.base") + expect(@provider).to receive(:shell_out!).with("installp -aYF -d /tmp/samba.base /tmp/samba.base") @provider.install_package("/tmp/samba.base", "3.3.12.0") end it "should run installp with -eLogfile option." do - @new_resource.stub(:options).and_return("-e/tmp/installp.log") - @provider.should_receive(:shell_out!).with("installp -aYF -e/tmp/installp.log -d /tmp/samba.base samba.base") + allow(@new_resource).to receive(:options).and_return("-e/tmp/installp.log") + expect(@provider).to receive(:shell_out!).with("installp -aYF -e/tmp/installp.log -d /tmp/samba.base samba.base") @provider.install_package("samba.base", "3.3.12.0") end end describe "remove" do it "should run installp -u samba.base to remove the package" do - @provider.should_receive(:shell_out!).with("installp -u samba.base") + expect(@provider).to receive(:shell_out!).with("installp -u samba.base") @provider.remove_package("samba.base", "3.3.12.0") 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") - @provider.should_receive(:shell_out!).with("installp -u -e/tmp/installp.log samba.base") + allow(@new_resource).to receive(:options).and_return("-e/tmp/installp.log") + expect(@provider).to receive(:shell_out!).with("installp -u -e/tmp/installp.log samba.base") @provider.remove_package("samba.base", "3.3.12.0") end diff --git a/spec/unit/provider/package/apt_spec.rb b/spec/unit/provider/package/apt_spec.rb index 90e9dd6d3f..edca3e4c22 100644 --- a/spec/unit/provider/package/apt_spec.rb +++ b/spec/unit/provider/package/apt_spec.rb @@ -45,17 +45,17 @@ PKG_STATUS describe "when loading current resource" do it "should create a current resource with the name of the new_resource" do - @provider.should_receive(:shell_out!).with( + expect(@provider).to receive(:shell_out!).with( "apt-cache policy #{@new_resource.package_name}", :timeout => @timeout ).and_return(@shell_out) @provider.load_current_resource current_resource = @provider.current_resource - current_resource.should be_a(Chef::Resource::Package) - current_resource.name.should == "irssi" - current_resource.package_name.should == "irssi" - current_resource.version.should be_nil + expect(current_resource).to be_a(Chef::Resource::Package) + expect(current_resource.name).to eq("irssi") + expect(current_resource.package_name).to eq("irssi") + expect(current_resource.version).to be_nil end it "should set the installed version if package has one" do @@ -71,10 +71,10 @@ sudo: 1.7.2p1-1ubuntu5 0 500 http://us.archive.ubuntu.com/ubuntu/ lucid/main Packages INSTALLED - @provider.should_receive(:shell_out!).and_return(@shell_out) + expect(@provider).to receive(:shell_out!).and_return(@shell_out) @provider.load_current_resource - @provider.current_resource.version.should == "1.7.2p1-1ubuntu5.3" - @provider.candidate_version.should eql("1.7.2p1-1ubuntu5.3") + expect(@provider.current_resource.version).to eq("1.7.2p1-1ubuntu5.3") + expect(@provider.candidate_version).to eql("1.7.2p1-1ubuntu5.3") end # libmysqlclient-dev is a real package in newer versions of debian + ubuntu @@ -88,7 +88,7 @@ libmysqlclient15-dev: Version table: VPKG_STDOUT virtual_package = double(:stdout => virtual_package_out,:exitstatus => 0) - @provider.should_receive(:shell_out!).with( + expect(@provider).to receive(:shell_out!).with( "apt-cache policy libmysqlclient15-dev", :timeout => @timeout ).and_return(virtual_package) @@ -111,7 +111,7 @@ libmysqlclient-dev 5.1.41-3ubuntu12.10 libmysqlclient-dev 5.1.41-3ubuntu12 SHOWPKG_STDOUT showpkg = double(:stdout => showpkg_out,:exitstatus => 0) - @provider.should_receive(:shell_out!).with( + expect(@provider).to receive(:shell_out!).with( "apt-cache showpkg libmysqlclient15-dev", :timeout => @timeout ).and_return(showpkg) @@ -129,7 +129,7 @@ libmysqlclient-dev: 500 http://us.archive.ubuntu.com/ubuntu/ lucid/main Packages RPKG_STDOUT real_package = double(:stdout => real_package_out,:exitstatus => 0) - @provider.should_receive(:shell_out!).with( + expect(@provider).to receive(:shell_out!).with( "apt-cache policy libmysqlclient-dev", :timeout => @timeout ).and_return(real_package) @@ -145,7 +145,7 @@ mp3-decoder: Version table: VPKG_STDOUT virtual_package = double(:stdout => virtual_package_out,:exitstatus => 0) - @provider.should_receive(:shell_out!).with( + expect(@provider).to receive(:shell_out!).with( "apt-cache policy mp3-decoder", :timeout => @timeout ).and_return(virtual_package) @@ -171,20 +171,20 @@ mpg321 0.2.10.6 mpg123 1.12.1-0ubuntu1 SHOWPKG_STDOUT showpkg = double(:stdout => showpkg_out,:exitstatus => 0) - @provider.should_receive(:shell_out!).with( + expect(@provider).to receive(:shell_out!).with( "apt-cache showpkg mp3-decoder", :timeout => @timeout ).and_return(showpkg) - lambda { @provider.load_current_resource }.should raise_error(Chef::Exceptions::Package) + expect { @provider.load_current_resource }.to raise_error(Chef::Exceptions::Package) end it "should run apt-cache policy with the default_release option, if there is one and provider is explicitly defined" do @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") - @provider.should_receive(:shell_out!).with( + allow(@new_resource).to receive(:default_release).and_return("lenny-backports") + allow(@new_resource).to receive(:provider).and_return("Chef::Provider::Package::Apt") + expect(@provider).to receive(:shell_out!).with( "apt-cache -o APT::Default-Release=lenny-backports policy irssi", :timeout => @timeout ).and_return(@shell_out) @@ -194,7 +194,7 @@ SHOWPKG_STDOUT it "raises an exception if a source is specified (CHEF-5113)" do @new_resource.source "pluto" @provider.define_resource_requirements - @provider.should_receive(:shell_out!).with("apt-cache policy irssi", {:timeout=>900}).and_return(@shell_out) + expect(@provider).to receive(:shell_out!).with("apt-cache policy irssi", {:timeout=>900}).and_return(@shell_out) expect { @provider.run_action(:install) }.to raise_error(Chef::Exceptions::Package) end end @@ -207,7 +207,7 @@ SHOWPKG_STDOUT describe "install_package" do it "should run apt-get install with the package name and version" do - @provider.should_receive(:shell_out!). with( + expect(@provider).to receive(:shell_out!). with( "apt-get -q -y install irssi=0.8.12-7", :env => { "DEBIAN_FRONTEND" => "noninteractive", "LC_ALL" => nil}, :timeout => @timeout @@ -216,7 +216,7 @@ SHOWPKG_STDOUT end it "should run apt-get install with the package name and version and options if specified" do - @provider.should_receive(:shell_out!).with( + expect(@provider).to receive(:shell_out!).with( "apt-get -q -y --force-yes install irssi=0.8.12-7", :env => {"DEBIAN_FRONTEND" => "noninteractive", "LC_ALL" => nil }, :timeout => @timeout @@ -232,7 +232,7 @@ SHOWPKG_STDOUT @new_resource.provider = @provider @provider.new_resource = @new_resource - @provider.should_receive(:shell_out!).with( + expect(@provider).to receive(:shell_out!).with( "apt-get -q -y -o APT::Default-Release=lenny-backports install irssi=0.8.12-7", :env => {"DEBIAN_FRONTEND" => "noninteractive", "LC_ALL" => nil }, :timeout => @timeout @@ -245,7 +245,7 @@ SHOWPKG_STDOUT describe Chef::Provider::Package::Apt, "upgrade_package" do it "should run install_package with the name and version" do - @provider.should_receive(:install_package).with("irssi", "0.8.12-7") + expect(@provider).to receive(:install_package).with("irssi", "0.8.12-7") @provider.upgrade_package("irssi", "0.8.12-7") end end @@ -253,7 +253,7 @@ SHOWPKG_STDOUT describe Chef::Provider::Package::Apt, "remove_package" do it "should run apt-get remove with the package name" do - @provider.should_receive(:shell_out!).with( + expect(@provider).to receive(:shell_out!).with( "apt-get -q -y remove irssi", :env => {"DEBIAN_FRONTEND" => "noninteractive", "LC_ALL" => nil}, :timeout => @timeout @@ -262,7 +262,7 @@ SHOWPKG_STDOUT end it "should run apt-get remove with the package name and options if specified" do - @provider.should_receive(:shell_out!).with( + expect(@provider).to receive(:shell_out!).with( "apt-get -q -y --force-yes remove irssi", :env => { "DEBIAN_FRONTEND" => "noninteractive", "LC_ALL" => nil }, :timeout => @timeout @@ -276,7 +276,7 @@ SHOWPKG_STDOUT describe "when purging a package" do it "should run apt-get purge with the package name" do - @provider.should_receive(:shell_out!).with( + expect(@provider).to receive(:shell_out!).with( "apt-get -q -y purge irssi", :env => { "DEBIAN_FRONTEND" => "noninteractive", "LC_ALL" => nil }, :timeout => @timeout @@ -285,7 +285,7 @@ SHOWPKG_STDOUT end it "should run apt-get purge with the package name and options if specified" do - @provider.should_receive(:shell_out!).with( + expect(@provider).to receive(:shell_out!).with( "apt-get -q -y --force-yes purge irssi", :env => { "DEBIAN_FRONTEND" => "noninteractive", "LC_ALL" => nil }, :timeout => @timeout @@ -298,14 +298,14 @@ 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") + allow(@provider).to receive(: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 - @provider.should_receive(:get_preseed_file).with("irssi", "0.8.12-7").and_return("/tmp/irssi-0.8.12-7.seed") + expect(@provider).to receive(:get_preseed_file).with("irssi", "0.8.12-7").and_return("/tmp/irssi-0.8.12-7.seed") file = @provider.get_preseed_file("irssi", "0.8.12-7") - @provider.should_receive(:shell_out!).with( + expect(@provider).to receive(:shell_out!).with( "debconf-set-selections /tmp/irssi-0.8.12-7.seed", :env => {"DEBIAN_FRONTEND" => "noninteractive", "LC_ALL" => nil}, :timeout => @timeout @@ -315,7 +315,7 @@ SHOWPKG_STDOUT end it "should run debconf-set-selections on the preseed file if it has changed" do - @provider.should_receive(:shell_out!).with( + expect(@provider).to receive(:shell_out!).with( "debconf-set-selections /tmp/irssi-0.8.12-7.seed", :env => {"DEBIAN_FRONTEND" => "noninteractive", "LC_ALL" => nil}, :timeout => @timeout @@ -325,18 +325,18 @@ SHOWPKG_STDOUT end it "should not run debconf-set-selections if the preseed file has not changed" do - @provider.stub(:check_package_state) + allow(@provider).to receive(:check_package_state) @current_resource.version "0.8.11" @new_resource.response_file "/tmp/file" - @provider.stub(:get_preseed_file).and_return(false) - @provider.should_not_receive(:shell_out!) + allow(@provider).to receive(:get_preseed_file).and_return(false) + expect(@provider).not_to receive(:shell_out!) @provider.run_action(:reconfig) end end describe "when reconfiguring a package" do it "should run dpkg-reconfigure package" do - @provider.should_receive(:shell_out!).with( + expect(@provider).to receive(:shell_out!).with( "dpkg-reconfigure irssi", :env => {"DEBIAN_FRONTEND" => "noninteractive", "LC_ALL" => nil }, :timeout => @timeout @@ -348,7 +348,7 @@ SHOWPKG_STDOUT describe "when installing a virtual package" do it "should install the package without specifying a version" do @provider.is_virtual_package = true - @provider.should_receive(:shell_out!).with( + expect(@provider).to receive(:shell_out!).with( "apt-get -q -y install libmysqlclient-dev", :env => {"DEBIAN_FRONTEND" => "noninteractive", "LC_ALL" => nil }, :timeout => @timeout diff --git a/spec/unit/provider/package/dpkg_spec.rb b/spec/unit/provider/package/dpkg_spec.rb index 439a42daa3..fdd9e50c8e 100644 --- a/spec/unit/provider/package/dpkg_spec.rb +++ b/spec/unit/provider/package/dpkg_spec.rb @@ -33,32 +33,32 @@ describe Chef::Provider::Package::Dpkg do @status = double("Status", :exitstatus => 0) @stderr = StringIO.new @pid = double("PID") - @provider.stub(:popen4).and_return(@status) + allow(@provider).to receive(:popen4).and_return(@status) - ::File.stub(:exists?).and_return(true) + allow(::File).to receive(:exists?).and_return(true) end describe "when loading the current resource state" do it "should create a current resource with the name of the new_resource" do @provider.load_current_resource - @provider.current_resource.package_name.should == "wget" + expect(@provider.current_resource.package_name).to eq("wget") end 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) - lambda { @provider.run_action(:install) }.should raise_error(Chef::Exceptions::Package) + allow(::File).to receive(:exists?).and_return(false) + expect { @provider.run_action(:install) }.to 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) + allow(@provider).to receive(: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 + expect(@provider.current_resource.package_name).to eq("wget") + expect(@new_resource.version).to eq(version) end it 'if short version provided' do @@ -80,9 +80,9 @@ 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) + allow(@provider).to receive(: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" + expect(@provider.current_resource.package_name).to eq("f.o.o-pkg++2") end it "should raise an exception if the source is not set but we are installing" do @@ -90,7 +90,7 @@ describe Chef::Provider::Package::Dpkg do @provider.new_resource = @new_resource @provider.define_resource_requirements @provider.load_current_resource - lambda { @provider.run_action(:install)}.should raise_error(Chef::Exceptions::Package) + expect { @provider.run_action(:install)}.to raise_error(Chef::Exceptions::Package) end it "should return the current version installed if found by dpkg" do @@ -107,22 +107,22 @@ 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) + allow(@provider).to receive(: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" + expect(@provider.current_resource.version).to eq("1.11.4-1ubuntu1") end it "should raise an exception if dpkg fails to run" do @status = double("Status", :exitstatus => -1) - @provider.stub(:popen4).and_return(@status) - lambda { @provider.load_current_resource }.should raise_error(Chef::Exceptions::Package) + allow(@provider).to receive(:popen4).and_return(@status) + expect { @provider.load_current_resource }.to raise_error(Chef::Exceptions::Package) end end describe Chef::Provider::Package::Dpkg, "install and upgrade" do it "should run dpkg -i with the package source" do - @provider.should_receive(:run_noninteractive).with( + expect(@provider).to receive(:run_noninteractive).with( "dpkg -i /tmp/wget_1.11.4-1ubuntu1_amd64.deb" ) @provider.install_package("wget", "1.11.4-1ubuntu1") @@ -131,7 +131,7 @@ DPKG_S it "should run dpkg -i if the package is a path and the source is nil" do @new_resource = Chef::Resource::Package.new("/tmp/wget_1.11.4-1ubuntu1_amd64.deb") @provider = Chef::Provider::Package::Dpkg.new(@new_resource, @run_context) - @provider.should_receive(:run_noninteractive).with( + expect(@provider).to receive(:run_noninteractive).with( "dpkg -i /tmp/wget_1.11.4-1ubuntu1_amd64.deb" ) @provider.install_package("/tmp/wget_1.11.4-1ubuntu1_amd64.deb", "1.11.4-1ubuntu1") @@ -140,55 +140,55 @@ DPKG_S it "should run dpkg -i if the package is a path and the source is nil for an upgrade" do @new_resource = Chef::Resource::Package.new("/tmp/wget_1.11.4-1ubuntu1_amd64.deb") @provider = Chef::Provider::Package::Dpkg.new(@new_resource, @run_context) - @provider.should_receive(:run_noninteractive).with( + expect(@provider).to receive(:run_noninteractive).with( "dpkg -i /tmp/wget_1.11.4-1ubuntu1_amd64.deb" ) @provider.upgrade_package("/tmp/wget_1.11.4-1ubuntu1_amd64.deb", "1.11.4-1ubuntu1") end it "should run dpkg -i with the package source and options if specified" do - @provider.should_receive(:run_noninteractive).with( + expect(@provider).to receive(:run_noninteractive).with( "dpkg -i --force-yes /tmp/wget_1.11.4-1ubuntu1_amd64.deb" ) - @new_resource.stub(:options).and_return("--force-yes") + allow(@new_resource).to receive(:options).and_return("--force-yes") @provider.install_package("wget", "1.11.4-1ubuntu1") end it "should upgrade by running install_package" do - @provider.should_receive(:install_package).with("wget", "1.11.4-1ubuntu1") + expect(@provider).to receive(:install_package).with("wget", "1.11.4-1ubuntu1") @provider.upgrade_package("wget", "1.11.4-1ubuntu1") end end describe Chef::Provider::Package::Dpkg, "remove and purge" do it "should run dpkg -r to remove the package" do - @provider.should_receive(:run_noninteractive).with( + expect(@provider).to receive(:run_noninteractive).with( "dpkg -r wget" ) @provider.remove_package("wget", "1.11.4-1ubuntu1") end it "should run dpkg -r to remove the package with options if specified" do - @provider.should_receive(:run_noninteractive).with( + expect(@provider).to receive(:run_noninteractive).with( "dpkg -r --force-yes wget" ) - @new_resource.stub(:options).and_return("--force-yes") + allow(@new_resource).to receive(:options).and_return("--force-yes") @provider.remove_package("wget", "1.11.4-1ubuntu1") end it "should run dpkg -P to purge the package" do - @provider.should_receive(:run_noninteractive).with( + expect(@provider).to receive(:run_noninteractive).with( "dpkg -P wget" ) @provider.purge_package("wget", "1.11.4-1ubuntu1") end it "should run dpkg -P to purge the package with options if specified" do - @provider.should_receive(:run_noninteractive).with( + expect(@provider).to receive(:run_noninteractive).with( "dpkg -P --force-yes wget" ) - @new_resource.stub(:options).and_return("--force-yes") + allow(@new_resource).to receive(: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 87cbabcc19..221ec8fdfc 100644 --- a/spec/unit/provider/package/easy_install_spec.rb +++ b/spec/unit/provider/package/easy_install_spec.rb @@ -30,79 +30,79 @@ 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) + allow(Chef::Resource::Package).to receive(:new).and_return(@current_resource) @stdin = StringIO.new @stdout = StringIO.new @status = double("Status", :exitstatus => 0) @stderr = StringIO.new @pid = 2342 - @provider.stub(:popen4).and_return(@status) + allow(@provider).to receive(:popen4).and_return(@status) end describe "easy_install_binary_path" do it "should return a Chef::Provider::EasyInstall object" do provider = Chef::Provider::Package::EasyInstall.new(@node, @new_resource) - provider.should be_a_kind_of(Chef::Provider::Package::EasyInstall) + expect(provider).to be_a_kind_of(Chef::Provider::Package::EasyInstall) end it "should set the current resources package name to the new resources package name" do - $stdout.stub(:write) - @current_resource.should_receive(:package_name).with(@new_resource.package_name) + allow($stdout).to receive(:write) + expect(@current_resource).to receive(:package_name).with(@new_resource.package_name) @provider.load_current_resource end it "should return a relative path to easy_install if no easy_install_binary is given" do - @provider.easy_install_binary_path.should eql("easy_install") + expect(@provider.easy_install_binary_path).to eql("easy_install") end it "should return a specific path to easy_install if a easy_install_binary is given" do - @new_resource.should_receive(:easy_install_binary).and_return("/opt/local/bin/custom/easy_install") - @provider.easy_install_binary_path.should eql("/opt/local/bin/custom/easy_install") + expect(@new_resource).to receive(:easy_install_binary).and_return("/opt/local/bin/custom/easy_install") + expect(@provider.easy_install_binary_path).to eql("/opt/local/bin/custom/easy_install") end end describe "actions_on_package" do it "should run easy_install with the package name and version" do - @provider.should_receive(:run_command).with({ + expect(@provider).to receive(:run_command).with({ :command => "easy_install \"boto==1.8d\"" }) @provider.install_package("boto", "1.8d") end it "should run easy_install with the package name and version and specified options" do - @provider.should_receive(:run_command).with({ + expect(@provider).to receive(:run_command).with({ :command => "easy_install --always-unzip \"boto==1.8d\"" }) - @new_resource.stub(:options).and_return("--always-unzip") + allow(@new_resource).to receive(:options).and_return("--always-unzip") @provider.install_package("boto", "1.8d") end it "should run easy_install with the package name and version" do - @provider.should_receive(:run_command).with({ + expect(@provider).to receive(:run_command).with({ :command => "easy_install \"boto==1.8d\"" }) @provider.upgrade_package("boto", "1.8d") end it "should run easy_install -m with the package name and version" do - @provider.should_receive(:run_command).with({ + expect(@provider).to receive(:run_command).with({ :command => "easy_install -m boto" }) @provider.remove_package("boto", "1.8d") end it "should run easy_install -m with the package name and version and specified options" do - @provider.should_receive(:run_command).with({ + expect(@provider).to receive(:run_command).with({ :command => "easy_install -x -m boto" }) - @new_resource.stub(:options).and_return("-x") + allow(@new_resource).to receive(:options).and_return("-x") @provider.remove_package("boto", "1.8d") end it "should run easy_install -m with the package name and version" do - @provider.should_receive(:run_command).with({ + expect(@provider).to receive(:run_command).with({ :command => "easy_install -m boto" }) @provider.purge_package("boto", "1.8d") diff --git a/spec/unit/provider/package/freebsd/pkg_spec.rb b/spec/unit/provider/package/freebsd/pkg_spec.rb index 9b2493a4c5..f67161930f 100644 --- a/spec/unit/provider/package/freebsd/pkg_spec.rb +++ b/spec/unit/provider/package/freebsd/pkg_spec.rb @@ -30,35 +30,35 @@ describe Chef::Provider::Package::Freebsd::Pkg, "load_current_resource" do @provider = Chef::Provider::Package::Freebsd::Pkg.new(@new_resource, @run_context) @provider.current_resource = @current_resource - ::File.stub(:exist?).with('/usr/ports/Makefile').and_return(false) + allow(::File).to receive(: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") + allow(@provider).to receive(:ports_candidate_version).and_return("4.3.6") end it "should create a current resource with the name of the new_resource" do current_resource = Chef::Provider::Package::Freebsd::Pkg.new(@new_resource, @run_context).current_resource - current_resource.name.should == "zsh" + expect(current_resource.name).to eq("zsh") end it "should return a version if the package is installed" do - @provider.should_receive(:current_installed_version).and_return("4.3.6_7") + expect(@provider).to receive(:current_installed_version).and_return("4.3.6_7") @provider.load_current_resource - @current_resource.version.should == "4.3.6_7" + expect(@current_resource.version).to eq("4.3.6_7") end it "should return nil if the package is not installed" do - @provider.should_receive(:current_installed_version).and_return(nil) + expect(@provider).to receive(:current_installed_version).and_return(nil) @provider.load_current_resource - @current_resource.version.should be_nil + expect(@current_resource.version).to be_nil end it "should return a candidate version if it exists" do - @provider.should_receive(:current_installed_version).and_return(nil) + expect(@provider).to receive(:current_installed_version).and_return(nil) @provider.load_current_resource - @provider.candidate_version.should eql("4.3.6") + expect(@provider.candidate_version).to eql("4.3.6") end end @@ -77,42 +77,42 @@ describe Chef::Provider::Package::Freebsd::Pkg, "load_current_resource" do it "should return the version number when it is installed" do pkg_info = OpenStruct.new(:stdout => "zsh-4.3.6_7") - @provider.should_receive(:shell_out!).with('pkg_info -E "zsh*"', :env => nil, :returns => [0,1]).and_return(pkg_info) + expect(@provider).to 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.current_installed_version.should == "4.3.6_7" + allow(@provider).to receive(:package_name).and_return("zsh") + expect(@provider.current_installed_version).to eq("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.current_installed_version.should be_nil + expect(@provider).to receive(:shell_out!).with('pkg_info -E "zsh*"', :env => nil, :returns => [0,1]).and_return(pkg_info) + allow(@provider).to receive(:package_name).and_return("zsh") + expect(@provider.current_installed_version).to be_nil end it "should return the port path for a valid port name" do whereis = OpenStruct.new(:stdout => "zsh: /usr/ports/shells/zsh") - @provider.should_receive(:shell_out!).with("whereis -s zsh", :env => nil).and_return(whereis) + expect(@provider).to 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.port_path.should == "/usr/ports/shells/zsh" + allow(@provider).to receive(:port_name).and_return("zsh") + expect(@provider.port_path).to eq("/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") + allow(@provider).to receive(:port_path).and_return("/usr/ports/shells/zsh") make_v = OpenStruct.new(:stdout => "4.3.6\n", :exitstatus => 0) - @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" + expect(@provider).to receive(:shell_out!).with("make -V PORTVERSION", {:cwd=>"/usr/ports/shells/zsh", :returns=>[0, 1], :env=>nil}).and_return(make_v) + expect(@provider.ports_candidate_version).to eq("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") + allow(::File).to receive(:exist?).with('/usr/ports/Makefile').and_return(true) + allow(@provider).to receive(:port_path).and_return("/usr/ports/shells/zsh") make_v = OpenStruct.new(:stdout => "zsh-4.3.6_7\n", :exitstatus => 0) - @provider.should_receive(:shell_out!).with("make -V PKGNAME", {:cwd=>"/usr/ports/shells/zsh", :env=>nil, :returns=>[0, 1]}).and_return(make_v) + expect(@provider).to 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") - @provider.package_name.should == "zsh" + expect(@provider.package_name).to eq("zsh") end end @@ -121,13 +121,13 @@ describe Chef::Provider::Package::Freebsd::Pkg, "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") + allow(@provider).to receive(:package_name).and_return("zsh") + allow(@provider).to receive(:latest_link_name).and_return("zsh") + allow(@provider).to receive(:port_path).and_return("/usr/ports/shells/zsh") end it "should run pkg_add -r with the package name" do - @provider.should_receive(:shell_out!).with("pkg_add -r zsh", :env => nil).and_return(@cmd_result) + expect(@provider).to receive(:shell_out!).with("pkg_add -r zsh", :env => nil).and_return(@cmd_result) @provider.install_package("zsh", "4.3.6_7") end end @@ -142,15 +142,15 @@ describe Chef::Provider::Package::Freebsd::Pkg, "load_current_resource" do it "should figure out the port path from the package_name using whereis" 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.port_path.should == "/usr/ports/shells/zsh" + expect(@provider).to receive(:shell_out!).with("whereis -s zsh", :env=>nil).and_return(whereis) + expect(@provider.port_path).to eq("/usr/ports/shells/zsh") end it "should use the package_name as the port path when it starts with /" do new_resource = Chef::Resource::Package.new("/usr/ports/www/wordpress") provider = Chef::Provider::Package::Freebsd::Pkg.new(new_resource, @run_context) - provider.should_not_receive(:popen4) - provider.port_path.should == "/usr/ports/www/wordpress" + expect(provider).not_to receive(:popen4) + expect(provider.port_path).to eq("/usr/ports/www/wordpress") end it "should use the package_name as a relative path from /usr/ports when it contains / but doesn't start with it" do @@ -159,8 +159,8 @@ describe Chef::Provider::Package::Freebsd::Pkg, "load_current_resource" do # :cookbook_name => "xenoparadox") new_resource = Chef::Resource::Package.new("www/wordpress") provider = Chef::Provider::Package::Freebsd::Pkg.new(new_resource, @run_context) - provider.should_not_receive(:popen4) - provider.port_path.should == "/usr/ports/www/wordpress" + expect(provider).not_to receive(:popen4) + expect(provider.port_path).to eq("/usr/ports/www/wordpress") end end @@ -170,15 +170,15 @@ describe Chef::Provider::Package::Freebsd::Pkg, "load_current_resource" do @current_resource = Chef::Resource::Package.new("ruby-iconv") @provider = Chef::Provider::Package::Freebsd::Pkg.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") + allow(@provider).to receive(:port_path).and_return("/usr/ports/converters/ruby-iconv") + allow(@provider).to receive(:package_name).and_return("ruby18-iconv") + allow(@provider).to receive(:latest_link_name).and_return("ruby18-iconv") @install_result = OpenStruct.new(:status => true) end it "should run pkg_add -r with the package name" do - @provider.should_receive(:shell_out!).with("pkg_add -r ruby18-iconv", :env => nil).and_return(@install_result) + expect(@provider).to receive(:shell_out!).with("pkg_add -r ruby18-iconv", :env => nil).and_return(@install_result) @provider.install_package("ruby-iconv", "1.0") end end @@ -189,11 +189,11 @@ describe Chef::Provider::Package::Freebsd::Pkg, "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") + allow(@provider).to receive(:package_name).and_return("zsh") end it "should run pkg_delete with the package name and version" do - @provider.should_receive(:shell_out!).with("pkg_delete zsh-4.3.6_7", :env => nil).and_return(@pkg_delete) + expect(@provider).to receive(:shell_out!).with("pkg_delete zsh-4.3.6_7", :env => nil).and_return(@pkg_delete) @provider.remove_package("zsh", "4.3.6_7") end end @@ -213,16 +213,16 @@ describe Chef::Provider::Package::Freebsd::Pkg, "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.port_path.should == "/usr/ports/benchmarks/bonnie++" + expect(@provider).to receive(:shell_out!).with("whereis -s bonnie++", :env => nil).and_return(whereis) + allow(@provider).to receive(:port_name).and_return("bonnie++") + expect(@provider.port_path).to eq("/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.current_installed_version.should == "1.96" + expect(@provider).to receive(:shell_out!).with('pkg_info -E "bonnie++*"', :env => nil, :returns => [0,1]).and_return(pkg_info) + allow(@provider).to receive(:package_name).and_return("bonnie++") + expect(@provider.current_installed_version).to eq("1.96") end end @@ -249,11 +249,11 @@ describe Chef::Provider::Package::Freebsd::Pkg, "load_current_resource" do @current_resource = Chef::Resource::Package.new("perl5.8") @provider = Chef::Provider::Package::Freebsd::Pkg.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") + allow(@provider).to receive(:package_name).and_return("perl") + allow(@provider).to receive(: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) + expect(@provider).to receive(:shell_out!).with("pkg_add -r perl", :env => nil).and_return(cmd) @provider.install_package("perl5.8", "5.8.8_1") end @@ -263,11 +263,11 @@ describe Chef::Provider::Package::Freebsd::Pkg, "load_current_resource" do @current_resource = Chef::Resource::Package.new("mysql50-server") @provider = Chef::Provider::Package::Freebsd::Pkg.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") + allow(@provider).to receive(:package_name).and_return("mysql-server") + allow(@provider).to receive(: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) + expect(@provider).to receive(:shell_out!).with("pkg_add -r mysql50-server", :env=>nil).and_return(cmd) @provider.install_package("mysql50-server", "5.0.45_1") end end diff --git a/spec/unit/provider/package/freebsd/pkgng_spec.rb b/spec/unit/provider/package/freebsd/pkgng_spec.rb index c3837a251b..d314735bf0 100644 --- a/spec/unit/provider/package/freebsd/pkgng_spec.rb +++ b/spec/unit/provider/package/freebsd/pkgng_spec.rb @@ -33,46 +33,46 @@ describe Chef::Provider::Package::Freebsd::Port do describe "initialization" do it "should create a current resource with the name of the new resource" do - @provider.current_resource.is_a?(Chef::Resource::Package).should be_true - @provider.current_resource.name.should == 'zsh' + expect(@provider.current_resource.is_a?(Chef::Resource::Package)).to be_true + expect(@provider.current_resource.name).to eq('zsh') end end describe "loading current resource" do before(:each) do - @provider.stub(:current_installed_version) - @provider.stub(:candidate_version) + allow(@provider).to receive(:current_installed_version) + allow(@provider).to receive(:candidate_version) end it "should set the package name" do @provider.load_current_resource - @provider.current_resource.package_name.should == "zsh" + expect(@provider.current_resource.package_name).to eq("zsh") end it "should set the current version" do - @provider.should_receive(:current_installed_version).and_return("5.0.2") + expect(@provider).to receive(:current_installed_version).and_return("5.0.2") @provider.load_current_resource - @provider.current_resource.version.should == "5.0.2" + expect(@provider.current_resource.version).to eq("5.0.2") end it "should set the candidate version" do - @provider.should_receive(:candidate_version).and_return("5.0.5") + expect(@provider).to receive(:candidate_version).and_return("5.0.5") @provider.load_current_resource - @provider.instance_variable_get(:"@candidate_version").should == "5.0.5" + expect(@provider.instance_variable_get(:"@candidate_version")).to eq("5.0.5") end end describe "determining current installed version" do before(:each) do - @provider.stub(:supports_pkgng?) + allow(@provider).to receive(:supports_pkgng?) @pkg_info = OpenStruct.new(:stdout => "zsh-3.1.7\nVersion : 3.1.7\n") end it "should query pkg database" do - @provider.should_receive(:shell_out!).with('pkg info "zsh"', :env => nil, :returns => [0,70]).and_return(@pkg_info) - @provider.current_installed_version.should == "3.1.7" + expect(@provider).to receive(:shell_out!).with('pkg info "zsh"', :env => nil, :returns => [0,70]).and_return(@pkg_info) + expect(@provider.current_installed_version).to eq("3.1.7") end end @@ -80,20 +80,20 @@ describe Chef::Provider::Package::Freebsd::Port do describe "determining candidate version" do it "should query repository" do pkg_query = OpenStruct.new(:stdout => "5.0.5\n", :exitstatus => 0) - @provider.should_receive(:shell_out!).with("pkg rquery '%v' zsh", :env => nil).and_return(pkg_query) - @provider.candidate_version.should == "5.0.5" + expect(@provider).to receive(:shell_out!).with("pkg rquery '%v' zsh", :env => nil).and_return(pkg_query) + expect(@provider.candidate_version).to eq("5.0.5") end it "should query specified repository when given option" do @provider.new_resource.options('-r LocalMirror') # This requires LocalMirror repo configuration. pkg_query = OpenStruct.new(:stdout => "5.0.3\n", :exitstatus => 0) - @provider.should_receive(:shell_out!).with("pkg rquery -r LocalMirror '%v' zsh", :env => nil).and_return(pkg_query) - @provider.candidate_version.should == "5.0.3" + expect(@provider).to receive(:shell_out!).with("pkg rquery -r LocalMirror '%v' zsh", :env => nil).and_return(pkg_query) + expect(@provider.candidate_version).to eq("5.0.3") end it "should return candidate version from file when given a file" do @provider.new_resource.source("/nas/pkg/repo/zsh-5.0.1.txz") - @provider.candidate_version.should == "5.0.1" + expect(@provider.candidate_version).to eq("5.0.1") end end @@ -105,7 +105,7 @@ describe Chef::Provider::Package::Freebsd::Port do it "should handle package source from file" do @provider.new_resource.source("/nas/pkg/repo/zsh-5.0.1.txz") - @provider.should_receive(:shell_out!). + expect(@provider).to receive(:shell_out!). with("pkg add /nas/pkg/repo/zsh-5.0.1.txz", :env => { 'LC_ALL' => nil }). and_return(@install_result) @provider.install_package("zsh", "5.0.1") @@ -113,21 +113,21 @@ describe Chef::Provider::Package::Freebsd::Port do it "should handle package source over ftp or http" do @provider.new_resource.source("http://repo.example.com/zsh-5.0.1.txz") - @provider.should_receive(:shell_out!). + expect(@provider).to receive(:shell_out!). with("pkg add http://repo.example.com/zsh-5.0.1.txz", :env => { 'LC_ALL' => nil }). and_return(@install_result) @provider.install_package("zsh", "5.0.1") end it "should handle a package name" do - @provider.should_receive(:shell_out!). + expect(@provider).to receive(:shell_out!). with("pkg install -y zsh", :env => { 'LC_ALL' => nil }).and_return(@install_result) @provider.install_package("zsh", "5.0.1") end it "should handle a package name with a specified repo" do @provider.new_resource.options('-r LocalMirror') # This requires LocalMirror repo configuration. - @provider.should_receive(:shell_out!). + expect(@provider).to receive(:shell_out!). with("pkg install -y -r LocalMirror zsh", :env => { 'LC_ALL' => nil }).and_return(@install_result) @provider.install_package("zsh", "5.0.1") end @@ -140,14 +140,14 @@ describe Chef::Provider::Package::Freebsd::Port do end it "should call pkg delete" do - @provider.should_receive(:shell_out!). + expect(@provider).to receive(:shell_out!). with("pkg delete -y zsh-5.0.1", :env => nil).and_return(@install_result) @provider.remove_package("zsh", "5.0.1") end it "should not include repo option in pkg delete" do @provider.new_resource.options('-r LocalMirror') # This requires LocalMirror repo configuration. - @provider.should_receive(:shell_out!). + expect(@provider).to receive(:shell_out!). with("pkg delete -y zsh-5.0.1", :env => nil).and_return(@install_result) @provider.remove_package("zsh", "5.0.1") end diff --git a/spec/unit/provider/package/freebsd/port_spec.rb b/spec/unit/provider/package/freebsd/port_spec.rb index 8725e5440f..3085b16a92 100644 --- a/spec/unit/provider/package/freebsd/port_spec.rb +++ b/spec/unit/provider/package/freebsd/port_spec.rb @@ -33,33 +33,33 @@ describe Chef::Provider::Package::Freebsd::Port do describe "initialization" do it "should create a current resource with the name of the new resource" do - @provider.current_resource.is_a?(Chef::Resource::Package).should be_true - @provider.current_resource.name.should == 'zsh' + expect(@provider.current_resource.is_a?(Chef::Resource::Package)).to be_true + expect(@provider.current_resource.name).to eq('zsh') end end describe "loading current resource" do before(:each) do - @provider.stub(:current_installed_version) - @provider.stub(:candidate_version) + allow(@provider).to receive(:current_installed_version) + allow(@provider).to receive(:candidate_version) end it "should set the package name" do @provider.load_current_resource - @provider.current_resource.package_name.should == "zsh" + expect(@provider.current_resource.package_name).to eq("zsh") end it "should set the current version" do - @provider.should_receive(:current_installed_version).and_return("5.0.2") + expect(@provider).to receive(:current_installed_version).and_return("5.0.2") @provider.load_current_resource - @provider.current_resource.version.should == "5.0.2" + expect(@provider.current_resource.version).to eq("5.0.2") end it "should set the candidate version" do - @provider.should_receive(:candidate_version).and_return("5.0.5") + expect(@provider).to receive(:candidate_version).and_return("5.0.5") @provider.load_current_resource - @provider.instance_variable_get(:"@candidate_version").should == "5.0.5" + expect(@provider.instance_variable_get(:"@candidate_version")).to eq("5.0.5") end end @@ -70,27 +70,27 @@ describe Chef::Provider::Package::Freebsd::Port do end it "should check 'pkg_info' if system uses pkg_* tools" do - @new_resource.stub(:supports_pkgng?) - @new_resource.should_receive(:supports_pkgng?).and_return(false) - @provider.should_receive(:shell_out!).with('pkg_info -E "zsh*"', :env => nil, :returns => [0,1]).and_return(@pkg_info) - @provider.current_installed_version.should == "3.1.7" + allow(@new_resource).to receive(:supports_pkgng?) + expect(@new_resource).to receive(:supports_pkgng?).and_return(false) + expect(@provider).to receive(:shell_out!).with('pkg_info -E "zsh*"', :env => nil, :returns => [0,1]).and_return(@pkg_info) + expect(@provider.current_installed_version).to eq("3.1.7") end it "should check 'pkg info' if make supports WITH_PKGNG if freebsd version is < 1000017" do pkg_enabled = OpenStruct.new(:stdout => "yes\n") [1000016, 1000000, 901503, 902506, 802511].each do |__freebsd_version| @node.automatic_attrs[:os_version] = __freebsd_version - @new_resource.should_receive(:shell_out!).with('make -V WITH_PKGNG', :env => nil).and_return(pkg_enabled) - @provider.should_receive(:shell_out!).with('pkg info "zsh"', :env => nil, :returns => [0,70]).and_return(@pkg_info) - @provider.current_installed_version.should == "3.1.7" + expect(@new_resource).to receive(:shell_out!).with('make -V WITH_PKGNG', :env => nil).and_return(pkg_enabled) + expect(@provider).to receive(:shell_out!).with('pkg info "zsh"', :env => nil, :returns => [0,70]).and_return(@pkg_info) + expect(@provider.current_installed_version).to eq("3.1.7") end end it "should check 'pkg info' if the freebsd version is greater than or equal to 1000017" do __freebsd_version = 1000017 @node.automatic_attrs[:os_version] = __freebsd_version - @provider.should_receive(:shell_out!).with('pkg info "zsh"', :env => nil, :returns => [0,70]).and_return(@pkg_info) - @provider.current_installed_version.should == "3.1.7" + expect(@provider).to receive(:shell_out!).with('pkg info "zsh"', :env => nil, :returns => [0,70]).and_return(@pkg_info) + expect(@provider.current_installed_version).to eq("3.1.7") end end @@ -100,15 +100,15 @@ describe Chef::Provider::Package::Freebsd::Port do end it "should return candidate version if port exists" do - ::File.stub(:exist?).with('/usr/ports/Makefile').and_return(true) - @provider.stub(:port_dir).and_return('/usr/ports/shells/zsh') - @provider.should_receive(:shell_out!).with("make -V PORTVERSION", :cwd => "/usr/ports/shells/zsh", :env => nil, :returns => [0,1]). + allow(::File).to receive(:exist?).with('/usr/ports/Makefile').and_return(true) + allow(@provider).to receive(:port_dir).and_return('/usr/ports/shells/zsh') + expect(@provider).to receive(:shell_out!).with("make -V PORTVERSION", :cwd => "/usr/ports/shells/zsh", :env => nil, :returns => [0,1]). and_return(@port_version) - @provider.candidate_version.should == "5.0.5" + expect(@provider.candidate_version).to eq("5.0.5") end it "should raise exception if ports tree not found" do - ::File.stub(:exist?).with('/usr/ports/Makefile').and_return(false) + allow(::File).to receive(:exist?).with('/usr/ports/Makefile').and_return(false) expect { @provider.candidate_version }.to raise_error(Chef::Exceptions::Package, "Ports collection could not be found") end end @@ -116,24 +116,24 @@ describe Chef::Provider::Package::Freebsd::Port do describe "determining port directory" do it "should return name if package name is absolute path" do - @provider.new_resource.stub(:package_name).and_return("/var/ports/shells/zsh") - @provider.port_dir.should == "/var/ports/shells/zsh" + allow(@provider.new_resource).to receive(:package_name).and_return("/var/ports/shells/zsh") + expect(@provider.port_dir).to eq("/var/ports/shells/zsh") end it "should return full ports path given package name and category" do - @provider.new_resource.stub(:package_name).and_return("shells/zsh") - @provider.port_dir.should == "/usr/ports/shells/zsh" + allow(@provider.new_resource).to receive(:package_name).and_return("shells/zsh") + expect(@provider.port_dir).to eq("/usr/ports/shells/zsh") end it "should query system for path given just a name" do whereis = OpenStruct.new(:stdout => "zsh: /usr/ports/shells/zsh\n") - @provider.should_receive(:shell_out!).with("whereis -s zsh", :env => nil).and_return(whereis) - @provider.port_dir.should == "/usr/ports/shells/zsh" + expect(@provider).to receive(:shell_out!).with("whereis -s zsh", :env => nil).and_return(whereis) + expect(@provider.port_dir).to eq("/usr/ports/shells/zsh") end it "should raise exception if not found" do whereis = OpenStruct.new(:stdout => "zsh:\n") - @provider.should_receive(:shell_out!).with("whereis -s zsh", :env => nil).and_return(whereis) + expect(@provider).to receive(:shell_out!).with("whereis -s zsh", :env => nil).and_return(whereis) expect { @provider.port_dir }.to raise_error(Chef::Exceptions::Package, "Could not find port with the name zsh") end end @@ -145,8 +145,8 @@ describe Chef::Provider::Package::Freebsd::Port do end it "should run make install in port directory" do - @provider.stub(:port_dir).and_return("/usr/ports/shells/zsh") - @provider.should_receive(:shell_out!). + allow(@provider).to receive(:port_dir).and_return("/usr/ports/shells/zsh") + expect(@provider).to receive(:shell_out!). with("make -DBATCH install clean", :timeout => 1800, :cwd => "/usr/ports/shells/zsh", :env => nil). and_return(@install_result) @provider.install_package("zsh", "5.0.5") @@ -160,8 +160,8 @@ describe Chef::Provider::Package::Freebsd::Port do end it "should run make deinstall in port directory" do - @provider.stub(:port_dir).and_return("/usr/ports/shells/zsh") - @provider.should_receive(:shell_out!). + allow(@provider).to receive(:port_dir).and_return("/usr/ports/shells/zsh") + expect(@provider).to receive(:shell_out!). with("make deinstall", :timeout => 300, :cwd => "/usr/ports/shells/zsh", :env => nil). and_return(@install_result) @provider.remove_package("zsh", "5.0.5") diff --git a/spec/unit/provider/package/ips_spec.rb b/spec/unit/provider/package/ips_spec.rb index 07bca7f6d5..4e0afc46e9 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) + allow(Chef::Resource::Package).to receive(:new).and_return(@current_resource) @provider = Chef::Provider::Package::Ips.new(@new_resource, @run_context) end @@ -65,30 +65,30 @@ PKG_STATUS context "when loading current resource" do it "should create a current resource with the name of the new_resource" do - @provider.should_receive(:shell_out).with("pkg info #{@new_resource.package_name}").and_return(local_output) - @provider.should_receive(:shell_out!).with("pkg info -r #{@new_resource.package_name}").and_return(remote_output) - Chef::Resource::Package.should_receive(:new).and_return(@current_resource) + expect(@provider).to receive(:shell_out).with("pkg info #{@new_resource.package_name}").and_return(local_output) + expect(@provider).to receive(:shell_out!).with("pkg info -r #{@new_resource.package_name}").and_return(remote_output) + expect(Chef::Resource::Package).to receive(:new).and_return(@current_resource) @provider.load_current_resource end it "should set the current resources package name to the new resources package name" do - @provider.should_receive(:shell_out).with("pkg info #{@new_resource.package_name}").and_return(local_output) - @provider.should_receive(:shell_out!).with("pkg info -r #{@new_resource.package_name}").and_return(remote_output) + expect(@provider).to receive(:shell_out).with("pkg info #{@new_resource.package_name}").and_return(local_output) + expect(@provider).to receive(:shell_out!).with("pkg info -r #{@new_resource.package_name}").and_return(remote_output) @provider.load_current_resource - @current_resource.package_name.should == @new_resource.package_name + expect(@current_resource.package_name).to eq(@new_resource.package_name) end it "should run pkg info with the package name" do - @provider.should_receive(:shell_out).with("pkg info #{@new_resource.package_name}").and_return(local_output) - @provider.should_receive(:shell_out!).with("pkg info -r #{@new_resource.package_name}").and_return(remote_output) + expect(@provider).to receive(:shell_out).with("pkg info #{@new_resource.package_name}").and_return(local_output) + expect(@provider).to receive(:shell_out!).with("pkg info -r #{@new_resource.package_name}").and_return(remote_output) @provider.load_current_resource end it "should set the installed version to nil on the current resource if package state is not installed" do - @provider.should_receive(:shell_out).with("pkg info #{@new_resource.package_name}").and_return(local_output) - @provider.should_receive(:shell_out!).with("pkg info -r #{@new_resource.package_name}").and_return(remote_output) + expect(@provider).to receive(:shell_out).with("pkg info #{@new_resource.package_name}").and_return(local_output) + expect(@provider).to receive(:shell_out!).with("pkg info -r #{@new_resource.package_name}").and_return(remote_output) @provider.load_current_resource - @current_resource.version.should be_nil + expect(@current_resource.version).to be_nil end it "should set the installed version if package has one" do @@ -108,28 +108,28 @@ Packaging Date: October 19, 2011 09:14:50 AM Size: 8.07 MB FMRI: pkg://solaris/crypto/gnupg@2.0.17,5.11-0.175.0.0.0.2.537:20111019T091450Z INSTALLED - @provider.should_receive(:shell_out).with("pkg info #{@new_resource.package_name}").and_return(local) - @provider.should_receive(:shell_out!).with("pkg info -r #{@new_resource.package_name}").and_return(remote_output) + expect(@provider).to receive(:shell_out).with("pkg info #{@new_resource.package_name}").and_return(local) + expect(@provider).to receive(:shell_out!).with("pkg info -r #{@new_resource.package_name}").and_return(remote_output) @provider.load_current_resource - @current_resource.version.should == "2.0.17" + expect(@current_resource.version).to eq("2.0.17") end it "should return the current resource" do - @provider.should_receive(:shell_out).with("pkg info #{@new_resource.package_name}").and_return(local_output) - @provider.should_receive(:shell_out!).with("pkg info -r #{@new_resource.package_name}").and_return(remote_output) - @provider.load_current_resource.should eql(@current_resource) + expect(@provider).to receive(:shell_out).with("pkg info #{@new_resource.package_name}").and_return(local_output) + expect(@provider).to receive(:shell_out!).with("pkg info -r #{@new_resource.package_name}").and_return(remote_output) + expect(@provider.load_current_resource).to eql(@current_resource) end end context "when installing a package" do it "should run pkg install with the package name and version" do - @provider.should_receive(:shell_out).with("pkg install -q crypto/gnupg@2.0.17") + expect(@provider).to receive(:shell_out).with("pkg install -q crypto/gnupg@2.0.17") @provider.install_package("crypto/gnupg", "2.0.17") end it "should run pkg install with the package name and version and options if specified" do - @provider.should_receive(:shell_out).with("pkg --no-refresh install -q crypto/gnupg@2.0.17") - @new_resource.stub(:options).and_return("--no-refresh") + expect(@provider).to receive(:shell_out).with("pkg --no-refresh install -q crypto/gnupg@2.0.17") + allow(@new_resource).to receive(:options).and_return("--no-refresh") @provider.install_package("crypto/gnupg", "2.0.17") end @@ -147,11 +147,11 @@ Packaging Date: April 1, 2012 05:55:52 PM Size: 2.57 MB FMRI: pkg://omnios/security/sudo@1.8.4.1,5.11-0.151002:20120401T175552Z PKG_STATUS - @provider.should_receive(:shell_out).with("pkg info #{@new_resource.package_name}").and_return(local_output) - @provider.should_receive(:shell_out!).with("pkg info -r #{@new_resource.package_name}").and_return(remote) + expect(@provider).to receive(:shell_out).with("pkg info #{@new_resource.package_name}").and_return(local_output) + expect(@provider).to receive(:shell_out!).with("pkg info -r #{@new_resource.package_name}").and_return(remote) @provider.load_current_resource - @current_resource.version.should be_nil - @provider.candidate_version.should eql("1.8.4.1") + expect(@current_resource.version).to be_nil + expect(@provider.candidate_version).to eql("1.8.4.1") end it "should not upgrade the package if it is already installed" do @@ -188,20 +188,20 @@ Packaging Date: October 19, 2011 09:14:50 AM FMRI: pkg://solaris/crypto/gnupg@2.0.18,5.11-0.175.0.0.0.2.537:20111019T091450Z REMOTE - @provider.should_receive(:shell_out).with("pkg info #{@new_resource.package_name}").and_return(local) - @provider.should_receive(:shell_out!).with("pkg info -r #{@new_resource.package_name}").and_return(remote) + expect(@provider).to receive(:shell_out).with("pkg info #{@new_resource.package_name}").and_return(local) + expect(@provider).to receive(:shell_out!).with("pkg info -r #{@new_resource.package_name}").and_return(remote) @provider.load_current_resource - @provider.should_receive(:install_package).exactly(0).times + expect(@provider).to receive(:install_package).exactly(0).times @provider.action_install end context "when accept_license is true" do before do - @new_resource.stub(:accept_license).and_return(true) + allow(@new_resource).to receive(:accept_license).and_return(true) end it "should run pkg install with the --accept flag" do - @provider.should_receive(:shell_out).with("pkg install -q --accept crypto/gnupg@2.0.17") + expect(@provider).to receive(:shell_out).with("pkg install -q --accept crypto/gnupg@2.0.17") @provider.install_package("crypto/gnupg", "2.0.17") end end @@ -209,20 +209,20 @@ REMOTE context "when upgrading a package" do it "should run pkg install with the package name and version" do - @provider.should_receive(:shell_out).with("pkg install -q crypto/gnupg@2.0.17") + expect(@provider).to receive(:shell_out).with("pkg install -q crypto/gnupg@2.0.17") @provider.upgrade_package("crypto/gnupg", "2.0.17") end end context "when uninstalling a package" do it "should run pkg uninstall with the package name and version" do - @provider.should_receive(:shell_out!).with("pkg uninstall -q crypto/gnupg@2.0.17") + expect(@provider).to receive(:shell_out!).with("pkg uninstall -q crypto/gnupg@2.0.17") @provider.remove_package("crypto/gnupg", "2.0.17") end it "should run pkg uninstall with the package name and version and options if specified" do - @provider.should_receive(:shell_out!).with("pkg --no-refresh uninstall -q crypto/gnupg@2.0.17") - @new_resource.stub(:options).and_return("--no-refresh") + expect(@provider).to receive(:shell_out!).with("pkg --no-refresh uninstall -q crypto/gnupg@2.0.17") + allow(@new_resource).to receive(: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 535a5d2459..23a8233c66 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) + allow(Chef::Resource::Package).to receive(:new).and_return(@current_resource) @status = double("Status", :exitstatus => 0) @stdin = StringIO.new @@ -38,91 +38,91 @@ describe Chef::Provider::Package::Macports do describe "load_current_resource" do it "should create a current resource with the name of the new_resource" do - @provider.should_receive(:current_installed_version).and_return(nil) - @provider.should_receive(:macports_candidate_version).and_return("4.2.7") + expect(@provider).to receive(:current_installed_version).and_return(nil) + expect(@provider).to receive(:macports_candidate_version).and_return("4.2.7") @provider.load_current_resource - @provider.current_resource.name.should == "zsh" + expect(@provider.current_resource.name).to eq("zsh") end it "should create a current resource with the version if the package is installed" do - @provider.should_receive(:macports_candidate_version).and_return("4.2.7") - @provider.should_receive(:current_installed_version).and_return("4.2.7") + expect(@provider).to receive(:macports_candidate_version).and_return("4.2.7") + expect(@provider).to receive(:current_installed_version).and_return("4.2.7") @provider.load_current_resource - @provider.candidate_version.should == "4.2.7" + expect(@provider.candidate_version).to eq("4.2.7") end it "should create a current resource with a nil version if the package is not installed" do - @provider.should_receive(:current_installed_version).and_return(nil) - @provider.should_receive(:macports_candidate_version).and_return("4.2.7") + expect(@provider).to receive(:current_installed_version).and_return(nil) + expect(@provider).to receive(:macports_candidate_version).and_return("4.2.7") @provider.load_current_resource - @provider.current_resource.version.should be_nil + expect(@provider.current_resource.version).to be_nil end it "should set a candidate version if one exists" do - @provider.should_receive(:current_installed_version).and_return(nil) - @provider.should_receive(:macports_candidate_version).and_return("4.2.7") + expect(@provider).to receive(:current_installed_version).and_return(nil) + expect(@provider).to receive(:macports_candidate_version).and_return("4.2.7") @provider.load_current_resource - @provider.candidate_version.should == "4.2.7" + expect(@provider.candidate_version).to eq("4.2.7") end end describe "current_installed_version" do it "should return the current version if the package is installed" do - @stdout.should_receive(:read).and_return(<<EOF + expect(@stdout).to receive(:read).and_return(<<EOF The following ports are currently installed: openssl @0.9.8k_0 (active) EOF ) - @provider.should_receive(:popen4).and_yield(@pid, @stdin, @stdout, @stderr).and_return(@status) - @provider.current_installed_version.should == "0.9.8k_0" + expect(@provider).to receive(:popen4).and_yield(@pid, @stdin, @stdout, @stderr).and_return(@status) + expect(@provider.current_installed_version).to eq("0.9.8k_0") end it "should return nil if a package is not currently installed" do - @stdout.should_receive(:read).and_return(" \n") - @provider.should_receive(:popen4).and_yield(@pid, @stdin, @stdout, @stderr).and_return(@status) - @provider.current_installed_version.should be_nil + expect(@stdout).to receive(:read).and_return(" \n") + expect(@provider).to receive(:popen4).and_yield(@pid, @stdin, @stdout, @stderr).and_return(@status) + expect(@provider.current_installed_version).to be_nil end end describe "macports_candidate_version" do it "should return the latest available version of a given package" do - @stdout.should_receive(:read).and_return("version: 4.2.7\n") - @provider.should_receive(:popen4).and_yield(@pid, @stdin, @stdout, @stderr).and_return(@status) - @provider.macports_candidate_version.should == "4.2.7" + expect(@stdout).to receive(:read).and_return("version: 4.2.7\n") + expect(@provider).to receive(:popen4).and_yield(@pid, @stdin, @stdout, @stderr).and_return(@status) + expect(@provider.macports_candidate_version).to eq("4.2.7") end it "should return nil if there is no version for a given package" do - @stdout.should_receive(:read).and_return("Error: port fadsfadsfads not found\n") - @provider.should_receive(:popen4).and_yield(@pid, @stdin, @stdout, @stderr).and_return(@status) - @provider.macports_candidate_version.should be_nil + expect(@stdout).to receive(:read).and_return("Error: port fadsfadsfads not found\n") + expect(@provider).to receive(:popen4).and_yield(@pid, @stdin, @stdout, @stderr).and_return(@status) + expect(@provider.macports_candidate_version).to be_nil end end describe "install_package" do it "should run the port install command with the correct version" do - @current_resource.should_receive(:version).and_return("4.1.6") + expect(@current_resource).to receive(:version).and_return("4.1.6") @provider.current_resource = @current_resource - @provider.should_receive(:shell_out!).with("port install zsh @4.2.7") + expect(@provider).to receive(:shell_out!).with("port install zsh @4.2.7") @provider.install_package("zsh", "4.2.7") end it "should not do anything if a package already exists with the same version" do - @current_resource.should_receive(:version).and_return("4.2.7") + expect(@current_resource).to receive(:version).and_return("4.2.7") @provider.current_resource = @current_resource - @provider.should_not_receive(:shell_out!) + expect(@provider).not_to receive(:shell_out!) @provider.install_package("zsh", "4.2.7") end it "should add options to the port command when specified" do - @current_resource.should_receive(:version).and_return("4.1.6") + expect(@current_resource).to receive(:version).and_return("4.1.6") @provider.current_resource = @current_resource - @new_resource.stub(:options).and_return("-f") - @provider.should_receive(:shell_out!).with("port -f install zsh @4.2.7") + allow(@new_resource).to receive(:options).and_return("-f") + expect(@provider).to receive(:shell_out!).with("port -f install zsh @4.2.7") @provider.install_package("zsh", "4.2.7") end @@ -130,72 +130,72 @@ EOF describe "purge_package" do it "should run the port uninstall command with the correct version" do - @provider.should_receive(:shell_out!).with("port uninstall zsh @4.2.7") + expect(@provider).to receive(:shell_out!).with("port uninstall zsh @4.2.7") @provider.purge_package("zsh", "4.2.7") end it "should purge the currently active version if no explicit version is passed in" do - @provider.should_receive(:shell_out!).with("port uninstall zsh") + expect(@provider).to receive(:shell_out!).with("port uninstall zsh") @provider.purge_package("zsh", nil) end it "should add options to the port command when specified" do - @new_resource.stub(:options).and_return("-f") - @provider.should_receive(:shell_out!).with("port -f uninstall zsh @4.2.7") + allow(@new_resource).to receive(:options).and_return("-f") + expect(@provider).to receive(:shell_out!).with("port -f uninstall zsh @4.2.7") @provider.purge_package("zsh", "4.2.7") end end describe "remove_package" do it "should run the port deactivate command with the correct version" do - @provider.should_receive(:shell_out!).with("port deactivate zsh @4.2.7") + expect(@provider).to receive(:shell_out!).with("port deactivate zsh @4.2.7") @provider.remove_package("zsh", "4.2.7") end it "should remove the currently active version if no explicit version is passed in" do - @provider.should_receive(:shell_out!).with("port deactivate zsh") + expect(@provider).to receive(:shell_out!).with("port deactivate zsh") @provider.remove_package("zsh", nil) end it "should add options to the port command when specified" do - @new_resource.stub(:options).and_return("-f") - @provider.should_receive(:shell_out!).with("port -f deactivate zsh @4.2.7") + allow(@new_resource).to receive(:options).and_return("-f") + expect(@provider).to receive(:shell_out!).with("port -f deactivate zsh @4.2.7") @provider.remove_package("zsh", "4.2.7") end end describe "upgrade_package" do it "should run the port upgrade command with the correct version" do - @current_resource.should_receive(:version).at_least(:once).and_return("4.1.6") + expect(@current_resource).to receive(:version).at_least(:once).and_return("4.1.6") @provider.current_resource = @current_resource - @provider.should_receive(:shell_out!).with("port upgrade zsh @4.2.7") + expect(@provider).to receive(:shell_out!).with("port upgrade zsh @4.2.7") @provider.upgrade_package("zsh", "4.2.7") end it "should not run the port upgrade command if the version is already installed" do - @current_resource.should_receive(:version).at_least(:once).and_return("4.2.7") + expect(@current_resource).to receive(:version).at_least(:once).and_return("4.2.7") @provider.current_resource = @current_resource - @provider.should_not_receive(:shell_out!) + expect(@provider).not_to receive(:shell_out!) @provider.upgrade_package("zsh", "4.2.7") end it "should call install_package if the package isn't currently installed" do - @current_resource.should_receive(:version).at_least(:once).and_return(nil) + expect(@current_resource).to receive(:version).at_least(:once).and_return(nil) @provider.current_resource = @current_resource - @provider.should_receive(:install_package).and_return(true) + expect(@provider).to receive(:install_package).and_return(true) @provider.upgrade_package("zsh", "4.2.7") end it "should add options to the port command when specified" do - @new_resource.stub(:options).and_return("-f") - @current_resource.should_receive(:version).at_least(:once).and_return("4.1.6") + allow(@new_resource).to receive(:options).and_return("-f") + expect(@current_resource).to receive(:version).at_least(:once).and_return("4.1.6") @provider.current_resource = @current_resource - @provider.should_receive(:shell_out!).with("port -f upgrade zsh @4.2.7") + expect(@provider).to receive(:shell_out!).with("port -f upgrade zsh @4.2.7") @provider.upgrade_package("zsh", "4.2.7") end diff --git a/spec/unit/provider/package/pacman_spec.rb b/spec/unit/provider/package/pacman_spec.rb index ed10513350..9fa5f9667c 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 = double("Status", :exitstatus => 0) @provider = Chef::Provider::Package::Pacman.new(@new_resource, @run_context) - Chef::Resource::Package.stub(:new).and_return(@current_resource) - @provider.stub(:popen4).and_return(@status) + allow(Chef::Resource::Package).to receive(:new).and_return(@current_resource) + allow(@provider).to receive(:popen4).and_return(@status) @stdin = StringIO.new @stdout = StringIO.new(<<-ERR) error: package "nano" not found @@ -40,29 +40,29 @@ ERR describe "when determining the current package state" do it "should create a current resource with the name of the new_resource" do - Chef::Resource::Package.should_receive(:new).and_return(@current_resource) + expect(Chef::Resource::Package).to receive(:new).and_return(@current_resource) @provider.load_current_resource end it "should set the current resources package name to the new resources package name" do - @current_resource.should_receive(:package_name).with(@new_resource.package_name) + expect(@current_resource).to receive(:package_name).with(@new_resource.package_name) @provider.load_current_resource end it "should run pacman query with the package name" do - @provider.should_receive(:popen4).with("pacman -Qi #{@new_resource.package_name}").and_return(@status) + expect(@provider).to receive(:popen4).with("pacman -Qi #{@new_resource.package_name}").and_return(@status) @provider.load_current_resource end it "should read stdout on pacman" do - @provider.stub(:popen4).and_yield(@pid, @stdin, @stdout, @stderr).and_return(@status) - @stdout.should_receive(:each).and_return(true) + allow(@provider).to receive(:popen4).and_yield(@pid, @stdin, @stdout, @stderr).and_return(@status) + expect(@stdout).to 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) - @current_resource.should_receive(:version).with(nil).and_return(true) + allow(@provider).to receive(:popen4).and_yield(@pid, @stdin, @stdout, @stderr).and_return(@status) + expect(@current_resource).to receive(:version).with(nil).and_return(true) @provider.load_current_resource end @@ -88,16 +88,16 @@ 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) + allow(@provider).to receive(:popen4).and_yield(@pid, @stdin, @stdout, @stderr).and_return(@status) @provider.load_current_resource - @current_resource.version.should == "2.2.2-1" + expect(@current_resource.version).to eq("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") - @provider.stub(:popen4).and_yield(@pid, @stdin, @stdout, @stderr).and_return(@status) + allow(@stdout).to receive(:each).and_yield("core nano 2.2.3-1") + allow(@provider).to receive(:popen4).and_yield(@pid, @stdin, @stdout, @stderr).and_return(@status) @provider.load_current_resource - @provider.candidate_version.should eql("2.2.3-1") + expect(@provider.candidate_version).to eql("2.2.3-1") end it "should use pacman.conf to determine valid repo names for package versions" do @@ -119,45 +119,45 @@ 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") - @provider.stub(:popen4).and_yield(@pid, @stdin, @stdout, @stderr).and_return(@status) + allow(::File).to receive(:exists?).with("/etc/pacman.conf").and_return(true) + allow(::File).to receive(:read).with("/etc/pacman.conf").and_return(@pacman_conf) + allow(@stdout).to receive(:each).and_yield("customrepo nano 1.2.3-4") + allow(@provider).to receive(:popen4).and_yield(@pid, @stdin, @stdout, @stderr).and_return(@status) @provider.load_current_resource - @provider.candidate_version.should eql("1.2.3-4") + expect(@provider.candidate_version).to eql("1.2.3-4") end it "should raise an exception if pacman fails" do - @status.should_receive(:exitstatus).and_return(2) - lambda { @provider.load_current_resource }.should raise_error(Chef::Exceptions::Package) + expect(@status).to receive(:exitstatus).and_return(2) + expect { @provider.load_current_resource }.to raise_error(Chef::Exceptions::Package) end it "should not raise an exception if pacman succeeds" do - @status.should_receive(:exitstatus).and_return(0) - lambda { @provider.load_current_resource }.should_not raise_error + expect(@status).to receive(:exitstatus).and_return(0) + expect { @provider.load_current_resource }.not_to raise_error end it "should raise an exception if pacman does not return a candidate version" do - @stdout.stub(:each).and_yield("") - @provider.stub(:popen4).and_yield(@pid, @stdin, @stdout, @stderr).and_return(@status) - lambda { @provider.candidate_version }.should raise_error(Chef::Exceptions::Package) + allow(@stdout).to receive(:each).and_yield("") + allow(@provider).to receive(:popen4).and_yield(@pid, @stdin, @stdout, @stderr).and_return(@status) + expect { @provider.candidate_version }.to raise_error(Chef::Exceptions::Package) end it "should return the current resouce" do - @provider.load_current_resource.should eql(@current_resource) + expect(@provider.load_current_resource).to eql(@current_resource) end end describe Chef::Provider::Package::Pacman, "install_package" do it "should run pacman install with the package name and version" do - @provider.should_receive(:shell_out!).with("pacman --sync --noconfirm --noprogressbar nano") + expect(@provider).to receive(:shell_out!).with("pacman --sync --noconfirm --noprogressbar nano") @provider.install_package("nano", "1.0") end it "should run pacman install with the package name and version and options if specified" do - @provider.should_receive(:shell_out!).with("pacman --sync --noconfirm --noprogressbar --debug nano") - @new_resource.stub(:options).and_return("--debug") + expect(@provider).to receive(:shell_out!).with("pacman --sync --noconfirm --noprogressbar --debug nano") + allow(@new_resource).to receive(:options).and_return("--debug") @provider.install_package("nano", "1.0") end @@ -165,20 +165,20 @@ PACMAN_CONF describe Chef::Provider::Package::Pacman, "upgrade_package" do it "should run install_package with the name and version" do - @provider.should_receive(:install_package).with("nano", "1.0") + expect(@provider).to receive(:install_package).with("nano", "1.0") @provider.upgrade_package("nano", "1.0") end end describe Chef::Provider::Package::Pacman, "remove_package" do it "should run pacman remove with the package name" do - @provider.should_receive(:shell_out!).with("pacman --remove --noconfirm --noprogressbar nano") + expect(@provider).to receive(:shell_out!).with("pacman --remove --noconfirm --noprogressbar nano") @provider.remove_package("nano", "1.0") end it "should run pacman remove with the package name and options if specified" do - @provider.should_receive(:shell_out!).with("pacman --remove --noconfirm --noprogressbar --debug nano") - @new_resource.stub(:options).and_return("--debug") + expect(@provider).to receive(:shell_out!).with("pacman --remove --noconfirm --noprogressbar --debug nano") + allow(@new_resource).to receive(:options).and_return("--debug") @provider.remove_package("nano", "1.0") end @@ -186,7 +186,7 @@ PACMAN_CONF describe Chef::Provider::Package::Pacman, "purge_package" do it "should run remove_package with the name and version" do - @provider.should_receive(:remove_package).with("nano", "1.0") + expect(@provider).to receive(:remove_package).with("nano", "1.0") @provider.purge_package("nano", "1.0") end diff --git a/spec/unit/provider/package/paludis_spec.rb b/spec/unit/provider/package/paludis_spec.rb index 8387bb1252..4ed5dfc003 100644 --- a/spec/unit/provider/package/paludis_spec.rb +++ b/spec/unit/provider/package/paludis_spec.rb @@ -28,7 +28,7 @@ describe Chef::Provider::Package::Paludis do @run_context = Chef::RunContext.new(@node, {}, @events) @new_resource = Chef::Resource::Package.new("net/ntp") @current_resource = Chef::Resource::Package.new("net/ntp") - Chef::Resource::Package.stub(:new).and_return(@current_resource) + allow(Chef::Resource::Package).to receive(:new).and_return(@current_resource) @provider = Chef::Provider::Package::Paludis.new(@new_resource, @run_context) @stdin = StringIO.new @@ -47,19 +47,19 @@ PKG_STATUS context "when loading current resource" do it "should create a current resource with the name of the new_resource" do - @provider.should_receive(:shell_out!).and_return(@shell_out) - Chef::Resource::Package.should_receive(:new).and_return(@current_resource) + expect(@provider).to receive(:shell_out!).and_return(@shell_out) + expect(Chef::Resource::Package).to receive(:new).and_return(@current_resource) @provider.load_current_resource end it "should set the current resources package name to the new resources package name" do - @provider.should_receive(:shell_out!).and_return(@shell_out) - @current_resource.should_receive(:package_name).with(@new_resource.package_name) + expect(@provider).to receive(:shell_out!).and_return(@shell_out) + expect(@current_resource).to receive(:package_name).with(@new_resource.package_name) @provider.load_current_resource end it "should run pkg info with the package name" do - @provider.should_receive(:shell_out!).with("cave -L warning print-ids -M none -m \"#{@new_resource.package_name}\" -f \"%c/%p %v %r\n\"").and_return(@shell_out) + expect(@provider).to receive(:shell_out!).with("cave -L warning print-ids -M none -m \"#{@new_resource.package_name}\" -f \"%c/%p %v %r\n\"").and_return(@shell_out) @provider.load_current_resource end @@ -72,28 +72,28 @@ user/ntp 0 accounts user/ntp 0 installed-accounts net/ntp 4.2.6_p5-r1 installed INSTALLED - @provider.should_receive(:shell_out!).and_return(@shell_out) + expect(@provider).to receive(:shell_out!).and_return(@shell_out) @provider.load_current_resource - @current_resource.version.should == "4.2.6_p5-r1" - @provider.candidate_version.should eql("4.2.6_p5-r2") + expect(@current_resource.version).to eq("4.2.6_p5-r1") + expect(@provider.candidate_version).to eql("4.2.6_p5-r2") end it "should return the current resource" do - @provider.should_receive(:shell_out!).and_return(@shell_out) - @provider.load_current_resource.should eql(@current_resource) + expect(@provider).to receive(:shell_out!).and_return(@shell_out) + expect(@provider.load_current_resource).to eql(@current_resource) end end context "when installing a package" do it "should run pkg install with the package name and version" do - @provider.should_receive(:shell_out!).with("cave -L warning resolve -x \"=net/ntp-4.2.6_p5-r2\"", {:timeout=>@new_resource.timeout}) + expect(@provider).to receive(:shell_out!).with("cave -L warning resolve -x \"=net/ntp-4.2.6_p5-r2\"", {:timeout=>@new_resource.timeout}) @provider.install_package("net/ntp", "4.2.6_p5-r2") end it "should run pkg install with the package name and version and options if specified" do - @provider.should_receive(:shell_out!).with("cave -L warning resolve -x --preserve-world \"=net/ntp-4.2.6_p5-r2\"", {:timeout=>@new_resource.timeout}) - @new_resource.stub(:options).and_return("--preserve-world") + expect(@provider).to receive(:shell_out!).with("cave -L warning resolve -x --preserve-world \"=net/ntp-4.2.6_p5-r2\"", {:timeout=>@new_resource.timeout}) + allow(@new_resource).to receive(:options).and_return("--preserve-world") @provider.install_package("net/ntp", "4.2.6_p5-r2") end @@ -102,7 +102,7 @@ INSTALLED sys-process/lsof 4.87 arbor sys-process/lsof 4.87 x86_64 PKG_STATUS - @provider.should_receive(:shell_out!).with("cave -L warning resolve -x \"=sys-process/lsof-4.87\"", {:timeout=>@new_resource.timeout}) + expect(@provider).to receive(:shell_out!).with("cave -L warning resolve -x \"=sys-process/lsof-4.87\"", {:timeout=>@new_resource.timeout}) @provider.install_package("sys-process/lsof", "4.87") end @@ -111,23 +111,23 @@ PKG_STATUS sys-process/lsof 4.87 arbor sys-process/lsof 4.87 x86_64 PKG_STATUS - @provider.should_receive(:shell_out!).and_return(@shell_out) + expect(@provider).to receive(:shell_out!).and_return(@shell_out) @provider.load_current_resource - @current_resource.version.should be_nil - @provider.candidate_version.should eql("4.87") + expect(@current_resource.version).to be_nil + expect(@provider.candidate_version).to eql("4.87") end end context "when upgrading a package" do it "should run pkg install with the package name and version" do - @provider.should_receive(:shell_out!).with("cave -L warning resolve -x \"=net/ntp-4.2.6_p5-r2\"", {:timeout=>@new_resource.timeout}) + expect(@provider).to receive(:shell_out!).with("cave -L warning resolve -x \"=net/ntp-4.2.6_p5-r2\"", {:timeout=>@new_resource.timeout}) @provider.upgrade_package("net/ntp", "4.2.6_p5-r2") end end context "when uninstalling a package" do it "should run pkg uninstall with the package name and version" do - @provider.should_receive(:shell_out!).with("cave -L warning uninstall -x \"=net/ntp-4.2.6_p5-r2\"") + expect(@provider).to receive(:shell_out!).with("cave -L warning uninstall -x \"=net/ntp-4.2.6_p5-r2\"") @provider.remove_package("net/ntp", "4.2.6_p5-r2") end diff --git a/spec/unit/provider/package/portage_spec.rb b/spec/unit/provider/package/portage_spec.rb index 570f123168..f83eda45de 100644 --- a/spec/unit/provider/package/portage_spec.rb +++ b/spec/unit/provider/package/portage_spec.rb @@ -27,73 +27,73 @@ 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) + allow(Chef::Resource::Package).to receive(: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"]) - Chef::Resource::Package.should_receive(:new).and_return(@current_resource) + allow(::Dir).to receive(:[]).with("/var/db/pkg/dev-util/git-*").and_return(["/var/db/pkg/dev-util/git-1.0.0"]) + expect(Chef::Resource::Package).to 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"]) - @current_resource.should_receive(:package_name).with(@new_resource.package_name) + allow(::Dir).to receive(:[]).with("/var/db/pkg/dev-util/git-*").and_return(["/var/db/pkg/dev-util/git-1.0.0"]) + expect(@current_resource).to 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"]) + allow(::Dir).to receive(:[]).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" + expect(@provider.current_resource.version).to eq("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"]) + allow(::Dir).to receive(:[]).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" + expect(@provider.current_resource.version).to eq("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"]) + allow(::Dir).to receive(:[]).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 + expect(@provider.current_resource.version).to 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"]) + allow(::Dir).to receive(:[]).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" + expect(@provider.current_resource.version).to eq("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"]) + allow(::Dir).to receive(:[]).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 + expect(@provider.current_resource.version).to 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"]) + allow(::Dir).to receive(:[]).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) + expect { @provider.load_current_resource }.to 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"]) + allow(::Dir).to receive(:[]).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 + expect(@provider.current_resource.version).to 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"]) + allow(::Dir).to receive(:[]).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 + expect(@provider.current_resource.version).to be_nil end end @@ -102,14 +102,14 @@ describe Chef::Provider::Package::Portage, "load_current_resource" do describe Chef::Provider::Package::Portage, "candidate_version" do it "should return the candidate_version variable if already set" do @provider.candidate_version = "1.0.0" - @provider.should_not_receive(:popen4) + expect(@provider).not_to receive(:popen4) @provider.candidate_version end it "should throw an exception if the exitstatus is not 0" do @status = double("Status", :exitstatus => 1) - @provider.stub(:popen4).and_return(@status) - lambda { @provider.candidate_version }.should raise_error(Chef::Exceptions::Package) + allow(@provider).to receive(:popen4).and_return(@status) + expect { @provider.candidate_version }.to raise_error(Chef::Exceptions::Package) end it "should find the candidate_version if a category is specifed and there are no duplicates" do @@ -144,8 +144,8 @@ Searching... EOF @status = double("Status", :exitstatus => 0) - @provider.should_receive(:popen4).and_yield(nil, nil, StringIO.new(output), nil).and_return(@status) - @provider.candidate_version.should == "1.6.0.6" + expect(@provider).to receive(:popen4).and_yield(nil, nil, StringIO.new(output), nil).and_return(@status) + expect(@provider.candidate_version).to eq("1.6.0.6") end it "should find the candidate_version if a category is not specifed and there are no duplicates" do @@ -181,8 +181,8 @@ EOF @status = double("Status", :exitstatus => 0) @provider = Chef::Provider::Package::Portage.new(@new_resource_without_category, @run_context) - @provider.should_receive(:popen4).and_yield(nil, nil, StringIO.new(output), nil).and_return(@status) - @provider.candidate_version.should == "1.6.0.6" + expect(@provider).to receive(:popen4).and_yield(nil, nil, StringIO.new(output), nil).and_return(@status) + expect(@provider.candidate_version).to eq("1.6.0.6") end it "should throw an exception if a category is not specified and there are duplicates" do @@ -226,8 +226,8 @@ EOF @status = double("Status", :exitstatus => 0) @provider = Chef::Provider::Package::Portage.new(@new_resource_without_category, @run_context) - @provider.should_receive(:popen4).and_yield(nil, nil, StringIO.new(output), nil).and_return(@status) - lambda { @provider.candidate_version }.should raise_error(Chef::Exceptions::Package) + expect(@provider).to receive(:popen4).and_yield(nil, nil, StringIO.new(output), nil).and_return(@status) + expect { @provider.candidate_version }.to raise_error(Chef::Exceptions::Package) end it "should find the candidate_version if a category is specifed and there are category duplicates" do @@ -271,25 +271,25 @@ EOF @status = double("Status", :exitstatus => 0) @provider = Chef::Provider::Package::Portage.new(@new_resource, @run_context) - @provider.should_receive(:popen4).and_yield(nil, nil, StringIO.new(output), nil).and_return(@status) - @provider.candidate_version.should == "1.6.0.6" + expect(@provider).to receive(:popen4).and_yield(nil, nil, StringIO.new(output), nil).and_return(@status) + expect(@provider.candidate_version).to eq("1.6.0.6") end end describe Chef::Provider::Package::Portage, "install_package" do it "should install a normally versioned package using portage" do - @provider.should_receive(:shell_out!).with("emerge -g --color n --nospinner --quiet =dev-util/git-1.0.0") + expect(@provider).to receive(:shell_out!).with("emerge -g --color n --nospinner --quiet =dev-util/git-1.0.0") @provider.install_package("dev-util/git", "1.0.0") end it "should install a tilde versioned package using portage" do - @provider.should_receive(:shell_out!).with("emerge -g --color n --nospinner --quiet ~dev-util/git-1.0.0") + expect(@provider).to receive(:shell_out!).with("emerge -g --color n --nospinner --quiet ~dev-util/git-1.0.0") @provider.install_package("dev-util/git", "~1.0.0") end it "should add options to the emerge command when specified" do - @provider.should_receive(:shell_out!).with("emerge -g --color n --nospinner --quiet --oneshot =dev-util/git-1.0.0") - @new_resource.stub(:options).and_return("--oneshot") + expect(@provider).to receive(:shell_out!).with("emerge -g --color n --nospinner --quiet --oneshot =dev-util/git-1.0.0") + allow(@new_resource).to receive(:options).and_return("--oneshot") @provider.install_package("dev-util/git", "1.0.0") end @@ -297,12 +297,12 @@ EOF describe Chef::Provider::Package::Portage, "remove_package" do it "should un-emerge the package with no version specified" do - @provider.should_receive(:shell_out!).with("emerge --unmerge --color n --nospinner --quiet dev-util/git") + expect(@provider).to receive(:shell_out!).with("emerge --unmerge --color n --nospinner --quiet dev-util/git") @provider.remove_package("dev-util/git", nil) end it "should un-emerge the package with a version specified" do - @provider.should_receive(:shell_out!).with("emerge --unmerge --color n --nospinner --quiet =dev-util/git-1.0.0") + expect(@provider).to receive(:shell_out!).with("emerge --unmerge --color n --nospinner --quiet =dev-util/git-1.0.0") @provider.remove_package("dev-util/git", "1.0.0") end end diff --git a/spec/unit/provider/package/rpm_spec.rb b/spec/unit/provider/package/rpm_spec.rb index 9a96d829b8..2aceee59a5 100644 --- a/spec/unit/provider/package/rpm_spec.rb +++ b/spec/unit/provider/package/rpm_spec.rb @@ -30,55 +30,55 @@ describe Chef::Provider::Package::Rpm do @provider = Chef::Provider::Package::Rpm.new(@new_resource, @run_context) @status = double("Status", :exitstatus => 0) - ::File.stub(:exists?).and_return(true) + allow(::File).to receive(: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) + allow(@provider).to receive(:popen4).and_return(@status) @provider.load_current_resource - @provider.current_resource.name.should == "ImageMagick-c++" + expect(@provider.current_resource.name).to eq("ImageMagick-c++") end it "should set the current reource package name to the new resource package name" do - @provider.stub(:popen4).and_return(@status) + allow(@provider).to receive(:popen4).and_return(@status) @provider.load_current_resource - @provider.current_resource.package_name.should == 'ImageMagick-c++' + expect(@provider.current_resource.package_name).to eq('ImageMagick-c++') end it "should raise an exception if a source is supplied but not found" do - ::File.stub(:exists?).and_return(false) - lambda { @provider.run_action(:any) }.should raise_error(Chef::Exceptions::Package) + allow(::File).to receive(:exists?).and_return(false) + expect { @provider.run_action(:any) }.to raise_error(Chef::Exceptions::Package) end it "should get the source package version from rpm if provided" do @stdout = StringIO.new("ImageMagick-c++ 6.5.4.7-7.el6_5") - @provider.should_receive(:popen4).with("rpm -qp --queryformat '%{NAME} %{VERSION}-%{RELEASE}\n' /tmp/ImageMagick-c++-6.5.4.7-7.el6_5.x86_64.rpm").and_yield(@pid, @stdin, @stdout, @stderr).and_return(@status) - @provider.should_receive(:popen4).with("rpm -q --queryformat '%{NAME} %{VERSION}-%{RELEASE}\n' ImageMagick-c++").and_return(@status) + expect(@provider).to receive(:popen4).with("rpm -qp --queryformat '%{NAME} %{VERSION}-%{RELEASE}\n' /tmp/ImageMagick-c++-6.5.4.7-7.el6_5.x86_64.rpm").and_yield(@pid, @stdin, @stdout, @stderr).and_return(@status) + expect(@provider).to receive(:popen4).with("rpm -q --queryformat '%{NAME} %{VERSION}-%{RELEASE}\n' ImageMagick-c++").and_return(@status) @provider.load_current_resource - @provider.current_resource.package_name.should == "ImageMagick-c++" - @provider.new_resource.version.should == "6.5.4.7-7.el6_5" + expect(@provider.current_resource.package_name).to eq("ImageMagick-c++") + expect(@provider.new_resource.version).to eq("6.5.4.7-7.el6_5") end it "should return the current version installed if found by rpm" do @stdout = StringIO.new("ImageMagick-c++ 6.5.4.7-7.el6_5") - @provider.should_receive(:popen4).with("rpm -qp --queryformat '%{NAME} %{VERSION}-%{RELEASE}\n' /tmp/ImageMagick-c++-6.5.4.7-7.el6_5.x86_64.rpm").and_return(@status) - @provider.should_receive(:popen4).with("rpm -q --queryformat '%{NAME} %{VERSION}-%{RELEASE}\n' ImageMagick-c++").and_yield(@pid, @stdin, @stdout, @stderr).and_return(@status) + expect(@provider).to receive(:popen4).with("rpm -qp --queryformat '%{NAME} %{VERSION}-%{RELEASE}\n' /tmp/ImageMagick-c++-6.5.4.7-7.el6_5.x86_64.rpm").and_return(@status) + expect(@provider).to receive(:popen4).with("rpm -q --queryformat '%{NAME} %{VERSION}-%{RELEASE}\n' ImageMagick-c++").and_yield(@pid, @stdin, @stdout, @stderr).and_return(@status) @provider.load_current_resource - @provider.current_resource.version.should == "6.5.4.7-7.el6_5" + expect(@provider.current_resource.version).to eq("6.5.4.7-7.el6_5") end it "should raise an exception if the source is not set but we are installing" do new_resource = Chef::Resource::Package.new("ImageMagick-c++") provider = Chef::Provider::Package::Rpm.new(new_resource, @run_context) - lambda { provider.run_action(:any) }.should raise_error(Chef::Exceptions::Package) + expect { provider.run_action(:any) }.to raise_error(Chef::Exceptions::Package) end it "should raise an exception if rpm fails to run" do status = double("Status", :exitstatus => -1) - @provider.stub(:popen4).and_return(status) - lambda { @provider.run_action(:any) }.should raise_error(Chef::Exceptions::Package) + allow(@provider).to receive(:popen4).and_return(status) + expect { @provider.run_action(:any) }.to raise_error(Chef::Exceptions::Package) end it "should not detect the package name as version when not installed" do @@ -87,10 +87,10 @@ describe Chef::Provider::Package::Rpm do @new_resource = Chef::Resource::Package.new("openssh-askpass") @new_resource.source 'openssh-askpass' @provider = Chef::Provider::Package::Rpm.new(@new_resource, @run_context) - @provider.should_receive(:popen4).with("rpm -qp --queryformat '%{NAME} %{VERSION}-%{RELEASE}\n' openssh-askpass").and_yield(@pid, @stdin, @stdout, @stderr).and_return(@status) - @provider.should_receive(:popen4).with("rpm -q --queryformat '%{NAME} %{VERSION}-%{RELEASE}\n' openssh-askpass").and_return(@status) + expect(@provider).to receive(:popen4).with("rpm -qp --queryformat '%{NAME} %{VERSION}-%{RELEASE}\n' openssh-askpass").and_yield(@pid, @stdin, @stdout, @stderr).and_return(@status) + expect(@provider).to receive(:popen4).with("rpm -q --queryformat '%{NAME} %{VERSION}-%{RELEASE}\n' openssh-askpass").and_return(@status) @provider.load_current_resource - @provider.current_resource.version.should be_nil + expect(@provider.current_resource.version).to be_nil end end @@ -102,54 +102,54 @@ describe Chef::Provider::Package::Rpm do describe "when installing or upgrading" do it "should run rpm -i with the package source to install" do - @provider.should_receive(:shell_out!).with("rpm -i /tmp/ImageMagick-c++-6.5.4.7-7.el6_5.x86_64.rpm") + expect(@provider).to receive(:shell_out!).with("rpm -i /tmp/ImageMagick-c++-6.5.4.7-7.el6_5.x86_64.rpm") @provider.install_package("ImageMagick-c++", "6.5.4.7-7.el6_5") end it "should run rpm -U with the package source to upgrade" do @current_resource.version("21.4-19.el5") - @provider.should_receive(:shell_out!).with("rpm -U /tmp/ImageMagick-c++-6.5.4.7-7.el6_5.x86_64.rpm") + expect(@provider).to receive(:shell_out!).with("rpm -U /tmp/ImageMagick-c++-6.5.4.7-7.el6_5.x86_64.rpm") @provider.upgrade_package("ImageMagick-c++", "6.5.4.7-7.el6_5") end it "should install package if missing and set to upgrade" do @current_resource.version("ImageMagick-c++") - @provider.should_receive(:shell_out!).with("rpm -U /tmp/ImageMagick-c++-6.5.4.7-7.el6_5.x86_64.rpm") + expect(@provider).to receive(:shell_out!).with("rpm -U /tmp/ImageMagick-c++-6.5.4.7-7.el6_5.x86_64.rpm") @provider.upgrade_package("ImageMagick-c++", "6.5.4.7-7.el6_5") end it "should install from a path when the package is a path and the source is nil" do @new_resource = Chef::Resource::Package.new("/tmp/ImageMagick-c++-6.5.4.7-7.el6_5.x86_64.rpm") @provider = Chef::Provider::Package::Rpm.new(@new_resource, @run_context) - @new_resource.source.should == "/tmp/ImageMagick-c++-6.5.4.7-7.el6_5.x86_64.rpm" + expect(@new_resource.source).to eq("/tmp/ImageMagick-c++-6.5.4.7-7.el6_5.x86_64.rpm") @current_resource = Chef::Resource::Package.new("ImageMagick-c++") @provider.current_resource = @current_resource - @provider.should_receive(:shell_out!).with("rpm -i /tmp/ImageMagick-c++-6.5.4.7-7.el6_5.x86_64.rpm") + expect(@provider).to receive(:shell_out!).with("rpm -i /tmp/ImageMagick-c++-6.5.4.7-7.el6_5.x86_64.rpm") @provider.install_package("/tmp/ImageMagick-c++-6.5.4.7-7.el6_5.x86_64.rpm", "6.5.4.7-7.el6_5") end it "should uprgrade from a path when the package is a path and the source is nil" do @new_resource = Chef::Resource::Package.new("/tmp/ImageMagick-c++-6.5.4.7-7.el6_5.x86_64.rpm") @provider = Chef::Provider::Package::Rpm.new(@new_resource, @run_context) - @new_resource.source.should == "/tmp/ImageMagick-c++-6.5.4.7-7.el6_5.x86_64.rpm" + expect(@new_resource.source).to eq("/tmp/ImageMagick-c++-6.5.4.7-7.el6_5.x86_64.rpm") @current_resource = Chef::Resource::Package.new("ImageMagick-c++") @current_resource.version("21.4-19.el5") @provider.current_resource = @current_resource - @provider.should_receive(:shell_out!).with("rpm -U /tmp/ImageMagick-c++-6.5.4.7-7.el6_5.x86_64.rpm") + expect(@provider).to receive(:shell_out!).with("rpm -U /tmp/ImageMagick-c++-6.5.4.7-7.el6_5.x86_64.rpm") @provider.upgrade_package("/tmp/ImageMagick-c++-6.5.4.7-7.el6_5.x86_64.rpm", "6.5.4.7-7.el6_5") end it "installs with custom options specified in the resource" do @provider.candidate_version = '11' @new_resource.options("--dbpath /var/lib/rpm") - @provider.should_receive(:shell_out!).with("rpm --dbpath /var/lib/rpm -i /tmp/ImageMagick-c++-6.5.4.7-7.el6_5.x86_64.rpm") + expect(@provider).to receive(:shell_out!).with("rpm --dbpath /var/lib/rpm -i /tmp/ImageMagick-c++-6.5.4.7-7.el6_5.x86_64.rpm") @provider.install_package(@new_resource.name, @provider.candidate_version) end end describe "when removing the package" do it "should run rpm -e to remove the package" do - @provider.should_receive(:shell_out!).with("rpm -e ImageMagick-c++-6.5.4.7-7.el6_5") + expect(@provider).to receive(:shell_out!).with("rpm -e ImageMagick-c++-6.5.4.7-7.el6_5") @provider.remove_package("ImageMagick-c++", "6.5.4.7-7.el6_5") end end diff --git a/spec/unit/provider/package/rubygems_spec.rb b/spec/unit/provider/package/rubygems_spec.rb index f4d0cebf62..bce0054220 100644 --- a/spec/unit/provider/package/rubygems_spec.rb +++ b/spec/unit/provider/package/rubygems_spec.rb @@ -39,23 +39,23 @@ describe Chef::Provider::Package::Rubygems::CurrentGemEnvironment do end it "determines the gem paths from the in memory rubygems" do - @gem_env.gem_paths.should == Gem.path + expect(@gem_env.gem_paths).to eq(Gem.path) end it "determines the installed versions of gems from Gem.source_index" do gems = [gemspec('rspec-core', Gem::Version.new('1.2.9')), gemspec('rspec-core', Gem::Version.new('1.3.0'))] if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.8.0') - Gem::Specification.should_receive(:find_all_by_name).with('rspec-core', Gem::Dependency.new('rspec-core').requirement).and_return(gems) + expect(Gem::Specification).to receive(:find_all_by_name).with('rspec-core', Gem::Dependency.new('rspec-core').requirement).and_return(gems) else - Gem.source_index.should_receive(:search).with(Gem::Dependency.new('rspec-core', nil)).and_return(gems) + expect(Gem.source_index).to receive(:search).with(Gem::Dependency.new('rspec-core', nil)).and_return(gems) end - @gem_env.installed_versions(Gem::Dependency.new('rspec-core', nil)).should == gems + expect(@gem_env.installed_versions(Gem::Dependency.new('rspec-core', nil))).to eq(gems) end it "determines the installed versions of gems from the source index (part2: the unmockening)" do expected = ['rspec-core', Gem::Version.new(RSpec::Core::Version::STRING)] actual = @gem_env.installed_versions(Gem::Dependency.new('rspec-core', nil)).map { |spec| [spec.name, spec.version] } - actual.should include(expected) + expect(actual).to include(expected) end it "yields to a block with an alternate source list set" do @@ -68,8 +68,8 @@ describe Chef::Provider::Package::Rubygems::CurrentGemEnvironment do end rescue RuntimeError end - sources_in_block.should == %w{http://gems.example.org} - Gem.sources.should == normal_sources + expect(sources_in_block).to eq(%w{http://gems.example.org}) + expect(Gem.sources).to eq(normal_sources) end it "it doesnt alter the gem sources if none are set" do @@ -82,29 +82,29 @@ describe Chef::Provider::Package::Rubygems::CurrentGemEnvironment do end rescue RuntimeError end - sources_in_block.should == normal_sources - Gem.sources.should == normal_sources + expect(sources_in_block).to eq(normal_sources) + expect(Gem.sources).to eq(normal_sources) end 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) + allow(@gem_env).to receive(: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') + expect(dep_installer).to receive(:find_gems_with_sources).with(dep).and_return(latest) + expect(@gem_env.candidate_version_from_remote(Gem::Dependency.new('rspec', '>= 0'))).to eq(Gem::Version.new('1.3.0')) end 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) + allow(@gem_env).to receive(:dependency_installer).and_return(dep_installer) best_gem = double("best gem match", :spec => gemspec("rspec", Gem::Version.new("1.3.0")), :source => "https://rubygems.org") available_set = double("Gem::AvailableSet test double") - available_set.should_receive(:pick_best!) - available_set.should_receive(:set).and_return([best_gem]) - dep_installer.should_receive(:find_gems_with_sources).with(dep).and_return(available_set) - @gem_env.candidate_version_from_remote(Gem::Dependency.new('rspec', '>= 0')).should == Gem::Version.new('1.3.0') + expect(available_set).to receive(:pick_best!) + expect(available_set).to receive(:set).and_return([best_gem]) + expect(dep_installer).to receive(:find_gems_with_sources).with(dep).and_return(available_set) + expect(@gem_env.candidate_version_from_remote(Gem::Dependency.new('rspec', '>= 0'))).to eq(Gem::Version.new('1.3.0')) end context "when rubygems was upgraded from 1.8->2.0" do @@ -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) + allow(Gem::Package).to receive(:respond_to?).with(:open).and_return(false) end after do @@ -132,8 +132,8 @@ describe Chef::Provider::Package::Rubygems::CurrentGemEnvironment do it "finds a matching gem candidate version on rubygems 2.0+ with some rubygems 1.8 code loaded" do package = double("Gem::Package", :spec => "a gemspec from package") - Gem::Package.should_receive(:new).with("/path/to/package.gem").and_return(package) - @gem_env.spec_from_file("/path/to/package.gem").should == "a gemspec from package" + expect(Gem::Package).to receive(:new).with("/path/to/package.gem").and_return(package) + expect(@gem_env.spec_from_file("/path/to/package.gem")).to eq("a gemspec from package") end end @@ -142,54 +142,54 @@ 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) - 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 + allow(@gem_env).to receive(:dependency_installer).and_return(dep_installer) + expect(dep_installer).to receive(:find_gems_with_sources).with(dep).and_return(latest) + expect(@gem_env.candidate_version_from_remote(Gem::Dependency.new('rspec', '>= 0'))).to be_nil end it "finds a matching candidate version from a .gem file when the path to the gem is supplied" do location = CHEF_SPEC_DATA + '/gems/chef-integration-test-0.1.0.gem' - @gem_env.candidate_version_from_file(Gem::Dependency.new('chef-integration-test', '>= 0'), location).should == Gem::Version.new('0.1.0') - @gem_env.candidate_version_from_file(Gem::Dependency.new('chef-integration-test', '>= 0.2.0'), location).should be_nil + expect(@gem_env.candidate_version_from_file(Gem::Dependency.new('chef-integration-test', '>= 0'), location)).to eq(Gem::Version.new('0.1.0')) + expect(@gem_env.candidate_version_from_file(Gem::Dependency.new('chef-integration-test', '>= 0.2.0'), location)).to be_nil end it "finds a matching gem from a specific gemserver when explicit sources are given" do dep = Gem::Dependency.new('rspec', '>= 0') latest = [[gemspec("rspec", Gem::Version.new("1.3.0")), "http://rubygems.org/"]] - @gem_env.should_receive(:with_gem_sources).with('http://gems.example.com').and_yield + expect(@gem_env).to 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) - 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') + allow(@gem_env).to receive(:dependency_installer).and_return(dep_installer) + expect(dep_installer).to receive(:find_gems_with_sources).with(dep).and_return(latest) + expect(@gem_env.candidate_version_from_remote(Gem::Dependency.new('rspec', '>=0'), 'http://gems.example.com')).to eq(Gem::Version.new('1.3.0')) end it "installs a gem with a hash of options for the dependency installer" do dep_installer = Gem::DependencyInstaller.new - @gem_env.should_receive(:dependency_installer).with(:install_dir => '/foo/bar').and_return(dep_installer) - @gem_env.should_receive(:with_gem_sources).with('http://gems.example.com').and_yield - dep_installer.should_receive(:install).with(Gem::Dependency.new('rspec', '>= 0')) + expect(@gem_env).to receive(:dependency_installer).with(:install_dir => '/foo/bar').and_return(dep_installer) + expect(@gem_env).to receive(:with_gem_sources).with('http://gems.example.com').and_yield + expect(dep_installer).to receive(:install).with(Gem::Dependency.new('rspec', '>= 0')) @gem_env.install(Gem::Dependency.new('rspec', '>= 0'), :install_dir => '/foo/bar', :sources => ['http://gems.example.com']) end it "builds an uninstaller for a gem with options set to avoid requiring user input" do # default options for uninstaller should be: # :ignore => true, :executables => true - Gem::Uninstaller.should_receive(:new).with('rspec', :ignore => true, :executables => true) + expect(Gem::Uninstaller).to receive(:new).with('rspec', :ignore => true, :executables => true) @gem_env.uninstaller('rspec') end it "uninstalls all versions of a gem" do uninstaller = double('gem uninstaller') - uninstaller.should_receive(:uninstall) - @gem_env.should_receive(:uninstaller).with('rspec', :all => true).and_return(uninstaller) + expect(uninstaller).to receive(:uninstall) + expect(@gem_env).to receive(:uninstaller).with('rspec', :all => true).and_return(uninstaller) @gem_env.uninstall('rspec') end it "uninstalls a specific version of a gem" do uninstaller = double('gem uninstaller') - uninstaller.should_receive(:uninstall) - @gem_env.should_receive(:uninstaller).with('rspec', :version => '1.2.3').and_return(uninstaller) + expect(uninstaller).to receive(:uninstall) + expect(@gem_env).to receive(:uninstaller).with('rspec', :version => '1.2.3').and_return(uninstaller) @gem_env.uninstall('rspec', '1.2.3') end @@ -207,35 +207,35 @@ describe Chef::Provider::Package::Rubygems::AlternateGemEnvironment do it "determines the gem paths from shelling out to gem env" do gem_env_output = ['/path/to/gems', '/another/path/to/gems'].join(File::PATH_SEPARATOR) shell_out_result = OpenStruct.new(:stdout => gem_env_output) - @gem_env.should_receive(:shell_out!).with('/usr/weird/bin/gem env gempath').and_return(shell_out_result) - @gem_env.gem_paths.should == ['/path/to/gems', '/another/path/to/gems'] + expect(@gem_env).to receive(:shell_out!).with('/usr/weird/bin/gem env gempath').and_return(shell_out_result) + expect(@gem_env.gem_paths).to eq(['/path/to/gems', '/another/path/to/gems']) end it "caches the gempaths by gem_binary" do gem_env_output = ['/path/to/gems', '/another/path/to/gems'].join(File::PATH_SEPARATOR) shell_out_result = OpenStruct.new(:stdout => gem_env_output) - @gem_env.should_receive(:shell_out!).with('/usr/weird/bin/gem env gempath').and_return(shell_out_result) + expect(@gem_env).to receive(:shell_out!).with('/usr/weird/bin/gem env gempath').and_return(shell_out_result) expected = ['/path/to/gems', '/another/path/to/gems'] - @gem_env.gem_paths.should == ['/path/to/gems', '/another/path/to/gems'] - Chef::Provider::Package::Rubygems::AlternateGemEnvironment.gempath_cache['/usr/weird/bin/gem'].should == expected + expect(@gem_env.gem_paths).to eq(['/path/to/gems', '/another/path/to/gems']) + expect(Chef::Provider::Package::Rubygems::AlternateGemEnvironment.gempath_cache['/usr/weird/bin/gem']).to eq(expected) end it "uses the cached result for gem paths when available" do gem_env_output = ['/path/to/gems', '/another/path/to/gems'].join(File::PATH_SEPARATOR) shell_out_result = OpenStruct.new(:stdout => gem_env_output) - @gem_env.should_not_receive(:shell_out!) + expect(@gem_env).not_to receive(:shell_out!) expected = ['/path/to/gems', '/another/path/to/gems'] Chef::Provider::Package::Rubygems::AlternateGemEnvironment.gempath_cache['/usr/weird/bin/gem']= expected - @gem_env.gem_paths.should == ['/path/to/gems', '/another/path/to/gems'] + expect(@gem_env.gem_paths).to eq(['/path/to/gems', '/another/path/to/gems']) 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']) + allow(@gem_env).to receive(: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' ] + expect(Gem::Specification.dirs).to eq([ '/path/to/gems/specifications', '/another/path/to/gems/specifications' ]) else - Gem::SourceIndex.should_receive(:from_gems_in).with('/path/to/gems/specifications', '/another/path/to/gems/specifications') + expect(Gem::SourceIndex).to receive(:from_gems_in).with('/path/to/gems/specifications', '/another/path/to/gems/specifications') @gem_env.gem_source_index end end @@ -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.gem_specification.should_receive(:find_all_by_name).with(rspec_dep.name, rspec_dep.requirement).and_return(gems) + allow(@gem_env).to receive(:gem_specification).and_return(Gem::Specification) + expect(@gem_env.gem_specification).to 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.gem_source_index.should_receive(:search).with(rspec_dep).and_return(gems) + allow(@gem_env).to receive(:gem_source_index).and_return(Gem.source_index) + expect(@gem_env.gem_source_index).to receive(:search).with(rspec_dep).and_return(gems) end - @gem_env.installed_versions(Gem::Dependency.new('rspec', nil)).should == gems + expect(@gem_env.installed_versions(Gem::Dependency.new('rspec', nil))).to eq(gems) end it "determines the installed versions of gems from the source index (part2: the unmockening)" do - $stdout.stub(:write) + allow($stdout).to receive(:write) path_to_gem = if windows? `where gem`.split[1] else @@ -264,7 +264,7 @@ describe Chef::Provider::Package::Rubygems::AlternateGemEnvironment do gem_env = Chef::Provider::Package::Rubygems::AlternateGemEnvironment.new(path_to_gem) expected = ['rspec-core', Gem::Version.new(RSpec::Core::Version::STRING)] actual = gem_env.installed_versions(Gem::Dependency.new('rspec-core', nil)).map { |s| [s.name, s.version] } - actual.should include(expected) + expect(actual).to include(expected) end it "detects when the target gem environment is the jruby platform" do @@ -295,18 +295,18 @@ RubyGems Environment: - http://rubygems.org/ - http://gems.github.com/ JRUBY_GEM_ENV - @gem_env.should_receive(:shell_out!).with('/usr/weird/bin/gem env').and_return(double('jruby_gem_env', :stdout => gem_env_out)) + expect(@gem_env).to receive(:shell_out!).with('/usr/weird/bin/gem env').and_return(double('jruby_gem_env', :stdout => gem_env_out)) expected = ['ruby', Gem::Platform.new('universal-java-1.6')] - @gem_env.gem_platforms.should == expected + expect(@gem_env.gem_platforms).to eq(expected) # it should also cache the result - Chef::Provider::Package::Rubygems::AlternateGemEnvironment.platform_cache['/usr/weird/bin/gem'].should == expected + expect(Chef::Provider::Package::Rubygems::AlternateGemEnvironment.platform_cache['/usr/weird/bin/gem']).to eq(expected) end it "uses the cached result for gem platforms if available" do - @gem_env.should_not_receive(:shell_out!) + expect(@gem_env).not_to receive(:shell_out!) expected = ['ruby', Gem::Platform.new('universal-java-1.6')] Chef::Provider::Package::Rubygems::AlternateGemEnvironment.platform_cache['/usr/weird/bin/gem']= expected - @gem_env.gem_platforms.should == expected + expect(@gem_env.gem_platforms).to eq(expected) end it "uses the current gem platforms when the target env is not jruby" do @@ -337,9 +337,9 @@ RubyGems Environment: - http://rubygems.org/ - http://gems.github.com/ RBX_GEM_ENV - @gem_env.should_receive(:shell_out!).with('/usr/weird/bin/gem env').and_return(double('rbx_gem_env', :stdout => gem_env_out)) - @gem_env.gem_platforms.should == Gem.platforms - Chef::Provider::Package::Rubygems::AlternateGemEnvironment.platform_cache['/usr/weird/bin/gem'].should == Gem.platforms + expect(@gem_env).to receive(:shell_out!).with('/usr/weird/bin/gem env').and_return(double('rbx_gem_env', :stdout => gem_env_out)) + expect(@gem_env.gem_platforms).to eq(Gem.platforms) + expect(Chef::Provider::Package::Rubygems::AlternateGemEnvironment.platform_cache['/usr/weird/bin/gem']).to eq(Gem.platforms) end it "yields to a block while masquerading as a different gems platform" do @@ -352,8 +352,8 @@ RBX_GEM_ENV end rescue RuntimeError end - platforms_in_block.should == ['ruby', Gem::Platform.new('sparc64-java-1.7')] - Gem.platforms.should == original_platforms + expect(platforms_in_block).to eq(['ruby', Gem::Platform.new('sparc64-java-1.7')]) + expect(Gem.platforms).to eq(original_platforms) end end @@ -369,7 +369,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") + allow(RbConfig::CONFIG).to receive(:[]).with('bindir').and_return("/usr/bin/ruby") @provider = Chef::Provider::Package::Rubygems.new(@new_resource, @run_context) end @@ -378,7 +378,7 @@ describe Chef::Provider::Package::Rubygems do it "target_version_already_installed? should return false so that we can search for candidates" do @provider.load_current_resource - @provider.target_version_already_installed?.should be_false + expect(@provider.target_version_already_installed?).to be_false end end @@ -387,74 +387,74 @@ describe Chef::Provider::Package::Rubygems do it "triggers a gem configuration load so a later one will not stomp its config values" do # ugly, is there a better way? - Gem.instance_variable_get(:@configuration).should_not be_nil + expect(Gem.instance_variable_get(:@configuration)).not_to be_nil end it "uses the CurrentGemEnvironment implementation when no gem_binary_path is provided" do - @provider.gem_env.should be_a_kind_of(Chef::Provider::Package::Rubygems::CurrentGemEnvironment) + expect(@provider.gem_env).to be_a_kind_of(Chef::Provider::Package::Rubygems::CurrentGemEnvironment) end it "uses the AlternateGemEnvironment implementation when a gem_binary_path is provided" do @new_resource.gem_binary('/usr/weird/bin/gem') provider = Chef::Provider::Package::Rubygems.new(@new_resource, @run_context) - provider.gem_env.gem_binary_location.should == '/usr/weird/bin/gem' + expect(provider.gem_env.gem_binary_location).to eq('/usr/weird/bin/gem') end 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 + allow(RbConfig::CONFIG).to receive(:[]).with('bindir').and_return("/opt/chef/embedded/bin") + allow(ENV).to receive(:[]).with('PATH').and_return("/usr/bin:/usr/sbin:/opt/chef/embedded/bin") + allow(File).to receive(:exists?).with('/usr/bin/gem').and_return(false) + allow(File).to receive(:exists?).with('/usr/sbin/gem').and_return(true) + allow(File).to receive(: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' + expect(provider.gem_env.gem_binary_location).to eq('/usr/sbin/gem') end end 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 + allow(RbConfig::CONFIG).to receive(:[]).with('bindir').and_return("d:/opscode/chef/embedded/bin") + allow(ENV).to receive(:[]).with('PATH').and_return('C:\windows\system32;C:\windows;C:\Ruby186\bin;d:\opscode\chef\embedded\bin') + allow(File).to receive(:exists?).with('C:\\windows\\system32\\gem').and_return(false) + allow(File).to receive(:exists?).with('C:\\windows\\gem').and_return(false) + allow(File).to receive(:exists?).with('C:\\Ruby186\\bin\\gem').and_return(true) + allow(File).to receive(:exists?).with('d:\\opscode\\chef\\bin\\gem').and_return(false) # should not get here + allow(File).to receive(: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' + expect(provider.gem_env.gem_binary_location).to eq('C:\Ruby186\bin\gem') end end it "smites you when you try to use a hash of install options with an explicit gem binary" do @new_resource.gem_binary('/foo/bar') @new_resource.options(:fail => :burger) - lambda {Chef::Provider::Package::Rubygems.new(@new_resource, @run_context)}.should raise_error(ArgumentError) + expect {Chef::Provider::Package::Rubygems.new(@new_resource, @run_context)}.to raise_error(ArgumentError) end it "converts the new resource into a gem dependency" do - @provider.gem_dependency.should == Gem::Dependency.new('rspec-core', @spec_version) + expect(@provider.gem_dependency).to eq(Gem::Dependency.new('rspec-core', @spec_version)) @new_resource.version('~> 1.2.0') - @provider.gem_dependency.should == Gem::Dependency.new('rspec-core', '~> 1.2.0') + expect(@provider.gem_dependency).to eq(Gem::Dependency.new('rspec-core', '~> 1.2.0')) end describe "when determining the currently installed version" do it "sets the current version to the version specified by the new resource if that version is installed" do @provider.load_current_resource - @provider.current_resource.version.should == @spec_version + expect(@provider.current_resource.version).to eq(@spec_version) end it "sets the current version to the highest installed version if the requested version is not installed" do @new_resource.version('9000.0.2') @provider.load_current_resource - @provider.current_resource.version.should == @spec_version + expect(@provider.current_resource.version).to eq(@spec_version) end it "leaves the current version at nil if the package is not installed" do @new_resource.package_name("no-such-gem-should-exist-with-this-name") @provider.load_current_resource - @provider.current_resource.version.should be_nil + expect(@provider.current_resource.version).to be_nil end end @@ -463,23 +463,23 @@ describe Chef::Provider::Package::Rubygems do it "does not query for available versions when the current version is the target version" do @provider.current_resource = @new_resource.dup - @provider.candidate_version.should be_nil + expect(@provider.candidate_version).to be_nil end it "determines the candidate version by querying the remote gem servers" do @new_resource.source('http://mygems.example.com') version = Gem::Version.new(@spec_version) - @provider.gem_env.should_receive(:candidate_version_from_remote). + expect(@provider.gem_env).to receive(:candidate_version_from_remote). with(Gem::Dependency.new('rspec-core', @spec_version), "http://mygems.example.com"). and_return(version) - @provider.candidate_version.should == @spec_version + expect(@provider.candidate_version).to eq(@spec_version) end it "parses the gem's specification if the requested source is a file" do @new_resource.package_name('chef-integration-test') @new_resource.version('>= 0') @new_resource.source(CHEF_SPEC_DATA + '/gems/chef-integration-test-0.1.0.gem') - @provider.candidate_version.should == '0.1.0' + expect(@provider.candidate_version).to eq('0.1.0') end end @@ -489,56 +489,56 @@ 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) + allow(@provider).to receive(:load_current_resource) end describe "in the current gem environment" do it "installs the gem via the gems api when no explicit options are used" do - @provider.gem_env.should_receive(:install).with(@gem_dep, :sources => nil) - @provider.action_install.should be_true + expect(@provider.gem_env).to receive(:install).with(@gem_dep, :sources => nil) + expect(@provider.action_install).to be_true end it "installs the gem via the gems api when a remote source is provided" do @new_resource.source('http://gems.example.org') sources = ['http://gems.example.org'] - @provider.gem_env.should_receive(:install).with(@gem_dep, :sources => sources) - @provider.action_install.should be_true + expect(@provider.gem_env).to receive(:install).with(@gem_dep, :sources => sources) + expect(@provider.action_install).to be_true end it "installs the gem from file via the gems api when no explicit options are used" do @new_resource.source(CHEF_SPEC_DATA + '/gems/chef-integration-test-0.1.0.gem') - @provider.gem_env.should_receive(:install).with(CHEF_SPEC_DATA + '/gems/chef-integration-test-0.1.0.gem') - @provider.action_install.should be_true + expect(@provider.gem_env).to receive(:install).with(CHEF_SPEC_DATA + '/gems/chef-integration-test-0.1.0.gem') + expect(@provider.action_install).to be_true end it "installs the gem from file via the gems api when the package is a path and the source is nil" do @new_resource = Chef::Resource::GemPackage.new(CHEF_SPEC_DATA + '/gems/chef-integration-test-0.1.0.gem') @provider = Chef::Provider::Package::Rubygems.new(@new_resource, @run_context) @provider.current_resource = @current_resource - @new_resource.source.should == CHEF_SPEC_DATA + '/gems/chef-integration-test-0.1.0.gem' - @provider.gem_env.should_receive(:install).with(CHEF_SPEC_DATA + '/gems/chef-integration-test-0.1.0.gem') - @provider.action_install.should be_true + expect(@new_resource.source).to eq(CHEF_SPEC_DATA + '/gems/chef-integration-test-0.1.0.gem') + expect(@provider.gem_env).to receive(:install).with(CHEF_SPEC_DATA + '/gems/chef-integration-test-0.1.0.gem') + expect(@provider.action_install).to be_true end # 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) + allow(::File).to receive(: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 + expect(@provider.gem_env).to receive(:install).with(@gem_dep, :sources => nil) + expect(@provider.action_install).to be_true end it "installs the gem by shelling out when options are provided as a String" do @new_resource.options('-i /alt/install/location') expected ="gem install rspec-core -q --no-rdoc --no-ri -v \"#{@spec_version}\" -i /alt/install/location" - @provider.should_receive(:shell_out!).with(expected, :env => nil) - @provider.action_install.should be_true + expect(@provider).to receive(:shell_out!).with(expected, :env => nil) + expect(@provider.action_install).to be_true end it "installs the gem via the gems api when options are given as a Hash" do @new_resource.options(:install_dir => '/alt/install/location') - @provider.gem_env.should_receive(:install).with(@gem_dep, :sources => nil, :install_dir => '/alt/install/location') - @provider.action_install.should be_true + expect(@provider.gem_env).to receive(:install).with(@gem_dep, :sources => nil, :install_dir => '/alt/install/location') + expect(@provider.action_install).to be_true end describe "at a specific version" do @@ -547,24 +547,24 @@ describe Chef::Provider::Package::Rubygems do end it "installs the gem via the gems api" do - @provider.gem_env.should_receive(:install).with(@gem_dep, :sources => nil) - @provider.action_install.should be_true + expect(@provider.gem_env).to receive(:install).with(@gem_dep, :sources => nil) + expect(@provider.action_install).to be_true end end describe "at version specified with comparison operator" do it "skips install if current version satisifies requested version" do - @current_resource.stub(:version).and_return("2.3.3") - @new_resource.stub(:version).and_return(">=2.3.0") + allow(@current_resource).to receive(:version).and_return("2.3.3") + allow(@new_resource).to receive(:version).and_return(">=2.3.0") - @provider.gem_env.should_not_receive(:install) + expect(@provider.gem_env).not_to receive(:install) @provider.action_install end it "allows user to specify gem version with fuzzy operator" do - @current_resource.stub(:version).and_return("2.3.3") - @new_resource.stub(:version).and_return("~>2.3.0") + allow(@current_resource).to receive(:version).and_return("2.3.3") + allow(@new_resource).to receive(:version).and_return("~>2.3.0") - @provider.gem_env.should_not_receive(:install) + expect(@provider.gem_env).not_to receive(:install) @provider.action_install end end @@ -573,16 +573,16 @@ describe Chef::Provider::Package::Rubygems do describe "in an alternate gem environment" do it "installs the gem by shelling out to gem install" do @new_resource.gem_binary('/usr/weird/bin/gem') - @provider.should_receive(:shell_out!).with("/usr/weird/bin/gem install rspec-core -q --no-rdoc --no-ri -v \"#{@spec_version}\"", :env=>nil) - @provider.action_install.should be_true + expect(@provider).to receive(:shell_out!).with("/usr/weird/bin/gem install rspec-core -q --no-rdoc --no-ri -v \"#{@spec_version}\"", :env=>nil) + expect(@provider.action_install).to be_true end it "installs the gem from file by shelling out to gem install" do @new_resource.gem_binary('/usr/weird/bin/gem') @new_resource.source(CHEF_SPEC_DATA + '/gems/chef-integration-test-0.1.0.gem') @new_resource.version('>= 0') - @provider.should_receive(:shell_out!).with("/usr/weird/bin/gem install #{CHEF_SPEC_DATA}/gems/chef-integration-test-0.1.0.gem -q --no-rdoc --no-ri -v \">= 0\"", :env=>nil) - @provider.action_install.should be_true + expect(@provider).to receive(:shell_out!).with("/usr/weird/bin/gem install #{CHEF_SPEC_DATA}/gems/chef-integration-test-0.1.0.gem -q --no-rdoc --no-ri -v \">= 0\"", :env=>nil) + expect(@provider.action_install).to be_true end it "installs the gem from file by shelling out to gem install when the package is a path and the source is nil" do @@ -591,9 +591,9 @@ describe Chef::Provider::Package::Rubygems do @provider.current_resource = @current_resource @new_resource.gem_binary('/usr/weird/bin/gem') @new_resource.version('>= 0') - @new_resource.source.should == CHEF_SPEC_DATA + '/gems/chef-integration-test-0.1.0.gem' - @provider.should_receive(:shell_out!).with("/usr/weird/bin/gem install #{CHEF_SPEC_DATA}/gems/chef-integration-test-0.1.0.gem -q --no-rdoc --no-ri -v \">= 0\"", :env=>nil) - @provider.action_install.should be_true + expect(@new_resource.source).to eq(CHEF_SPEC_DATA + '/gems/chef-integration-test-0.1.0.gem') + expect(@provider).to receive(:shell_out!).with("/usr/weird/bin/gem install #{CHEF_SPEC_DATA}/gems/chef-integration-test-0.1.0.gem -q --no-rdoc --no-ri -v \">= 0\"", :env=>nil) + expect(@provider.action_install).to be_true end end @@ -611,32 +611,32 @@ describe Chef::Provider::Package::Rubygems do describe "in the current gem environment" do it "uninstalls via the api when no explicit options are used" do # pre-reqs for action_remove to actually remove the package: - @provider.new_resource.version.should be_nil - @provider.current_resource.version.should_not be_nil + expect(@provider.new_resource.version).to be_nil + expect(@provider.current_resource.version).not_to be_nil # the behavior we're testing: - @provider.gem_env.should_receive(:uninstall).with('rspec', nil) + expect(@provider.gem_env).to receive(:uninstall).with('rspec', nil) @provider.action_remove end it "uninstalls via the api when options are given as a Hash" do # pre-reqs for action_remove to actually remove the package: - @provider.new_resource.version.should be_nil - @provider.current_resource.version.should_not be_nil + expect(@provider.new_resource.version).to be_nil + expect(@provider.current_resource.version).not_to be_nil # the behavior we're testing: @new_resource.options(:install_dir => '/alt/install/location') - @provider.gem_env.should_receive(:uninstall).with('rspec', nil, :install_dir => '/alt/install/location') + expect(@provider.gem_env).to receive(:uninstall).with('rspec', nil, :install_dir => '/alt/install/location') @provider.action_remove end it "uninstalls via the gem command when options are given as a String" do @new_resource.options('-i /alt/install/location') - @provider.should_receive(:shell_out!).with("gem uninstall rspec -q -x -I -a -i /alt/install/location", :env=>nil) + expect(@provider).to receive(:shell_out!).with("gem uninstall rspec -q -x -I -a -i /alt/install/location", :env=>nil) @provider.action_remove end it "uninstalls a specific version of a gem when a version is provided" do @new_resource.version('1.2.3') - @provider.gem_env.should_receive(:uninstall).with('rspec', '1.2.3') + expect(@provider.gem_env).to receive(:uninstall).with('rspec', '1.2.3') @provider.action_remove end end @@ -644,7 +644,7 @@ describe Chef::Provider::Package::Rubygems do describe "in an alternate gem environment" do it "uninstalls via the gem command" do @new_resource.gem_binary('/usr/weird/bin/gem') - @provider.should_receive(:shell_out!).with("/usr/weird/bin/gem uninstall rspec -q -x -I -a", :env=>nil) + expect(@provider).to receive(:shell_out!).with("/usr/weird/bin/gem uninstall rspec -q -x -I -a", :env=>nil) @provider.action_remove end end diff --git a/spec/unit/provider/package/smartos_spec.rb b/spec/unit/provider/package/smartos_spec.rb index 1c690acbf5..db39589b85 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 = double("Status", :exitstatus => 0) @provider = Chef::Provider::Package::SmartOS.new(@new_resource, @run_context) - Chef::Resource::Package.stub(:new).and_return(@current_resource) + allow(Chef::Resource::Package).to receive(:new).and_return(@current_resource) @stdin = StringIO.new @stdout = "varnish-2.1.5nb2\n" @stderr = StringIO.new @@ -42,28 +42,28 @@ describe Chef::Provider::Package::SmartOS, "load_current_resource" do describe "when loading current resource" do it "should create a current resource with the name of the new_resource" do - @provider.should_receive(:shell_out!).and_return(@shell_out) - Chef::Resource::Package.should_receive(:new).and_return(@current_resource) + expect(@provider).to receive(:shell_out!).and_return(@shell_out) + expect(Chef::Resource::Package).to receive(:new).and_return(@current_resource) @provider.load_current_resource end it "should set the current resource package name" do - @provider.should_receive(:shell_out!).and_return(@shell_out) - @current_resource.should_receive(:package_name).with(@new_resource.package_name) + expect(@provider).to receive(:shell_out!).and_return(@shell_out) + expect(@current_resource).to receive(:package_name).with(@new_resource.package_name) @provider.load_current_resource end it "should set the installed version if it is installed" do - @provider.should_receive(:shell_out!).and_return(@shell_out) + expect(@provider).to receive(:shell_out!).and_return(@shell_out) @provider.load_current_resource - @current_resource.version.should == "2.1.5nb2" + expect(@current_resource.version).to eq("2.1.5nb2") end it "should set the installed version to nil if it's not installed" do out = OpenStruct.new(:stdout => nil) - @provider.should_receive(:shell_out!).and_return(out) + expect(@provider).to receive(:shell_out!).and_return(out) @provider.load_current_resource - @current_resource.version.should == nil + expect(@current_resource.version).to eq(nil) end @@ -72,18 +72,18 @@ describe Chef::Provider::Package::SmartOS, "load_current_resource" do describe "candidate_version" do it "should return the candidate_version variable if already setup" do @provider.candidate_version = "2.1.1" - @provider.should_not_receive(:shell_out!) + expect(@provider).not_to receive(:shell_out!) @provider.candidate_version end it "should lookup the candidate_version if the variable is not already set" do search = double() - search.should_receive(:each_line). + expect(search).to receive(:each_line). and_yield("something-varnish-1.1.1 something varnish like\n"). and_yield("varnish-2.3.4 actual varnish\n") @shell_out = double('shell_out!', :stdout => search) - @provider.should_receive(:shell_out!).with('/opt/local/bin/pkgin se varnish', :env => nil, :returns => [0,1]).and_return(@shell_out) - @provider.candidate_version.should == "2.3.4" + expect(@provider).to receive(:shell_out!).with('/opt/local/bin/pkgin se varnish', :env => nil, :returns => [0,1]).and_return(@shell_out) + expect(@provider.candidate_version).to eq("2.3.4") end end @@ -91,8 +91,8 @@ describe Chef::Provider::Package::SmartOS, "load_current_resource" do it "run pkgin and install the package" do out = OpenStruct.new(:stdout => nil) - @provider.should_receive(:shell_out!).with("/opt/local/sbin/pkg_info -E \"varnish*\"", {:env => nil, :returns=>[0,1]}).and_return(@shell_out) - @provider.should_receive(:shell_out!).with("/opt/local/bin/pkgin -y install varnish-2.1.5nb2", {:env=>nil}).and_return(out) + expect(@provider).to receive(:shell_out!).with("/opt/local/sbin/pkg_info -E \"varnish*\"", {:env => nil, :returns=>[0,1]}).and_return(@shell_out) + expect(@provider).to receive(:shell_out!).with("/opt/local/bin/pkgin -y install varnish-2.1.5nb2", {:env=>nil}).and_return(out) @provider.load_current_resource @provider.install_package("varnish", "2.1.5nb2") end diff --git a/spec/unit/provider/package/solaris_spec.rb b/spec/unit/provider/package/solaris_spec.rb index d83ccbdf06..8438202576 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) + allow(::File).to receive(:exists?).and_return(true) end describe "assessing the current package status" do @@ -50,119 +50,119 @@ PKGINFO end it "should create a current resource with the name of new_resource" do - @provider.stub(:popen4).and_return(@status) + allow(@provider).to receive(:popen4).and_return(@status) @provider.load_current_resource - @provider.current_resource.name.should == "SUNWbash" + expect(@provider.current_resource.name).to eq("SUNWbash") end it "should set the current reource package name to the new resource package name" do - @provider.stub(:popen4).and_return(@status) + allow(@provider).to receive(:popen4).and_return(@status) @provider.load_current_resource - @provider.current_resource.package_name.should == "SUNWbash" + expect(@provider.current_resource.package_name).to eq("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) + allow(@provider).to receive(:popen4).and_return(@status) + allow(::File).to receive(:exists?).and_return(false) @provider.define_resource_requirements @provider.load_current_resource - lambda { @provider.process_resource_requirements }.should raise_error(Chef::Exceptions::Package) + expect { @provider.process_resource_requirements }.to raise_error(Chef::Exceptions::Package) end it "should get the source package version from pkginfo if provided" do @stdout = StringIO.new(@pkginfo) @stdin, @stderr = StringIO.new, StringIO.new - @provider.should_receive(:popen4).with("pkginfo -l -d /tmp/bash.pkg SUNWbash").and_yield(@pid, @stdin, @stdout, @stderr).and_return(@status) - @provider.should_receive(:popen4).with("pkginfo -l SUNWbash").and_return(@status) + expect(@provider).to receive(:popen4).with("pkginfo -l -d /tmp/bash.pkg SUNWbash").and_yield(@pid, @stdin, @stdout, @stderr).and_return(@status) + expect(@provider).to receive(:popen4).with("pkginfo -l SUNWbash").and_return(@status) @provider.load_current_resource - @provider.current_resource.package_name.should == "SUNWbash" - @new_resource.version.should == "11.10.0,REV=2005.01.08.05.16" + expect(@provider.current_resource.package_name).to eq("SUNWbash") + expect(@new_resource.version).to eq("11.10.0,REV=2005.01.08.05.16") end it "should return the current version installed if found by pkginfo" do @stdout = StringIO.new(@pkginfo) @stdin, @stderr = StringIO.new, StringIO.new - @provider.should_receive(:popen4).with("pkginfo -l -d /tmp/bash.pkg SUNWbash").and_return(@status) - @provider.should_receive(:popen4).with("pkginfo -l SUNWbash").and_yield(@pid, @stdin, @stdout, @stderr).and_return(@status) + expect(@provider).to receive(:popen4).with("pkginfo -l -d /tmp/bash.pkg SUNWbash").and_return(@status) + expect(@provider).to receive(:popen4).with("pkginfo -l SUNWbash").and_yield(@pid, @stdin, @stdout, @stderr).and_return(@status) @provider.load_current_resource - @provider.current_resource.version.should == "11.10.0,REV=2005.01.08.05.16" + expect(@provider.current_resource.version).to eq("11.10.0,REV=2005.01.08.05.16") end 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) - lambda { @provider.run_action(:install) }.should raise_error(Chef::Exceptions::Package) + allow(@provider).to receive(:popen4).and_return(@status) + expect { @provider.run_action(:install) }.to raise_error(Chef::Exceptions::Package) end it "should raise an exception if pkginfo fails to run" do @status = double("Status", :exitstatus => -1) - @provider.stub(:popen4).and_return(@status) - lambda { @provider.load_current_resource }.should raise_error(Chef::Exceptions::Package) + allow(@provider).to receive(:popen4).and_return(@status) + expect { @provider.load_current_resource }.to raise_error(Chef::Exceptions::Package) end it "should return a current resource with a nil version if the package is not found" do @stdout = StringIO.new - @provider.should_receive(:popen4).with("pkginfo -l -d /tmp/bash.pkg SUNWbash").and_return(@status) - @provider.should_receive(:popen4).with("pkginfo -l SUNWbash").and_yield(@pid, @stdin, @stdout, @stderr).and_return(@status) + expect(@provider).to receive(:popen4).with("pkginfo -l -d /tmp/bash.pkg SUNWbash").and_return(@status) + expect(@provider).to receive(:popen4).with("pkginfo -l SUNWbash").and_yield(@pid, @stdin, @stdout, @stderr).and_return(@status) @provider.load_current_resource - @provider.current_resource.version.should be_nil + expect(@provider.current_resource.version).to be_nil end end describe "candidate_version" do it "should return the candidate_version variable if already setup" do @provider.candidate_version = "11.10.0,REV=2005.01.08.05.16" - @provider.should_not_receive(:popen4) + expect(@provider).not_to receive(:popen4) @provider.candidate_version end it "should lookup the candidate_version if the variable is not already set" do @status = double("Status", :exitstatus => 0) - @provider.stub(:popen4).and_return(@status) - @provider.should_receive(:popen4) + allow(@provider).to receive(:popen4).and_return(@status) + expect(@provider).to receive(:popen4) @provider.candidate_version end it "should throw and exception if the exitstatus is not 0" do @status = double("Status", :exitstatus => 1) - @provider.stub(:popen4).and_return(@status) - lambda { @provider.candidate_version }.should raise_error(Chef::Exceptions::Package) + allow(@provider).to receive(:popen4).and_return(@status) + expect { @provider.candidate_version }.to raise_error(Chef::Exceptions::Package) end end describe "install and upgrade" do it "should run pkgadd -n -d with the package source to install" do - @provider.should_receive(:shell_out!).with("pkgadd -n -d /tmp/bash.pkg all") + expect(@provider).to receive(:shell_out!).with("pkgadd -n -d /tmp/bash.pkg all") @provider.install_package("SUNWbash", "11.10.0,REV=2005.01.08.05.16") end it "should run pkgadd -n -d when the package is a path to install" do @new_resource = Chef::Resource::Package.new("/tmp/bash.pkg") @provider = Chef::Provider::Package::Solaris.new(@new_resource, @run_context) - @new_resource.source.should == "/tmp/bash.pkg" - @provider.should_receive(:shell_out!).with("pkgadd -n -d /tmp/bash.pkg all") + expect(@new_resource.source).to eq("/tmp/bash.pkg") + expect(@provider).to receive(:shell_out!).with("pkgadd -n -d /tmp/bash.pkg all") @provider.install_package("/tmp/bash.pkg", "11.10.0,REV=2005.01.08.05.16") 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") - @provider.should_receive(:shell_out!).with("pkgadd -n -a /tmp/myadmin -d /tmp/bash.pkg all") + allow(@new_resource).to receive(:options).and_return("-a /tmp/myadmin") + expect(@provider).to receive(:shell_out!).with("pkgadd -n -a /tmp/myadmin -d /tmp/bash.pkg all") @provider.install_package("SUNWbash", "11.10.0,REV=2005.01.08.05.16") end end describe "remove" do it "should run pkgrm -n to remove the package" do - @provider.should_receive(:shell_out!).with("pkgrm -n SUNWbash") + expect(@provider).to receive(:shell_out!).with("pkgrm -n SUNWbash") @provider.remove_package("SUNWbash", "11.10.0,REV=2005.01.08.05.16") end it "should run pkgrm -n -a /tmp/myadmin with options -a /tmp/myadmin" do - @new_resource.stub(:options).and_return("-a /tmp/myadmin") - @provider.should_receive(:shell_out!).with("pkgrm -n -a /tmp/myadmin SUNWbash") + allow(@new_resource).to receive(:options).and_return("-a /tmp/myadmin") + expect(@provider).to receive(:shell_out!).with("pkgrm -n -a /tmp/myadmin SUNWbash") @provider.remove_package("SUNWbash", "11.10.0,REV=2005.01.08.05.16") end diff --git a/spec/unit/provider/package/windows/msi_spec.rb b/spec/unit/provider/package/windows/msi_spec.rb index c8a63ad066..e539bbbb79 100644 --- a/spec/unit/provider/package/windows/msi_spec.rb +++ b/spec/unit/provider/package/windows/msi_spec.rb @@ -37,15 +37,15 @@ describe Chef::Provider::Package::Windows::MSI, :windows_only do describe "installed_version" do it "returns the installed version" do - provider.stub(:get_product_property).and_return("{23170F69-40C1-2702-0920-000001000000}") - provider.stub(:get_installed_version).with("{23170F69-40C1-2702-0920-000001000000}").and_return("3.14159.1337.42") + allow(provider).to receive(:get_product_property).and_return("{23170F69-40C1-2702-0920-000001000000}") + allow(provider).to receive(:get_installed_version).with("{23170F69-40C1-2702-0920-000001000000}").and_return("3.14159.1337.42") expect(provider.installed_version).to eql("3.14159.1337.42") end end describe "package_version" do it "returns the version of a package" do - provider.stub(:get_product_property).with(/calculator.msi$/, "ProductVersion").and_return(42) + allow(provider).to receive(:get_product_property).with(/calculator.msi$/, "ProductVersion").and_return(42) expect(provider.package_version).to eql(42) end end diff --git a/spec/unit/provider/package/windows_spec.rb b/spec/unit/provider/package/windows_spec.rb index b4ababb243..5ab84e7ac7 100644 --- a/spec/unit/provider/package/windows_spec.rb +++ b/spec/unit/provider/package/windows_spec.rb @@ -27,8 +27,8 @@ describe Chef::Provider::Package::Windows, :windows_only do describe "load_current_resource" do before(:each) do - Chef::Util::PathHelper.stub(:validate_path) - provider.stub(:package_provider).and_return(double('package_provider', + allow(Chef::Util::PathHelper).to receive(:validate_path) + allow(provider).to receive(:package_provider).and_return(double('package_provider', :installed_version => "1.0", :package_version => "2.0")) end @@ -56,12 +56,12 @@ describe Chef::Provider::Package::Windows, :windows_only do describe "package_provider" do it "sets the package provider to MSI if the the installer type is :msi" do - provider.stub(:installer_type).and_return(:msi) + allow(provider).to receive(:installer_type).and_return(:msi) expect(provider.package_provider).to be_a(Chef::Provider::Package::Windows::MSI) end it "raises an error if the installer_type is unknown" do - provider.stub(:installer_type).and_return(:apt_for_windows) + allow(provider).to receive(:installer_type).and_return(:apt_for_windows) expect { provider.package_provider }.to raise_error end end diff --git a/spec/unit/provider/package/yum_spec.rb b/spec/unit/provider/package/yum_spec.rb index 9b3b6b60e0..0d2a44f3ae 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) + allow(Chef::Provider::Package::Yum::YumCache).to receive(:instance).and_return(@yum_cache) @provider = Chef::Provider::Package::Yum.new(@new_resource, @run_context) @pid = double("PID") end @@ -45,32 +45,32 @@ describe Chef::Provider::Package::Yum do describe "when loading the current system state" do it "should create a current resource with the name of the new_resource" do @provider.load_current_resource - @provider.current_resource.name.should == "cups" + expect(@provider.current_resource.name).to eq("cups") end it "should set the current resources package name to the new resources package name" do @provider.load_current_resource - @provider.current_resource.package_name.should == "cups" + expect(@provider.current_resource.package_name).to eq("cups") 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) + allow(@yum_cache).to receive(:installed_version).and_return(nil) @provider.load_current_resource - @provider.current_resource.version.should be_nil + expect(@provider.current_resource.version).to be_nil end it "should set the installed version if yum has one" do @provider.load_current_resource - @provider.current_resource.version.should == "1.2.4-11.18.el5" + expect(@provider.current_resource.version).to eq("1.2.4-11.18.el5") end it "should set the candidate version if yum info has one" do @provider.load_current_resource - @provider.candidate_version.should eql("1.2.4-11.18.el5_2.3") + expect(@provider.candidate_version).to eql("1.2.4-11.18.el5_2.3") end it "should return the current resouce" do - @provider.load_current_resource.should eql(@provider.current_resource) + expect(@provider.load_current_resource).to eql(@provider.current_resource) end describe "when arch in package_name" do @@ -79,11 +79,11 @@ describe Chef::Provider::Package::Yum do @yum_cache = double( 'Chef::Provider::Yum::YumCache' ) - @yum_cache.stub(:installed_version) do |package_name, arch| + allow(@yum_cache).to receive(: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| + allow(@yum_cache).to receive(:candidate_version) do |package_name, arch| if package_name == "testing.noarch" || package_name == "testing.more.noarch" nil # candidate for new_package_name @@ -91,21 +91,21 @@ 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) + allow(@yum_cache).to receive(:package_available?).and_return(true) + allow(@yum_cache).to receive(:disable_extra_repo_control).and_return(true) + allow(Chef::Provider::Package::Yum::YumCache).to receive(: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" - @provider.new_resource.arch.should == "noarch" - @provider.arch.should == "noarch" + expect(@provider.new_resource.package_name).to eq("testing") + expect(@provider.new_resource.arch).to eq("noarch") + expect(@provider.arch).to eq("noarch") @new_resource = Chef::Resource::YumPackage.new('testing.more.noarch') @provider = Chef::Provider::Package::Yum.new(@new_resource, @run_context) @provider.load_current_resource - @provider.new_resource.package_name.should == "testing.more" - @provider.new_resource.arch.should == "noarch" - @provider.arch.should == "noarch" + expect(@provider.new_resource.package_name).to eq("testing.more") + expect(@provider.new_resource.arch).to eq("noarch") + expect(@provider.arch).to eq("noarch") end it "should not set the arch when an existing package_name is found" do @@ -113,7 +113,7 @@ describe Chef::Provider::Package::Yum do @yum_cache = double( 'Chef::Provider::Yum::YumCache' ) - @yum_cache.stub(:installed_version) do |package_name, arch| + allow(@yum_cache).to receive(:installed_version) do |package_name, arch| # installed for package_name if package_name == "testing.beta3" || package_name == "testing.beta3.more" "1.1" @@ -121,26 +121,26 @@ describe Chef::Provider::Package::Yum do nil end end - @yum_cache.stub(:candidate_version) do |package_name, arch| + allow(@yum_cache).to receive(: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) + allow(@yum_cache).to receive(:package_available?).and_return(true) + allow(@yum_cache).to receive(:disable_extra_repo_control).and_return(true) + allow(Chef::Provider::Package::Yum::YumCache).to receive(: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 - @provider.new_resource.package_name.should == "testing.beta3" - @provider.new_resource.arch.should == nil - @provider.arch.should == nil + expect(@provider.new_resource.package_name).to eq("testing.beta3") + expect(@provider.new_resource.arch).to eq(nil) + expect(@provider.arch).to eq(nil) @new_resource = Chef::Resource::YumPackage.new('testing.beta3.more') @provider = Chef::Provider::Package::Yum.new(@new_resource, @run_context) @provider.load_current_resource - @provider.new_resource.package_name.should == "testing.beta3.more" - @provider.new_resource.arch.should == nil - @provider.arch.should == nil + expect(@provider.new_resource.package_name).to eq("testing.beta3.more") + expect(@provider.new_resource.arch).to eq(nil) + expect(@provider.arch).to eq(nil) end it "should not set the arch when no existing package_name or new_package_name+new_arch is found" do @@ -148,29 +148,29 @@ describe Chef::Provider::Package::Yum do @yum_cache = double( 'Chef::Provider::Yum::YumCache' ) - @yum_cache.stub(:installed_version) do |package_name, arch| + allow(@yum_cache).to receive(: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| + allow(@yum_cache).to receive(: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) + allow(@yum_cache).to receive(:package_available?).and_return(true) + allow(@yum_cache).to receive(:disable_extra_repo_control).and_return(true) + allow(Chef::Provider::Package::Yum::YumCache).to receive(: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" - @provider.new_resource.arch.should == nil - @provider.arch.should == nil + expect(@provider.new_resource.package_name).to eq("testing.beta3") + expect(@provider.new_resource.arch).to eq(nil) + expect(@provider.arch).to eq(nil) @new_resource = Chef::Resource::YumPackage.new('testing.beta3.more') @provider = Chef::Provider::Package::Yum.new(@new_resource, @run_context) @provider.load_current_resource - @provider.new_resource.package_name.should == "testing.beta3.more" - @provider.new_resource.arch.should == nil - @provider.arch.should == nil + expect(@provider.new_resource.package_name).to eq("testing.beta3.more") + expect(@provider.new_resource.arch).to eq(nil) + expect(@provider.arch).to eq(nil) end it "should ensure it doesn't clobber an existing arch if passed" do @@ -179,11 +179,11 @@ describe Chef::Provider::Package::Yum do @yum_cache = double( 'Chef::Provider::Yum::YumCache' ) - @yum_cache.stub(:installed_version) do |package_name, arch| + allow(@yum_cache).to receive(: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| + allow(@yum_cache).to receive(:candidate_version) do |package_name, arch| if package_name == "testing.noarch" nil # candidate for new_package_name @@ -191,43 +191,43 @@ 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) + allow(@yum_cache).to receive(:package_available?).and_return(true) + allow(@yum_cache).to receive(:disable_extra_repo_control).and_return(true) + allow(Chef::Provider::Package::Yum::YumCache).to receive(: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" - @provider.new_resource.arch.should == "x86_64" + expect(@provider.new_resource.package_name).to eq("testing.i386") + expect(@provider.new_resource.arch).to eq("x86_64") end end it "should flush the cache if :before is true" do - @new_resource.stub(:flush_cache).and_return({:after => false, :before => true}) - @yum_cache.should_receive(:reload).once + allow(@new_resource).to receive(:flush_cache).and_return({:after => false, :before => true}) + expect(@yum_cache).to 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}) - @yum_cache.should_not_receive(:reload) + allow(@new_resource).to receive(:flush_cache).and_return({:after => false, :before => false}) + expect(@yum_cache).not_to 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") - @yum_cache.should_receive(:enable_extra_repo_control).with("--enablerepo=foo --disablerepo=a,b,c --enablerepo=bar") + allow(@new_resource).to receive(:options).and_return("--stuff --enablerepo=foo --otherthings --disablerepo=a,b,c --enablerepo=bar") + expect(@yum_cache).to 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") - @yum_cache.should_receive(:disable_extra_repo_control) + allow(@new_resource).to receive(:options).and_return("--stuff --otherthings") + expect(@yum_cache).to 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) - @yum_cache.should_receive(:disable_extra_repo_control) + allow(@new_resource).to receive(:options).and_return(nil) + expect(@yum_cache).to receive(:disable_extra_repo_control) @provider.load_current_resource end @@ -242,12 +242,12 @@ 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) + allow(Chef::Provider::Package::Yum::YumCache).to receive(: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]) + expect(@yum_cache).to receive(:packages_from_require).and_return([pkg]) @provider = Chef::Provider::Package::Yum.new(@new_resource, @run_context) @provider.load_current_resource - @new_resource.package_name.should == "test-package" + expect(@new_resource.package_name).to eq("test-package") end it "should search provides if package name can't be found, warn about multiple matches, but use the first one" do @@ -261,14 +261,14 @@ 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) + allow(Chef::Provider::Package::Yum::YumCache).to receive(: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]) - Chef::Log.should_receive(:warn).exactly(1).times.with(%r{matched multiple Provides}) + expect(@yum_cache).to receive(:packages_from_require).and_return([pkg_x, pkg_y]) + expect(Chef::Log).to receive(:warn).exactly(1).times.with(%r{matched multiple Provides}) @provider = Chef::Provider::Package::Yum.new(@new_resource, @run_context) @provider.load_current_resource - @new_resource.package_name.should == "test-package-x" + expect(@new_resource.package_name).to eq("test-package-x") end it "should search provides if no package is available - if no match in installed provides then load the complete set" do @@ -282,9 +282,9 @@ 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) - @yum_cache.should_receive(:packages_from_require).twice.and_return([]) - @yum_cache.should_receive(:reload_provides) + allow(Chef::Provider::Package::Yum::YumCache).to receive(:instance).and_return(@yum_cache) + expect(@yum_cache).to receive(:packages_from_require).twice.and_return([]) + expect(@yum_cache).to receive(:reload_provides) @provider = Chef::Provider::Package::Yum.new(@new_resource, @run_context) @provider.load_current_resource end @@ -300,14 +300,14 @@ 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) + allow(Chef::Provider::Package::Yum::YumCache).to receive(: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) + expect(@yum_cache).to receive(:packages_from_require).once.and_return([]) + expect(@yum_cache).not_to receive(:reload_provides) @new_resource.action(:remove) @provider.load_current_resource - @yum_cache.should_receive(:packages_from_require).once.and_return([]) - @yum_cache.should_not_receive(:reload_provides) + expect(@yum_cache).to receive(:packages_from_require).once.and_return([]) + expect(@yum_cache).not_to receive(:reload_provides) @new_resource.action(:purge) @provider.load_current_resource end @@ -324,27 +324,27 @@ 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) - @yum_cache.should_receive(:packages_from_require).twice.and_return([]) + allow(Chef::Provider::Package::Yum::YumCache).to receive(:instance).and_return(@yum_cache) + expect(@yum_cache).to receive(:packages_from_require).twice.and_return([]) @provider = Chef::Provider::Package::Yum.new(@new_resource, @run_context) @provider.load_current_resource - @new_resource.package_name.should == "cups" + expect(@new_resource.package_name).to eq("cups") end end 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) - @provider.should_receive(:yum_command).with( + allow(Chef::Provider::Package::Yum::RPMUtils).to receive(:rpmvercmp).and_return(-1) + expect(@provider).to receive(:yum_command).with( "yum -d0 -e0 -y install emacs-1.0" ) @provider.install_package("emacs", "1.0") 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") - @provider.should_receive(:yum_command).with( + allow(@new_resource).to receive(:source).and_return("/tmp/emacs-21.4-20.el5.i386.rpm") + expect(@provider).to receive(:yum_command).with( "yum -d0 -e0 -y localinstall /tmp/emacs-21.4-20.el5.i386.rpm" ) @provider.install_package("emacs", "21.4-20.el5") @@ -352,10 +352,10 @@ 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) + allow(::File).to receive(: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( + expect(@new_resource.source).to eq("/tmp/emacs-21.4-20.el5.i386.rpm") + expect(@provider).to receive(:yum_command).with( "yum -d0 -e0 -y localinstall /tmp/emacs-21.4-20.el5.i386.rpm" ) @provider.install_package("/tmp/emacs-21.4-20.el5.i386.rpm", "21.4-20.el5") @@ -363,9 +363,9 @@ 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) - @provider.should_receive(:yum_command).with( + allow(@new_resource).to receive(:arch).and_return("i386") + allow(Chef::Provider::Package::Yum::RPMUtils).to receive(:rpmvercmp).and_return(-1) + expect(@provider).to receive(:yum_command).with( "yum -d0 -e0 -y install emacs-21.4-20.el5.i386" ) @provider.install_package("emacs", "21.4-20.el5") @@ -374,9 +374,9 @@ 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) - @provider.should_receive(:yum_command).with( + allow(@new_resource).to receive(:options).and_return("--disablerepo epmd") + allow(Chef::Provider::Package::Yum::RPMUtils).to receive(:rpmvercmp).and_return(-1) + expect(@provider).to receive(:yum_command).with( "yum -d0 -e0 -y --disablerepo epmd install cups-11" ) @provider.install_package(@new_resource.name, @provider.candidate_version) @@ -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) + allow(Chef::Provider::Package::Yum::YumCache).to receive(: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}) + expect { @provider.install_package("lolcats", "0.99") }.to 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) + allow(@new_resource).to receive(:allow_downgrade).and_return(false) @yum_cache = double( 'Chef::Provider::Yum::YumCache', :reload_installed => true, @@ -411,10 +411,10 @@ 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) + allow(Chef::Provider::Package::Yum::YumCache).to receive(: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}) + expect { @provider.install_package("cups", "1.2.4-11.15.el5") }.to raise_error(Chef::Exceptions::Package, %r{is newer than candidate package}) end it "should not raise an exception if candidate version is older than the installed version and the package is list in yum's installonlypkg option" do @@ -430,17 +430,17 @@ 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) + allow(Chef::Provider::Package::Yum::YumCache).to receive(: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( + expect(@provider).to receive(:yum_command).with( "yum -d0 -e0 -y install cups-1.2.4-11.15.el5" ) @provider.install_package("cups", "1.2.4-11.15.el5") 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) + allow(@new_resource).to receive(:allow_downgrade).and_return(true) @yum_cache = double( 'Chef::Provider::Yum::YumCache', :reload_installed => true, @@ -453,34 +453,34 @@ 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) + allow(Chef::Provider::Package::Yum::YumCache).to receive(: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( + expect(@provider).to receive(:yum_command).with( "yum -d0 -e0 -y downgrade cups-1.2.4-11.15.el5" ) @provider.install_package("cups", "1.2.4-11.15.el5") 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}) + allow(@new_resource).to receive(:flush_cache).and_return({:after => true, :before => false}) @provider.load_current_resource - Chef::Provider::Package::Yum::RPMUtils.stub(:rpmvercmp).and_return(-1) - @provider.should_receive(:yum_command).with( + allow(Chef::Provider::Package::Yum::RPMUtils).to receive(:rpmvercmp).and_return(-1) + expect(@provider).to receive(:yum_command).with( "yum -d0 -e0 -y install emacs-1.0" ) - @yum_cache.should_receive(:reload).once + expect(@yum_cache).to receive(:reload).once @provider.install_package("emacs", "1.0") 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}) + allow(@new_resource).to receive(:flush_cache).and_return({:after => false, :before => false}) @provider.load_current_resource - Chef::Provider::Package::Yum::RPMUtils.stub(:rpmvercmp).and_return(-1) - @provider.should_receive(:yum_command).with( + allow(Chef::Provider::Package::Yum::RPMUtils).to receive(:rpmvercmp).and_return(-1) + expect(@provider).to receive(:yum_command).with( "yum -d0 -e0 -y install emacs-1.0" ) - @yum_cache.should_not_receive(:reload) + expect(@yum_cache).not_to receive(:reload) @provider.install_package("emacs", "1.0") end end @@ -489,8 +489,8 @@ 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) - @provider.should_receive(:yum_command).with( + allow(Chef::Provider::Package::Yum::RPMUtils).to receive(:rpmvercmp).and_return(-1) + expect(@provider).to receive(:yum_command).with( "yum -d0 -e0 -y install cups-11" ) @provider.upgrade_package(@new_resource.name, @provider.candidate_version) @@ -500,8 +500,8 @@ 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) - @provider.should_receive(:yum_command).with( + allow(Chef::Provider::Package::Yum::RPMUtils).to receive(:rpmvercmp).and_return(-1) + expect(@provider).to receive(:yum_command).with( "yum -d0 -e0 -y install cups-11" ) @provider.upgrade_package(@new_resource.name, @provider.candidate_version) @@ -519,19 +519,19 @@ 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) + allow(Chef::Provider::Package::Yum::YumCache).to receive(: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}) + expect { @provider.upgrade_package("cups", "1.2.4-11.15.el5") }.to raise_error(Chef::Exceptions::Package, %r{is newer than candidate package}) end # 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) + allow(@yum_cache).to receive(:installed_version).and_return(nil) @provider.load_current_resource @current_resource = Chef::Resource::Package.new('cups') @provider.candidate_version = '11' - @provider.should_receive(:upgrade_package).with( + expect(@provider).to receive(:upgrade_package).with( "cups", "11" ) @@ -542,7 +542,7 @@ describe Chef::Provider::Package::Yum do @provider.load_current_resource @current_resource = Chef::Resource::Package.new('cups') @provider.candidate_version = nil - @provider.should_not_receive(:upgrade_package) + expect(@provider).not_to receive(:upgrade_package) @provider.action_upgrade end @@ -550,7 +550,7 @@ describe Chef::Provider::Package::Yum do @provider.load_current_resource @current_resource = Chef::Resource::Package.new('cups') @provider.candidate_version = '11' - @provider.should_receive(:upgrade_package).with( + expect(@provider).to receive(:upgrade_package).with( "cups", "11" ) @@ -558,26 +558,26 @@ 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") + allow(@yum_cache).to receive(:installed_version).and_return("12") @provider.load_current_resource @current_resource = Chef::Resource::Package.new('cups') @provider.candidate_version = '11' - @provider.should_not_receive(:upgrade_package) + expect(@provider).not_to receive(:upgrade_package) @provider.action_upgrade end end describe "when removing a package" do it "should run yum remove with the package name" do - @provider.should_receive(:yum_command).with( + expect(@provider).to receive(:yum_command).with( "yum -d0 -e0 -y remove emacs-1.0" ) @provider.remove_package("emacs", "1.0") end it "should run yum remove with the package name and arch" do - @new_resource.stub(:arch).and_return("x86_64") - @provider.should_receive(:yum_command).with( + allow(@new_resource).to receive(:arch).and_return("x86_64") + expect(@provider).to receive(:yum_command).with( "yum -d0 -e0 -y remove emacs-1.0.x86_64" ) @provider.remove_package("emacs", "1.0") @@ -586,7 +586,7 @@ describe Chef::Provider::Package::Yum do describe "when purging a package" do it "should run yum remove with the package name" do - @provider.should_receive(:yum_command).with( + expect(@provider).to receive(:yum_command).with( "yum -d0 -e0 -y remove emacs-1.0" ) @provider.purge_package("emacs", "1.0") @@ -596,8 +596,8 @@ describe Chef::Provider::Package::Yum do describe "when running yum" do it "should run yum once if it exits with a return code of 0" do @status = double("Status", :exitstatus => 0) - @provider.stub(:output_of_command).and_return([@status, "", ""]) - @provider.should_receive(:output_of_command).once.with( + allow(@provider).to receive(:output_of_command).and_return([@status, "", ""]) + expect(@provider).to receive(:output_of_command).once.with( "yum -d0 -e0 -y install emacs-1.0", {:timeout => Chef::Config[:yum_timeout]} ) @@ -606,34 +606,34 @@ 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 = double("Status", :exitstatus => 2) - @provider.stub(:output_of_command).and_return([@status, "failure failure", "problem problem"]) - @provider.should_receive(:output_of_command).once.with( + allow(@provider).to receive(:output_of_command).and_return([@status, "failure failure", "problem problem"]) + expect(@provider).to receive(:output_of_command).once.with( "yum -d0 -e0 -y install emacs-1.0", {:timeout => Chef::Config[:yum_timeout]} ) - lambda { @provider.yum_command("yum -d0 -e0 -y install emacs-1.0") }.should raise_error(Chef::Exceptions::Exec) + expect { @provider.yum_command("yum -d0 -e0 -y install emacs-1.0") }.to raise_error(Chef::Exceptions::Exec) end it "should run yum once if it exits with a return code of 1 and %pre scriptlet failures" do @status = double("Status", :exitstatus => 1) - @provider.stub(:output_of_command).and_return([@status, "error: %pre(demo-1-1.el5.centos.x86_64) scriptlet failed, exit status 2", ""]) - @provider.should_receive(:output_of_command).once.with( + allow(@provider).to receive(:output_of_command).and_return([@status, "error: %pre(demo-1-1.el5.centos.x86_64) scriptlet failed, exit status 2", ""]) + expect(@provider).to receive(:output_of_command).once.with( "yum -d0 -e0 -y install emacs-1.0", {:timeout => Chef::Config[:yum_timeout]} ) # will still raise an exception, can't stub out the subsequent call - lambda { @provider.yum_command("yum -d0 -e0 -y install emacs-1.0") }.should raise_error(Chef::Exceptions::Exec) + expect { @provider.yum_command("yum -d0 -e0 -y install emacs-1.0") }.to raise_error(Chef::Exceptions::Exec) end it "should run yum twice if it exits with a return code of 1 and %post scriptlet failures" do @status = double("Status", :exitstatus => 1) - @provider.stub(:output_of_command).and_return([@status, "error: %post(demo-1-1.el5.centos.x86_64) scriptlet failed, exit status 2", ""]) - @provider.should_receive(:output_of_command).twice.with( + allow(@provider).to receive(:output_of_command).and_return([@status, "error: %post(demo-1-1.el5.centos.x86_64) scriptlet failed, exit status 2", ""]) + expect(@provider).to receive(:output_of_command).twice.with( "yum -d0 -e0 -y install emacs-1.0", {:timeout => Chef::Config[:yum_timeout]} ) # will still raise an exception, can't stub out the subsequent call - lambda { @provider.yum_command("yum -d0 -e0 -y install emacs-1.0") }.should raise_error(Chef::Exceptions::Exec) + expect { @provider.yum_command("yum -d0 -e0 -y install emacs-1.0") }.to raise_error(Chef::Exceptions::Exec) end end end @@ -650,7 +650,7 @@ describe Chef::Provider::Package::Yum::RPMUtils do [ "9:1.7.3", [ 9, "1.7.3", nil ] ], [ "15:20020927", [ 15, "20020927", nil ] ] ].each do |x, y| - @rpmutils.version_parse(x).should == y + expect(@rpmutils.version_parse(x)).to eq(y) end end @@ -660,7 +660,7 @@ describe Chef::Provider::Package::Yum::RPMUtils do [ "-1:1.7.3", [ nil, nil, "1:1.7.3" ] ], [ "-:20020927", [ nil, nil, ":20020927" ] ] ].each do |x, y| - @rpmutils.version_parse(x).should == y + expect(@rpmutils.version_parse(x)).to eq(y) end end @@ -670,7 +670,7 @@ describe Chef::Provider::Package::Yum::RPMUtils do [ "1.7.3", [ nil, "1.7.3", nil ] ], [ "20020927", [ nil, "20020927", nil ] ] ].each do |x, y| - @rpmutils.version_parse(x).should == y + expect(@rpmutils.version_parse(x)).to eq(y) end end @@ -680,7 +680,7 @@ describe Chef::Provider::Package::Yum::RPMUtils do [ "0001.7.3", [ nil, "0001.7.3", nil ] ], [ "20020927,3", [ nil, "20020927,3", nil ] ] ].each do |x, y| - @rpmutils.version_parse(x).should == y + expect(@rpmutils.version_parse(x)).to eq(y) end end @@ -690,7 +690,7 @@ describe Chef::Provider::Package::Yum::RPMUtils do [ "1.7.3-1jpp.2.el5", [ nil, "1.7.3", "1jpp.2.el5" ] ], [ "20020927-46.el5", [ nil, "20020927", "46.el5" ] ] ].each do |x, y| - @rpmutils.version_parse(x).should == y + expect(@rpmutils.version_parse(x)).to eq(y) end end @@ -700,7 +700,7 @@ describe Chef::Provider::Package::Yum::RPMUtils do [ "-1jpp.2.el5", [ nil, nil, "1jpp.2.el5" ] ], [ "-0020020927-46.el5", [ nil, "-0020020927", "46.el5" ] ] ].each do |x, y| - @rpmutils.version_parse(x).should == y + expect(@rpmutils.version_parse(x)).to eq(y) end end end @@ -757,7 +757,7 @@ describe Chef::Provider::Package::Yum::RPMUtils do [ "0.0.1aa", "0.0.1aa", 0 ], [ "0.0.1a", "0.0.1aa", -1 ], ].each do |x, y, result| - @rpmutils.rpmvercmp(x,y).should == result + expect(@rpmutils.rpmvercmp(x,y)).to eq(result) end end @@ -776,43 +776,43 @@ describe Chef::Provider::Package::Yum::RPMUtils do [ "", "", 0 ], [ "", "1.0.1", -1 ] ].each do |x, y, result| - @rpmutils.rpmvercmp(x,y).should == result + expect(@rpmutils.rpmvercmp(x,y)).to eq(result) end end it "tests isalnum good input" do [ 'a', 'z', 'A', 'Z', '0', '9' ].each do |t| - @rpmutils.isalnum(t).should == true + expect(@rpmutils.isalnum(t)).to eq(true) end end it "tests isalnum bad input" do [ '-', '.', '!', '^', ':', '_' ].each do |t| - @rpmutils.isalnum(t).should == false + expect(@rpmutils.isalnum(t)).to eq(false) end end it "tests isalpha good input" do [ 'a', 'z', 'A', 'Z', ].each do |t| - @rpmutils.isalpha(t).should == true + expect(@rpmutils.isalpha(t)).to eq(true) end end it "tests isalpha bad input" do [ '0', '9', '-', '.', '!', '^', ':', '_' ].each do |t| - @rpmutils.isalpha(t).should == false + expect(@rpmutils.isalpha(t)).to eq(false) end end it "tests isdigit good input" do [ '0', '9', ].each do |t| - @rpmutils.isdigit(t).should == true + expect(@rpmutils.isdigit(t)).to eq(true) end end it "tests isdigit bad input" do [ 'A', 'z', '-', '.', '!', '^', ':', '_' ].each do |t| - @rpmutils.isdigit(t).should == false + expect(@rpmutils.isdigit(t)).to eq(false) end end end @@ -826,15 +826,15 @@ describe Chef::Provider::Package::Yum::RPMVersion do end it "should expose evr (name-version-release) available" do - @rpmv.e.should == 1 - @rpmv.v.should == "1.6.5" - @rpmv.r.should == "9.36.el5" + expect(@rpmv.e).to eq(1) + expect(@rpmv.v).to eq("1.6.5") + expect(@rpmv.r).to eq("9.36.el5") - @rpmv.evr.should == "1:1.6.5-9.36.el5" + expect(@rpmv.evr).to eq("1:1.6.5-9.36.el5") end it "should output a version-release string" do - @rpmv.to_s.should == "1.6.5-9.36.el5" + expect(@rpmv.to_s).to eq("1.6.5-9.36.el5") end end @@ -844,34 +844,34 @@ describe Chef::Provider::Package::Yum::RPMVersion do end it "should expose evr (name-version-release) available" do - @rpmv.e.should == 1 - @rpmv.v.should == "1.6.5" - @rpmv.r.should == "9.36.el5" + expect(@rpmv.e).to eq(1) + expect(@rpmv.v).to eq("1.6.5") + expect(@rpmv.r).to eq("9.36.el5") - @rpmv.evr.should == "1:1.6.5-9.36.el5" + expect(@rpmv.evr).to eq("1:1.6.5-9.36.el5") end it "should output a version-release string" do - @rpmv.to_s.should == "1.6.5-9.36.el5" + expect(@rpmv.to_s).to eq("1.6.5-9.36.el5") end end it "should raise an error unless passed 1 or 3 args" do - lambda { + expect { Chef::Provider::Package::Yum::RPMVersion.new() - }.should raise_error(ArgumentError) - lambda { + }.to raise_error(ArgumentError) + expect { Chef::Provider::Package::Yum::RPMVersion.new("1:1.6.5-9.36.el5") - }.should_not raise_error - lambda { + }.not_to raise_error + expect { Chef::Provider::Package::Yum::RPMVersion.new("1:1.6.5-9.36.el5", "extra") - }.should raise_error(ArgumentError) - lambda { + }.to raise_error(ArgumentError) + expect { Chef::Provider::Package::Yum::RPMVersion.new("1", "1.6.5", "9.36.el5") - }.should_not raise_error - lambda { + }.not_to raise_error + expect { Chef::Provider::Package::Yum::RPMVersion.new("1", "1.6.5", "9.36.el5", "extra") - }.should raise_error(ArgumentError) + }.to raise_error(ArgumentError) end # thanks version_class_spec.rb! @@ -898,9 +898,9 @@ describe Chef::Provider::Package::Yum::RPMVersion do ].each do |smaller, larger| sm = Chef::Provider::Package::Yum::RPMVersion.new(smaller) lg = Chef::Provider::Package::Yum::RPMVersion.new(larger) - sm.should be < lg - lg.should be > sm - sm.should_not == lg + expect(sm).to be < lg + expect(lg).to be > sm + expect(sm).not_to eq(lg) end end @@ -924,9 +924,9 @@ describe Chef::Provider::Package::Yum::RPMVersion do ].each do |smaller, larger| sm = Chef::Provider::Package::Yum::RPMVersion.new(smaller) lg = Chef::Provider::Package::Yum::RPMVersion.new(larger) - sm.should be < lg - lg.should be > sm - sm.should_not == lg + expect(sm).to be < lg + expect(lg).to be > sm + expect(sm).not_to eq(lg) end end @@ -941,7 +941,7 @@ describe Chef::Provider::Package::Yum::RPMVersion do ].each do |smaller, larger| sm = Chef::Provider::Package::Yum::RPMVersion.new(smaller) lg = Chef::Provider::Package::Yum::RPMVersion.new(larger) - sm.should be == lg + expect(sm).to eq(lg) end end @@ -956,7 +956,7 @@ describe Chef::Provider::Package::Yum::RPMVersion do ].each do |smaller, larger| sm = Chef::Provider::Package::Yum::RPMVersion.new(smaller) lg = Chef::Provider::Package::Yum::RPMVersion.new(larger) - sm.should be == lg + expect(sm).to eq(lg) end end end @@ -980,9 +980,9 @@ describe Chef::Provider::Package::Yum::RPMVersion do ].each do |smaller, larger| sm = Chef::Provider::Package::Yum::RPMVersion.new(smaller) lg = Chef::Provider::Package::Yum::RPMVersion.new(larger) - sm.partial_compare(lg).should be == -1 - lg.partial_compare(sm).should be == 1 - sm.partial_compare(lg).should_not be == 0 + expect(sm.partial_compare(lg)).to eq(-1) + expect(lg.partial_compare(sm)).to eq(1) + expect(sm.partial_compare(lg)).not_to eq(0) end end @@ -997,7 +997,7 @@ describe Chef::Provider::Package::Yum::RPMVersion do ].each do |smaller, larger| sm = Chef::Provider::Package::Yum::RPMVersion.new(smaller) lg = Chef::Provider::Package::Yum::RPMVersion.new(larger) - sm.partial_compare(lg).should be == 0 + expect(sm.partial_compare(lg)).to eq(0) end end end @@ -1011,18 +1011,18 @@ describe Chef::Provider::Package::Yum::RPMPackage do end it "should expose nevra (name-epoch-version-release-arch) available" do - @rpm.name.should == "testing" - @rpm.version.e.should == 1 - @rpm.version.v.should == "1.6.5" - @rpm.version.r.should == "9.36.el5" - @rpm.arch.should == "x86_64" + expect(@rpm.name).to eq("testing") + expect(@rpm.version.e).to eq(1) + expect(@rpm.version.v).to eq("1.6.5") + expect(@rpm.version.r).to eq("9.36.el5") + expect(@rpm.arch).to eq("x86_64") - @rpm.nevra.should == "testing-1:1.6.5-9.36.el5.x86_64" - @rpm.to_s.should == @rpm.nevra + expect(@rpm.nevra).to eq("testing-1:1.6.5-9.36.el5.x86_64") + expect(@rpm.to_s).to eq(@rpm.nevra) end it "should always have at least one provide, itself" do - @rpm.provides.size.should == 1 + expect(@rpm.provides.size).to eq(1) @rpm.provides[0].name == "testing" @rpm.provides[0].version.evr == "1:1.6.5-9.36.el5" @rpm.provides[0].flag == :== @@ -1035,18 +1035,18 @@ describe Chef::Provider::Package::Yum::RPMPackage do end it "should expose nevra (name-epoch-version-release-arch) available" do - @rpm.name.should == "testing" - @rpm.version.e.should == 1 - @rpm.version.v.should == "1.6.5" - @rpm.version.r.should == "9.36.el5" - @rpm.arch.should == "x86_64" + expect(@rpm.name).to eq("testing") + expect(@rpm.version.e).to eq(1) + expect(@rpm.version.v).to eq("1.6.5") + expect(@rpm.version.r).to eq("9.36.el5") + expect(@rpm.arch).to eq("x86_64") - @rpm.nevra.should == "testing-1:1.6.5-9.36.el5.x86_64" - @rpm.to_s.should == @rpm.nevra + expect(@rpm.nevra).to eq("testing-1:1.6.5-9.36.el5.x86_64") + expect(@rpm.to_s).to eq(@rpm.nevra) end it "should always have at least one provide, itself" do - @rpm.provides.size.should == 1 + expect(@rpm.provides.size).to eq(1) @rpm.provides[0].name == "testing" @rpm.provides[0].version.evr == "1:1.6.5-9.36.el5" @rpm.provides[0].flag == :== @@ -1054,30 +1054,30 @@ describe Chef::Provider::Package::Yum::RPMPackage do end it "should raise an error unless passed 4 or 6 args" do - lambda { + expect { Chef::Provider::Package::Yum::RPMPackage.new() - }.should raise_error(ArgumentError) - lambda { + }.to raise_error(ArgumentError) + expect { Chef::Provider::Package::Yum::RPMPackage.new("testing") - }.should raise_error(ArgumentError) - lambda { + }.to raise_error(ArgumentError) + expect { Chef::Provider::Package::Yum::RPMPackage.new("testing", "1:1.6.5-9.36.el5") - }.should raise_error(ArgumentError) - lambda { + }.to raise_error(ArgumentError) + expect { Chef::Provider::Package::Yum::RPMPackage.new("testing", "1:1.6.5-9.36.el5", "x86_64") - }.should raise_error(ArgumentError) - lambda { + }.to raise_error(ArgumentError) + expect { Chef::Provider::Package::Yum::RPMPackage.new("testing", "1:1.6.5-9.36.el5", "x86_64", []) - }.should_not raise_error - lambda { + }.not_to raise_error + expect { Chef::Provider::Package::Yum::RPMPackage.new("testing", "1", "1.6.5", "9.36.el5", "x86_64") - }.should raise_error(ArgumentError) - lambda { + }.to raise_error(ArgumentError) + expect { Chef::Provider::Package::Yum::RPMPackage.new("testing", "1", "1.6.5", "9.36.el5", "x86_64", []) - }.should_not raise_error - lambda { + }.not_to raise_error + expect { Chef::Provider::Package::Yum::RPMPackage.new("testing", "1", "1.6.5", "9.36.el5", "x86_64", [], "extra") - }.should raise_error(ArgumentError) + }.to raise_error(ArgumentError) end describe "<=>" do @@ -1096,9 +1096,9 @@ describe Chef::Provider::Package::Yum::RPMPackage do ].each do |smaller, larger| sm = Chef::Provider::Package::Yum::RPMPackage.new(smaller, "0:0.0.1-1", "x86_64", []) lg = Chef::Provider::Package::Yum::RPMPackage.new(larger, "0:0.0.1-1", "x86_64", []) - sm.should be < lg - lg.should be > sm - sm.should_not == lg + expect(sm).to be < lg + expect(lg).to be > sm + expect(sm).not_to eq(lg) end end @@ -1113,9 +1113,9 @@ describe Chef::Provider::Package::Yum::RPMPackage do ].each do |smaller, larger| sm = Chef::Provider::Package::Yum::RPMPackage.new("test-package", "0:0.0.1-1", smaller, []) lg = Chef::Provider::Package::Yum::RPMPackage.new("test-package", "0:0.0.1-1", larger, []) - sm.should be < lg - lg.should be > sm - sm.should_not == lg + expect(sm).to be < lg + expect(lg).to be > sm + expect(sm).not_to eq(lg) end end end @@ -1132,31 +1132,31 @@ describe Chef::Provider::Package::Yum::RPMDbPackage do describe "initialize" do it "should return a Chef::Provider::Package::Yum::RPMDbPackage object" do - @rpm_x.should be_kind_of(Chef::Provider::Package::Yum::RPMDbPackage) + expect(@rpm_x).to be_kind_of(Chef::Provider::Package::Yum::RPMDbPackage) end end describe "available" do it "should return true" do - @rpm_x.available.should be == true - @rpm_y.available.should be == true - @rpm_z.available.should be == false + expect(@rpm_x.available).to eq(true) + expect(@rpm_y.available).to eq(true) + expect(@rpm_z.available).to eq(false) end end describe "installed" do it "should return true" do - @rpm_x.installed.should be == false - @rpm_y.installed.should be == true - @rpm_z.installed.should be == true + expect(@rpm_x.installed).to eq(false) + expect(@rpm_y.installed).to eq(true) + expect(@rpm_z.installed).to eq(true) end end describe "repoid" do it "should return the source repository repoid" do - @rpm_x.repoid.should be == "base" - @rpm_y.repoid.should be == "extras" - @rpm_z.repoid.should be == "other" + expect(@rpm_x.repoid).to eq("base") + expect(@rpm_y.repoid).to eq("extras") + expect(@rpm_z.repoid).to eq("other") end end end @@ -1168,11 +1168,11 @@ describe Chef::Provider::Package::Yum::RPMDependency do end it "should expose name, version, flag available" do - @rpmdep.name.should == "testing" - @rpmdep.version.e.should == 1 - @rpmdep.version.v.should == "1.6.5" - @rpmdep.version.r.should == "9.36.el5" - @rpmdep.flag.should == :== + expect(@rpmdep.name).to eq("testing") + expect(@rpmdep.version.e).to eq(1) + expect(@rpmdep.version.v).to eq("1.6.5") + expect(@rpmdep.version.r).to eq("9.36.el5") + expect(@rpmdep.flag).to eq(:==) end end @@ -1182,67 +1182,67 @@ describe Chef::Provider::Package::Yum::RPMDependency do end it "should expose name, version, flag available" do - @rpmdep.name.should == "testing" - @rpmdep.version.e.should == 1 - @rpmdep.version.v.should == "1.6.5" - @rpmdep.version.r.should == "9.36.el5" - @rpmdep.flag.should == :== + expect(@rpmdep.name).to eq("testing") + expect(@rpmdep.version.e).to eq(1) + expect(@rpmdep.version.v).to eq("1.6.5") + expect(@rpmdep.version.r).to eq("9.36.el5") + expect(@rpmdep.flag).to eq(:==) end end it "should raise an error unless passed 3 or 5 args" do - lambda { + expect { Chef::Provider::Package::Yum::RPMDependency.new() - }.should raise_error(ArgumentError) - lambda { + }.to raise_error(ArgumentError) + expect { Chef::Provider::Package::Yum::RPMDependency.new("testing") - }.should raise_error(ArgumentError) - lambda { + }.to raise_error(ArgumentError) + expect { Chef::Provider::Package::Yum::RPMDependency.new("testing", "1:1.6.5-9.36.el5") - }.should raise_error(ArgumentError) - lambda { + }.to raise_error(ArgumentError) + expect { Chef::Provider::Package::Yum::RPMDependency.new("testing", "1:1.6.5-9.36.el5", :==) - }.should_not raise_error - lambda { + }.not_to raise_error + expect { Chef::Provider::Package::Yum::RPMDependency.new("testing", "1:1.6.5-9.36.el5", :==, "extra") - }.should raise_error(ArgumentError) - lambda { + }.to raise_error(ArgumentError) + expect { Chef::Provider::Package::Yum::RPMDependency.new("testing", "1", "1.6.5", "9.36.el5", :==) - }.should_not raise_error - lambda { + }.not_to raise_error + expect { Chef::Provider::Package::Yum::RPMDependency.new("testing", "1", "1.6.5", "9.36.el5", :==, "extra") - }.should raise_error(ArgumentError) + }.to raise_error(ArgumentError) end describe "parse" do it "should parse a name, flag, version string into a valid RPMDependency object" do @rpmdep = Chef::Provider::Package::Yum::RPMDependency.parse("testing >= 1:1.6.5-9.36.el5") - @rpmdep.name.should == "testing" - @rpmdep.version.e.should == 1 - @rpmdep.version.v.should == "1.6.5" - @rpmdep.version.r.should == "9.36.el5" - @rpmdep.flag.should == :>= + expect(@rpmdep.name).to eq("testing") + expect(@rpmdep.version.e).to eq(1) + expect(@rpmdep.version.v).to eq("1.6.5") + expect(@rpmdep.version.r).to eq("9.36.el5") + expect(@rpmdep.flag).to eq(:>=) end it "should parse a name into a valid RPMDependency object" do @rpmdep = Chef::Provider::Package::Yum::RPMDependency.parse("testing") - @rpmdep.name.should == "testing" - @rpmdep.version.e.should == nil - @rpmdep.version.v.should == nil - @rpmdep.version.r.should == nil - @rpmdep.flag.should == :== + expect(@rpmdep.name).to eq("testing") + expect(@rpmdep.version.e).to eq(nil) + expect(@rpmdep.version.v).to eq(nil) + expect(@rpmdep.version.r).to eq(nil) + expect(@rpmdep.flag).to eq(:==) end it "should parse an invalid string into the name of a RPMDependency object" do @rpmdep = Chef::Provider::Package::Yum::RPMDependency.parse("testing blah >") - @rpmdep.name.should == "testing blah >" - @rpmdep.version.e.should == nil - @rpmdep.version.v.should == nil - @rpmdep.version.r.should == nil - @rpmdep.flag.should == :== + expect(@rpmdep.name).to eq("testing blah >") + expect(@rpmdep.version.e).to eq(nil) + expect(@rpmdep.version.v).to eq(nil) + expect(@rpmdep.version.r).to eq(nil) + expect(@rpmdep.flag).to eq(:==) end it "should parse various valid flags" do @@ -1255,7 +1255,7 @@ describe Chef::Provider::Package::Yum::RPMDependency do [ "<", :< ] ].each do |before, after| @rpmdep = Chef::Provider::Package::Yum::RPMDependency.parse("testing #{before} 1:1.1-1") - @rpmdep.flag.should == after + expect(@rpmdep.flag).to eq(after) end end @@ -1269,8 +1269,8 @@ describe Chef::Provider::Package::Yum::RPMDependency do [ "~", :== ] ].each do |before, after| @rpmdep = Chef::Provider::Package::Yum::RPMDependency.parse("testing #{before} 1:1.1-1") - @rpmdep.name.should == "testing #{before} 1:1.1-1" - @rpmdep.flag.should == after + expect(@rpmdep.name).to eq("testing #{before} 1:1.1-1") + expect(@rpmdep.flag).to eq(after) end end end @@ -1279,12 +1279,12 @@ describe Chef::Provider::Package::Yum::RPMDependency do it "should raise an error unless a RPMDependency is passed" do @rpmprovide = Chef::Provider::Package::Yum::RPMDependency.new("testing", "1:1.6.5-9.36.el5", :==) @rpmrequire = Chef::Provider::Package::Yum::RPMDependency.new("testing", "1:1.6.5-9.36.el5", :>=) - lambda { + expect { @rpmprovide.satisfy?("hi") - }.should raise_error(ArgumentError) - lambda { + }.to raise_error(ArgumentError) + expect { @rpmprovide.satisfy?(@rpmrequire) - }.should_not raise_error + }.not_to raise_error end it "should validate dependency satisfaction logic for standard examples" do @@ -1326,8 +1326,8 @@ describe Chef::Provider::Package::Yum::RPMDependency do @rpmprovide = Chef::Provider::Package::Yum::RPMDependency.parse(prov) @rpmrequire = Chef::Provider::Package::Yum::RPMDependency.parse(req) - @rpmprovide.satisfy?(@rpmrequire).should == result - @rpmrequire.satisfy?(@rpmprovide).should == result + expect(@rpmprovide.satisfy?(@rpmrequire)).to eq(result) + expect(@rpmrequire.satisfy?(@rpmprovide)).to eq(result) end end end @@ -1358,89 +1358,89 @@ describe Chef::Provider::Package::Yum::RPMDb do describe "initialize" do it "should return a Chef::Provider::Package::Yum::RPMDb object" do - @rpmdb.should be_kind_of(Chef::Provider::Package::Yum::RPMDb) + expect(@rpmdb).to be_kind_of(Chef::Provider::Package::Yum::RPMDb) end end describe "push" do it "should accept an RPMDbPackage object through pushing" do - lambda { @rpmdb.push(@rpm_w) }.should_not raise_error + expect { @rpmdb.push(@rpm_w) }.not_to raise_error end it "should accept multiple RPMDbPackage object through pushing" do - lambda { @rpmdb.push(@rpm_w, @rpm_x, @rpm_y, @rpm_z) }.should_not raise_error + expect { @rpmdb.push(@rpm_w, @rpm_x, @rpm_y, @rpm_z) }.not_to raise_error end it "should only accept an RPMDbPackage object" do - lambda { @rpmdb.push("string") }.should raise_error + expect { @rpmdb.push("string") }.to raise_error end it "should add the package to the package db" do @rpmdb.push(@rpm_w) - @rpmdb["test-package-b"].should_not be == nil + expect(@rpmdb["test-package-b"]).not_to eq(nil) end it "should add conditionally add the package to the available list" do - @rpmdb.available_size.should be == 0 + expect(@rpmdb.available_size).to eq(0) @rpmdb.push(@rpm_v, @rpm_w) - @rpmdb.available_size.should be == 1 + expect(@rpmdb.available_size).to eq(1) end it "should add conditionally add the package to the installed list" do - @rpmdb.installed_size.should be == 0 + expect(@rpmdb.installed_size).to eq(0) @rpmdb.push(@rpm_w, @rpm_x) - @rpmdb.installed_size.should be == 1 + expect(@rpmdb.installed_size).to eq(1) end it "should have a total of 2 packages in the RPMDb" do - @rpmdb.size.should be == 0 + expect(@rpmdb.size).to eq(0) @rpmdb.push(@rpm_w, @rpm_x, @rpm_y, @rpm_z) - @rpmdb.size.should be == 2 + expect(@rpmdb.size).to eq(2) end it "should keep the Array unique when a duplicate is pushed" do @rpmdb.push(@rpm_z, @rpm_z_mirror) - @rpmdb["test-package-c"].size.should be == 1 + expect(@rpmdb["test-package-c"].size).to eq(1) end it "should register the package provides in the provides index" do @rpmdb.push(@rpm_v, @rpm_w, @rpm_z) - @rpmdb.lookup_provides("test-package-a")[0].should be == @rpm_v - @rpmdb.lookup_provides("config(test)")[0].should be == @rpm_z - @rpmdb.lookup_provides("libz.so.1()(64bit)")[0].should be == @rpm_v - @rpmdb.lookup_provides("libz.so.1()(64bit)")[1].should be == @rpm_z + expect(@rpmdb.lookup_provides("test-package-a")[0]).to eq(@rpm_v) + expect(@rpmdb.lookup_provides("config(test)")[0]).to eq(@rpm_z) + expect(@rpmdb.lookup_provides("libz.so.1()(64bit)")[0]).to eq(@rpm_v) + expect(@rpmdb.lookup_provides("libz.so.1()(64bit)")[1]).to eq(@rpm_z) end end describe "<<" do it "should accept an RPMPackage object through the << operator" do - lambda { @rpmdb << @rpm_w }.should_not raise_error + expect { @rpmdb << @rpm_w }.not_to raise_error end end describe "lookup" do it "should return an Array of RPMPackage objects by index" do @rpmdb << @rpm_w - @rpmdb.lookup("test-package-b").should be_kind_of(Array) + expect(@rpmdb.lookup("test-package-b")).to be_kind_of(Array) end end describe "[]" do it "should return an Array of RPMPackage objects though the [index] operator" do @rpmdb << @rpm_w - @rpmdb["test-package-b"].should be_kind_of(Array) + expect(@rpmdb["test-package-b"]).to be_kind_of(Array) end it "should return an Array of 3 RPMPackage objects" do @rpmdb.push(@rpm_w, @rpm_x, @rpm_y, @rpm_z) - @rpmdb["test-package-b"].size.should be == 3 + expect(@rpmdb["test-package-b"].size).to eq(3) end it "should return an Array of RPMPackage objects sorted from newest to oldest" do @rpmdb.push(@rpm_w, @rpm_x, @rpm_y, @rpm_z) - @rpmdb["test-package-b"][0].should be == @rpm_y - @rpmdb["test-package-b"][1].should be == @rpm_x - @rpmdb["test-package-b"][2].should be == @rpm_w + expect(@rpmdb["test-package-b"][0]).to eq(@rpm_y) + expect(@rpmdb["test-package-b"][1]).to eq(@rpm_x) + expect(@rpmdb["test-package-b"][2]).to eq(@rpm_w) end end @@ -1448,57 +1448,57 @@ describe Chef::Provider::Package::Yum::RPMDb do it "should return an Array of RPMPackage objects by index" do @rpmdb << @rpm_z x = @rpmdb.lookup_provides("config(test)") - x.should be_kind_of(Array) - x[0].should be == @rpm_z + expect(x).to be_kind_of(Array) + expect(x[0]).to eq(@rpm_z) end end describe "clear" do it "should clear the RPMDb" do - @rpmdb.should_receive(:clear_available).once - @rpmdb.should_receive(:clear_installed).once + expect(@rpmdb).to receive(:clear_available).once + expect(@rpmdb).to receive(:clear_installed).once @rpmdb.push(@rpm_w, @rpm_x, @rpm_y, @rpm_z) - @rpmdb.size.should_not be == 0 - @rpmdb.lookup_provides("config(test)").should be_kind_of(Array) + expect(@rpmdb.size).not_to eq(0) + expect(@rpmdb.lookup_provides("config(test)")).to be_kind_of(Array) @rpmdb.clear - @rpmdb.lookup_provides("config(test)").should be == nil - @rpmdb.size.should be == 0 + expect(@rpmdb.lookup_provides("config(test)")).to eq(nil) + expect(@rpmdb.size).to eq(0) end end describe "clear_available" do it "should clear the available list" do @rpmdb.push(@rpm_w, @rpm_x, @rpm_y, @rpm_z) - @rpmdb.available_size.should_not be == 0 + expect(@rpmdb.available_size).not_to eq(0) @rpmdb.clear_available - @rpmdb.available_size.should be == 0 + expect(@rpmdb.available_size).to eq(0) end end describe "available?" do it "should return true if a package is available" do - @rpmdb.available?(@rpm_w).should be == false + expect(@rpmdb.available?(@rpm_w)).to eq(false) @rpmdb.push(@rpm_v, @rpm_w) - @rpmdb.available?(@rpm_v).should be == false - @rpmdb.available?(@rpm_w).should be == true + expect(@rpmdb.available?(@rpm_v)).to eq(false) + expect(@rpmdb.available?(@rpm_w)).to eq(true) end end describe "clear_installed" do it "should clear the installed list" do @rpmdb.push(@rpm_w, @rpm_x, @rpm_y, @rpm_z) - @rpmdb.installed_size.should_not be == 0 + expect(@rpmdb.installed_size).not_to eq(0) @rpmdb.clear_installed - @rpmdb.installed_size.should be == 0 + expect(@rpmdb.installed_size).to eq(0) end end describe "installed?" do it "should return true if a package is installed" do - @rpmdb.installed?(@rpm_w).should be == false + expect(@rpmdb.installed?(@rpm_w)).to eq(false) @rpmdb.push(@rpm_w, @rpm_x) - @rpmdb.installed?(@rpm_w).should be == true - @rpmdb.installed?(@rpm_x).should be == false + expect(@rpmdb.installed?(@rpm_w)).to eq(true) + expect(@rpmdb.installed?(@rpm_x)).to eq(false) end end @@ -1506,12 +1506,12 @@ describe Chef::Provider::Package::Yum::RPMDb do it "should raise an error unless a RPMDependency is passed" do @rpmprovide = Chef::Provider::Package::Yum::RPMDependency.new("testing", "1:1.6.5-9.36.el5", :==) @rpmrequire = Chef::Provider::Package::Yum::RPMDependency.new("testing", "1:1.6.5-9.36.el5", :>=) - lambda { + expect { @rpmdb.whatprovides("hi") - }.should raise_error(ArgumentError) - lambda { + }.to raise_error(ArgumentError) + expect { @rpmdb.whatprovides(@rpmrequire) - }.should_not raise_error + }.not_to raise_error end it "should return an Array of packages statisfying a RPMDependency" do @@ -1519,14 +1519,14 @@ describe Chef::Provider::Package::Yum::RPMDb do @rpmrequire = Chef::Provider::Package::Yum::RPMDependency.parse("test-package-a >= 1.6.5") x = @rpmdb.whatprovides(@rpmrequire) - x.should be_kind_of(Array) - x[0].should be == @rpm_v + expect(x).to be_kind_of(Array) + expect(x[0]).to eq(@rpm_v) @rpmrequire = Chef::Provider::Package::Yum::RPMDependency.parse("libz.so.1()(64bit)") x = @rpmdb.whatprovides(@rpmrequire) - x.should be_kind_of(Array) - x[0].should be == @rpm_v - x[1].should be == @rpm_z + expect(x).to be_kind_of(Array) + expect(x[0]).to eq(@rpm_v) + expect(x[1]).to eq(@rpm_z) end end @@ -1592,18 +1592,18 @@ 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) + allow(@yc).to receive(:shell_out!).and_return(@status) end describe "initialize" do it "should return a Chef::Provider::Package::Yum::YumCache object" do - @yc.should be_kind_of(Chef::Provider::Package::Yum::YumCache) + expect(@yc).to be_kind_of(Chef::Provider::Package::Yum::YumCache) end it "should register reload for start of Chef::Client runs" do Chef::Provider::Package::Yum::YumCache.reset_instance - Chef::Client.should_receive(:when_run_starts) do |&b| - b.should_not be_nil + expect(Chef::Client).to receive(:when_run_starts) do |&b| + expect(b).not_to be_nil end @yc = Chef::Provider::Package::Yum::YumCache.instance end @@ -1611,7 +1611,7 @@ EOF describe "refresh" do it "should implicitly call yum-dump.py only once by default after being instantiated" do - @yc.should_receive(:shell_out!).once + expect(@yc).to receive(:shell_out!).once @yc.installed_version("zlib") @yc.reset @yc.installed_version("zlib") @@ -1619,226 +1619,226 @@ EOF it "should run yum-dump.py using the system python when next_refresh is for :all" do @yc.reload - @yc.should_receive(:shell_out!).with(%r{^/usr/bin/python .*/yum-dump.py --options --installed-provides --yum-lock-timeout 30$}, :timeout=>Chef::Config[:yum_timeout]) + expect(@yc).to receive(:shell_out!).with(%r{^/usr/bin/python .*/yum-dump.py --options --installed-provides --yum-lock-timeout 30$}, :timeout=>Chef::Config[:yum_timeout]) @yc.refresh end it "should run yum-dump.py with the installed flag when next_refresh is for :installed" do @yc.reload_installed - @yc.should_receive(:shell_out!).with(%r{^/usr/bin/python .*/yum-dump.py --installed --yum-lock-timeout 30$}, :timeout=>Chef::Config[:yum_timeout]) + expect(@yc).to receive(:shell_out!).with(%r{^/usr/bin/python .*/yum-dump.py --installed --yum-lock-timeout 30$}, :timeout=>Chef::Config[:yum_timeout]) @yc.refresh end it "should run yum-dump.py with the all-provides flag when next_refresh is for :provides" do @yc.reload_provides - @yc.should_receive(:shell_out!).with(%r{^/usr/bin/python .*/yum-dump.py --options --all-provides --yum-lock-timeout 30$}, :timeout=>Chef::Config[:yum_timeout]) + expect(@yc).to receive(:shell_out!).with(%r{^/usr/bin/python .*/yum-dump.py --options --all-provides --yum-lock-timeout 30$}, :timeout=>Chef::Config[:yum_timeout]) @yc.refresh end it "should pass extra_repo_control args to yum-dump.py" do @yc.enable_extra_repo_control("--enablerepo=foo --disablerepo=bar") - @yc.should_receive(:shell_out!).with(%r{^/usr/bin/python .*/yum-dump.py --options --installed-provides --enablerepo=foo --disablerepo=bar --yum-lock-timeout 30$}, :timeout=>Chef::Config[:yum_timeout]) + expect(@yc).to receive(:shell_out!).with(%r{^/usr/bin/python .*/yum-dump.py --options --installed-provides --enablerepo=foo --disablerepo=bar --yum-lock-timeout 30$}, :timeout=>Chef::Config[:yum_timeout]) @yc.refresh end it "should pass extra_repo_control args and configured yum lock timeout to yum-dump.py" do Chef::Config[:yum_lock_timeout] = 999 @yc.enable_extra_repo_control("--enablerepo=foo --disablerepo=bar") - @yc.should_receive(:shell_out!).with(%r{^/usr/bin/python .*/yum-dump.py --options --installed-provides --enablerepo=foo --disablerepo=bar --yum-lock-timeout 999$}, :timeout=>Chef::Config[:yum_timeout]) + expect(@yc).to receive(:shell_out!).with(%r{^/usr/bin/python .*/yum-dump.py --options --installed-provides --enablerepo=foo --disablerepo=bar --yum-lock-timeout 999$}, :timeout=>Chef::Config[:yum_timeout]) @yc.refresh end it "should warn about invalid data with too many separators" do @status = double("Status", :exitstatus => 0, :stdin => @stdin, :stdout => @stdout_bad_separators, :stderr => @stderr) - @yc.stub(:shell_out!).and_return(@status) - Chef::Log.should_receive(:warn).exactly(3).times.with(%r{Problem parsing}) + allow(@yc).to receive(:shell_out!).and_return(@status) + expect(Chef::Log).to receive(:warn).exactly(3).times.with(%r{Problem parsing}) @yc.refresh end it "should warn about invalid data with an incorrect type" do @status = double("Status", :exitstatus => 0, :stdin => @stdin, :stdout => @stdout_bad_type, :stderr => @stderr) - @yc.stub(:shell_out!).and_return(@status) - Chef::Log.should_receive(:warn).exactly(2).times.with(%r{Problem parsing}) + allow(@yc).to receive(:shell_out!).and_return(@status) + expect(Chef::Log).to receive(:warn).exactly(2).times.with(%r{Problem parsing}) @yc.refresh end it "should warn about no output from yum-dump.py" do @status = double("Status", :exitstatus => 0, :stdin => @stdin, :stdout => @stdout_no_output, :stderr => @stderr) - @yc.stub(:shell_out!).and_return(@status) - Chef::Log.should_receive(:warn).exactly(1).times.with(%r{no output from yum-dump.py}) + allow(@yc).to receive(:shell_out!).and_return(@status) + expect(Chef::Log).to 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 = double("Status", :exitstatus => 1, :stdin => @stdin, :stdout => @stdout_no_output, :stderr => @stderr) - @yc.stub(:shell_out!).and_return(@status) - lambda { @yc.refresh}.should raise_error(Chef::Exceptions::Package, %r{CentOS-Base.repo, line: 12}) + allow(@yc).to receive(:shell_out!).and_return(@status) + expect { @yc.refresh}.to raise_error(Chef::Exceptions::Package, %r{CentOS-Base.repo, line: 12}) end it "should parse type 'i' into an installed state for a package" do - @yc.available_version("erlang-mochiweb").should be == nil - @yc.installed_version("erlang-mochiweb").should_not be == nil + expect(@yc.available_version("erlang-mochiweb")).to eq(nil) + expect(@yc.installed_version("erlang-mochiweb")).not_to eq(nil) end it "should parse type 'a' into an available state for a package" do - @yc.available_version("znc").should_not be == nil - @yc.installed_version("znc").should be == nil + expect(@yc.available_version("znc")).not_to eq(nil) + expect(@yc.installed_version("znc")).to eq(nil) end it "should parse type 'r' into an installed and available states for a package" do - @yc.available_version("zip").should_not be == nil - @yc.installed_version("zip").should_not be == nil + expect(@yc.available_version("zip")).not_to eq(nil) + expect(@yc.installed_version("zip")).not_to eq(nil) end it "should parse installonlypkgs from yum-dump.py options output" do - @yc.allow_multi_install.should be == %w{kernel kernel-bigmem kernel-enterprise} + expect(@yc.allow_multi_install).to eq(%w{kernel kernel-bigmem kernel-enterprise}) end end describe "installed_version" do it "should take one or two arguments" do - lambda { @yc.installed_version("zip") }.should_not raise_error - lambda { @yc.installed_version("zip", "i386") }.should_not raise_error - lambda { @yc.installed_version("zip", "i386", "extra") }.should raise_error(ArgumentError) + expect { @yc.installed_version("zip") }.not_to raise_error + expect { @yc.installed_version("zip", "i386") }.not_to raise_error + expect { @yc.installed_version("zip", "i386", "extra") }.to raise_error(ArgumentError) end it "should return version-release for matching package regardless of arch" do - @yc.installed_version("zip", "x86_64").should be == "2.31-2.el5" - @yc.installed_version("zip", nil).should be == "2.31-2.el5" + expect(@yc.installed_version("zip", "x86_64")).to eq("2.31-2.el5") + expect(@yc.installed_version("zip", nil)).to eq("2.31-2.el5") end it "should return version-release for matching package and arch" do - @yc.installed_version("zip", "x86_64").should be == "2.31-2.el5" - @yc.installed_version("zisofs-tools", "i386").should be == nil + expect(@yc.installed_version("zip", "x86_64")).to eq("2.31-2.el5") + expect(@yc.installed_version("zisofs-tools", "i386")).to eq(nil) end it "should return nil for an unmatched package" do - @yc.installed_version(nil, nil).should be == nil - @yc.installed_version("test1", nil).should be == nil - @yc.installed_version("test2", "x86_64").should be == nil + expect(@yc.installed_version(nil, nil)).to eq(nil) + expect(@yc.installed_version("test1", nil)).to eq(nil) + expect(@yc.installed_version("test2", "x86_64")).to eq(nil) end end describe "available_version" do it "should take one or two arguments" do - lambda { @yc.available_version("zisofs-tools") }.should_not raise_error - lambda { @yc.available_version("zisofs-tools", "i386") }.should_not raise_error - lambda { @yc.available_version("zisofs-tools", "i386", "extra") }.should raise_error(ArgumentError) + expect { @yc.available_version("zisofs-tools") }.not_to raise_error + expect { @yc.available_version("zisofs-tools", "i386") }.not_to raise_error + expect { @yc.available_version("zisofs-tools", "i386", "extra") }.to raise_error(ArgumentError) end it "should return version-release for matching package regardless of arch" do - @yc.available_version("zip", "x86_64").should be == "2.31-2.el5" - @yc.available_version("zip", nil).should be == "2.31-2.el5" + expect(@yc.available_version("zip", "x86_64")).to eq("2.31-2.el5") + expect(@yc.available_version("zip", nil)).to eq("2.31-2.el5") end it "should return version-release for matching package and arch" do - @yc.available_version("zip", "x86_64").should be == "2.31-2.el5" - @yc.available_version("zisofs-tools", "i386").should be == nil + expect(@yc.available_version("zip", "x86_64")).to eq("2.31-2.el5") + expect(@yc.available_version("zisofs-tools", "i386")).to eq(nil) end it "should return nil for an unmatched package" do - @yc.available_version(nil, nil).should be == nil - @yc.available_version("test1", nil).should be == nil - @yc.available_version("test2", "x86_64").should be == nil + expect(@yc.available_version(nil, nil)).to eq(nil) + expect(@yc.available_version("test1", nil)).to eq(nil) + expect(@yc.available_version("test2", "x86_64")).to eq(nil) end end describe "version_available?" do it "should take two or three arguments" do - lambda { @yc.version_available?("zisofs-tools") }.should raise_error(ArgumentError) - lambda { @yc.version_available?("zisofs-tools", "1.0.6-3.2.2") }.should_not raise_error - lambda { @yc.version_available?("zisofs-tools", "1.0.6-3.2.2", "x86_64") }.should_not raise_error + expect { @yc.version_available?("zisofs-tools") }.to raise_error(ArgumentError) + expect { @yc.version_available?("zisofs-tools", "1.0.6-3.2.2") }.not_to raise_error + expect { @yc.version_available?("zisofs-tools", "1.0.6-3.2.2", "x86_64") }.not_to raise_error end it "should return true if our package-version-arch is available" do - @yc.version_available?("zisofs-tools", "1.0.6-3.2.2", "x86_64").should be == true + expect(@yc.version_available?("zisofs-tools", "1.0.6-3.2.2", "x86_64")).to eq(true) end it "should return true if our package-version, no arch, is available" do - @yc.version_available?("zisofs-tools", "1.0.6-3.2.2", nil).should be == true - @yc.version_available?("zisofs-tools", "1.0.6-3.2.2").should be == true + expect(@yc.version_available?("zisofs-tools", "1.0.6-3.2.2", nil)).to eq(true) + expect(@yc.version_available?("zisofs-tools", "1.0.6-3.2.2")).to eq(true) end it "should return false if our package-version-arch isn't available" do - @yc.version_available?("zisofs-tools", "1.0.6-3.2.2", "pretend").should be == false - @yc.version_available?("zisofs-tools", "pretend", "x86_64").should be == false - @yc.version_available?("pretend", "1.0.6-3.2.2", "x86_64").should be == false + expect(@yc.version_available?("zisofs-tools", "1.0.6-3.2.2", "pretend")).to eq(false) + expect(@yc.version_available?("zisofs-tools", "pretend", "x86_64")).to eq(false) + expect(@yc.version_available?("pretend", "1.0.6-3.2.2", "x86_64")).to eq(false) end it "should return false if our package-version, no arch, isn't available" do - @yc.version_available?("zisofs-tools", "pretend", nil).should be == false - @yc.version_available?("zisofs-tools", "pretend").should be == false - @yc.version_available?("pretend", "1.0.6-3.2.2").should be == false + expect(@yc.version_available?("zisofs-tools", "pretend", nil)).to eq(false) + expect(@yc.version_available?("zisofs-tools", "pretend")).to eq(false) + expect(@yc.version_available?("pretend", "1.0.6-3.2.2")).to eq(false) end end describe "package_repository" do it "should take two or three arguments" do - lambda { @yc.package_repository("zisofs-tools") }.should raise_error(ArgumentError) - lambda { @yc.package_repository("zisofs-tools", "1.0.6-3.2.2") }.should_not raise_error - lambda { @yc.package_repository("zisofs-tools", "1.0.6-3.2.2", "x86_64") }.should_not raise_error + expect { @yc.package_repository("zisofs-tools") }.to raise_error(ArgumentError) + expect { @yc.package_repository("zisofs-tools", "1.0.6-3.2.2") }.not_to raise_error + expect { @yc.package_repository("zisofs-tools", "1.0.6-3.2.2", "x86_64") }.not_to raise_error end it "should return repoid for package-version-arch" do - @yc.package_repository("zlib-devel", "1.2.3-3", "i386").should be == "extras" - @yc.package_repository("zlib-devel", "1.2.3-3", "x86_64").should be == "base" + expect(@yc.package_repository("zlib-devel", "1.2.3-3", "i386")).to eq("extras") + expect(@yc.package_repository("zlib-devel", "1.2.3-3", "x86_64")).to eq("base") end it "should return repoid for package-version, no arch" do - @yc.package_repository("zisofs-tools", "1.0.6-3.2.2", nil).should be == "extras" - @yc.package_repository("zisofs-tools", "1.0.6-3.2.2").should be == "extras" + expect(@yc.package_repository("zisofs-tools", "1.0.6-3.2.2", nil)).to eq("extras") + expect(@yc.package_repository("zisofs-tools", "1.0.6-3.2.2")).to eq("extras") end it "should return nil when no match for package-version-arch" do - @yc.package_repository("zisofs-tools", "1.0.6-3.2.2", "pretend").should be == nil - @yc.package_repository("zisofs-tools", "pretend", "x86_64").should be == nil - @yc.package_repository("pretend", "1.0.6-3.2.2", "x86_64").should be == nil + expect(@yc.package_repository("zisofs-tools", "1.0.6-3.2.2", "pretend")).to eq(nil) + expect(@yc.package_repository("zisofs-tools", "pretend", "x86_64")).to eq(nil) + expect(@yc.package_repository("pretend", "1.0.6-3.2.2", "x86_64")).to eq(nil) end it "should return nil when no match for package-version, no arch" do - @yc.package_repository("zisofs-tools", "pretend", nil).should be == nil - @yc.package_repository("zisofs-tools", "pretend").should be == nil - @yc.package_repository("pretend", "1.0.6-3.2.2").should be == nil + expect(@yc.package_repository("zisofs-tools", "pretend", nil)).to eq(nil) + expect(@yc.package_repository("zisofs-tools", "pretend")).to eq(nil) + expect(@yc.package_repository("pretend", "1.0.6-3.2.2")).to eq(nil) end end describe "reset" do it "should empty the installed and available packages RPMDb" do - @yc.available_version("zip", "x86_64").should be == "2.31-2.el5" - @yc.installed_version("zip", "x86_64").should be == "2.31-2.el5" + expect(@yc.available_version("zip", "x86_64")).to eq("2.31-2.el5") + expect(@yc.installed_version("zip", "x86_64")).to eq("2.31-2.el5") @yc.reset - @yc.available_version("zip", "x86_64").should be == nil - @yc.installed_version("zip", "x86_64").should be == nil + expect(@yc.available_version("zip", "x86_64")).to eq(nil) + expect(@yc.installed_version("zip", "x86_64")).to eq(nil) end end describe "package_available?" do it "should return true a package name is available" do - @yc.package_available?("zisofs-tools").should be == true - @yc.package_available?("moo").should be == false - @yc.package_available?(nil).should be == false + expect(@yc.package_available?("zisofs-tools")).to eq(true) + expect(@yc.package_available?("moo")).to eq(false) + expect(@yc.package_available?(nil)).to eq(false) end it "should return true a package name + arch is available" do - @yc.package_available?("zlib-devel.i386").should be == true - @yc.package_available?("zisofs-tools.x86_64").should be == true - @yc.package_available?("znc-test.beta1.x86_64").should be == true - @yc.package_available?("znc-test.beta1").should be == true - @yc.package_available?("znc-test.test.beta1").should be == true - @yc.package_available?("moo.i386").should be == false - @yc.package_available?("zisofs-tools.beta").should be == false - @yc.package_available?("znc-test.test").should be == false + expect(@yc.package_available?("zlib-devel.i386")).to eq(true) + expect(@yc.package_available?("zisofs-tools.x86_64")).to eq(true) + expect(@yc.package_available?("znc-test.beta1.x86_64")).to eq(true) + expect(@yc.package_available?("znc-test.beta1")).to eq(true) + expect(@yc.package_available?("znc-test.test.beta1")).to eq(true) + expect(@yc.package_available?("moo.i386")).to eq(false) + expect(@yc.package_available?("zisofs-tools.beta")).to eq(false) + expect(@yc.package_available?("znc-test.test")).to eq(false) end end describe "enable_extra_repo_control" do it "should set @extra_repo_control to arg" do @yc.enable_extra_repo_control("--enablerepo=test") - @yc.extra_repo_control.should be == "--enablerepo=test" + expect(@yc.extra_repo_control).to eq("--enablerepo=test") end it "should call reload once when set to flag cache for update" do - @yc.should_receive(:reload).once + expect(@yc).to receive(:reload).once @yc.enable_extra_repo_control("--enablerepo=test") @yc.enable_extra_repo_control("--enablerepo=test") end @@ -1848,13 +1848,13 @@ EOF it "should set @extra_repo_control to nil" do @yc.enable_extra_repo_control("--enablerepo=test") @yc.disable_extra_repo_control - @yc.extra_repo_control.should be == nil + expect(@yc.extra_repo_control).to eq(nil) end it "should call reload once when cleared to flag cache for update" do - @yc.should_receive(:reload).once + expect(@yc).to receive(:reload).once @yc.enable_extra_repo_control("--enablerepo=test") - @yc.should_receive(:reload).once + expect(@yc).to receive(:reload).once @yc.disable_extra_repo_control @yc.disable_extra_repo_control end diff --git a/spec/unit/provider/package/zypper_spec.rb b/spec/unit/provider/package/zypper_spec.rb index 87f02d7794..17d99640e6 100644 --- a/spec/unit/provider/package/zypper_spec.rb +++ b/spec/unit/provider/package/zypper_spec.rb @@ -30,84 +30,84 @@ describe Chef::Provider::Package::Zypper do @status = double("Status", :exitstatus => 0) @provider = Chef::Provider::Package::Zypper.new(@new_resource, @run_context) - Chef::Resource::Package.stub(:new).and_return(@current_resource) - @provider.stub(:popen4).and_return(@status) + allow(Chef::Resource::Package).to receive(:new).and_return(@current_resource) + allow(@provider).to receive(:popen4).and_return(@status) @stderr = StringIO.new @stdout = StringIO.new @pid = double("PID") - @provider.stub(:`).and_return("2.0") + allow(@provider).to receive(:`).and_return("2.0") end describe "when loading the current package state" do it "should create a current resource with the name of the new_resource" do - Chef::Resource::Package.should_receive(:new).and_return(@current_resource) + expect(Chef::Resource::Package).to receive(:new).and_return(@current_resource) @provider.load_current_resource end it "should set the current resources package name to the new resources package name" do - @current_resource.should_receive(:package_name).with(@new_resource.package_name) + expect(@current_resource).to receive(:package_name).with(@new_resource.package_name) @provider.load_current_resource end it "should run zypper info with the package name" do - @provider.should_receive(:popen4).with("zypper --non-interactive info #{@new_resource.package_name}").and_return(@status) + expect(@provider).to receive(:popen4).with("zypper --non-interactive info #{@new_resource.package_name}").and_return(@status) @provider.load_current_resource 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) - @current_resource.should_receive(:version).with(nil).and_return(true) + allow(@provider).to receive(:popen4).and_yield(@pid, @stdin, @stdout, @stderr).and_return(@status) + expect(@current_resource).to 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) - @current_resource.should_receive(:version).with("1.0").and_return(true) + allow(@provider).to receive(:popen4).and_yield(@pid, @stdin, @stdout, @stderr).and_return(@status) + expect(@current_resource).to receive(:version).with("1.0").and_return(true) @provider.load_current_resource end 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) + allow(@provider).to receive(:popen4).and_yield(@pid, @stdin, @stdout, @stderr).and_return(@status) @provider.load_current_resource - @provider.candidate_version.should eql("1.0") + expect(@provider.candidate_version).to eql("1.0") end it "should raise an exception if zypper info fails" do - @status.should_receive(:exitstatus).and_return(1) - lambda { @provider.load_current_resource }.should raise_error(Chef::Exceptions::Package) + expect(@status).to receive(:exitstatus).and_return(1) + expect { @provider.load_current_resource }.to raise_error(Chef::Exceptions::Package) end it "should not raise an exception if zypper info succeeds" do - @status.should_receive(:exitstatus).and_return(0) - lambda { @provider.load_current_resource }.should_not raise_error + expect(@status).to receive(:exitstatus).and_return(0) + expect { @provider.load_current_resource }.not_to raise_error end it "should return the current resouce" do - @provider.load_current_resource.should eql(@current_resource) + expect(@provider.load_current_resource).to eql(@current_resource) end end describe "install_package" do it "should run zypper install with the package name and version" do - Chef::Config.stub(:[]).with(:zypper_check_gpg).and_return(true) - @provider.should_receive(:shell_out!).with( + allow(Chef::Config).to receive(:[]).with(:zypper_check_gpg).and_return(true) + expect(@provider).to receive(:shell_out!).with( "zypper --non-interactive install --auto-agree-with-licenses emacs=1.0") @provider.install_package("emacs", "1.0") end it "should run zypper install without gpg checks" do - Chef::Config.stub(:[]).with(:zypper_check_gpg).and_return(false) - @provider.should_receive(:shell_out!).with( + allow(Chef::Config).to receive(:[]).with(:zypper_check_gpg).and_return(false) + expect(@provider).to receive(:shell_out!).with( "zypper --non-interactive --no-gpg-checks install "+ "--auto-agree-with-licenses emacs=1.0") @provider.install_package("emacs", "1.0") end it "should warn about gpg checks on zypper install" do - Chef::Log.should_receive(:warn).with( + expect(Chef::Log).to receive(:warn).with( /All packages will be installed without gpg signature checks/) - @provider.should_receive(:shell_out!).with( + expect(@provider).to receive(:shell_out!).with( "zypper --non-interactive --no-gpg-checks install "+ "--auto-agree-with-licenses emacs=1.0") @provider.install_package("emacs", "1.0") @@ -116,28 +116,28 @@ describe Chef::Provider::Package::Zypper do describe "upgrade_package" do it "should run zypper update with the package name and version" do - Chef::Config.stub(:[]).with(:zypper_check_gpg).and_return(true) - @provider.should_receive(:shell_out!).with( + allow(Chef::Config).to receive(:[]).with(:zypper_check_gpg).and_return(true) + expect(@provider).to receive(:shell_out!).with( "zypper --non-interactive install --auto-agree-with-licenses emacs=1.0") @provider.upgrade_package("emacs", "1.0") end it "should run zypper update without gpg checks" do - Chef::Config.stub(:[]).with(:zypper_check_gpg).and_return(false) - @provider.should_receive(:shell_out!).with( + allow(Chef::Config).to receive(:[]).with(:zypper_check_gpg).and_return(false) + expect(@provider).to receive(:shell_out!).with( "zypper --non-interactive --no-gpg-checks install "+ "--auto-agree-with-licenses emacs=1.0") @provider.upgrade_package("emacs", "1.0") end it "should warn about gpg checks on zypper upgrade" do - Chef::Log.should_receive(:warn).with( + expect(Chef::Log).to receive(:warn).with( /All packages will be installed without gpg signature checks/) - @provider.should_receive(:shell_out!).with( + expect(@provider).to receive(:shell_out!).with( "zypper --non-interactive --no-gpg-checks install "+ "--auto-agree-with-licenses emacs=1.0") @provider.upgrade_package("emacs", "1.0") end it "should run zypper upgrade without gpg checks" do - @provider.should_receive(:shell_out!).with( + expect(@provider).to receive(:shell_out!).with( "zypper --non-interactive --no-gpg-checks install "+ "--auto-agree-with-licenses emacs=1.0") @@ -149,8 +149,8 @@ describe Chef::Provider::Package::Zypper do context "when package version is not explicitly specified" do it "should run zypper remove with the package name" do - Chef::Config.stub(:[]).with(:zypper_check_gpg).and_return(true) - @provider.should_receive(:shell_out!).with( + allow(Chef::Config).to receive(:[]).with(:zypper_check_gpg).and_return(true) + expect(@provider).to receive(:shell_out!).with( "zypper --non-interactive remove emacs") @provider.remove_package("emacs", nil) end @@ -158,21 +158,21 @@ describe Chef::Provider::Package::Zypper do context "when package version is explicitly specified" do it "should run zypper remove with the package name" do - Chef::Config.stub(:[]).with(:zypper_check_gpg).and_return(true) - @provider.should_receive(:shell_out!).with( + allow(Chef::Config).to receive(:[]).with(:zypper_check_gpg).and_return(true) + expect(@provider).to receive(:shell_out!).with( "zypper --non-interactive remove emacs=1.0") @provider.remove_package("emacs", "1.0") end it "should run zypper remove without gpg checks" do - Chef::Config.stub(:[]).with(:zypper_check_gpg).and_return(false) - @provider.should_receive(:shell_out!).with( + allow(Chef::Config).to receive(:[]).with(:zypper_check_gpg).and_return(false) + expect(@provider).to receive(:shell_out!).with( "zypper --non-interactive --no-gpg-checks remove emacs=1.0") @provider.remove_package("emacs", "1.0") end it "should warn about gpg checks on zypper remove" do - Chef::Log.should_receive(:warn).with( + expect(Chef::Log).to receive(:warn).with( /All packages will be installed without gpg signature checks/) - @provider.should_receive(:shell_out!).with( + expect(@provider).to receive(:shell_out!).with( "zypper --non-interactive --no-gpg-checks remove emacs=1.0") @provider.remove_package("emacs", "1.0") @@ -182,20 +182,20 @@ describe Chef::Provider::Package::Zypper do describe "purge_package" do it "should run remove_package with the name and version" do - @provider.should_receive(:shell_out!).with( + expect(@provider).to receive(:shell_out!).with( "zypper --non-interactive --no-gpg-checks remove --clean-deps emacs=1.0") @provider.purge_package("emacs", "1.0") end it "should run zypper purge without gpg checks" do - Chef::Config.stub(:[]).with(:zypper_check_gpg).and_return(false) - @provider.should_receive(:shell_out!).with( + allow(Chef::Config).to receive(:[]).with(:zypper_check_gpg).and_return(false) + expect(@provider).to receive(:shell_out!).with( "zypper --non-interactive --no-gpg-checks remove --clean-deps emacs=1.0") @provider.purge_package("emacs", "1.0") end it "should warn about gpg checks on zypper purge" do - Chef::Log.should_receive(:warn).with( + expect(Chef::Log).to receive(:warn).with( /All packages will be installed without gpg signature checks/) - @provider.should_receive(:shell_out!).with( + expect(@provider).to receive(:shell_out!).with( "zypper --non-interactive --no-gpg-checks remove --clean-deps emacs=1.0") @provider.purge_package("emacs", "1.0") end @@ -203,12 +203,12 @@ describe Chef::Provider::Package::Zypper do describe "on an older zypper" do before(:each) do - @provider.stub(:`).and_return("0.11.6") + allow(@provider).to receive(:`).and_return("0.11.6") end describe "install_package" do it "should run zypper install with the package name and version" do - @provider.should_receive(:shell_out!).with( + expect(@provider).to receive(:shell_out!).with( "zypper --no-gpg-checks install --auto-agree-with-licenses -y emacs") @provider.install_package("emacs", "1.0") end @@ -216,7 +216,7 @@ describe Chef::Provider::Package::Zypper do describe "upgrade_package" do it "should run zypper update with the package name and version" do - @provider.should_receive(:shell_out!).with( + expect(@provider).to receive(:shell_out!).with( "zypper --no-gpg-checks install --auto-agree-with-licenses -y emacs") @provider.upgrade_package("emacs", "1.0") end @@ -224,7 +224,7 @@ describe Chef::Provider::Package::Zypper do describe "remove_package" do it "should run zypper remove with the package name" do - @provider.should_receive(:shell_out!).with( + expect(@provider).to receive(:shell_out!).with( "zypper --no-gpg-checks remove -y emacs") @provider.remove_package("emacs", "1.0") end diff --git a/spec/unit/provider/package_spec.rb b/spec/unit/provider/package_spec.rb index 375a0d0646..3a42bcacf6 100644 --- a/spec/unit/provider/package_spec.rb +++ b/spec/unit/provider/package_spec.rb @@ -34,80 +34,80 @@ 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) + allow(@provider).to receive(:install_package).and_return(true) end it "should raise a Chef::Exceptions::Package if no version is specified, and no candidate is available" do @provider.candidate_version = nil - lambda { @provider.run_action(:install) }.should raise_error(Chef::Exceptions::Package) + expect { @provider.run_action(:install) }.to raise_error(Chef::Exceptions::Package) end it "should call preseed_package if a response_file is given" do @new_resource.response_file("foo") - @provider.should_receive(:get_preseed_file).with( + expect(@provider).to receive(:get_preseed_file).with( @new_resource.name, @provider.candidate_version ).and_return("/var/cache/preseed-test") - @provider.should_receive(:preseed_package).with( + expect(@provider).to receive(:preseed_package).with( "/var/cache/preseed-test" ).and_return(true) @provider.run_action(:install) end it "should not call preseed_package if a response_file is not given" do - @provider.should_not_receive(:preseed_package) + expect(@provider).not_to receive(:preseed_package) @provider.run_action(:install) end it "should install the package at the candidate_version if it is not already installed" do - @provider.should_receive(:install_package).with( + expect(@provider).to receive(:install_package).with( @new_resource.name, @provider.candidate_version ).and_return(true) @provider.run_action(:install) - @new_resource.should be_updated_by_last_action + expect(@new_resource).to be_updated_by_last_action end it "should install the package at the version specified if it is not already installed" do @new_resource.version("1.0") - @provider.should_receive(:install_package).with( + expect(@provider).to receive(:install_package).with( @new_resource.name, @new_resource.version ).and_return(true) @provider.run_action(:install) - @new_resource.should be_updated_by_last_action + expect(@new_resource).to be_updated_by_last_action end 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") - @provider.should_receive(:install_package).with( + allow(@current_resource).to receive(:version).and_return("0.99") + expect(@provider).to receive(:install_package).with( @new_resource.name, @new_resource.version ).and_return(true) @provider.run_action(:install) - @new_resource.should be_updated_by_last_action + expect(@new_resource).to be_updated_by_last_action end it "should not install the package if it is already installed and no version is specified" do @current_resource.version("1.0") - @provider.should_not_receive(:install_package) + expect(@provider).not_to receive(:install_package) @provider.run_action(:install) - @new_resource.should_not be_updated_by_last_action + expect(@new_resource).not_to be_updated_by_last_action end it "should not install the package if it is already installed at the version specified" do @current_resource.version("1.0") @new_resource.version("1.0") - @provider.should_not_receive(:install_package) + expect(@provider).not_to receive(:install_package) @provider.run_action(:install) - @new_resource.should_not be_updated_by_last_action + expect(@new_resource).not_to be_updated_by_last_action end 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") + allow(@provider).to receive(:candidate_version).and_return("1.0") @provider.run_action(:install) end @@ -119,220 +119,220 @@ describe Chef::Provider::Package do it "should set the resource to updated if it installs the package" do @provider.run_action(:install) - @new_resource.should be_updated + expect(@new_resource).to be_updated end end describe "when upgrading the package" do before(:each) do - @provider.stub(:upgrade_package).and_return(true) + allow(@provider).to receive(:upgrade_package).and_return(true) end it "should upgrade the package if the current version is not the candidate version" do - @provider.should_receive(:upgrade_package).with( + expect(@provider).to receive(:upgrade_package).with( @new_resource.name, @provider.candidate_version ).and_return(true) @provider.run_action(:upgrade) - @new_resource.should be_updated_by_last_action + expect(@new_resource).to be_updated_by_last_action end it "should set the resource to updated if it installs the package" do @provider.run_action(:upgrade) - @new_resource.should be_updated + expect(@new_resource).to be_updated end it "should not install the package if the current version is the candidate version" do @current_resource.version "1.0" - @provider.should_not_receive(:upgrade_package) + expect(@provider).not_to receive(:upgrade_package) @provider.run_action(:upgrade) - @new_resource.should_not be_updated_by_last_action + expect(@new_resource).not_to be_updated_by_last_action end it "should print the word 'uninstalled' if there was no original version" do - @current_resource.stub(:version).and_return(nil) - Chef::Log.should_receive(:info).with("package[emacs] upgraded from uninstalled to 1.0") + allow(@current_resource).to receive(:version).and_return(nil) + expect(Chef::Log).to receive(:info).with("package[emacs] upgraded from uninstalled to 1.0") @provider.run_action(:upgrade) - @new_resource.should be_updated_by_last_action + expect(@new_resource).to 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) + allow(@current_resource).to receive(:version).and_return(nil) @provider.candidate_version = nil - lambda { @provider.run_action(:upgrade) }.should raise_error(Chef::Exceptions::Package) + expect { @provider.run_action(:upgrade) }.to raise_error(Chef::Exceptions::Package) end it "should not install the package if candidate version is nil" do @current_resource.version "1.0" @provider.candidate_version = nil - @provider.should_not_receive(:upgrade_package) + expect(@provider).not_to receive(:upgrade_package) @provider.run_action(:upgrade) - @new_resource.should_not be_updated_by_last_action + expect(@new_resource).not_to be_updated_by_last_action end end describe "When removing the package" do before(:each) do - @provider.stub(:remove_package).and_return(true) + allow(@provider).to receive(:remove_package).and_return(true) @current_resource.version '1.4.2' end it "should remove the package if it is installed" do - @provider.should be_removing_package - @provider.should_receive(:remove_package).with('emacs', nil) + expect(@provider).to be_removing_package + expect(@provider).to receive(:remove_package).with('emacs', nil) @provider.run_action(:remove) - @new_resource.should be_updated - @new_resource.should be_updated_by_last_action + expect(@new_resource).to be_updated + expect(@new_resource).to be_updated_by_last_action end it "should remove the package at a specific version if it is installed at that version" do @new_resource.version "1.4.2" - @provider.should be_removing_package - @provider.should_receive(:remove_package).with('emacs', '1.4.2') + expect(@provider).to be_removing_package + expect(@provider).to receive(:remove_package).with('emacs', '1.4.2') @provider.run_action(:remove) - @new_resource.should be_updated_by_last_action + expect(@new_resource).to be_updated_by_last_action end it "should not remove the package at a specific version if it is not installed at that version" do @new_resource.version "1.0" - @provider.should_not be_removing_package - @provider.should_not_receive(:remove_package) + expect(@provider).not_to be_removing_package + expect(@provider).not_to receive(:remove_package) @provider.run_action(:remove) - @new_resource.should_not be_updated_by_last_action + expect(@new_resource).not_to be_updated_by_last_action end 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) + expect(@provider).not_to receive(:remove_package) + allow(@current_resource).to receive(:version).and_return(nil) @provider.run_action(:remove) - @new_resource.should_not be_updated_by_last_action + expect(@new_resource).not_to be_updated_by_last_action end it "should set the resource to updated if it removes the package" do @provider.run_action(:remove) - @new_resource.should be_updated + expect(@new_resource).to be_updated end end describe "When purging the package" do before(:each) do - @provider.stub(:purge_package).and_return(true) + allow(@provider).to receive(:purge_package).and_return(true) @current_resource.version '1.4.2' end it "should purge the package if it is installed" do - @provider.should be_removing_package - @provider.should_receive(:purge_package).with('emacs', nil) + expect(@provider).to be_removing_package + expect(@provider).to receive(:purge_package).with('emacs', nil) @provider.run_action(:purge) - @new_resource.should be_updated - @new_resource.should be_updated_by_last_action + expect(@new_resource).to be_updated + expect(@new_resource).to be_updated_by_last_action end it "should purge the package at a specific version if it is installed at that version" do @new_resource.version "1.4.2" - @provider.should be_removing_package - @provider.should_receive(:purge_package).with('emacs', '1.4.2') + expect(@provider).to be_removing_package + expect(@provider).to receive(:purge_package).with('emacs', '1.4.2') @provider.run_action(:purge) - @new_resource.should be_updated_by_last_action + expect(@new_resource).to be_updated_by_last_action end it "should not purge the package at a specific version if it is not installed at that version" do @new_resource.version "1.0" - @provider.should_not be_removing_package - @provider.should_not_receive(:purge_package) + expect(@provider).not_to be_removing_package + expect(@provider).not_to receive(:purge_package) @provider.run_action(:purge) - @new_resource.should_not be_updated_by_last_action + expect(@new_resource).not_to be_updated_by_last_action end it "should not purge the package if it is not installed" do @current_resource.instance_variable_set(:@version, nil) - @provider.should_not be_removing_package + expect(@provider).not_to be_removing_package - @provider.should_not_receive(:purge_package) + expect(@provider).not_to receive(:purge_package) @provider.run_action(:purge) - @new_resource.should_not be_updated_by_last_action + expect(@new_resource).not_to be_updated_by_last_action end it "should set the resource to updated if it purges the package" do @provider.run_action(:purge) - @new_resource.should be_updated + expect(@new_resource).to be_updated end end describe "when reconfiguring the package" do before(:each) do - @provider.stub(:reconfig_package).and_return(true) + allow(@provider).to receive(: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) - @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) - Chef::Log.should_receive(:info).with("package[emacs] reconfigured") - @provider.should_receive(:reconfig_package) + allow(@current_resource).to receive(:version).and_return('1.0') + allow(@new_resource).to receive(:response_file).and_return(true) + expect(@provider).to receive(:get_preseed_file).and_return('/var/cache/preseed-test') + allow(@provider).to receive(:preseed_package).and_return(true) + allow(@provider).to receive(:reconfig_package).and_return(true) + expect(Chef::Log).to receive(:info).with("package[emacs] reconfigured") + expect(@provider).to receive(:reconfig_package) @provider.run_action(:reconfig) - @new_resource.should be_updated - @new_resource.should be_updated_by_last_action + expect(@new_resource).to be_updated + expect(@new_resource).to be_updated_by_last_action end it "should debug log and not reconfigure the package if the package is not installed" do - @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) + allow(@current_resource).to receive(:version).and_return(nil) + expect(Chef::Log).to receive(:debug).with("package[emacs] is NOT installed - nothing to do") + expect(@provider).not_to receive(:reconfig_package) @provider.run_action(:reconfig) - @new_resource.should_not be_updated_by_last_action + expect(@new_resource).not_to be_updated_by_last_action 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) - Chef::Log.should_receive(:debug).with("package[emacs] no response_file provided - nothing to do") - @provider.should_not_receive(:reconfig_package) + allow(@current_resource).to receive(:version).and_return('1.0') + allow(@new_resource).to receive(:response_file).and_return(nil) + expect(Chef::Log).to receive(:debug).with("package[emacs] no response_file provided - nothing to do") + expect(@provider).not_to receive(:reconfig_package) @provider.run_action(:reconfig) - @new_resource.should_not be_updated_by_last_action + expect(@new_resource).not_to be_updated_by_last_action 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) - @provider.should_receive(:get_preseed_file).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) + allow(@current_resource).to receive(:version).and_return('1.0') + allow(@new_resource).to receive(:response_file).and_return(true) + expect(@provider).to receive(:get_preseed_file).and_return(false) + allow(@provider).to receive(:preseed_package).and_return(false) + expect(Chef::Log).to receive(:debug).with("package[emacs] preseeding has not changed - nothing to do") + expect(@provider).not_to receive(:reconfig_package) @provider.run_action(:reconfig) - @new_resource.should_not be_updated_by_last_action + expect(@new_resource).not_to be_updated_by_last_action end end describe "when running commands to be implemented by subclasses" do it "should raises UnsupportedAction for install" do - lambda { @provider.install_package('emacs', '1.4.2') }.should raise_error(Chef::Exceptions::UnsupportedAction) + expect { @provider.install_package('emacs', '1.4.2') }.to raise_error(Chef::Exceptions::UnsupportedAction) end it "should raises UnsupportedAction for upgrade" do - lambda { @provider.upgrade_package('emacs', '1.4.2') }.should raise_error(Chef::Exceptions::UnsupportedAction) + expect { @provider.upgrade_package('emacs', '1.4.2') }.to raise_error(Chef::Exceptions::UnsupportedAction) end it "should raises UnsupportedAction for remove" do - lambda { @provider.remove_package('emacs', '1.4.2') }.should raise_error(Chef::Exceptions::UnsupportedAction) + expect { @provider.remove_package('emacs', '1.4.2') }.to raise_error(Chef::Exceptions::UnsupportedAction) end it "should raises UnsupportedAction for purge" do - lambda { @provider.purge_package('emacs', '1.4.2') }.should raise_error(Chef::Exceptions::UnsupportedAction) + expect { @provider.purge_package('emacs', '1.4.2') }.to raise_error(Chef::Exceptions::UnsupportedAction) end it "should raise UnsupportedAction for preseed_package" do preseed_file = "/tmp/sun-jdk-package-preseed-file.seed" - lambda { @provider.preseed_package(preseed_file) }.should raise_error(Chef::Exceptions::UnsupportedAction) + expect { @provider.preseed_package(preseed_file) }.to raise_error(Chef::Exceptions::UnsupportedAction) end it "should raise UnsupportedAction for reconfig" do - lambda { @provider.reconfig_package('emacs', '1.4.2') }.should raise_error(Chef::Exceptions::UnsupportedAction) + expect { @provider.reconfig_package('emacs', '1.4.2') }.to raise_error(Chef::Exceptions::UnsupportedAction) end end @@ -358,29 +358,29 @@ describe Chef::Provider::Package do describe "creating the cookbook file resource to fetch the response file" do before do - Chef::FileCache.should_receive(:create_cache_path).with('preseed/java').and_return("/tmp/preseed/java") + expect(Chef::FileCache).to receive(:create_cache_path).with('preseed/java').and_return("/tmp/preseed/java") 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") - @provider.preseed_resource('java', '6').run_context.should_not be_nil - @provider.preseed_resource('java', '6').run_context.should equal(@provider.run_context) + allow(Chef::FileCache).to receive(:create_cache_path).and_return("/tmp/preseed/java") + expect(@provider.preseed_resource('java', '6').run_context).not_to be_nil + expect(@provider.preseed_resource('java', '6').run_context).to equal(@provider.run_context) end it "should set the cookbook name of the remote file to the new resources cookbook name" do - @provider.preseed_resource('java', '6').cookbook_name.should == 'java' + expect(@provider.preseed_resource('java', '6').cookbook_name).to eq('java') end it "should set remote files source to the new resources response file" do - @provider.preseed_resource('java', '6').source.should == 'java.response' + expect(@provider.preseed_resource('java', '6').source).to eq('java.response') end it "should never back up the cached response file" do - @provider.preseed_resource('java', '6').backup.should be_false + expect(@provider.preseed_resource('java', '6').backup).to be_false end it "sets the install path of the resource to $file_cache/$cookbook/$pkg_name-$pkg_version.seed" do - @provider.preseed_resource('java', '6').path.should == '/tmp/preseed/java/java-6.seed' + expect(@provider.preseed_resource('java', '6').path).to eq('/tmp/preseed/java/java-6.seed') end end @@ -397,7 +397,7 @@ describe Chef::Provider::Package do @response_file_resource.source('java.response') - @provider.should_receive(:preseed_resource).with('java', '6').and_return(@response_file_resource) + expect(@provider).to receive(:preseed_resource).with('java', '6').and_return(@response_file_resource) end after do @@ -405,20 +405,20 @@ describe Chef::Provider::Package do end it "creates the preseed file in the cache" do - @response_file_resource.should_receive(:run_action).with(:create) + expect(@response_file_resource).to receive(:run_action).with(:create) @provider.get_preseed_file("java", "6") end it "returns the path to the response file if the response file was updated" do - @provider.get_preseed_file("java", "6").should == @response_file_destination + expect(@provider.get_preseed_file("java", "6")).to eq(@response_file_destination) end it "should return false if the response file has not been updated" do @response_file_resource.updated_by_last_action(false) - @response_file_resource.should_not be_updated_by_last_action + expect(@response_file_resource).not_to be_updated_by_last_action # don't let the response_file_resource set updated to true - @response_file_resource.should_receive(:run_action).with(:create) - @provider.get_preseed_file("java", "6").should be(false) + expect(@response_file_resource).to receive(:run_action).with(:create) + expect(@provider.get_preseed_file("java", "6")).to be(false) end end diff --git a/spec/unit/provider/powershell_spec.rb b/spec/unit/provider/powershell_spec.rb index 33c402836b..60dbcf80b0 100644 --- a/spec/unit/provider/powershell_spec.rb +++ b/spec/unit/provider/powershell_spec.rb @@ -32,7 +32,7 @@ describe Chef::Provider::PowershellScript, "action_run" do end it "should set the -File flag as the last flag" do - @provider.flags.split(' ').pop.should == "-File" + expect(@provider.flags.split(' ').pop).to eq("-File") end end diff --git a/spec/unit/provider/registry_key_spec.rb b/spec/unit/provider/registry_key_spec.rb index 2cfbcf98f1..79811fdab8 100644 --- a/spec/unit/provider/registry_key_spec.rb +++ b/spec/unit/provider/registry_key_spec.rb @@ -31,9 +31,9 @@ shared_examples_for "a registry key" do @provider = Chef::Provider::RegistryKey.new(@new_resource, @run_context) - @provider.stub(:running_on_windows!).and_return(true) + allow(@provider).to receive(:running_on_windows!).and_return(true) @double_registry = double(Chef::Win32::Registry) - @provider.stub(:registry).and_return(@double_registry) + allow(@provider).to receive(:registry).and_return(@double_registry) end describe "when first created" do @@ -42,36 +42,36 @@ shared_examples_for "a registry key" do describe "executing load_current_resource" do describe "when the key exists" do before(:each) do - @double_registry.should_receive(:key_exists?).with(keyname).and_return(true) - @double_registry.should_receive(:get_values).with(keyname).and_return( testval2 ) + expect(@double_registry).to receive(:key_exists?).with(keyname).and_return(true) + expect(@double_registry).to receive(:get_values).with(keyname).and_return( testval2 ) @provider.load_current_resource end it "should set the key of the current resource to the key of the new resource" do - @provider.current_resource.key.should == @new_resource.key + expect(@provider.current_resource.key).to eq(@new_resource.key) end it "should set the architecture of the current resource to the architecture of the new resource" do - @provider.current_resource.architecture.should == @new_resource.architecture + expect(@provider.current_resource.architecture).to eq(@new_resource.architecture) end it "should set the recursive flag of the current resource to the recursive flag of the new resource" do - @provider.current_resource.recursive.should == @new_resource.recursive + expect(@provider.current_resource.recursive).to eq(@new_resource.recursive) end it "should set the unscrubbed values of the current resource to the values it got from the registry" do - @provider.current_resource.unscrubbed_values.should == [ testval2 ] + expect(@provider.current_resource.unscrubbed_values).to eq([ testval2 ]) end end describe "when the key does not exist" do before(:each) do - @double_registry.should_receive(:key_exists?).with(keyname).and_return(false) + expect(@double_registry).to receive(:key_exists?).with(keyname).and_return(false) @provider.load_current_resource end it "should set the values in the current resource to empty array" do - @provider.current_resource.values.should == [] + expect(@provider.current_resource.values).to eq([]) end end end @@ -79,29 +79,29 @@ shared_examples_for "a registry key" do describe "action_create" do context "when the key exists" do before(:each) do - @double_registry.should_receive(:key_exists?).twice.with(keyname).and_return(true) + expect(@double_registry).to receive(:key_exists?).twice.with(keyname).and_return(true) end it "should do nothing if the key and the value both exist" do - @double_registry.should_receive(:get_values).with(keyname).and_return( testval1 ) - @double_registry.should_not_receive(:set_value) + expect(@double_registry).to receive(:get_values).with(keyname).and_return( testval1 ) + expect(@double_registry).not_to receive(:set_value) @provider.load_current_resource @provider.action_create end it "should create the value if the key exists but the value does not" do - @double_registry.should_receive(:get_values).with(keyname).and_return( testval2 ) - @double_registry.should_receive(:set_value).with(keyname, testval1) + expect(@double_registry).to receive(:get_values).with(keyname).and_return( testval2 ) + expect(@double_registry).to receive(:set_value).with(keyname, testval1) @provider.load_current_resource @provider.action_create end it "should set the value if the key exists but the data does not match" do - @double_registry.should_receive(:get_values).with(keyname).and_return( testval1_wrong_data ) - @double_registry.should_receive(:set_value).with(keyname, testval1) + expect(@double_registry).to receive(:get_values).with(keyname).and_return( testval1_wrong_data ) + expect(@double_registry).to receive(:set_value).with(keyname, testval1) @provider.load_current_resource @provider.action_create end it "should set the value if the key exists but the type does not match" do - @double_registry.should_receive(:get_values).with(keyname).and_return( testval1_wrong_type ) - @double_registry.should_receive(:set_value).with(keyname, testval1) + expect(@double_registry).to receive(:get_values).with(keyname).and_return( testval1_wrong_type ) + expect(@double_registry).to receive(:set_value).with(keyname, testval1) @provider.load_current_resource @provider.action_create end @@ -109,30 +109,30 @@ shared_examples_for "a registry key" do context "when the key exists and the values in the new resource are empty" do it "when a value is in the key, it should do nothing" do @provider.new_resource.values([]) - @double_registry.should_receive(:key_exists?).twice.with(keyname).and_return(true) - @double_registry.should_receive(:get_values).with(keyname).and_return( testval1 ) - @double_registry.should_not_receive(:create_key) - @double_registry.should_not_receive(:set_value) + expect(@double_registry).to receive(:key_exists?).twice.with(keyname).and_return(true) + expect(@double_registry).to receive(:get_values).with(keyname).and_return( testval1 ) + expect(@double_registry).not_to receive(:create_key) + expect(@double_registry).not_to receive(:set_value) @provider.load_current_resource @provider.action_create end it "when no value is in the key, it should do nothing" do @provider.new_resource.values([]) - @double_registry.should_receive(:key_exists?).twice.with(keyname).and_return(true) - @double_registry.should_receive(:get_values).with(keyname).and_return( nil ) - @double_registry.should_not_receive(:create_key) - @double_registry.should_not_receive(:set_value) + expect(@double_registry).to receive(:key_exists?).twice.with(keyname).and_return(true) + expect(@double_registry).to receive(:get_values).with(keyname).and_return( nil ) + expect(@double_registry).not_to receive(:create_key) + expect(@double_registry).not_to receive(:set_value) @provider.load_current_resource @provider.action_create end end context "when the key does not exist" do before(:each) do - @double_registry.should_receive(:key_exists?).twice.with(keyname).and_return(false) + expect(@double_registry).to receive(:key_exists?).twice.with(keyname).and_return(false) end it "should create the key and the value" do - @double_registry.should_receive(:create_key).with(keyname, false) - @double_registry.should_receive(:set_value).with(keyname, testval1) + expect(@double_registry).to receive(:create_key).with(keyname, false) + expect(@double_registry).to receive(:set_value).with(keyname, testval1) @provider.load_current_resource @provider.action_create end @@ -140,9 +140,9 @@ shared_examples_for "a registry key" do context "when the key does not exist and the values in the new resource are empty" do it "should create the key" do @new_resource.values([]) - @double_registry.should_receive(:key_exists?).twice.with(keyname).and_return(false) - @double_registry.should_receive(:create_key).with(keyname, false) - @double_registry.should_not_receive(:set_value) + expect(@double_registry).to receive(:key_exists?).twice.with(keyname).and_return(false) + expect(@double_registry).to receive(:create_key).with(keyname, false) + expect(@double_registry).not_to receive(:set_value) @provider.load_current_resource @provider.action_create end @@ -152,40 +152,40 @@ shared_examples_for "a registry key" do describe "action_create_if_missing" do context "when the key exists" do before(:each) do - @double_registry.should_receive(:key_exists?).twice.with(keyname).and_return(true) + expect(@double_registry).to receive(:key_exists?).twice.with(keyname).and_return(true) end it "should do nothing if the key and the value both exist" do - @double_registry.should_receive(:get_values).with(keyname).and_return( testval1 ) - @double_registry.should_not_receive(:set_value) + expect(@double_registry).to receive(:get_values).with(keyname).and_return( testval1 ) + expect(@double_registry).not_to receive(:set_value) @provider.load_current_resource @provider.action_create_if_missing end it "should create the value if the key exists but the value does not" do - @double_registry.should_receive(:get_values).with(keyname).and_return( testval2 ) - @double_registry.should_receive(:set_value).with(keyname, testval1) + expect(@double_registry).to receive(:get_values).with(keyname).and_return( testval2 ) + expect(@double_registry).to receive(:set_value).with(keyname, testval1) @provider.load_current_resource @provider.action_create_if_missing end it "should not set the value if the key exists but the data does not match" do - @double_registry.should_receive(:get_values).with(keyname).and_return( testval1_wrong_data ) - @double_registry.should_not_receive(:set_value) + expect(@double_registry).to receive(:get_values).with(keyname).and_return( testval1_wrong_data ) + expect(@double_registry).not_to receive(:set_value) @provider.load_current_resource @provider.action_create_if_missing end it "should not set the value if the key exists but the type does not match" do - @double_registry.should_receive(:get_values).with(keyname).and_return( testval1_wrong_type ) - @double_registry.should_not_receive(:set_value) + expect(@double_registry).to receive(:get_values).with(keyname).and_return( testval1_wrong_type ) + expect(@double_registry).not_to receive(:set_value) @provider.load_current_resource @provider.action_create_if_missing end end context "when the key does not exist" do before(:each) do - @double_registry.should_receive(:key_exists?).twice.with(keyname).and_return(false) + expect(@double_registry).to receive(:key_exists?).twice.with(keyname).and_return(false) end it "should create the key and the value" do - @double_registry.should_receive(:create_key).with(keyname, false) - @double_registry.should_receive(:set_value).with(keyname, testval1) + expect(@double_registry).to receive(:create_key).with(keyname, false) + expect(@double_registry).to receive(:set_value).with(keyname, testval1) @provider.load_current_resource @provider.action_create_if_missing end @@ -195,39 +195,39 @@ shared_examples_for "a registry key" do describe "action_delete" do context "when the key exists" do before(:each) do - @double_registry.should_receive(:key_exists?).twice.with(keyname).and_return(true) + expect(@double_registry).to receive(:key_exists?).twice.with(keyname).and_return(true) end it "deletes the value when the value exists" do - @double_registry.should_receive(:get_values).with(keyname).and_return( testval1 ) - @double_registry.should_receive(:delete_value).with(keyname, testval1) + expect(@double_registry).to receive(:get_values).with(keyname).and_return( testval1 ) + expect(@double_registry).to receive(:delete_value).with(keyname, testval1) @provider.load_current_resource @provider.action_delete end it "deletes the value when the value exists, but the type is wrong" do - @double_registry.should_receive(:get_values).with(keyname).and_return( testval1_wrong_type ) - @double_registry.should_receive(:delete_value).with(keyname, testval1) + expect(@double_registry).to receive(:get_values).with(keyname).and_return( testval1_wrong_type ) + expect(@double_registry).to receive(:delete_value).with(keyname, testval1) @provider.load_current_resource @provider.action_delete end it "deletes the value when the value exists, but the data is wrong" do - @double_registry.should_receive(:get_values).with(keyname).and_return( testval1_wrong_data ) - @double_registry.should_receive(:delete_value).with(keyname, testval1) + expect(@double_registry).to receive(:get_values).with(keyname).and_return( testval1_wrong_data ) + expect(@double_registry).to receive(:delete_value).with(keyname, testval1) @provider.load_current_resource @provider.action_delete end it "does not delete the value when the value does not exist" do - @double_registry.should_receive(:get_values).with(keyname).and_return( testval2 ) - @double_registry.should_not_receive(:delete_value) + expect(@double_registry).to receive(:get_values).with(keyname).and_return( testval2 ) + expect(@double_registry).not_to receive(:delete_value) @provider.load_current_resource @provider.action_delete end end context "when the key does not exist" do before(:each) do - @double_registry.should_receive(:key_exists?).twice.with(keyname).and_return(false) + expect(@double_registry).to receive(:key_exists?).twice.with(keyname).and_return(false) end it "does nothing" do - @double_registry.should_not_receive(:delete_value) + expect(@double_registry).not_to receive(:delete_value) @provider.load_current_resource @provider.action_delete end @@ -237,21 +237,21 @@ shared_examples_for "a registry key" do describe "action_delete_key" do context "when the key exists" do before(:each) do - @double_registry.should_receive(:key_exists?).twice.with(keyname).and_return(true) + expect(@double_registry).to receive(:key_exists?).twice.with(keyname).and_return(true) end it "deletes the key" do - @double_registry.should_receive(:get_values).with(keyname).and_return( testval1 ) - @double_registry.should_receive(:delete_key).with(keyname, false) + expect(@double_registry).to receive(:get_values).with(keyname).and_return( testval1 ) + expect(@double_registry).to receive(:delete_key).with(keyname, false) @provider.load_current_resource @provider.action_delete_key end end context "when the key does not exist" do before(:each) do - @double_registry.should_receive(:key_exists?).twice.with(keyname).and_return(false) + expect(@double_registry).to receive(:key_exists?).twice.with(keyname).and_return(false) end it "does nothing" do - @double_registry.should_not_receive(:delete_key) + expect(@double_registry).not_to receive(:delete_key) @provider.load_current_resource @provider.action_delete_key end diff --git a/spec/unit/provider/remote_directory_spec.rb b/spec/unit/provider/remote_directory_spec.rb index b986e2c8ad..a2f5092f57 100644 --- a/spec/unit/provider/remote_directory_spec.rb +++ b/spec/unit/provider/remote_directory_spec.rb @@ -27,7 +27,7 @@ end describe Chef::Provider::RemoteDirectory do before do - Chef::FileAccessControl.any_instance.stub(:set_all) + allow_any_instance_of(Chef::FileAccessControl).to receive(:set_all) @resource = Chef::Resource::RemoteDirectory.new(File.join(Dir.tmpdir, "tafty")) # in CHEF_SPEC_DATA/cookbooks/openldap/files/default/remotedir @@ -80,11 +80,11 @@ describe Chef::Provider::RemoteDirectory do it "configures access control on intermediate directorys" do directory_resource = @provider.send(:resource_for_directory, File.join(Dir.tmpdir, "intermediate_dir")) - directory_resource.path.should == File.join(Dir.tmpdir, "intermediate_dir") - directory_resource.mode.should == "0750" - directory_resource.group.should == "wheel" - directory_resource.owner.should == "root" - directory_resource.recursive.should be_true + expect(directory_resource.path).to eq(File.join(Dir.tmpdir, "intermediate_dir")) + expect(directory_resource.mode).to eq("0750") + expect(directory_resource.group).to eq("wheel") + expect(directory_resource.owner).to eq("root") + expect(directory_resource.recursive).to be_true end it "configures access control on files in the directory" do @@ -92,12 +92,12 @@ describe Chef::Provider::RemoteDirectory do cookbook_file = @provider.send(:cookbook_file_resource, "/target/destination/path.txt", "relative/source/path.txt") - cookbook_file.cookbook_name.should == "berlin_style_tasty_cupcakes" - cookbook_file.source.should == "remotedir_root/relative/source/path.txt" - cookbook_file.mode.should == "0640" - cookbook_file.group.should == "staff" - cookbook_file.owner.should == "toor" - cookbook_file.backup.should == 23 + expect(cookbook_file.cookbook_name).to eq("berlin_style_tasty_cupcakes") + expect(cookbook_file.source).to eq("remotedir_root/relative/source/path.txt") + expect(cookbook_file.mode).to eq("0640") + expect(cookbook_file.group).to eq("staff") + expect(cookbook_file.owner).to eq("toor") + expect(cookbook_file.backup).to eq(23) end end @@ -116,17 +116,17 @@ describe Chef::Provider::RemoteDirectory do it "creates the toplevel directory without error " do @resource.recursive(false) @provider.run_action(:create) - ::File.exist?(@destination_dir).should be_true + expect(::File.exist?(@destination_dir)).to be_true end it "transfers the directory with all contents" do @provider.run_action(:create) - ::File.exist?(@destination_dir + '/remote_dir_file1.txt').should be_true - ::File.exist?(@destination_dir + '/remote_dir_file2.txt').should be_true - ::File.exist?(@destination_dir + '/remotesubdir/remote_subdir_file1.txt').should be_true - ::File.exist?(@destination_dir + '/remotesubdir/remote_subdir_file2.txt').should be_true - ::File.exist?(@destination_dir + '/remotesubdir/.a_dotfile').should be_true - ::File.exist?(@destination_dir + '/.a_dotdir/.a_dotfile_in_a_dotdir').should be_true + expect(::File.exist?(@destination_dir + '/remote_dir_file1.txt')).to be_true + expect(::File.exist?(@destination_dir + '/remote_dir_file2.txt')).to be_true + expect(::File.exist?(@destination_dir + '/remotesubdir/remote_subdir_file1.txt')).to be_true + expect(::File.exist?(@destination_dir + '/remotesubdir/remote_subdir_file2.txt')).to be_true + expect(::File.exist?(@destination_dir + '/remotesubdir/.a_dotfile')).to be_true + expect(::File.exist?(@destination_dir + '/.a_dotdir/.a_dotfile_in_a_dotdir')).to be_true end describe "only if it is missing" do @@ -141,8 +141,8 @@ describe Chef::Provider::RemoteDirectory do @provider.run_action(:create_if_missing) - file1md5.eql?(Digest::MD5.hexdigest(File.read(@destination_dir + '/remote_dir_file1.txt'))).should be_true - subdirfile1md5.eql?(Digest::MD5.hexdigest(File.read(@destination_dir + '/remotesubdir/remote_subdir_file1.txt'))).should be_true + expect(file1md5.eql?(Digest::MD5.hexdigest(File.read(@destination_dir + '/remote_dir_file1.txt')))).to be_true + expect(subdirfile1md5.eql?(Digest::MD5.hexdigest(File.read(@destination_dir + '/remotesubdir/remote_subdir_file1.txt')))).to be_true end end @@ -155,13 +155,13 @@ describe Chef::Provider::RemoteDirectory do FileUtils.touch(@destination_dir + '/remotesubdir/marked_for_death_again.txt') @provider.run_action(:create) - ::File.exist?(@destination_dir + '/remote_dir_file1.txt').should be_true - ::File.exist?(@destination_dir + '/remote_dir_file2.txt').should be_true - ::File.exist?(@destination_dir + '/remotesubdir/remote_subdir_file1.txt').should be_true - ::File.exist?(@destination_dir + '/remotesubdir/remote_subdir_file2.txt').should be_true + expect(::File.exist?(@destination_dir + '/remote_dir_file1.txt')).to be_true + expect(::File.exist?(@destination_dir + '/remote_dir_file2.txt')).to be_true + expect(::File.exist?(@destination_dir + '/remotesubdir/remote_subdir_file1.txt')).to be_true + expect(::File.exist?(@destination_dir + '/remotesubdir/remote_subdir_file2.txt')).to be_true - ::File.exist?(@destination_dir + '/marked_for_death.txt').should be_false - ::File.exist?(@destination_dir + '/remotesubdir/marked_for_death_again.txt').should be_false + expect(::File.exist?(@destination_dir + '/marked_for_death.txt')).to be_false + expect(::File.exist?(@destination_dir + '/remotesubdir/marked_for_death_again.txt')).to be_false end it "removes files in subdirectories before files above" do @@ -172,10 +172,10 @@ describe Chef::Provider::RemoteDirectory do FileUtils.touch(@destination_dir + '/a/multiply/nested/baz.txt') FileUtils.touch(@destination_dir + '/a/multiply/nested/directory/qux.txt') @provider.run_action(:create) - ::File.exist?(@destination_dir + '/a/foo.txt').should be_false - ::File.exist?(@destination_dir + '/a/multiply/bar.txt').should be_false - ::File.exist?(@destination_dir + '/a/multiply/nested/baz.txt').should be_false - ::File.exist?(@destination_dir + '/a/multiply/nested/directory/qux.txt').should be_false + expect(::File.exist?(@destination_dir + '/a/foo.txt')).to be_false + expect(::File.exist?(@destination_dir + '/a/multiply/bar.txt')).to be_false + expect(::File.exist?(@destination_dir + '/a/multiply/nested/baz.txt')).to be_false + expect(::File.exist?(@destination_dir + '/a/multiply/nested/directory/qux.txt')).to be_false end it "removes directory symlinks properly", :not_supported_on_win2k3 do @@ -188,12 +188,12 @@ describe Chef::Provider::RemoteDirectory do Dir.mktmpdir do |tmp_dir| begin @fclass.file_class.symlink(tmp_dir.dup, symlinked_dir_path) - ::File.exist?(symlinked_dir_path).should be_true + expect(::File.exist?(symlinked_dir_path)).to be_true @provider.run_action - ::File.exist?(symlinked_dir_path).should be_false - ::File.exist?(tmp_dir).should be_true + expect(::File.exist?(symlinked_dir_path)).to be_false + expect(::File.exist?(tmp_dir)).to be_true rescue Chef::Exceptions::Win32APIError => e pending "This must be run as an Administrator to create symlinks" end @@ -212,8 +212,8 @@ describe Chef::Provider::RemoteDirectory do file1md5 = Digest::MD5.hexdigest(::File.read(@destination_dir + '/remote_dir_file1.txt')) subdirfile1md5 = Digest::MD5.hexdigest(::File.read(@destination_dir + '/remotesubdir/remote_subdir_file1.txt')) @provider.run_action(:create) - file1md5.eql?(Digest::MD5.hexdigest(::File.read(@destination_dir + '/remote_dir_file1.txt'))).should be_true - subdirfile1md5.eql?(Digest::MD5.hexdigest(::File.read(@destination_dir + '/remotesubdir/remote_subdir_file1.txt'))).should be_true + expect(file1md5.eql?(Digest::MD5.hexdigest(::File.read(@destination_dir + '/remote_dir_file1.txt')))).to be_true + expect(subdirfile1md5.eql?(Digest::MD5.hexdigest(::File.read(@destination_dir + '/remotesubdir/remote_subdir_file1.txt')))).to be_true end end diff --git a/spec/unit/provider/remote_file/cache_control_data_spec.rb b/spec/unit/provider/remote_file/cache_control_data_spec.rb index 8a849d9d7d..11f2af3edc 100644 --- a/spec/unit/provider/remote_file/cache_control_data_spec.rb +++ b/spec/unit/provider/remote_file/cache_control_data_spec.rb @@ -44,21 +44,21 @@ describe Chef::Provider::RemoteFile::CacheControlData do context "when loading data for an unknown URI" do before do - Chef::FileCache.should_receive(:load).with(cache_path).and_raise(Chef::Exceptions::FileNotFound, "nope") + expect(Chef::FileCache).to receive(:load).with(cache_path).and_raise(Chef::Exceptions::FileNotFound, "nope") end context "and there is no current copy of the file" do let(:current_file_checksum) { nil } it "returns empty cache control data" do - cache_control_data.etag.should be_nil - cache_control_data.mtime.should be_nil + expect(cache_control_data.etag).to be_nil + expect(cache_control_data.mtime).to be_nil end end it "returns empty cache control data" do - cache_control_data.etag.should be_nil - cache_control_data.mtime.should be_nil + expect(cache_control_data.etag).to be_nil + expect(cache_control_data.mtime).to be_nil end context "and the URI contains a password" do @@ -89,15 +89,15 @@ describe Chef::Provider::RemoteFile::CacheControlData do end before do - Chef::FileCache.should_receive(:load).with(cache_path).and_return(cache_json_data) + expect(Chef::FileCache).to receive(:load).with(cache_path).and_return(cache_json_data) end context "and there is no on-disk copy of the file" do let(:current_file_checksum) { nil } it "returns empty cache control data" do - cache_control_data.etag.should be_nil - cache_control_data.mtime.should be_nil + expect(cache_control_data.etag).to be_nil + expect(cache_control_data.mtime).to be_nil end end @@ -105,16 +105,16 @@ describe Chef::Provider::RemoteFile::CacheControlData do let(:current_file_checksum) { "e2a8938cc31754f6c067b35aab1d0d4864272e9bf8504536ef3e79ebf8432305" } it "returns empty cache control data" do - cache_control_data.etag.should be_nil - cache_control_data.mtime.should be_nil + expect(cache_control_data.etag).to be_nil + expect(cache_control_data.mtime).to be_nil end end context "and the cached checksum matches the on-disk copy" do it "populates the cache control data" do - cache_control_data.etag.should == etag - cache_control_data.mtime.should == mtime + expect(cache_control_data.etag).to eq(etag) + expect(cache_control_data.mtime).to eq(mtime) end end @@ -122,16 +122,16 @@ describe Chef::Provider::RemoteFile::CacheControlData do let(:cache_json_data) { '{"foo",,"bar" []}' } it "returns empty cache control data" do - cache_control_data.etag.should be_nil - cache_control_data.mtime.should be_nil + expect(cache_control_data.etag).to be_nil + expect(cache_control_data.mtime).to be_nil end context "and it still is valid JSON" do let(:cache_json_data) { '' } it "returns empty cache control data" do - cache_control_data.etag.should be_nil - cache_control_data.mtime.should be_nil + expect(cache_control_data.etag).to be_nil + expect(cache_control_data.mtime).to be_nil end end end @@ -162,12 +162,12 @@ describe Chef::Provider::RemoteFile::CacheControlData do # so we can't count on the order of the keys in the json format. json_data = cache_control_data.json_data - Chef::JSONCompat.from_json(json_data).should == expected_serialization_data + expect(Chef::JSONCompat.from_json(json_data)).to eq(expected_serialization_data) end it "writes data to the cache" do json_data = cache_control_data.json_data - Chef::FileCache.should_receive(:store).with(cache_path, json_data) + expect(Chef::FileCache).to receive(:store).with(cache_path, json_data) cache_control_data.save end @@ -178,7 +178,7 @@ describe Chef::Provider::RemoteFile::CacheControlData do it "writes the data to the cache with a sanitized path name" do json_data = cache_control_data.json_data - Chef::FileCache.should_receive(:store).with(cache_path, json_data) + expect(Chef::FileCache).to receive(:store).with(cache_path, json_data) cache_control_data.save end end @@ -199,18 +199,18 @@ describe Chef::Provider::RemoteFile::CacheControlData do it "truncates the file cache path to 102 characters" do normalized_cache_path = cache_control_data.send('sanitized_cache_file_basename') - Chef::FileCache.should_receive(:store).with("remote_file/" + normalized_cache_path, cache_control_data.json_data) + expect(Chef::FileCache).to receive(:store).with("remote_file/" + normalized_cache_path, cache_control_data.json_data) cache_control_data.save - normalized_cache_path.length.should == CACHE_FILE_PATH_LIMIT + expect(normalized_cache_path.length).to eq(CACHE_FILE_PATH_LIMIT) end it "uses a file cache path that starts with the first #{CACHE_FILE_TRUNCATED_FRIENDLY_FILE_NAME_LENGTH} characters of the URI" do normalized_cache_path = cache_control_data.send('sanitized_cache_file_basename') - truncated_file_cache_path.length.should == CACHE_FILE_TRUNCATED_FRIENDLY_FILE_NAME_LENGTH - normalized_cache_path.start_with?(truncated_file_cache_path).should == true + expect(truncated_file_cache_path.length).to eq(CACHE_FILE_TRUNCATED_FRIENDLY_FILE_NAME_LENGTH) + expect(normalized_cache_path.start_with?(truncated_file_cache_path)).to eq(true) end end diff --git a/spec/unit/provider/remote_file/content_spec.rb b/spec/unit/provider/remote_file/content_spec.rb index 4ee33aeefb..ce18d23a09 100644 --- a/spec/unit/provider/remote_file/content_spec.rb +++ b/spec/unit/provider/remote_file/content_spec.rb @@ -47,31 +47,31 @@ 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") + allow(new_resource).to receive(:checksum).and_return("0fd012fdc96e96f8f7cf2046522a54aed0ce470224513e45da6bc1a17a4924aa") + allow(current_resource).to receive(:checksum).and_return("0fd012fdc96e96f8f7cf2046522a54aed0ce470224513e45da6bc1a17a4924aa") end it "should return nil for the tempfile" do - content.tempfile.should be_nil + expect(content.tempfile).to be_nil end it "should not call any fetcher" do - Chef::Provider::RemoteFile::Fetcher.should_not_receive(:for_resource) + expect(Chef::Provider::RemoteFile::Fetcher).not_to receive(:for_resource) end end 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") + allow(new_resource).to receive(:checksum).and_return("0fd012fd") + allow(current_resource).to receive(:checksum).and_return("0fd012fdc96e96f8f7cf2046522a54aed0ce470224513e45da6bc1a17a4924aa") end it "should return nil for the tempfile" do - content.tempfile.should be_nil + expect(content.tempfile).to be_nil end it "should not call any fetcher" do - Chef::Provider::RemoteFile::Fetcher.should_not_receive(:for_resource) + expect(Chef::Provider::RemoteFile::Fetcher).not_to receive(:for_resource) end end @@ -79,17 +79,17 @@ describe Chef::Provider::RemoteFile::Content do before do # FIXME: test one or the other nil, test both not nil and not equal, abuse the regexp a little @uri = double("URI") - URI.should_receive(:parse).with(new_resource.source[0]).and_return(@uri) + expect(URI).to receive(:parse).with(new_resource.source[0]).and_return(@uri) end describe "when the fetcher returns nil for the tempfile" do before do http_fetcher = double("Chef::Provider::RemoteFile::HTTP", :fetch => nil) - Chef::Provider::RemoteFile::Fetcher.should_receive(:for_resource).with(@uri, new_resource, current_resource).and_return(http_fetcher) + expect(Chef::Provider::RemoteFile::Fetcher).to receive(:for_resource).with(@uri, new_resource, current_resource).and_return(http_fetcher) end it "should return nil for the tempfile" do - content.tempfile.should be_nil + expect(content.tempfile).to be_nil end end @@ -100,43 +100,43 @@ describe Chef::Provider::RemoteFile::Content do let(:http_fetcher) { double("Chef::Provider::RemoteFile::HTTP", :fetch => tempfile) } before do - Chef::Provider::RemoteFile::Fetcher.should_receive(:for_resource).with(@uri, new_resource, current_resource).and_return(http_fetcher) + expect(Chef::Provider::RemoteFile::Fetcher).to receive(:for_resource).with(@uri, new_resource, current_resource).and_return(http_fetcher) end it "should return the tempfile object to the caller" do - content.tempfile.should == tempfile + expect(content.tempfile).to eq(tempfile) end end end describe "when the checksum are both nil" do before do - new_resource.checksum.should be_nil - current_resource.checksum.should be_nil + expect(new_resource.checksum).to be_nil + expect(current_resource.checksum).to be_nil end it_behaves_like "the resource needs fetching" end 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) + allow(new_resource).to receive(:checksum).and_return("fd012fd") + allow(current_resource).to receive(: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") + allow(new_resource).to receive(:checksum).and_return(nil) + allow(current_resource).to receive(: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") + allow(new_resource).to receive(:checksum).and_return("fd012fd") + allow(current_resource).to receive(:checksum).and_return("0fd012fdc96e96f8f7cf2046522a54aed0ce470224513e45da6bc1a17a4924aa") end it_behaves_like "the resource needs fetching" end @@ -144,17 +144,17 @@ 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) + allow(new_resource).to receive(:checksum).and_return(nil) + allow(current_resource).to receive(:checksum).and_return(nil) @uri = double("URI") - URI.should_receive(:parse).with(new_resource.source[0]).and_return(@uri) + expect(URI).to receive(:parse).with(new_resource.source[0]).and_return(@uri) http_fetcher = double("Chef::Provider::RemoteFile::HTTP") - http_fetcher.should_receive(:fetch).and_raise(Errno::ECONNREFUSED) - Chef::Provider::RemoteFile::Fetcher.should_receive(:for_resource).with(@uri, new_resource, current_resource).and_return(http_fetcher) + expect(http_fetcher).to receive(:fetch).and_raise(Errno::ECONNREFUSED) + expect(Chef::Provider::RemoteFile::Fetcher).to receive(:for_resource).with(@uri, new_resource, current_resource).and_return(http_fetcher) end it "should propagate the error back to the caller" do - lambda { content.tempfile }.should raise_error(Errno::ECONNREFUSED) + expect { content.tempfile }.to raise_error(Errno::ECONNREFUSED) end end @@ -184,15 +184,15 @@ describe Chef::Provider::RemoteFile::Content do ].each do |exception| describe "with an exception of #{exception}" do before do - new_resource.stub(:checksum).and_return(nil) - current_resource.stub(:checksum).and_return(nil) + allow(new_resource).to receive(:checksum).and_return(nil) + allow(current_resource).to receive(:checksum).and_return(nil) @uri0 = double("URI0") @uri1 = double("URI1") - URI.should_receive(:parse).with(new_resource.source[0]).and_return(@uri0) - URI.should_receive(:parse).with(new_resource.source[1]).and_return(@uri1) + expect(URI).to receive(:parse).with(new_resource.source[0]).and_return(@uri0) + expect(URI).to receive(:parse).with(new_resource.source[1]).and_return(@uri1) @http_fetcher_throws_exception = double("Chef::Provider::RemoteFile::HTTP") - @http_fetcher_throws_exception.should_receive(:fetch).at_least(:once).and_raise(create_exception(exception)) - Chef::Provider::RemoteFile::Fetcher.should_receive(:for_resource).with(@uri0, new_resource, current_resource).and_return(@http_fetcher_throws_exception) + expect(@http_fetcher_throws_exception).to receive(:fetch).at_least(:once).and_raise(create_exception(exception)) + expect(Chef::Provider::RemoteFile::Fetcher).to receive(:for_resource).with(@uri0, new_resource, current_resource).and_return(@http_fetcher_throws_exception) end describe "the second url should succeed" do @@ -200,26 +200,26 @@ describe Chef::Provider::RemoteFile::Content do @tempfile = double("Tempfile") mtime = Time.now http_fetcher_works = double("Chef::Provider::RemoteFile::HTTP", :fetch => @tempfile) - Chef::Provider::RemoteFile::Fetcher.should_receive(:for_resource).with(@uri1, new_resource, current_resource).and_return(http_fetcher_works) + expect(Chef::Provider::RemoteFile::Fetcher).to receive(:for_resource).with(@uri1, new_resource, current_resource).and_return(http_fetcher_works) end it "should return a valid tempfile" do - content.tempfile.should == @tempfile + expect(content.tempfile).to eq(@tempfile) end it "should not mutate the new_resource" do content.tempfile - new_resource.source.length.should == 2 + expect(new_resource.source.length).to eq(2) end end describe "when both urls fail" do before do - Chef::Provider::RemoteFile::Fetcher.should_receive(:for_resource).with(@uri1, new_resource, current_resource).and_return(@http_fetcher_throws_exception) + expect(Chef::Provider::RemoteFile::Fetcher).to receive(:for_resource).with(@uri1, new_resource, current_resource).and_return(@http_fetcher_throws_exception) end it "should propagate the error back to the caller" do - lambda { content.tempfile }.should raise_error(exception) + expect { content.tempfile }.to raise_error(exception) end end end @@ -229,24 +229,24 @@ 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) + allow(new_resource).to receive(:checksum).and_return(nil) + allow(current_resource).to receive(:checksum).and_return(nil) @uri0 = double("URI0") - URI.should_receive(:parse).with(new_resource.source[0]).and_return(@uri0) - URI.should_not_receive(:parse).with(new_resource.source[1]) + expect(URI).to receive(:parse).with(new_resource.source[0]).and_return(@uri0) + expect(URI).not_to receive(:parse).with(new_resource.source[1]) @tempfile = double("Tempfile") mtime = Time.now http_fetcher_works = double("Chef::Provider::RemoteFile::HTTP", :fetch => @tempfile) - Chef::Provider::RemoteFile::Fetcher.should_receive(:for_resource).with(@uri0, new_resource, current_resource).and_return(http_fetcher_works) + expect(Chef::Provider::RemoteFile::Fetcher).to receive(:for_resource).with(@uri0, new_resource, current_resource).and_return(http_fetcher_works) end it "should return a valid tempfile" do - content.tempfile.should == @tempfile + expect(content.tempfile).to eq(@tempfile) end it "should not mutate the new_resource" do content.tempfile - new_resource.source.length.should == 2 + expect(new_resource.source.length).to eq(2) end end diff --git a/spec/unit/provider/remote_file/fetcher_spec.rb b/spec/unit/provider/remote_file/fetcher_spec.rb index b5594b50e6..c049848fbf 100644 --- a/spec/unit/provider/remote_file/fetcher_spec.rb +++ b/spec/unit/provider/remote_file/fetcher_spec.rb @@ -27,47 +27,47 @@ describe Chef::Provider::RemoteFile::Fetcher do describe "when passed an http url" do let(:uri) { double("uri", :scheme => "http" ) } before do - Chef::Provider::RemoteFile::HTTP.should_receive(:new).and_return(fetcher_instance) + expect(Chef::Provider::RemoteFile::HTTP).to receive(:new).and_return(fetcher_instance) end it "returns an http fetcher" do - described_class.for_resource(uri, new_resource, current_resource).should == fetcher_instance + expect(described_class.for_resource(uri, new_resource, current_resource)).to eq(fetcher_instance) end end describe "when passed an https url" do let(:uri) { double("uri", :scheme => "https" ) } before do - Chef::Provider::RemoteFile::HTTP.should_receive(:new).and_return(fetcher_instance) + expect(Chef::Provider::RemoteFile::HTTP).to receive(:new).and_return(fetcher_instance) end it "returns an http fetcher" do - described_class.for_resource(uri, new_resource, current_resource).should == fetcher_instance + expect(described_class.for_resource(uri, new_resource, current_resource)).to eq(fetcher_instance) end end describe "when passed an ftp url" do let(:uri) { double("uri", :scheme => "ftp" ) } before do - Chef::Provider::RemoteFile::FTP.should_receive(:new).and_return(fetcher_instance) + expect(Chef::Provider::RemoteFile::FTP).to receive(:new).and_return(fetcher_instance) end it "returns an ftp fetcher" do - described_class.for_resource(uri, new_resource, current_resource).should == fetcher_instance + expect(described_class.for_resource(uri, new_resource, current_resource)).to eq(fetcher_instance) end end describe "when passed a file url" do let(:uri) { double("uri", :scheme => "file" ) } before do - Chef::Provider::RemoteFile::LocalFile.should_receive(:new).and_return(fetcher_instance) + expect(Chef::Provider::RemoteFile::LocalFile).to receive(:new).and_return(fetcher_instance) end it "returns a localfile fetcher" do - described_class.for_resource(uri, new_resource, current_resource).should == fetcher_instance + expect(described_class.for_resource(uri, new_resource, current_resource)).to eq(fetcher_instance) end end describe "when passed a url we do not recognize" do let(:uri) { double("uri", :scheme => "xyzzy" ) } it "throws an ArgumentError exception" do - lambda { described_class.for_resource(uri, new_resource, current_resource) }.should raise_error(ArgumentError) + expect { described_class.for_resource(uri, new_resource, current_resource) }.to raise_error(ArgumentError) end end diff --git a/spec/unit/provider/remote_file/ftp_spec.rb b/spec/unit/provider/remote_file/ftp_spec.rb index b393912ef9..b3a3fcf376 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 = double(Net::FTP, { }) - ftp.stub(:connect) - ftp.stub(:login) - ftp.stub(:voidcmd) - ftp.stub(:mtime).and_return(Time.now) - ftp.stub(:getbinaryfile) - ftp.stub(:close) - ftp.stub(:passive=) + allow(ftp).to receive(:connect) + allow(ftp).to receive(:login) + allow(ftp).to receive(:voidcmd) + allow(ftp).to receive(:mtime).and_return(Time.now) + allow(ftp).to receive(:getbinaryfile) + allow(ftp).to receive(:close) + allow(ftp).to receive(:passive=) ftp end @@ -53,49 +53,49 @@ describe Chef::Provider::RemoteFile::FTP do let(:tempfile) do t = StringIO.new - t.stub(:path).and_return(tempfile_path) + allow(t).to receive(:path).and_return(tempfile_path) t end 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) + allow(Net::FTP).to receive(:new).with().and_return(ftp) + allow(Tempfile).to receive(:new).and_return(tempfile) end describe "when first created" do it "throws an argument exception when no path is given" do uri.path = "" - lambda { Chef::Provider::RemoteFile::FTP.new(uri, new_resource, current_resource) }.should raise_error(ArgumentError) + expect { Chef::Provider::RemoteFile::FTP.new(uri, new_resource, current_resource) }.to raise_error(ArgumentError) end it "throws an argument exception when only a / is given" do uri.path = "/" - lambda { Chef::Provider::RemoteFile::FTP.new(uri, new_resource, current_resource) }.should raise_error(ArgumentError) + expect { Chef::Provider::RemoteFile::FTP.new(uri, new_resource, current_resource) }.to raise_error(ArgumentError) end it "throws an argument exception when no filename is given" do uri.path = "/the/whole/path/" - lambda { Chef::Provider::RemoteFile::FTP.new(uri, new_resource, current_resource) }.should raise_error(ArgumentError) + expect { Chef::Provider::RemoteFile::FTP.new(uri, new_resource, current_resource) }.to raise_error(ArgumentError) end it "throws an argument exception when the typecode is invalid" do uri.typecode = "d" - lambda { Chef::Provider::RemoteFile::FTP.new(uri, new_resource, current_resource) }.should raise_error(ArgumentError) + expect { Chef::Provider::RemoteFile::FTP.new(uri, new_resource, current_resource) }.to raise_error(ArgumentError) end it "does not use passive mode when new_resource sets ftp_active_mode to true" do new_resource.ftp_active_mode(true) fetcher = Chef::Provider::RemoteFile::FTP.new(uri, new_resource, current_resource) - fetcher.use_passive_mode?.should be_false + expect(fetcher.use_passive_mode?).to be_false end it "uses passive mode when new_resource sets ftp_active_mode to false" do new_resource.ftp_active_mode(false) fetcher = Chef::Provider::RemoteFile::FTP.new(uri, new_resource, current_resource) - fetcher.use_passive_mode?.should be_true + expect(fetcher.use_passive_mode?).to be_true end end @@ -112,24 +112,24 @@ describe Chef::Provider::RemoteFile::FTP do end it "should connect to the host from the uri on the default port 21" do - ftp.should_receive(:connect).with("opscode.com", 21) + expect(ftp).to receive(:connect).with("opscode.com", 21) fetcher.fetch end it "should set passive true when ftp_active_mode is false" do new_resource.ftp_active_mode(false) - ftp.should_receive(:passive=).with(true) + expect(ftp).to receive(:passive=).with(true) fetcher.fetch end it "should set passive false when ftp_active_mode is false" do new_resource.ftp_active_mode(true) - ftp.should_receive(:passive=).with(false) + expect(ftp).to receive(:passive=).with(false) fetcher.fetch end it "should use anonymous ftp when no userinfo is provided" do - ftp.should_receive(:login).with("anonymous", nil) + expect(ftp).to receive(:login).with("anonymous", nil) fetcher.fetch end @@ -138,7 +138,7 @@ describe Chef::Provider::RemoteFile::FTP do it "should connect on an alternate port when one is provided" do uri = URI.parse("ftp://opscode.com:8021/seattle.txt") - ftp.should_receive(:connect).with("opscode.com", 8021) + expect(ftp).to receive(:connect).with("opscode.com", 8021) fetcher.fetch end @@ -148,7 +148,7 @@ describe Chef::Provider::RemoteFile::FTP do let(:uri) { URI.parse("ftp://the_user:the_password@opscode.com/seattle.txt") } it "should use authenticated ftp when userinfo is provided" do - ftp.should_receive(:login).with("the_user", "the_password") + expect(ftp).to receive(:login).with("the_user", "the_password") fetcher.fetch end end @@ -157,7 +157,7 @@ describe Chef::Provider::RemoteFile::FTP do let(:uri) { URI.parse("ftp://the_user:the_password@opscode.com/seattle.txt;type=a") } it "fetches the file with ascii typecode set" do - ftp.should_receive(:voidcmd).with("TYPE A").once + expect(ftp).to receive(:voidcmd).with("TYPE A").once fetcher.fetch end @@ -167,7 +167,7 @@ describe Chef::Provider::RemoteFile::FTP do let(:uri) { URI.parse("ftp://the_user:the_password@opscode.com/seattle.txt;type=i") } it "should accept image for the typecode" do - ftp.should_receive(:voidcmd).with("TYPE I").once + expect(ftp).to receive(:voidcmd).with("TYPE I").once fetcher.fetch end @@ -177,10 +177,10 @@ describe Chef::Provider::RemoteFile::FTP do let(:uri) { URI.parse("ftp://opscode.com/the/whole/path/seattle.txt") } it "should fetch the file from the correct path" do - ftp.should_receive(:voidcmd).with("CWD the").once - ftp.should_receive(:voidcmd).with("CWD whole").once - ftp.should_receive(:voidcmd).with("CWD path").once - ftp.should_receive(:getbinaryfile).with("seattle.txt", tempfile.path) + expect(ftp).to receive(:voidcmd).with("CWD the").once + expect(ftp).to receive(:voidcmd).with("CWD whole").once + expect(ftp).to receive(:voidcmd).with("CWD path").once + expect(ftp).to receive(:getbinaryfile).with("seattle.txt", tempfile.path) fetcher.fetch end @@ -193,7 +193,7 @@ describe Chef::Provider::RemoteFile::FTP do it "should return a tempfile in the result" do result = fetcher.fetch - result.should equal(tempfile) + expect(result).to equal(tempfile) end end @@ -207,10 +207,10 @@ describe Chef::Provider::RemoteFile::FTP do it "fetches the file via the proxy" do current_socks_server = ENV["SOCKS_SERVER"] - ENV.should_receive(:[]=).with("SOCKS_SERVER", "socks5://bill:ted@socks.example.com:5000").ordered - ENV.should_receive(:[]=).with("SOCKS_SERVER", current_socks_server).ordered + expect(ENV).to receive(:[]=).with("SOCKS_SERVER", "socks5://bill:ted@socks.example.com:5000").ordered + expect(ENV).to receive(:[]=).with("SOCKS_SERVER", current_socks_server).ordered result = fetcher.fetch - result.should equal(tempfile) + expect(result).to equal(tempfile) end end diff --git a/spec/unit/provider/remote_file/http_spec.rb b/spec/unit/provider/remote_file/http_spec.rb index 951d9f0a05..d9cfaa15eb 100644 --- a/spec/unit/provider/remote_file/http_spec.rb +++ b/spec/unit/provider/remote_file/http_spec.rb @@ -48,11 +48,11 @@ describe Chef::Provider::RemoteFile::HTTP do context "and there is no valid cache control data for this URI on disk" do before do - Chef::Provider::RemoteFile::CacheControlData.should_receive(:load_and_validate).with(uri, current_resource_checksum).and_return(cache_control_data) + expect(Chef::Provider::RemoteFile::CacheControlData).to receive(:load_and_validate).with(uri, current_resource_checksum).and_return(cache_control_data) end it "does not add conditional GET headers" do - fetcher.conditional_get_headers.should == {} + expect(fetcher.conditional_get_headers).to eq({}) end context "and the resource specifies custom headers" do @@ -61,7 +61,7 @@ describe Chef::Provider::RemoteFile::HTTP do end it "has the user-specified custom headers" do - fetcher.headers.should == {"x-myapp-header" => "custom-header-value"} + expect(fetcher.headers).to eq({"x-myapp-header" => "custom-header-value"}) end end @@ -79,7 +79,7 @@ describe Chef::Provider::RemoteFile::HTTP do cache_control_data.etag = etag cache_control_data.mtime = mtime - Chef::Provider::RemoteFile::CacheControlData.should_receive(:load_and_validate).with(uri, current_resource_checksum).and_return(cache_control_data) + expect(Chef::Provider::RemoteFile::CacheControlData).to receive(:load_and_validate).with(uri, current_resource_checksum).and_return(cache_control_data) end context "and no conditional get features are enabled" do @@ -88,7 +88,7 @@ describe Chef::Provider::RemoteFile::HTTP do end it "does not add headers to the request" do - fetcher.headers.should == {} + expect(fetcher.headers).to eq({}) end end @@ -99,8 +99,8 @@ describe Chef::Provider::RemoteFile::HTTP do it "adds If-None-Match and If-Modified-Since headers to the request" do headers = fetcher.headers - headers["if-none-match"].should == etag - headers["if-modified-since"].should == mtime + expect(headers["if-none-match"]).to eq(etag) + expect(headers["if-modified-since"]).to eq(mtime) end context "and custom headers are provided" do @@ -111,13 +111,13 @@ describe Chef::Provider::RemoteFile::HTTP do end it "preserves non-conflicting headers" do - fetcher.headers["x-myapp-header"].should == "app-specific-header" + expect(fetcher.headers["x-myapp-header"]).to eq("app-specific-header") end it "prefers user-supplied cache control headers" do headers = fetcher.headers - headers["if-none-match"].should == "custom-etag" - headers["if-modified-since"].should == "custom-last-modified" + expect(headers["if-none-match"]).to eq("custom-etag") + expect(headers["if-modified-since"]).to eq("custom-last-modified") end end @@ -131,8 +131,8 @@ describe Chef::Provider::RemoteFile::HTTP do it "only adds If-None-Match headers to the request" do headers = fetcher.headers - headers["if-none-match"].should == etag - headers.should_not have_key("if-modified-since") + expect(headers["if-none-match"]).to eq(etag) + expect(headers).not_to have_key("if-modified-since") end end @@ -144,8 +144,8 @@ describe Chef::Provider::RemoteFile::HTTP do it "only adds If-Modified-Since headers to the request" do headers = fetcher.headers - headers["if-modified-since"].should == mtime - headers.should_not have_key("if-none-match") + expect(headers["if-modified-since"]).to eq(mtime) + expect(headers).not_to have_key("if-none-match") end end end @@ -165,17 +165,17 @@ describe Chef::Provider::RemoteFile::HTTP do let(:rest) do rest = double(Chef::HTTP::Simple) - rest.stub(:streaming_request).and_return(tempfile) - rest.stub(:last_response).and_return(last_response) + allow(rest).to receive(:streaming_request).and_return(tempfile) + allow(rest).to receive(:last_response).and_return(last_response) rest end before do new_resource.headers({}) new_resource.use_last_modified(false) - Chef::Provider::RemoteFile::CacheControlData.should_receive(:load_and_validate).with(uri, current_resource_checksum).and_return(cache_control_data) + expect(Chef::Provider::RemoteFile::CacheControlData).to receive(:load_and_validate).with(uri, current_resource_checksum).and_return(cache_control_data) - Chef::HTTP::Simple.should_receive(:new).with(*expected_http_args).and_return(rest) + expect(Chef::HTTP::Simple).to receive(:new).with(*expected_http_args).and_return(rest) end @@ -183,8 +183,8 @@ describe Chef::Provider::RemoteFile::HTTP do it "should return a nil tempfile for a 304 HTTPNotModifed" do # Streaming request returns nil for 304 errors - rest.stub(:streaming_request).and_return(nil) - fetcher.fetch.should be_nil + allow(rest).to receive(:streaming_request).and_return(nil) + expect(fetcher.fetch).to be_nil end end @@ -194,25 +194,25 @@ describe Chef::Provider::RemoteFile::HTTP do let(:fetched_content_checksum) { "e2a8938cc31754f6c067b35aab1d0d4864272e9bf8504536ef3e79ebf8432305" } before do - cache_control_data.should_receive(:save) - Chef::Digester.should_receive(:checksum_for_file).with(tempfile_path).and_return(fetched_content_checksum) + expect(cache_control_data).to receive(:save) + expect(Chef::Digester).to receive(:checksum_for_file).with(tempfile_path).and_return(fetched_content_checksum) end it "should return a tempfile" do result = fetcher.fetch - result.should == tempfile - cache_control_data.etag.should be_nil - cache_control_data.mtime.should be_nil - cache_control_data.checksum.should == fetched_content_checksum + expect(result).to eq(tempfile) + expect(cache_control_data.etag).to be_nil + expect(cache_control_data.mtime).to be_nil + expect(cache_control_data.checksum).to eq(fetched_content_checksum) end context "and the response does not contain an etag" do let(:last_response) { {"etag" => nil} } it "does not include an etag in the result" do fetcher.fetch - cache_control_data.etag.should be_nil - cache_control_data.mtime.should be_nil - cache_control_data.checksum.should == fetched_content_checksum + expect(cache_control_data.etag).to be_nil + expect(cache_control_data.mtime).to be_nil + expect(cache_control_data.checksum).to eq(fetched_content_checksum) end end @@ -221,9 +221,9 @@ describe Chef::Provider::RemoteFile::HTTP do it "includes the etag value in the response" do fetcher.fetch - cache_control_data.etag.should == "abc123" - cache_control_data.mtime.should be_nil - cache_control_data.checksum.should == fetched_content_checksum + expect(cache_control_data.etag).to eq("abc123") + expect(cache_control_data.mtime).to be_nil + expect(cache_control_data.checksum).to eq(fetched_content_checksum) end end @@ -234,9 +234,9 @@ describe Chef::Provider::RemoteFile::HTTP do # RFC 2616 suggests that servers that do not set a Date header do not # have a reliable clock, so no use in making them deal with dates. fetcher.fetch - cache_control_data.etag.should be_nil - cache_control_data.mtime.should be_nil - cache_control_data.checksum.should == fetched_content_checksum + expect(cache_control_data.etag).to be_nil + expect(cache_control_data.mtime).to be_nil + expect(cache_control_data.checksum).to eq(fetched_content_checksum) end end @@ -248,8 +248,8 @@ describe Chef::Provider::RemoteFile::HTTP do it "sets the mtime to the Last-Modified time in the response" do fetcher.fetch - cache_control_data.etag.should be_nil - cache_control_data.mtime.should == last_response["last_modified"] + expect(cache_control_data.etag).to be_nil + expect(cache_control_data.mtime).to eq(last_response["last_modified"]) end end @@ -260,9 +260,9 @@ describe Chef::Provider::RemoteFile::HTTP do it "sets the mtime to the Date in the response" do fetcher.fetch - cache_control_data.etag.should be_nil - cache_control_data.mtime.should == last_response["date"] - cache_control_data.checksum.should == fetched_content_checksum + expect(cache_control_data.etag).to be_nil + expect(cache_control_data.mtime).to eq(last_response["date"]) + expect(cache_control_data.checksum).to eq(fetched_content_checksum) end end @@ -288,11 +288,11 @@ describe Chef::Provider::RemoteFile::HTTP do # This is intended to provide insurance that refactoring of the parent # context does not negate the value of this particular example. Chef::HTTP::Simple.new(*expected_http_args) - Chef::HTTP::Simple.should_receive(:new).once.with(*expected_http_args).and_return(rest) + expect(Chef::HTTP::Simple).to receive(:new).once.with(*expected_http_args).and_return(rest) fetcher.fetch - cache_control_data.etag.should be_nil - cache_control_data.mtime.should be_nil - cache_control_data.checksum.should == fetched_content_checksum + expect(cache_control_data.etag).to be_nil + expect(cache_control_data.mtime).to be_nil + expect(cache_control_data.checksum).to eq(fetched_content_checksum) end end end diff --git a/spec/unit/provider/remote_file/local_file_spec.rb b/spec/unit/provider/remote_file/local_file_spec.rb index b65c917c44..b33d82f624 100644 --- a/spec/unit/provider/remote_file/local_file_spec.rb +++ b/spec/unit/provider/remote_file/local_file_spec.rb @@ -30,21 +30,21 @@ describe Chef::Provider::RemoteFile::LocalFile do describe "when given local unix path" do let(:uri) { URI.parse("file:///nyan_cat.png") } it "returns a correct unix path" do - fetcher.fix_windows_path(uri.path).should == "/nyan_cat.png" + expect(fetcher.fix_windows_path(uri.path)).to eq("/nyan_cat.png") end end describe "when given local windows path" do let(:uri) { URI.parse("file:///z:/windows/path/file.txt") } it "returns a valid windows local path" do - fetcher.fix_windows_path(uri.path).should == "z:/windows/path/file.txt" + expect(fetcher.fix_windows_path(uri.path)).to eq("z:/windows/path/file.txt") end end describe "when given unc windows path" do let(:uri) { URI.parse("file:////server/share/windows/path/file.txt") } it "returns a valid windows unc path" do - fetcher.fix_windows_path(uri.path).should == "//server/share/windows/path/file.txt" + expect(fetcher.fix_windows_path(uri.path)).to eq("//server/share/windows/path/file.txt") end end end @@ -52,11 +52,11 @@ describe Chef::Provider::RemoteFile::LocalFile do context "when first created" do it "stores the uri it is passed" do - fetcher.uri.should == uri + expect(fetcher.uri).to eq(uri) end it "stores the new_resource" do - fetcher.new_resource.should == new_resource + expect(fetcher.new_resource).to eq(new_resource) end end @@ -71,12 +71,12 @@ describe Chef::Provider::RemoteFile::LocalFile do end it "stages the local file to a temporary file" do - Chef::FileContentManagement::Tempfile.should_receive(:new).with(new_resource).and_return(chef_tempfile) - ::FileUtils.should_receive(:cp).with(uri.path, tempfile.path) - tempfile.should_receive(:close) + expect(Chef::FileContentManagement::Tempfile).to receive(:new).with(new_resource).and_return(chef_tempfile) + expect(::FileUtils).to receive(:cp).with(uri.path, tempfile.path) + expect(tempfile).to receive(:close) result = fetcher.fetch - result.should == tempfile + expect(result).to eq(tempfile) end end diff --git a/spec/unit/provider/remote_file_spec.rb b/spec/unit/provider/remote_file_spec.rb index 3fa3866743..de4a897847 100644 --- a/spec/unit/provider/remote_file_spec.rb +++ b/spec/unit/provider/remote_file_spec.rb @@ -47,13 +47,13 @@ describe Chef::Provider::RemoteFile do subject(:provider) do provider = described_class.new(resource, run_context) - provider.stub(:content).and_return(content) - provider.stub(:update_new_resource_checksum).and_return(nil) # Otherwise it doesn't behave like a File provider + allow(provider).to receive(:content).and_return(content) + allow(provider).to receive(:update_new_resource_checksum).and_return(nil) # Otherwise it doesn't behave like a File provider provider end before do - Chef::FileCache.stub(:load).with("remote_file/#{resource.name}").and_raise(Chef::Exceptions::FileNotFound) + allow(Chef::FileCache).to receive(:load).with("remote_file/#{resource.name}").and_raise(Chef::Exceptions::FileNotFound) end it_behaves_like Chef::Provider::File diff --git a/spec/unit/provider/route_spec.rb b/spec/unit/provider/route_spec.rb index 2a6d48c79e..e63029ad07 100644 --- a/spec/unit/provider/route_spec.rb +++ b/spec/unit/provider/route_spec.rb @@ -36,14 +36,14 @@ describe Chef::Provider::Route do describe Chef::Provider::Route, "hex2ip" do it "should return nil if ip address is invalid" do - @provider.hex2ip('foo').should be_nil # does not even look like an ip - @provider.hex2ip('ABCDEFGH').should be_nil # 8 chars, but invalid + expect(@provider.hex2ip('foo')).to be_nil # does not even look like an ip + expect(@provider.hex2ip('ABCDEFGH')).to be_nil # 8 chars, but invalid end it "should return quad-dotted notation for a valid IP" do - @provider.hex2ip('01234567').should == '103.69.35.1' - @provider.hex2ip('0064a8c0').should == '192.168.100.0' - @provider.hex2ip('00FFFFFF').should == '255.255.255.0' + expect(@provider.hex2ip('01234567')).to eq('103.69.35.1') + expect(@provider.hex2ip('0064a8c0')).to eq('192.168.100.0') + expect(@provider.hex2ip('00FFFFFF')).to eq('255.255.255.0') end end @@ -55,158 +55,158 @@ 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) + allow(File).to receive(: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") + allow(resource).to receive(:gateway).and_return("10.0.0.1") + allow(resource).to receive(:device).and_return("eth0") provider = Chef::Provider::Route.new(resource, @run_context) provider.load_current_resource - provider.is_running.should be_false + expect(provider.is_running).to be_false end 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") + allow(resource).to receive(:gateway).and_return("192.168.132.9") + allow(resource).to receive(:device).and_return("eth0") provider = Chef::Provider::Route.new(resource, @run_context) provider.load_current_resource - provider.is_running.should be_true + expect(provider.is_running).to be_true end 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") + allow(resource).to receive(:gateway).and_return("10.10.10.10") + allow(resource).to receive(:device).and_return("eth0") provider = Chef::Provider::Route.new(resource, @run_context) provider.load_current_resource - provider.is_running.should be_false + expect(provider.is_running).to be_false end end end 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.should_receive(:generate_command).once.with(:add) - @provider.should_receive(:generate_config) + allow(@provider).to receive(:run_command).and_return(true) + allow(@current_resource).to receive(:gateway).and_return(nil) + expect(@provider).to receive(:generate_command).once.with(:add) + expect(@provider).to receive(:generate_config) @provider.run_action(:add) - @new_resource.should be_updated + expect(@new_resource).to be_updated 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.should_not_receive(:generate_command).with(:add) - @provider.should_receive(:generate_config) + allow(@provider).to receive(:run_command).and_return(true) + allow(@provider).to receive(:is_running).and_return(true) + expect(@provider).not_to receive(:generate_command).with(:add) + expect(@provider).to receive(:generate_config) @provider.run_action(:add) - @new_resource.should_not be_updated + expect(@new_resource).not_to be_updated end it "should not delete config file for :add action (CHEF-3332)" do @node.automatic_attrs[:platform] = 'centos' route_file = StringIO.new - File.should_receive(:new).and_return(route_file) + expect(File).to 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) + allow(@provider).to receive(:run_command).and_return(true) @resource_add.action(:add) @provider.run_action(:add) - route_file.string.split("\n").should have(1).items - route_file.string.should match(/^192\.168\.1\.0\/24 via 192\.168\.0\.1$/) + expect(route_file.string.split("\n").size).to eq(1) + expect(route_file.string).to match(/^192\.168\.1\.0\/24 via 192\.168\.0\.1$/) end end describe Chef::Provider::Route, "action_delete" do it "should delete the route if it exists" do - @provider.stub(:run_command).and_return(true) - @provider.should_receive(:generate_command).once.with(:delete) - @provider.stub(:is_running).and_return(true) + allow(@provider).to receive(:run_command).and_return(true) + expect(@provider).to receive(:generate_command).once.with(:delete) + allow(@provider).to receive(:is_running).and_return(true) @provider.run_action(:delete) - @new_resource.should be_updated + expect(@new_resource).to 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) - @provider.should_not_receive(:generate_command).with(:add) + allow(@current_resource).to receive(:gateway).and_return(nil) + allow(@provider).to receive(:run_command).and_return(true) + expect(@provider).not_to receive(:generate_command).with(:add) @provider.run_action(:delete) - @new_resource.should_not be_updated + expect(@new_resource).not_to be_updated end end 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') - @provider.generate_command(:add).should match(/\/\d{1,2}\s/) + allow(@new_resource).to receive(:netmask).and_return('255.255.0.0') + expect(@provider.generate_command(:add)).to 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) - @provider.generate_command(:add).should_not match(/\/\d{1,2}\s/) + allow(@new_resource).to receive(:netmask).and_return(nil) + expect(@provider.generate_command(:add)).not_to match(/\/\d{1,2}\s/) end it "should include ' via $gateway ' when a gateway is specified" do - @provider.generate_command(:add).should match(/\svia\s#{Regexp.escape(@new_resource.gateway.to_s)}\s/) + expect(@provider.generate_command(:add)).to match(/\svia\s#{Regexp.escape(@new_resource.gateway.to_s)}\s/) end it "should not include ' via $gateway ' when a gateway is not specified" do - @new_resource.stub(:gateway).and_return(nil) - @provider.generate_command(:add).should_not match(/\svia\s#{Regexp.escape(@new_resource.gateway.to_s)}\s/) + allow(@new_resource).to receive(:gateway).and_return(nil) + expect(@provider.generate_command(:add)).not_to 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') - @provider.generate_command(:delete).should match(/\/\d{1,2}\s/) + allow(@new_resource).to receive(:netmask).and_return('255.255.0.0') + expect(@provider.generate_command(:delete)).to 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) - @provider.generate_command(:delete).should_not match(/\/\d{1,2}\s/) + allow(@new_resource).to receive(:netmask).and_return(nil) + expect(@provider.generate_command(:delete)).not_to match(/\/\d{1,2}\s/) end it "should include ' via $gateway ' when a gateway is specified" do - @provider.generate_command(:delete).should match(/\svia\s#{Regexp.escape(@new_resource.gateway.to_s)}\s/) + expect(@provider.generate_command(:delete)).to match(/\svia\s#{Regexp.escape(@new_resource.gateway.to_s)}\s/) end it "should not include ' via $gateway ' when a gateway is not specified" do - @new_resource.stub(:gateway).and_return(nil) - @provider.generate_command(:delete).should_not match(/\svia\s#{Regexp.escape(@new_resource.gateway.to_s)}\s/) + allow(@new_resource).to receive(:gateway).and_return(nil) + expect(@provider.generate_command(:delete)).not_to 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') - @provider.config_file_contents(:add, { :target => @new_resource.target, :netmask => @new_resource.netmask}).should match(/\/\d{1,2}.*\n$/) + allow(@new_resource).to receive(:netmask).and_return('255.255.0.0') + expect(@provider.config_file_contents(:add, { :target => @new_resource.target, :netmask => @new_resource.netmask})).to match(/\/\d{1,2}.*\n$/) end it "should not include a netmask when a one is specified" do - @provider.config_file_contents(:add, { :target => @new_resource.target}).should_not match(/\/\d{1,2}.*\n$/) + expect(@provider.config_file_contents(:add, { :target => @new_resource.target})).not_to match(/\/\d{1,2}.*\n$/) end it "should include ' via $gateway ' when a gateway is specified" do - @provider.config_file_contents(:add, { :target => @new_resource.target, :gateway => @new_resource.gateway}).should match(/\svia\s#{Regexp.escape(@new_resource.gateway.to_s)}\n/) + expect(@provider.config_file_contents(:add, { :target => @new_resource.target, :gateway => @new_resource.gateway})).to match(/\svia\s#{Regexp.escape(@new_resource.gateway.to_s)}\n/) end it "should not include ' via $gateway ' when a gateway is not specified" do - @provider.generate_command(:add).should_not match(/\svia\s#{Regexp.escape(@new_resource.gateway.to_s)}\n/) + expect(@provider.generate_command(:add)).not_to match(/\svia\s#{Regexp.escape(@new_resource.gateway.to_s)}\n/) end end describe Chef::Provider::Route, "config_file_contents for action_delete" do it "should return an empty string" do - @provider.config_file_contents(:delete).should match(/^$/) + expect(@provider.config_file_contents(:delete)).to match(/^$/) end end @@ -216,7 +216,7 @@ describe Chef::Provider::Route do @node.automatic_attrs[:platform] = platform route_file = StringIO.new - File.should_receive(:new).with("/etc/sysconfig/network-scripts/route-eth0", "w").and_return(route_file) + expect(File).to receive(:new).with("/etc/sysconfig/network-scripts/route-eth0", "w").and_return(route_file) #Chef::Log.should_receive(:debug).with("route[10.0.0.10] writing route.eth0\n10.0.0.10 via 10.0.0.9\n") @run_context.resource_collection << @new_resource @provider.generate_config @@ -227,17 +227,17 @@ describe Chef::Provider::Route do @node.automatic_attrs[:platform] = 'centos' route_file = StringIO.new - File.should_receive(:new).and_return(route_file) + expect(File).to receive(:new).and_return(route_file) @run_context.resource_collection << Chef::Resource::Route.new('192.168.1.0/24 via 192.168.0.1') @run_context.resource_collection << Chef::Resource::Route.new('192.168.2.0/24 via 192.168.0.1') @run_context.resource_collection << Chef::Resource::Route.new('192.168.3.0/24 via 192.168.0.1') @provider.action = :add @provider.generate_config - route_file.string.split("\n").should have(3).items - route_file.string.should match(/^192\.168\.1\.0\/24 via 192\.168\.0\.1$/) - route_file.string.should match(/^192\.168\.2\.0\/24 via 192\.168\.0\.1$/) - route_file.string.should match(/^192\.168\.3\.0\/24 via 192\.168\.0\.1$/) + expect(route_file.string.split("\n").size).to eq(3) + expect(route_file.string).to match(/^192\.168\.1\.0\/24 via 192\.168\.0\.1$/) + expect(route_file.string).to match(/^192\.168\.2\.0\/24 via 192\.168\.0\.1$/) + expect(route_file.string).to match(/^192\.168\.3\.0\/24 via 192\.168\.0\.1$/) end end end diff --git a/spec/unit/provider/ruby_block_spec.rb b/spec/unit/provider/ruby_block_spec.rb index 6e5c9a638b..266c943367 100644 --- a/spec/unit/provider/ruby_block_spec.rb +++ b/spec/unit/provider/ruby_block_spec.rb @@ -31,16 +31,16 @@ describe Chef::Provider::RubyBlock, "initialize" do it "should call the block and flag the resource as updated" do @provider.run_action(:run) - $evil_global_evil_laugh.should == :mwahahaha - @new_resource.should be_updated + expect($evil_global_evil_laugh).to eq(:mwahahaha) + expect(@new_resource).to be_updated end it "accepts `create' as an alias for `run'" do # SEE ALSO: CHEF-3500 # "create" used to be the default action, it was renamed. @provider.run_action(:create) - $evil_global_evil_laugh.should == :mwahahaha - @new_resource.should be_updated + expect($evil_global_evil_laugh).to eq(:mwahahaha) + expect(@new_resource).to be_updated end end diff --git a/spec/unit/provider/script_spec.rb b/spec/unit/provider/script_spec.rb index d072eddd04..7dc8588397 100644 --- a/spec/unit/provider/script_spec.rb +++ b/spec/unit/provider/script_spec.rb @@ -30,44 +30,44 @@ 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') + allow(@script_file).to receive(:path).and_return('/tmp/the_script_file') - @provider.stub(:shell_out!).and_return(true) + allow(@provider).to receive(:shell_out!).and_return(true) end it "creates a temporary file to store the script" do - @provider.script_file.should be_an_instance_of(Tempfile) + expect(@provider.script_file).to be_an_instance_of(Tempfile) end it "unlinks the tempfile when finished" do tempfile_path = @provider.script_file.path @provider.unlink_script_file - File.exist?(tempfile_path).should be_false + expect(File.exist?(tempfile_path)).to be_false end 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) - FileUtils.should_receive(:chown).with('toor', 'wheel', "/tmp/the_script_file") + allow(@provider).to receive(:script_file).and_return(@script_file) + expect(FileUtils).to 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) + allow(@provider).to receive(:set_owner_and_group) + allow(@provider).to receive(: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 @provider.action_run @script_file.rewind - @script_file.string.should == "$| = 1; print 'i like beans'\n" + expect(@script_file.string).to eq("$| = 1; print 'i like beans'\n") end it "closes before executing the script and unlinks it when finished" do @provider.action_run - @script_file.should be_closed + expect(@script_file).to be_closed end end @@ -75,7 +75,7 @@ describe Chef::Provider::Script, "action_run" do describe "when running the script" do it 'should set the command to "interpreter" "tempfile"' do @provider.action_run - @new_resource.command.should == '"perl" "/tmp/the_script_file"' + expect(@new_resource.command).to eq('"perl" "/tmp/the_script_file"') end describe "with flags set on the resource" do @@ -85,7 +85,7 @@ describe Chef::Provider::Script, "action_run" do it "should set the command to 'interpreter flags tempfile'" do @provider.action_run - @new_resource.command.should == '"perl" -f "/tmp/the_script_file"' + expect(@new_resource.command).to eq('"perl" -f "/tmp/the_script_file"') end end diff --git a/spec/unit/provider/service/aix_service_spec.rb b/spec/unit/provider/service/aix_service_spec.rb index 070f618b99..a2557354c2 100644 --- a/spec/unit/provider/service/aix_service_spec.rb +++ b/spec/unit/provider/service/aix_service_spec.rb @@ -28,17 +28,17 @@ describe Chef::Provider::Service::Aix do @current_resource = Chef::Resource::Service.new("chef") @provider = Chef::Provider::Service::Aix.new(@new_resource, @run_context) - Chef::Resource::Service.stub(:new).and_return(@current_resource) + allow(Chef::Resource::Service).to receive(:new).and_return(@current_resource) end describe "load current resource" do it "should create a current resource with the name of the new resource and determine the status" do @status = double("Status", :exitstatus => 0, :stdout => @stdout) - @provider.stub(:shell_out!).and_return(@status) + allow(@provider).to receive(:shell_out!).and_return(@status) - Chef::Resource::Service.should_receive(:new).and_return(@current_resource) - @current_resource.should_receive(:service_name).with("chef") - @provider.should_receive(:determine_current_status!) + expect(Chef::Resource::Service).to receive(:new).and_return(@current_resource) + expect(@current_resource).to receive(:service_name).with("chef") + expect(@provider).to receive(:determine_current_status!) @provider.load_current_resource end @@ -51,11 +51,11 @@ describe Chef::Provider::Service::Aix do end it "current resource is running" do - @provider.should_receive(:shell_out!).with("lssrc -a | grep -w chef").and_return(@status) - @provider.should_receive(:is_resource_group?).with(["chef chef 12345 active"]) + expect(@provider).to receive(:shell_out!).with("lssrc -a | grep -w chef").and_return(@status) + expect(@provider).to receive(:is_resource_group?).with(["chef chef 12345 active"]) @provider.load_current_resource - @current_resource.running.should be_true + expect(@current_resource.running).to be_true end end @@ -65,11 +65,11 @@ describe Chef::Provider::Service::Aix do end it "current resource is not running" do - @provider.should_receive(:shell_out!).with("lssrc -a | grep -w chef").and_return(@status) - @provider.should_receive(:is_resource_group?).with(["chef chef inoperative"]) + expect(@provider).to receive(:shell_out!).with("lssrc -a | grep -w chef").and_return(@status) + expect(@provider).to receive(:is_resource_group?).with(["chef chef inoperative"]) @provider.load_current_resource - @current_resource.running.should be_false + expect(@current_resource.running).to be_false end end end @@ -81,9 +81,9 @@ describe Chef::Provider::Service::Aix do end it "service is a group" do - @provider.should_receive(:shell_out!).with("lssrc -a | grep -w chef").and_return(@status) + expect(@provider).to receive(:shell_out!).with("lssrc -a | grep -w chef").and_return(@status) @provider.load_current_resource - @provider.instance_eval("@is_resource_group").should be_true + expect(@provider.instance_eval("@is_resource_group")).to be_true end end @@ -93,9 +93,9 @@ describe Chef::Provider::Service::Aix do end it "service is a group" do - @provider.should_receive(:shell_out!).with("lssrc -a | grep -w chef").and_return(@status) + expect(@provider).to receive(:shell_out!).with("lssrc -a | grep -w chef").and_return(@status) @provider.load_current_resource - @provider.instance_eval("@is_resource_group").should be_true + expect(@provider.instance_eval("@is_resource_group")).to be_true end end @@ -105,9 +105,9 @@ describe Chef::Provider::Service::Aix do end it "service is a subsystem" do - @provider.should_receive(:shell_out!).with("lssrc -a | grep -w chef").and_return(@status) + expect(@provider).to receive(:shell_out!).with("lssrc -a | grep -w chef").and_return(@status) @provider.load_current_resource - @provider.instance_eval("@is_resource_group").should be_false + expect(@provider.instance_eval("@is_resource_group")).to be_false end end end @@ -119,13 +119,13 @@ describe Chef::Provider::Service::Aix do it "should call the start command for groups" do @provider.instance_eval('@is_resource_group = true') - @provider.should_receive(:shell_out!).with("startsrc -g #{@new_resource.service_name}") + expect(@provider).to receive(:shell_out!).with("startsrc -g #{@new_resource.service_name}") @provider.start_service end it "should call the start command for subsystem" do - @provider.should_receive(:shell_out!).with("startsrc -s #{@new_resource.service_name}") + expect(@provider).to receive(:shell_out!).with("startsrc -s #{@new_resource.service_name}") @provider.start_service end @@ -138,13 +138,13 @@ describe Chef::Provider::Service::Aix do it "should call the stop command for groups" do @provider.instance_eval('@is_resource_group = true') - @provider.should_receive(:shell_out!).with("stopsrc -g #{@new_resource.service_name}") + expect(@provider).to receive(:shell_out!).with("stopsrc -g #{@new_resource.service_name}") @provider.stop_service end it "should call the stop command for subsystem" do - @provider.should_receive(:shell_out!).with("stopsrc -s #{@new_resource.service_name}") + expect(@provider).to receive(:shell_out!).with("stopsrc -s #{@new_resource.service_name}") @provider.stop_service end @@ -157,13 +157,13 @@ describe Chef::Provider::Service::Aix do it "should call the reload command for groups" do @provider.instance_eval('@is_resource_group = true') - @provider.should_receive(:shell_out!).with("refresh -g #{@new_resource.service_name}") + expect(@provider).to receive(:shell_out!).with("refresh -g #{@new_resource.service_name}") @provider.reload_service end it "should call the reload command for subsystem" do - @provider.should_receive(:shell_out!).with("refresh -s #{@new_resource.service_name}") + expect(@provider).to receive(:shell_out!).with("refresh -s #{@new_resource.service_name}") @provider.reload_service end @@ -171,8 +171,8 @@ describe Chef::Provider::Service::Aix do describe "when restarting the service" do it "should call stop service followed by start service" do - @provider.should_receive(:stop_service) - @provider.should_receive(:start_service) + expect(@provider).to receive(:stop_service) + expect(@provider).to receive(:start_service) @provider.restart_service end diff --git a/spec/unit/provider/service/aixinit_service_spec.rb b/spec/unit/provider/service/aixinit_service_spec.rb index bb090b112c..e4c9faa8b4 100644 --- a/spec/unit/provider/service/aixinit_service_spec.rb +++ b/spec/unit/provider/service/aixinit_service_spec.rb @@ -36,7 +36,7 @@ describe Chef::Provider::Service::AixInit do describe "load_current_resource" do it "sets current resource attributes" do - @provider.should_receive(:set_current_resource_attributes) + expect(@provider).to receive(:set_current_resource_attributes) @provider.load_current_resource end @@ -45,19 +45,19 @@ describe Chef::Provider::Service::AixInit do describe "action_enable" do shared_examples_for "the service is up to date" do it "does not enable the service" do - @provider.should_not_receive(:enable_service) + expect(@provider).not_to receive(:enable_service) @provider.action_enable @provider.set_updated_status - @provider.new_resource.should_not be_updated + expect(@provider.new_resource).not_to be_updated end end shared_examples_for "the service is not up to date" do it "enables the service and sets the resource as updated" do - @provider.should_receive(:enable_service).and_return(true) + expect(@provider).to receive(:enable_service).and_return(true) @provider.action_enable @provider.set_updated_status - @provider.new_resource.should be_updated + expect(@provider.new_resource).to be_updated end end @@ -97,12 +97,12 @@ describe Chef::Provider::Service::AixInit do describe "enable_service" do before do - Dir.stub(:glob).with(["/etc/rc.d/rc2.d/[SK][0-9][0-9]#{@new_resource.service_name}", "/etc/rc.d/rc2.d/[SK]#{@new_resource.service_name}"]).and_return([]) + allow(Dir).to receive(:glob).with(["/etc/rc.d/rc2.d/[SK][0-9][0-9]#{@new_resource.service_name}", "/etc/rc.d/rc2.d/[SK]#{@new_resource.service_name}"]).and_return([]) end context "when the service doesn't set a priority" do it "creates symlink with status S" do - @provider.should_receive(:create_symlink).with(2,'S','') + expect(@provider).to receive(:create_symlink).with(2,'S','') @provider.enable_service end @@ -114,7 +114,7 @@ describe Chef::Provider::Service::AixInit do end it "creates a symlink with status S and a priority" do - @provider.should_receive(:create_symlink).with(2,'S',75) + expect(@provider).to receive(:create_symlink).with(2,'S',75) @provider.enable_service end @@ -127,8 +127,8 @@ describe Chef::Provider::Service::AixInit do end it "create symlink with status start (S) or stop (K) and a priority " do - @provider.should_receive(:create_symlink).with(2,'S',20) - @provider.should_receive(:create_symlink).with(3,'K',10) + expect(@provider).to receive(:create_symlink).with(2,'S',20) + expect(@provider).to receive(:create_symlink).with(3,'K',10) @provider.enable_service end @@ -137,12 +137,12 @@ describe Chef::Provider::Service::AixInit do describe "disable_service" do before do - Dir.stub(:glob).with(["/etc/rc.d/rc2.d/[SK][0-9][0-9]#{@new_resource.service_name}", "/etc/rc.d/rc2.d/[SK]#{@new_resource.service_name}"]).and_return([]) + allow(Dir).to receive(:glob).with(["/etc/rc.d/rc2.d/[SK][0-9][0-9]#{@new_resource.service_name}", "/etc/rc.d/rc2.d/[SK]#{@new_resource.service_name}"]).and_return([]) end context "when the service doesn't set a priority" do it "creates symlinks with status stop (K)" do - @provider.should_receive(:create_symlink).with(2,'K','') + expect(@provider).to receive(:create_symlink).with(2,'K','') @provider.disable_service end @@ -154,7 +154,7 @@ describe Chef::Provider::Service::AixInit do end it "create symlink with status stop (k) and a priority " do - @provider.should_receive(:create_symlink).with(2,'K',25) + expect(@provider).to receive(:create_symlink).with(2,'K',25) @provider.disable_service end @@ -167,7 +167,7 @@ describe Chef::Provider::Service::AixInit do end it "create symlink with status stop (k) and a priority " do - @provider.should_receive(:create_symlink).with(3,'K',90) + expect(@provider).to receive(:create_symlink).with(3,'K',90) @provider.disable_service end @@ -179,12 +179,12 @@ describe Chef::Provider::Service::AixInit do before do files = ["/etc/rc.d/rc2.d/S20apache"] - Dir.stub(:glob).with(["/etc/rc.d/rc2.d/[SK][0-9][0-9]#{@new_resource.service_name}", "/etc/rc.d/rc2.d/[SK]chef"]).and_return(files) + allow(Dir).to receive(:glob).with(["/etc/rc.d/rc2.d/[SK][0-9][0-9]#{@new_resource.service_name}", "/etc/rc.d/rc2.d/[SK]chef"]).and_return(files) end it "the service is enabled" do - @provider.current_resource.should_receive(:enabled).with(true) - @provider.current_resource.should_receive(:priority).with(20) + expect(@provider.current_resource).to receive(:enabled).with(true) + expect(@provider.current_resource).to receive(:priority).with(20) @provider.set_current_resource_attributes end @@ -195,11 +195,11 @@ describe Chef::Provider::Service::AixInit do files = ["/etc/rc.d/rc2.d/K20apache"] @priority = {2 => [:stop, 20]} - Dir.stub(:glob).with(["/etc/rc.d/rc2.d/[SK][0-9][0-9]#{@new_resource.service_name}", "/etc/rc.d/rc2.d/[SK]chef"]).and_return(files) + allow(Dir).to receive(:glob).with(["/etc/rc.d/rc2.d/[SK][0-9][0-9]#{@new_resource.service_name}", "/etc/rc.d/rc2.d/[SK]chef"]).and_return(files) end it "the service is not enabled" do - @provider.current_resource.should_receive(:enabled).with(false) - @provider.current_resource.should_receive(:priority).with(@priority) + expect(@provider.current_resource).to receive(:enabled).with(false) + expect(@provider.current_resource).to receive(:priority).with(@priority) @provider.set_current_resource_attributes end @@ -210,11 +210,11 @@ describe Chef::Provider::Service::AixInit do @files = ["/etc/rc.d/rc2.d/S20apache", "/etc/rc.d/rc2.d/K80apache"] @priority = {2 => [:start, 20], 2 => [:stop, 80]} - Dir.stub(:glob).with(["/etc/rc.d/rc2.d/[SK][0-9][0-9]#{@new_resource.service_name}", "/etc/rc.d/rc2.d/[SK]chef"]).and_return(@files) + allow(Dir).to receive(:glob).with(["/etc/rc.d/rc2.d/[SK][0-9][0-9]#{@new_resource.service_name}", "/etc/rc.d/rc2.d/[SK]chef"]).and_return(@files) end it "the service is enabled" do - @current_resource.should_receive(:enabled).with(true) - @current_resource.should_receive(:priority).with(@priority) + expect(@current_resource).to receive(:enabled).with(true) + expect(@current_resource).to receive(:priority).with(@priority) @provider.set_current_resource_attributes end @@ -224,12 +224,12 @@ describe Chef::Provider::Service::AixInit do before do files = ["/etc/rc.d/rc2.d/Sapache"] - Dir.stub(:glob).with(["/etc/rc.d/rc2.d/[SK][0-9][0-9]#{@new_resource.service_name}", "/etc/rc.d/rc2.d/[SK]#{@new_resource.service_name}"]).and_return(files) + allow(Dir).to receive(:glob).with(["/etc/rc.d/rc2.d/[SK][0-9][0-9]#{@new_resource.service_name}", "/etc/rc.d/rc2.d/[SK]#{@new_resource.service_name}"]).and_return(files) end it "the service is enabled" do - @provider.current_resource.should_receive(:enabled).with(true) - @provider.current_resource.should_receive(:priority).with('') + expect(@provider.current_resource).to receive(:enabled).with(true) + expect(@provider.current_resource).to receive(:priority).with('') @provider.set_current_resource_attributes end @@ -240,11 +240,11 @@ describe Chef::Provider::Service::AixInit do files = ["/etc/rc.d/rc2.d/Kapache"] @priority = {2 => [:stop, '']} - Dir.stub(:glob).with(["/etc/rc.d/rc2.d/[SK][0-9][0-9]#{@new_resource.service_name}", "/etc/rc.d/rc2.d/[SK]#{@new_resource.service_name}"]).and_return(files) + allow(Dir).to receive(:glob).with(["/etc/rc.d/rc2.d/[SK][0-9][0-9]#{@new_resource.service_name}", "/etc/rc.d/rc2.d/[SK]#{@new_resource.service_name}"]).and_return(files) end it "the service is not enabled" do - @provider.current_resource.should_receive(:enabled).with(false) - @provider.current_resource.should_receive(:priority).with(@priority) + expect(@provider.current_resource).to receive(:enabled).with(false) + expect(@provider.current_resource).to receive(:priority).with(@priority) @provider.set_current_resource_attributes end @@ -255,11 +255,11 @@ describe Chef::Provider::Service::AixInit do files = ["/etc/rc.d/rc2.d/Sapache", "/etc/rc.d/rc2.d/Kapache"] @priority = {2 => [:start, ''], 2 => [:stop, '']} - Dir.stub(:glob).with(["/etc/rc.d/rc2.d/[SK][0-9][0-9]#{@new_resource.service_name}", "/etc/rc.d/rc2.d/[SK]#{@new_resource.service_name}"]).and_return(files) + allow(Dir).to receive(:glob).with(["/etc/rc.d/rc2.d/[SK][0-9][0-9]#{@new_resource.service_name}", "/etc/rc.d/rc2.d/[SK]#{@new_resource.service_name}"]).and_return(files) end it "the service is enabled" do - @current_resource.should_receive(:enabled).with(true) - @current_resource.should_receive(:priority).with(@priority) + expect(@current_resource).to receive(:enabled).with(true) + expect(@current_resource).to receive(:priority).with(@priority) @provider.set_current_resource_attributes end diff --git a/spec/unit/provider/service/arch_service_spec.rb b/spec/unit/provider/service/arch_service_spec.rb index 38ed74cdee..e71d9adfad 100644 --- a/spec/unit/provider/service/arch_service_spec.rb +++ b/spec/unit/provider/service/arch_service_spec.rb @@ -37,15 +37,15 @@ 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)") + allow(::File).to receive(:exists?).with("/etc/rc.conf").and_return(true) + allow(::File).to receive(:read).with("/etc/rc.conf").and_return("DAEMONS=(network apache sshd)") end describe "when first created" do it "should set the current resources service name to the new resources service name" do - @provider.stub(:shell_out).and_return(OpenStruct.new(:exitstatus => 0, :stdout => "")) + allow(@provider).to receive(:shell_out).and_return(OpenStruct.new(:exitstatus => 0, :stdout => "")) @provider.load_current_resource - @provider.current_resource.service_name.should == 'chef' + expect(@provider.current_resource.service_name).to eq('chef') end end @@ -55,26 +55,26 @@ describe Chef::Provider::Service::Arch, "load_current_resource" do end it "should run '/etc/rc.d/service_name status'" do - @provider.should_receive(:shell_out).with("/etc/rc.d/chef status").and_return(OpenStruct.new(:exitstatus => 0)) + expect(@provider).to receive(:shell_out).with("/etc/rc.d/chef status").and_return(OpenStruct.new(:exitstatus => 0)) @provider.load_current_resource 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)) + allow(@provider).to receive(: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 + expect(@provider.current_resource.running).to 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)) + allow(@provider).to receive(: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 + expect(@provider.current_resource.running).to 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) + allow(@provider).to receive(:shell_out).with("/etc/rc.d/chef status").and_raise(Mixlib::ShellOut::ShellCommandFailed) @provider.load_current_resource - @provider.current_resource.running.should be_false + expect(@provider.current_resource.running).to be_false end end @@ -85,7 +85,7 @@ describe Chef::Provider::Service::Arch, "load_current_resource" do end it "should run the services status command if one has been specified" do - @provider.should_receive(:shell_out).with("/etc/rc.d/chefhasmonkeypants status").and_return(OpenStruct.new(:exitstatus => 0)) + expect(@provider).to receive(:shell_out).with("/etc/rc.d/chefhasmonkeypants status").and_return(OpenStruct.new(:exitstatus => 0)) @provider.load_current_resource end @@ -95,24 +95,24 @@ describe Chef::Provider::Service::Arch, "load_current_resource" do @node.automatic_attrs[:command] = {:ps => nil} @provider.define_resource_requirements @provider.action = :start - lambda { @provider.process_resource_requirements }.should raise_error(Chef::Exceptions::Service) + expect { @provider.process_resource_requirements }.to raise_error(Chef::Exceptions::Service) end it "should raise error if the node has an empty ps attribute and no other means to get status" do @node.automatic_attrs[:command] = {:ps => ""} @provider.define_resource_requirements @provider.action = :start - lambda { @provider.process_resource_requirements }.should raise_error(Chef::Exceptions::Service) + expect { @provider.process_resource_requirements }.to raise_error(Chef::Exceptions::Service) end it "should fail if file /etc/rc.conf does not exist" do - ::File.stub(:exists?).with("/etc/rc.conf").and_return(false) - lambda { @provider.load_current_resource }.should raise_error(Chef::Exceptions::Service) + allow(::File).to receive(:exists?).with("/etc/rc.conf").and_return(false) + expect { @provider.load_current_resource }.to 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("") - lambda { @provider.load_current_resource }.should raise_error(Chef::Exceptions::Service) + allow(::File).to receive(:read).with("/etc/rc.conf").and_return("") + expect { @provider.load_current_resource }.to raise_error(Chef::Exceptions::Service) end describe "when discovering service status with ps" do @@ -123,7 +123,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 = double("Status", :exitstatus => 0, :stdout => @stdout) - @provider.stub(:shell_out!).and_return(@status) + allow(@provider).to receive(:shell_out!).and_return(@status) @node.automatic_attrs[:command] = {:ps => "ps -ef"} end @@ -133,29 +133,29 @@ 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) + allow(@status).to receive(:stdout).and_return(@stdout) @provider.load_current_resource - @provider.current_resource.running.should be_true + expect(@provider.current_resource.running).to 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) + allow(@provider).to receive(:shell_out!).and_return(@status) @provider.load_current_resource - @provider.current_resource.running.should be_false + expect(@provider.current_resource.running).to be_false end it "should raise an exception if ps fails" do - @provider.stub(:shell_out!).and_raise(Mixlib::ShellOut::ShellCommandFailed) + allow(@provider).to receive(:shell_out!).and_raise(Mixlib::ShellOut::ShellCommandFailed) @provider.load_current_resource @provider.action = :start @provider.define_resource_requirements - lambda { @provider.process_resource_requirements }.should raise_error(Chef::Exceptions::Service) + expect { @provider.process_resource_requirements }.to raise_error(Chef::Exceptions::Service) end end it "should return existing entries in DAEMONS array" do - ::File.stub(:read).with("/etc/rc.conf").and_return("DAEMONS=(network !apache ssh)") - @provider.daemons.should == ['network', '!apache', 'ssh'] + allow(::File).to receive(:read).with("/etc/rc.conf").and_return("DAEMONS=(network !apache ssh)") + expect(@provider.daemons).to eq(['network', '!apache', 'ssh']) end context "when the current service status is known" do @@ -179,8 +179,8 @@ RUNNING_PS # end it "should add chef to DAEMONS array" do - ::File.stub(:read).with("/etc/rc.conf").and_return("DAEMONS=(network)") - @provider.should_receive(:update_daemons).with(['network', 'chef']) + allow(::File).to receive(:read).with("/etc/rc.conf").and_return("DAEMONS=(network)") + expect(@provider).to receive(:update_daemons).with(['network', 'chef']) @provider.enable_service() end end @@ -200,8 +200,8 @@ RUNNING_PS # end it "should remove chef from DAEMONS array" do - ::File.stub(:read).with("/etc/rc.conf").and_return("DAEMONS=(network chef)") - @provider.should_receive(:update_daemons).with(['network', '!chef']) + allow(::File).to receive(:read).with("/etc/rc.conf").and_return("DAEMONS=(network chef)") + expect(@provider).to receive(:update_daemons).with(['network', '!chef']) @provider.disable_service() end end @@ -221,13 +221,13 @@ RUNNING_PS # end it "should call the start command if one is specified" do - @new_resource.stub(:start_command).and_return("/etc/rc.d/chef startyousillysally") - @provider.should_receive(:shell_out_with_systems_locale!).with("/etc/rc.d/chef startyousillysally") + allow(@new_resource).to receive(:start_command).and_return("/etc/rc.d/chef startyousillysally") + expect(@provider).to receive(:shell_out_with_systems_locale!).with("/etc/rc.d/chef startyousillysally") @provider.start_service() end it "should call '/etc/rc.d/service_name start' if no start command is specified" do - @provider.should_receive(:shell_out_with_systems_locale!).with("/etc/rc.d/#{@new_resource.service_name} start") + expect(@provider).to receive(:shell_out_with_systems_locale!).with("/etc/rc.d/#{@new_resource.service_name} start") @provider.start_service() end end @@ -247,13 +247,13 @@ RUNNING_PS # end it "should call the stop command if one is specified" do - @new_resource.stub(:stop_command).and_return("/etc/rc.d/chef itoldyoutostop") - @provider.should_receive(:shell_out_with_systems_locale!).with("/etc/rc.d/chef itoldyoutostop") + allow(@new_resource).to receive(:stop_command).and_return("/etc/rc.d/chef itoldyoutostop") + expect(@provider).to receive(:shell_out_with_systems_locale!).with("/etc/rc.d/chef itoldyoutostop") @provider.stop_service() end it "should call '/etc/rc.d/service_name stop' if no stop command is specified" do - @provider.should_receive(:shell_out_with_systems_locale!).with("/etc/rc.d/#{@new_resource.service_name} stop") + expect(@provider).to receive(:shell_out_with_systems_locale!).with("/etc/rc.d/#{@new_resource.service_name} stop") @provider.stop_service() end end @@ -274,21 +274,21 @@ RUNNING_PS # end it "should call 'restart' on the service_name if the resource supports it" do - @new_resource.stub(:supports).and_return({:restart => true}) - @provider.should_receive(:shell_out_with_systems_locale!).with("/etc/rc.d/#{@new_resource.service_name} restart") + allow(@new_resource).to receive(:supports).and_return({:restart => true}) + expect(@provider).to receive(:shell_out_with_systems_locale!).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") - @provider.should_receive(:shell_out_with_systems_locale!).with("/etc/rc.d/#{@new_resource.service_name} restartinafire") + allow(@new_resource).to receive(:restart_command).and_return("/etc/rc.d/chef restartinafire") + expect(@provider).to receive(:shell_out_with_systems_locale!).with("/etc/rc.d/#{@new_resource.service_name} restartinafire") @provider.restart_service() end it "should just call stop, then start when the resource doesn't support restart and no restart_command is specified" do - @provider.should_receive(:stop_service) - @provider.should_receive(:sleep).with(1) - @provider.should_receive(:start_service) + expect(@provider).to receive(:stop_service) + expect(@provider).to receive(:sleep).with(1) + expect(@provider).to receive(:start_service) @provider.restart_service() end end @@ -309,14 +309,14 @@ RUNNING_PS # end it "should call 'reload' on the service if it supports it" do - @new_resource.stub(:supports).and_return({:reload => true}) - @provider.should_receive(:shell_out_with_systems_locale!).with("/etc/rc.d/#{@new_resource.service_name} reload") + allow(@new_resource).to receive(:supports).and_return({:reload => true}) + expect(@provider).to receive(:shell_out_with_systems_locale!).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") - @provider.should_receive(:shell_out_with_systems_locale!).with("/etc/rc.d/#{@new_resource.service_name} lollerpants") + allow(@new_resource).to receive(:reload_command).and_return("/etc/rc.d/chef lollerpants") + expect(@provider).to receive(:shell_out_with_systems_locale!).with("/etc/rc.d/#{@new_resource.service_name} lollerpants") @provider.reload_service() end end diff --git a/spec/unit/provider/service/debian_service_spec.rb b/spec/unit/provider/service/debian_service_spec.rb index 3e60857cbf..b974a6bf9e 100644 --- a/spec/unit/provider/service/debian_service_spec.rb +++ b/spec/unit/provider/service/debian_service_spec.rb @@ -36,17 +36,17 @@ describe Chef::Provider::Service::Debian do describe "load_current_resource" do it "ensures /usr/sbin/update-rc.d is available" do - File.should_receive(:exists?).with("/usr/sbin/update-rc.d") .and_return(false) + expect(File).to receive(:exists?).with("/usr/sbin/update-rc.d") .and_return(false) @provider.define_resource_requirements - lambda { + expect { @provider.process_resource_requirements - }.should raise_error(Chef::Exceptions::Service) + }.to raise_error(Chef::Exceptions::Service) end context "when update-rc.d shows init linked to rc*.d/" do before do - @provider.stub(:assert_update_rcd_available) + allow(@provider).to receive(:assert_update_rcd_available) result = <<-UPDATE_RC_D_SUCCESS Removing any system startup links for /etc/init.d/chef ... @@ -62,55 +62,55 @@ describe Chef::Provider::Service::Debian do @stdout = StringIO.new(result) @stderr = StringIO.new @status = double("Status", :exitstatus => 0, :stdout => @stdout) - @provider.stub(:shell_out!).and_return(@status) - @provider.stub(:popen4).and_yield(@pid, @stdin, @stdout, @stderr).and_return(@status) + allow(@provider).to receive(:shell_out!).and_return(@status) + allow(@provider).to receive(:popen4).and_yield(@pid, @stdin, @stdout, @stderr).and_return(@status) end it "says the service is enabled" do - @provider.service_currently_enabled?(@provider.get_priority).should be_true + expect(@provider.service_currently_enabled?(@provider.get_priority)).to be_true end it "stores the 'enabled' state" do - Chef::Resource::Service.stub(:new).and_return(@current_resource) - @provider.load_current_resource.should equal(@current_resource) - @current_resource.enabled.should be_true + allow(Chef::Resource::Service).to receive(:new).and_return(@current_resource) + expect(@provider.load_current_resource).to equal(@current_resource) + expect(@current_resource.enabled).to be_true end end context "when update-rc.d shows init isn't linked to rc*.d/" do before do - @provider.stub(:assert_update_rcd_available) + allow(@provider).to receive(:assert_update_rcd_available) @status = double("Status", :exitstatus => 0) @stdout = StringIO.new( " Removing any system startup links for /etc/init.d/chef ...") @stderr = StringIO.new @status = double("Status", :exitstatus => 0, :stdout => @stdout) - @provider.stub(:shell_out!).and_return(@status) - @provider.stub(:popen4).and_yield(@pid, @stdin, @stdout, @stderr).and_return(@status) + allow(@provider).to receive(:shell_out!).and_return(@status) + allow(@provider).to receive(:popen4).and_yield(@pid, @stdin, @stdout, @stderr).and_return(@status) end it "says the service is disabled" do - @provider.service_currently_enabled?(@provider.get_priority).should be_false + expect(@provider.service_currently_enabled?(@provider.get_priority)).to be_false end it "stores the 'disabled' state" do - Chef::Resource::Service.stub(:new).and_return(@current_resource) - @provider.load_current_resource.should equal(@current_resource) - @current_resource.enabled.should be_false + allow(Chef::Resource::Service).to receive(:new).and_return(@current_resource) + expect(@provider.load_current_resource).to equal(@current_resource) + expect(@current_resource.enabled).to be_false end end context "when update-rc.d fails" do before do @status = double("Status", :exitstatus => -1) - @provider.stub(:popen4).and_return(@status) + allow(@provider).to receive(:popen4).and_return(@status) end it "raises an error" do @provider.define_resource_requirements - lambda { + expect { @provider.process_resource_requirements - }.should raise_error(Chef::Exceptions::Service) + }.to raise_error(Chef::Exceptions::Service) end end @@ -196,49 +196,49 @@ 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) + allow(@provider).to receive(:assert_update_rcd_available) @stdout = StringIO.new(expected_results["linked"]["stdout"]) @stderr = StringIO.new(expected_results["linked"]["stderr"]) @status = double("Status", :exitstatus => 0, :stdout => @stdout) - @provider.stub(:shell_out!).and_return(@status) - @provider.stub(:popen4).and_yield(@pid, @stdin, @stdout, @stderr).and_return(@status) + allow(@provider).to receive(:shell_out!).and_return(@status) + allow(@provider).to receive(:popen4).and_yield(@pid, @stdin, @stdout, @stderr).and_return(@status) end it "says the service is enabled" do - @provider.service_currently_enabled?(@provider.get_priority).should be_true + expect(@provider.service_currently_enabled?(@provider.get_priority)).to be_true end it "stores the 'enabled' state" do - Chef::Resource::Service.stub(:new).and_return(@current_resource) - @provider.load_current_resource.should equal(@current_resource) - @current_resource.enabled.should be_true + allow(Chef::Resource::Service).to receive(:new).and_return(@current_resource) + expect(@provider.load_current_resource).to equal(@current_resource) + expect(@current_resource.enabled).to be_true end it "stores the start/stop priorities of the service" do @provider.load_current_resource - @provider.current_resource.priority.should == expected_results["linked"]["priorities"] + expect(@provider.current_resource.priority).to eq(expected_results["linked"]["priorities"]) end end context "when update-rc.d shows init isn't linked to rc*.d/" do before do - @provider.stub(:assert_update_rcd_available) + allow(@provider).to receive(:assert_update_rcd_available) @stdout = StringIO.new(expected_results["not linked"]["stdout"]) @stderr = StringIO.new(expected_results["not linked"]["stderr"]) @status = double("Status", :exitstatus => 0, :stdout => @stdout) - @provider.stub(:shell_out!).and_return(@status) - @provider.stub(:popen4).and_yield(@pid, @stdin, @stdout, @stderr).and_return(@status) + allow(@provider).to receive(:shell_out!).and_return(@status) + allow(@provider).to receive(:popen4).and_yield(@pid, @stdin, @stdout, @stderr).and_return(@status) end it "says the service is disabled" do - @provider.service_currently_enabled?(@provider.get_priority).should be_false + expect(@provider.service_currently_enabled?(@provider.get_priority)).to be_false end it "stores the 'disabled' state" do - Chef::Resource::Service.stub(:new).and_return(@current_resource) - @provider.load_current_resource.should equal(@current_resource) - @current_resource.enabled.should be_false + allow(Chef::Resource::Service).to receive(:new).and_return(@current_resource) + expect(@provider.load_current_resource).to equal(@current_resource) + expect(@current_resource.enabled).to be_false end end end @@ -249,19 +249,19 @@ insserv: dryrun, not creating .depend.boot, .depend.start, and .depend.stop describe "action_enable" do shared_examples_for "the service is up to date" do it "does not enable the service" do - @provider.should_not_receive(:enable_service) + expect(@provider).not_to receive(:enable_service) @provider.action_enable @provider.set_updated_status - @provider.new_resource.should_not be_updated + expect(@provider.new_resource).not_to be_updated end end shared_examples_for "the service is not up to date" do it "enables the service and sets the resource as updated" do - @provider.should_receive(:enable_service).and_return(true) + expect(@provider).to receive(:enable_service).and_return(true) @provider.action_enable @provider.set_updated_status - @provider.new_resource.should be_updated + expect(@provider.new_resource).to be_updated end end @@ -301,7 +301,7 @@ insserv: dryrun, not creating .depend.boot, .depend.start, and .depend.stop def expect_commands(provider, commands) commands.each do |command| - provider.should_receive(:shell_out!).with(command) + expect(provider).to receive(:shell_out!).with(command) end end diff --git a/spec/unit/provider/service/gentoo_service_spec.rb b/spec/unit/provider/service/gentoo_service_spec.rb index 022a73cc9a..04734e9c5d 100644 --- a/spec/unit/provider/service/gentoo_service_spec.rb +++ b/spec/unit/provider/service/gentoo_service_spec.rb @@ -29,72 +29,72 @@ 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) + allow(Chef::Resource::Service).to receive(:new).and_return(@current_resource) @status = double("Status", :exitstatus => 0, :stdout => @stdout) - @provider.stub(:shell_out).and_return(@status) - File.stub(:exists?).with("/etc/init.d/chef").and_return(true) - File.stub(:exists?).with("/sbin/rc-update").and_return(true) - File.stub(:exists?).with("/etc/runlevels/default/chef").and_return(false) - File.stub(:readable?).with("/etc/runlevels/default/chef").and_return(false) + allow(@provider).to receive(:shell_out).and_return(@status) + allow(File).to receive(:exists?).with("/etc/init.d/chef").and_return(true) + allow(File).to receive(:exists?).with("/sbin/rc-update").and_return(true) + allow(File).to receive(:exists?).with("/etc/runlevels/default/chef").and_return(false) + allow(File).to receive(:readable?).with("/etc/runlevels/default/chef").and_return(false) end # new test: found_enabled state # describe "load_current_resource" do it "should raise Chef::Exceptions::Service if /sbin/rc-update does not exist" do - File.should_receive(:exists?).with("/sbin/rc-update").and_return(false) + expect(File).to receive(:exists?).with("/sbin/rc-update").and_return(false) @provider.define_resource_requirements - lambda { @provider.process_resource_requirements }.should raise_error(Chef::Exceptions::Service) + expect { @provider.process_resource_requirements }.to raise_error(Chef::Exceptions::Service) end it "should track when service file is not found in /etc/runlevels" do @provider.load_current_resource - @provider.instance_variable_get("@found_script").should be_false + expect(@provider.instance_variable_get("@found_script")).to be_false 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"]) + allow(Dir).to receive(:glob).with("/etc/runlevels/**/chef").and_return(["/etc/runlevels/default/chef"]) @provider.load_current_resource - @provider.instance_variable_get("@found_script").should be_true + expect(@provider.instance_variable_get("@found_script")).to be_true end 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"]) + allow(Dir).to receive(: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) + allow(File).to receive(:exists?).with("/etc/runlevels/default/chef").and_return(true) + allow(File).to receive(:readable?).with("/etc/runlevels/default/chef").and_return(true) end it "should set enabled to true" do @provider.load_current_resource - @current_resource.enabled.should be_true + expect(@current_resource.enabled).to be_true end end 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) + allow(File).to receive(:exists?).with("/etc/runlevels/default/chef").and_return(true) + allow(File).to receive(:readable?).with("/etc/runlevels/default/chef").and_return(false) end it "should set enabled to false" do @provider.load_current_resource - @current_resource.enabled.should be_false + expect(@current_resource.enabled).to be_false end end 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") + allow(File).to receive(:exists?).with("/etc/runlevels/default/chef").and_return(false) + allow(File).to receive(:readable?).with("/etc/runlevels/default/chef").and_return("foobarbaz") end it "should set enabled to false" do @provider.load_current_resource - @current_resource.enabled.should be_false + expect(@current_resource.enabled).to be_false end end @@ -103,39 +103,39 @@ describe Chef::Provider::Service::Gentoo do end it "should return the current_resource" do - @provider.load_current_resource.should == @current_resource + expect(@provider.load_current_resource).to eq(@current_resource) end it "should support the status command automatically" do @provider.load_current_resource - @new_resource.supports[:status].should be_true + expect(@new_resource.supports[:status]).to be_true end it "should support the restart command automatically" do @provider.load_current_resource - @new_resource.supports[:restart].should be_true + expect(@new_resource.supports[:restart]).to be_true end it "should not support the reload command automatically" do @provider.load_current_resource - @new_resource.supports[:reload].should_not be_true + expect(@new_resource.supports[:reload]).not_to be_true end end describe "action_methods" do - before(:each) { @provider.stub(:load_current_resource).and_return(@current_resource) } + before(:each) { allow(@provider).to receive(:load_current_resource).and_return(@current_resource) } describe Chef::Provider::Service::Gentoo, "enable_service" do it "should call rc-update add *service* default" do - @provider.should_receive(:shell_out!).with("/sbin/rc-update add chef default") + expect(@provider).to receive(:shell_out!).with("/sbin/rc-update add chef default") @provider.enable_service() end end describe Chef::Provider::Service::Gentoo, "disable_service" do it "should call rc-update del *service* default" do - @provider.should_receive(:shell_out!).with("/sbin/rc-update del chef default") + expect(@provider).to receive(:shell_out!).with("/sbin/rc-update del chef default") @provider.disable_service() end end diff --git a/spec/unit/provider/service/init_service_spec.rb b/spec/unit/provider/service/init_service_spec.rb index b523f6d3a9..5dc5256061 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) + allow(Chef::Resource::Service).to receive(:new).and_return(@current_resource) @stdout = StringIO.new(<<-PS) aj 7842 5057 0 21:26 pts/2 00:00:06 vi init.rb @@ -38,17 +38,17 @@ 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 = double("Status", :exitstatus => 0, :stdout => @stdout) - @provider.stub(:shell_out!).and_return(@status) + allow(@provider).to receive(:shell_out!).and_return(@status) end it "should create a current resource with the name of the new resource" do @provider.load_current_resource - @provider.current_resource.should equal(@current_resource) + expect(@provider.current_resource).to equal(@current_resource) end it "should set the current resources service name to the new resources service name" do @provider.load_current_resource - @current_resource.service_name.should == 'chef' + expect(@current_resource.service_name).to eq('chef') end describe "when the service supports status" do @@ -57,37 +57,37 @@ PS end it "should run '/etc/init.d/service_name status'" do - @provider.should_receive(:shell_out).with("/etc/init.d/#{@current_resource.service_name} status").and_return(@status) + expect(@provider).to receive(:shell_out).with("/etc/init.d/#{@current_resource.service_name} status").and_return(@status) @provider.load_current_resource 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) + allow(@provider).to receive(:shell_out).with("/etc/init.d/#{@current_resource.service_name} status").and_return(@status) @provider.load_current_resource - @current_resource.running.should be_true + expect(@current_resource.running).to 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) + allow(@status).to receive(:exitstatus).and_return(1) + allow(@provider).to receive(:shell_out).with("/etc/init.d/#{@current_resource.service_name} status").and_return(@status) @provider.load_current_resource - @current_resource.running.should be_false + expect(@current_resource.running).to be_false end it "should set running to false if the status command raises" do - @provider.stub(:shell_out).and_raise(Mixlib::ShellOut::ShellCommandFailed) + allow(@provider).to receive(:shell_out).and_raise(Mixlib::ShellOut::ShellCommandFailed) @provider.load_current_resource - @current_resource.running.should be_false + expect(@current_resource.running).to be_false end end describe "when a status command has been specified" do before do - @new_resource.stub(:status_command).and_return("/etc/init.d/chefhasmonkeypants status") + allow(@new_resource).to receive(:status_command).and_return("/etc/init.d/chefhasmonkeypants status") end it "should run the services status command if one has been specified" do - @provider.should_receive(:shell_out).with("/etc/init.d/chefhasmonkeypants status").and_return(@status) + expect(@provider).to receive(:shell_out).with("/etc/init.d/chefhasmonkeypants status").and_return(@status) @provider.load_current_resource end @@ -95,12 +95,12 @@ PS describe "when an init command has been specified" do before do - @new_resource.stub(:init_command).and_return("/opt/chef-server/service/erchef") + allow(@new_resource).to receive(:init_command).and_return("/opt/chef-server/service/erchef") @provider = Chef::Provider::Service::Init.new(@new_resource, @run_context) end it "should use the init_command if one has been specified" do - @provider.should_receive(:shell_out_with_systems_locale!).with("/opt/chef-server/service/erchef start") + expect(@provider).to receive(:shell_out_with_systems_locale!).with("/opt/chef-server/service/erchef start") @provider.start_service end @@ -113,7 +113,7 @@ PS @provider.load_current_resource @provider.action = :start @provider.define_resource_requirements - lambda { @provider.process_resource_requirements }.should raise_error(Chef::Exceptions::Service) + expect { @provider.process_resource_requirements }.to raise_error(Chef::Exceptions::Service) end it "should raise an error if the node has an empty ps attribute" do @@ -121,14 +121,14 @@ PS @provider.load_current_resource @provider.action = :start @provider.define_resource_requirements - lambda { @provider.process_resource_requirements }.should raise_error(Chef::Exceptions::Service) + expect { @provider.process_resource_requirements }.to raise_error(Chef::Exceptions::Service) end end describe "when we have a 'ps' attribute" do it "should shell_out! the node's ps command" do - @provider.should_receive(:shell_out!).and_return(@status) + expect(@provider).to receive(:shell_out!).and_return(@status) @provider.load_current_resource end @@ -137,39 +137,39 @@ 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) + allow(@status).to receive(:stdout).and_return(@stdout) @provider.load_current_resource - @current_resource.running.should be_true + expect(@current_resource.running).to be_true end it "should set running to false if the regex doesn't match" do - @provider.stub(:shell_out!).and_return(@status) + allow(@provider).to receive(:shell_out!).and_return(@status) @provider.load_current_resource - @current_resource.running.should be_false + expect(@current_resource.running).to be_false end it "should raise an exception if ps fails" do - @provider.stub(:shell_out!).and_raise(Mixlib::ShellOut::ShellCommandFailed) + allow(@provider).to receive(:shell_out!).and_raise(Mixlib::ShellOut::ShellCommandFailed) @provider.load_current_resource @provider.action = :start @provider.define_resource_requirements - lambda { @provider.process_resource_requirements }.should raise_error(Chef::Exceptions::Service) + expect { @provider.process_resource_requirements }.to raise_error(Chef::Exceptions::Service) end end it "should return the current resource" do - @provider.load_current_resource.should eql(@current_resource) + expect(@provider.load_current_resource).to eql(@current_resource) end describe "when starting the service" do it "should call the start command if one is specified" do @new_resource.start_command("/etc/init.d/chef startyousillysally") - @provider.should_receive(:shell_out_with_systems_locale!).with("/etc/init.d/chef startyousillysally") + expect(@provider).to receive(:shell_out_with_systems_locale!).with("/etc/init.d/chef startyousillysally") @provider.start_service() end it "should call '/etc/init.d/service_name start' if no start command is specified" do - @provider.should_receive(:shell_out_with_systems_locale!).with("/etc/init.d/#{@new_resource.service_name} start") + expect(@provider).to receive(:shell_out_with_systems_locale!).with("/etc/init.d/#{@new_resource.service_name} start") @provider.start_service() end end @@ -177,12 +177,12 @@ RUNNING_PS describe Chef::Provider::Service::Init, "stop_service" do it "should call the stop command if one is specified" do @new_resource.stop_command("/etc/init.d/chef itoldyoutostop") - @provider.should_receive(:shell_out_with_systems_locale!).with("/etc/init.d/chef itoldyoutostop") + expect(@provider).to receive(:shell_out_with_systems_locale!).with("/etc/init.d/chef itoldyoutostop") @provider.stop_service() end it "should call '/etc/init.d/service_name stop' if no stop command is specified" do - @provider.should_receive(:shell_out_with_systems_locale!).with("/etc/init.d/#{@new_resource.service_name} stop") + expect(@provider).to receive(:shell_out_with_systems_locale!).with("/etc/init.d/#{@new_resource.service_name} stop") @provider.stop_service() end end @@ -190,20 +190,20 @@ RUNNING_PS describe "when restarting a service" do it "should call 'restart' on the service_name if the resource supports it" do @new_resource.supports({:restart => true}) - @provider.should_receive(:shell_out_with_systems_locale!).with("/etc/init.d/#{@new_resource.service_name} restart") + expect(@provider).to receive(:shell_out_with_systems_locale!).with("/etc/init.d/#{@new_resource.service_name} restart") @provider.restart_service() end it "should call the restart_command if one has been specified" do @new_resource.restart_command("/etc/init.d/chef restartinafire") - @provider.should_receive(:shell_out_with_systems_locale!).with("/etc/init.d/#{@new_resource.service_name} restartinafire") + expect(@provider).to receive(:shell_out_with_systems_locale!).with("/etc/init.d/#{@new_resource.service_name} restartinafire") @provider.restart_service() end it "should just call stop, then start when the resource doesn't support restart and no restart_command is specified" do - @provider.should_receive(:stop_service) - @provider.should_receive(:sleep).with(1) - @provider.should_receive(:start_service) + expect(@provider).to receive(:stop_service) + expect(@provider).to receive(:sleep).with(1) + expect(@provider).to receive(:start_service) @provider.restart_service() end end @@ -211,13 +211,13 @@ RUNNING_PS describe "when reloading a service" do it "should call 'reload' on the service if it supports it" do @new_resource.supports({:reload => true}) - @provider.should_receive(:shell_out_with_systems_locale!).with("/etc/init.d/chef reload") + expect(@provider).to receive(:shell_out_with_systems_locale!).with("/etc/init.d/chef 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.reload_command("/etc/init.d/chef lollerpants") - @provider.should_receive(:shell_out_with_systems_locale!).with("/etc/init.d/chef lollerpants") + expect(@provider).to receive(:shell_out_with_systems_locale!).with("/etc/init.d/chef lollerpants") @provider.reload_service() end end @@ -225,11 +225,11 @@ RUNNING_PS describe "when a custom command has been specified" do before do @new_resource.start_command("/etc/init.d/chef startyousillysally") - @provider.should_receive(:shell_out_with_systems_locale!).with("/etc/init.d/chef startyousillysally") + expect(@provider).to receive(:shell_out_with_systems_locale!).with("/etc/init.d/chef startyousillysally") end it "should still pass all why run assertions" do - lambda { @provider.run_action(:start) }.should_not raise_error + expect { @provider.run_action(:start) }.not_to raise_error end end end diff --git a/spec/unit/provider/service/insserv_service_spec.rb b/spec/unit/provider/service/insserv_service_spec.rb index 9ed03b519f..6cead238fe 100644 --- a/spec/unit/provider/service/insserv_service_spec.rb +++ b/spec/unit/provider/service/insserv_service_spec.rb @@ -30,29 +30,29 @@ describe Chef::Provider::Service::Insserv do @provider = Chef::Provider::Service::Insserv.new(@new_resource, @run_context) @status = double("Process::Status mock", :exitstatus => 0, :stdout => "") - @provider.stub(:shell_out!).and_return(@status) + allow(@provider).to receive(: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"]) + allow(Dir).to receive(: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 @provider.load_current_resource - @provider.current_resource.enabled.should be_true + expect(@provider.current_resource.enabled).to be_true end end describe "when startup links do not exist" do before do - Dir.stub(:glob).with("/etc/rc**/S*initgrediant").and_return([]) + allow(Dir).to receive(:glob).with("/etc/rc**/S*initgrediant").and_return([]) end it "sets the current enabled status to false" do @provider.load_current_resource - @provider.current_resource.enabled.should be_false + expect(@provider.current_resource.enabled).to be_false end end @@ -60,15 +60,15 @@ describe Chef::Provider::Service::Insserv do describe "enable_service" do it "should call insserv and create the default links" do - @provider.should_receive(:shell_out!).with("/sbin/insserv -r -f #{@new_resource.service_name}") - @provider.should_receive(:shell_out!).with("/sbin/insserv -d -f #{@new_resource.service_name}") + expect(@provider).to receive(:shell_out!).with("/sbin/insserv -r -f #{@new_resource.service_name}") + expect(@provider).to receive(:shell_out!).with("/sbin/insserv -d -f #{@new_resource.service_name}") @provider.enable_service end end describe "disable_service" do it "should call insserv and remove the links" do - @provider.should_receive(:shell_out!).with("/sbin/insserv -r -f #{@new_resource.service_name}") + expect(@provider).to receive(:shell_out!).with("/sbin/insserv -r -f #{@new_resource.service_name}") @provider.disable_service end end diff --git a/spec/unit/provider/service/invokercd_service_spec.rb b/spec/unit/provider/service/invokercd_service_spec.rb index d8a9851837..0b3b799798 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) + allow(Chef::Resource::Service).to receive(:new).and_return(@current_resource) @stdout = StringIO.new(<<-PS) aj 7842 5057 0 21:26 pts/2 00:00:06 vi init.rb @@ -38,17 +38,17 @@ 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 = double("Status", :exitstatus => 0, :stdout => @stdout) - @provider.stub(:shell_out!).and_return(@status) + allow(@provider).to receive(:shell_out!).and_return(@status) end it "should create a current resource with the name of the new resource" do @provider.load_current_resource - @provider.current_resource.should equal(@current_resource) + expect(@provider.current_resource).to equal(@current_resource) end it "should set the current resources service name to the new resources service name" do @provider.load_current_resource - @current_resource.service_name.should == 'chef' + expect(@current_resource.service_name).to eq('chef') end describe "when the service supports status" do @@ -57,37 +57,37 @@ PS end it "should run '/usr/sbin/invoke-rc.d service_name status'" do - @provider.should_receive(:shell_out).with("/usr/sbin/invoke-rc.d #{@current_resource.service_name} status").and_return(@status) + expect(@provider).to receive(:shell_out).with("/usr/sbin/invoke-rc.d #{@current_resource.service_name} status").and_return(@status) @provider.load_current_resource 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) + allow(@provider).to receive(: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 + expect(@current_resource.running).to 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) + allow(@status).to receive(:exitstatus).and_return(1) + allow(@provider).to receive(: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 + expect(@current_resource.running).to 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) + allow(@provider).to receive(: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 + expect(@current_resource.running).to be_false end end 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") + allow(@new_resource).to receive(: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 - @provider.should_receive(:shell_out).with("/usr/sbin/invoke-rc.d chefhasmonkeypants status").and_return(@status) + expect(@provider).to receive(:shell_out).with("/usr/sbin/invoke-rc.d chefhasmonkeypants status").and_return(@status) @provider.load_current_resource end @@ -98,14 +98,14 @@ PS @node.automatic_attrs[:command] = {:ps => nil} @provider.action = :start @provider.define_resource_requirements - lambda { @provider.process_resource_requirements }.should raise_error(Chef::Exceptions::Service) + expect { @provider.process_resource_requirements }.to raise_error(Chef::Exceptions::Service) end it "should raise error if the node has an empty ps attribute and no other means to get status" do @node.automatic_attrs[:command] = {:ps => ""} @provider.action = :start @provider.define_resource_requirements - lambda { @provider.process_resource_requirements }.should raise_error(Chef::Exceptions::Service) + expect { @provider.process_resource_requirements }.to raise_error(Chef::Exceptions::Service) end end @@ -113,7 +113,7 @@ PS describe "when we have a 'ps' attribute" do it "should shell_out! the node's ps command" do @status = double("Status", :exitstatus => 0, :stdout => @stdout) - @provider.should_receive(:shell_out!).with(@node[:command][:ps]).and_return(@status) + expect(@provider).to receive(:shell_out!).with(@node[:command][:ps]).and_return(@status) @provider.load_current_resource end @@ -123,40 +123,40 @@ 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 = double("Status", :exitstatus => 0, :stdout => @stdout) - @provider.should_receive(:shell_out!).and_return(@status) + expect(@provider).to receive(:shell_out!).and_return(@status) @provider.load_current_resource - @current_resource.running.should be_true + expect(@current_resource.running).to be_true end it "should set running to false if the regex doesn't match" do @status = double("Status", :exitstatus => 0, :stdout => @stdout) - @provider.should_receive(:shell_out!).and_return(@status) + expect(@provider).to receive(:shell_out!).and_return(@status) @provider.load_current_resource - @current_resource.running.should be_false + expect(@current_resource.running).to be_false end it "should raise an exception if ps fails" do - @provider.stub(:shell_out!).and_raise(Mixlib::ShellOut::ShellCommandFailed) + allow(@provider).to receive(:shell_out!).and_raise(Mixlib::ShellOut::ShellCommandFailed) @provider.action = :start @provider.load_current_resource @provider.define_resource_requirements - lambda { @provider.process_resource_requirements }.should raise_error(Chef::Exceptions::Service) + expect { @provider.process_resource_requirements }.to raise_error(Chef::Exceptions::Service) end end it "should return the current resource" do - @provider.load_current_resource.should eql(@current_resource) + expect(@provider.load_current_resource).to eql(@current_resource) end describe "when starting the service" do it "should call the start command if one is specified" do @new_resource.start_command("/usr/sbin/invoke-rc.d chef startyousillysally") - @provider.should_receive(:shell_out_with_systems_locale!).with("/usr/sbin/invoke-rc.d chef startyousillysally") + expect(@provider).to receive(:shell_out_with_systems_locale!).with("/usr/sbin/invoke-rc.d chef startyousillysally") @provider.start_service() end it "should call '/usr/sbin/invoke-rc.d service_name start' if no start command is specified" do - @provider.should_receive(:shell_out_with_systems_locale!).with("/usr/sbin/invoke-rc.d #{@new_resource.service_name} start") + expect(@provider).to receive(:shell_out_with_systems_locale!).with("/usr/sbin/invoke-rc.d #{@new_resource.service_name} start") @provider.start_service() end end @@ -164,12 +164,12 @@ RUNNING_PS describe Chef::Provider::Service::Invokercd, "stop_service" do it "should call the stop command if one is specified" do @new_resource.stop_command("/usr/sbin/invoke-rc.d chef itoldyoutostop") - @provider.should_receive(:shell_out_with_systems_locale!).with("/usr/sbin/invoke-rc.d chef itoldyoutostop") + expect(@provider).to receive(:shell_out_with_systems_locale!).with("/usr/sbin/invoke-rc.d chef itoldyoutostop") @provider.stop_service() end it "should call '/usr/sbin/invoke-rc.d service_name stop' if no stop command is specified" do - @provider.should_receive(:shell_out_with_systems_locale!).with("/usr/sbin/invoke-rc.d #{@new_resource.service_name} stop") + expect(@provider).to receive(:shell_out_with_systems_locale!).with("/usr/sbin/invoke-rc.d #{@new_resource.service_name} stop") @provider.stop_service() end end @@ -177,20 +177,20 @@ RUNNING_PS describe "when restarting a service" do it "should call 'restart' on the service_name if the resource supports it" do @new_resource.supports({:restart => true}) - @provider.should_receive(:shell_out_with_systems_locale!).with("/usr/sbin/invoke-rc.d #{@new_resource.service_name} restart") + expect(@provider).to receive(:shell_out_with_systems_locale!).with("/usr/sbin/invoke-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.restart_command("/usr/sbin/invoke-rc.d chef restartinafire") - @provider.should_receive(:shell_out_with_systems_locale!).with("/usr/sbin/invoke-rc.d #{@new_resource.service_name} restartinafire") + expect(@provider).to receive(:shell_out_with_systems_locale!).with("/usr/sbin/invoke-rc.d #{@new_resource.service_name} restartinafire") @provider.restart_service() end it "should just call stop, then start when the resource doesn't support restart and no restart_command is specified" do - @provider.should_receive(:stop_service) - @provider.should_receive(:sleep).with(1) - @provider.should_receive(:start_service) + expect(@provider).to receive(:stop_service) + expect(@provider).to receive(:sleep).with(1) + expect(@provider).to receive(:start_service) @provider.restart_service() end end @@ -198,13 +198,13 @@ RUNNING_PS describe "when reloading a service" do it "should call 'reload' on the service if it supports it" do @new_resource.supports({:reload => true}) - @provider.should_receive(:shell_out_with_systems_locale!).with("/usr/sbin/invoke-rc.d chef reload") + expect(@provider).to receive(:shell_out_with_systems_locale!).with("/usr/sbin/invoke-rc.d chef 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.reload_command("/usr/sbin/invoke-rc.d chef lollerpants") - @provider.should_receive(:shell_out_with_systems_locale!).with("/usr/sbin/invoke-rc.d chef lollerpants") + expect(@provider).to receive(:shell_out_with_systems_locale!).with("/usr/sbin/invoke-rc.d chef lollerpants") @provider.reload_service() end end diff --git a/spec/unit/provider/service/macosx_spec.rb b/spec/unit/provider/service/macosx_spec.rb index c5df1e0637..0d31ae2ffb 100644 --- a/spec/unit/provider/service/macosx_spec.rb +++ b/spec/unit/provider/service/macosx_spec.rb @@ -22,21 +22,21 @@ describe Chef::Provider::Service::Macosx do describe ".gather_plist_dirs" do context "when HOME directory is set" do before do - ENV.stub(:[]).with('HOME').and_return("/User/someuser") + allow(ENV).to receive(:[]).with('HOME').and_return("/User/someuser") end it "includes users's LaunchAgents folder" do - described_class.gather_plist_dirs.should include("#{ENV['HOME']}/Library/LaunchAgents") + expect(described_class.gather_plist_dirs).to include("#{ENV['HOME']}/Library/LaunchAgents") end end context "when HOME directory is not set" do before do - ENV.stub(:[]).with('HOME').and_return(nil) + allow(ENV).to receive(:[]).with('HOME').and_return(nil) end it "doesn't include user's LaunchAgents folder" do - described_class.gather_plist_dirs.should_not include("~/Library/LaunchAgents") + expect(described_class.gather_plist_dirs).not_to include("~/Library/LaunchAgents") end end end @@ -60,20 +60,20 @@ XML ["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!). + allow(Dir).to receive(:glob).and_return(["/Users/igor/Library/LaunchAgents/io.redis.redis-server.plist"], []) + allow(provider).to receive(:shell_out!). with("launchctl list", {:group => 1001, :user => 101}). and_return(double("Status", :stdout => launchctl_stdout)) - provider.stub(:shell_out). + allow(provider).to receive(:shell_out). with(/launchctl list /, {:group => nil, :user => nil}). and_return(double("Status", :stdout => launchctl_stdout, :exitstatus => 0)) - provider.stub(:shell_out!). + allow(provider).to receive(:shell_out!). with(/plutil -convert xml1 -o/). and_return(double("Status", :stdout => plutil_stdout)) - File.stub(:stat).and_return(double("stat", :gid => 1001, :uid => 101)) + allow(File).to receive(:stat).and_return(double("stat", :gid => 1001, :uid => 101)) end context "#{service_name}" do @@ -95,26 +95,26 @@ XML end before do - Dir.stub(:glob).and_return([]) - provider.stub(:shell_out!). + allow(Dir).to receive(:glob).and_return([]) + allow(provider).to receive(:shell_out!). with(/plutil -convert xml1 -o/). and_raise(Mixlib::ShellOut::ShellCommandFailed) end it "works for action :nothing" do - lambda { run_resource_setup_for_action(:nothing) }.should_not raise_error + expect { run_resource_setup_for_action(:nothing) }.not_to raise_error end it "works for action :start" do - lambda { run_resource_setup_for_action(:start) }.should_not raise_error + expect { run_resource_setup_for_action(:start) }.not_to raise_error end it "errors if action is :enable" do - lambda { run_resource_setup_for_action(:enable) }.should raise_error(Chef::Exceptions::Service) + expect { run_resource_setup_for_action(:enable) }.to raise_error(Chef::Exceptions::Service) end it "errors if action is :disable" do - lambda { run_resource_setup_for_action(:disable) }.should raise_error(Chef::Exceptions::Service) + expect { run_resource_setup_for_action(:disable) }.to raise_error(Chef::Exceptions::Service) end end @@ -130,11 +130,11 @@ XML end it "sets resource running state to true" do - provider.current_resource.running.should be_true + expect(provider.current_resource.running).to be_true end it "sets resouce enabled state to true" do - provider.current_resource.enabled.should be_true + expect(provider.current_resource.enabled).to be_true end end @@ -146,10 +146,10 @@ XML SVC_LIST before do - Dir.stub(:glob).and_return(["/Users/igor/Library/LaunchAgents/io.redis.redis-server.plist"], []) + allow(Dir).to receive(:glob).and_return(["/Users/igor/Library/LaunchAgents/io.redis.redis-server.plist"], []) end it "should throw an exception when reload action is attempted" do - lambda {provider.run_action(:reload)}.should raise_error(Chef::Exceptions::UnsupportedAction) + expect {provider.run_action(:reload)}.to raise_error(Chef::Exceptions::UnsupportedAction) end end context "when launchctl returns empty service pid" do @@ -164,11 +164,11 @@ SVC_LIST end it "sets resource running state to false" do - provider.current_resource.running.should be_false + expect(provider.current_resource.running).to be_false end it "sets resouce enabled state to true" do - provider.current_resource.enabled.should be_true + expect(provider.current_resource.enabled).to be_true end end @@ -180,65 +180,65 @@ SVC_LIST it "sets service running state to false" do provider.load_current_resource - provider.current_resource.running.should be_false + expect(provider.current_resource.running).to be_false end context "and plist for service is not available" do before do - Dir.stub(:glob).and_return([]) + allow(Dir).to receive(:glob).and_return([]) provider.load_current_resource end it "sets resouce enabled state to false" do - provider.current_resource.enabled.should be_false + expect(provider.current_resource.enabled).to be_false end end context "and plist for service is available" do before do - Dir.stub(:glob).and_return(["/Users/igor/Library/LaunchAgents/io.redis.redis-server.plist"], []) + allow(Dir).to receive(:glob).and_return(["/Users/igor/Library/LaunchAgents/io.redis.redis-server.plist"], []) provider.load_current_resource end it "sets resouce enabled state to true" do - provider.current_resource.enabled.should be_true + expect(provider.current_resource.enabled).to be_true end end 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", + allow(Dir).to receive(:glob).and_return(["/Users/igor/Library/LaunchAgents/io.redis.redis-server.plist", "/Users/wtf/something.plist"]) provider.load_current_resource provider.define_resource_requirements - lambda { provider.process_resource_requirements }.should raise_error(Chef::Exceptions::Service) + expect { provider.process_resource_requirements }.to raise_error(Chef::Exceptions::Service) end end end end describe "#start_service" do before do - Chef::Resource::Service.stub(:new).and_return(current_resource) + allow(Chef::Resource::Service).to receive(:new).and_return(current_resource) provider.load_current_resource - current_resource.stub(:running).and_return(false) + allow(current_resource).to receive(: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") + allow(new_resource).to receive(:start_command).and_return("cowsay dirty") - provider.should_receive(:shell_out_with_systems_locale!).with("cowsay dirty") + expect(provider).to receive(:shell_out_with_systems_locale!).with("cowsay dirty") provider.start_service end it "shows warning message if service is already running" do - current_resource.stub(:running).and_return(true) - Chef::Log.should_receive(:debug).with("service[#{service_name}] already running, not starting") + allow(current_resource).to receive(:running).and_return(true) + expect(Chef::Log).to receive(:debug).with("service[#{service_name}] already running, not starting") provider.start_service end it "starts service via launchctl if service found" do - provider.should_receive(:shell_out_with_systems_locale!). + expect(provider).to receive(:shell_out_with_systems_locale!). with("launchctl load -w '/Users/igor/Library/LaunchAgents/io.redis.redis-server.plist'", :group => 1001, :user => 101). and_return(0) @@ -249,28 +249,28 @@ SVC_LIST describe "#stop_service" do before do - Chef::Resource::Service.stub(:new).and_return(current_resource) + allow(Chef::Resource::Service).to receive(:new).and_return(current_resource) provider.load_current_resource - current_resource.stub(:running).and_return(true) + allow(current_resource).to receive(: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") + allow(new_resource).to receive(:stop_command).and_return("kill -9 123") - provider.should_receive(:shell_out_with_systems_locale!).with("kill -9 123") + expect(provider).to receive(:shell_out_with_systems_locale!).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) - Chef::Log.should_receive(:debug).with("service[#{service_name}] not running, not stopping") + allow(current_resource).to receive(:running).and_return(false) + expect(Chef::Log).to receive(:debug).with("service[#{service_name}] not running, not stopping") provider.stop_service end it "stops the service via launchctl if service found" do - provider.should_receive(:shell_out_with_systems_locale!). + expect(provider).to receive(:shell_out_with_systems_locale!). with("launchctl unload '/Users/igor/Library/LaunchAgents/io.redis.redis-server.plist'", :group => 1001, :user => 101). and_return(0) @@ -281,23 +281,23 @@ SVC_LIST describe "#restart_service" do before do - Chef::Resource::Service.stub(:new).and_return(current_resource) + allow(Chef::Resource::Service).to receive(:new).and_return(current_resource) provider.load_current_resource - current_resource.stub(:running).and_return(true) - provider.stub(:sleep) + allow(current_resource).to receive(:running).and_return(true) + allow(provider).to receive(:sleep) end it "issues a command if given" do - new_resource.stub(:restart_command).and_return("reload that thing") + allow(new_resource).to receive(:restart_command).and_return("reload that thing") - provider.should_receive(:shell_out_with_systems_locale!).with("reload that thing") + expect(provider).to receive(:shell_out_with_systems_locale!).with("reload that thing") provider.restart_service end it "stops and then starts service" do - provider.should_receive(:stop_service) - provider.should_receive(:start_service); + expect(provider).to receive(:stop_service) + expect(provider).to receive(:start_service); provider.restart_service end diff --git a/spec/unit/provider/service/redhat_spec.rb b/spec/unit/provider/service/redhat_spec.rb index 8cc6fb6549..ed3dd5bfa7 100644 --- a/spec/unit/provider/service/redhat_spec.rb +++ b/spec/unit/provider/service/redhat_spec.rb @@ -21,22 +21,22 @@ 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) + allow(File).to receive(:exists?).with("/sbin/chkconfig").and_return(false) + allow(@provider).to receive(:shell_out).with("/sbin/service chef status").and_raise(Errno::ENOENT) + allow(@provider).to receive(: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) + expect { @provider.process_resource_requirements }.to raise_error(Chef::Exceptions::Service) end it "should not raise an error if the service exists but is not added to any runlevels" do status = double("Status", :exitstatus => 0, :stdout => "" , :stderr => "") - @provider.should_receive(:shell_out).with("/sbin/service chef status").and_return(status) + expect(@provider).to receive(:shell_out).with("/sbin/service chef status").and_return(status) chkconfig = double("Chkconfig", :exitstatus => 0, :stdout => "", :stderr => "service chef supports chkconfig, but is not referenced in any runlevel (run 'chkconfig --add chef')") - @provider.should_receive(:shell_out!).with("/sbin/chkconfig --list chef", :returns => [0,1]).and_return(chkconfig) + expect(@provider).to receive(:shell_out!).with("/sbin/chkconfig --list chef", :returns => [0,1]).and_return(chkconfig) @provider.load_current_resource @provider.define_resource_requirements - lambda { @provider.process_resource_requirements }.should_not raise_error + expect { @provider.process_resource_requirements }.not_to raise_error end end @@ -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) + allow(Chef::Resource::Service).to receive(:new).and_return(@current_resource) + allow(File).to receive(:exists?).with("/sbin/chkconfig").and_return(true) end describe "while not in why run mode" do @@ -66,22 +66,22 @@ describe "Chef::Provider::Service::Redhat" do describe "load current resource" do it "sets the current enabled status to true if the service is enabled for any run level" do status = double("Status", :exitstatus => 0, :stdout => "" , :stderr => "") - @provider.should_receive(:shell_out).with("/sbin/service chef status").and_return(status) + expect(@provider).to receive(:shell_out).with("/sbin/service chef status").and_return(status) chkconfig = double("Chkconfig", :exitstatus => 0, :stdout => "chef 0:off 1:off 2:off 3:off 4:off 5:on 6:off", :stderr => "") - @provider.should_receive(:shell_out!).with("/sbin/chkconfig --list chef", :returns => [0,1]).and_return(chkconfig) - @provider.instance_variable_get("@service_missing").should be_false + expect(@provider).to receive(:shell_out!).with("/sbin/chkconfig --list chef", :returns => [0,1]).and_return(chkconfig) + expect(@provider.instance_variable_get("@service_missing")).to be_false @provider.load_current_resource - @current_resource.enabled.should be_true + expect(@current_resource.enabled).to be_true end it "sets the current enabled status to false if the regex does not match" do status = double("Status", :exitstatus => 0, :stdout => "" , :stderr => "") - @provider.should_receive(:shell_out).with("/sbin/service chef status").and_return(status) + expect(@provider).to receive(:shell_out).with("/sbin/service chef status").and_return(status) chkconfig = double("Chkconfig", :exitstatus => 0, :stdout => "chef 0:off 1:off 2:off 3:off 4:off 5:off 6:off", :stderr => "") - @provider.should_receive(:shell_out!).with("/sbin/chkconfig --list chef", :returns => [0,1]).and_return(chkconfig) - @provider.instance_variable_get("@service_missing").should be_false - @provider.load_current_resource.should eql(@current_resource) - @current_resource.enabled.should be_false + expect(@provider).to receive(:shell_out!).with("/sbin/chkconfig --list chef", :returns => [0,1]).and_return(chkconfig) + expect(@provider.instance_variable_get("@service_missing")).to be_false + expect(@provider.load_current_resource).to eql(@current_resource) + expect(@current_resource.enabled).to be_false end end @@ -91,9 +91,9 @@ describe "Chef::Provider::Service::Redhat" do context "when the service does not exist" do before do status = double("Status", :exitstatus => 1, :stdout => "", :stderr => "chef: unrecognized service") - @provider.should_receive(:shell_out).with("/sbin/service chef status").and_return(status) + expect(@provider).to receive(:shell_out).with("/sbin/service chef status").and_return(status) chkconfig = double("Chkconfig", :existatus=> 1, :stdout => "", :stderr => "error reading information on service chef: No such file or directory") - @provider.should_receive(:shell_out!).with("/sbin/chkconfig --list chef", :returns => [0,1]).and_return(chkconfig) + expect(@provider).to receive(:shell_out!).with("/sbin/chkconfig --list chef", :returns => [0,1]).and_return(chkconfig) @provider.load_current_resource @provider.define_resource_requirements end @@ -101,14 +101,14 @@ describe "Chef::Provider::Service::Redhat" do [ "start", "reload", "restart", "enable" ].each do |action| it "should raise an error when the action is #{action}" do @provider.action = action - lambda { @provider.process_resource_requirements }.should raise_error(Chef::Exceptions::Service) + expect { @provider.process_resource_requirements }.to raise_error(Chef::Exceptions::Service) end end [ "stop", "disable" ].each do |action| it "should not raise an error when the action is #{action}" do @provider.action = action - lambda { @provider.process_resource_requirements }.should_not raise_error + expect { @provider.process_resource_requirements }.not_to raise_error end end end @@ -129,26 +129,26 @@ describe "Chef::Provider::Service::Redhat" do it "should not raise an error if the service does not exist" do status = double("Status", :exitstatus => 1, :stdout => "", :stderr => "chef: unrecognized service") - @provider.should_receive(:shell_out).with("/sbin/service chef status").and_return(status) + expect(@provider).to receive(:shell_out).with("/sbin/service chef status").and_return(status) chkconfig = double("Chkconfig", :existatus=> 1, :stdout => "", :stderr => "error reading information on service chef: No such file or directory") - @provider.should_receive(:shell_out!).with("/sbin/chkconfig --list chef", :returns => [0,1]).and_return(chkconfig) + expect(@provider).to receive(:shell_out!).with("/sbin/chkconfig --list chef", :returns => [0,1]).and_return(chkconfig) @provider.load_current_resource @provider.define_resource_requirements - lambda { @provider.process_resource_requirements }.should_not raise_error + expect { @provider.process_resource_requirements }.not_to raise_error end end end describe "enable_service" do it "should call chkconfig to add 'service_name'" do - @provider.should_receive(:shell_out!).with("/sbin/chkconfig #{@new_resource.service_name} on") + expect(@provider).to receive(:shell_out!).with("/sbin/chkconfig #{@new_resource.service_name} on") @provider.enable_service end end describe "disable_service" do it "should call chkconfig to del 'service_name'" do - @provider.should_receive(:shell_out!).with("/sbin/chkconfig #{@new_resource.service_name} off") + expect(@provider).to receive(:shell_out!).with("/sbin/chkconfig #{@new_resource.service_name} off") @provider.disable_service end end diff --git a/spec/unit/provider/service/simple_service_spec.rb b/spec/unit/provider/service/simple_service_spec.rb index 11ebf74725..83ebcb688f 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) + allow(Chef::Resource::Service).to receive(:new).and_return(@current_resource) @stdout = StringIO.new(<<-NOMOCKINGSTRINGSPLZ) aj 7842 5057 0 21:26 pts/2 00:00:06 vi init.rb @@ -37,40 +37,40 @@ 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 = double("Status", :exitstatus => 0, :stdout => @stdout) - @provider.stub(:shell_out!).and_return(@status) + allow(@provider).to receive(:shell_out!).and_return(@status) end it "should create a current resource with the name of the new resource" do - Chef::Resource::Service.should_receive(:new).and_return(@current_resource) + expect(Chef::Resource::Service).to receive(:new).and_return(@current_resource) @provider.load_current_resource end it "should set the current resources service name to the new resources service name" do - @current_resource.should_receive(:service_name).with(@new_resource.service_name) + expect(@current_resource).to receive(:service_name).with(@new_resource.service_name) @provider.load_current_resource end it "should raise error if the node has a nil ps attribute and no other means to get status" do @node.automatic_attrs[:command] = {:ps => nil} @provider.define_resource_requirements - lambda { @provider.process_resource_requirements }.should raise_error(Chef::Exceptions::Service) + expect { @provider.process_resource_requirements }.to raise_error(Chef::Exceptions::Service) end it "should raise error if the node has an empty ps attribute and no other means to get status" do @node.automatic_attrs[:command] = {:ps => ""} @provider.define_resource_requirements - lambda { @provider.process_resource_requirements }.should raise_error(Chef::Exceptions::Service) + expect { @provider.process_resource_requirements }.to raise_error(Chef::Exceptions::Service) end describe "when we have a 'ps' attribute" do it "should shell_out! the node's ps command" do - @provider.should_receive(:shell_out!).with(@node[:command][:ps]).and_return(@status) + expect(@provider).to receive(:shell_out!).with(@node[:command][:ps]).and_return(@status) @provider.load_current_resource end it "should read stdout of the ps command" do - @provider.stub(:shell_out!).and_return(@status) - @stdout.should_receive(:each_line).and_return(true) + allow(@provider).to receive(:shell_out!).and_return(@status) + expect(@stdout).to receive(:each_line).and_return(true) @provider.load_current_resource end @@ -80,75 +80,75 @@ 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 = double("Status", :exitstatus => 0, :stdout => @stdout) - @provider.stub(:shell_out!).and_return(@status) + allow(@provider).to receive(:shell_out!).and_return(@status) @provider.load_current_resource - @current_resource.running.should be_true + expect(@current_resource.running).to be_true end it "should set running to false if the regex doesn't match" do - @provider.stub(:shell_out!).and_return(@status) + allow(@provider).to receive(:shell_out!).and_return(@status) @provider.load_current_resource - @current_resource.running.should be_false + expect(@current_resource.running).to be_false end it "should raise an exception if ps fails" do - @provider.stub(:shell_out!).and_raise(Mixlib::ShellOut::ShellCommandFailed) + allow(@provider).to receive(:shell_out!).and_raise(Mixlib::ShellOut::ShellCommandFailed) @provider.action = :start @provider.load_current_resource @provider.define_resource_requirements - lambda { @provider.process_resource_requirements }.should raise_error(Chef::Exceptions::Service) + expect { @provider.process_resource_requirements }.to raise_error(Chef::Exceptions::Service) end end it "should return the current resource" do - @provider.load_current_resource.should eql(@current_resource) + expect(@provider.load_current_resource).to eql(@current_resource) end 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}") - @provider.should_receive(:shell_out_with_systems_locale!).with("#{@new_resource.start_command}") + allow(@new_resource).to receive(:start_command).and_return("#{@new_resource.start_command}") + expect(@provider).to receive(:shell_out_with_systems_locale!).with("#{@new_resource.start_command}") @provider.start_service() end it "should raise an exception if no start command is specified" do @provider.define_resource_requirements @provider.action = :start - lambda { @provider.process_resource_requirements }.should raise_error(Chef::Exceptions::Service) + expect { @provider.process_resource_requirements }.to raise_error(Chef::Exceptions::Service) end end describe "when stopping a service" do it "should call the stop command if one is specified" do @new_resource.stop_command("/etc/init.d/themadness stop") - @provider.should_receive(:shell_out_with_systems_locale!).with("/etc/init.d/themadness stop") + expect(@provider).to receive(:shell_out_with_systems_locale!).with("/etc/init.d/themadness stop") @provider.stop_service() end it "should raise an exception if no stop command is specified" do @provider.define_resource_requirements @provider.action = :stop - lambda { @provider.process_resource_requirements }.should raise_error(Chef::Exceptions::Service) + expect { @provider.process_resource_requirements }.to raise_error(Chef::Exceptions::Service) end end describe Chef::Provider::Service::Simple, "restart_service" do it "should call the restart command if one has been specified" do @new_resource.restart_command("/etc/init.d/foo restart") - @provider.should_receive(:shell_out_with_systems_locale!).with("/etc/init.d/foo restart") + expect(@provider).to receive(:shell_out_with_systems_locale!).with("/etc/init.d/foo restart") @provider.restart_service() end it "should raise an exception if the resource doesn't support restart, no restart command is provided, and no stop command is provided" do @provider.define_resource_requirements @provider.action = :restart - lambda { @provider.process_resource_requirements }.should raise_error(Chef::Exceptions::Service) + expect { @provider.process_resource_requirements }.to raise_error(Chef::Exceptions::Service) end it "should just call stop, then start when the resource doesn't support restart and no restart_command is specified" do - @provider.should_receive(:stop_service) - @provider.should_receive(:sleep).with(1) - @provider.should_receive(:start_service) + expect(@provider).to receive(:stop_service) + expect(@provider).to receive(:sleep).with(1) + expect(@provider).to receive(:start_service) @provider.restart_service() end end @@ -157,12 +157,12 @@ NOMOCKINGSTRINGSPLZ it "should raise an exception if reload is requested but no command is specified" do @provider.define_resource_requirements @provider.action = :reload - lambda { @provider.process_resource_requirements }.should raise_error(Chef::Exceptions::UnsupportedAction) + expect { @provider.process_resource_requirements }.to raise_error(Chef::Exceptions::UnsupportedAction) end it "should should run the user specified reload command if one is specified" do @new_resource.reload_command("kill -9 1") - @provider.should_receive(:shell_out_with_systems_locale!).with("kill -9 1") + expect(@provider).to receive(:shell_out_with_systems_locale!).with("kill -9 1") @provider.reload_service() end end diff --git a/spec/unit/provider/service/solaris_smf_service_spec.rb b/spec/unit/provider/service/solaris_smf_service_spec.rb index 8df22efa7e..2f790a0ebb 100644 --- a/spec/unit/provider/service/solaris_smf_service_spec.rb +++ b/spec/unit/provider/service/solaris_smf_service_spec.rb @@ -29,70 +29,70 @@ 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) + allow(Chef::Resource::Service).to receive(: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) + allow(@stdout).to receive(:gets).and_return(@stdout_string) @status = double("Status", :exitstatus => 0, :stdout => @stdout) - @provider.stub(:shell_out!).and_return(@status) + allow(@provider).to receive(:shell_out!).and_return(@status) end it "should raise an error if /bin/svcs does not exist" do - File.should_receive(:exists?).with("/bin/svcs").and_return(false) - lambda { @provider.load_current_resource }.should raise_error(Chef::Exceptions::Service) + expect(File).to receive(:exists?).with("/bin/svcs").and_return(false) + expect { @provider.load_current_resource }.to raise_error(Chef::Exceptions::Service) end describe "on a host with /bin/svcs" do before do - File.stub(:exists?).with('/bin/svcs').and_return(true) + allow(File).to receive(: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(:shell_out!).with("/bin/svcs -l chef").and_return(@status) - Chef::Resource::Service.should_receive(:new).and_return(@current_resource) + allow(@provider).to receive(:shell_out!).with("/bin/svcs -l chef").and_return(@status) + expect(Chef::Resource::Service).to receive(:new).and_return(@current_resource) @provider.load_current_resource end it "should return the current resource" do - @provider.stub(:shell_out!).with("/bin/svcs -l chef").and_return(@status) - @provider.load_current_resource.should eql(@current_resource) + allow(@provider).to receive(:shell_out!).with("/bin/svcs -l chef").and_return(@status) + expect(@provider.load_current_resource).to eql(@current_resource) end it "should call '/bin/svcs -l service_name'" do - @provider.should_receive(:shell_out!).with("/bin/svcs -l chef", {:returns=>[0, 1]}).and_return(@status) + expect(@provider).to receive(:shell_out!).with("/bin/svcs -l chef", {:returns=>[0, 1]}).and_return(@status) @provider.load_current_resource end it "should mark service as not running" do - @provider.stub(:shell_out!).and_return(@status) - @current_resource.should_receive(:running).with(false) + allow(@provider).to receive(:shell_out!).and_return(@status) + expect(@current_resource).to receive(:running).with(false) @provider.load_current_resource end it "should mark service as running" do @status = double("Status", :exitstatus => 0, :stdout => 'state online') - @provider.stub(:shell_out!).and_return(@status) - @current_resource.should_receive(:running).with(true) + allow(@provider).to receive(:shell_out!).and_return(@status) + expect(@current_resource).to receive(:running).with(true) @provider.load_current_resource end it "should not mark service as maintenance" do - @provider.stub(:shell_out!).and_return(@status) + allow(@provider).to receive(:shell_out!).and_return(@status) @provider.load_current_resource - @provider.maintenance.should be_false + expect(@provider.maintenance).to be_false end it "should mark service as maintenance" do @status = double("Status", :exitstatus => 0, :stdout => 'state maintenance') - @provider.stub(:shell_out!).and_return(@status) + allow(@provider).to receive(:shell_out!).and_return(@status) @provider.load_current_resource - @provider.maintenance.should be_true + expect(@provider.maintenance).to be_true end end @@ -103,30 +103,27 @@ 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}") - @provider.should_not_receive(:shell_out!).with("/usr/sbin/svcadm clear #{@current_resource.service_name}") - @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 + expect(@provider).not_to receive(:shell_out!).with("/usr/sbin/svcadm clear #{@current_resource.service_name}") + expect(@provider).to receive(:shell_out!).with("/usr/sbin/svcadm enable -s #{@current_resource.service_name}").and_return(@status) + expect(@provider.enable_service).to be_true + expect(@current_resource.enabled).to 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}") - @provider.should_not_receive(:shell_out!).with("/usr/sbin/svcadm clear #{@current_resource.service_name}") - @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 + expect(@provider).not_to receive(:shell_out!).with("/usr/sbin/svcadm clear #{@current_resource.service_name}") + expect(@provider).to receive(:shell_out!).with("/usr/sbin/svcadm enable -s #{@current_resource.service_name}").and_return(@status) + expect(@provider.start_service).to be_true + expect(@current_resource.enabled).to be_true end it "should call svcadm clear chef for start_service when state maintenance" do @status = double("Status", :exitstatus => 0, :stdout => 'state maintenance') - @provider.stub(:shell_out!).and_return(@status) + allow(@provider).to receive(:shell_out!).and_return(@status) @provider.load_current_resource - @new_resource.stub(:enable_command).and_return("#{@new_resource.enable_command}") - @provider.should_receive(:shell_out!).with("/usr/sbin/svcadm clear #{@current_resource.service_name}").and_return(@status) - @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 + expect(@provider).to receive(:shell_out!).with("/usr/sbin/svcadm clear #{@current_resource.service_name}").and_return(@status) + expect(@provider).to receive(:shell_out!).with("/usr/sbin/svcadm enable -s #{@current_resource.service_name}").and_return(@status) + expect(@provider.enable_service).to be_true + expect(@current_resource.enabled).to be_true end end @@ -137,15 +134,15 @@ describe Chef::Provider::Service::Solaris do end it "should call svcadm disable -s chef" do - @provider.should_receive(:shell_out!).with("/usr/sbin/svcadm disable -s chef").and_return(@status) - @provider.disable_service.should be_true - @current_resource.enabled.should be_false + expect(@provider).to receive(:shell_out!).with("/usr/sbin/svcadm disable -s chef").and_return(@status) + expect(@provider.disable_service).to be_true + expect(@current_resource.enabled).to be_false end it "should call svcadm disable -s chef for stop_service" do - @provider.should_receive(:shell_out!).with("/usr/sbin/svcadm disable -s chef").and_return(@status) - @provider.stop_service.should be_true - @current_resource.enabled.should be_false + expect(@provider).to receive(:shell_out!).with("/usr/sbin/svcadm disable -s chef").and_return(@status) + expect(@provider.stop_service).to be_true + expect(@current_resource.enabled).to be_false end end @@ -157,7 +154,7 @@ describe Chef::Provider::Service::Solaris do end it "should call svcadm refresh chef" do - @provider.should_receive(:shell_out_with_systems_locale!).with("/usr/sbin/svcadm refresh chef").and_return(@status) + expect(@provider).to receive(:shell_out_with_systems_locale!).with("/usr/sbin/svcadm refresh chef").and_return(@status) @provider.reload_service end @@ -171,15 +168,15 @@ describe Chef::Provider::Service::Solaris do end it "should be marked not running" do - @provider.should_receive(:shell_out!).with("/bin/svcs -l chef", {:returns=>[0, 1]}).and_return(@status) + expect(@provider).to receive(:shell_out!).with("/bin/svcs -l chef", {:returns=>[0, 1]}).and_return(@status) @provider.service_status - @current_resource.running.should be_false + expect(@current_resource.running).to be_false end it "should be marked not enabled" do - @provider.should_receive(:shell_out!).with("/bin/svcs -l chef", {:returns=>[0, 1]}).and_return(@status) + expect(@provider).to receive(:shell_out!).with("/bin/svcs -l chef", {:returns=>[0, 1]}).and_return(@status) @provider.service_status - @current_resource.enabled.should be_false + expect(@current_resource.enabled).to be_false end end diff --git a/spec/unit/provider/service/systemd_service_spec.rb b/spec/unit/provider/service/systemd_service_spec.rb index 7358f63b5e..2fed6bfd11 100644 --- a/spec/unit/provider/service/systemd_service_spec.rb +++ b/spec/unit/provider/service/systemd_service_spec.rb @@ -35,169 +35,169 @@ 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) + allow(Chef::Resource::Service).to receive(:new).and_return(@current_resource) - @provider.stub(:is_active?).and_return(false) - @provider.stub(:is_enabled?).and_return(false) + allow(@provider).to receive(:is_active?).and_return(false) + allow(@provider).to receive(:is_enabled?).and_return(false) end it "should create a current resource with the name of the new resource" do - Chef::Resource::Service.should_receive(:new).and_return(@current_resource) + expect(Chef::Resource::Service).to receive(:new).and_return(@current_resource) @provider.load_current_resource end it "should set the current resources service name to the new resources service name" do - @current_resource.should_receive(:service_name).with(@new_resource.service_name) + expect(@current_resource).to receive(:service_name).with(@new_resource.service_name) @provider.load_current_resource end it "should check if the service is running" do - @provider.should_receive(:is_active?) + expect(@provider).to receive(:is_active?) @provider.load_current_resource end it "should set running to true if the service is running" do - @provider.stub(:is_active?).and_return(true) - @current_resource.should_receive(:running).with(true) + allow(@provider).to receive(:is_active?).and_return(true) + expect(@current_resource).to 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) - @current_resource.should_receive(:running).with(false) + allow(@provider).to receive(:is_active?).and_return(false) + expect(@current_resource).to 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") + allow(@new_resource).to receive(:status_command).and_return("/bin/chefhasmonkeypants status") end it "should run the services status command if one has been specified" do - @provider.stub(:shell_out).and_return(@shell_out_success) - @current_resource.should_receive(:running).with(true) + allow(@provider).to receive(:shell_out).and_return(@shell_out_success) + expect(@current_resource).to 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(:shell_out).with("/bin/chefhasmonkeypants status").and_return(@shell_out_success) + allow(@provider).to receive(:shell_out).with("/bin/chefhasmonkeypants status").and_return(@shell_out_success) @provider.load_current_resource - @provider.instance_variable_get("@status_check_success").should be_true + expect(@provider.instance_variable_get("@status_check_success")).to be_true end it "should set running to false if a status command fails" do - @provider.stub(:shell_out).and_return(@shell_out_failure) - @current_resource.should_receive(:running).with(false) + allow(@provider).to receive(:shell_out).and_return(@shell_out_failure) + expect(@current_resource).to receive(:running).with(false) @provider.load_current_resource end it "should update state to indicate status check failed when a status command fails" do - @provider.stub(:shell_out).and_return(@shell_out_failure) + allow(@provider).to receive(:shell_out).and_return(@shell_out_failure) @provider.load_current_resource - @provider.instance_variable_get("@status_check_success").should be_false + expect(@provider.instance_variable_get("@status_check_success")).to be_false end end it "should check if the service is enabled" do - @provider.should_receive(:is_enabled?) + expect(@provider).to receive(:is_enabled?) @provider.load_current_resource end it "should set enabled to true if the service is enabled" do - @provider.stub(:is_enabled?).and_return(true) - @current_resource.should_receive(:enabled).with(true) + allow(@provider).to receive(:is_enabled?).and_return(true) + expect(@current_resource).to 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) - @current_resource.should_receive(:enabled).with(false) + allow(@provider).to receive(:is_enabled?).and_return(false) + expect(@current_resource).to receive(:enabled).with(false) @provider.load_current_resource end it "should return the current resource" do - @provider.load_current_resource.should eql(@current_resource) + expect(@provider.load_current_resource).to eql(@current_resource) end end 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) + allow(Chef::Resource::Service).to receive(: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") - @provider.should_receive(:shell_out_with_systems_locale!).with("/sbin/rsyslog startyousillysally") + allow(@new_resource).to receive(:start_command).and_return("/sbin/rsyslog startyousillysally") + expect(@provider).to receive(:shell_out_with_systems_locale!).with("/sbin/rsyslog startyousillysally") @provider.start_service end it "should call '/bin/systemctl start service_name' if no start command is specified" do - @provider.should_receive(:shell_out_with_systems_locale!).with("/bin/systemctl start #{@new_resource.service_name}").and_return(@shell_out_success) + expect(@provider).to receive(:shell_out_with_systems_locale!).with("/bin/systemctl start #{@new_resource.service_name}").and_return(@shell_out_success) @provider.start_service end it "should not call '/bin/systemctl start service_name' if it is already running" do - @current_resource.stub(:running).and_return(true) - @provider.should_not_receive(:shell_out_with_systems_locale!).with("/bin/systemctl start #{@new_resource.service_name}") + allow(@current_resource).to receive(:running).and_return(true) + expect(@provider).not_to receive(:shell_out_with_systems_locale!).with("/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") - @provider.should_receive(:shell_out_with_systems_locale!).with("/sbin/rsyslog restartyousillysally") + allow(@current_resource).to receive(:running).and_return(true) + allow(@new_resource).to receive(:restart_command).and_return("/sbin/rsyslog restartyousillysally") + expect(@provider).to receive(:shell_out_with_systems_locale!).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) - @provider.should_receive(:shell_out_with_systems_locale!).with("/bin/systemctl restart #{@new_resource.service_name}").and_return(@shell_out_success) + allow(@current_resource).to receive(:running).and_return(true) + expect(@provider).to receive(:shell_out_with_systems_locale!).with("/bin/systemctl restart #{@new_resource.service_name}").and_return(@shell_out_success) @provider.restart_service end describe "reload service" do context "when a reload command is specified" do it "should call the reload command" do - @current_resource.stub(:running).and_return(true) - @new_resource.stub(:reload_command).and_return("/sbin/rsyslog reloadyousillysally") - @provider.should_receive(:shell_out_with_systems_locale!).with("/sbin/rsyslog reloadyousillysally") + allow(@current_resource).to receive(:running).and_return(true) + allow(@new_resource).to receive(:reload_command).and_return("/sbin/rsyslog reloadyousillysally") + expect(@provider).to receive(:shell_out_with_systems_locale!).with("/sbin/rsyslog reloadyousillysally") @provider.reload_service end end context "when a reload command is not specified" do it "should call '/bin/systemctl reload service_name' if the service is running" do - @current_resource.stub(:running).and_return(true) - @provider.should_receive(:shell_out_with_systems_locale!).with("/bin/systemctl reload #{@new_resource.service_name}").and_return(@shell_out_success) + allow(@current_resource).to receive(:running).and_return(true) + expect(@provider).to receive(:shell_out_with_systems_locale!).with("/bin/systemctl reload #{@new_resource.service_name}").and_return(@shell_out_success) @provider.reload_service end it "should start the service if the service is not running" do - @current_resource.stub(:running).and_return(false) - @provider.should_receive(:start_service).and_return(true) + allow(@current_resource).to receive(:running).and_return(false) + expect(@provider).to receive(:start_service).and_return(true) @provider.reload_service end end 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") - @provider.should_receive(:shell_out_with_systems_locale!).with("/sbin/rsyslog stopyousillysally") + allow(@current_resource).to receive(:running).and_return(true) + allow(@new_resource).to receive(:stop_command).and_return("/sbin/rsyslog stopyousillysally") + expect(@provider).to receive(:shell_out_with_systems_locale!).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) - @provider.should_receive(:shell_out_with_systems_locale!).with("/bin/systemctl stop #{@new_resource.service_name}").and_return(@shell_out_success) + allow(@current_resource).to receive(:running).and_return(true) + expect(@provider).to receive(:shell_out_with_systems_locale!).with("/bin/systemctl stop #{@new_resource.service_name}").and_return(@shell_out_success) @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) - @provider.should_not_receive(:shell_out_with_systems_locale!).with("/bin/systemctl stop #{@new_resource.service_name}") + allow(@current_resource).to receive(:running).and_return(false) + expect(@provider).not_to receive(:shell_out_with_systems_locale!).with("/bin/systemctl stop #{@new_resource.service_name}") @provider.stop_service end end @@ -205,17 +205,17 @@ 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) + allow(Chef::Resource::Service).to receive(:new).and_return(@current_resource) @provider.current_resource = @current_resource end it "should call '/bin/systemctl enable service_name' to enable the service" do - @provider.should_receive(:shell_out!).with("/bin/systemctl enable #{@new_resource.service_name}").and_return(@shell_out_success) + expect(@provider).to receive(:shell_out!).with("/bin/systemctl enable #{@new_resource.service_name}").and_return(@shell_out_success) @provider.enable_service end it "should call '/bin/systemctl disable service_name' to disable the service" do - @provider.should_receive(:shell_out!).with("/bin/systemctl disable #{@new_resource.service_name}").and_return(@shell_out_success) + expect(@provider).to receive(:shell_out!).with("/bin/systemctl disable #{@new_resource.service_name}").and_return(@shell_out_success) @provider.disable_service end end @@ -223,34 +223,34 @@ 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) + allow(Chef::Resource::Service).to receive(:new).and_return(@current_resource) end it "should return true if '/bin/systemctl is-active service_name' returns 0" do - @provider.should_receive(:shell_out).with('/bin/systemctl is-active rsyslog.service --quiet').and_return(@shell_out_success) - @provider.is_active?.should be_true + expect(@provider).to receive(:shell_out).with('/bin/systemctl is-active rsyslog.service --quiet').and_return(@shell_out_success) + expect(@provider.is_active?).to be_true end it "should return false if '/bin/systemctl is-active service_name' returns anything except 0" do - @provider.should_receive(:shell_out).with('/bin/systemctl is-active rsyslog.service --quiet').and_return(@shell_out_failure) - @provider.is_active?.should be_false + expect(@provider).to receive(:shell_out).with('/bin/systemctl is-active rsyslog.service --quiet').and_return(@shell_out_failure) + expect(@provider.is_active?).to be_false end end describe "is_enabled?" do before(:each) do @current_resource = Chef::Resource::Service.new('rsyslog.service') - Chef::Resource::Service.stub(:new).and_return(@current_resource) + allow(Chef::Resource::Service).to receive(:new).and_return(@current_resource) end it "should return true if '/bin/systemctl is-enabled service_name' returns 0" do - @provider.should_receive(:shell_out).with('/bin/systemctl is-enabled rsyslog.service --quiet').and_return(@shell_out_success) - @provider.is_enabled?.should be_true + expect(@provider).to receive(:shell_out).with('/bin/systemctl is-enabled rsyslog.service --quiet').and_return(@shell_out_success) + expect(@provider.is_enabled?).to be_true end it "should return false if '/bin/systemctl is-enabled service_name' returns anything except 0" do - @provider.should_receive(:shell_out).with('/bin/systemctl is-enabled rsyslog.service --quiet').and_return(@shell_out_failure) - @provider.is_enabled?.should be_false + expect(@provider).to receive(:shell_out).with('/bin/systemctl is-enabled rsyslog.service --quiet').and_return(@shell_out_failure) + expect(@provider.is_enabled?).to be_false end end end diff --git a/spec/unit/provider/service/upstart_service_spec.rb b/spec/unit/provider/service/upstart_service_spec.rb index 499a794ff4..69948fbc6a 100644 --- a/spec/unit/provider/service/upstart_service_spec.rb +++ b/spec/unit/provider/service/upstart_service_spec.rb @@ -41,22 +41,22 @@ describe Chef::Provider::Service::Upstart do @node.automatic_attrs[:platform_version] = '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 == "" + expect(@provider.instance_variable_get(:@upstart_job_dir)).to eq("/etc/event.d") + expect(@provider.instance_variable_get(:@upstart_conf_suffix)).to eq("") end it "should return /etc/init as the upstart job directory when running on Ubuntu 9.10" do @node.automatic_attrs[:platform_version] = '9.10' @provider = Chef::Provider::Service::Upstart.new(@new_resource, @run_context) - @provider.instance_variable_get(:@upstart_job_dir).should == "/etc/init" - @provider.instance_variable_get(:@upstart_conf_suffix).should == ".conf" + expect(@provider.instance_variable_get(:@upstart_job_dir)).to eq("/etc/init") + expect(@provider.instance_variable_get(:@upstart_conf_suffix)).to eq(".conf") end it "should return /etc/init as the upstart job directory by default" do @node.automatic_attrs[:platform_version] = '9000' @provider = Chef::Provider::Service::Upstart.new(@new_resource, @run_context) - @provider.instance_variable_get(:@upstart_job_dir).should == "/etc/init" - @provider.instance_variable_get(:@upstart_conf_suffix).should == ".conf" + expect(@provider.instance_variable_get(:@upstart_job_dir)).to eq("/etc/init") + expect(@provider.instance_variable_get(:@upstart_conf_suffix)).to eq(".conf") end end @@ -65,26 +65,26 @@ 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) + allow(Chef::Resource::Service).to receive(:new).and_return(@current_resource) @status = double("Status", :exitstatus => 0) - @provider.stub(:popen4).and_return(@status) + allow(@provider).to receive(:popen4).and_return(@status) @stdin = StringIO.new @stdout = StringIO.new @stderr = StringIO.new @pid = double("PID") - ::File.stub(:exists?).and_return(true) - ::File.stub(:open).and_return(true) + allow(::File).to receive(:exists?).and_return(true) + allow(::File).to receive(:open).and_return(true) end it "should create a current resource with the name of the new resource" do - Chef::Resource::Service.should_receive(:new).and_return(@current_resource) + expect(Chef::Resource::Service).to receive(:new).and_return(@current_resource) @provider.load_current_resource end it "should set the current resources service name to the new resources service name" do - @current_resource.should_receive(:service_name).with(@new_resource.service_name) + expect(@current_resource).to receive(:service_name).with(@new_resource.service_name) @provider.load_current_resource end @@ -92,11 +92,11 @@ describe Chef::Provider::Service::Upstart do @new_resource.parameters({ "OSD_ID" => "2" }) @provider = Chef::Provider::Service::Upstart.new(@new_resource, @run_context) @provider.current_resource = @current_resource - @new_resource.service_name.should == @current_resource.service_name + expect(@new_resource.service_name).to eq(@current_resource.service_name) end it "should run '/sbin/status rsyslog'" do - @provider.should_receive(:popen4).with("/sbin/status rsyslog").and_return(@status) + expect(@provider).to receive(:popen4).with("/sbin/status rsyslog").and_return(@status) @provider.load_current_resource end @@ -106,99 +106,99 @@ 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) + allow(@provider).to receive(:popen4).and_yield(@pid, @stdin, @stdout, @stderr).and_return(@status) @provider.load_current_resource - @current_resource.running.should be_true + expect(@current_resource.running).to 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) + allow(@provider).to receive(:popen4).and_yield(@pid, @stdin, @stdout, @stderr).and_return(@status) @provider.load_current_resource - @current_resource.running.should be_false + expect(@current_resource.running).to be_false end end 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) + allow(@provider).to receive(:popen4).and_yield(@pid, @stdin, @stdout, @stderr).and_return(@status) @provider.load_current_resource - @current_resource.running.should be_true + expect(@current_resource.running).to 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) + allow(@provider).to receive(:popen4).and_yield(@pid, @stdin, @stdout, @stderr).and_return(@status) @provider.load_current_resource - @current_resource.running.should be_false + expect(@current_resource.running).to 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) - @current_resource.should_receive(:running).with(false) + allow(@provider).to receive(:popen4).and_yield(@pid, @stdin, @stdout, @stderr).and_raise(Chef::Exceptions::Exec) + expect(@current_resource).to receive(:running).with(false) @provider.load_current_resource end it "should set enabled to true when it finds 'starts on'" do @lines = double("start on filesystem", :gets => "start on filesystem") - ::File.stub(:open).and_yield(@lines) - @current_resource.should_receive(:running).with(false) + allow(::File).to receive(:open).and_yield(@lines) + expect(@current_resource).to receive(:running).with(false) @provider.load_current_resource end it "should set enabled to false when it finds '#starts on'" do @lines = double("start on filesystem", :gets => "#start on filesystem") - ::File.stub(:open).and_yield(@lines) - @current_resource.should_receive(:running).with(false) + allow(::File).to receive(:open).and_yield(@lines) + expect(@current_resource).to 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) - @current_resource.should_receive(:running).with(false) + allow(::File).to receive(:exists?).and_return(false) + expect(@current_resource).to receive(:running).with(false) @provider.load_current_resource end it "should track state when the upstart configuration file fails to load" do - File.should_receive(:exists?).and_return false + expect(File).to receive(:exists?).and_return false @provider.load_current_resource - @provider.instance_variable_get("@config_file_found").should == false + expect(@provider.instance_variable_get("@config_file_found")).to eq(false) end describe "when a status command has been specified" do before do - @new_resource.stub(:status_command).and_return("/bin/chefhasmonkeypants status") + allow(@new_resource).to receive(:status_command).and_return("/bin/chefhasmonkeypants status") end it "should run the services status command if one has been specified" do - @provider.stub(:shell_out!).with("/bin/chefhasmonkeypants status").and_return(0) - @current_resource.should_receive(:running).with(true) + allow(@provider).to receive(:shell_out!).with("/bin/chefhasmonkeypants status").and_return(0) + expect(@current_resource).to receive(:running).with(true) @provider.load_current_resource end it "should track state when the user-provided status command fails" do - @provider.stub(:shell_out!).and_raise(Errno::ENOENT) + allow(@provider).to receive(:shell_out!).and_raise(Errno::ENOENT) @provider.load_current_resource - @provider.instance_variable_get("@command_success").should == false + expect(@provider.instance_variable_get("@command_success")).to eq(false) end it "should set running to false if it catches a Chef::Exceptions::Exec when using a status command" do - @provider.stub(:shell_out!).and_raise(Errno::ENOENT) - @current_resource.should_receive(:running).with(false) + allow(@provider).to receive(:shell_out!).and_raise(Errno::ENOENT) + expect(@current_resource).to receive(:running).with(false) @provider.load_current_resource end end it "should track state when we fail to obtain service status via upstart_state" do - @provider.should_receive(:upstart_state).and_raise Chef::Exceptions::Exec + expect(@provider).to receive(:upstart_state).and_raise Chef::Exceptions::Exec @provider.load_current_resource - @provider.instance_variable_get("@command_success").should == false + expect(@provider.instance_variable_get("@command_success")).to eq(false) end it "should return the current resource" do - @provider.load_current_resource.should eql(@current_resource) + expect(@provider.load_current_resource).to eql(@current_resource) end end @@ -206,26 +206,26 @@ 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) + allow(Chef::Resource::Service).to receive(:new).and_return(@current_resource) @provider.current_resource = @current_resource - Chef::Util::FileEdit.stub(:new) + allow(Chef::Util::FileEdit).to receive(: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) - @file.should_receive(:search_file_replace) - @file.should_receive(:write_file) + allow(Chef::Util::FileEdit).to receive(:new).and_return(@file) + allow(@current_resource).to receive(:enabled).and_return(false) + expect(@file).to receive(:search_file_replace) + expect(@file).to receive(:write_file) @provider.enable_service() end 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) - @file.should_receive(:search_file_replace) - @file.should_receive(:write_file) + allow(Chef::Util::FileEdit).to receive(:new).and_return(@file) + allow(@current_resource).to receive(:enabled).and_return(true) + expect(@file).to receive(:search_file_replace) + expect(@file).to receive(:write_file) @provider.disable_service() end @@ -235,24 +235,24 @@ 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) + allow(Chef::Resource::Service).to receive(: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") - @provider.should_receive(:shell_out_with_systems_locale!).with("/sbin/rsyslog startyousillysally") + allow(@new_resource).to receive(:start_command).and_return("/sbin/rsyslog startyousillysally") + expect(@provider).to receive(:shell_out_with_systems_locale!).with("/sbin/rsyslog startyousillysally") @provider.start_service() end it "should call '/sbin/start service_name' if no start command is specified" do - @provider.should_receive(:shell_out_with_systems_locale!).with("/sbin/start #{@new_resource.service_name}").and_return(0) + expect(@provider).to receive(:shell_out_with_systems_locale!).with("/sbin/start #{@new_resource.service_name}").and_return(0) @provider.start_service() end it "should not call '/sbin/start service_name' if it is already running" do - @current_resource.stub(:running).and_return(true) - @provider.should_not_receive(:shell_out_with_systems_locale!) + allow(@current_resource).to receive(:running).and_return(true) + expect(@provider).not_to receive(:shell_out_with_systems_locale!) @provider.start_service() end @@ -261,58 +261,58 @@ describe Chef::Provider::Service::Upstart do @new_resource.parameters({ "OSD_ID" => "2" }) @provider = Chef::Provider::Service::Upstart.new(@new_resource, @run_context) @provider.current_resource = @current_resource - @provider.should_receive(:shell_out_with_systems_locale!).with("/sbin/start rsyslog OSD_ID=2").and_return(0) + expect(@provider).to receive(:shell_out_with_systems_locale!).with("/sbin/start rsyslog OSD_ID=2").and_return(0) @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") - @provider.should_receive(:shell_out_with_systems_locale!).with("/sbin/rsyslog restartyousillysally") + allow(@current_resource).to receive(:running).and_return(true) + allow(@new_resource).to receive(:restart_command).and_return("/sbin/rsyslog restartyousillysally") + expect(@provider).to receive(:shell_out_with_systems_locale!).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) - @provider.should_receive(:shell_out_with_systems_locale!).with("/sbin/restart #{@new_resource.service_name}").and_return(0) + allow(@current_resource).to receive(:running).and_return(true) + expect(@provider).to receive(:shell_out_with_systems_locale!).with("/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) - @provider.should_receive(:shell_out_with_systems_locale!).with("/sbin/start #{@new_resource.service_name}").and_return(0) + allow(@current_resource).to receive(:running).and_return(false) + expect(@provider).to receive(:shell_out_with_systems_locale!).with("/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") - @provider.should_receive(:shell_out_with_systems_locale!).with("/sbin/rsyslog reloadyousillysally") + allow(@current_resource).to receive(:running).and_return(true) + allow(@new_resource).to receive(:reload_command).and_return("/sbin/rsyslog reloadyousillysally") + expect(@provider).to receive(:shell_out_with_systems_locale!).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) - @provider.should_receive(:shell_out_with_systems_locale!).with("/sbin/reload #{@new_resource.service_name}").and_return(0) + allow(@current_resource).to receive(:running).and_return(true) + expect(@provider).to receive(:shell_out_with_systems_locale!).with("/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") - @provider.should_receive(:shell_out_with_systems_locale!).with("/sbin/rsyslog stopyousillysally") + allow(@current_resource).to receive(:running).and_return(true) + allow(@new_resource).to receive(:stop_command).and_return("/sbin/rsyslog stopyousillysally") + expect(@provider).to receive(:shell_out_with_systems_locale!).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) - @provider.should_receive(:shell_out_with_systems_locale!).with("/sbin/stop #{@new_resource.service_name}").and_return(0) + allow(@current_resource).to receive(:running).and_return(true) + expect(@provider).to receive(:shell_out_with_systems_locale!).with("/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) - @provider.should_not_receive(:shell_out_with_systems_locale!).with("/sbin/stop #{@new_resource.service_name}") + allow(@current_resource).to receive(:running).and_return(false) + expect(@provider).not_to receive(:shell_out_with_systems_locale!).with("/sbin/stop #{@new_resource.service_name}") @provider.stop_service() end end diff --git a/spec/unit/provider/service/windows_spec.rb b/spec/unit/provider/service/windows_spec.rb index 14bdb782cd..f35f169bc4 100644 --- a/spec/unit/provider/service/windows_spec.rb +++ b/spec/unit/provider/service/windows_spec.rb @@ -33,102 +33,102 @@ describe Chef::Provider::Service::Windows, "load_current_resource" do Win32::Service::AUTO_START = 0x00000002 Win32::Service::DEMAND_START = 0x00000003 Win32::Service::DISABLED = 0x00000004 - Win32::Service.stub(:status).with(@new_resource.service_name).and_return( + allow(Win32::Service).to receive(:status).with(@new_resource.service_name).and_return( double("StatusStruct", :current_state => "running")) - Win32::Service.stub(:config_info).with(@new_resource.service_name).and_return( + allow(Win32::Service).to receive(:config_info).with(@new_resource.service_name).and_return( double("ConfigStruct", :start_type => "auto start")) - Win32::Service.stub(:exists?).and_return(true) + allow(Win32::Service).to receive(:exists?).and_return(true) end it "should set the current resources service name to the new resources service name" do @provider.load_current_resource - @provider.current_resource.service_name.should == 'chef' + expect(@provider.current_resource.service_name).to eq('chef') end it "should return the current resource" do - @provider.load_current_resource.should equal(@provider.current_resource) + expect(@provider.load_current_resource).to equal(@provider.current_resource) end it "should set the current resources status" do @provider.load_current_resource - @provider.current_resource.running.should be_true + expect(@provider.current_resource.running).to be_true end it "should set the current resources start type" do @provider.load_current_resource - @provider.current_resource.enabled.should be_true + expect(@provider.current_resource.enabled).to be_true end it "does not set the current resources start type if it is neither AUTO START or DISABLED" do - Win32::Service.stub(:config_info).with(@new_resource.service_name).and_return( + allow(Win32::Service).to receive(:config_info).with(@new_resource.service_name).and_return( double("ConfigStruct", :start_type => "manual")) @provider.load_current_resource - @provider.current_resource.enabled.should be_nil + expect(@provider.current_resource.enabled).to be_nil end describe Chef::Provider::Service::Windows, "start_service" do before(:each) do - Win32::Service.stub(:status).with(@new_resource.service_name).and_return( + allow(Win32::Service).to receive(:status).with(@new_resource.service_name).and_return( double("StatusStruct", :current_state => "stopped"), double("StatusStruct", :current_state => "running")) end it "should call the start command if one is specified" do @new_resource.start_command "sc start chef" - @provider.should_receive(:shell_out!).with("#{@new_resource.start_command}").and_return("Starting custom service") + expect(@provider).to receive(:shell_out!).with("#{@new_resource.start_command}").and_return("Starting custom service") @provider.start_service - @new_resource.updated_by_last_action?.should be_true + expect(@new_resource.updated_by_last_action?).to be_true end it "should use the built-in command if no start command is specified" do - Win32::Service.should_receive(:start).with(@new_resource.service_name) + expect(Win32::Service).to receive(:start).with(@new_resource.service_name) @provider.start_service - @new_resource.updated_by_last_action?.should be_true + expect(@new_resource.updated_by_last_action?).to be_true end it "should do nothing if the service does not exist" do - Win32::Service.stub(:exists?).with(@new_resource.service_name).and_return(false) - Win32::Service.should_not_receive(:start).with(@new_resource.service_name) + allow(Win32::Service).to receive(:exists?).with(@new_resource.service_name).and_return(false) + expect(Win32::Service).not_to receive(:start).with(@new_resource.service_name) @provider.start_service - @new_resource.updated_by_last_action?.should be_false + expect(@new_resource.updated_by_last_action?).to be_false end it "should do nothing if the service is running" do - Win32::Service.stub(:status).with(@new_resource.service_name).and_return( + allow(Win32::Service).to receive(:status).with(@new_resource.service_name).and_return( double("StatusStruct", :current_state => "running")) @provider.load_current_resource - Win32::Service.should_not_receive(:start).with(@new_resource.service_name) + expect(Win32::Service).not_to receive(:start).with(@new_resource.service_name) @provider.start_service - @new_resource.updated_by_last_action?.should be_false + expect(@new_resource.updated_by_last_action?).to be_false end it "should raise an error if the service is paused" do - Win32::Service.stub(:status).with(@new_resource.service_name).and_return( + allow(Win32::Service).to receive(:status).with(@new_resource.service_name).and_return( double("StatusStruct", :current_state => "paused")) @provider.load_current_resource - Win32::Service.should_not_receive(:start).with(@new_resource.service_name) + expect(Win32::Service).not_to receive(:start).with(@new_resource.service_name) expect { @provider.start_service }.to raise_error( Chef::Exceptions::Service ) - @new_resource.updated_by_last_action?.should be_false + expect(@new_resource.updated_by_last_action?).to be_false end it "should wait and continue if the service is in start_pending" do - Win32::Service.stub(:status).with(@new_resource.service_name).and_return( + allow(Win32::Service).to receive(:status).with(@new_resource.service_name).and_return( double("StatusStruct", :current_state => "start pending"), double("StatusStruct", :current_state => "start pending"), double("StatusStruct", :current_state => "running")) @provider.load_current_resource - Win32::Service.should_not_receive(:start).with(@new_resource.service_name) + expect(Win32::Service).not_to receive(:start).with(@new_resource.service_name) @provider.start_service - @new_resource.updated_by_last_action?.should be_false + expect(@new_resource.updated_by_last_action?).to be_false end it "should fail if the service is in stop_pending" do - Win32::Service.stub(:status).with(@new_resource.service_name).and_return( + allow(Win32::Service).to receive(:status).with(@new_resource.service_name).and_return( double("StatusStruct", :current_state => "stop pending")) @provider.load_current_resource - Win32::Service.should_not_receive(:start).with(@new_resource.service_name) + expect(Win32::Service).not_to receive(:start).with(@new_resource.service_name) expect { @provider.start_service }.to raise_error( Chef::Exceptions::Service ) - @new_resource.updated_by_last_action?.should be_false + expect(@new_resource.updated_by_last_action?).to be_false end end @@ -137,78 +137,78 @@ 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( + allow(Win32::Service).to receive(:status).with(@new_resource.service_name).and_return( double("StatusStruct", :current_state => "running"), double("StatusStruct", :current_state => "stopped")) end it "should call the stop command if one is specified" do @new_resource.stop_command "sc stop chef" - @provider.should_receive(:shell_out!).with("#{@new_resource.stop_command}").and_return("Stopping custom service") + expect(@provider).to receive(:shell_out!).with("#{@new_resource.stop_command}").and_return("Stopping custom service") @provider.stop_service - @new_resource.updated_by_last_action?.should be_true + expect(@new_resource.updated_by_last_action?).to be_true end it "should use the built-in command if no stop command is specified" do - Win32::Service.should_receive(:stop).with(@new_resource.service_name) + expect(Win32::Service).to receive(:stop).with(@new_resource.service_name) @provider.stop_service - @new_resource.updated_by_last_action?.should be_true + expect(@new_resource.updated_by_last_action?).to be_true end it "should do nothing if the service does not exist" do - Win32::Service.stub(:exists?).with(@new_resource.service_name).and_return(false) - Win32::Service.should_not_receive(:stop).with(@new_resource.service_name) + allow(Win32::Service).to receive(:exists?).with(@new_resource.service_name).and_return(false) + expect(Win32::Service).not_to receive(:stop).with(@new_resource.service_name) @provider.stop_service - @new_resource.updated_by_last_action?.should be_false + expect(@new_resource.updated_by_last_action?).to be_false end it "should do nothing if the service is stopped" do - Win32::Service.stub(:status).with(@new_resource.service_name).and_return( + allow(Win32::Service).to receive(:status).with(@new_resource.service_name).and_return( double("StatusStruct", :current_state => "stopped")) @provider.load_current_resource - Win32::Service.should_not_receive(:stop).with(@new_resource.service_name) + expect(Win32::Service).not_to receive(:stop).with(@new_resource.service_name) @provider.stop_service - @new_resource.updated_by_last_action?.should be_false + expect(@new_resource.updated_by_last_action?).to be_false end it "should raise an error if the service is paused" do - Win32::Service.stub(:status).with(@new_resource.service_name).and_return( + allow(Win32::Service).to receive(:status).with(@new_resource.service_name).and_return( double("StatusStruct", :current_state => "paused")) @provider.load_current_resource - Win32::Service.should_not_receive(:start).with(@new_resource.service_name) + expect(Win32::Service).not_to receive(:start).with(@new_resource.service_name) expect { @provider.stop_service }.to raise_error( Chef::Exceptions::Service ) - @new_resource.updated_by_last_action?.should be_false + expect(@new_resource.updated_by_last_action?).to be_false end it "should wait and continue if the service is in stop_pending" do - Win32::Service.stub(:status).with(@new_resource.service_name).and_return( + allow(Win32::Service).to receive(:status).with(@new_resource.service_name).and_return( double("StatusStruct", :current_state => "stop pending"), double("StatusStruct", :current_state => "stop pending"), double("StatusStruct", :current_state => "stopped")) @provider.load_current_resource - Win32::Service.should_not_receive(:stop).with(@new_resource.service_name) + expect(Win32::Service).not_to receive(:stop).with(@new_resource.service_name) @provider.stop_service - @new_resource.updated_by_last_action?.should be_false + expect(@new_resource.updated_by_last_action?).to be_false end it "should fail if the service is in start_pending" do - Win32::Service.stub(:status).with(@new_resource.service_name).and_return( + allow(Win32::Service).to receive(:status).with(@new_resource.service_name).and_return( double("StatusStruct", :current_state => "start pending")) @provider.load_current_resource - Win32::Service.should_not_receive(:stop).with(@new_resource.service_name) + expect(Win32::Service).not_to receive(:stop).with(@new_resource.service_name) expect { @provider.stop_service }.to raise_error( Chef::Exceptions::Service ) - @new_resource.updated_by_last_action?.should be_false + expect(@new_resource.updated_by_last_action?).to be_false end it "should pass custom timeout to the stop command if provided" do - Win32::Service.stub(:status).with(@new_resource.service_name).and_return( + allow(Win32::Service).to receive(:status).with(@new_resource.service_name).and_return( double("StatusStruct", :current_state => "running")) @new_resource.timeout 1 - Win32::Service.should_receive(:stop).with(@new_resource.service_name) + expect(Win32::Service).to receive(:stop).with(@new_resource.service_name) Timeout.timeout(2) do expect { @provider.stop_service }.to raise_error(Timeout::Error) end - @new_resource.updated_by_last_action?.should be_false + expect(@new_resource.updated_by_last_action?).to be_false end end @@ -217,112 +217,112 @@ describe Chef::Provider::Service::Windows, "load_current_resource" do it "should call the restart command if one is specified" do @new_resource.restart_command "sc restart" - @provider.should_receive(:shell_out!).with("#{@new_resource.restart_command}") + expect(@provider).to receive(:shell_out!).with("#{@new_resource.restart_command}") @provider.restart_service - @new_resource.updated_by_last_action?.should be_true + expect(@new_resource.updated_by_last_action?).to be_true end it "should stop then start the service if it is running" do - Win32::Service.stub(:status).with(@new_resource.service_name).and_return( + allow(Win32::Service).to receive(:status).with(@new_resource.service_name).and_return( double("StatusStruct", :current_state => "running"), double("StatusStruct", :current_state => "stopped"), double("StatusStruct", :current_state => "stopped"), double("StatusStruct", :current_state => "running")) - Win32::Service.should_receive(:stop).with(@new_resource.service_name) - Win32::Service.should_receive(:start).with(@new_resource.service_name) + expect(Win32::Service).to receive(:stop).with(@new_resource.service_name) + expect(Win32::Service).to receive(:start).with(@new_resource.service_name) @provider.restart_service - @new_resource.updated_by_last_action?.should be_true + expect(@new_resource.updated_by_last_action?).to be_true end it "should just start the service if it is stopped" do - Win32::Service.stub(:status).with(@new_resource.service_name).and_return( + allow(Win32::Service).to receive(:status).with(@new_resource.service_name).and_return( double("StatusStruct", :current_state => "stopped"), double("StatusStruct", :current_state => "stopped"), double("StatusStruct", :current_state => "running")) - Win32::Service.should_receive(:start).with(@new_resource.service_name) + expect(Win32::Service).to receive(:start).with(@new_resource.service_name) @provider.restart_service - @new_resource.updated_by_last_action?.should be_true + expect(@new_resource.updated_by_last_action?).to be_true end it "should do nothing if the service does not exist" do - Win32::Service.stub(:exists?).with(@new_resource.service_name).and_return(false) - Win32::Service.should_not_receive(:stop).with(@new_resource.service_name) - Win32::Service.should_not_receive(:start).with(@new_resource.service_name) + allow(Win32::Service).to receive(:exists?).with(@new_resource.service_name).and_return(false) + expect(Win32::Service).not_to receive(:stop).with(@new_resource.service_name) + expect(Win32::Service).not_to receive(:start).with(@new_resource.service_name) @provider.restart_service - @new_resource.updated_by_last_action?.should be_false + expect(@new_resource.updated_by_last_action?).to be_false end end describe Chef::Provider::Service::Windows, "enable_service" do before(:each) do - Win32::Service.stub(:config_info).with(@new_resource.service_name).and_return( + allow(Win32::Service).to receive(:config_info).with(@new_resource.service_name).and_return( double("ConfigStruct", :start_type => "disabled")) end it "should enable service" do - Win32::Service.should_receive(:configure).with(:service_name => @new_resource.service_name, :start_type => Win32::Service::AUTO_START) + expect(Win32::Service).to receive(:configure).with(:service_name => @new_resource.service_name, :start_type => Win32::Service::AUTO_START) @provider.enable_service - @new_resource.updated_by_last_action?.should be_true + expect(@new_resource.updated_by_last_action?).to be_true end it "should do nothing if the service does not exist" do - Win32::Service.stub(:exists?).with(@new_resource.service_name).and_return(false) - Win32::Service.should_not_receive(:configure) + allow(Win32::Service).to receive(:exists?).with(@new_resource.service_name).and_return(false) + expect(Win32::Service).not_to receive(:configure) @provider.enable_service - @new_resource.updated_by_last_action?.should be_false + expect(@new_resource.updated_by_last_action?).to be_false end end describe Chef::Provider::Service::Windows, "action_enable" do it "does nothing if the service is enabled" do - Win32::Service.stub(:config_info).with(@new_resource.service_name).and_return( + allow(Win32::Service).to receive(:config_info).with(@new_resource.service_name).and_return( double("ConfigStruct", :start_type => "auto start")) - @provider.should_not_receive(:enable_service) + expect(@provider).not_to receive(:enable_service) @provider.action_enable end it "enables the service if it is not set to automatic start" do - Win32::Service.stub(:config_info).with(@new_resource.service_name).and_return( + allow(Win32::Service).to receive(:config_info).with(@new_resource.service_name).and_return( double("ConfigStruct", :start_type => "disabled")) - @provider.should_receive(:enable_service) + expect(@provider).to receive(:enable_service) @provider.action_enable end end describe Chef::Provider::Service::Windows, "action_disable" do it "does nothing if the service is disabled" do - Win32::Service.stub(:config_info).with(@new_resource.service_name).and_return( + allow(Win32::Service).to receive(:config_info).with(@new_resource.service_name).and_return( double("ConfigStruct", :start_type => "disabled")) - @provider.should_not_receive(:disable_service) + expect(@provider).not_to receive(:disable_service) @provider.action_disable end it "disables the service if it is not set to disabled" do - Win32::Service.stub(:config_info).with(@new_resource.service_name).and_return( + allow(Win32::Service).to receive(:config_info).with(@new_resource.service_name).and_return( double("ConfigStruct", :start_type => "auto start")) - @provider.should_receive(:disable_service) + expect(@provider).to receive(:disable_service) @provider.action_disable end end describe Chef::Provider::Service::Windows, "disable_service" do before(:each) do - Win32::Service.stub(:config_info).with(@new_resource.service_name).and_return( + allow(Win32::Service).to receive(:config_info).with(@new_resource.service_name).and_return( double("ConfigStruct", :start_type => "auto start")) end it "should disable service" do - Win32::Service.should_receive(:configure) + expect(Win32::Service).to receive(:configure) @provider.disable_service - @new_resource.updated_by_last_action?.should be_true + expect(@new_resource.updated_by_last_action?).to be_true end it "should do nothing if the service does not exist" do - Win32::Service.stub(:exists?).with(@new_resource.service_name).and_return(false) - Win32::Service.should_not_receive(:configure) + allow(Win32::Service).to receive(:exists?).with(@new_resource.service_name).and_return(false) + expect(Win32::Service).not_to receive(:configure) @provider.disable_service - @new_resource.updated_by_last_action?.should be_false + expect(@new_resource.updated_by_last_action?).to be_false end end @@ -330,15 +330,15 @@ describe Chef::Provider::Service::Windows, "load_current_resource" do { :automatic => "auto start", :manual => "demand start", :disabled => "disabled" }.each do |type,win32| it "sets the startup type to #{type} if it is something else" do @new_resource.startup_type(type) - @provider.stub(:current_start_type).and_return("fire") - @provider.should_receive(:set_startup_type).with(type) + allow(@provider).to receive(:current_start_type).and_return("fire") + expect(@provider).to receive(:set_startup_type).with(type) @provider.action_configure_startup end it "leaves the startup type as #{type} if it is already set" do @new_resource.startup_type(type) - @provider.stub(:current_start_type).and_return(win32) - @provider.should_not_receive(:set_startup_type).with(type) + allow(@provider).to receive(:current_start_type).and_return(win32) + expect(@provider).not_to receive(:set_startup_type).with(type) @provider.action_configure_startup end end @@ -346,17 +346,17 @@ describe Chef::Provider::Service::Windows, "load_current_resource" do describe Chef::Provider::Service::Windows, "set_start_type" do it "when called with :automatic it calls Win32::Service#configure with Win32::Service::AUTO_START" do - Win32::Service.should_receive(:configure).with(:service_name => @new_resource.service_name, :start_type => Win32::Service::AUTO_START) + expect(Win32::Service).to receive(:configure).with(:service_name => @new_resource.service_name, :start_type => Win32::Service::AUTO_START) @provider.send(:set_startup_type, :automatic) end it "when called with :manual it calls Win32::Service#configure with Win32::Service::DEMAND_START" do - Win32::Service.should_receive(:configure).with(:service_name => @new_resource.service_name, :start_type => Win32::Service::DEMAND_START) + expect(Win32::Service).to receive(:configure).with(:service_name => @new_resource.service_name, :start_type => Win32::Service::DEMAND_START) @provider.send(:set_startup_type, :manual) end it "when called with :disabled it calls Win32::Service#configure with Win32::Service::DISABLED" do - Win32::Service.should_receive(:configure).with(:service_name => @new_resource.service_name, :start_type => Win32::Service::DISABLED) + expect(Win32::Service).to receive(:configure).with(:service_name => @new_resource.service_name, :start_type => Win32::Service::DISABLED) @provider.send(:set_startup_type, :disabled) end diff --git a/spec/unit/provider/service_spec.rb b/spec/unit/provider/service_spec.rb index 7ddc01ff0b..e60b08e7f0 100644 --- a/spec/unit/provider/service_spec.rb +++ b/spec/unit/provider/service_spec.rb @@ -28,73 +28,73 @@ describe Chef::Provider::Service do @provider = Chef::Provider::Service.new(@new_resource, @run_context) @provider.current_resource = @current_resource - @provider.stub(:load_current_resource) + allow(@provider).to receive(:load_current_resource) end describe "when enabling the service" do it "should enable the service if disabled and set the resource as updated" do @current_resource.enabled(false) - @provider.should_receive(:enable_service).and_return(true) + expect(@provider).to receive(:enable_service).and_return(true) @provider.action_enable @provider.set_updated_status - @provider.new_resource.should be_updated + expect(@provider.new_resource).to be_updated end it "should not enable the service if already enabled" do @current_resource.enabled(true) - @provider.should_not_receive(:enable_service) + expect(@provider).not_to receive(:enable_service) @provider.action_enable @provider.set_updated_status - @provider.new_resource.should_not be_updated + expect(@provider.new_resource).not_to be_updated end end 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) - @provider.should_receive(:disable_service).and_return(true) + allow(@current_resource).to receive(:enabled).and_return(true) + expect(@provider).to receive(:disable_service).and_return(true) @provider.run_action(:disable) - @provider.new_resource.should be_updated + expect(@provider.new_resource).to be_updated end it "should not disable the service if already disabled" do - @current_resource.stub(:enabled).and_return(false) - @provider.should_not_receive(:disable_service) + allow(@current_resource).to receive(:enabled).and_return(false) + expect(@provider).not_to receive(:disable_service) @provider.run_action(:disable) - @provider.new_resource.should_not be_updated + expect(@provider.new_resource).not_to be_updated end end describe "action_start" do it "should start the service if it isn't running and set the resource as updated" do @current_resource.running(false) - @provider.should_receive(:start_service).with.and_return(true) + expect(@provider).to receive(:start_service).with.and_return(true) @provider.run_action(:start) - @provider.new_resource.should be_updated + expect(@provider.new_resource).to be_updated end it "should not start the service if already running" do @current_resource.running(true) - @provider.should_not_receive(:start_service) + expect(@provider).not_to receive(:start_service) @provider.run_action(:start) - @provider.new_resource.should_not be_updated + expect(@provider.new_resource).not_to be_updated end end 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) - @provider.should_receive(:stop_service).and_return(true) + allow(@current_resource).to receive(:running).and_return(true) + expect(@provider).to receive(:stop_service).and_return(true) @provider.run_action(:stop) - @provider.new_resource.should be_updated + expect(@provider.new_resource).to be_updated end it "should not stop the service if it's already stopped" do - @current_resource.stub(:running).and_return(false) - @provider.should_not_receive(:stop_service) + allow(@current_resource).to receive(:running).and_return(false) + expect(@provider).not_to receive(:stop_service) @provider.run_action(:stop) - @provider.new_resource.should_not be_updated + expect(@provider.new_resource).not_to be_updated end end @@ -104,16 +104,16 @@ describe Chef::Provider::Service do end it "should restart the service if it's supported and set the resource as updated" do - @provider.should_receive(:restart_service).and_return(true) + expect(@provider).to receive(:restart_service).and_return(true) @provider.run_action(:restart) - @provider.new_resource.should be_updated + expect(@provider.new_resource).to be_updated 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) - @provider.should_receive(:restart_service).and_return(true) + allow(@current_resource).to receive(:running).and_return(false) + expect(@provider).to receive(:restart_service).and_return(true) @provider.run_action(:restart) - @provider.new_resource.should be_updated + expect(@provider.new_resource).to be_updated end end @@ -124,46 +124,46 @@ 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) - lambda { @provider.run_action(:reload) }.should raise_error(Chef::Exceptions::UnsupportedAction) + allow(@new_resource).to receive(:reload_command).and_return(false) + expect { @provider.run_action(:reload) }.to 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) - @provider.should_receive(:reload_service).and_return(true) + allow(@current_resource).to receive(:running).and_return(true) + expect(@provider).to receive(:reload_service).and_return(true) @provider.run_action(:reload) - @provider.new_resource.should be_updated + expect(@provider.new_resource).to be_updated end it "should not reload the service if it's stopped" do - @current_resource.stub(:running).and_return(false) - @provider.should_not_receive(:reload_service) + allow(@current_resource).to receive(:running).and_return(false) + expect(@provider).not_to receive(:reload_service) @provider.run_action(:stop) - @provider.new_resource.should_not be_updated + expect(@provider.new_resource).not_to be_updated end end it "delegates enable_service to subclasses" do - lambda { @provider.enable_service }.should raise_error(Chef::Exceptions::UnsupportedAction) + expect { @provider.enable_service }.to raise_error(Chef::Exceptions::UnsupportedAction) end it "delegates disable_service to subclasses" do - lambda { @provider.disable_service }.should raise_error(Chef::Exceptions::UnsupportedAction) + expect { @provider.disable_service }.to raise_error(Chef::Exceptions::UnsupportedAction) end it "delegates start_service to subclasses" do - lambda { @provider.start_service }.should raise_error(Chef::Exceptions::UnsupportedAction) + expect { @provider.start_service }.to raise_error(Chef::Exceptions::UnsupportedAction) end it "delegates stop_service to subclasses" do - lambda { @provider.stop_service }.should raise_error(Chef::Exceptions::UnsupportedAction) + expect { @provider.stop_service }.to raise_error(Chef::Exceptions::UnsupportedAction) end it "delegates restart_service to subclasses" do - lambda { @provider.restart_service }.should raise_error(Chef::Exceptions::UnsupportedAction) + expect { @provider.restart_service }.to raise_error(Chef::Exceptions::UnsupportedAction) end it "delegates reload_service to subclasses" do - lambda { @provider.reload_service }.should raise_error(Chef::Exceptions::UnsupportedAction) + expect { @provider.reload_service }.to raise_error(Chef::Exceptions::UnsupportedAction) end end diff --git a/spec/unit/provider/subversion_spec.rb b/spec/unit/provider/subversion_spec.rb index 5d9d1cec1e..b372f0df7a 100644 --- a/spec/unit/provider/subversion_spec.rb +++ b/spec/unit/provider/subversion_spec.rb @@ -34,9 +34,9 @@ describe Chef::Provider::Subversion do end it "converts resource attributes to options for run_command and popen4" do - @provider.run_options.should == {} + expect(@provider.run_options).to eq({}) @resource.user 'deployninja' - @provider.run_options.should == {:user => "deployninja"} + expect(@provider.run_options).to eq({:user => "deployninja"}) end context "determining the revision of the currently deployed code" do @@ -48,8 +48,8 @@ describe Chef::Provider::Subversion do end it "sets the revision to nil if there isn't any deployed code yet" do - ::File.should_receive(:exist?).with("/my/deploy/dir/.svn").and_return(false) - @provider.find_current_revision.should be_nil + expect(::File).to receive(:exist?).with("/my/deploy/dir/.svn").and_return(false) + expect(@provider.find_current_revision).to be_nil end it "determines the current revision if there's a checkout with svn data available" do @@ -62,47 +62,47 @@ describe Chef::Provider::Subversion do "Last Changed Author: codeninja\n" + "Last Changed Rev: 11410\n" + # Last Changed Rev is preferred to Revision "Last Changed Date: 2009-03-25 06:09:56 -0600 (Wed, 25 Mar 2009)\n\n" - ::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) + expect(::File).to receive(:exist?).at_least(1).times.with("/my/deploy/dir/.svn").and_return(true) + expect(::File).to receive(:directory?).with("/my/deploy/dir").and_return(true) + expect(::Dir).to receive(:chdir).with("/my/deploy/dir").and_yield + allow(@stdout).to receive(:string).and_return(example_svn_info) + allow(@stderr).to receive(:string).and_return("") + allow(@exitstatus).to receive(:exitstatus).and_return(0) expected_command = ["svn info", {:cwd=>"/my/deploy/dir"}] - @provider.should_receive(:popen4).with(*expected_command). + expect(@provider).to receive(:popen4).with(*expected_command). and_yield("no-pid", "no-stdin", @stdout,@stderr). and_return(@exitstatus) - @provider.find_current_revision.should eql("11410") + expect(@provider.find_current_revision).to eql("11410") end it "gives nil as the current revision if the deploy dir isn't a SVN working copy" do example_svn_info = "svn: '/tmp/deploydir' is not a working copy\n" - ::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) - @provider.should_receive(:popen4).and_yield("no-pid", "no-stdin", @stdout,@stderr). + expect(::File).to receive(:exist?).with("/my/deploy/dir/.svn").and_return(true) + expect(::File).to receive(:directory?).with("/my/deploy/dir").and_return(true) + expect(::Dir).to receive(:chdir).with("/my/deploy/dir").and_yield + allow(@stdout).to receive(:string).and_return(example_svn_info) + allow(@stderr).to receive(:string).and_return("") + allow(@exitstatus).to receive(:exitstatus).and_return(1) + expect(@provider).to receive(:popen4).and_yield("no-pid", "no-stdin", @stdout,@stderr). and_return(@exitstatus) - @provider.find_current_revision.should be_nil + expect(@provider.find_current_revision).to be_nil end it "finds the current revision when loading the current resource state" do # note: the test is kinda janky, but it provides regression coverage for CHEF-2092 @resource.instance_variable_set(:@action, :sync) - @provider.should_receive(:find_current_revision).and_return("12345") + expect(@provider).to receive(:find_current_revision).and_return("12345") @provider.load_current_resource - @provider.current_resource.revision.should == "12345" + expect(@provider.current_resource.revision).to eq("12345") end 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") + allow(@provider).to receive(: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) - @provider.current_resource.revision.should eql("11410") + expect(@provider.current_resource.name).to eql(@resource.name) + expect(@provider.current_resource.revision).to eql("11410") end context "resolving revisions to an integer" do @@ -114,7 +114,7 @@ describe Chef::Provider::Subversion do end it "returns the revision number as is if it's already an integer" do - @provider.revision_int.should eql("12345") + expect(@provider.revision_int).to eql("12345") end it "queries the server and resolves the revision if it's not an integer (i.e. 'HEAD')" do @@ -128,153 +128,153 @@ 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 = double("exitstatus") - exitstatus.stub(:exitstatus).and_return(0) + allow(exitstatus).to receive(:exitstatus).and_return(0) @resource.revision "HEAD" - @stdout.stub(:string).and_return(example_svn_info) - @stderr.stub(:string).and_return("") + allow(@stdout).to receive(:string).and_return(example_svn_info) + allow(@stderr).to receive(: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). + expect(@provider).to receive(:popen4).with(*expected_command). and_yield("no-pid","no-stdin",@stdout,@stderr). and_return(exitstatus) - @provider.revision_int.should eql("11410") + expect(@provider.revision_int).to eql("11410") end 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 = double("exitstatus") - exitstatus.stub(:exitstatus).and_return(0) + allow(exitstatus).to receive(:exitstatus).and_return(0) @resource.revision "HEAD" - @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). + allow(@stdout).to receive(:string).and_return(example_svn_info) + allow(@stderr).to receive(:string).and_return("") + expect(@provider).to 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") + expect {@provider.revision_int}.to raise_error(RuntimeError, "Could not parse `svn info` data: some random text from an error message") end it "responds to :revision_slug as an alias for revision_sha" do - @provider.should respond_to(:revision_slug) + expect(@provider).to respond_to(:revision_slug) end end it "generates a checkout command with default options" do - @provider.checkout_command.should eql("svn checkout -q -r12345 http://svn.example.org/trunk/ /my/deploy/dir") + expect(@provider.checkout_command).to eql("svn checkout -q -r12345 http://svn.example.org/trunk/ /my/deploy/dir") end it "generates a checkout command with authentication" do @resource.svn_username "deployNinja" @resource.svn_password "vanish!" - @provider.checkout_command.should eql("svn checkout -q --username deployNinja --password vanish! " + + expect(@provider.checkout_command).to eql("svn checkout -q --username deployNinja --password vanish! " + "-r12345 http://svn.example.org/trunk/ /my/deploy/dir") end it "generates a checkout command with arbitrary options" do @resource.svn_arguments "--no-auth-cache" - @provider.checkout_command.should eql("svn checkout --no-auth-cache -q -r12345 "+ + expect(@provider.checkout_command).to eql("svn checkout --no-auth-cache -q -r12345 "+ "http://svn.example.org/trunk/ /my/deploy/dir") end it "generates a sync command with default options" do - @provider.sync_command.should eql("svn update -q -r12345 /my/deploy/dir") + expect(@provider.sync_command).to eql("svn update -q -r12345 /my/deploy/dir") end it "generates an export command with default options" do - @provider.export_command.should eql("svn export --force -q -r12345 http://svn.example.org/trunk/ /my/deploy/dir") + expect(@provider.export_command).to eql("svn export --force -q -r12345 http://svn.example.org/trunk/ /my/deploy/dir") end it "doesn't try to find the current revision when loading the resource if running an export" do @provider.new_resource.instance_variable_set :@action, [:export] - @provider.should_not_receive(:find_current_revision) + expect(@provider).not_to receive(:find_current_revision) @provider.load_current_resource end it "doesn't try to find the current revision when loading the resource if running a force export" do @provider.new_resource.instance_variable_set :@action, [:force_export] - @provider.should_not_receive(:find_current_revision) + expect(@provider).not_to receive(:find_current_revision) @provider.load_current_resource end it "runs an export with the --force option" do - ::File.stub(:directory?).with("/my/deploy").and_return(true) + allow(::File).to receive(: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(:shell_out!).with(command: expected_cmd) + expect(@provider).to receive(:shell_out!).with(command: expected_cmd) @provider.run_action(:force_export) - @resource.should be_updated + expect(@resource).to be_updated end it "runs the checkout command for action_checkout" do - ::File.stub(:directory?).with("/my/deploy").and_return(true) + allow(::File).to receive(:directory?).with("/my/deploy").and_return(true) expected_cmd = "svn checkout -q -r12345 http://svn.example.org/trunk/ /my/deploy/dir" - @provider.should_receive(:shell_out!).with(command: expected_cmd) + expect(@provider).to receive(:shell_out!).with(command: expected_cmd) @provider.run_action(:checkout) - @resource.should be_updated + expect(@resource).to be_updated end it "raises an error if the svn checkout command would fail because the enclosing directory doesn't exist" do - lambda {@provider.run_action(:sync)}.should raise_error(Chef::Exceptions::MissingParentDirectory) + expect {@provider.run_action(:sync)}.to raise_error(Chef::Exceptions::MissingParentDirectory) 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']) - @provider.should_not_receive(:checkout_command) + allow(::File).to receive(:exist?).with("/my/deploy/dir/.svn").and_return(false) + allow(::File).to receive(:exist?).with("/my/deploy/dir").and_return(true) + allow(::File).to receive(:directory?).with("/my/deploy").and_return(true) + allow(::Dir).to receive(:entries).with("/my/deploy/dir").and_return(['.','..','foo','bar']) + expect(@provider).not_to receive(:checkout_command) @provider.run_action(:checkout) - @resource.should_not be_updated + expect(@resource).not_to 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) + allow(::File).to receive(: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" - @provider.should_receive(:shell_out!).with(command: expected_cmd, user: "whois", group: "thisis") + expect(@provider).to receive(:shell_out!).with(command: expected_cmd, user: "whois", group: "thisis") @provider.run_action(:checkout) - @resource.should be_updated + expect(@resource).to be_updated 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.should_receive(:exist?).with("/my/deploy/dir/.svn").twice.and_return(false) - @provider.should_receive(:action_checkout) + allow(::File).to receive(:directory?).with("/my/deploy").and_return(true) + expect(::File).to receive(:exist?).with("/my/deploy/dir/.svn").twice.and_return(false) + expect(@provider).to 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.should_receive(:exist?).with("/my/deploy/dir/.svn").twice.and_return(false) - @provider.should_receive(:action_checkout) + allow(::File).to receive(:directory?).with("/my/deploy").and_return(true) + expect(::File).to receive(:exist?).with("/my/deploy/dir/.svn").twice.and_return(false) + expect(@provider).to 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.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) + allow(::File).to receive(:directory?).with("/my/deploy").and_return(true) + expect(::File).to receive(:exist?).with("/my/deploy/dir/.svn").and_return(true) + allow(@provider).to receive(:find_current_revision).and_return("11410") + allow(@provider).to receive(:current_revision_matches_target_revision?).and_return(false) expected_cmd = "svn update -q -r12345 /my/deploy/dir" - @provider.should_receive(:shell_out!).with(command: expected_cmd) + expect(@provider).to receive(:shell_out!).with(command: expected_cmd) @provider.run_action(:sync) - @resource.should be_updated + expect(@resource).to be_updated 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.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) + allow(::File).to receive(:directory?).with("/my/deploy").and_return(true) + expect(::File).to receive(:exist?).with("/my/deploy/dir/.svn").and_return(true) + allow(@provider).to receive(:find_current_revision).and_return('12345') + allow(@provider).to receive(:current_revision_matches_target_revision?).and_return(true) @provider.run_action(:sync) - @resource.should_not be_updated + expect(@resource).not_to be_updated end it "runs the export_command on action_export" do - ::File.stub(:directory?).with("/my/deploy").and_return(true) + allow(::File).to receive(: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(:shell_out!).with(command: expected_cmd) + expect(@provider).to receive(:shell_out!).with(command: expected_cmd) @provider.run_action(:export) - @resource.should be_updated + expect(@resource).to be_updated end end diff --git a/spec/unit/provider/template/content_spec.rb b/spec/unit/provider/template/content_spec.rb index b419e70519..4b88a3aea5 100644 --- a/spec/unit/provider/template/content_spec.rb +++ b/spec/unit/provider/template/content_spec.rb @@ -54,25 +54,25 @@ describe Chef::Provider::Template::Content do end it "finds the template file in the cookbook cache if it isn't local" do - content.template_location.should == CHEF_SPEC_DATA + '/cookbooks/openldap/templates/default/openldap_stuff.conf.erb' + expect(content.template_location).to eq(CHEF_SPEC_DATA + '/cookbooks/openldap/templates/default/openldap_stuff.conf.erb') 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') - content.template_location.should == '/tmp/its_on_disk.erb' + allow(new_resource).to receive(:local).and_return(true) + allow(new_resource).to receive(:source).and_return('/tmp/its_on_disk.erb') + expect(content.template_location).to eq('/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") - content.template_location.should == CHEF_SPEC_DATA + '/cookbooks/openldap/templates/default/test.erb' + allow(new_resource).to receive(:cookbook_name).and_return('apache2') + allow(new_resource).to receive(:cookbook).and_return('openldap') + allow(new_resource).to receive(:source).and_return("test.erb") + expect(content.template_location).to eq(CHEF_SPEC_DATA + '/cookbooks/openldap/templates/default/test.erb') end it "creates the template with the rendered content" do run_context.node.normal[:slappiness] = "a warm gun" - IO.read(content.tempfile.path).should == "slappiness is a warm gun" + expect(IO.read(content.tempfile.path)).to eq("slappiness is a warm gun") end end diff --git a/spec/unit/provider/template_spec.rb b/spec/unit/provider/template_spec.rb index 514bdc12ff..713303d818 100644 --- a/spec/unit/provider/template_spec.rb +++ b/spec/unit/provider/template_spec.rb @@ -39,7 +39,7 @@ describe Chef::Provider::Template do let(:provider) do provider = described_class.new(resource, run_context) - provider.stub(:content).and_return(content) + allow(provider).to receive(:content).and_return(content) provider end @@ -51,7 +51,7 @@ describe Chef::Provider::Template do let(:content) do content = double('Chef::Provider::File::Content::Template', :template_location => "/foo/bar/baz") - File.stub(:exists?).with("/foo/bar/baz").and_return(true) + allow(File).to receive(:exists?).with("/foo/bar/baz").and_return(true) content end @@ -73,15 +73,15 @@ describe Chef::Provider::Template do let(:provider) do provider = described_class.new(resource, run_context) - provider.stub(:content).and_return(content) + allow(provider).to receive(:content).and_return(content) provider end it "stops executing when the local template source can't be found" do setup_normal_file - content.stub(:template_location).and_return("/baz/bar/foo") - File.stub(:exists?).with("/baz/bar/foo").and_return(false) - lambda { provider.run_action(:create) }.should raise_error Chef::Mixin::WhyRun::ResourceRequirements::Assertion::AssertionFailure + allow(content).to receive(:template_location).and_return("/baz/bar/foo") + allow(File).to receive(:exists?).with("/baz/bar/foo").and_return(false) + expect { provider.run_action(:create) }.to raise_error Chef::Mixin::WhyRun::ResourceRequirements::Assertion::AssertionFailure end end diff --git a/spec/unit/provider/user/dscl_spec.rb b/spec/unit/provider/user/dscl_spec.rb index c17aefb00d..c8dbef770e 100644 --- a/spec/unit/provider/user/dscl_spec.rb +++ b/spec/unit/provider/user/dscl_spec.rb @@ -24,12 +24,12 @@ require 'mixlib/shellout' describe Chef::Provider::User::Dscl do before do - Chef::Platform.stub(:windows?) { false } + allow(Chef::Platform).to receive(:windows?) { false } end let(:node) { node = Chef::Node.new - node.stub(:[]).with(:platform_version).and_return(mac_version) - node.stub(:[]).with(:platform).and_return("mac_os_x") + allow(node).to receive(:[]).with(:platform_version).and_return(mac_version) + allow(node).to receive(:[]).with(:platform).and_return("mac_os_x") node } @@ -115,38 +115,38 @@ ea18e18b720e358e7fbe3cfbeaa561456f6ba008937a30" describe "when shelling out to dscl" do it "should run dscl with the supplied cmd /Path args" do shell_return = ShellCmdResult.new('stdout', 'err', 0) - provider.should_receive(:shell_out).with("dscl . -cmd /Path args").and_return(shell_return) - provider.run_dscl("cmd /Path args").should == 'stdout' + expect(provider).to receive(:shell_out).with("dscl . -cmd /Path args").and_return(shell_return) + expect(provider.run_dscl("cmd /Path args")).to eq('stdout') end it "returns an empty string from delete commands" do shell_return = ShellCmdResult.new('out', 'err', 23) - provider.should_receive(:shell_out).with("dscl . -delete /Path args").and_return(shell_return) - provider.run_dscl("delete /Path args").should == "" + expect(provider).to receive(:shell_out).with("dscl . -delete /Path args").and_return(shell_return) + expect(provider.run_dscl("delete /Path args")).to eq("") end it "should raise an exception for any other command" do shell_return = ShellCmdResult.new('out', 'err', 23) - provider.should_receive(:shell_out).with('dscl . -cmd /Path arguments').and_return(shell_return) - lambda { provider.run_dscl("cmd /Path arguments") }.should raise_error(Chef::Exceptions::DsclCommandFailed) + expect(provider).to receive(:shell_out).with('dscl . -cmd /Path arguments').and_return(shell_return) + expect { provider.run_dscl("cmd /Path arguments") }.to raise_error(Chef::Exceptions::DsclCommandFailed) end it "raises an exception when dscl reports 'no such key'" do shell_return = ShellCmdResult.new("No such key: ", 'err', 23) - provider.should_receive(:shell_out).with('dscl . -cmd /Path args').and_return(shell_return) - lambda { provider.run_dscl("cmd /Path args") }.should raise_error(Chef::Exceptions::DsclCommandFailed) + expect(provider).to receive(:shell_out).with('dscl . -cmd /Path args').and_return(shell_return) + expect { provider.run_dscl("cmd /Path args") }.to raise_error(Chef::Exceptions::DsclCommandFailed) end it "raises an exception when dscl reports 'eDSRecordNotFound'" do shell_return = ShellCmdResult.new("<dscl_cmd> DS Error: -14136 (eDSRecordNotFound)", 'err', -14136) - provider.should_receive(:shell_out).with('dscl . -cmd /Path args').and_return(shell_return) - lambda { provider.run_dscl("cmd /Path args") }.should raise_error(Chef::Exceptions::DsclCommandFailed) + expect(provider).to receive(:shell_out).with('dscl . -cmd /Path args').and_return(shell_return) + expect { provider.run_dscl("cmd /Path args") }.to raise_error(Chef::Exceptions::DsclCommandFailed) end end describe "get_free_uid" do before do - provider.should_receive(:run_dscl).with("list /Users uid").and_return("\nwheel 200\nstaff 201\nbrahms 500\nchopin 501\n") + expect(provider).to receive(:run_dscl).with("list /Users uid").and_return("\nwheel 200\nstaff 201\nbrahms 500\nchopin 501\n") end describe "when resource is configured as system" do @@ -155,59 +155,59 @@ ea18e18b720e358e7fbe3cfbeaa561456f6ba008937a30" end it "should return the first unused uid number on or above 500" do - provider.get_free_uid.should eq(202) + expect(provider.get_free_uid).to eq(202) end end it "should return the first unused uid number on or above 200" do - provider.get_free_uid.should eq(502) + expect(provider.get_free_uid).to eq(502) end it "should raise an exception when the search limit is exhausted" do search_limit = 1 - lambda { provider.get_free_uid(search_limit) }.should raise_error(RuntimeError) + expect { provider.get_free_uid(search_limit) }.to raise_error(RuntimeError) end end describe "uid_used?" do it "should return false if not given any valid uid number" do - provider.uid_used?(nil).should be_false + expect(provider.uid_used?(nil)).to be_false end describe "when called with a user id" do before do - provider.should_receive(:run_dscl).with("list /Users uid").and_return("\naj 500\n") + expect(provider).to receive(:run_dscl).with("list /Users uid").and_return("\naj 500\n") end it "should return true for a used uid number" do - provider.uid_used?(500).should be_true + expect(provider.uid_used?(500)).to be_true end it "should return false for an unused uid number" do - provider.uid_used?(501).should be_false + expect(provider.uid_used?(501)).to be_false end end end 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.should_receive(:get_free_uid).and_return(501) - lambda { provider.dscl_set_uid }.should raise_error(Chef::Exceptions::RequestedUIDUnavailable) + allow(provider).to receive(:uid_used?).and_return(true) + expect(provider).to receive(:get_free_uid).and_return(501) + expect { provider.dscl_set_uid }.to raise_error(Chef::Exceptions::RequestedUIDUnavailable) end it "finds a valid, unused uid when none is specified" do - provider.should_receive(:run_dscl).with("list /Users uid").and_return('') - provider.should_receive(:run_dscl).with("create /Users/toor UniqueID 501") - provider.should_receive(:get_free_uid).and_return(501) + expect(provider).to receive(:run_dscl).with("list /Users uid").and_return('') + expect(provider).to receive(:run_dscl).with("create /Users/toor UniqueID 501") + expect(provider).to receive(:get_free_uid).and_return(501) provider.dscl_set_uid - new_resource.uid.should eq(501) + expect(new_resource.uid).to eq(501) end it "sets the uid specified in the resource" do new_resource.uid(1000) - provider.should_receive(:run_dscl).with("create /Users/toor UniqueID 1000").and_return(true) - provider.should_receive(:run_dscl).with("list /Users uid").and_return('') + expect(provider).to receive(:run_dscl).with("create /Users/toor UniqueID 1000").and_return(true) + expect(provider).to receive(:run_dscl).with("list /Users uid").and_return('') provider.dscl_set_uid end end @@ -226,14 +226,14 @@ ea18e18b720e358e7fbe3cfbeaa561456f6ba008937a30" it "deletes the home directory when resource#home is nil" do new_resource.instance_variable_set(:@home, nil) - provider.should_receive(:run_dscl).with("delete /Users/toor NFSHomeDirectory").and_return(true) + expect(provider).to receive(:run_dscl).with("delete /Users/toor NFSHomeDirectory").and_return(true) provider.dscl_set_home end it "raises InvalidHomeDirectory when the resource's home directory doesn't look right" do new_resource.home('epic-fail') - lambda { provider.dscl_set_home }.should raise_error(Chef::Exceptions::InvalidHomeDirectory) + expect { provider.dscl_set_home }.to raise_error(Chef::Exceptions::InvalidHomeDirectory) end it "moves the users home to the new location if it exists and the target location is different" do @@ -243,34 +243,34 @@ ea18e18b720e358e7fbe3cfbeaa561456f6ba008937a30" 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) + allow(::File).to receive(:exists?).with('/old/home/toor').and_return(true) + allow(::File).to receive(: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) - ::Dir.should_receive(:glob).with("#{CHEF_SPEC_DATA}/old_home_dir/*",::File::FNM_DOTMATCH).and_return(current_home_files) - FileUtils.should_receive(:mv).with(current_home_files, "/Users/toor", :force => true) - FileUtils.should_receive(:chown_R).with('toor','23','/Users/toor') + expect(FileUtils).to receive(:mkdir_p).with('/Users/toor').and_return(true) + expect(FileUtils).to receive(:rmdir).with(current_home) + expect(::Dir).to receive(:glob).with("#{CHEF_SPEC_DATA}/old_home_dir/*",::File::FNM_DOTMATCH).and_return(current_home_files) + expect(FileUtils).to receive(:mv).with(current_home_files, "/Users/toor", :force => true) + expect(FileUtils).to receive(:chown_R).with('toor','23','/Users/toor') - provider.should_receive(:run_dscl).with("create /Users/toor NFSHomeDirectory '/Users/toor'") + expect(provider).to receive(:run_dscl).with("create /Users/toor NFSHomeDirectory '/Users/toor'") provider.dscl_set_home 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) - lambda { provider.dscl_set_home }.should raise_error(Chef::Exceptions::User) + allow(::File).to receive(:exists?).and_return(false,false,false) + expect { provider.dscl_set_home }.to raise_error(Chef::Exceptions::User) end it "should run ditto to copy any missing files from skel to the new home dir" do - ::File.should_receive(:exists?).with("/System/Library/User\ Template/English.lproj").and_return(true) - FileUtils.should_receive(:chown_R).with('toor', '', '/Users/toor') - provider.should_receive(:shell_out!).with("ditto '/System/Library/User Template/English.lproj' '/Users/toor'") + expect(::File).to receive(:exists?).with("/System/Library/User\ Template/English.lproj").and_return(true) + expect(FileUtils).to receive(:chown_R).with('toor', '', '/Users/toor') + expect(provider).to receive(:shell_out!).with("ditto '/System/Library/User Template/English.lproj' '/Users/toor'") provider.ditto_home end it "creates the user's NFSHomeDirectory and home directory" do - provider.should_receive(:run_dscl).with("create /Users/toor NFSHomeDirectory '/Users/toor'").and_return(true) - provider.should_receive(:ditto_home) + expect(provider).to receive(:run_dscl).with("create /Users/toor NFSHomeDirectory '/Users/toor'").and_return(true) + expect(provider).to receive(:ditto_home) provider.dscl_set_home end end @@ -280,8 +280,8 @@ ea18e18b720e358e7fbe3cfbeaa561456f6ba008937a30" let(:plutil_exists) { true } before do - ::File.stub(:exists?).with("/usr/bin/dscl").and_return(dscl_exists) - ::File.stub(:exists?).with("/usr/bin/plutil").and_return(plutil_exists) + allow(::File).to receive(:exists?).with("/usr/bin/dscl").and_return(dscl_exists) + allow(::File).to receive(:exists?).with("/usr/bin/plutil").and_return(plutil_exists) end def run_requirements @@ -294,7 +294,7 @@ ea18e18b720e358e7fbe3cfbeaa561456f6ba008937a30" let(:dscl_exists) { false } it "should raise an error" do - lambda { run_requirements }.should raise_error + expect { run_requirements }.to raise_error end end @@ -302,7 +302,7 @@ ea18e18b720e358e7fbe3cfbeaa561456f6ba008937a30" let(:plutil_exists) { false } it "should raise an error" do - lambda { run_requirements }.should raise_error + expect { run_requirements }.to raise_error end end @@ -312,7 +312,7 @@ ea18e18b720e358e7fbe3cfbeaa561456f6ba008937a30" } it "should raise an error" do - lambda { run_requirements }.should raise_error + expect { run_requirements }.to raise_error end end @@ -325,7 +325,7 @@ ea18e18b720e358e7fbe3cfbeaa561456f6ba008937a30" let(:password) { salted_sha512_password } it "should not raise an error" do - lambda { run_requirements }.should_not raise_error + expect { run_requirements }.not_to raise_error end end @@ -333,7 +333,7 @@ ea18e18b720e358e7fbe3cfbeaa561456f6ba008937a30" let(:password) { salted_sha512_pbkdf2_password } it "should raise an error" do - lambda { run_requirements }.should raise_error + expect { run_requirements }.to raise_error end end end @@ -348,7 +348,7 @@ ea18e18b720e358e7fbe3cfbeaa561456f6ba008937a30" let(:password) { salted_sha512_password } it "should raise an error" do - lambda { run_requirements }.should raise_error + expect { run_requirements }.to raise_error end end @@ -357,7 +357,7 @@ ea18e18b720e358e7fbe3cfbeaa561456f6ba008937a30" describe "when salt and iteration is not set" do it "should raise an error" do - lambda { run_requirements }.should raise_error + expect { run_requirements }.to raise_error end end @@ -366,7 +366,7 @@ ea18e18b720e358e7fbe3cfbeaa561456f6ba008937a30" let(:iterations) { salted_sha512_pbkdf2_iterations } it "should not raise an error" do - lambda { run_requirements }.should_not raise_error + expect { run_requirements }.not_to raise_error end end end @@ -379,8 +379,8 @@ ea18e18b720e358e7fbe3cfbeaa561456f6ba008937a30" let(:user_plist_file) { nil } before do - provider.should_receive(:shell_out).with("dscacheutil '-flushcache'") - provider.should_receive(:shell_out).with("plutil -convert xml1 -o - /var/db/dslocal/nodes/Default/users/toor.plist") do + expect(provider).to receive(:shell_out).with("dscacheutil '-flushcache'") + expect(provider).to receive(:shell_out).with("plutil -convert xml1 -o - /var/db/dslocal/nodes/Default/users/toor.plist") do if user_plist_file.nil? ShellCmdResult.new('Can not find the file', 'Sorry!!', 1) else @@ -389,23 +389,23 @@ ea18e18b720e358e7fbe3cfbeaa561456f6ba008937a30" end if !user_plist_file.nil? - provider.should_receive(:convert_binary_plist_to_xml).and_return(File.read(File.join(CHEF_SPEC_DATA, "mac_users/#{user_plist_file}.shadow.xml"))) + expect(provider).to receive(:convert_binary_plist_to_xml).and_return(File.read(File.join(CHEF_SPEC_DATA, "mac_users/#{user_plist_file}.shadow.xml"))) end end describe "when user is not there" do it "shouldn't raise an error" do - lambda { provider.load_current_resource }.should_not raise_error + expect { provider.load_current_resource }.not_to raise_error end it "should set @user_exists" do provider.load_current_resource - provider.instance_variable_get(:@user_exists).should be_false + expect(provider.instance_variable_get(:@user_exists)).to be_false end it "should set username" do provider.load_current_resource - provider.current_resource.username.should eq("toor") + expect(provider.current_resource.username).to eq("toor") end end @@ -421,12 +421,12 @@ ea18e18b720e358e7fbe3cfbeaa561456f6ba008937a30" it "collects the user data correctly" do provider.load_current_resource - provider.current_resource.comment.should eq("vagrant") - provider.current_resource.uid.should eq("11112222-3333-4444-AAAA-BBBBCCCCDDDD") - provider.current_resource.gid.should eq("80") - provider.current_resource.home.should eq("/Users/vagrant") - provider.current_resource.shell.should eq("/bin/bash") - provider.current_resource.password.should eq(vagrant_sha_512) + expect(provider.current_resource.comment).to eq("vagrant") + expect(provider.current_resource.uid).to eq("11112222-3333-4444-AAAA-BBBBCCCCDDDD") + expect(provider.current_resource.gid).to eq("80") + expect(provider.current_resource.home).to eq("/Users/vagrant") + expect(provider.current_resource.shell).to eq("/bin/bash") + expect(provider.current_resource.password).to eq(vagrant_sha_512) end describe "when a plain password is set that is same" do @@ -434,7 +434,7 @@ ea18e18b720e358e7fbe3cfbeaa561456f6ba008937a30" it "diverged_password? should report false" do provider.load_current_resource - provider.diverged_password?.should be_false + expect(provider.diverged_password?).to be_false end end @@ -443,7 +443,7 @@ ea18e18b720e358e7fbe3cfbeaa561456f6ba008937a30" it "diverged_password? should report true" do provider.load_current_resource - provider.diverged_password?.should be_true + expect(provider.diverged_password?).to be_true end end @@ -453,7 +453,7 @@ ea18e18b720e358e7fbe3cfbeaa561456f6ba008937a30" it "diverged_password? should report false" do provider.load_current_resource - provider.diverged_password?.should be_false + expect(provider.diverged_password?).to be_false end end @@ -462,7 +462,7 @@ ea18e18b720e358e7fbe3cfbeaa561456f6ba008937a30" it "diverged_password? should report true" do provider.load_current_resource - provider.diverged_password?.should be_true + expect(provider.diverged_password?).to be_true end end @@ -472,7 +472,7 @@ ea18e18b720e358e7fbe3cfbeaa561456f6ba008937a30" it "diverged_password? should report false" do provider.load_current_resource - provider.diverged_password?.should be_false + expect(provider.diverged_password?).to be_false end end end @@ -486,19 +486,19 @@ ea18e18b720e358e7fbe3cfbeaa561456f6ba008937a30" it "collects the user data correctly" do provider.load_current_resource - provider.current_resource.comment.should eq("vagrant") - provider.current_resource.uid.should eq("11112222-3333-4444-AAAA-BBBBCCCCDDDD") - provider.current_resource.gid.should eq("80") - provider.current_resource.home.should eq("/Users/vagrant") - provider.current_resource.shell.should eq("/bin/bash") - provider.current_resource.password.should eq("ea4c2d265d801ba0ec0dfccd\ + expect(provider.current_resource.comment).to eq("vagrant") + expect(provider.current_resource.uid).to eq("11112222-3333-4444-AAAA-BBBBCCCCDDDD") + expect(provider.current_resource.gid).to eq("80") + expect(provider.current_resource.home).to eq("/Users/vagrant") + expect(provider.current_resource.shell).to eq("/bin/bash") + expect(provider.current_resource.password).to eq("ea4c2d265d801ba0ec0dfccd\ 253dfc1de91cbe0806b4acc1ed7fe22aebcf6beb5344d0f442e590\ ffa04d679075da3afb119e41b72b5eaf08ee4aa54693722646d5\ 19ee04843deb8a3e977428d33f625e83887913e5c13b70035961\ 5e00ad7bc3e7a0c98afc3e19d1360272454f8d33a9214d2fbe8b\ e68d1f9821b26689312366") - provider.current_resource.salt.should eq("f994ef2f73b7c5594ebd1553300976b20733ce0e24d659783d87f3d81cbbb6a9") - provider.current_resource.iterations.should eq(39840) + expect(provider.current_resource.salt).to eq("f994ef2f73b7c5594ebd1553300976b20733ce0e24d659783d87f3d81cbbb6a9") + expect(provider.current_resource.iterations).to eq(39840) end end @@ -512,12 +512,12 @@ e68d1f9821b26689312366") it "collects the user data correctly" do provider.load_current_resource - provider.current_resource.comment.should eq("vagrant") - provider.current_resource.uid.should eq("11112222-3333-4444-AAAA-BBBBCCCCDDDD") - provider.current_resource.gid.should eq("80") - provider.current_resource.home.should eq("/Users/vagrant") - provider.current_resource.shell.should eq("/bin/bash") - provider.current_resource.password.should eq("6f75d7190441facc34291ebbea1fc756b242d4f\ + expect(provider.current_resource.comment).to eq("vagrant") + expect(provider.current_resource.uid).to eq("11112222-3333-4444-AAAA-BBBBCCCCDDDD") + expect(provider.current_resource.gid).to eq("80") + expect(provider.current_resource.home).to eq("/Users/vagrant") + expect(provider.current_resource.shell).to eq("/bin/bash") + expect(provider.current_resource.password).to eq("6f75d7190441facc34291ebbea1fc756b242d4f\ e9bcff141bccb84f1979e27e539539aa31f9f7dcc92c0cea959\ ea18e18b720e358e7fbe3cfbeaa561456f6ba008937a30") end @@ -525,7 +525,7 @@ ea18e18b720e358e7fbe3cfbeaa561456f6ba008937a30") describe "when a plain text password is set" do it "reports password needs to be updated" do provider.load_current_resource - provider.diverged_password?.should be_true + expect(provider.diverged_password?).to be_true end end @@ -536,7 +536,7 @@ ea18e18b720e358e7fbe3cfbeaa561456f6ba008937a30") it "reports password needs to be updated" do provider.load_current_resource - provider.diverged_password?.should be_true + expect(provider.diverged_password?).to be_true end end end @@ -550,14 +550,14 @@ ea18e18b720e358e7fbe3cfbeaa561456f6ba008937a30") it "collects the user data correctly" do provider.load_current_resource - provider.current_resource.comment.should eq("vagrant") - provider.current_resource.uid.should eq("11112222-3333-4444-AAAA-BBBBCCCCDDDD") - provider.current_resource.gid.should eq("80") - provider.current_resource.home.should eq("/Users/vagrant") - provider.current_resource.shell.should eq("/bin/bash") - provider.current_resource.password.should eq(vagrant_sha_512_pbkdf2) - provider.current_resource.salt.should eq(vagrant_sha_512_pbkdf2_salt) - provider.current_resource.iterations.should eq(vagrant_sha_512_pbkdf2_iterations) + expect(provider.current_resource.comment).to eq("vagrant") + expect(provider.current_resource.uid).to eq("11112222-3333-4444-AAAA-BBBBCCCCDDDD") + expect(provider.current_resource.gid).to eq("80") + expect(provider.current_resource.home).to eq("/Users/vagrant") + expect(provider.current_resource.shell).to eq("/bin/bash") + expect(provider.current_resource.password).to eq(vagrant_sha_512_pbkdf2) + expect(provider.current_resource.salt).to eq(vagrant_sha_512_pbkdf2_salt) + expect(provider.current_resource.iterations).to eq(vagrant_sha_512_pbkdf2_iterations) end describe "when a plain password is set that is same" do @@ -565,7 +565,7 @@ ea18e18b720e358e7fbe3cfbeaa561456f6ba008937a30") it "diverged_password? should report false" do provider.load_current_resource - provider.diverged_password?.should be_false + expect(provider.diverged_password?).to be_false end end @@ -574,7 +574,7 @@ ea18e18b720e358e7fbe3cfbeaa561456f6ba008937a30") it "diverged_password? should report true" do provider.load_current_resource - provider.diverged_password?.should be_true + expect(provider.diverged_password?).to be_true end end @@ -585,7 +585,7 @@ ea18e18b720e358e7fbe3cfbeaa561456f6ba008937a30") it "diverged_password? should report true" do provider.load_current_resource - provider.diverged_password?.should be_true + expect(provider.diverged_password?).to be_true end end @@ -596,7 +596,7 @@ ea18e18b720e358e7fbe3cfbeaa561456f6ba008937a30") it "diverged_password? should report true" do provider.load_current_resource - provider.diverged_password?.should be_true + expect(provider.diverged_password?).to be_true end end @@ -607,7 +607,7 @@ ea18e18b720e358e7fbe3cfbeaa561456f6ba008937a30") it "diverged_password? should report true" do provider.load_current_resource - provider.diverged_password?.should be_true + expect(provider.diverged_password?).to be_true end end end @@ -616,23 +616,23 @@ ea18e18b720e358e7fbe3cfbeaa561456f6ba008937a30") describe "salted_sha512_pbkdf2?" do it "should return true when the string is a salted_sha512_pbkdf2 hash" do - provider.salted_sha512_pbkdf2?(salted_sha512_pbkdf2_password).should be_true + expect(provider.salted_sha512_pbkdf2?(salted_sha512_pbkdf2_password)).to be_true end it "should return false otherwise" do - provider.salted_sha512_pbkdf2?(salted_sha512_password).should be_false - provider.salted_sha512_pbkdf2?("any other string").should be_false + expect(provider.salted_sha512_pbkdf2?(salted_sha512_password)).to be_false + expect(provider.salted_sha512_pbkdf2?("any other string")).to be_false end end describe "salted_sha512?" do it "should return true when the string is a salted_sha512_pbkdf2 hash" do - provider.salted_sha512_pbkdf2?(salted_sha512_pbkdf2_password).should be_true + expect(provider.salted_sha512_pbkdf2?(salted_sha512_pbkdf2_password)).to be_true end it "should return false otherwise" do - provider.salted_sha512?(salted_sha512_pbkdf2_password).should be_false - provider.salted_sha512?("any other string").should be_false + expect(provider.salted_sha512?(salted_sha512_pbkdf2_password)).to be_false + expect(provider.salted_sha512?("any other string")).to be_false end end @@ -647,9 +647,9 @@ ea18e18b720e358e7fbe3cfbeaa561456f6ba008937a30") it "password_shadow_info should have salted-sha-512 format" do shadow_info = provider.prepare_password_shadow_info - shadow_info.should have_key("SALTED-SHA512") + expect(shadow_info).to have_key("SALTED-SHA512") info = shadow_info["SALTED-SHA512"].string.unpack('H*').first - provider.salted_sha512?(info).should be_true + expect(provider.salted_sha512?(info)).to be_true end end @@ -658,10 +658,10 @@ ea18e18b720e358e7fbe3cfbeaa561456f6ba008937a30") it "password_shadow_info should have salted-sha-512 format" do shadow_info = provider.prepare_password_shadow_info - shadow_info.should have_key("SALTED-SHA512") + expect(shadow_info).to have_key("SALTED-SHA512") info = shadow_info["SALTED-SHA512"].string.unpack('H*').first - provider.salted_sha512?(info).should be_true - info.should eq(vagrant_sha_512) + expect(provider.salted_sha512?(info)).to be_true + expect(info).to eq(vagrant_sha_512) end end end @@ -677,12 +677,12 @@ ea18e18b720e358e7fbe3cfbeaa561456f6ba008937a30") it "password_shadow_info should have salted-sha-512 format" do shadow_info = provider.prepare_password_shadow_info - shadow_info.should have_key("SALTED-SHA512-PBKDF2") - shadow_info["SALTED-SHA512-PBKDF2"].should have_key("entropy") - shadow_info["SALTED-SHA512-PBKDF2"].should have_key("salt") - shadow_info["SALTED-SHA512-PBKDF2"].should have_key("iterations") + expect(shadow_info).to have_key("SALTED-SHA512-PBKDF2") + expect(shadow_info["SALTED-SHA512-PBKDF2"]).to have_key("entropy") + expect(shadow_info["SALTED-SHA512-PBKDF2"]).to have_key("salt") + expect(shadow_info["SALTED-SHA512-PBKDF2"]).to have_key("iterations") info = shadow_info["SALTED-SHA512-PBKDF2"]["entropy"].string.unpack('H*').first - provider.salted_sha512_pbkdf2?(info).should be_true + expect(provider.salted_sha512_pbkdf2?(info)).to be_true end end @@ -693,13 +693,13 @@ ea18e18b720e358e7fbe3cfbeaa561456f6ba008937a30") it "password_shadow_info should have salted-sha-512 format" do shadow_info = provider.prepare_password_shadow_info - shadow_info.should have_key("SALTED-SHA512-PBKDF2") - shadow_info["SALTED-SHA512-PBKDF2"].should have_key("entropy") - shadow_info["SALTED-SHA512-PBKDF2"].should have_key("salt") - shadow_info["SALTED-SHA512-PBKDF2"].should have_key("iterations") + expect(shadow_info).to have_key("SALTED-SHA512-PBKDF2") + expect(shadow_info["SALTED-SHA512-PBKDF2"]).to have_key("entropy") + expect(shadow_info["SALTED-SHA512-PBKDF2"]).to have_key("salt") + expect(shadow_info["SALTED-SHA512-PBKDF2"]).to have_key("iterations") info = shadow_info["SALTED-SHA512-PBKDF2"]["entropy"].string.unpack('H*').first - provider.salted_sha512_pbkdf2?(info).should be_true - info.should eq(vagrant_sha_512_pbkdf2) + expect(provider.salted_sha512_pbkdf2?(info)).to be_true + expect(info).to eq(vagrant_sha_512_pbkdf2) end end end @@ -712,14 +712,14 @@ ea18e18b720e358e7fbe3cfbeaa561456f6ba008937a30") end it "should sleep and flush the dscl cache before saving the password" do - provider.should_receive(:prepare_password_shadow_info).and_return({ }) + expect(provider).to receive(:prepare_password_shadow_info).and_return({ }) mock_shellout = double("Mock::Shellout") - mock_shellout.stub(:run_command) - Mixlib::ShellOut.should_receive(:new).and_return(mock_shellout) - provider.should_receive(:read_user_info) - provider.should_receive(:dscl_set) - provider.should_receive(:sleep).with(3) - provider.should_receive(:save_user_info) + allow(mock_shellout).to receive(:run_command) + expect(Mixlib::ShellOut).to receive(:new).and_return(mock_shellout) + expect(provider).to receive(:read_user_info) + expect(provider).to receive(:dscl_set) + expect(provider).to receive(:sleep).with(3) + expect(provider).to receive(:save_user_info) provider.set_password end end @@ -732,33 +732,33 @@ ea18e18b720e358e7fbe3cfbeaa561456f6ba008937a30") end it "creates the user, comment field, sets uid, gid, configures the home directory, sets the shell, and sets the password" do - provider.should_receive :dscl_create_user - provider.should_receive :dscl_create_comment - provider.should_receive :dscl_set_uid - provider.should_receive :dscl_set_gid - provider.should_receive :dscl_set_home - provider.should_receive :dscl_set_shell - provider.should_receive :set_password + expect(provider).to receive :dscl_create_user + expect(provider).to receive :dscl_create_comment + expect(provider).to receive :dscl_set_uid + expect(provider).to receive :dscl_set_gid + expect(provider).to receive :dscl_set_home + expect(provider).to receive :dscl_set_shell + expect(provider).to receive :set_password provider.create_user end it "creates the user and sets the comment field" do - provider.should_receive(:run_dscl).with("create /Users/toor").and_return(true) + expect(provider).to receive(:run_dscl).with("create /Users/toor").and_return(true) provider.dscl_create_user end it "sets the comment field" do - provider.should_receive(:run_dscl).with("create /Users/toor RealName '#mockssuck'").and_return(true) + expect(provider).to receive(:run_dscl).with("create /Users/toor RealName '#mockssuck'").and_return(true) provider.dscl_create_comment end it "should run run_dscl with create /Users/user PrimaryGroupID to set the users primary group" do - provider.should_receive(:run_dscl).with("create /Users/toor PrimaryGroupID '1001'").and_return(true) + expect(provider).to receive(:run_dscl).with("create /Users/toor PrimaryGroupID '1001'").and_return(true) provider.dscl_set_gid end it "should run run_dscl with create /Users/user UserShell to set the users login shell" do - provider.should_receive(:run_dscl).with("create /Users/toor UserShell '/usr/bin/false'").and_return(true) + expect(provider).to receive(:run_dscl).with("create /Users/toor UserShell '/usr/bin/false'").and_return(true) provider.dscl_set_shell end end @@ -770,15 +770,15 @@ ea18e18b720e358e7fbe3cfbeaa561456f6ba008937a30") end it "should map the group name to a numeric ID when the group exists" do - provider.should_receive(:run_dscl).with("read /Groups/newgroup PrimaryGroupID").ordered.and_return("PrimaryGroupID: 1001\n") - provider.should_receive(:run_dscl).with("create /Users/toor PrimaryGroupID '1001'").ordered.and_return(true) + expect(provider).to receive(:run_dscl).with("read /Groups/newgroup PrimaryGroupID").ordered.and_return("PrimaryGroupID: 1001\n") + expect(provider).to receive(:run_dscl).with("create /Users/toor PrimaryGroupID '1001'").ordered.and_return(true) provider.dscl_set_gid end it "should raise an exception when the group does not exist" do shell_return = ShellCmdResult.new("<dscl_cmd> DS Error: -14136 (eDSRecordNotFound)", 'err', -14136) - provider.should_receive(:shell_out).with('dscl . -read /Groups/newgroup PrimaryGroupID').and_return(shell_return) - lambda { provider.dscl_set_gid }.should raise_error(Chef::Exceptions::GroupIDNotFound) + expect(provider).to receive(:shell_out).with('dscl . -read /Groups/newgroup PrimaryGroupID').and_return(shell_return) + expect { provider.dscl_set_gid }.to raise_error(Chef::Exceptions::GroupIDNotFound) end end end @@ -797,13 +797,13 @@ ea18e18b720e358e7fbe3cfbeaa561456f6ba008937a30") end it "sets the user, comment field, uid, gid, moves the home directory, sets the shell, and sets the password" do - provider.should_receive :dscl_create_user - provider.should_receive :dscl_create_comment - provider.should_receive :dscl_set_uid - provider.should_receive :dscl_set_gid - provider.should_receive :dscl_set_home - provider.should_receive :dscl_set_shell - provider.should_receive :set_password + expect(provider).to receive :dscl_create_user + expect(provider).to receive :dscl_create_comment + expect(provider).to receive :dscl_set_uid + expect(provider).to receive :dscl_set_gid + expect(provider).to receive :dscl_set_home + expect(provider).to receive :dscl_set_shell + expect(provider).to receive :set_password provider.create_user end end @@ -818,15 +818,15 @@ ea18e18b720e358e7fbe3cfbeaa561456f6ba008937a30") end it "sets the gid" do - provider.should_receive :dscl_set_gid + expect(provider).to receive :dscl_set_gid provider.manage_user end end describe "when the user exists" do before do - provider.should_receive(:shell_out).with("dscacheutil '-flushcache'") - provider.should_receive(:shell_out).with("plutil -convert xml1 -o - /var/db/dslocal/nodes/Default/users/toor.plist") do + expect(provider).to receive(:shell_out).with("dscacheutil '-flushcache'") + expect(provider).to receive(:shell_out).with("plutil -convert xml1 -o - /var/db/dslocal/nodes/Default/users/toor.plist") do ShellCmdResult.new(File.read(File.join(CHEF_SPEC_DATA, "mac_users/10.9.plist.xml")), "", 0) end provider.load_current_resource @@ -835,20 +835,20 @@ ea18e18b720e358e7fbe3cfbeaa561456f6ba008937a30") describe "when Chef is removing the user" do it "removes the user from the groups and deletes home directory when the resource is configured to manage home" do new_resource.supports({ :manage_home => true }) - provider.should_receive(:run_dscl).with("list /Groups").and_return("my_group\nyour_group\nreal_group\n") - provider.should_receive(:run_dscl).with("read /Groups/my_group").and_raise(Chef::Exceptions::DsclCommandFailed) # Empty group - provider.should_receive(:run_dscl).with("read /Groups/your_group").and_return("GroupMembership: not_you") - provider.should_receive(:run_dscl).with("read /Groups/real_group").and_return("GroupMembership: toor") - provider.should_receive(:run_dscl).with("delete /Groups/real_group GroupMembership 'toor'") - provider.should_receive(:run_dscl).with("delete /Users/toor") - FileUtils.should_receive(:rm_rf).with("/Users/vagrant") + expect(provider).to receive(:run_dscl).with("list /Groups").and_return("my_group\nyour_group\nreal_group\n") + expect(provider).to receive(:run_dscl).with("read /Groups/my_group").and_raise(Chef::Exceptions::DsclCommandFailed) # Empty group + expect(provider).to receive(:run_dscl).with("read /Groups/your_group").and_return("GroupMembership: not_you") + expect(provider).to receive(:run_dscl).with("read /Groups/real_group").and_return("GroupMembership: toor") + expect(provider).to receive(:run_dscl).with("delete /Groups/real_group GroupMembership 'toor'") + expect(provider).to receive(:run_dscl).with("delete /Users/toor") + expect(FileUtils).to receive(:rm_rf).with("/Users/vagrant") provider.remove_user end end describe "when user is not locked" do it "determines the user as not locked" do - provider.should_not be_locked + expect(provider).not_to be_locked end end @@ -859,11 +859,11 @@ ea18e18b720e358e7fbe3cfbeaa561456f6ba008937a30") end it "determines the user as not locked" do - provider.should be_locked + expect(provider).to be_locked end it "can unlock the user" do - provider.should_receive(:run_dscl).with("create /Users/toor AuthenticationAuthority ';ShadowHash;HASHLIST:<SALTED-SHA512-PBKDF2>'") + expect(provider).to receive(:run_dscl).with("create /Users/toor AuthenticationAuthority ';ShadowHash;HASHLIST:<SALTED-SHA512-PBKDF2>'") provider.unlock_user end end @@ -871,7 +871,7 @@ ea18e18b720e358e7fbe3cfbeaa561456f6ba008937a30") describe "when locking the user" do it "should run run_dscl with append /Users/user AuthenticationAuthority ;DisabledUser; to lock the user account" do - provider.should_receive(:run_dscl).with("append /Users/toor AuthenticationAuthority ';DisabledUser;'") + expect(provider).to receive(:run_dscl).with("append /Users/toor AuthenticationAuthority ';DisabledUser;'") provider.lock_user end end diff --git a/spec/unit/provider/user/pw_spec.rb b/spec/unit/provider/user/pw_spec.rb index a577a57de9..b225972e87 100644 --- a/spec/unit/provider/user/pw_spec.rb +++ b/spec/unit/provider/user/pw_spec.rb @@ -56,64 +56,64 @@ describe Chef::Provider::User::Pw do } field_list.each do |attribute, option| it "should check for differences in #{attribute} between the new and current resources" do - @current_resource.should_receive(attribute) - @new_resource.should_receive(attribute) + expect(@current_resource).to receive(attribute) + expect(@new_resource).to receive(attribute) @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("hola") - @provider.set_options.should eql(" #{@new_resource.username} #{option} '#{@new_resource.send(attribute)}' -m") + allow(@new_resource).to receive(attribute).and_return("hola") + expect(@provider.set_options).to 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") - @provider.set_options.should eql(" #{@new_resource.username} #{option} '#{@new_resource.send(attribute)}'") + allow(@new_resource).to receive(:supports).and_return({:manage_home => false}) + allow(@new_resource).to receive(attribute).and_return("hola") + expect(@provider.set_options).to eql(" #{@new_resource.username} #{option} '#{@new_resource.send(attribute)}'") end end 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") + allow(@new_resource).to receive(attribute).and_return("hola") match_string << " #{option} 'hola'" end match_string << " -m" - @provider.set_options.should eql(match_string) + expect(@provider.set_options).to eql(match_string) end end describe "create_user" do before(:each) do - @provider.stub(:run_command).and_return(true) - @provider.stub(:modify_password).and_return(true) + allow(@provider).to receive(:run_command).and_return(true) + allow(@provider).to receive(:modify_password).and_return(true) end it "should run pw useradd with the return of set_options" do - @provider.should_receive(:run_command).with({ :command => "pw useradd adam -m" }).and_return(true) + expect(@provider).to receive(:run_command).with({ :command => "pw useradd adam -m" }).and_return(true) @provider.create_user end it "should modify the password" do - @provider.should_receive(:modify_password).and_return(true) + expect(@provider).to receive(:modify_password).and_return(true) @provider.create_user end end describe "manage_user" do before(:each) do - @provider.stub(:run_command).and_return(true) - @provider.stub(:modify_password).and_return(true) + allow(@provider).to receive(:run_command).and_return(true) + allow(@provider).to receive(:modify_password).and_return(true) end it "should run pw usermod with the return of set_options" do - @provider.should_receive(:run_command).with({ :command => "pw usermod adam -m" }).and_return(true) + expect(@provider).to receive(:run_command).with({ :command => "pw usermod adam -m" }).and_return(true) @provider.manage_user end it "should modify the password" do - @provider.should_receive(:modify_password).and_return(true) + expect(@provider).to receive(:modify_password).and_return(true) @provider.create_user end end @@ -121,38 +121,38 @@ describe Chef::Provider::User::Pw do describe "remove_user" do it "should run pw userdel with the new resources user name" do @new_resource.supports :manage_home => false - @provider.should_receive(:run_command).with({ :command => "pw userdel #{@new_resource.username}" }).and_return(true) + expect(@provider).to receive(:run_command).with({ :command => "pw userdel #{@new_resource.username}" }).and_return(true) @provider.remove_user end it "should run pw userdel with the new resources user name and -r if manage_home is true" do - @provider.should_receive(:run_command).with({ :command => "pw userdel #{@new_resource.username} -r"}).and_return(true) + expect(@provider).to receive(:run_command).with({ :command => "pw userdel #{@new_resource.username} -r"}).and_return(true) @provider.remove_user end end 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") - @provider.check_lock.should eql(true) + allow(@current_resource).to receive(:password).and_return("*LOCKED*abracadabra") + expect(@provider.check_lock).to eql(true) end it "should return false if user is not locked" do - @current_resource.stub(:password).and_return("abracadabra") - @provider.check_lock.should eql(false) + allow(@current_resource).to receive(:password).and_return("abracadabra") + expect(@provider.check_lock).to eql(false) end end describe "when locking the user" do it "should run pw lock with the new resources username" do - @provider.should_receive(:run_command).with({ :command => "pw lock #{@new_resource.username}"}) + expect(@provider).to receive(:run_command).with({ :command => "pw lock #{@new_resource.username}"}) @provider.lock_user end end describe "when unlocking the user" do it "should run pw unlock with the new resources username" do - @provider.should_receive(:run_command).with({ :command => "pw unlock #{@new_resource.username}"}) + expect(@provider).to receive(:run_command).with({ :command => "pw unlock #{@new_resource.username}"}) @provider.unlock_user end end @@ -160,76 +160,76 @@ describe Chef::Provider::User::Pw do describe "when modifying the password" do before(:each) do @status = double("Status", :exitstatus => 0) - @provider.stub(:popen4).and_return(@status) + allow(@provider).to receive(:popen4).and_return(@status) @pid, @stdin, @stdout, @stderr = nil, nil, nil, nil end describe "and the new password has not been specified" do before(:each) do - @new_resource.stub(:password).and_return(nil) + allow(@new_resource).to receive(:password).and_return(nil) end it "logs an appropriate message" do - Chef::Log.should_receive(:debug).with("user[adam] no change needed to password") + expect(Chef::Log).to receive(:debug).with("user[adam] no change needed to password") @provider.modify_password end end describe "and the new password has been specified" do before(:each) do - @new_resource.stub(:password).and_return("abracadabra") + allow(@new_resource).to receive(:password).and_return("abracadabra") end it "should check for differences in password between the new and current resources" do - @current_resource.should_receive(:password) - @new_resource.should_receive(:password) + expect(@current_resource).to receive(:password) + expect(@new_resource).to receive(:password) @provider.modify_password end end describe "and the passwords are identical" do before(:each) do - @new_resource.stub(:password).and_return("abracadabra") - @current_resource.stub(:password).and_return("abracadabra") + allow(@new_resource).to receive(:password).and_return("abracadabra") + allow(@current_resource).to receive(:password).and_return("abracadabra") end it "logs an appropriate message" do - Chef::Log.should_receive(:debug).with("user[adam] no change needed to password") + expect(Chef::Log).to receive(:debug).with("user[adam] no change needed to password") @provider.modify_password end end describe "and the passwords are different" do before(:each) do - @new_resource.stub(:password).and_return("abracadabra") - @current_resource.stub(:password).and_return("sesame") + allow(@new_resource).to receive(:password).and_return("abracadabra") + allow(@current_resource).to receive(:password).and_return("sesame") end it "should log an appropriate message" do - Chef::Log.should_receive(:debug).with("user[adam] updating password") + expect(Chef::Log).to receive(:debug).with("user[adam] updating password") @provider.modify_password end it "should run pw usermod with the username and the option -H 0" do - @provider.should_receive(:popen4).with("pw usermod adam -H 0", :waitlast => true).and_return(@status) + expect(@provider).to receive(:popen4).with("pw usermod adam -H 0", :waitlast => true).and_return(@status) @provider.modify_password end 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) + allow(@provider).to receive(:popen4).and_yield(@pid, @stdin, @stdout, @stderr).and_return(@status) @provider.modify_password - @stdin.string.should == "abracadabra\n" + expect(@stdin.string).to eq("abracadabra\n") end it "should raise an exception if pw usermod fails" do - @status.should_receive(:exitstatus).and_return(1) - lambda { @provider.modify_password }.should raise_error(Chef::Exceptions::User) + expect(@status).to receive(:exitstatus).and_return(1) + expect { @provider.modify_password }.to raise_error(Chef::Exceptions::User) end it "should not raise an exception if pw usermod succeeds" do - @status.should_receive(:exitstatus).and_return(0) - lambda { @provider.modify_password }.should_not raise_error + expect(@status).to receive(:exitstatus).and_return(0) + expect { @provider.modify_password }.not_to raise_error end end end @@ -240,13 +240,13 @@ describe Chef::Provider::User::Pw do end it "should raise an error if the required binary /usr/sbin/pw doesn't exist" do - File.should_receive(:exists?).with("/usr/sbin/pw").and_return(false) - lambda { @provider.load_current_resource }.should raise_error(Chef::Exceptions::User) + expect(File).to receive(:exists?).with("/usr/sbin/pw").and_return(false) + expect { @provider.load_current_resource }.to raise_error(Chef::Exceptions::User) end it "shouldn't raise an error if /usr/sbin/pw exists" do - File.stub(:exists?).and_return(true) - lambda { @provider.load_current_resource }.should_not raise_error + allow(File).to receive(:exists?).and_return(true) + expect { @provider.load_current_resource }.not_to raise_error end end end diff --git a/spec/unit/provider/user/solaris_spec.rb b/spec/unit/provider/user/solaris_spec.rb index d8bd0f9e75..ef62fd1d5a 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) + allow(p).to receive(:write_shadow_file) p end @@ -51,28 +51,28 @@ describe Chef::Provider::User::Solaris do @new_resource.password "hocus-pocus" - # Let these tests run #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) + expect(provider).to receive(:write_shadow_file) + allow(provider).to receive(:shell_out!).and_return(true) provider.manage_user end it "should write out a modified version of the password file" do + # Let this test run #write_shadow_file + allow(provider).to receive(:write_shadow_file).and_call_original password_file = Tempfile.new("shadow") password_file.puts "adam:existingpassword:15441::::::" password_file.close provider.password_file = password_file.path - provider.stub(:shell_out!).and_return(true) + allow(provider).to receive(: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) + allow(Tempfile).to receive(: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:/ + expect(::File.open(password_file.path, "r").read).to match(/adam:verysecurepassword:/) password_file.unlink end end diff --git a/spec/unit/provider/user/useradd_spec.rb b/spec/unit/provider/user/useradd_spec.rb index a65da3f9e1..b9f6ee0d86 100644 --- a/spec/unit/provider/user/useradd_spec.rb +++ b/spec/unit/provider/user/useradd_spec.rb @@ -43,7 +43,7 @@ describe Chef::Provider::User::Useradd do # CHEF-5247: Chef::Provider::User::Solaris subclasses Chef::Provider::User::Useradd, but does not use usermod to change passwords. # Thus, a call to Solaris#manage_user calls Solaris#manage_password and Useradd#manage_user, but the latter should be a no-op. it "should not run the command if universal_options is an empty array" do - provider.stub(:universal_options).and_return([]) + allow(provider).to receive(:universal_options).and_return([]) expect(provider).not_to receive(:shell_out!) provider.manage_user end diff --git a/spec/unit/provider/user/windows_spec.rb b/spec/unit/provider/user/windows_spec.rb index 45a1c61c41..e51e20a68f 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 = double("Chef::Util::Windows::NetUser") - Chef::Util::Windows::NetUser.stub(:new).and_return(@net_user) + allow(Chef::Util::Windows::NetUser).to receive(:new).and_return(@net_user) @provider = Chef::Provider::User::Windows.new(@new_resource, @run_context) @provider.current_resource = @current_resource @@ -62,27 +62,27 @@ describe Chef::Provider::User::Windows do describe "and the attributes match" do it "doesn't set the comment field to be updated" do - @provider.set_options.should_not have_key(:full_name) + expect(@provider.set_options).not_to have_key(:full_name) end it "doesn't set the home directory to be updated" do - @provider.set_options.should_not have_key(:home_dir) + expect(@provider.set_options).not_to have_key(:home_dir) end it "doesn't set the group id to be updated" do - @provider.set_options.should_not have_key(:primary_group_id) + expect(@provider.set_options).not_to have_key(:primary_group_id) end it "doesn't set the user id to be updated" do - @provider.set_options.should_not have_key(:user_id) + expect(@provider.set_options).not_to have_key(:user_id) end it "doesn't set the shell to be updated" do - @provider.set_options.should_not have_key(:script_path) + expect(@provider.set_options).not_to have_key(:script_path) end it "doesn't set the password to be updated" do - @provider.set_options.should_not have_key(:password) + expect(@provider.set_options).not_to have_key(:password) end end @@ -100,53 +100,53 @@ describe Chef::Provider::User::Windows do end it "marks the full_name field to be updated" do - @provider.set_options[:full_name].should == "Adam Jacob" + expect(@provider.set_options[:full_name]).to eq("Adam Jacob") end it "marks the home_dir attribute to be updated" do - @provider.set_options[:home_dir].should == '/home/adam' + expect(@provider.set_options[:home_dir]).to eq('/home/adam') end it "marks the primary_group_id attribute to be updated" do - @provider.set_options[:primary_group_id].should == 1000 + expect(@provider.set_options[:primary_group_id]).to eq(1000) end it "marks the user_id attribute to be updated" do - @provider.set_options[:user_id].should == 1000 + expect(@provider.set_options[:user_id]).to eq(1000) end it "marks the script_path attribute to be updated" do - @provider.set_options[:script_path].should == '/usr/bin/zsh' + expect(@provider.set_options[:script_path]).to eq('/usr/bin/zsh') end it "marks the password attribute to be updated" do - @provider.set_options[:password].should == 'abracadabra' + expect(@provider.set_options[:password]).to eq('abracadabra') end end end 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") - @net_user.should_receive(:add).with(:name=> "monkey") + allow(@provider).to receive(:set_options).and_return(:name=> "monkey") + expect(@net_user).to receive(:add).with(:name=> "monkey") @provider.create_user end end describe "manage_user" do before(:each) do - @provider.stub(:set_options).and_return(:name=> "monkey") + allow(@provider).to receive(:set_options).and_return(:name=> "monkey") end it "should call @net_user.update with the return of set_options" do - @net_user.should_receive(:update).with(:name=> "monkey") + expect(@net_user).to receive(:update).with(:name=> "monkey") @provider.manage_user end end describe "when removing the user" do it "should call @net_user.delete" do - @net_user.should_receive(:delete) + expect(@net_user).to receive(:delete) @provider.remove_user end end @@ -157,28 +157,28 @@ describe Chef::Provider::User::Windows do end it "should return true if user is locked" do - @net_user.stub(:check_enabled).and_return(true) - @provider.check_lock.should eql(true) + allow(@net_user).to receive(:check_enabled).and_return(true) + expect(@provider.check_lock).to eql(true) end it "should return false if user is not locked" do - @net_user.stub(:check_enabled).and_return(false) - @provider.check_lock.should eql(false) + allow(@net_user).to receive(:check_enabled).and_return(false) + expect(@provider.check_lock).to 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.should_receive(:disable_account) + allow(@net_user).to receive(:check_enabled).and_return(true) + expect(@net_user).to receive(:disable_account) @provider.lock_user end end describe "unlocking the user" do it "should call @net_user.enable_account" do - @net_user.stub(:check_enabled).and_return(false) - @net_user.should_receive(:enable_account) + allow(@net_user).to receive(:check_enabled).and_return(false) + expect(@net_user).to receive(:enable_account) @provider.unlock_user end end diff --git a/spec/unit/provider/user_spec.rb b/spec/unit/provider/user_spec.rb index 153db6f283..44434794e7 100644 --- a/spec/unit/provider/user_spec.rb +++ b/spec/unit/provider/user_spec.rb @@ -47,11 +47,11 @@ describe Chef::Provider::User do describe "when first created" do it "assume the user exists by default" do - @provider.user_exists.should eql(true) + expect(@provider.user_exists).to eql(true) end it "does not know the locked state" do - @provider.locked.should eql(nil) + expect(@provider.locked).to eql(nil) end end @@ -69,7 +69,7 @@ describe Chef::Provider::User do # :password => nil, # :updated => nil #) - Chef::Resource::User.stub(:new).and_return(@current_resource) + allow(Chef::Resource::User).to receive(:new).and_return(@current_resource) @pw_user = EtcPwnamIsh.new @pw_user.name = "adam" @pw_user.gid = 1000 @@ -78,34 +78,34 @@ 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) + allow(Etc).to receive(:getpwnam).and_return(@pw_user) end it "should create a current resource with the same name as the new resource" do @provider.load_current_resource - @provider.current_resource.name.should == 'adam' + expect(@provider.current_resource.name).to eq('adam') end it "should set the username of the current resource to the username of the new resource" do @provider.load_current_resource - @current_resource.username.should == @new_resource.username + expect(@current_resource.username).to eq(@new_resource.username) end it "should change the encoding of gecos to the encoding of the new resource", :ruby_gte_19_only do @pw_user.gecos.force_encoding('ASCII-8BIT') @provider.load_current_resource - @provider.current_resource.comment.encoding.should == @new_resource.comment.encoding + expect(@provider.current_resource.comment.encoding).to eq(@new_resource.comment.encoding) end it "should look up the user in /etc/passwd with getpwnam" do - Etc.should_receive(:getpwnam).with(@new_resource.username).and_return(@pw_user) + expect(Etc).to receive(:getpwnam).with(@new_resource.username).and_return(@pw_user) @provider.load_current_resource end it "should set user_exists to false if the user is not found with getpwnam" do - Etc.should_receive(:getpwnam).and_raise(ArgumentError) + expect(Etc).to receive(:getpwnam).and_raise(ArgumentError) @provider.load_current_resource - @provider.user_exists.should eql(false) + expect(@provider.user_exists).to eql(false) end # The mapping between the Chef::Resource::User and Getpwnam struct @@ -118,24 +118,24 @@ describe Chef::Provider::User do } user_attrib_map.each do |user_attrib, getpwnam_attrib| it "should set the current resources #{user_attrib} based on getpwnam #{getpwnam_attrib}" do - @current_resource.should_receive(user_attrib).with(@pw_user.send(getpwnam_attrib)) + expect(@current_resource).to receive(user_attrib).with(@pw_user.send(getpwnam_attrib)) @provider.load_current_resource end end it "should attempt to convert the group gid if one has been supplied" do - @provider.should_receive(:convert_group_name) + expect(@provider).to receive(:convert_group_name) @provider.load_current_resource end it "shouldn't try and convert the group gid if none has been supplied" do - @new_resource.stub(:gid).and_return(nil) - @provider.should_not_receive(:convert_group_name) + allow(@new_resource).to receive(:gid).and_return(nil) + expect(@provider).not_to receive(:convert_group_name) @provider.load_current_resource end it "should return the current resource" do - @provider.load_current_resource.should eql(@current_resource) + expect(@provider.load_current_resource).to eql(@current_resource) end describe "and running assertions" do @@ -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) + allow(Etc).to receive(:getpwnam).and_return(user) end unless shadow_lib_unavail? @@ -167,10 +167,10 @@ describe Chef::Provider::User do it "should pass assertions when ruby-shadow can be loaded" do @provider.action = 'create' original_method = @provider.method(:require) - @provider.should_receive(:require) { |*args| original_method.call(*args) } + expect(@provider).to receive(:require) { |*args| original_method.call(*args) } passwd_info = Struct::PasswdEntry.new(:sp_namp => "adm ", :sp_pwdp => "$1$T0N0Q.lc$nyG6pFI3Dpqa5cxUz/57j0", :sp_lstchg => 14861, :sp_min => 0, :sp_max => 99999, :sp_warn => 7, :sp_inact => -1, :sp_expire => -1, :sp_flag => -1) - Shadow::Passwd.should_receive(:getspnam).with("adam").and_return(passwd_info) + expect(Shadow::Passwd).to receive(:getspnam).with("adam").and_return(passwd_info) @provider.load_current_resource @provider.define_resource_requirements @provider.process_resource_requirements @@ -180,10 +180,10 @@ describe Chef::Provider::User do end it "should fail assertions when ruby-shadow cannot be loaded" do - @provider.should_receive(:require).with("shadow") { raise LoadError } + expect(@provider).to receive(:require).with("shadow") { raise LoadError } @provider.load_current_resource @provider.define_resource_requirements - lambda {@provider.process_resource_requirements}.should raise_error Chef::Exceptions::MissingLibrary + expect {@provider.process_resource_requirements}.to raise_error Chef::Exceptions::MissingLibrary end end @@ -206,7 +206,7 @@ describe Chef::Provider::User do it "should return true if #{attribute} doesn't match" do @new_resource.send(attribute, mapping[attribute][0]) @current_resource.send(attribute, mapping[attribute][1]) - @provider.compare_user.should eql(true) + expect(@provider.compare_user).to eql(true) end end @@ -214,18 +214,18 @@ describe Chef::Provider::User do it "should return false if string #{attribute} matches fixnum" do @new_resource.send(attribute, "100") @current_resource.send(attribute, 100) - @provider.compare_user.should eql(false) + expect(@provider.compare_user).to eql(false) end end it "should return false if the objects are identical" do - @provider.compare_user.should eql(false) + expect(@provider.compare_user).to eql(false) end end describe "action_create" do before(:each) do - @provider.stub(:load_current_resource) + allow(@provider).to receive(:load_current_resource) # @current_resource = double("Chef::Resource::User", # :null_object => true, # :username => "adam", @@ -246,58 +246,58 @@ describe Chef::Provider::User do it "should call create_user if the user does not exist" do @provider.user_exists = false - @provider.should_receive(:create_user).and_return(true) + expect(@provider).to receive(:create_user).and_return(true) @provider.action_create @provider.set_updated_status - @new_resource.should be_updated + expect(@new_resource).to be_updated end 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.should_receive(:manage_user).and_return(true) + allow(@provider).to receive(:compare_user).and_return(true) + expect(@provider).to 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) + allow(@provider).to receive(:compare_user).and_return(true) + allow(@provider).to receive(:manage_user).and_return(true) @provider.action_create @provider.set_updated_status - @new_resource.should be_updated + expect(@new_resource).to be_updated end end describe "action_remove" do before(:each) do - @provider.stub(:load_current_resource) + allow(@provider).to receive(:load_current_resource) end it "should not call remove_user if the user does not exist" do @provider.user_exists = false - @provider.should_not_receive(:remove_user) + expect(@provider).not_to receive(:remove_user) @provider.action_remove end it "should call remove_user if the user exists" do @provider.user_exists = true - @provider.should_receive(:remove_user) + expect(@provider).to receive(:remove_user) @provider.action_remove end it "should set the new_resources updated flag to true if the user is removed" do @provider.user_exists = true - @provider.should_receive(:remove_user) + expect(@provider).to receive(:remove_user) @provider.action_remove @provider.set_updated_status - @new_resource.should be_updated + expect(@new_resource).to be_updated end end describe "action_manage" do before(:each) do - @provider.stub(:load_current_resource) + allow(@provider).to receive(:load_current_resource) # @node = Chef::Node.new # @new_resource = double("Chef::Resource::User", # :null_object => true @@ -312,35 +312,35 @@ describe Chef::Provider::User do end it "should run manage_user if the user exists and has mismatched attributes" do - @provider.should_receive(:compare_user).and_return(true) - @provider.should_receive(:manage_user).and_return(true) + expect(@provider).to receive(:compare_user).and_return(true) + expect(@provider).to receive(:manage_user).and_return(true) @provider.action_manage 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) + allow(@provider).to receive(:compare_user).and_return(true) + allow(@provider).to receive(:manage_user).and_return(true) @provider.action_manage @provider.set_updated_status - @new_resource.should be_updated + expect(@new_resource).to be_updated end it "should not run manage_user if the user does not exist" do @provider.user_exists = false - @provider.should_not_receive(:manage_user) + expect(@provider).not_to receive(:manage_user) @provider.action_manage end it "should not run manage_user if the user exists but has no differing attributes" do - @provider.should_receive(:compare_user).and_return(false) - @provider.should_not_receive(:manage_user) + expect(@provider).to receive(:compare_user).and_return(false) + expect(@provider).not_to receive(:manage_user) @provider.action_manage end end describe "action_modify" do before(:each) do - @provider.stub(:load_current_resource) + allow(@provider).to receive(:load_current_resource) # @node = Chef::Node.new # @new_resource = double("Chef::Resource::User", # :null_object => true @@ -355,61 +355,61 @@ describe Chef::Provider::User do end it "should run manage_user if the user exists and has mismatched attributes" do - @provider.should_receive(:compare_user).and_return(true) - @provider.should_receive(:manage_user).and_return(true) + expect(@provider).to receive(:compare_user).and_return(true) + expect(@provider).to receive(:manage_user).and_return(true) @provider.action_modify 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) + allow(@provider).to receive(:compare_user).and_return(true) + allow(@provider).to receive(:manage_user).and_return(true) @provider.action_modify @provider.set_updated_status - @new_resource.should be_updated + expect(@new_resource).to be_updated end it "should not run manage_user if the user exists but has no differing attributes" do - @provider.should_receive(:compare_user).and_return(false) - @provider.should_not_receive(:manage_user) + expect(@provider).to receive(:compare_user).and_return(false) + expect(@provider).not_to receive(:manage_user) @provider.action_modify end it "should raise a Chef::Exceptions::User if the user doesn't exist" do @provider.user_exists = false - lambda { @provider.action = :modify; @provider.run_action }.should raise_error(Chef::Exceptions::User) + expect { @provider.action = :modify; @provider.run_action }.to raise_error(Chef::Exceptions::User) end end describe "action_lock" do before(:each) do - @provider.stub(:load_current_resource) + allow(@provider).to receive(:load_current_resource) end it "should lock the user if it exists and is unlocked" do - @provider.stub(:check_lock).and_return(false) - @provider.should_receive(:lock_user).and_return(true) + allow(@provider).to receive(:check_lock).and_return(false) + expect(@provider).to 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.should_receive(:lock_user) + allow(@provider).to receive(:check_lock).and_return(false) + expect(@provider).to receive(:lock_user) @provider.action_lock @provider.set_updated_status - @new_resource.should be_updated + expect(@new_resource).to be_updated end it "should raise a Chef::Exceptions::User if we try and lock a user that does not exist" do @provider.user_exists = false @provider.action = :lock - lambda { @provider.run_action }.should raise_error(Chef::Exceptions::User) + expect { @provider.run_action }.to raise_error(Chef::Exceptions::User) end end describe "action_unlock" do before(:each) do - @provider.stub(:load_current_resource) + allow(@provider).to receive(:load_current_resource) # @node = Chef::Node.new # @new_resource = double("Chef::Resource::User", # :null_object => true @@ -425,17 +425,17 @@ describe Chef::Provider::User do end it "should unlock the user if it exists and is locked" do - @provider.stub(:check_lock).and_return(true) - @provider.should_receive(:unlock_user).and_return(true) + allow(@provider).to receive(:check_lock).and_return(true) + expect(@provider).to receive(:unlock_user).and_return(true) @provider.action_unlock @provider.set_updated_status - @new_resource.should be_updated + expect(@new_resource).to be_updated end it "should raise a Chef::Exceptions::User if we try and unlock a user that does not exist" do @provider.user_exists = false @provider.action = :unlock - lambda { @provider.run_action }.should raise_error(Chef::Exceptions::User) + expect { @provider.run_action }.to raise_error(Chef::Exceptions::User) end end @@ -446,21 +446,21 @@ describe Chef::Provider::User do end it "should lookup the group name locally" do - Etc.should_receive(:getgrnam).with("999").and_return(@group) - @provider.convert_group_name.should == 999 + expect(Etc).to receive(:getgrnam).with("999").and_return(@group) + expect(@provider.convert_group_name).to eq(999) end it "should raise an error if we can't translate the group name during resource assertions" do - Etc.should_receive(:getgrnam).and_raise(ArgumentError) + expect(Etc).to receive(:getgrnam).and_raise(ArgumentError) @provider.define_resource_requirements @provider.convert_group_name - lambda { @provider.process_resource_requirements }.should raise_error(Chef::Exceptions::User) + expect { @provider.process_resource_requirements }.to raise_error(Chef::Exceptions::User) end it "should set the new resources gid to the integerized version if available" do - Etc.should_receive(:getgrnam).with("999").and_return(@group) + expect(Etc).to receive(:getgrnam).with("999").and_return(@group) @provider.convert_group_name - @new_resource.gid.should == 999 + expect(@new_resource.gid).to eq(999) end end end diff --git a/spec/unit/provider/whyrun_safe_ruby_block_spec.rb b/spec/unit/provider/whyrun_safe_ruby_block_spec.rb index d5209248b3..2a4dccdad7 100644 --- a/spec/unit/provider/whyrun_safe_ruby_block_spec.rb +++ b/spec/unit/provider/whyrun_safe_ruby_block_spec.rb @@ -31,15 +31,15 @@ describe Chef::Provider::WhyrunSafeRubyBlock, "initialize" do it "should call the block and flag the resource as updated" do @provider.run_action(:run) - $evil_global_evil_laugh.should == :mwahahaha - @new_resource.should be_updated + expect($evil_global_evil_laugh).to eq(:mwahahaha) + expect(@new_resource).to be_updated end it "should call the block and flat the resource as updated - even in whyrun" do Chef::Config[:why_run] = true @provider.run_action(:run) - $evil_global_evil_laugh.should == :mwahahaha - @new_resource.should be_updated + expect($evil_global_evil_laugh).to eq(:mwahahaha) + expect(@new_resource).to be_updated Chef::Config[:why_run] = false end diff --git a/spec/unit/resource/apt_package_spec.rb b/spec/unit/resource/apt_package_spec.rb index 9503e0cbe1..be8eb9c324 100644 --- a/spec/unit/resource/apt_package_spec.rb +++ b/spec/unit/resource/apt_package_spec.rb @@ -35,6 +35,6 @@ describe Chef::Resource::AptPackage, "initialize" do it "should support default_release" do @resource.default_release("lenny-backports") - @resource.default_release.should eql("lenny-backports") + expect(@resource.default_release).to eql("lenny-backports") end end diff --git a/spec/unit/resource/bash_spec.rb b/spec/unit/resource/bash_spec.rb index d729db6977..f313900433 100644 --- a/spec/unit/resource/bash_spec.rb +++ b/spec/unit/resource/bash_spec.rb @@ -25,16 +25,16 @@ describe Chef::Resource::Bash do end it "should create a new Chef::Resource::Bash" do - @resource.should be_a_kind_of(Chef::Resource) - @resource.should be_a_kind_of(Chef::Resource::Bash) + expect(@resource).to be_a_kind_of(Chef::Resource) + expect(@resource).to be_a_kind_of(Chef::Resource::Bash) end it "should have a resource name of :bash" do - @resource.resource_name.should eql(:bash) + expect(@resource.resource_name).to eql(:bash) end it "should have an interpreter of bash" do - @resource.interpreter.should eql("bash") + expect(@resource.interpreter).to eql("bash") end end diff --git a/spec/unit/resource/batch_spec.rb b/spec/unit/resource/batch_spec.rb index b74c7d24a7..4a056b8735 100644 --- a/spec/unit/resource/batch_spec.rb +++ b/spec/unit/resource/batch_spec.rb @@ -33,7 +33,7 @@ describe Chef::Resource::Batch do end it "should create a new Chef::Resource::Batch" do - @resource.should be_a_kind_of(Chef::Resource::Batch) + expect(@resource).to be_a_kind_of(Chef::Resource::Batch) end context "windows script" do diff --git a/spec/unit/resource/breakpoint_spec.rb b/spec/unit/resource/breakpoint_spec.rb index ed655b84a6..ed1f3ebcd5 100644 --- a/spec/unit/resource/breakpoint_spec.rb +++ b/spec/unit/resource/breakpoint_spec.rb @@ -33,15 +33,15 @@ describe Chef::Resource::Breakpoint do end it "allows the action :break" do - @breakpoint.allowed_actions.should include(:break) + expect(@breakpoint.allowed_actions).to include(:break) end it "defaults to the break action" do - @breakpoint.action.should == "break" + expect(@breakpoint.action).to eq("break") end it "names itself after the line number of the file where it's created" do - @breakpoint.name.should match(/breakpoint_spec\.rb\:[\d]{2}\:in \`new\'$/) + expect(@breakpoint.name).to match(/breakpoint_spec\.rb\:[\d]{2}\:in \`new\'$/) end end diff --git a/spec/unit/resource/chef_gem_spec.rb b/spec/unit/resource/chef_gem_spec.rb index 6a419b3f3b..480856d19f 100644 --- a/spec/unit/resource/chef_gem_spec.rb +++ b/spec/unit/resource/chef_gem_spec.rb @@ -38,7 +38,7 @@ describe Chef::Resource::ChefGem, "gem_binary" do end it "should raise an exception when gem_binary is set" do - lambda { @resource.gem_binary("/lol/cats/gem") }.should raise_error(ArgumentError) + expect { @resource.gem_binary("/lol/cats/gem") }.to raise_error(ArgumentError) end it "should set the gem_binary based on computing it from RbConfig" do diff --git a/spec/unit/resource/conditional_action_not_nothing_spec.rb b/spec/unit/resource/conditional_action_not_nothing_spec.rb index 49bc0ad57d..9f29de55f2 100644 --- a/spec/unit/resource/conditional_action_not_nothing_spec.rb +++ b/spec/unit/resource/conditional_action_not_nothing_spec.rb @@ -27,7 +27,7 @@ describe Chef::Resource::ConditionalActionNotNothing do end it "indicates that resource convergence should not continue" do - @conditional.continue?.should be_false + expect(@conditional.continue?).to be_false end end @@ -38,7 +38,7 @@ describe Chef::Resource::ConditionalActionNotNothing do end it "indicates that resource convergence should continue" do - @conditional.continue?.should be_true + expect(@conditional.continue?).to be_true end end diff --git a/spec/unit/resource/conditional_spec.rb b/spec/unit/resource/conditional_spec.rb index 1fc2518013..cacac925b7 100644 --- a/spec/unit/resource/conditional_spec.rb +++ b/spec/unit/resource/conditional_spec.rb @@ -21,9 +21,9 @@ require 'ostruct' describe Chef::Resource::Conditional do before do - Mixlib::ShellOut.any_instance.stub(:run_command).and_return(nil) + allow_any_instance_of(Mixlib::ShellOut).to receive(:run_command).and_return(nil) @status = OpenStruct.new(:success? => true) - Mixlib::ShellOut.any_instance.stub(:status).and_return(@status) + allow_any_instance_of(Mixlib::ShellOut).to receive(:status).and_return(@status) @parent_resource = Chef::Resource.new(nil, Chef::Node.new) end @@ -53,7 +53,7 @@ describe Chef::Resource::Conditional do end it "indicates that resource convergence should continue" do - @conditional.continue?.should be_true + expect(@conditional.continue?).to be_true end end @@ -64,22 +64,22 @@ describe Chef::Resource::Conditional do end it "indicates that resource convergence should not continue" do - @conditional.continue?.should be_false + expect(@conditional.continue?).to be_false end end describe 'after running a command which timed out' do before do @conditional = Chef::Resource::Conditional.only_if(@parent_resource, "false") - Chef::GuardInterpreter::DefaultGuardInterpreter.any_instance.stub(:shell_out).and_raise(Chef::Exceptions::CommandTimeout) + allow_any_instance_of(Chef::GuardInterpreter::DefaultGuardInterpreter).to receive(:shell_out).and_raise(Chef::Exceptions::CommandTimeout) end it 'indicates that resource convergence should not continue' do - @conditional.continue?.should be_false + expect(@conditional.continue?).to be_false end it 'should log a warning' do - Chef::Log.should_receive(:warn).with("Command 'false' timed out") + expect(Chef::Log).to receive(:warn).with("Command 'false' timed out") @conditional.continue? end end @@ -90,7 +90,7 @@ describe Chef::Resource::Conditional do end it "indicates that resource convergence should continue" do - @conditional.continue?.should be_true + expect(@conditional.continue?).to be_true end end @@ -100,7 +100,7 @@ describe Chef::Resource::Conditional do end it "indicates that resource convergence should not continue" do - @conditional.continue?.should be_false + expect(@conditional.continue?).to be_false end end end @@ -112,7 +112,7 @@ describe Chef::Resource::Conditional do end it "indicates that resource convergence should not continue" do - @conditional.continue?.should be_false + expect(@conditional.continue?).to be_false end end @@ -123,22 +123,22 @@ describe Chef::Resource::Conditional do end it "indicates that resource convergence should continue" do - @conditional.continue?.should be_true + expect(@conditional.continue?).to be_true end end describe 'after running a command which timed out' do before do @conditional = Chef::Resource::Conditional.not_if(@parent_resource, "false") - Chef::GuardInterpreter::DefaultGuardInterpreter.any_instance.stub(:shell_out).and_raise(Chef::Exceptions::CommandTimeout) + allow_any_instance_of(Chef::GuardInterpreter::DefaultGuardInterpreter).to receive(:shell_out).and_raise(Chef::Exceptions::CommandTimeout) end it 'indicates that resource convergence should continue' do - @conditional.continue?.should be_true + expect(@conditional.continue?).to be_true end it 'should log a warning' do - Chef::Log.should_receive(:warn).with("Command 'false' timed out") + expect(Chef::Log).to receive(:warn).with("Command 'false' timed out") @conditional.continue? end end @@ -149,7 +149,7 @@ describe Chef::Resource::Conditional do end it "indicates that resource convergence should not continue" do - @conditional.continue?.should be_false + expect(@conditional.continue?).to be_false end end @@ -159,7 +159,7 @@ describe Chef::Resource::Conditional do end it "indicates that resource convergence should continue" do - @conditional.continue?.should be_true + expect(@conditional.continue?).to be_true end end end diff --git a/spec/unit/resource/cookbook_file_spec.rb b/spec/unit/resource/cookbook_file_spec.rb index 6c55c8035a..834e08bba4 100644 --- a/spec/unit/resource/cookbook_file_spec.rb +++ b/spec/unit/resource/cookbook_file_spec.rb @@ -25,25 +25,25 @@ describe Chef::Resource::CookbookFile do end it "uses the name parameter for the source parameter" do - @cookbook_file.name.should == 'sourcecode_tarball.tgz' + expect(@cookbook_file.name).to eq('sourcecode_tarball.tgz') end it "has a source parameter" do @cookbook_file.name('config_file.conf') - @cookbook_file.name.should == 'config_file.conf' + expect(@cookbook_file.name).to eq('config_file.conf') end it "defaults to a nil cookbook parameter (current cookbook will be used)" do - @cookbook_file.cookbook.should be_nil + expect(@cookbook_file.cookbook).to be_nil end it "has a cookbook parameter" do @cookbook_file.cookbook("munin") - @cookbook_file.cookbook.should == 'munin' + expect(@cookbook_file.cookbook).to eq('munin') end it "sets the provider to Chef::Provider::CookbookFile" do - @cookbook_file.provider.should == Chef::Provider::CookbookFile + expect(@cookbook_file.provider).to eq(Chef::Provider::CookbookFile) end describe "when it has a backup number, group, mode, owner, source, checksum, and cookbook on nix or path, rights, deny_rights, checksum on windows" do @@ -68,21 +68,21 @@ describe Chef::Resource::CookbookFile do state = @cookbook_file.state if Chef::Platform.windows? puts state - state[:rights].should == [{:permissions => :read, :principals => "Everyone"}] - state[:deny_rights].should == [{:permissions => :full_control, :principals => "Clumsy_Sam"}] + expect(state[:rights]).to eq([{:permissions => :read, :principals => "Everyone"}]) + expect(state[:deny_rights]).to eq([{:permissions => :full_control, :principals => "Clumsy_Sam"}]) else - state[:group].should == "wheel" - state[:mode].should == "0664" - state[:owner].should == "root" + expect(state[:group]).to eq("wheel") + expect(state[:mode]).to eq("0664") + expect(state[:owner]).to eq("root") end - state[:checksum].should == "1" * 64 + expect(state[:checksum]).to eq("1" * 64) end it "returns the path as its identity" do if Chef::Platform.windows? - @cookbook_file.identity.should == "C:/temp/origin/file.txt" + expect(@cookbook_file.identity).to eq("C:/temp/origin/file.txt") else - @cookbook_file.identity.should == "/tmp/origin/file.txt" + expect(@cookbook_file.identity).to eq("/tmp/origin/file.txt") end end end diff --git a/spec/unit/resource/cron_spec.rb b/spec/unit/resource/cron_spec.rb index cf821e3d32..743552c1de 100644 --- a/spec/unit/resource/cron_spec.rb +++ b/spec/unit/resource/cron_spec.rb @@ -26,135 +26,135 @@ describe Chef::Resource::Cron do end it "should create a new Chef::Resource::Cron" do - @resource.should be_a_kind_of(Chef::Resource) - @resource.should be_a_kind_of(Chef::Resource::Cron) + expect(@resource).to be_a_kind_of(Chef::Resource) + expect(@resource).to be_a_kind_of(Chef::Resource::Cron) end it "should have a name" do - @resource.name.should eql("cronify") + expect(@resource.name).to eql("cronify") end it "should have a default action of 'create'" do - @resource.action.should eql(:create) + expect(@resource.action).to eql(:create) end it "should accept create or delete for action" do - lambda { @resource.action :create }.should_not raise_error - lambda { @resource.action :delete }.should_not raise_error - lambda { @resource.action :lolcat }.should raise_error(ArgumentError) + expect { @resource.action :create }.not_to raise_error + expect { @resource.action :delete }.not_to raise_error + expect { @resource.action :lolcat }.to raise_error(ArgumentError) end it "should allow you to set a command" do @resource.command "/bin/true" - @resource.command.should eql("/bin/true") + expect(@resource.command).to eql("/bin/true") end it "should allow you to set a user" do @resource.user "daemon" - @resource.user.should eql("daemon") + expect(@resource.user).to eql("daemon") end it "should allow you to specify the minute" do @resource.minute "30" - @resource.minute.should eql("30") + expect(@resource.minute).to eql("30") end it "should allow you to specify the hour" do @resource.hour "6" - @resource.hour.should eql("6") + expect(@resource.hour).to eql("6") end it "should allow you to specify the day" do @resource.day "10" - @resource.day.should eql("10") + expect(@resource.day).to eql("10") end it "should allow you to specify the month" do @resource.month "10" - @resource.month.should eql("10") + expect(@resource.month).to eql("10") end it "should allow you to specify the weekday" do @resource.weekday "2" - @resource.weekday.should eql("2") + expect(@resource.weekday).to eql("2") end it "should allow you to specify the mailto variable" do @resource.mailto "test@example.com" - @resource.mailto.should eql("test@example.com") + expect(@resource.mailto).to eql("test@example.com") end it "should allow you to specify the path" do @resource.path "/usr/bin:/usr/sbin" - @resource.path.should eql("/usr/bin:/usr/sbin") + expect(@resource.path).to eql("/usr/bin:/usr/sbin") end it "should allow you to specify the home directory" do @resource.home "/root" - @resource.home.should eql("/root") + expect(@resource.home).to eql("/root") end it "should allow you to specify the shell to run the command with" do @resource.shell "/bin/zsh" - @resource.shell.should eql("/bin/zsh") + expect(@resource.shell).to eql("/bin/zsh") end it "should allow you to specify environment variables hash" do env = {"TEST" => "LOL"} @resource.environment env - @resource.environment.should eql(env) + expect(@resource.environment).to eql(env) end it "should allow * for all time and date values" do [ "minute", "hour", "day", "month", "weekday" ].each do |x| - @resource.send(x, "*").should eql("*") + expect(@resource.send(x, "*")).to eql("*") end end it "should allow ranges for all time and date values" do [ "minute", "hour", "day", "month", "weekday" ].each do |x| - @resource.send(x, "1-2,5").should eql("1-2,5") + expect(@resource.send(x, "1-2,5")).to eql("1-2,5") end end it "should have a default value of * for all time and date values" do [ "minute", "hour", "day", "month", "weekday" ].each do |x| - @resource.send(x).should eql("*") + expect(@resource.send(x)).to eql("*") end end it "should have a default value of root for the user" do - @resource.user.should eql("root") + expect(@resource.user).to eql("root") end it "should reject any minute over 59" do - lambda { @resource.minute "60" }.should raise_error(RangeError) + expect { @resource.minute "60" }.to raise_error(RangeError) end it "should reject any hour over 23" do - lambda { @resource.hour "24" }.should raise_error(RangeError) + expect { @resource.hour "24" }.to raise_error(RangeError) end it "should reject any day over 31" do - lambda { @resource.day "32" }.should raise_error(RangeError) + expect { @resource.day "32" }.to raise_error(RangeError) end it "should reject any month over 12" do - lambda { @resource.month "13" }.should raise_error(RangeError) + expect { @resource.month "13" }.to raise_error(RangeError) end describe "weekday" do it "should reject any weekday over 7" do - lambda { @resource.weekday "8" }.should raise_error(RangeError) + expect { @resource.weekday "8" }.to raise_error(RangeError) end it "should reject any symbols which don't represent day of week" do - lambda { @resource.weekday :foo }.should raise_error(RangeError) + expect { @resource.weekday :foo }.to raise_error(RangeError) end end it "should convert integer schedule values to a string" do [ "minute", "hour", "day", "month", "weekday" ].each do |x| - @resource.send(x, 5).should eql("5") + expect(@resource.send(x, 5)).to eql("5") end end @@ -171,16 +171,16 @@ describe Chef::Resource::Cron do it "describes the state" do state = @resource.state - state[:minute].should == "1" - state[:hour].should == "2" - state[:day].should == "3" - state[:month].should == "4" - state[:weekday].should == "5" - state[:user].should == "root" + expect(state[:minute]).to eq("1") + expect(state[:hour]).to eq("2") + expect(state[:day]).to eq("3") + expect(state[:month]).to eq("4") + expect(state[:weekday]).to eq("5") + expect(state[:user]).to eq("root") end it "returns the command as its identity" do - @resource.identity.should == "tackle" + expect(@resource.identity).to eq("tackle") end end end diff --git a/spec/unit/resource/csh_spec.rb b/spec/unit/resource/csh_spec.rb index e1534a8f5f..5fb3b00507 100644 --- a/spec/unit/resource/csh_spec.rb +++ b/spec/unit/resource/csh_spec.rb @@ -25,16 +25,16 @@ describe Chef::Resource::Csh do end it "should create a new Chef::Resource::Csh" do - @resource.should be_a_kind_of(Chef::Resource) - @resource.should be_a_kind_of(Chef::Resource::Csh) + expect(@resource).to be_a_kind_of(Chef::Resource) + expect(@resource).to be_a_kind_of(Chef::Resource::Csh) end it "should have a resource name of :csh" do - @resource.resource_name.should eql(:csh) + expect(@resource.resource_name).to eql(:csh) end it "should have an interpreter of csh" do - @resource.interpreter.should eql("csh") + expect(@resource.interpreter).to eql("csh") end end diff --git a/spec/unit/resource/deploy_spec.rb b/spec/unit/resource/deploy_spec.rb index 914ea19030..6592fae26c 100644 --- a/spec/unit/resource/deploy_spec.rb +++ b/spec/unit/resource/deploy_spec.rb @@ -33,28 +33,28 @@ describe Chef::Resource::Deploy do def resource_has_a_string_attribute(attr_name) it "has a String attribute for #{attr_name.to_s}" do @resource.send(attr_name, "this is a string") - @resource.send(attr_name).should eql("this is a string") - lambda {@resource.send(attr_name, 8675309)}.should raise_error(ArgumentError) + expect(@resource.send(attr_name)).to eql("this is a string") + expect {@resource.send(attr_name, 8675309)}.to raise_error(ArgumentError) end end def resource_has_a_boolean_attribute(attr_name, opts={:defaults_to=>false}) it "has a Boolean attribute for #{attr_name.to_s}" do - @resource.send(attr_name).should eql(opts[:defaults_to]) + expect(@resource.send(attr_name)).to eql(opts[:defaults_to]) @resource.send(attr_name, !opts[:defaults_to]) - @resource.send(attr_name).should eql( !opts[:defaults_to] ) + expect(@resource.send(attr_name)).to eql( !opts[:defaults_to] ) end end def resource_has_a_callback_attribute(attr_name) it "has a Callback attribute #{attr_name}" do callback_block = lambda { :noop } - lambda {@resource.send(attr_name, &callback_block)}.should_not raise_error - @resource.send(attr_name).should == callback_block + expect {@resource.send(attr_name, &callback_block)}.not_to raise_error + expect(@resource.send(attr_name)).to eq(callback_block) callback_file = "path/to/callback.rb" - lambda {@resource.send(attr_name, callback_file)}.should_not raise_error - @resource.send(attr_name).should == callback_file - lambda {@resource.send(attr_name, :this_is_fail)}.should raise_error(ArgumentError) + expect {@resource.send(attr_name, callback_file)}.not_to raise_error + expect(@resource.send(attr_name)).to eq(callback_file) + expect {@resource.send(attr_name, :this_is_fail)}.to raise_error(ArgumentError) end end end @@ -85,7 +85,7 @@ describe Chef::Resource::Deploy do resource_has_a_boolean_attribute(:shallow_clone, :defaults_to=>false) it "uses the first argument as the deploy directory" do - @resource.deploy_to.should eql("/my/deploy/dir") + expect(@resource.deploy_to).to eql("/my/deploy/dir") end # For git, any revision, branch, tag, whatever is resolved to a SHA1 ref. @@ -93,100 +93,100 @@ describe Chef::Resource::Deploy do # Therefore, revision and branch ARE NOT SEPARATE THINGS it "aliases #revision as #branch" do @resource.branch "stable" - @resource.revision.should eql("stable") + expect(@resource.revision).to eql("stable") end it "takes the SCM resource to use as a constant, and defaults to git" do - @resource.scm_provider.should eql(Chef::Provider::Git) + expect(@resource.scm_provider).to eql(Chef::Provider::Git) @resource.scm_provider Chef::Provider::Subversion - @resource.scm_provider.should eql(Chef::Provider::Subversion) + expect(@resource.scm_provider).to eql(Chef::Provider::Subversion) end it "allows scm providers to be set via symbol" do - @resource.scm_provider.should == Chef::Provider::Git + expect(@resource.scm_provider).to eq(Chef::Provider::Git) @resource.scm_provider :subversion - @resource.scm_provider.should == Chef::Provider::Subversion + expect(@resource.scm_provider).to eq(Chef::Provider::Subversion) end it "allows scm providers to be set via string" do - @resource.scm_provider.should == Chef::Provider::Git + expect(@resource.scm_provider).to eq(Chef::Provider::Git) @resource.scm_provider "subversion" - @resource.scm_provider.should == Chef::Provider::Subversion + expect(@resource.scm_provider).to eq(Chef::Provider::Subversion) end it "has a boolean attribute for svn_force_export defaulting to false" do - @resource.svn_force_export.should be_false + expect(@resource.svn_force_export).to be_false @resource.svn_force_export true - @resource.svn_force_export.should be_true - lambda {@resource.svn_force_export(10053)}.should raise_error(ArgumentError) + expect(@resource.svn_force_export).to be_true + expect {@resource.svn_force_export(10053)}.to raise_error(ArgumentError) end it "takes arbitrary environment variables in a hash" do @resource.environment "RAILS_ENV" => "production" - @resource.environment.should == {"RAILS_ENV" => "production"} + expect(@resource.environment).to eq({"RAILS_ENV" => "production"}) end it "takes string arguments to environment for backwards compat, setting RAILS_ENV, RACK_ENV, and MERB_ENV" do @resource.environment "production" - @resource.environment.should == {"RAILS_ENV"=>"production", "RACK_ENV"=>"production","MERB_ENV"=>"production"} + expect(@resource.environment).to eq({"RAILS_ENV"=>"production", "RACK_ENV"=>"production","MERB_ENV"=>"production"}) end it "sets destination to $deploy_to/shared/$repository_cache" do - @resource.destination.should eql("/my/deploy/dir/shared/cached-copy") + expect(@resource.destination).to eql("/my/deploy/dir/shared/cached-copy") end it "sets shared_path to $deploy_to/shared" do - @resource.shared_path.should eql("/my/deploy/dir/shared") + expect(@resource.shared_path).to eql("/my/deploy/dir/shared") end it "sets current_path to $deploy_to/current" do - @resource.current_path.should eql("/my/deploy/dir/current") + expect(@resource.current_path).to eql("/my/deploy/dir/current") end it "gets the current_path correct even if the shared_path is set (regression test)" do @resource.shared_path - @resource.current_path.should eql("/my/deploy/dir/current") + expect(@resource.current_path).to eql("/my/deploy/dir/current") end it "gives #depth as 5 if shallow clone is true, nil otherwise" do - @resource.depth.should be_nil + expect(@resource.depth).to be_nil @resource.shallow_clone true - @resource.depth.should eql("5") + expect(@resource.depth).to eql("5") end it "aliases repo as repository" do @resource.repository "git@github.com/opcode/cookbooks.git" - @resource.repo.should eql("git@github.com/opcode/cookbooks.git") + expect(@resource.repo).to eql("git@github.com/opcode/cookbooks.git") end it "aliases git_ssh_wrapper as ssh_wrapper" do @resource.ssh_wrapper "git_my_repo.sh" - @resource.git_ssh_wrapper.should eql("git_my_repo.sh") + expect(@resource.git_ssh_wrapper).to eql("git_my_repo.sh") end it "has an Array attribute purge_before_symlink, default: log, tmp/pids, public/system" do - @resource.purge_before_symlink.should == %w{ log tmp/pids public/system } + expect(@resource.purge_before_symlink).to eq(%w{ log tmp/pids public/system }) @resource.purge_before_symlink %w{foo bar baz} - @resource.purge_before_symlink.should == %w{foo bar baz} + expect(@resource.purge_before_symlink).to eq(%w{foo bar baz}) end it "has an Array attribute create_dirs_before_symlink, default: tmp, public, config" do - @resource.create_dirs_before_symlink.should == %w{tmp public config} + expect(@resource.create_dirs_before_symlink).to eq(%w{tmp public config}) @resource.create_dirs_before_symlink %w{foo bar baz} - @resource.create_dirs_before_symlink.should == %w{foo bar baz} + expect(@resource.create_dirs_before_symlink).to eq(%w{foo bar baz}) end it 'has a Hash attribute symlinks, default: {"system" => "public/system", "pids" => "tmp/pids", "log" => "log"}' do default = { "system" => "public/system", "pids" => "tmp/pids", "log" => "log"} - @resource.symlinks.should == default + expect(@resource.symlinks).to eq(default) @resource.symlinks "foo" => "bar/baz" - @resource.symlinks.should == {"foo" => "bar/baz"} + expect(@resource.symlinks).to eq({"foo" => "bar/baz"}) end it 'has a Hash attribute symlink_before_migrate, default "config/database.yml" => "config/database.yml"' do - @resource.symlink_before_migrate.should == {"config/database.yml" => "config/database.yml"} + expect(@resource.symlink_before_migrate).to eq({"config/database.yml" => "config/database.yml"}) @resource.symlink_before_migrate "wtf?" => "wtf is going on" - @resource.symlink_before_migrate.should == {"wtf?" => "wtf is going on"} + expect(@resource.symlink_before_migrate).to eq({"wtf?" => "wtf is going on"}) end resource_has_a_callback_attribute :before_migrate @@ -196,55 +196,55 @@ describe Chef::Resource::Deploy do it "aliases restart_command as restart" do @resource.restart "foobaz" - @resource.restart_command.should == "foobaz" + expect(@resource.restart_command).to eq("foobaz") end it "takes a block for the restart parameter" do restart_like_this = lambda {p :noop} @resource.restart(&restart_like_this) - @resource.restart.should == restart_like_this + expect(@resource.restart).to eq(restart_like_this) end it "allows providers to be set with a full class name" do @resource.provider Chef::Provider::Deploy::Timestamped - @resource.provider.should == Chef::Provider::Deploy::Timestamped + expect(@resource.provider).to eq(Chef::Provider::Deploy::Timestamped) end it "allows deploy providers to be set via symbol" do @resource.provider :revision - @resource.provider.should == Chef::Provider::Deploy::Revision + expect(@resource.provider).to eq(Chef::Provider::Deploy::Revision) end it "allows deploy providers to be set via string" do @resource.provider "revision" - @resource.provider.should == Chef::Provider::Deploy::Revision + expect(@resource.provider).to eq(Chef::Provider::Deploy::Revision) end it "defaults keep_releases to 5" do - @resource.keep_releases.should == 5 + expect(@resource.keep_releases).to eq(5) end it "allows keep_releases to be set via integer" do @resource.keep_releases 10 - @resource.keep_releases.should == 10 + expect(@resource.keep_releases).to eq(10) end it "enforces a minimum keep_releases of 1" do @resource.keep_releases 0 - @resource.keep_releases.should == 1 + expect(@resource.keep_releases).to eq(1) end describe "when it has a timeout attribute" do let(:ten_seconds) { 10 } before { @resource.timeout(ten_seconds) } it "stores this timeout" do - @resource.timeout.should == ten_seconds + expect(@resource.timeout).to eq(ten_seconds) end end describe "when it has no timeout attribute" do it "should have no default timeout" do - @resource.timeout.should be_nil + expect(@resource.timeout).to be_nil end end @@ -266,12 +266,12 @@ describe Chef::Resource::Deploy do it "describes its state" do state = @resource.state - state[:deploy_to].should == "/" - state[:revision].should == "1.2.3" + expect(state[:deploy_to]).to eq("/") + expect(state[:revision]).to eq("1.2.3") end it "returns the repository URI as its identity" do - @resource.identity.should == "http://uri.org" + expect(@resource.identity).to eq("http://uri.org") end end diff --git a/spec/unit/resource/directory_spec.rb b/spec/unit/resource/directory_spec.rb index a42383c49e..c452b2a914 100644 --- a/spec/unit/resource/directory_spec.rb +++ b/spec/unit/resource/directory_spec.rb @@ -26,38 +26,38 @@ describe Chef::Resource::Directory do end it "should create a new Chef::Resource::Directory" do - @resource.should be_a_kind_of(Chef::Resource) - @resource.should be_a_kind_of(Chef::Resource::Directory) + expect(@resource).to be_a_kind_of(Chef::Resource) + expect(@resource).to be_a_kind_of(Chef::Resource::Directory) end it "should have a name" do - @resource.name.should eql("fakey_fakerton") + expect(@resource.name).to eql("fakey_fakerton") end it "should have a default action of 'create'" do - @resource.action.should eql(:create) + expect(@resource.action).to eql(:create) end it "should accept create or delete for action" do - lambda { @resource.action :create }.should_not raise_error - lambda { @resource.action :delete }.should_not raise_error - lambda { @resource.action :blues }.should raise_error(ArgumentError) + expect { @resource.action :create }.not_to raise_error + expect { @resource.action :delete }.not_to raise_error + expect { @resource.action :blues }.to raise_error(ArgumentError) end it "should use the object name as the path by default" do - @resource.path.should eql("fakey_fakerton") + expect(@resource.path).to eql("fakey_fakerton") end it "should accept a string as the path" do - lambda { @resource.path "/tmp" }.should_not raise_error - @resource.path.should eql("/tmp") - lambda { @resource.path Hash.new }.should raise_error(ArgumentError) + expect { @resource.path "/tmp" }.not_to raise_error + expect(@resource.path).to eql("/tmp") + expect { @resource.path Hash.new }.to raise_error(ArgumentError) end it "should allow you to have specify whether the action is recursive with true/false" do - lambda { @resource.recursive true }.should_not raise_error - lambda { @resource.recursive false }.should_not raise_error - lambda { @resource.recursive "monkey" }.should raise_error(ArgumentError) + expect { @resource.recursive true }.not_to raise_error + expect { @resource.recursive false }.not_to raise_error + expect { @resource.recursive "monkey" }.to raise_error(ArgumentError) end describe "when it has group, mode, and owner" do @@ -70,13 +70,13 @@ describe Chef::Resource::Directory do it "describes its state" do state = @resource.state - state[:group].should == "wheel" - state[:mode].should == "0664" - state[:owner].should == "root" + expect(state[:group]).to eq("wheel") + expect(state[:mode]).to eq("0664") + expect(state[:owner]).to eq("root") end it "returns the directory path as its identity" do - @resource.identity.should == "/tmp/foo/bar/" + expect(@resource.identity).to eq("/tmp/foo/bar/") end end end diff --git a/spec/unit/resource/easy_install_package_spec.rb b/spec/unit/resource/easy_install_package_spec.rb index d3a5f4a0fe..c68b026b39 100644 --- a/spec/unit/resource/easy_install_package_spec.rb +++ b/spec/unit/resource/easy_install_package_spec.rb @@ -34,6 +34,6 @@ describe Chef::Resource::EasyInstallPackage, "initialize" do it "should allow you to set the easy_install_binary attribute" do @resource.easy_install_binary "/opt/local/bin/easy_install" - @resource.easy_install_binary.should eql("/opt/local/bin/easy_install") + expect(@resource.easy_install_binary).to eql("/opt/local/bin/easy_install") end end diff --git a/spec/unit/resource/env_spec.rb b/spec/unit/resource/env_spec.rb index a1f599400b..566827a27e 100644 --- a/spec/unit/resource/env_spec.rb +++ b/spec/unit/resource/env_spec.rb @@ -26,43 +26,43 @@ describe Chef::Resource::Env do end it "should create a new Chef::Resource::Env" do - @resource.should be_a_kind_of(Chef::Resource) - @resource.should be_a_kind_of(Chef::Resource::Env) + expect(@resource).to be_a_kind_of(Chef::Resource) + expect(@resource).to be_a_kind_of(Chef::Resource::Env) end it "should have a name" do - @resource.name.should eql("FOO") + expect(@resource.name).to eql("FOO") end it "should have a default action of 'create'" do - @resource.action.should eql(:create) + expect(@resource.action).to eql(:create) end { :create => false, :delete => false, :modify => false, :flibber => true }.each do |action,bad_value| it "should #{bad_value ? 'not' : ''} accept #{action.to_s}" do if bad_value - lambda { @resource.action action }.should raise_error(ArgumentError) + expect { @resource.action action }.to raise_error(ArgumentError) else - lambda { @resource.action action }.should_not raise_error + expect { @resource.action action }.not_to raise_error end end end it "should use the object name as the key_name by default" do - @resource.key_name.should eql("FOO") + expect(@resource.key_name).to eql("FOO") end it "should accept a string as the env value via 'value'" do - lambda { @resource.value "bar" }.should_not raise_error + expect { @resource.value "bar" }.not_to raise_error end it "should not accept a Hash for the env value via 'to'" do - lambda { @resource.value Hash.new }.should raise_error(ArgumentError) + expect { @resource.value Hash.new }.to raise_error(ArgumentError) end it "should allow you to set an env value via 'to'" do @resource.value "bar" - @resource.value.should eql("bar") + expect(@resource.value).to eql("bar") end describe "when it has key name and value" do @@ -74,11 +74,11 @@ describe Chef::Resource::Env do it "describes its state" do state = @resource.state - state[:value].should == "level7" + expect(state[:value]).to eq("level7") end it "returns the key name as its identity" do - @resource.identity.should == "charmander" + expect(@resource.identity).to eq("charmander") end end diff --git a/spec/unit/resource/erl_call_spec.rb b/spec/unit/resource/erl_call_spec.rb index 3efbdca9a0..8ec182665f 100644 --- a/spec/unit/resource/erl_call_spec.rb +++ b/spec/unit/resource/erl_call_spec.rb @@ -26,45 +26,45 @@ describe Chef::Resource::ErlCall do end it "should create a new Chef::Resource::ErlCall" do - @resource.should be_a_kind_of(Chef::Resource) - @resource.should be_a_kind_of(Chef::Resource::ErlCall) + expect(@resource).to be_a_kind_of(Chef::Resource) + expect(@resource).to be_a_kind_of(Chef::Resource::ErlCall) end it "should have a resource name of :erl_call" do - @resource.resource_name.should eql(:erl_call) + expect(@resource.resource_name).to eql(:erl_call) end it "should have a default action of run" do - @resource.action.should eql("run") + expect(@resource.action).to eql("run") end it "should accept run as an action" do - lambda { @resource.action :run }.should_not raise_error + expect { @resource.action :run }.not_to raise_error end it "should allow you to set the code attribute" do @resource.code "q()." - @resource.code.should eql("q().") + expect(@resource.code).to eql("q().") end it "should allow you to set the cookie attribute" do @resource.cookie "nomnomnom" - @resource.cookie.should eql("nomnomnom") + expect(@resource.cookie).to eql("nomnomnom") end it "should allow you to set the distributed attribute" do @resource.distributed true - @resource.distributed.should eql(true) + expect(@resource.distributed).to eql(true) end it "should allow you to set the name_type attribute" do @resource.name_type "sname" - @resource.name_type.should eql("sname") + expect(@resource.name_type).to eql("sname") end it "should allow you to set the node_name attribute" do @resource.node_name "chef@erlang" - @resource.node_name.should eql("chef@erlang") + expect(@resource.node_name).to eql("chef@erlang") end describe "when it has cookie and node_name" do @@ -75,7 +75,7 @@ describe Chef::Resource::ErlCall do end it "returns the code as its identity" do - @resource.identity.should == "erl-call:function()" + expect(@resource.identity).to eq("erl-call:function()") end end end diff --git a/spec/unit/resource/execute_spec.rb b/spec/unit/resource/execute_spec.rb index e1728b7892..70b9d87d4c 100644 --- a/spec/unit/resource/execute_spec.rb +++ b/spec/unit/resource/execute_spec.rb @@ -25,7 +25,7 @@ describe Chef::Resource::Execute do it_behaves_like "an execute resource" it "default guard interpreter should be :execute interpreter" do - execute_resource.guard_interpreter.should be(:execute) + expect(execute_resource.guard_interpreter).to be(:execute) end end diff --git a/spec/unit/resource/file_spec.rb b/spec/unit/resource/file_spec.rb index 9c6365f6d3..cfa7511673 100644 --- a/spec/unit/resource/file_spec.rb +++ b/spec/unit/resource/file_spec.rb @@ -25,55 +25,55 @@ describe Chef::Resource::File do end it "should have a name" do - @resource.name.should eql("fakey_fakerton") + expect(@resource.name).to eql("fakey_fakerton") end it "should have a default action of 'create'" do - @resource.action.should eql("create") + expect(@resource.action).to eql("create") end it "should have a default content of nil" do - @resource.content.should be_nil + expect(@resource.content).to be_nil end it "should be set to back up 5 files by default" do - @resource.backup.should eql(5) + expect(@resource.backup).to eql(5) end it "should only accept strings for content" do - lambda { @resource.content 5 }.should raise_error(ArgumentError) - lambda { @resource.content :foo }.should raise_error(ArgumentError) - lambda { @resource.content "hello" => "there" }.should raise_error(ArgumentError) - lambda { @resource.content "hi" }.should_not raise_error + expect { @resource.content 5 }.to raise_error(ArgumentError) + expect { @resource.content :foo }.to raise_error(ArgumentError) + expect { @resource.content "hello" => "there" }.to raise_error(ArgumentError) + expect { @resource.content "hi" }.not_to raise_error end it "should only accept false or a number for backup" do - lambda { @resource.backup true }.should raise_error(ArgumentError) - lambda { @resource.backup false }.should_not raise_error - lambda { @resource.backup 10 }.should_not raise_error - lambda { @resource.backup "blues" }.should raise_error(ArgumentError) + expect { @resource.backup true }.to raise_error(ArgumentError) + expect { @resource.backup false }.not_to raise_error + expect { @resource.backup 10 }.not_to raise_error + expect { @resource.backup "blues" }.to raise_error(ArgumentError) end it "should accept a sha256 for checksum" do - lambda { @resource.checksum "0fd012fdc96e96f8f7cf2046522a54aed0ce470224513e45da6bc1a17a4924aa" }.should_not raise_error - lambda { @resource.checksum "monkey!" }.should raise_error(ArgumentError) + expect { @resource.checksum "0fd012fdc96e96f8f7cf2046522a54aed0ce470224513e45da6bc1a17a4924aa" }.not_to raise_error + expect { @resource.checksum "monkey!" }.to raise_error(ArgumentError) end it "should accept create, delete or touch for action" do - lambda { @resource.action :create }.should_not raise_error - lambda { @resource.action :delete }.should_not raise_error - lambda { @resource.action :touch }.should_not raise_error - lambda { @resource.action :blues }.should raise_error(ArgumentError) + expect { @resource.action :create }.not_to raise_error + expect { @resource.action :delete }.not_to raise_error + expect { @resource.action :touch }.not_to raise_error + expect { @resource.action :blues }.to raise_error(ArgumentError) end it "should use the object name as the path by default" do - @resource.path.should eql("fakey_fakerton") + expect(@resource.path).to eql("fakey_fakerton") end it "should accept a string as the path" do - lambda { @resource.path "/tmp" }.should_not raise_error - @resource.path.should eql("/tmp") - lambda { @resource.path Hash.new }.should raise_error(ArgumentError) + expect { @resource.path "/tmp" }.not_to raise_error + expect(@resource.path).to eql("/tmp") + expect { @resource.path Hash.new }.to raise_error(ArgumentError) end describe "when it has a path, owner, group, mode, and checksum" do @@ -88,15 +88,15 @@ describe Chef::Resource::File do context "on unix", :unix_only do it "describes its state" do state = @resource.state - state[:owner].should == "root" - state[:group].should == "wheel" - state[:mode].should == "0644" - state[:checksum].should == "1" * 64 + expect(state[:owner]).to eq("root") + expect(state[:group]).to eq("wheel") + expect(state[:mode]).to eq("0644") + expect(state[:checksum]).to eq("1" * 64) end end it "returns the file path as its identity" do - @resource.identity.should == "/tmp/foo.txt" + expect(@resource.identity).to eq("/tmp/foo.txt") end end @@ -108,8 +108,8 @@ describe Chef::Resource::File do end it "describes its state including windows ACL attributes" do state = @resource.state - state[:rights].should == [ {:permissions => :read, :principals => "Everyone"}, - {:permissions => :full_control, :principals => "DOMAIN\User"} ] + expect(state[:rights]).to eq([ {:permissions => :read, :principals => "Everyone"}, + {:permissions => :full_control, :principals => "DOMAIN\User"} ]) end end diff --git a/spec/unit/resource/freebsd_package_spec.rb b/spec/unit/resource/freebsd_package_spec.rb index 04a6962270..7263d3a7ba 100644 --- a/spec/unit/resource/freebsd_package_spec.rb +++ b/spec/unit/resource/freebsd_package_spec.rb @@ -32,15 +32,15 @@ describe Chef::Resource::FreebsdPackage do describe "Initialization" do it "should return a Chef::Resource::FreebsdPackage" do - @resource.should be_a_kind_of(Chef::Resource::FreebsdPackage) + expect(@resource).to be_a_kind_of(Chef::Resource::FreebsdPackage) end it "should set the resource_name to :freebsd_package" do - @resource.resource_name.should eql(:freebsd_package) + expect(@resource.resource_name).to eql(:freebsd_package) end it "should not set the provider" do - @resource.provider.should be_nil + expect(@resource.provider).to be_nil end end @@ -50,7 +50,7 @@ describe Chef::Resource::FreebsdPackage do it "should be Freebsd::Port" do @resource.source('ports') @resource.after_created - @resource.provider.should == Chef::Provider::Package::Freebsd::Port + expect(@resource.provider).to eq(Chef::Provider::Package::Freebsd::Port) end end @@ -59,7 +59,7 @@ describe Chef::Resource::FreebsdPackage do [1000017, 1000018, 1000500, 1001001, 1100000].each do |__freebsd_version| @node.automatic_attrs[:os_version] = __freebsd_version @resource.after_created - @resource.provider.should == Chef::Provider::Package::Freebsd::Pkgng + expect(@resource.provider).to eq(Chef::Provider::Package::Freebsd::Pkgng) end end end @@ -67,21 +67,21 @@ describe Chef::Resource::FreebsdPackage do describe "if pkgng enabled" do it "should be Freebsd::Pkgng" do pkg_enabled = OpenStruct.new(:stdout => "yes\n") - @resource.stub(:shell_out!).with("make -V WITH_PKGNG", :env => nil).and_return(pkg_enabled) + allow(@resource).to receive(:shell_out!).with("make -V WITH_PKGNG", :env => nil).and_return(pkg_enabled) @resource.after_created - @resource.provider.should == Chef::Provider::Package::Freebsd::Pkgng + expect(@resource.provider).to eq(Chef::Provider::Package::Freebsd::Pkgng) end end describe "if __Freebsd_version is less than 1000017 and pkgng not enabled" do it "should be Freebsd::Pkg" do pkg_enabled = OpenStruct.new(:stdout => "\n") - @resource.stub(:shell_out!).with("make -V WITH_PKGNG", :env => nil).and_return(pkg_enabled) + allow(@resource).to receive(:shell_out!).with("make -V WITH_PKGNG", :env => nil).and_return(pkg_enabled) [1000016, 1000000, 901503, 902506, 802511].each do |__freebsd_version| @node.automatic_attrs[:os_version] = __freebsd_version @resource.after_created - @resource.provider.should == Chef::Provider::Package::Freebsd::Pkg + expect(@resource.provider).to eq(Chef::Provider::Package::Freebsd::Pkg) end end end diff --git a/spec/unit/resource/gem_package_spec.rb b/spec/unit/resource/gem_package_spec.rb index 01c4fb6106..0f3eae70bb 100644 --- a/spec/unit/resource/gem_package_spec.rb +++ b/spec/unit/resource/gem_package_spec.rb @@ -37,6 +37,6 @@ describe Chef::Resource::GemPackage, "gem_binary" do it "should set the gem_binary variable to whatever is passed in" do @resource.gem_binary("/opt/local/bin/gem") - @resource.gem_binary.should eql("/opt/local/bin/gem") + expect(@resource.gem_binary).to eql("/opt/local/bin/gem") end end diff --git a/spec/unit/resource/git_spec.rb b/spec/unit/resource/git_spec.rb index da7aee1014..6a39b3d172 100644 --- a/spec/unit/resource/git_spec.rb +++ b/spec/unit/resource/git_spec.rb @@ -33,18 +33,18 @@ describe Chef::Resource::Git do end it "is a kind of Scm Resource" do - @git.should be_a_kind_of(Chef::Resource::Scm) - @git.should be_an_instance_of(Chef::Resource::Git) + expect(@git).to be_a_kind_of(Chef::Resource::Scm) + expect(@git).to be_an_instance_of(Chef::Resource::Git) end it "uses aliases revision as branch" do @git.branch "HEAD" - @git.revision.should eql("HEAD") + expect(@git.revision).to eql("HEAD") end it "aliases revision as reference" do @git.reference "v1.0 tag" - @git.revision.should eql("v1.0 tag") + expect(@git.revision).to eql("v1.0 tag") end end diff --git a/spec/unit/resource/group_spec.rb b/spec/unit/resource/group_spec.rb index 0c3cf4f67f..bcf9205f7e 100644 --- a/spec/unit/resource/group_spec.rb +++ b/spec/unit/resource/group_spec.rb @@ -25,47 +25,47 @@ describe Chef::Resource::Group, "initialize" do end it "should create a new Chef::Resource::Group" do - @resource.should be_a_kind_of(Chef::Resource) - @resource.should be_a_kind_of(Chef::Resource::Group) + expect(@resource).to be_a_kind_of(Chef::Resource) + expect(@resource).to be_a_kind_of(Chef::Resource::Group) end it "should set the resource_name to :group" do - @resource.resource_name.should eql(:group) + expect(@resource.resource_name).to eql(:group) end it "should set the group_name equal to the argument to initialize" do - @resource.group_name.should eql("admin") + expect(@resource.group_name).to eql("admin") end it "should default gid to nil" do - @resource.gid.should eql(nil) + expect(@resource.gid).to eql(nil) end it "should default members to an empty array" do - @resource.members.should eql([]) + expect(@resource.members).to eql([]) end it "should alias users to members, also an empty array" do - @resource.users.should eql([]) + expect(@resource.users).to eql([]) end it "should set action to :create" do - @resource.action.should eql(:create) + expect(@resource.action).to eql(:create) end %w{create remove modify manage}.each do |action| it "should allow action #{action}" do - @resource.allowed_actions.detect { |a| a == action.to_sym }.should eql(action.to_sym) + expect(@resource.allowed_actions.detect { |a| a == action.to_sym }).to eql(action.to_sym) end end it "should accept domain groups (@ or \ separator) on non-windows" do - lambda { @resource.group_name "domain\@group" }.should_not raise_error - @resource.group_name.should == "domain\@group" - lambda { @resource.group_name "domain\\group" }.should_not raise_error - @resource.group_name.should == "domain\\group" - lambda { @resource.group_name "domain\\group^name" }.should_not raise_error - @resource.group_name.should == "domain\\group^name" + expect { @resource.group_name "domain\@group" }.not_to raise_error + expect(@resource.group_name).to eq("domain\@group") + expect { @resource.group_name "domain\\group" }.not_to raise_error + expect(@resource.group_name).to eq("domain\\group") + expect { @resource.group_name "domain\\group^name" }.not_to raise_error + expect(@resource.group_name).to eq("domain\\group^name") end end @@ -76,11 +76,11 @@ describe Chef::Resource::Group, "group_name" do it "should allow a string" do @resource.group_name "pirates" - @resource.group_name.should eql("pirates") + expect(@resource.group_name).to eql("pirates") end it "should not allow a hash" do - lambda { @resource.send(:group_name, { :aj => "is freakin awesome" }) }.should raise_error(ArgumentError) + expect { @resource.send(:group_name, { :aj => "is freakin awesome" }) }.to raise_error(ArgumentError) end end @@ -91,11 +91,11 @@ describe Chef::Resource::Group, "gid" do it "should allow an integer" do @resource.gid 100 - @resource.gid.should eql(100) + expect(@resource.gid).to eql(100) end it "should not allow a hash" do - lambda { @resource.send(:gid, { :aj => "is freakin awesome" }) }.should raise_error(ArgumentError) + expect { @resource.send(:gid, { :aj => "is freakin awesome" }) }.to raise_error(ArgumentError) end end @@ -107,16 +107,16 @@ describe Chef::Resource::Group, "members" do [ :users, :members].each do |method| it "(#{method}) should allow and convert a string" do @resource.send(method, "aj") - @resource.send(method).should eql(["aj"]) + expect(@resource.send(method)).to eql(["aj"]) end it "(#{method}) should allow an array" do @resource.send(method, [ "aj", "adam" ]) - @resource.send(method).should eql( ["aj", "adam"] ) + expect(@resource.send(method)).to eql( ["aj", "adam"] ) end it "(#{method}) should not allow a hash" do - lambda { @resource.send(method, { :aj => "is freakin awesome" }) }.should raise_error(ArgumentError) + expect { @resource.send(method, { :aj => "is freakin awesome" }) }.to raise_error(ArgumentError) end end end @@ -127,16 +127,16 @@ describe Chef::Resource::Group, "append" do end it "should default to false" do - @resource.append.should eql(false) + expect(@resource.append).to eql(false) end it "should allow a boolean" do @resource.append true - @resource.append.should eql(true) + expect(@resource.append).to eql(true) end it "should not allow a hash" do - lambda { @resource.send(:gid, { :aj => "is freakin awesome" }) }.should raise_error(ArgumentError) + expect { @resource.send(:gid, { :aj => "is freakin awesome" }) }.to raise_error(ArgumentError) end describe "when it has members" do @@ -147,11 +147,11 @@ describe Chef::Resource::Group, "append" do it "describes its state" do state = @resource.state - state[:members].should eql(["blastoise", "pikachu"]) + expect(state[:members]).to eql(["blastoise", "pikachu"]) end it "returns the group name as its identity" do - @resource.identity.should == "pokemon" + expect(@resource.identity).to eq("pokemon") end end end diff --git a/spec/unit/resource/http_request_spec.rb b/spec/unit/resource/http_request_spec.rb index b636ca9994..aa4ce4dfbc 100644 --- a/spec/unit/resource/http_request_spec.rb +++ b/spec/unit/resource/http_request_spec.rb @@ -26,22 +26,22 @@ describe Chef::Resource::HttpRequest do end it "should create a new Chef::Resource::HttpRequest" do - @resource.should be_a_kind_of(Chef::Resource) - @resource.should be_a_kind_of(Chef::Resource::HttpRequest) + expect(@resource).to be_a_kind_of(Chef::Resource) + expect(@resource).to be_a_kind_of(Chef::Resource::HttpRequest) end it "should set url to a string" do @resource.url "http://slashdot.org" - @resource.url.should eql("http://slashdot.org") + expect(@resource.url).to eql("http://slashdot.org") end it "should set the message to the name by default" do - @resource.message.should eql("fakey_fakerton") + expect(@resource.message).to eql("fakey_fakerton") end it "should set message to a string" do @resource.message "monkeybars" - @resource.message.should eql("monkeybars") + expect(@resource.message).to eql("monkeybars") end describe "when it has a message and headers" do @@ -52,7 +52,7 @@ describe Chef::Resource::HttpRequest do end it "returns the url as its identity" do - @resource.identity.should == "http://www.trololol.net" + expect(@resource.identity).to eq("http://www.trololol.net") end end diff --git a/spec/unit/resource/ifconfig_spec.rb b/spec/unit/resource/ifconfig_spec.rb index 10a4d09982..ea5282acd5 100644 --- a/spec/unit/resource/ifconfig_spec.rb +++ b/spec/unit/resource/ifconfig_spec.rb @@ -38,12 +38,12 @@ describe Chef::Resource::Ifconfig do it "describes its state" do state = @resource.state - state[:inet_addr].should == "434.2343.23" - state[:mask].should == "255.255.545" + expect(state[:inet_addr]).to eq("434.2343.23") + expect(state[:mask]).to eq("255.255.545") end it "returns the device as its identity" do - @resource.identity.should == "charmander" + expect(@resource.identity).to eq("charmander") end end @@ -54,9 +54,9 @@ describe Chef::Resource::Ifconfig do end it "should use an ordinary Provider::Ifconfig as a provider for #{platform} #{version}" do - @resource.provider_for_action(:add).should be_a_kind_of(Chef::Provider::Ifconfig) - @resource.provider_for_action(:add).should_not be_a_kind_of(Chef::Provider::Ifconfig::Debian) - @resource.provider_for_action(:add).should_not be_a_kind_of(Chef::Provider::Ifconfig::Redhat) + expect(@resource.provider_for_action(:add)).to be_a_kind_of(Chef::Provider::Ifconfig) + expect(@resource.provider_for_action(:add)).not_to be_a_kind_of(Chef::Provider::Ifconfig::Debian) + expect(@resource.provider_for_action(:add)).not_to be_a_kind_of(Chef::Provider::Ifconfig::Redhat) end end @@ -67,7 +67,7 @@ describe Chef::Resource::Ifconfig do end it "should use an Provider::Ifconfig::Redhat as a provider for #{platform} #{version}" do - @resource.provider_for_action(:add).should be_a_kind_of(Chef::Provider::Ifconfig::Redhat) + expect(@resource.provider_for_action(:add)).to be_a_kind_of(Chef::Provider::Ifconfig::Redhat) end end @@ -78,7 +78,7 @@ describe Chef::Resource::Ifconfig do end it "should use an Ifconfig::Debian as a provider for #{platform} #{version}" do - @resource.provider_for_action(:add).should be_a_kind_of(Chef::Provider::Ifconfig::Debian) + expect(@resource.provider_for_action(:add)).to be_a_kind_of(Chef::Provider::Ifconfig::Debian) end end diff --git a/spec/unit/resource/ips_package_spec.rb b/spec/unit/resource/ips_package_spec.rb index 8718c5c093..126ae00224 100644 --- a/spec/unit/resource/ips_package_spec.rb +++ b/spec/unit/resource/ips_package_spec.rb @@ -35,6 +35,6 @@ describe Chef::Resource::IpsPackage, "initialize" do it "should support accept_license" do @resource.accept_license(true) - @resource.accept_license.should eql(true) + expect(@resource.accept_license).to eql(true) end end diff --git a/spec/unit/resource/link_spec.rb b/spec/unit/resource/link_spec.rb index 221617f9b3..3573a15f31 100644 --- a/spec/unit/resource/link_spec.rb +++ b/spec/unit/resource/link_spec.rb @@ -22,78 +22,78 @@ require 'spec_helper' describe Chef::Resource::Link do before(:each) do - Chef::Resource::Link.any_instance.should_receive(:verify_links_supported!).and_return(true) + expect_any_instance_of(Chef::Resource::Link).to receive(:verify_links_supported!).and_return(true) @resource = Chef::Resource::Link.new("fakey_fakerton") end it "should create a new Chef::Resource::Link" do - @resource.should be_a_kind_of(Chef::Resource) - @resource.should be_a_kind_of(Chef::Resource::Link) + expect(@resource).to be_a_kind_of(Chef::Resource) + expect(@resource).to be_a_kind_of(Chef::Resource::Link) end it "should have a name" do - @resource.name.should eql("fakey_fakerton") + expect(@resource.name).to eql("fakey_fakerton") end it "should have a default action of 'create'" do - @resource.action.should eql(:create) + expect(@resource.action).to eql(:create) end { :create => false, :delete => false, :blues => true }.each do |action,bad_value| it "should #{bad_value ? 'not' : ''} accept #{action.to_s}" do if bad_value - lambda { @resource.action action }.should raise_error(ArgumentError) + expect { @resource.action action }.to raise_error(ArgumentError) else - lambda { @resource.action action }.should_not raise_error + expect { @resource.action action }.not_to raise_error end end end it "should use the object name as the target_file by default" do - @resource.target_file.should eql("fakey_fakerton") + expect(@resource.target_file).to eql("fakey_fakerton") end it "should accept a string as the link source via 'to'" do - lambda { @resource.to "/tmp" }.should_not raise_error + expect { @resource.to "/tmp" }.not_to raise_error end it "should not accept a Hash for the link source via 'to'" do - lambda { @resource.to Hash.new }.should raise_error(ArgumentError) + expect { @resource.to Hash.new }.to raise_error(ArgumentError) end it "should allow you to set a link source via 'to'" do @resource.to "/tmp/foo" - @resource.to.should eql("/tmp/foo") + expect(@resource.to).to eql("/tmp/foo") end it "should allow you to specify the link type" do @resource.link_type "symbolic" - @resource.link_type.should eql(:symbolic) + expect(@resource.link_type).to eql(:symbolic) end it "should default to a symbolic link" do - @resource.link_type.should eql(:symbolic) + expect(@resource.link_type).to eql(:symbolic) end it "should accept a hard link_type" do @resource.link_type :hard - @resource.link_type.should eql(:hard) + expect(@resource.link_type).to eql(:hard) end it "should reject any other link_type but :hard and :symbolic" do - lambda { @resource.link_type "x-men" }.should raise_error(ArgumentError) + expect { @resource.link_type "x-men" }.to raise_error(ArgumentError) end it "should accept a group name or id for group" do - lambda { @resource.group "root" }.should_not raise_error - lambda { @resource.group 123 }.should_not raise_error - lambda { @resource.group "root:goo" }.should raise_error(ArgumentError) + expect { @resource.group "root" }.not_to raise_error + expect { @resource.group 123 }.not_to raise_error + expect { @resource.group "root:goo" }.to raise_error(ArgumentError) end it "should accept a user name or id for owner" do - lambda { @resource.owner "root" }.should_not raise_error - lambda { @resource.owner 123 }.should_not raise_error - lambda { @resource.owner "root:goo" }.should raise_error(ArgumentError) + expect { @resource.owner "root" }.not_to raise_error + expect { @resource.owner 123 }.not_to raise_error + expect { @resource.owner "root:goo" }.to raise_error(ArgumentError) end describe "when it has to, link_type, owner, and group" do @@ -107,13 +107,13 @@ describe Chef::Resource::Link do it "describes its state" do state = @resource.state - state[:to].should == "/to/dir/file.tar" - state[:owner].should == "root" - state[:group].should == "0664" + expect(state[:to]).to eq("/to/dir/file.tar") + expect(state[:owner]).to eq("root") + expect(state[:group]).to eq("0664") end it "returns the target file as its identity" do - @resource.identity.should == "/var/target.tar" + expect(@resource.identity).to eq("/var/target.tar") end end end diff --git a/spec/unit/resource/log_spec.rb b/spec/unit/resource/log_spec.rb index c0201e57f3..b2af194238 100644 --- a/spec/unit/resource/log_spec.rb +++ b/spec/unit/resource/log_spec.rb @@ -27,29 +27,29 @@ describe Chef::Resource::Log do end it "should create a new Chef::Resource::Log" do - @resource.should be_a_kind_of(Chef::Resource) - @resource.should be_a_kind_of(Chef::Resource::Log) + expect(@resource).to be_a_kind_of(Chef::Resource) + expect(@resource).to be_a_kind_of(Chef::Resource::Log) end it "supports the :write actions" do - @resource.allowed_actions.should include(:write) + expect(@resource.allowed_actions).to include(:write) end it "should have a name of log" do - @resource.resource_name.should == :log + expect(@resource.resource_name).to eq(:log) end it "should allow you to set a log string" do - @resource.name.should == @log_str + expect(@resource.name).to eq(@log_str) end it "should set the message to the first argument to new" do - @resource.message.should == @log_str + expect(@resource.message).to eq(@log_str) end it "should accept a string for the log message" do @resource.message "this is different" - @resource.message.should == "this is different" + expect(@resource.message).to eq("this is different") end it "should accept a vaild level option" do @@ -58,7 +58,7 @@ describe Chef::Resource::Log do @resource.level :warn @resource.level :error @resource.level :fatal - lambda { @resource.level :unsupported }.should raise_error(ArgumentError) + expect { @resource.level :unsupported }.to raise_error(ArgumentError) end describe "when the identity is defined" do @@ -67,7 +67,7 @@ describe Chef::Resource::Log do end it "returns the log string as its identity" do - @resource.identity.should == "ery day I'm loggin-in" + expect(@resource.identity).to eq("ery day I'm loggin-in") end end end diff --git a/spec/unit/resource/mdadm_spec.rb b/spec/unit/resource/mdadm_spec.rb index daf10bcfea..866309ec5b 100644 --- a/spec/unit/resource/mdadm_spec.rb +++ b/spec/unit/resource/mdadm_spec.rb @@ -26,57 +26,57 @@ describe Chef::Resource::Mdadm do end it "should create a new Chef::Resource::Mdadm" do - @resource.should be_a_kind_of(Chef::Resource) - @resource.should be_a_kind_of(Chef::Resource::Mdadm) + expect(@resource).to be_a_kind_of(Chef::Resource) + expect(@resource).to be_a_kind_of(Chef::Resource::Mdadm) end it "should have a resource name of :mdadm" do - @resource.resource_name.should eql(:mdadm) + expect(@resource.resource_name).to eql(:mdadm) end it "should have a default action of create" do - @resource.action.should eql(:create) + expect(@resource.action).to eql(:create) end it "should accept create, assemble, stop as actions" do - lambda { @resource.action :create }.should_not raise_error - lambda { @resource.action :assemble }.should_not raise_error - lambda { @resource.action :stop }.should_not raise_error + expect { @resource.action :create }.not_to raise_error + expect { @resource.action :assemble }.not_to raise_error + expect { @resource.action :stop }.not_to raise_error end it "should allow you to set the raid_device attribute" do @resource.raid_device "/dev/md3" - @resource.raid_device.should eql("/dev/md3") + expect(@resource.raid_device).to eql("/dev/md3") end it "should allow you to set the chunk attribute" do @resource.chunk 256 - @resource.chunk.should eql(256) + expect(@resource.chunk).to eql(256) end it "should allow you to set the level attribute" do @resource.level 1 - @resource.level.should eql(1) + expect(@resource.level).to eql(1) end it "should allow you to set the metadata attribute" do @resource.metadata "1.2" - @resource.metadata.should eql("1.2") + expect(@resource.metadata).to eql("1.2") end it "should allow you to set the bitmap attribute" do @resource.metadata "internal" - @resource.metadata.should eql("internal") + expect(@resource.metadata).to eql("internal") end it "should allow you to set the devices attribute" do @resource.devices ["/dev/sda", "/dev/sdb"] - @resource.devices.should eql(["/dev/sda", "/dev/sdb"]) + expect(@resource.devices).to eql(["/dev/sda", "/dev/sdb"]) end it "should allow you to set the exists attribute" do @resource.exists true - @resource.exists.should eql(true) + expect(@resource.exists).to eql(true) end describe "when it has devices, level, and chunk" do @@ -89,13 +89,13 @@ describe Chef::Resource::Mdadm do it "describes its state" do state = @resource.state - state[:devices].should eql(["device1", "device2"]) - state[:level].should == 1 - state[:chunk].should == 42 + expect(state[:devices]).to eql(["device1", "device2"]) + expect(state[:level]).to eq(1) + expect(state[:chunk]).to eq(42) end it "returns the raid device as its identity" do - @resource.identity.should == "raider" + expect(@resource.identity).to eq("raider") end end diff --git a/spec/unit/resource/mount_spec.rb b/spec/unit/resource/mount_spec.rb index 0a154342c7..ad95c06e04 100644 --- a/spec/unit/resource/mount_spec.rb +++ b/spec/unit/resource/mount_spec.rb @@ -25,150 +25,150 @@ describe Chef::Resource::Mount do end it "should create a new Chef::Resource::Mount" do - @resource.should be_a_kind_of(Chef::Resource) - @resource.should be_a_kind_of(Chef::Resource::Mount) + expect(@resource).to be_a_kind_of(Chef::Resource) + expect(@resource).to be_a_kind_of(Chef::Resource::Mount) end it "should have a name" do - @resource.name.should eql("filesystem") + expect(@resource.name).to eql("filesystem") end it "should set mount_point to the name" do - @resource.mount_point.should eql("filesystem") + expect(@resource.mount_point).to eql("filesystem") end it "should have a default action of mount" do - @resource.action.should eql(:mount) + expect(@resource.action).to eql(:mount) end it "should accept mount, umount and remount as actions" do - lambda { @resource.action :mount }.should_not raise_error - lambda { @resource.action :umount }.should_not raise_error - lambda { @resource.action :remount }.should_not raise_error - lambda { @resource.action :brooklyn }.should raise_error(ArgumentError) + expect { @resource.action :mount }.not_to raise_error + expect { @resource.action :umount }.not_to raise_error + expect { @resource.action :remount }.not_to raise_error + expect { @resource.action :brooklyn }.to raise_error(ArgumentError) end it "should allow you to set the device attribute" do @resource.device "/dev/sdb3" - @resource.device.should eql("/dev/sdb3") + expect(@resource.device).to eql("/dev/sdb3") end it "should set fsck_device to '-' by default" do - @resource.fsck_device.should eql('-') + expect(@resource.fsck_device).to eql('-') end it "should allow you to set the fsck_device attribute" do @resource.fsck_device "/dev/rdsk/sdb3" - @resource.fsck_device.should eql("/dev/rdsk/sdb3") + expect(@resource.fsck_device).to eql("/dev/rdsk/sdb3") end it "should allow you to set the fstype attribute" do @resource.fstype "nfs" - @resource.fstype.should eql("nfs") + expect(@resource.fstype).to eql("nfs") end it "should allow you to set the dump attribute" do @resource.dump 1 - @resource.dump.should eql(1) + expect(@resource.dump).to eql(1) end it "should allow you to set the pass attribute" do @resource.pass 1 - @resource.pass.should eql(1) + expect(@resource.pass).to eql(1) end it "should set the options attribute to defaults" do - @resource.options.should eql(["defaults"]) + expect(@resource.options).to eql(["defaults"]) end it "should allow options to be sent as a string, and convert to array" do @resource.options "rw,noexec" - @resource.options.should be_a_kind_of(Array) + expect(@resource.options).to be_a_kind_of(Array) end it "should allow options attribute as an array" do @resource.options ["ro", "nosuid"] - @resource.options.should be_a_kind_of(Array) + expect(@resource.options).to be_a_kind_of(Array) end it "should allow options to be sent as a delayed evaluator" do @resource.options Chef::DelayedEvaluator.new {["rw", "noexec"]} - @resource.options.should eql(["rw", "noexec"]) + expect(@resource.options).to eql(["rw", "noexec"]) end it "should allow options to be sent as a delayed evaluator, and convert to array" do @resource.options Chef::DelayedEvaluator.new {"rw,noexec"} - @resource.options.should be_a_kind_of(Array) - @resource.options.should eql(["rw", "noexec"]) + expect(@resource.options).to be_a_kind_of(Array) + expect(@resource.options).to eql(["rw", "noexec"]) end it "should accept true for mounted" do @resource.mounted(true) - @resource.mounted.should eql(true) + expect(@resource.mounted).to eql(true) end it "should accept false for mounted" do @resource.mounted(false) - @resource.mounted.should eql(false) + expect(@resource.mounted).to eql(false) end it "should set mounted to false by default" do - @resource.mounted.should eql(false) + expect(@resource.mounted).to eql(false) end it "should not accept a string for mounted" do - lambda { @resource.mounted("poop") }.should raise_error(ArgumentError) + expect { @resource.mounted("poop") }.to raise_error(ArgumentError) end it "should accept true for enabled" do @resource.enabled(true) - @resource.enabled.should eql(true) + expect(@resource.enabled).to eql(true) end it "should accept false for enabled" do @resource.enabled(false) - @resource.enabled.should eql(false) + expect(@resource.enabled).to eql(false) end it "should set enabled to false by default" do - @resource.enabled.should eql(false) + expect(@resource.enabled).to eql(false) end it "should not accept a string for enabled" do - lambda { @resource.enabled("poop") }.should raise_error(ArgumentError) + expect { @resource.enabled("poop") }.to raise_error(ArgumentError) end it "should default all feature support to false" do support_hash = { :remount => false } - @resource.supports.should == support_hash + expect(@resource.supports).to eq(support_hash) end it "should allow you to set feature support as an array" do support_array = [ :remount ] support_hash = { :remount => true } @resource.supports(support_array) - @resource.supports.should == support_hash + expect(@resource.supports).to eq(support_hash) end it "should allow you to set feature support as a hash" do support_hash = { :remount => true } @resource.supports(support_hash) - @resource.supports.should == support_hash + expect(@resource.supports).to eq(support_hash) end it "should allow you to set username" do @resource.username("Administrator") - @resource.username.should == "Administrator" + expect(@resource.username).to eq("Administrator") end it "should allow you to set password" do @resource.password("Jetstream123!") - @resource.password.should == "Jetstream123!" + expect(@resource.password).to eq("Jetstream123!") end it "should allow you to set domain" do @resource.domain("TEST_DOMAIN") - @resource.domain.should == "TEST_DOMAIN" + expect(@resource.domain).to eq("TEST_DOMAIN") end describe "when it has mount point, device type, and fstype" do @@ -181,13 +181,13 @@ describe Chef::Resource::Mount do it "describes its state" do state = @resource.state - state[:mount_point].should == "123.456" - state[:device_type].should eql(:device) - state[:fstype].should == "ranked" + expect(state[:mount_point]).to eq("123.456") + expect(state[:device_type]).to eql(:device) + expect(state[:fstype]).to eq("ranked") end it "returns the device as its identity" do - @resource.identity.should == "charmander" + expect(@resource.identity).to eq("charmander") end end @@ -202,12 +202,12 @@ describe Chef::Resource::Mount do it "describes its state" do state = @resource.state - state[:mount_point].should == "T:" - state[:username].should == "Administrator" - state[:password].should == "Jetstream123!" - state[:domain].should == "TEST_DOMAIN" - state[:device_type].should eql(:device) - state[:fstype].should == "auto" + expect(state[:mount_point]).to eq("T:") + expect(state[:username]).to eq("Administrator") + expect(state[:password]).to eq("Jetstream123!") + expect(state[:domain]).to eq("TEST_DOMAIN") + expect(state[:device_type]).to eql(:device) + expect(state[:fstype]).to eq("auto") end end diff --git a/spec/unit/resource/ohai_spec.rb b/spec/unit/resource/ohai_spec.rb index b8d062b4c9..fe29755abf 100644 --- a/spec/unit/resource/ohai_spec.rb +++ b/spec/unit/resource/ohai_spec.rb @@ -25,21 +25,21 @@ describe Chef::Resource::Ohai do end it "should create a new Chef::Resource::Ohai" do - @resource.should be_a_kind_of(Chef::Resource) - @resource.should be_a_kind_of(Chef::Resource::Ohai) + expect(@resource).to be_a_kind_of(Chef::Resource) + expect(@resource).to be_a_kind_of(Chef::Resource::Ohai) end it "should have a resource name of :ohai" do - @resource.resource_name.should eql(:ohai) + expect(@resource.resource_name).to eql(:ohai) end it "should have a default action of create" do - @resource.action.should eql(:reload) + expect(@resource.action).to eql(:reload) end it "should allow you to set the plugin attribute" do @resource.plugin "passwd" - @resource.plugin.should eql("passwd") + expect(@resource.plugin).to eql("passwd") end describe "when it has a plugin value" do @@ -50,11 +50,11 @@ describe Chef::Resource::Ohai do it "describes its state" do state = @resource.state - state[:plugin].should == "passwd" + expect(state[:plugin]).to eq("passwd") end it "returns the name as its identity" do - @resource.identity.should == "test" + expect(@resource.identity).to eq("test") end end diff --git a/spec/unit/resource/package_spec.rb b/spec/unit/resource/package_spec.rb index 8a1a13394e..449732a3c4 100644 --- a/spec/unit/resource/package_spec.rb +++ b/spec/unit/resource/package_spec.rb @@ -26,42 +26,42 @@ describe Chef::Resource::Package do end it "should create a new Chef::Resource::Package" do - @resource.should be_a_kind_of(Chef::Resource) - @resource.should be_a_kind_of(Chef::Resource::Package) + expect(@resource).to be_a_kind_of(Chef::Resource) + expect(@resource).to be_a_kind_of(Chef::Resource::Package) end it "should set the package_name to the first argument to new" do - @resource.package_name.should eql("emacs") + expect(@resource.package_name).to eql("emacs") end it "should accept a string for the package name" do @resource.package_name "something" - @resource.package_name.should eql("something") + expect(@resource.package_name).to eql("something") end it "should accept a string for the version" do @resource.version "something" - @resource.version.should eql("something") + expect(@resource.version).to eql("something") end it "should accept a string for the response file" do @resource.response_file "something" - @resource.response_file.should eql("something") + expect(@resource.response_file).to eql("something") end it "should accept a hash for response file template variables" do @resource.response_file_variables({:variables => true}) - @resource.response_file_variables.should eql({:variables => true}) + expect(@resource.response_file_variables).to eql({:variables => true}) end it "should accept a string for the source" do @resource.source "something" - @resource.source.should eql("something") + expect(@resource.source).to eql("something") end it "should accept a string for the options" do @resource.options "something" - @resource.options.should eql("something") + expect(@resource.options).to eql("something") end describe "when it has a package_name and version" do @@ -73,12 +73,12 @@ describe Chef::Resource::Package do it "describes its state" do state = @resource.state - state[:version].should == "10.9.8" - state[:options].should == "-al" + expect(state[:version]).to eq("10.9.8") + expect(state[:options]).to eq("-al") end it "returns the file path as its identity" do - @resource.identity.should == "tomcat" + expect(@resource.identity).to eq("tomcat") end end diff --git a/spec/unit/resource/perl_spec.rb b/spec/unit/resource/perl_spec.rb index d25dc98563..7247cce6e3 100644 --- a/spec/unit/resource/perl_spec.rb +++ b/spec/unit/resource/perl_spec.rb @@ -25,16 +25,16 @@ describe Chef::Resource::Perl do end it "should create a new Chef::Resource::Perl" do - @resource.should be_a_kind_of(Chef::Resource) - @resource.should be_a_kind_of(Chef::Resource::Perl) + expect(@resource).to be_a_kind_of(Chef::Resource) + expect(@resource).to be_a_kind_of(Chef::Resource::Perl) end it "should have a resource name of :perl" do - @resource.resource_name.should eql(:perl) + expect(@resource.resource_name).to eql(:perl) end it "should have an interpreter of perl" do - @resource.interpreter.should eql("perl") + expect(@resource.interpreter).to eql("perl") end end diff --git a/spec/unit/resource/portage_package_spec.rb b/spec/unit/resource/portage_package_spec.rb index 510f3b5864..d2ac7ac4be 100644 --- a/spec/unit/resource/portage_package_spec.rb +++ b/spec/unit/resource/portage_package_spec.rb @@ -25,14 +25,14 @@ describe Chef::Resource::PortagePackage, "initialize" do end it "should return a Chef::Resource::PortagePackage" do - @resource.should be_a_kind_of(Chef::Resource::PortagePackage) + expect(@resource).to be_a_kind_of(Chef::Resource::PortagePackage) end it "should set the resource_name to :portage_package" do - @resource.resource_name.should eql(:portage_package) + expect(@resource.resource_name).to eql(:portage_package) end it "should set the provider to Chef::Provider::Package::Portage" do - @resource.provider.should eql(Chef::Provider::Package::Portage) + expect(@resource.provider).to eql(Chef::Provider::Package::Portage) end end diff --git a/spec/unit/resource/powershell_spec.rb b/spec/unit/resource/powershell_spec.rb index da20c4f0bf..c263172ae6 100644 --- a/spec/unit/resource/powershell_spec.rb +++ b/spec/unit/resource/powershell_spec.rb @@ -33,32 +33,32 @@ describe Chef::Resource::PowershellScript do end it "should create a new Chef::Resource::PowershellScript" do - @resource.should be_a_kind_of(Chef::Resource::PowershellScript) + expect(@resource).to be_a_kind_of(Chef::Resource::PowershellScript) end it "should set convert_boolean_return to false by default" do - @resource.convert_boolean_return.should == false + expect(@resource.convert_boolean_return).to eq(false) end it "should return the value for convert_boolean_return that was set" do @resource.convert_boolean_return true - @resource.convert_boolean_return.should == true + expect(@resource.convert_boolean_return).to eq(true) @resource.convert_boolean_return false - @resource.convert_boolean_return.should == false + expect(@resource.convert_boolean_return).to eq(false) end context "when using guards" do let(:resource) { @resource } before(:each) do - resource.stub(:run_action) - resource.stub(:updated).and_return(true) + allow(resource).to receive(:run_action) + allow(resource).to receive(:updated).and_return(true) end it "inherits exactly the :cwd, :environment, :group, :path, :user, :umask, and :architecture attributes from a parent resource class" do inherited_difference = Chef::Resource::PowershellScript.guard_inherited_attributes - [:cwd, :environment, :group, :path, :user, :umask, :architecture ] - inherited_difference.should == [] + expect(inherited_difference).to eq([]) end it "should allow guard interpreter to be set to Chef::Resource::Script" do diff --git a/spec/unit/resource/python_spec.rb b/spec/unit/resource/python_spec.rb index 3362b68c62..8a3f7e48ca 100644 --- a/spec/unit/resource/python_spec.rb +++ b/spec/unit/resource/python_spec.rb @@ -25,16 +25,16 @@ describe Chef::Resource::Python do end it "should create a new Chef::Resource::Python" do - @resource.should be_a_kind_of(Chef::Resource) - @resource.should be_a_kind_of(Chef::Resource::Python) + expect(@resource).to be_a_kind_of(Chef::Resource) + expect(@resource).to be_a_kind_of(Chef::Resource::Python) end it "should have a resource name of :python" do - @resource.resource_name.should eql(:python) + expect(@resource.resource_name).to eql(:python) end it "should have an interpreter of python" do - @resource.interpreter.should eql("python") + expect(@resource.interpreter).to eql("python") end end diff --git a/spec/unit/resource/registry_key_spec.rb b/spec/unit/resource/registry_key_spec.rb index 00c301d61d..e2a864d73a 100644 --- a/spec/unit/resource/registry_key_spec.rb +++ b/spec/unit/resource/registry_key_spec.rb @@ -24,33 +24,33 @@ describe Chef::Resource::RegistryKey, "initialize" do end it "should create a new Chef::Resource::RegistryKey" do - @resource.should be_a_kind_of(Chef::Resource) - @resource.should be_a_kind_of(Chef::Resource::RegistryKey) + expect(@resource).to be_a_kind_of(Chef::Resource) + expect(@resource).to be_a_kind_of(Chef::Resource::RegistryKey) end it "should set the resource_name to :registry_key" do - @resource.resource_name.should eql(:registry_key) + expect(@resource.resource_name).to eql(:registry_key) end it "should set the key equal to the argument to initialize" do - @resource.key.should eql('HKCU\Software\Raxicoricofallapatorius') + expect(@resource.key).to eql('HKCU\Software\Raxicoricofallapatorius') end it "should default recursive to false" do - @resource.recursive.should eql(false) + expect(@resource.recursive).to eql(false) end it "should default architecture to :machine" do - @resource.architecture.should eql(:machine) + expect(@resource.architecture).to eql(:machine) end it "should set action to :create" do - @resource.action.should eql(:create) + expect(@resource.action).to eql(:create) end %w{create create_if_missing delete delete_key}.each do |action| it "should allow action #{action}" do - @resource.allowed_actions.detect { |a| a == action.to_sym }.should eql(action.to_sym) + expect(@resource.allowed_actions.detect { |a| a == action.to_sym }).to eql(action.to_sym) end end end @@ -62,15 +62,15 @@ describe Chef::Resource::RegistryKey, "key" do it "should allow a string" do @resource.key 'HKCU\Software\Poosh' - @resource.key.should eql('HKCU\Software\Poosh') + expect(@resource.key).to eql('HKCU\Software\Poosh') end it "should not allow an integer" do - lambda { @resource.send(:key, 100) }.should raise_error(ArgumentError) + expect { @resource.send(:key, 100) }.to raise_error(ArgumentError) end it "should not allow a hash" do - lambda { @resource.send(:key, { :sonic => "screwdriver" }) }.should raise_error(ArgumentError) + expect { @resource.send(:key, { :sonic => "screwdriver" }) }.to raise_error(ArgumentError) end end @@ -81,41 +81,41 @@ describe Chef::Resource::RegistryKey, "values" do it "should allow a single proper hash of registry values" do @resource.values( { :name => 'poosh', :type => :string, :data => 'carmen' } ) - @resource.values.should eql([ { :name => 'poosh', :type => :string, :data => 'carmen' } ]) + expect(@resource.values).to eql([ { :name => 'poosh', :type => :string, :data => 'carmen' } ]) end it "should allow an array of proper hashes of registry values" do @resource.values [ { :name => 'poosh', :type => :string, :data => 'carmen' } ] - @resource.values.should eql([ { :name => 'poosh', :type => :string, :data => 'carmen' } ]) + expect(@resource.values).to eql([ { :name => 'poosh', :type => :string, :data => 'carmen' } ]) end it "should return checksummed data if the type is unsafe" do @resource.values( { :name => 'poosh', :type => :binary, :data => 255.chr * 1 }) - @resource.values.should eql([ { :name => 'poosh', :type => :binary, :data => "00594fd4f42ba43fc1ca0427a0576295" } ]) + expect(@resource.values).to eql([ { :name => 'poosh', :type => :binary, :data => "00594fd4f42ba43fc1ca0427a0576295" } ]) end it "should throw an exception if the name field is missing" do - lambda { @resource.values [ { :type => :string, :data => 'carmen' } ] }.should raise_error(ArgumentError) + expect { @resource.values [ { :type => :string, :data => 'carmen' } ] }.to raise_error(ArgumentError) end it "should throw an exception if the type field is missing" do - lambda { @resource.values [ { :name => 'poosh', :data => 'carmen' } ] }.should raise_error(ArgumentError) + expect { @resource.values [ { :name => 'poosh', :data => 'carmen' } ] }.to raise_error(ArgumentError) end it "should throw an exception if the data field is missing" do - lambda { @resource.values [ { :name => 'poosh', :type => :string } ] }.should raise_error(ArgumentError) + expect { @resource.values [ { :name => 'poosh', :type => :string } ] }.to raise_error(ArgumentError) end it "should throw an exception if extra fields are present" do - lambda { @resource.values [ { :name => 'poosh', :type => :string, :data => 'carmen', :screwdriver => 'sonic' } ] }.should raise_error(ArgumentError) + expect { @resource.values [ { :name => 'poosh', :type => :string, :data => 'carmen', :screwdriver => 'sonic' } ] }.to raise_error(ArgumentError) end it "should not allow a string" do - lambda { @resource.send(:values, 'souffle') }.should raise_error(ArgumentError) + expect { @resource.send(:values, 'souffle') }.to raise_error(ArgumentError) end it "should not allow an integer" do - lambda { @resource.send(:values, 100) }.should raise_error(ArgumentError) + expect { @resource.send(:values, 100) }.to raise_error(ArgumentError) end end @@ -126,23 +126,23 @@ describe Chef::Resource::RegistryKey, "recursive" do it "should allow a boolean" do @resource.recursive(true) - @resource.recursive.should eql(true) + expect(@resource.recursive).to eql(true) end it "should not allow a hash" do - lambda { @resource.recursive({:sonic => :screwdriver}) }.should raise_error(ArgumentError) + expect { @resource.recursive({:sonic => :screwdriver}) }.to raise_error(ArgumentError) end it "should not allow an array" do - lambda { @resource.recursive([:nose, :chin]) }.should raise_error(ArgumentError) + expect { @resource.recursive([:nose, :chin]) }.to raise_error(ArgumentError) end it "should not allow a string" do - lambda { @resource.recursive('souffle') }.should raise_error(ArgumentError) + expect { @resource.recursive('souffle') }.to raise_error(ArgumentError) end it "should not allow an integer" do - lambda { @resource.recursive(100) }.should raise_error(ArgumentError) + expect { @resource.recursive(100) }.to raise_error(ArgumentError) end end @@ -154,24 +154,24 @@ describe Chef::Resource::RegistryKey, "architecture" do [ :i386, :x86_64, :machine ].each do |arch| it "should allow #{arch} as a symbol" do @resource.architecture(arch) - @resource.architecture.should eql(arch) + expect(@resource.architecture).to eql(arch) end end it "should not allow a hash" do - lambda { @resource.architecture({:sonic => :screwdriver}) }.should raise_error(ArgumentError) + expect { @resource.architecture({:sonic => :screwdriver}) }.to raise_error(ArgumentError) end it "should not allow an array" do - lambda { @resource.architecture([:nose, :chin]) }.should raise_error(ArgumentError) + expect { @resource.architecture([:nose, :chin]) }.to raise_error(ArgumentError) end it "should not allow a string" do - lambda { @resource.architecture('souffle') }.should raise_error(ArgumentError) + expect { @resource.architecture('souffle') }.to raise_error(ArgumentError) end it "should not allow an integer" do - lambda { @resource.architecture(100) }.should raise_error(ArgumentError) + expect { @resource.architecture(100) }.to raise_error(ArgumentError) end end @@ -183,7 +183,7 @@ describe Chef::Resource::RegistryKey, ":unscrubbed_values" do it "should return unsafe data as-is" do key_values = [ { :name => 'poosh', :type => :binary, :data => 255.chr * 1 } ] @resource.values(key_values) - @resource.unscrubbed_values.should eql(key_values) + expect(@resource.unscrubbed_values).to eql(key_values) end end @@ -194,6 +194,6 @@ describe Chef::Resource::RegistryKey, "state" do it "should return scrubbed values" do @resource.values([ { :name => 'poosh', :type => :binary, :data => 255.chr * 1 } ]) - @resource.state.should eql( { :values => [{ :name => 'poosh', :type => :binary, :data => "00594fd4f42ba43fc1ca0427a0576295" }] } ) + expect(@resource.state).to eql( { :values => [{ :name => 'poosh', :type => :binary, :data => "00594fd4f42ba43fc1ca0427a0576295" }] } ) end end diff --git a/spec/unit/resource/remote_directory_spec.rb b/spec/unit/resource/remote_directory_spec.rb index d3800062ae..1ab75586b6 100644 --- a/spec/unit/resource/remote_directory_spec.rb +++ b/spec/unit/resource/remote_directory_spec.rb @@ -25,52 +25,52 @@ describe Chef::Resource::RemoteDirectory do end it "should create a new Chef::Resource::RemoteDirectory" do - @resource.should be_a_kind_of(Chef::Resource) - @resource.should be_a_kind_of(Chef::Resource::RemoteDirectory) + expect(@resource).to be_a_kind_of(Chef::Resource) + expect(@resource).to be_a_kind_of(Chef::Resource::RemoteDirectory) end it "should set the path to the first argument to new" do - @resource.path.should eql("/etc/dunk") + expect(@resource.path).to eql("/etc/dunk") end it "should accept a string for the remote directory source" do @resource.source "foo" - @resource.source.should eql("foo") + expect(@resource.source).to eql("foo") end it "should have the basename of the remote directory resource as the default source" do - @resource.source.should eql("dunk") + expect(@resource.source).to eql("dunk") end it "should accept a number for the remote files backup" do @resource.files_backup 1 - @resource.files_backup.should eql(1) + expect(@resource.files_backup).to eql(1) end it "should accept false for the remote files backup" do @resource.files_backup false - @resource.files_backup.should eql(false) + expect(@resource.files_backup).to eql(false) end it "should accept 3 or 4 digets for the files_mode" do @resource.files_mode 100 - @resource.files_mode.should eql(100) + expect(@resource.files_mode).to eql(100) @resource.files_mode 1000 - @resource.files_mode.should eql(1000) + expect(@resource.files_mode).to eql(1000) end it "should accept a string or number for the files group" do @resource.files_group "heart" - @resource.files_group.should eql("heart") + expect(@resource.files_group).to eql("heart") @resource.files_group 1000 - @resource.files_group.should eql(1000) + expect(@resource.files_group).to eql(1000) end it "should accept a string or number for the files owner" do @resource.files_owner "heart" - @resource.files_owner.should eql("heart") + expect(@resource.files_owner).to eql("heart") @resource.files_owner 1000 - @resource.files_owner.should eql(1000) + expect(@resource.files_owner).to eql(1000) end describe "when it has cookbook, files owner, files mode, and source" do @@ -85,13 +85,13 @@ describe Chef::Resource::RemoteDirectory do it "describes its state" do state = @resource.state - state[:files_owner].should == "root" - state[:files_group].should == "supergroup" - state[:files_mode].should == "0664" + expect(state[:files_owner]).to eq("root") + expect(state[:files_group]).to eq("supergroup") + expect(state[:files_mode]).to eq("0664") end it "returns the path as its identity" do - @resource.identity.should == "/var/path/" + expect(@resource.identity).to eq("/var/path/") end end end diff --git a/spec/unit/resource/remote_file_spec.rb b/spec/unit/resource/remote_file_spec.rb index 8f1633119d..14d2fb97bc 100644 --- a/spec/unit/resource/remote_file_spec.rb +++ b/spec/unit/resource/remote_file_spec.rb @@ -27,74 +27,74 @@ describe Chef::Resource::RemoteFile do describe "initialize" do it "should create a new Chef::Resource::RemoteFile" do - @resource.should be_a_kind_of(Chef::Resource) - @resource.should be_a_kind_of(Chef::Resource::File) - @resource.should be_a_kind_of(Chef::Resource::RemoteFile) + expect(@resource).to be_a_kind_of(Chef::Resource) + expect(@resource).to be_a_kind_of(Chef::Resource::File) + expect(@resource).to be_a_kind_of(Chef::Resource::RemoteFile) end end it "says its provider is RemoteFile when the source is an absolute URI" do @resource.source("http://www.google.com/robots.txt") - @resource.provider.should == Chef::Provider::RemoteFile - Chef::Platform.find_provider(:noplatform, 'noversion', @resource).should == Chef::Provider::RemoteFile + expect(@resource.provider).to eq(Chef::Provider::RemoteFile) + expect(Chef::Platform.find_provider(:noplatform, 'noversion', @resource)).to eq(Chef::Provider::RemoteFile) end describe "source" do it "does not have a default value for 'source'" do - @resource.source.should eql([]) + expect(@resource.source).to eql([]) end it "should accept a URI for the remote file source" do @resource.source "http://opscode.com/" - @resource.source.should eql([ "http://opscode.com/" ]) + expect(@resource.source).to eql([ "http://opscode.com/" ]) end it "should accept a delayed evalutator (string) for the remote file source" do @resource.source Chef::DelayedEvaluator.new {"http://opscode.com/"} - @resource.source.should eql([ "http://opscode.com/" ]) + expect(@resource.source).to eql([ "http://opscode.com/" ]) end it "should accept an array of URIs for the remote file source" do @resource.source([ "http://opscode.com/", "http://puppetlabs.com/" ]) - @resource.source.should eql([ "http://opscode.com/", "http://puppetlabs.com/" ]) + expect(@resource.source).to eql([ "http://opscode.com/", "http://puppetlabs.com/" ]) end it "should accept a delated evaluator (array) for the remote file source" do @resource.source Chef::DelayedEvaluator.new { [ "http://opscode.com/", "http://puppetlabs.com/" ] } - @resource.source.should eql([ "http://opscode.com/", "http://puppetlabs.com/" ]) + expect(@resource.source).to eql([ "http://opscode.com/", "http://puppetlabs.com/" ]) end it "should accept an multiple URIs as arguments for the remote file source" do @resource.source("http://opscode.com/", "http://puppetlabs.com/") - @resource.source.should eql([ "http://opscode.com/", "http://puppetlabs.com/" ]) + expect(@resource.source).to eql([ "http://opscode.com/", "http://puppetlabs.com/" ]) end it "should only accept a single argument if a delayed evalutor is used" do - lambda { + expect { @resource.source("http://opscode.com/", Chef::DelayedEvaluator.new {"http://opscode.com/"}) - }.should raise_error(Chef::Exceptions::InvalidRemoteFileURI) + }.to raise_error(Chef::Exceptions::InvalidRemoteFileURI) end it "should only accept a single array item if a delayed evalutor is used" do - lambda { + expect { @resource.source(["http://opscode.com/", Chef::DelayedEvaluator.new {"http://opscode.com/"}]) - }.should raise_error(Chef::Exceptions::InvalidRemoteFileURI) + }.to raise_error(Chef::Exceptions::InvalidRemoteFileURI) end it "does not accept a non-URI as the source" do - lambda { @resource.source("not-a-uri") }.should raise_error(Chef::Exceptions::InvalidRemoteFileURI) + expect { @resource.source("not-a-uri") }.to raise_error(Chef::Exceptions::InvalidRemoteFileURI) end it "does not accept a non-URI as the source when read from a delayed evaluator" do - lambda { + expect { @resource.source(Chef::DelayedEvaluator.new {"not-a-uri"}) @resource.source - }.should raise_error(Chef::Exceptions::InvalidRemoteFileURI) + }.to raise_error(Chef::Exceptions::InvalidRemoteFileURI) end it "should raise an exception when source is an empty array" do - lambda { @resource.source([]) }.should raise_error(ArgumentError) + expect { @resource.source([]) }.to raise_error(ArgumentError) end end @@ -102,51 +102,51 @@ describe Chef::Resource::RemoteFile do describe "checksum" do it "should accept a string for the checksum object" do @resource.checksum "asdf" - @resource.checksum.should eql("asdf") + expect(@resource.checksum).to eql("asdf") end it "should default to nil" do - @resource.checksum.should == nil + expect(@resource.checksum).to eq(nil) end end describe "ftp_active_mode" do it "should accept a boolean for the ftp_active_mode object" do @resource.ftp_active_mode true - @resource.ftp_active_mode.should be_true + expect(@resource.ftp_active_mode).to be_true end it "should default to false" do - @resource.ftp_active_mode.should be_false + expect(@resource.ftp_active_mode).to be_false end end describe "conditional get options" do it "defaults to using etags and last modified" do - @resource.use_etags.should be_true - @resource.use_last_modified.should be_true + expect(@resource.use_etags).to be_true + expect(@resource.use_last_modified).to be_true end it "enable or disables etag and last modified options as a group" do @resource.use_conditional_get(false) - @resource.use_etags.should be_false - @resource.use_last_modified.should be_false + expect(@resource.use_etags).to be_false + expect(@resource.use_last_modified).to be_false @resource.use_conditional_get(true) - @resource.use_etags.should be_true - @resource.use_last_modified.should be_true + expect(@resource.use_etags).to be_true + expect(@resource.use_last_modified).to be_true end it "disables etags indivdually" do @resource.use_etags(false) - @resource.use_etags.should be_false - @resource.use_last_modified.should be_true + expect(@resource.use_etags).to be_false + expect(@resource.use_last_modified).to be_true end it "disables last modified individually" do @resource.use_last_modified(false) - @resource.use_last_modified.should be_false - @resource.use_etags.should be_true + expect(@resource.use_last_modified).to be_false + expect(@resource.use_etags).to be_true end end @@ -171,21 +171,21 @@ describe Chef::Resource::RemoteFile do state = @resource.state if Chef::Platform.windows? puts state - state[:rights].should == [{:permissions => :read, :principals => "Everyone"}] - state[:deny_rights].should == [{:permissions => :full_control, :principals => "Clumsy_Sam"}] + expect(state[:rights]).to eq([{:permissions => :read, :principals => "Everyone"}]) + expect(state[:deny_rights]).to eq([{:permissions => :full_control, :principals => "Clumsy_Sam"}]) else - state[:group].should == "pokemon" - state[:mode].should == "0664" - state[:owner].should == "root" - state[:checksum].should == "1"*26 + expect(state[:group]).to eq("pokemon") + expect(state[:mode]).to eq("0664") + expect(state[:owner]).to eq("root") + expect(state[:checksum]).to eq("1"*26) end end it "returns the path as its identity" do if Chef::Platform.windows? - @resource.identity.should == "C:/temp/origin/file.txt" + expect(@resource.identity).to eq("C:/temp/origin/file.txt") else - @resource.identity.should == "/this/path/" + expect(@resource.identity).to eq("/this/path/") end end end diff --git a/spec/unit/resource/route_spec.rb b/spec/unit/resource/route_spec.rb index 4522438402..ec1d369932 100644 --- a/spec/unit/resource/route_spec.rb +++ b/spec/unit/resource/route_spec.rb @@ -26,64 +26,64 @@ describe Chef::Resource::Route do end it "should create a new Chef::Resource::Route" do - @resource.should be_a_kind_of(Chef::Resource) - @resource.should be_a_kind_of(Chef::Resource::Route) + expect(@resource).to be_a_kind_of(Chef::Resource) + expect(@resource).to be_a_kind_of(Chef::Resource::Route) end it "should have a name" do - @resource.name.should eql("10.0.0.10") + expect(@resource.name).to eql("10.0.0.10") end it "should have a default action of 'add'" do - @resource.action.should eql([:add]) + expect(@resource.action).to eql([:add]) end it "should accept add or delete for action" do - lambda { @resource.action :add }.should_not raise_error - lambda { @resource.action :delete }.should_not raise_error - lambda { @resource.action :lolcat }.should raise_error(ArgumentError) + expect { @resource.action :add }.not_to raise_error + expect { @resource.action :delete }.not_to raise_error + expect { @resource.action :lolcat }.to raise_error(ArgumentError) end it "should use the object name as the target by default" do - @resource.target.should eql("10.0.0.10") + expect(@resource.target).to eql("10.0.0.10") end it "should allow you to specify the netmask" do @resource.netmask "255.255.255.0" - @resource.netmask.should eql("255.255.255.0") + expect(@resource.netmask).to eql("255.255.255.0") end it "should allow you to specify the gateway" do @resource.gateway "10.0.0.1" - @resource.gateway.should eql("10.0.0.1") + expect(@resource.gateway).to eql("10.0.0.1") end it "should allow you to specify the metric" do @resource.metric 10 - @resource.metric.should eql(10) + expect(@resource.metric).to eql(10) end it "should allow you to specify the device" do @resource.device "eth0" - @resource.device.should eql("eth0") + expect(@resource.device).to eql("eth0") end it "should allow you to specify the route type" do @resource.route_type "host" - @resource.route_type.should eql(:host) + expect(@resource.route_type).to eql(:host) end it "should default to a host route type" do - @resource.route_type.should eql(:host) + expect(@resource.route_type).to eql(:host) end it "should accept a net route type" do @resource.route_type :net - @resource.route_type.should eql(:net) + expect(@resource.route_type).to eql(:net) end it "should reject any other route_type but :host and :net" do - lambda { @resource.route_type "lolcat" }.should raise_error(ArgumentError) + expect { @resource.route_type "lolcat" }.to raise_error(ArgumentError) end describe "when it has netmask, gateway, and device" do @@ -96,12 +96,12 @@ describe Chef::Resource::Route do it "describes its state" do state = @resource.state - state[:netmask].should == "lemask" - state[:gateway].should == "111.111.111" + expect(state[:netmask]).to eq("lemask") + expect(state[:gateway]).to eq("111.111.111") end it "returns the target as its identity" do - @resource.identity.should == "charmander" + expect(@resource.identity).to eq("charmander") end end end diff --git a/spec/unit/resource/ruby_block_spec.rb b/spec/unit/resource/ruby_block_spec.rb index 82bbd1ffc7..9f19fecd4f 100644 --- a/spec/unit/resource/ruby_block_spec.rb +++ b/spec/unit/resource/ruby_block_spec.rb @@ -26,27 +26,27 @@ describe Chef::Resource::RubyBlock do end it "should create a new Chef::Resource::RubyBlock" do - @resource.should be_a_kind_of(Chef::Resource) - @resource.should be_a_kind_of(Chef::Resource::RubyBlock) + expect(@resource).to be_a_kind_of(Chef::Resource) + expect(@resource).to be_a_kind_of(Chef::Resource::RubyBlock) end it "should have a default action of 'create'" do - @resource.action.should eql("run") + expect(@resource.action).to eql("run") end it "should have a resource name of :ruby_block" do - @resource.resource_name.should eql(:ruby_block) + expect(@resource.resource_name).to eql(:ruby_block) end it "should accept a ruby block/proc/.. for the 'block' parameter" do - @resource.block do + expect(@resource.block do "foo" - end.call.should eql("foo") + end.call).to eql("foo") end it "allows the action to be 'create'" do @resource.action :create - @resource.action.should == [:create] + expect(@resource.action).to eq([:create]) end describe "when it has been initialized with block code" do @@ -55,7 +55,7 @@ describe Chef::Resource::RubyBlock do end it "returns the block as its identity" do - @resource.identity.should == "puts 'harrrr'" + expect(@resource.identity).to eq("puts 'harrrr'") end end end diff --git a/spec/unit/resource/ruby_spec.rb b/spec/unit/resource/ruby_spec.rb index 9bf7316e6d..e899810ab9 100644 --- a/spec/unit/resource/ruby_spec.rb +++ b/spec/unit/resource/ruby_spec.rb @@ -25,16 +25,16 @@ describe Chef::Resource::Ruby do end it "should create a new Chef::Resource::Ruby" do - @resource.should be_a_kind_of(Chef::Resource) - @resource.should be_a_kind_of(Chef::Resource::Ruby) + expect(@resource).to be_a_kind_of(Chef::Resource) + expect(@resource).to be_a_kind_of(Chef::Resource::Ruby) end it "should have a resource name of :ruby" do - @resource.resource_name.should eql(:ruby) + expect(@resource.resource_name).to eql(:ruby) end it "should have an interpreter of ruby" do - @resource.interpreter.should eql("ruby") + expect(@resource.interpreter).to eql("ruby") end end diff --git a/spec/unit/resource/scm_spec.rb b/spec/unit/resource/scm_spec.rb index eeb2fb1c3c..daabdd03ba 100644 --- a/spec/unit/resource/scm_spec.rb +++ b/spec/unit/resource/scm_spec.rb @@ -26,141 +26,141 @@ describe Chef::Resource::Scm do end it "should be a SCM resource" do - @resource.should be_a_kind_of(Chef::Resource::Scm) + expect(@resource).to be_a_kind_of(Chef::Resource::Scm) end it "supports :checkout, :export, :sync, :diff, and :log actions" do - @resource.allowed_actions.should include(:checkout) - @resource.allowed_actions.should include(:export) - @resource.allowed_actions.should include(:sync) - @resource.allowed_actions.should include(:diff) - @resource.allowed_actions.should include(:log) + expect(@resource.allowed_actions).to include(:checkout) + expect(@resource.allowed_actions).to include(:export) + expect(@resource.allowed_actions).to include(:sync) + expect(@resource.allowed_actions).to include(:diff) + expect(@resource.allowed_actions).to include(:log) end it "takes the destination path as a string" do @resource.destination "/path/to/deploy/dir" - @resource.destination.should eql("/path/to/deploy/dir") + expect(@resource.destination).to eql("/path/to/deploy/dir") end it "takes a string for the repository URL" do @resource.repository "git://github.com/opscode/chef.git" - @resource.repository.should eql("git://github.com/opscode/chef.git") + expect(@resource.repository).to eql("git://github.com/opscode/chef.git") end it "takes a string for the revision" do @resource.revision "abcdef" - @resource.revision.should eql("abcdef") + expect(@resource.revision).to eql("abcdef") end it "defaults to the ``HEAD'' revision" do - @resource.revision.should eql("HEAD") + expect(@resource.revision).to eql("HEAD") end it "takes a string for the user to run as" do @resource.user "dr_deploy" - @resource.user.should eql("dr_deploy") + expect(@resource.user).to eql("dr_deploy") end it "also takes an integer for the user to run as" do @resource.user 0 - @resource.user.should eql(0) + expect(@resource.user).to eql(0) end it "takes a string for the group to run as, defaulting to nil" do - @resource.group.should be_nil + expect(@resource.group).to be_nil @resource.group "opsdevs" - @resource.group.should == "opsdevs" + expect(@resource.group).to eq("opsdevs") end it "also takes an integer for the group to run as" do @resource.group 23 - @resource.group.should == 23 + expect(@resource.group).to eq(23) end it "has a svn_username String attribute" do @resource.svn_username "moartestsplz" - @resource.svn_username.should eql("moartestsplz") + expect(@resource.svn_username).to eql("moartestsplz") end it "has a svn_password String attribute" do @resource.svn_password "taftplz" - @resource.svn_password.should eql("taftplz") + expect(@resource.svn_password).to eql("taftplz") end it "has a svn_arguments String attribute" do @resource.svn_arguments "--more-taft plz" - @resource.svn_arguments.should eql("--more-taft plz") + expect(@resource.svn_arguments).to eql("--more-taft plz") end it "has a svn_info_args String attribute" do - @resource.svn_info_args.should be_nil + expect(@resource.svn_info_args).to be_nil @resource.svn_info_args("--no-moar-plaintext-creds yep") - @resource.svn_info_args.should == "--no-moar-plaintext-creds yep" + expect(@resource.svn_info_args).to eq("--no-moar-plaintext-creds yep") end it "takes the depth as an integer for shallow clones" do @resource.depth 5 - @resource.depth.should == 5 - lambda {@resource.depth "five"}.should raise_error(ArgumentError) + expect(@resource.depth).to eq(5) + expect {@resource.depth "five"}.to raise_error(ArgumentError) end it "defaults to nil depth for a full clone" do - @resource.depth.should be_nil + expect(@resource.depth).to be_nil end it "takes a boolean for #enable_submodules" do @resource.enable_submodules true - @resource.enable_submodules.should be_true - lambda {@resource.enable_submodules "lolz"}.should raise_error(ArgumentError) + expect(@resource.enable_submodules).to be_true + expect {@resource.enable_submodules "lolz"}.to raise_error(ArgumentError) end it "defaults to not enabling submodules" do - @resource.enable_submodules.should be_false + expect(@resource.enable_submodules).to be_false end it "takes a boolean for #enable_checkout" do @resource.enable_checkout true - @resource.enable_checkout.should be_true - lambda {@resource.enable_checkout "lolz"}.should raise_error(ArgumentError) + expect(@resource.enable_checkout).to be_true + expect {@resource.enable_checkout "lolz"}.to raise_error(ArgumentError) end it "defaults to enabling checkout" do - @resource.enable_checkout.should be_true + expect(@resource.enable_checkout).to be_true end it "takes a string for the remote" do @resource.remote "opscode" - @resource.remote.should eql("opscode") - lambda {@resource.remote 1337}.should raise_error(ArgumentError) + expect(@resource.remote).to eql("opscode") + expect {@resource.remote 1337}.to raise_error(ArgumentError) end it "defaults to ``origin'' for the remote" do - @resource.remote.should == "origin" + expect(@resource.remote).to eq("origin") end it "takes a string for the ssh wrapper" do @resource.ssh_wrapper "with_ssh_fu" - @resource.ssh_wrapper.should eql("with_ssh_fu") + expect(@resource.ssh_wrapper).to eql("with_ssh_fu") end it "defaults to nil for the ssh wrapper" do - @resource.ssh_wrapper.should be_nil + expect(@resource.ssh_wrapper).to be_nil end it "defaults to nil for the environment" do - @resource.environment.should be_nil + expect(@resource.environment).to be_nil end describe "when it has a timeout attribute" do let(:ten_seconds) { 10 } before { @resource.timeout(ten_seconds) } it "stores this timeout" do - @resource.timeout.should == ten_seconds + expect(@resource.timeout).to eq(ten_seconds) end end describe "when it has no timeout attribute" do it "should have no default timeout" do - @resource.timeout.should be_nil + expect(@resource.timeout).to be_nil end end @@ -175,11 +175,11 @@ describe Chef::Resource::Scm do it "describes its state" do state = @resource.state - state[:revision].should == "1.2.3" + expect(state[:revision]).to eq("1.2.3") end it "returns the destination as its identity" do - @resource.identity.should == "hell" + expect(@resource.identity).to eq("hell") end end @@ -187,7 +187,7 @@ describe Chef::Resource::Scm do let(:test_environment) { {'CHEF_ENV' => '/tmp' } } before { @resource.environment(test_environment) } it "stores this environment" do - @resource.environment.should == test_environment + expect(@resource.environment).to eq(test_environment) end end end diff --git a/spec/unit/resource/script_spec.rb b/spec/unit/resource/script_spec.rb index f100b0dc85..9d744baaa5 100644 --- a/spec/unit/resource/script_spec.rb +++ b/spec/unit/resource/script_spec.rb @@ -26,7 +26,7 @@ describe Chef::Resource::Script do it "should accept a string for the interpreter" do script_resource.interpreter "naaaaNaNaNaaNaaNaaNaa" - script_resource.interpreter.should eql("naaaaNaNaNaaNaaNaaNaa") + expect(script_resource.interpreter).to eql("naaaaNaNaNaaNaaNaaNaa") end describe "when it has interpreter and flags" do @@ -37,7 +37,7 @@ describe Chef::Resource::Script do end it "returns the command as its identity" do - script_resource.identity.should == "grep" + expect(script_resource.identity).to eq("grep") end end diff --git a/spec/unit/resource/service_spec.rb b/spec/unit/resource/service_spec.rb index 9b779e5830..eb6f444e93 100644 --- a/spec/unit/resource/service_spec.rb +++ b/spec/unit/resource/service_spec.rb @@ -26,135 +26,135 @@ describe Chef::Resource::Service do end it "should create a new Chef::Resource::Service" do - @resource.should be_a_kind_of(Chef::Resource) - @resource.should be_a_kind_of(Chef::Resource::Service) + expect(@resource).to be_a_kind_of(Chef::Resource) + expect(@resource).to be_a_kind_of(Chef::Resource::Service) end it "should not set a provider unless node[:init_package] is defined as systemd" do - @resource.provider.should == nil + expect(@resource.provider).to eq(nil) end it "should set the service_name to the first argument to new" do - @resource.service_name.should eql("chef") + expect(@resource.service_name).to eql("chef") end it "should set the pattern to be the service name by default" do - @resource.pattern.should eql("chef") + expect(@resource.pattern).to eql("chef") end it "should accept a string for the service name" do @resource.service_name "something" - @resource.service_name.should eql("something") + expect(@resource.service_name).to eql("something") end it "should accept a string for the service pattern" do @resource.pattern ".*" - @resource.pattern.should eql(".*") + expect(@resource.pattern).to eql(".*") end it "should not accept a regexp for the service pattern" do - lambda { + expect { @resource.pattern /.*/ - }.should raise_error(ArgumentError) + }.to raise_error(ArgumentError) end it "should accept a string for the service start command" do @resource.start_command "/etc/init.d/chef start" - @resource.start_command.should eql("/etc/init.d/chef start") + expect(@resource.start_command).to eql("/etc/init.d/chef start") end it "should not accept a regexp for the service start command" do - lambda { + expect { @resource.start_command /.*/ - }.should raise_error(ArgumentError) + }.to raise_error(ArgumentError) end it "should accept a string for the service stop command" do @resource.stop_command "/etc/init.d/chef stop" - @resource.stop_command.should eql("/etc/init.d/chef stop") + expect(@resource.stop_command).to eql("/etc/init.d/chef stop") end it "should not accept a regexp for the service stop command" do - lambda { + expect { @resource.stop_command /.*/ - }.should raise_error(ArgumentError) + }.to raise_error(ArgumentError) end it "should accept a string for the service status command" do @resource.status_command "/etc/init.d/chef status" - @resource.status_command.should eql("/etc/init.d/chef status") + expect(@resource.status_command).to eql("/etc/init.d/chef status") end it "should not accept a regexp for the service status command" do - lambda { + expect { @resource.status_command /.*/ - }.should raise_error(ArgumentError) + }.to raise_error(ArgumentError) end it "should accept a string for the service restart command" do @resource.restart_command "/etc/init.d/chef restart" - @resource.restart_command.should eql("/etc/init.d/chef restart") + expect(@resource.restart_command).to eql("/etc/init.d/chef restart") end it "should not accept a regexp for the service restart command" do - lambda { + expect { @resource.restart_command /.*/ - }.should raise_error(ArgumentError) + }.to raise_error(ArgumentError) end it "should accept a string for the service reload command" do @resource.reload_command "/etc/init.d/chef reload" - @resource.reload_command.should eql("/etc/init.d/chef reload") + expect(@resource.reload_command).to eql("/etc/init.d/chef reload") end it "should not accept a regexp for the service reload command" do - lambda { + expect { @resource.reload_command /.*/ - }.should raise_error(ArgumentError) + }.to raise_error(ArgumentError) end it "should accept a string for the service init command" do @resource.init_command "/etc/init.d/chef" - @resource.init_command.should eql("/etc/init.d/chef") + expect(@resource.init_command).to eql("/etc/init.d/chef") end it "should not accept a regexp for the service init command" do - lambda { + expect { @resource.init_command /.*/ - }.should raise_error(ArgumentError) + }.to raise_error(ArgumentError) end %w{enabled running}.each do |attrib| it "should accept true for #{attrib}" do @resource.send(attrib, true) - @resource.send(attrib).should eql(true) + expect(@resource.send(attrib)).to eql(true) end it "should accept false for #{attrib}" do @resource.send(attrib, false) - @resource.send(attrib).should eql(false) + expect(@resource.send(attrib)).to eql(false) end it "should not accept a string for #{attrib}" do - lambda { @resource.send(attrib, "poop") }.should raise_error(ArgumentError) + expect { @resource.send(attrib, "poop") }.to raise_error(ArgumentError) end it "should default all the feature support to false" do support_hash = { :status => false, :restart => false, :reload=> false } - @resource.supports.should == support_hash + expect(@resource.supports).to eq(support_hash) end it "should allow you to set what features this resource supports as a array" do support_array = [ :status, :restart ] support_hash = { :status => true, :restart => true, :reload => false } @resource.supports(support_array) - @resource.supports.should == support_hash + expect(@resource.supports).to eq(support_hash) end it "should allow you to set what features this resource supports as a hash" do support_hash = { :status => true, :restart => true, :reload => false } @resource.supports(support_hash) - @resource.supports.should == support_hash + expect(@resource.supports).to eq(support_hash) end end @@ -167,12 +167,12 @@ describe Chef::Resource::Service do it "describes its state" do state = @resource.state - state[:enabled].should eql(true) - state[:running].should eql(false) + expect(state[:enabled]).to eql(true) + expect(state[:running]).to eql(false) end it "returns the service name as its identity" do - @resource.identity.should == "superfriend" + expect(@resource.identity).to eq("superfriend") end end diff --git a/spec/unit/resource/solaris_package_spec.rb b/spec/unit/resource/solaris_package_spec.rb index ab4e03807d..f5d3e669a1 100644 --- a/spec/unit/resource/solaris_package_spec.rb +++ b/spec/unit/resource/solaris_package_spec.rb @@ -37,6 +37,6 @@ describe Chef::Resource::SolarisPackage, "initialize" do end it "should set the package_name to the name provided" do - @resource.package_name.should eql("foo") + expect(@resource.package_name).to eql("foo") end end diff --git a/spec/unit/resource/subversion_spec.rb b/spec/unit/resource/subversion_spec.rb index a52d8421c6..4cbca9be11 100644 --- a/spec/unit/resource/subversion_spec.rb +++ b/spec/unit/resource/subversion_spec.rb @@ -33,35 +33,35 @@ describe Chef::Resource::Subversion do end it "is a subclass of Resource::Scm" do - @svn.should be_an_instance_of(Chef::Resource::Subversion) - @svn.should be_a_kind_of(Chef::Resource::Scm) + expect(@svn).to be_an_instance_of(Chef::Resource::Subversion) + expect(@svn).to be_a_kind_of(Chef::Resource::Scm) end it "allows the force_export action" do - @svn.allowed_actions.should include(:force_export) + expect(@svn.allowed_actions).to include(:force_export) end it "sets svn info arguments to --no-auth-cache by default" do - @svn.svn_info_args.should == '--no-auth-cache' + expect(@svn.svn_info_args).to eq('--no-auth-cache') end it "resets svn info arguments to nil when given false in the setter" do @svn.svn_info_args(false) - @svn.svn_info_args.should be_nil + expect(@svn.svn_info_args).to be_nil end it "sets svn arguments to --no-auth-cache by default" do - @svn.svn_arguments.should == '--no-auth-cache' + expect(@svn.svn_arguments).to eq('--no-auth-cache') end it "resets svn arguments to nil when given false in the setter" do @svn.svn_arguments(false) - @svn.svn_arguments.should be_nil + expect(@svn.svn_arguments).to be_nil end it "hides password from custom exception message" do @svn.svn_password "l33th4x0rpa$$w0rd" e = @svn.customize_exception(Chef::Exceptions::Exec.new "Exception with password #{@svn.svn_password}") - e.message.include?(@svn.svn_password).should be_false + expect(e.message.include?(@svn.svn_password)).to be_false end end diff --git a/spec/unit/resource/template_spec.rb b/spec/unit/resource/template_spec.rb index c9dfdc7014..df5ca94b8a 100644 --- a/spec/unit/resource/template_spec.rb +++ b/spec/unit/resource/template_spec.rb @@ -26,54 +26,54 @@ describe Chef::Resource::Template do describe "initialize" do it "should create a new Chef::Resource::Template" do - @resource.should be_a_kind_of(Chef::Resource) - @resource.should be_a_kind_of(Chef::Resource::File) - @resource.should be_a_kind_of(Chef::Resource::Template) + expect(@resource).to be_a_kind_of(Chef::Resource) + expect(@resource).to be_a_kind_of(Chef::Resource::File) + expect(@resource).to be_a_kind_of(Chef::Resource::Template) end end describe "source" do it "should accept a string for the template source" do @resource.source "something" - @resource.source.should eql("something") + expect(@resource.source).to eql("something") end it "should have a default based on the param name with .erb appended" do - @resource.source.should eql("fakey_fakerton.erb") + expect(@resource.source).to eql("fakey_fakerton.erb") end it "should use only the basename of the file as the default" do r = Chef::Resource::Template.new("/tmp/obit/fakey_fakerton") - r.source.should eql("fakey_fakerton.erb") + expect(r.source).to eql("fakey_fakerton.erb") end end describe "variables" do it "should accept a hash for the variable list" do @resource.variables({ :reluctance => :awkward }) - @resource.variables.should == { :reluctance => :awkward } + expect(@resource.variables).to eq({ :reluctance => :awkward }) end end describe "cookbook" do it "should accept a string for the cookbook name" do @resource.cookbook("foo") - @resource.cookbook.should == "foo" + expect(@resource.cookbook).to eq("foo") end it "should default to nil" do - @resource.cookbook.should == nil + expect(@resource.cookbook).to eq(nil) end end describe "local" do it "should accept a boolean for whether a template is local or remote" do @resource.local(true) - @resource.local.should == true + expect(@resource.local).to eq(true) end it "should default to false" do - @resource.local.should == false + expect(@resource.local).to eq(false) end end @@ -89,10 +89,10 @@ describe Chef::Resource::Template do context "on unix", :unix_only do it "describes its state" do state = @resource.state - state[:owner].should == "root" - state[:group].should == "wheel" - state[:mode].should == "0644" - state[:checksum].should == "1" * 64 + expect(state[:owner]).to eq("root") + expect(state[:group]).to eq("wheel") + expect(state[:mode]).to eq("0644") + expect(state[:checksum]).to eq("1" * 64) end end @@ -102,7 +102,7 @@ describe Chef::Resource::Template do end it "returns the file path as its identity" do - @resource.identity.should == "/tmp/foo.txt" + expect(@resource.identity).to eq("/tmp/foo.txt") end end @@ -117,19 +117,19 @@ describe Chef::Resource::Template do it "collects helper method bodies as blocks" do @resource.helper(:example_1) { "example_1" } @resource.helper(:example_2) { "example_2" } - @resource.inline_helper_blocks[:example_1].call.should == "example_1" - @resource.inline_helper_blocks[:example_2].call.should == "example_2" + expect(@resource.inline_helper_blocks[:example_1].call).to eq("example_1") + expect(@resource.inline_helper_blocks[:example_2].call).to eq("example_2") end it "compiles helper methods into a module" do @resource.helper(:example_1) { "example_1" } @resource.helper(:example_2) { "example_2" } modules = @resource.helper_modules - modules.should have(1).module + expect(modules.size).to eq(1) o = Object.new modules.each {|m| o.extend(m)} - o.example_1.should == "example_1" - o.example_2.should == "example_2" + expect(o.example_1).to eq("example_1") + expect(o.example_2).to eq("example_2") end it "compiles helper methods with arguments into a module" do @@ -137,15 +137,15 @@ describe Chef::Resource::Template do modules = @resource.helper_modules o = Object.new modules.each {|m| o.extend(m)} - o.shout("shout").should == "SHOUT" + expect(o.shout("shout")).to eq("SHOUT") end it "raises an error when attempting to define a helper method without a method body" do - lambda { @resource.helper(:example) }.should raise_error(Chef::Exceptions::ValidationFailed) + expect { @resource.helper(:example) }.to raise_error(Chef::Exceptions::ValidationFailed) end it "raises an error when attempting to define a helper method with a non-Symbod method name" do - lambda { @resource.helper("example") { "fail" } }.should raise_error(Chef::Exceptions::ValidationFailed) + expect { @resource.helper("example") { "fail" } }.to raise_error(Chef::Exceptions::ValidationFailed) end it "collects helper module bodies as blocks" do @@ -155,7 +155,7 @@ describe Chef::Resource::Template do end end module_body = @resource.inline_helper_modules.first - module_body.should be_a(Proc) + expect(module_body).to be_a(Proc) end it "compiles helper module bodies into modules" do @@ -165,27 +165,27 @@ describe Chef::Resource::Template do end end modules = @resource.helper_modules - modules.should have(1).module + expect(modules.size).to eq(1) o = Object.new modules.each {|m| o.extend(m)} - o.example_1.should == "example_1" + expect(o.example_1).to eq("example_1") end it "raises an error when no block or module name is given for helpers definition" do - lambda { @resource.helpers() }.should raise_error(Chef::Exceptions::ValidationFailed) + expect { @resource.helpers() }.to raise_error(Chef::Exceptions::ValidationFailed) end it "raises an error when a non-module is given for helpers definition" do - lambda { @resource.helpers("NotAModule") }.should raise_error(Chef::Exceptions::ValidationFailed) + expect { @resource.helpers("NotAModule") }.to raise_error(Chef::Exceptions::ValidationFailed) end it "raises an error when a module name and block are both given for helpers definition" do - lambda { @resource.helpers(ExampleHelpers) { module_code } }.should raise_error(Chef::Exceptions::ValidationFailed) + expect { @resource.helpers(ExampleHelpers) { module_code } }.to raise_error(Chef::Exceptions::ValidationFailed) end it "collects helper modules" do @resource.helpers(ExampleHelpers) - @resource.helper_modules.should include(ExampleHelpers) + expect(@resource.helper_modules).to include(ExampleHelpers) end it "combines all helpers into a set of compiled modules" do @@ -196,13 +196,13 @@ describe Chef::Resource::Template do end end @resource.helper(:inline_method) { "inline_method" } - @resource.should have(3).helper_modules + expect(@resource.helper_modules.size).to eq(3) o = Object.new @resource.helper_modules.each {|m| o.extend(m)} - o.static_example.should == "static_example" - o.inline_module.should == "inline_module" - o.inline_method.should == "inline_method" + expect(o.static_example).to eq("static_example") + expect(o.inline_module).to eq("inline_module") + expect(o.inline_method).to eq("inline_method") end diff --git a/spec/unit/resource/user_spec.rb b/spec/unit/resource/user_spec.rb index 70b866202b..f05de94fe0 100644 --- a/spec/unit/resource/user_spec.rb +++ b/spec/unit/resource/user_spec.rb @@ -24,51 +24,51 @@ describe Chef::Resource::User, "initialize" do end it "should create a new Chef::Resource::User" do - @resource.should be_a_kind_of(Chef::Resource) - @resource.should be_a_kind_of(Chef::Resource::User) + expect(@resource).to be_a_kind_of(Chef::Resource) + expect(@resource).to be_a_kind_of(Chef::Resource::User) end it "should set the resource_name to :user" do - @resource.resource_name.should eql(:user) + expect(@resource.resource_name).to eql(:user) end it "should set the username equal to the argument to initialize" do - @resource.username.should eql("adam") + expect(@resource.username).to eql("adam") end %w{comment uid gid home shell password}.each do |attrib| it "should set #{attrib} to nil" do - @resource.send(attrib).should eql(nil) + expect(@resource.send(attrib)).to eql(nil) end end it "should set action to :create" do - @resource.action.should eql(:create) + expect(@resource.action).to eql(:create) end it "should set supports[:manage_home] to false" do - @resource.supports[:manage_home].should eql(false) + expect(@resource.supports[:manage_home]).to eql(false) end it "should set supports[:non_unique] to false" do - @resource.supports[:non_unique].should eql(false) + expect(@resource.supports[:non_unique]).to eql(false) end it "should set force to false" do - @resource.force.should eql(false) + expect(@resource.force).to eql(false) end %w{create remove modify manage lock unlock}.each do |action| it "should allow action #{action}" do - @resource.allowed_actions.detect { |a| a == action.to_sym }.should eql(action.to_sym) + expect(@resource.allowed_actions.detect { |a| a == action.to_sym }).to eql(action.to_sym) end end it "should accept domain users (@ or \ separator) on non-windows" do - lambda { @resource.username "domain\@user" }.should_not raise_error - @resource.username.should == "domain\@user" - lambda { @resource.username "domain\\user" }.should_not raise_error - @resource.username.should == "domain\\user" + expect { @resource.username "domain\@user" }.not_to raise_error + expect(@resource.username).to eq("domain\@user") + expect { @resource.username "domain\\user" }.not_to raise_error + expect(@resource.username).to eq("domain\\user") end end @@ -80,11 +80,11 @@ end it "should allow a string" do @resource.send(attrib, "adam") - @resource.send(attrib).should eql("adam") + expect(@resource.send(attrib)).to eql("adam") end it "should not allow a hash" do - lambda { @resource.send(attrib, { :woot => "i found it" }) }.should raise_error(ArgumentError) + expect { @resource.send(attrib, { :woot => "i found it" }) }.to raise_error(ArgumentError) end end end @@ -97,16 +97,16 @@ end it "should allow a string" do @resource.send(attrib, "100") - @resource.send(attrib).should eql("100") + expect(@resource.send(attrib)).to eql("100") end it "should allow an integer" do @resource.send(attrib, 100) - @resource.send(attrib).should eql(100) + expect(@resource.send(attrib)).to eql(100) end it "should not allow a hash" do - lambda { @resource.send(attrib, { :woot => "i found it" }) }.should raise_error(ArgumentError) + expect { @resource.send(attrib, { :woot => "i found it" }) }.to raise_error(ArgumentError) end end @@ -120,13 +120,13 @@ end it "describes its state" do state = @resource.state - state[:uid].should == 123 - state[:gid].should == 456 - state[:home].should == "/usr/local/root/" + expect(state[:uid]).to eq(123) + expect(state[:gid]).to eq(456) + expect(state[:home]).to eq("/usr/local/root/") end it "returns the username as its identity" do - @resource.identity.should == "root" + expect(@resource.identity).to eq("root") end end diff --git a/spec/unit/resource/windows_package_spec.rb b/spec/unit/resource/windows_package_spec.rb index c9ef8d910c..3c45548ece 100644 --- a/spec/unit/resource/windows_package_spec.rb +++ b/spec/unit/resource/windows_package_spec.rb @@ -56,13 +56,13 @@ describe Chef::Resource::WindowsPackage, "initialize", :windows_only do end it "coverts a source to an absolute path" do - ::File.stub(:absolute_path).and_return("c:\\Files\\frost.msi") + allow(::File).to receive(:absolute_path).and_return("c:\\Files\\frost.msi") resource.source("frost.msi") expect(resource.source).to eql "c:\\Files\\frost.msi" end it "converts slashes to backslashes in the source path" do - ::File.stub(:absolute_path).and_return("c:\\frost.msi") + allow(::File).to receive(:absolute_path).and_return("c:\\frost.msi") resource.source("c:/frost.msi") expect(resource.source).to eql "c:\\frost.msi" end diff --git a/spec/unit/resource/windows_service_spec.rb b/spec/unit/resource/windows_service_spec.rb index c92c3be1b0..fd7bedec9f 100644 --- a/spec/unit/resource/windows_service_spec.rb +++ b/spec/unit/resource/windows_service_spec.rb @@ -41,6 +41,6 @@ describe Chef::Resource::WindowsService, "initialize", :windows_only do it "allows the action to be 'configure_startup'" do resource.action :configure_startup - resource.action.should == [:configure_startup] + expect(resource.action).to eq([:configure_startup]) end end diff --git a/spec/unit/resource/yum_package_spec.rb b/spec/unit/resource/yum_package_spec.rb index 7e1979fdfd..e01b87c580 100644 --- a/spec/unit/resource/yum_package_spec.rb +++ b/spec/unit/resource/yum_package_spec.rb @@ -39,7 +39,7 @@ describe Chef::Resource::YumPackage, "arch" do it "should set the arch variable to whatever is passed in" do @resource.arch("i386") - @resource.arch.should eql("i386") + expect(@resource.arch).to eql("i386") end end @@ -50,20 +50,20 @@ describe Chef::Resource::YumPackage, "flush_cache" do it "should default the flush timing to false" do flush_hash = { :before => false, :after => false } - @resource.flush_cache.should == flush_hash + expect(@resource.flush_cache).to eq(flush_hash) end it "should allow you to set the flush timing with an array" do flush_array = [ :before, :after ] flush_hash = { :before => true, :after => true } @resource.flush_cache(flush_array) - @resource.flush_cache.should == flush_hash + expect(@resource.flush_cache).to eq(flush_hash) end it "should allow you to set the flush timing with a hash" do flush_hash = { :before => true, :after => true } @resource.flush_cache(flush_hash) - @resource.flush_cache.should == flush_hash + expect(@resource.flush_cache).to eq(flush_hash) end end @@ -73,8 +73,8 @@ describe Chef::Resource::YumPackage, "allow_downgrade" do end it "should allow you to specify whether allow_downgrade is true or false" do - lambda { @resource.allow_downgrade true }.should_not raise_error - lambda { @resource.allow_downgrade false }.should_not raise_error - lambda { @resource.allow_downgrade "monkey" }.should raise_error(ArgumentError) + expect { @resource.allow_downgrade true }.not_to raise_error + expect { @resource.allow_downgrade false }.not_to raise_error + expect { @resource.allow_downgrade "monkey" }.to raise_error(ArgumentError) end end |