diff options
Diffstat (limited to 'spec/unit/knife/cookbook_site_download_spec.rb')
-rw-r--r-- | spec/unit/knife/cookbook_site_download_spec.rb | 50 |
1 files changed, 25 insertions, 25 deletions
diff --git a/spec/unit/knife/cookbook_site_download_spec.rb b/spec/unit/knife/cookbook_site_download_spec.rb index 76ce6508d7..6676fb34a1 100644 --- a/spec/unit/knife/cookbook_site_download_spec.rb +++ b/spec/unit/knife/cookbook_site_download_spec.rb @@ -33,9 +33,9 @@ describe Chef::Knife::CookbookSiteDownload do 'latest_version' => "#{@cookbook_api_url}/apache2/versions/#{@version_us}", 'replacement' => 'other_apache2' } - @knife.ui.stub(:stderr).and_return(@stderr) - @knife.stub(:noauth_rest).and_return(@noauth_rest) - @noauth_rest.should_receive(:get_rest). + allow(@knife.ui).to receive(:stderr).and_return(@stderr) + allow(@knife).to receive(:noauth_rest).and_return(@noauth_rest) + expect(@noauth_rest).to receive(:get_rest). with("#{@cookbook_api_url}/apache2"). and_return(@current_data) end @@ -46,9 +46,9 @@ describe Chef::Knife::CookbookSiteDownload do end it 'should warn with info about the replacement' do - @knife.ui.should_receive(:warn). + expect(@knife.ui).to receive(:warn). with(/.+deprecated.+replaced by other_apache2.+/i) - @knife.ui.should_receive(:warn). + expect(@knife.ui).to receive(:warn). with(/use --force.+download.+/i) @knife.run end @@ -61,15 +61,15 @@ describe Chef::Knife::CookbookSiteDownload do @temp_file = double( :path => "/tmp/apache2_#{@version_us}.tgz" ) @file = File.join(Dir.pwd, "apache2-#{@version}.tar.gz") - @noauth_rest.should_receive(:sign_on_redirect=).with(false) + expect(@noauth_rest).to receive(:sign_on_redirect=).with(false) end context 'downloading the latest version' do before do - @noauth_rest.should_receive(:get_rest). + expect(@noauth_rest).to receive(:get_rest). with(@current_data['latest_version']). and_return(@cookbook_data) - @noauth_rest.should_receive(:get_rest). + expect(@noauth_rest).to receive(:get_rest). with(@cookbook_data['file'], true). and_return(@temp_file) end @@ -81,40 +81,40 @@ describe Chef::Knife::CookbookSiteDownload do end it 'should download the latest version' do - @knife.ui.should_receive(:warn). + expect(@knife.ui).to receive(:warn). with(/.+deprecated.+replaced by other_apache2.+/i) - FileUtils.should_receive(:cp).with(@temp_file.path, @file) + expect(FileUtils).to receive(:cp).with(@temp_file.path, @file) @knife.run - @stderr.string.should match /downloading apache2.+version.+#{Regexp.escape(@version)}/i - @stderr.string.should match /cookbook save.+#{Regexp.escape(@file)}/i + expect(@stderr.string).to match /downloading apache2.+version.+#{Regexp.escape(@version)}/i + expect(@stderr.string).to match /cookbook save.+#{Regexp.escape(@file)}/i end end it 'should download the latest version' do - FileUtils.should_receive(:cp).with(@temp_file.path, @file) + expect(FileUtils).to receive(:cp).with(@temp_file.path, @file) @knife.run - @stderr.string.should match /downloading apache2.+version.+#{Regexp.escape(@version)}/i - @stderr.string.should match /cookbook save.+#{Regexp.escape(@file)}/i + expect(@stderr.string).to match /downloading apache2.+version.+#{Regexp.escape(@version)}/i + expect(@stderr.string).to match /cookbook save.+#{Regexp.escape(@file)}/i end context 'with -f or --file' do before do @file = '/opt/chef/cookbooks/apache2.tar.gz' @knife.config[:file] = @file - FileUtils.should_receive(:cp).with(@temp_file.path, @file) + expect(FileUtils).to receive(:cp).with(@temp_file.path, @file) end it 'should download the cookbook to the desired file' do @knife.run - @stderr.string.should match /downloading apache2.+version.+#{Regexp.escape(@version)}/i - @stderr.string.should match /cookbook save.+#{Regexp.escape(@file)}/i + expect(@stderr.string).to match /downloading apache2.+version.+#{Regexp.escape(@version)}/i + expect(@stderr.string).to match /cookbook save.+#{Regexp.escape(@file)}/i end end it 'should provide an accessor to the version' do - FileUtils.stub(:cp).and_return(true) - @knife.version.should == @version + allow(FileUtils).to receive(:cp).and_return(true) + expect(@knife.version).to eq(@version) @knife.run end end @@ -131,16 +131,16 @@ describe Chef::Knife::CookbookSiteDownload do end it 'should download the desired version' do - @noauth_rest.should_receive(:get_rest). + expect(@noauth_rest).to receive(:get_rest). with("#{@cookbook_api_url}/apache2/versions/#{@version_us}"). and_return(@cookbook_data) - @noauth_rest.should_receive(:get_rest). + expect(@noauth_rest).to receive(:get_rest). with(@cookbook_data['file'], true). and_return(@temp_file) - FileUtils.should_receive(:cp).with(@temp_file.path, @file) + expect(FileUtils).to receive(:cp).with(@temp_file.path, @file) @knife.run - @stderr.string.should match /downloading apache2.+version.+#{Regexp.escape(@version)}/i - @stderr.string.should match /cookbook save.+#{Regexp.escape(@file)}/i + expect(@stderr.string).to match /downloading apache2.+version.+#{Regexp.escape(@version)}/i + expect(@stderr.string).to match /cookbook save.+#{Regexp.escape(@file)}/i end end |