diff --git a/.puppet-lint.rc b/.puppet-lint.rc index e69de29..cc96ece 100644 --- a/.puppet-lint.rc +++ b/.puppet-lint.rc @@ -0,0 +1 @@ +--relative diff --git a/.sync.yml b/.sync.yml index 22b1dad..b4dd4f5 100644 --- a/.sync.yml +++ b/.sync.yml @@ -1,33 +1,37 @@ --- +.gitlab-ci.yml: + unmanaged: true + .travis.yml: docker_sets: - set: docker/centos-7 - set: docker/ubuntu-14.04 docker_defaults: bundler_args: "" secure: "" branches: - release +appveyor.yml: + delete: true + Gemfile: required: ':system_tests': - gem: 'puppet-module-posix-system-r#{minor_version}' platforms: ruby - gem: 'puppet-module-win-system-r#{minor_version}' platforms: - mswin - mingw - x64_mingw optional: ':development': - gem: 'github_changelog_generator' git: 'https://github.com/skywinder/github-changelog-generator' ref: '20ee04ba1234e9e83eb2ffb5056e23d641c7a018' condition: "Gem::Version.new(RUBY_VERSION.dup) >= Gem::Version.new('2.2.2')" -appveyor.yml: - delete: true - -.gitlab-ci.yml: - unmanaged: true +spec/spec_helper.rb: + mock_with: ':rspec' + coverage_report: true diff --git a/metadata.json b/metadata.json index 890a616..4f99f56 100644 --- a/metadata.json +++ b/metadata.json @@ -1,78 +1,78 @@ { "name": "puppetlabs-vcsrepo", "version": "2.4.0", "author": "puppetlabs", "summary": "Puppet module providing a type to manage repositories from various version control systems", "license": "GPL-2.0+", "source": "https://github.com/puppetlabs/puppetlabs-vcsrepo", "project_page": "https://github.com/puppetlabs/puppetlabs-vcsrepo", "issues_url": "https://tickets.puppetlabs.com/browse/MODULES", "dependencies": [ ], "operatingsystem_support": [ { "operatingsystem": "RedHat", "operatingsystemrelease": [ "5", "6", "7" ] }, { "operatingsystem": "CentOS", "operatingsystemrelease": [ "5", "6", "7" ] }, { "operatingsystem": "OracleLinux", "operatingsystemrelease": [ "5", "6", "7" ] }, { "operatingsystem": "Scientific", "operatingsystemrelease": [ "6", "7" ] }, { "operatingsystem": "SLES", "operatingsystemrelease": [ "11 SP1", "12", "15" ] }, { "operatingsystem": "Debian", "operatingsystemrelease": [ "8", "9" ] }, { "operatingsystem": "Ubuntu", "operatingsystemrelease": [ "14.04", "16.04", "18.04" ] } ], "requirements": [ { "name": "puppet", "version_requirement": ">= 4.7.0 < 7.0.0" } ], "template-url": "https://github.com/puppetlabs/pdk-templates/", - "template-ref": "heads/master-0-g6814a87", - "pdk-version": "1.7.1" -} + "template-ref": "1.9.0-0-g7281db5", + "pdk-version": "1.9.0" +} \ No newline at end of file diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index 35654b3..149ff03 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -1,44 +1,52 @@ +RSpec.configure do |c| + c.mock_with :rspec +end + require 'puppetlabs_spec_helper/module_spec_helper' require 'rspec-puppet-facts' require 'spec_helper_local' if File.file?(File.join(File.dirname(__FILE__), 'spec_helper_local.rb')) include RspecPuppetFacts default_facts = { puppetversion: Puppet.version, facterversion: Facter.version, } default_fact_files = [ File.expand_path(File.join(File.dirname(__FILE__), 'default_facts.yml')), File.expand_path(File.join(File.dirname(__FILE__), 'default_module_facts.yml')), ] default_fact_files.each do |f| next unless File.exist?(f) && File.readable?(f) && File.size?(f) begin default_facts.merge!(YAML.safe_load(File.read(f))) rescue => e RSpec.configuration.reporter.message "WARNING: Unable to load #{f}: #{e}" end end RSpec.configure do |c| c.default_facts = default_facts c.before :each do # set to strictest setting for testing # by default Puppet runs at warning level Puppet.settings[:strict] = :warning end + c.filter_run_excluding(bolt: true) unless ENV['GEM_BOLT'] + c.after(:suite) do + RSpec::Puppet::Coverage.report!(0) + end end def ensure_module_defined(module_name) module_name.split('::').reduce(Object) do |last_module, next_module| last_module.const_set(next_module, Module.new) unless last_module.const_defined?(next_module, false) last_module.const_get(next_module, false) end end # 'spec_overrides' from sync.yml will appear below this line diff --git a/spec/spec_helper_local.rb b/spec/spec_helper_local.rb index c7d27b5..b74c7f3 100644 --- a/spec/spec_helper_local.rb +++ b/spec/spec_helper_local.rb @@ -1,7 +1,36 @@ +if ENV['COVERAGE'] == 'yes' + require 'simplecov' + require 'simplecov-console' + require 'codecov' + + SimpleCov.formatters = [ + SimpleCov::Formatter::HTMLFormatter, + SimpleCov::Formatter::Console, + SimpleCov::Formatter::Codecov, + ] + SimpleCov.start do + track_files 'lib/**/*.rb' + + add_filter '/spec' + + # do not track vendored files + add_filter '/vendor' + add_filter '/.vendor' + + # do not track gitignored files + # this adds about 4 seconds to the coverage check + # this could definitely be optimized + add_filter do |f| + # system returns true if exit status is 0, which with git-check-ignore means file is ignored + system("git check-ignore --quiet #{f.filename}") + end + end +end + require 'support/filesystem_helpers' require 'support/fixture_helpers' RSpec.configure do |c| c.include FilesystemHelpers c.include FixtureHelpers end diff --git a/spec/support/filesystem_helpers.rb b/spec/support/filesystem_helpers.rb index fa1f4bf..d6d6015 100644 --- a/spec/support/filesystem_helpers.rb +++ b/spec/support/filesystem_helpers.rb @@ -1,18 +1,18 @@ # filesystem_helpers.rb module FilesystemHelpers - def expects_chdir(path = resource.value(:path)) - Dir.expects(:chdir).with(path).at_least_once.yields + def expect_chdir(path = resource.value(:path)) + expect(Dir).to receive(:chdir).with(path).at_least(:once).and_yield end - def expects_mkdir(path = resource.value(:path)) - Dir.expects(:mkdir).with(path).at_least_once + def expect_mkdir(path = resource.value(:path)) + expect(Dir).to receive(:mkdir).with(path).once end - def expects_rm_rf(path = resource.value(:path)) - FileUtils.expects(:rm_rf).with(path) + def expect_rm_rf(path = resource.value(:path)) + expect(FileUtils).to receive(:rm_rf).with(path) end - def expects_directory?(returns = true, path = resource.value(:path)) - File.expects(:directory?).with(path).returns(returns) + def expect_directory?(returns = true, path = resource.value(:path)) + expect(File).to receive(:directory?).with(path).and_return(returns) end end diff --git a/spec/unit/facter/vcsrepo_svn_ver_spec.rb b/spec/unit/facter/vcsrepo_svn_ver_spec.rb index 997977d..0b48327 100644 --- a/spec/unit/facter/vcsrepo_svn_ver_spec.rb +++ b/spec/unit/facter/vcsrepo_svn_ver_spec.rb @@ -1,21 +1,21 @@ require 'spec_helper' describe Facter::Util::Fact do # rubocop:disable RSpec/FilePath before(:each) do Facter.clear end describe 'vcsrepo_svn_ver' do context 'with valid value' do before :each do - Facter::Core::Execution - .stubs(:execute) + allow(Facter.fact(:operatingsystem)).to receive(:value).and_return('OpenBSD') + allow(Facter::Core::Execution).to receive(:execute) .with('svn --version --quiet') - .returns('1.7.23') + .and_return('1.7.23') end it { expect(Facter.fact(:vcsrepo_svn_ver).value).to eq('1.7.23') } end end end diff --git a/spec/unit/puppet/provider/vcsrepo/bzr_spec.rb b/spec/unit/puppet/provider/vcsrepo/bzr_spec.rb index 90e3032..23014ff 100644 --- a/spec/unit/puppet/provider/vcsrepo/bzr_spec.rb +++ b/spec/unit/puppet/provider/vcsrepo/bzr_spec.rb @@ -1,121 +1,121 @@ require 'spec_helper' describe Puppet::Type.type(:vcsrepo).provider(:bzr) do let(:resource) do Puppet::Type.type(:vcsrepo).new(name: 'test', ensure: :present, provider: :bzr, revision: '2634', source: 'lp:do', path: '/tmp/test') end let(:provider) { resource.provider } before :each do - Puppet::Util.stubs(:which).with('bzr').returns('/usr/bin/bzr') + allow(Puppet::Util).to receive(:which).with('bzr').and_return('/usr/bin/bzr') end describe 'creating' do context 'with defaults' do it "executes 'bzr clone -r' with the revision" do - provider.expects(:bzr).with('branch', '-r', resource.value(:revision), resource.value(:source), resource.value(:path)) + expect(provider).to receive(:bzr).with('branch', '-r', resource.value(:revision), resource.value(:source), resource.value(:path)) provider.create end end context 'without revision' do it "justs execute 'bzr clone' without a revision" do resource.delete(:revision) - provider.expects(:bzr).with('branch', resource.value(:source), resource.value(:path)) + expect(provider).to receive(:bzr).with('branch', resource.value(:source), resource.value(:path)) provider.create end end context 'without source' do it "executes 'bzr init'" do resource.delete(:source) - provider.expects(:bzr).with('init', resource.value(:path)) + expect(provider).to receive(:bzr).with('init', resource.value(:path)) provider.create end end end describe 'destroying' do it 'removes the directory' do provider.destroy end end describe 'checking existence' do it 'executes bzr status on the path' do - File.expects(:directory?).with(resource.value(:path)).returns(true) - provider.expects(:bzr).with('status', resource[:path]) + expect(File).to receive(:directory?).with(resource.value(:path)).and_return(true) + expect(provider).to receive(:bzr).with('status', resource[:path]) provider.exists? end end describe 'checking the revision property' do before(:each) do - expects_chdir - provider.expects(:bzr).with('version-info').returns(File.read(fixtures('bzr_version_info.txt'))) + expect_chdir + allow(provider).to receive(:bzr).with('version-info').and_return(File.read(fixtures('bzr_version_info.txt'))) end let(:current_revid) { 'menesis@pov.lt-20100309191856-4wmfqzc803fj300x' } context 'when given a non-revid as the resource revision and its revid is not different than the current revid' do - it 'returns the ref' do + it 'and_return the ref' do resource[:revision] = '2634' - provider.expects(:bzr).with('revision-info', '2634').returns("2634 menesis@pov.lt-20100309191856-4wmfqzc803fj300x\n") + expect(provider).to receive(:bzr).with('revision-info', '2634').and_return("2634 menesis@pov.lt-20100309191856-4wmfqzc803fj300x\n") expect(provider.revision).to eq(resource.value(:revision)) end end context 'when given a non-revid as the resource revision and its revid is different than the current revid' do - it 'returns the current revid' do + it 'and_return the current revid' do resource[:revision] = '2636' - provider.expects(:bzr).with('revision-info', resource.value(:revision)).returns("2635 foo\n") + expect(provider).to receive(:bzr).with('revision-info', resource.value(:revision)).and_return("2635 foo\n") expect(provider.revision).to eq(current_revid) end end context 'when given a revid as the resource revision and it is the same as the current revid' do - it 'returns it' do + it 'and_return it' do resource[:revision] = 'menesis@pov.lt-20100309191856-4wmfqzc803fj300x' - provider.expects(:bzr).with('revision-info', resource.value(:revision)).returns("1234 #{resource.value(:revision)}\n") + expect(provider).to receive(:bzr).with('revision-info', resource.value(:revision)).and_return("1234 #{resource.value(:revision)}\n") expect(provider.revision).to eq(resource.value(:revision)) end end context 'when given a revid as the resource revision and it is not the same as the current revid' do - it 'returns the current revid' do + it 'and_return the current revid' do resource[:revision] = 'menesis@pov.lt-20100309191856-4wmfqzc803fj300y' - provider.expects(:bzr).with('revision-info', resource.value(:revision)).returns("2636 foo\n") + expect(provider).to receive(:bzr).with('revision-info', resource.value(:revision)).and_return("2636 foo\n") expect(provider.revision).to eq(current_revid) end end end describe 'setting the revision property' do it "uses 'bzr update -r' with the revision" do - Dir.expects(:chdir).with('/tmp/test').at_least_once.yields - provider.expects(:bzr).with('update', '-r', 'somerev') + expect(Dir).to receive(:chdir).with('/tmp/test').once.and_yield + expect(provider).to receive(:bzr).with('update', '-r', 'somerev') provider.revision = 'somerev' end end describe 'checking the source property' do it "uses 'bzr info'" do - expects_chdir + expect_chdir resource[:source] = 'http://bazaar.launchpad.net/~bzr-pqm/bzr/bzr.dev/' - provider.expects(:bzr).with('info').returns(' parent branch: http://bazaar.launchpad.net/~bzr-pqm/bzr/bzr.dev/') + expect(provider).to receive(:bzr).with('info').and_return(' parent branch: http://bazaar.launchpad.net/~bzr-pqm/bzr/bzr.dev/') expect(provider.source).to eq(resource.value(:source)) end end describe 'setting the source property' do it "calls 'create'" do resource[:source] = 'http://bazaar.launchpad.net/~bzr-pqm/bzr/bzr.dev/' - provider.expects(:create) + expect(provider).to receive(:create) provider.source = resource.value(:source) end end end diff --git a/spec/unit/puppet/provider/vcsrepo/cvs_spec.rb b/spec/unit/puppet/provider/vcsrepo/cvs_spec.rb index 841f99d..4285820 100644 --- a/spec/unit/puppet/provider/vcsrepo/cvs_spec.rb +++ b/spec/unit/puppet/provider/vcsrepo/cvs_spec.rb @@ -1,161 +1,161 @@ require 'spec_helper' describe Puppet::Type.type(:vcsrepo).provider(:cvs) do let(:resource) do Puppet::Type.type(:vcsrepo).new(name: 'test', ensure: :present, provider: :cvs, revision: '2634', source: ':pserver:anonymous@cvs.sv.gnu.org:/sources/cvs/', path: '/tmp/test') end let(:provider) { resource.provider } before :each do - Puppet::Util.stubs(:which).with('cvs').returns('/usr/bin/cvs') + allow(Puppet::Util).to receive(:which).with('cvs').and_return('/usr/bin/cvs') end describe 'creating' do context 'with a source' do it "executes 'cvs checkout'" do resource[:source] = ':ext:source@example.com:/foo/bar' resource[:revision] = 'an-unimportant-value' - expects_chdir('/tmp') - Puppet::Util::Execution.expects(:execute).with([:cvs, '-d', resource.value(:source), 'checkout', '-r', - 'an-unimportant-value', '-d', 'test', '.'], custom_environment: {}, combine: true, failonfail: true) + expect_chdir('/tmp') + expect(Puppet::Util::Execution).to receive(:execute).with([:cvs, '-d', resource.value(:source), 'checkout', '-r', + 'an-unimportant-value', '-d', 'test', '.'], custom_environment: {}, combine: true, failonfail: true) provider.create end it "executes 'cvs checkout' as user 'muppet'" do resource[:source] = ':ext:source@example.com:/foo/bar' resource[:revision] = 'an-unimportant-value' resource[:user] = 'muppet' - expects_chdir('/tmp') - Puppet::Util::Execution.expects(:execute).with([:cvs, '-d', resource.value(:source), 'checkout', '-r', - 'an-unimportant-value', '-d', 'test', '.'], uid: 'muppet', custom_environment: {}, combine: true, failonfail: true) + expect_chdir('/tmp') + expect(Puppet::Util::Execution).to receive(:execute).with([:cvs, '-d', resource.value(:source), 'checkout', '-r', + 'an-unimportant-value', '-d', 'test', '.'], uid: 'muppet', custom_environment: {}, combine: true, failonfail: true) provider.create end it "justs execute 'cvs checkout' without a revision" do resource[:source] = ':ext:source@example.com:/foo/bar' resource.delete(:revision) - Puppet::Util::Execution.expects(:execute).with([:cvs, '-d', resource.value(:source), 'checkout', '-d', - File.basename(resource.value(:path)), '.'], custom_environment: {}, combine: true, failonfail: true) + expect(Puppet::Util::Execution).to receive(:execute).with([:cvs, '-d', resource.value(:source), 'checkout', '-d', + File.basename(resource.value(:path)), '.'], custom_environment: {}, combine: true, failonfail: true) provider.create end end context 'with a compression' do it "justs execute 'cvs checkout' without a revision" do resource[:source] = ':ext:source@example.com:/foo/bar' resource[:compression] = '3' resource.delete(:revision) - Puppet::Util::Execution.expects(:execute).with([:cvs, '-d', resource.value(:source), '-z', '3', 'checkout', '-d', - File.basename(resource.value(:path)), '.'], custom_environment: {}, combine: true, failonfail: true) + expect(Puppet::Util::Execution).to receive(:execute).with([:cvs, '-d', resource.value(:source), '-z', '3', 'checkout', '-d', + File.basename(resource.value(:path)), '.'], custom_environment: {}, combine: true, failonfail: true) provider.create end end context 'when a source is not given' do it "executes 'cvs init'" do resource.delete(:source) - Puppet::Util::Execution.expects(:execute).with([:cvs, '-d', resource.value(:path), 'init'], custom_environment: {}, combine: true, failonfail: true) + expect(Puppet::Util::Execution).to receive(:execute).with([:cvs, '-d', resource.value(:path), 'init'], custom_environment: {}, combine: true, failonfail: true) provider.create end end end describe 'destroying' do it 'removes the directory' do provider.destroy end end describe 'checking existence' do context 'with a source value' do it "runs 'cvs status'" do resource[:source] = ':ext:source@example.com:/foo/bar' - File.expects(:directory?).with(File.join(resource.value(:path), 'CVS')).returns(true) - expects_chdir - Puppet::Util::Execution.expects(:execute).with([:cvs, '-nq', 'status', '-l'], custom_environment: {}, combine: true, failonfail: true) + expect(File).to receive(:directory?).with(File.join(resource.value(:path), 'CVS')).and_return(true) + expect_chdir + expect(Puppet::Util::Execution).to receive(:execute).with([:cvs, '-nq', 'status', '-l'], custom_environment: {}, combine: true, failonfail: true) provider.exist? end end context 'without a source value' do it 'checks for the CVSROOT directory and config file' do resource.delete(:source) - File.expects(:directory?).with(File.join(resource.value(:path), 'CVSROOT')).returns(true) - File.expects(:exist?).with(File.join(resource.value(:path), 'CVSROOT', 'config,v')).returns(true) + expect(File).to receive(:directory?).with(File.join(resource.value(:path), 'CVSROOT')).and_return(true) + expect(File).to receive(:exist?).with(File.join(resource.value(:path), 'CVSROOT', 'config,v')).and_return(true) provider.exist? end end end describe 'checking the revision property' do let(:tag_file) { File.join(resource.value(:path), 'CVS', 'Tag') } context 'when CVS/Tag exists' do let(:tag) { 'TAG' } before(:each) do - File.expects(:exist?).with(tag_file).returns(true) + allow(File).to receive(:exist?).with(tag_file).and_return(true) end it 'reads CVS/Tag' do - File.expects(:read).with(tag_file).returns("T#{tag}") + expect(File).to receive(:read).with(tag_file).and_return("T#{tag}") expect(provider.revision).to eq(tag) end end context 'when CVS/Tag does not exist' do before(:each) do - File.expects(:exist?).with(tag_file).returns(false) + allow(File).to receive(:exist?).with(tag_file).and_return(false) end it 'assumes HEAD' do expect(provider.revision).to eq('HEAD') end end end describe 'when setting the revision property' do let(:tag) { 'SOMETAG' } it "uses 'cvs update -dr'" do - expects_chdir - Puppet::Util::Execution.expects(:execute).with([:cvs, 'update', '-dr', tag, '.'], custom_environment: {}, combine: true, failonfail: true) + expect_chdir + expect(Puppet::Util::Execution).to receive(:execute).with([:cvs, 'update', '-dr', tag, '.'], custom_environment: {}, combine: true, failonfail: true) provider.revision = tag end end describe 'checking the source property' do it "reads the contents of file 'CVS/Root'" do - File.expects(:read).with(File.join(resource.value(:path), 'CVS', 'Root')) - .returns(':pserver:anonymous@cvs.sv.gnu.org:/sources/cvs/') + expect(File).to receive(:read).with(File.join(resource.value(:path), 'CVS', 'Root')) + .and_return(':pserver:anonymous@cvs.sv.gnu.org:/sources/cvs/') expect(provider.source).to eq(resource.value(:source)) end end describe 'setting the source property' do it "calls 'create'" do - provider.expects(:create) + expect(provider).to receive(:create) provider.source = resource.value(:source) end end describe 'checking the module property' do before(:each) do resource[:module] = 'ccvs' end it "reads the contents of file 'CVS/Repository'" do - File.expects(:read).with(File.join(resource.value(:path), 'CVS', 'Repository')) - .returns('ccvs') + expect(File).to receive(:read).with(File.join(resource.value(:path), 'CVS', 'Repository')) + .and_return('ccvs') expect(provider.module).to eq(resource.value(:module)) end end describe 'setting the module property' do it "calls 'create'" do - provider.expects(:create) + expect(provider).to receive(:create) provider.module = resource.value(:module) end end end diff --git a/spec/unit/puppet/provider/vcsrepo/git_spec.rb b/spec/unit/puppet/provider/vcsrepo/git_spec.rb index 41279ef..aca88e6 100644 --- a/spec/unit/puppet/provider/vcsrepo/git_spec.rb +++ b/spec/unit/puppet/provider/vcsrepo/git_spec.rb @@ -1,552 +1,552 @@ require 'spec_helper' describe Puppet::Type.type(:vcsrepo).provider(:git) do def branch_a_list(include_branch = nil?) < 'git://git@foo.com/bar.git', 'other' => 'git://git@foo.com/baz.git' } resource.delete(:revision) - Dir.expects(:chdir).with('/').at_least_once.yields - provider.expects(:git).with('clone', '--mirror', resource.value(:source)['origin'], resource.value(:path)) - provider.expects(:update_remotes) - expects_chdir - provider.expects(:git).with('config', 'remote.origin.mirror', 'true') - provider.expects(:git).with('config', 'remote.other.mirror', 'true') + expect(Dir).to receive(:chdir).with('/').once.and_yield + expect(provider).to receive(:git).with('clone', '--mirror', resource.value(:source)['origin'], resource.value(:path)) + expect(provider).to receive(:update_remotes) + expect_chdir + expect(provider).to receive(:git).with('config', 'remote.origin.mirror', 'true') + expect(provider).to receive(:git).with('config', 'remote.other.mirror', 'true') provider.create end end end context 'when with an ensure of mirror - when the path is a working copy repository' do it 'clones overtop it using force' do resource[:force] = true - Dir.expects(:chdir).with('/').at_least_once.yields - Dir.expects(:chdir).with('/tmp/test').at_least_once.yields - provider.expects(:path_exists?).returns(true) - provider.expects(:path_empty?).returns(false) + expect(Dir).to receive(:chdir).with('/').once.and_yield + expect(Dir).to receive(:chdir).with('/tmp/test').at_least(:once).and_yield + expect(provider).to receive(:path_exists?).and_return(true) + expect(provider).to receive(:path_empty?).and_return(false) provider.destroy - provider.expects(:git).with('clone', resource.value(:source), resource.value(:path)) - provider.expects(:update_submodules) - provider.expects(:update_remote_url).with('origin', resource.value(:source)).returns false - provider.expects(:git).with('branch', '-a').returns(branch_a_list(resource.value(:revision))) - provider.expects(:git).with('checkout', '--force', resource.value(:revision)) + expect(provider).to receive(:git).with('clone', resource.value(:source), resource.value(:path)) + expect(provider).to receive(:update_submodules) + expect(provider).to receive(:update_remote_url).with('origin', resource.value(:source)).and_return false + expect(provider).to receive(:git).with('branch', '-a').and_return(branch_a_list(resource.value(:revision))) + expect(provider).to receive(:git).with('checkout', '--force', resource.value(:revision)) provider.create end end context 'when with an ensure of mirror - when the path is not empty and not a repository' do it 'raises an exception' do - provider.expects(:path_exists?).returns(true) - provider.expects(:path_empty?).returns(false) + expect(provider).to receive(:path_exists?).and_return(true) + expect(provider).to receive(:path_empty?).and_return(false) expect { provider.create }.to raise_error(Puppet::Error) end end context 'when converting repo type' do context 'when with working copy to bare' do it 'converts the repo' do resource[:ensure] = :bare - provider.expects(:working_copy_exists?).returns(true) - provider.expects(:bare_exists?).returns(false) - FileUtils.expects(:mv).returns(true) - FileUtils.expects(:rm_rf).returns(true) - FileUtils.expects(:mv).returns(true) - expects_chdir - provider.expects(:git).with('config', '--local', '--bool', 'core.bare', 'true') + expect(provider).to receive(:working_copy_exists?).and_return(true) + expect(provider).to receive(:bare_exists?).and_return(false) + expect(FileUtils).to receive(:mv).and_return(true) + expect(FileUtils).to receive(:rm_rf).and_return(true) + expect(FileUtils).to receive(:mv).and_return(true) + expect_chdir + expect(provider).to receive(:git).with('config', '--local', '--bool', 'core.bare', 'true') provider.instance_eval { convert_working_copy_to_bare } end end context 'when with working copy to mirror' do it 'converts the repo' do resource[:ensure] = :mirror - provider.expects(:working_copy_exists?).returns(true) - provider.expects(:bare_exists?).returns(false) - FileUtils.expects(:mv).returns(true) - FileUtils.expects(:rm_rf).returns(true) - FileUtils.expects(:mv).returns(true) - expects_chdir - provider.expects(:git).with('config', '--local', '--bool', 'core.bare', 'true') - provider.expects(:git).with('config', 'remote.origin.mirror', 'true') + expect(provider).to receive(:working_copy_exists?).and_return(true) + expect(provider).to receive(:bare_exists?).and_return(false) + expect(FileUtils).to receive(:mv).and_return(true) + expect(FileUtils).to receive(:rm_rf).and_return(true) + expect(FileUtils).to receive(:mv).and_return(true) + expect_chdir + expect(provider).to receive(:git).with('config', '--local', '--bool', 'core.bare', 'true') + expect(provider).to receive(:git).with('config', 'remote.origin.mirror', 'true') provider.instance_eval { convert_working_copy_to_bare } end end context 'when with bare copy to working copy' do it 'converts the repo' do - FileUtils.expects(:mv).returns(true) - FileUtils.expects(:mkdir).returns(true) - FileUtils.expects(:mv).returns(true) - expects_chdir - provider.expects(:commits?).returns(true) + expect(FileUtils).to receive(:mv).and_return(true) + expect(FileUtils).to receive(:mkdir).and_return(true) + expect(FileUtils).to receive(:mv).and_return(true) + expect_chdir + expect(provider).to receive(:commits?).and_return(true) # If you forget to stub these out you lose 3 hours of rspec work. - provider.expects(:git) - .with('config', '--local', '--bool', 'core.bare', 'false').returns(true) - provider.expects(:reset).with('HEAD').returns(true) - provider.expects(:git_with_identity).with('checkout', '--force').returns(true) - provider.expects(:update_owner_and_excludes).returns(true) - provider.expects(:mirror?).returns(false) + expect(provider).to receive(:git) + .with('config', '--local', '--bool', 'core.bare', 'false').and_return(true) + expect(provider).to receive(:reset).with('HEAD').and_return(true) + expect(provider).to receive(:git_with_identity).with('checkout', '--force').and_return(true) + expect(provider).to receive(:update_owner_and_excludes).and_return(true) + expect(provider).to receive(:mirror?).and_return(false) provider.instance_eval { convert_bare_to_working_copy } end end context 'when with mirror to working copy' do it 'converts the repo' do - FileUtils.expects(:mv).returns(true) - FileUtils.expects(:mkdir).returns(true) - FileUtils.expects(:mv).returns(true) - expects_chdir - provider.expects(:commits?).returns(true) - provider.expects(:git) - .with('config', '--local', '--bool', 'core.bare', 'false').returns(true) - provider.expects(:reset).with('HEAD').returns(true) - provider.expects(:git_with_identity).with('checkout', '--force').returns(true) - provider.expects(:update_owner_and_excludes).returns(true) - provider.expects(:git).with('config', '--unset', 'remote.origin.mirror') - provider.expects(:mirror?).returns(true) + expect(FileUtils).to receive(:mv).and_return(true) + expect(FileUtils).to receive(:mkdir).and_return(true) + expect(FileUtils).to receive(:mv).and_return(true) + expect_chdir + expect(provider).to receive(:commits?).and_return(true) + expect(provider).to receive(:git) + .with('config', '--local', '--bool', 'core.bare', 'false').and_return(true) + expect(provider).to receive(:reset).with('HEAD').and_return(true) + expect(provider).to receive(:git_with_identity).with('checkout', '--force').and_return(true) + expect(provider).to receive(:update_owner_and_excludes).and_return(true) + expect(provider).to receive(:git).with('config', '--unset', 'remote.origin.mirror') + expect(provider).to receive(:mirror?).and_return(true) provider.instance_eval { convert_bare_to_working_copy } end end end context 'when destroying' do it 'removes the directory' do - expects_rm_rf + expect_rm_rf provider.destroy end end context 'when checking the revision property' do before(:each) do - expects_chdir('/tmp/test') + expect_chdir('/tmp/test') resource[:source] = 'http://example.com' - provider.stubs(:git).with('config', 'remote.origin.url').returns('') - provider.stubs(:git).with('fetch', 'origin') # FIXME - provider.stubs(:git).with('fetch', '--tags', 'origin') - provider.stubs(:git).with('rev-parse', 'HEAD').returns('currentsha') - provider.stubs(:git).with('tag', '-l').returns('Hello') + allow(provider).to receive(:git).with('config', 'remote.origin.url').and_return('') + allow(provider).to receive(:git).with('fetch', 'origin') # FIXME + allow(provider).to receive(:git).with('fetch', '--tags', 'origin') + allow(provider).to receive(:git).with('rev-parse', 'HEAD').and_return('currentsha') + allow(provider).to receive(:git).with('tag', '-l').and_return('Hello') end context 'when its a SHA and is not different than the current SHA' do - it 'returns the current SHA' do + it 'and_return the current SHA' do resource[:revision] = 'currentsha' - provider.stubs(:git).with('branch', '-a').returns(branch_a_list) - provider.expects(:git).with('rev-parse', '--revs-only', resource.value(:revision)).never - provider.expects(:update_references).never + allow(provider).to receive(:git).with('branch', '-a').and_return(branch_a_list) + expect(provider).to receive(:git).with('rev-parse', '--revs-only', resource.value(:revision)).never + expect(provider).to receive(:update_references).never expect(provider.revision).to eq(resource.value(:revision)) end end context 'when its a SHA and is different than the current SHA' do - it 'returns the current SHA' do + it 'and_return the current SHA' do resource[:revision] = 'othersha' - provider.stubs(:git).with('branch', '-a').returns(branch_a_list) - provider.expects(:git).with('rev-parse', '--revs-only', resource.value(:revision)).returns('othersha') - provider.expects(:update_references) + allow(provider).to receive(:git).with('branch', '-a').and_return(branch_a_list) + expect(provider).to receive(:git).with('rev-parse', '--revs-only', resource.value(:revision)).and_return('othersha') + expect(provider).to receive(:update_references) expect(provider.revision).to eq('currentsha') end end context 'when its a local branch and is not different than the current SHA' do - it 'returns the ref' do + it 'and_return the ref' do resource[:revision] = 'localbranch' - provider.stubs(:git).with('branch', '-a').returns(branch_a_list('localbranch')) - provider.expects(:git).with('rev-parse', resource.value(:revision)).returns('currentsha') - provider.expects(:update_references) + allow(provider).to receive(:git).with('branch', '-a').and_return(branch_a_list('localbranch')) + expect(provider).to receive(:git).with('rev-parse', resource.value(:revision)).and_return('currentsha') + expect(provider).to receive(:update_references) expect(provider.revision).to eq(resource.value(:revision)) end end context 'when its a local branch and is different than the current SHA' do - it 'returns the current SHA' do + it 'and_return the current SHA' do resource[:revision] = 'localbranch' - provider.stubs(:git).with('branch', '-a').returns(branch_a_list('localbranch')) - provider.expects(:git).with('rev-parse', resource.value(:revision)).returns('othersha') - provider.expects(:update_references) + allow(provider).to receive(:git).with('branch', '-a').and_return(branch_a_list('localbranch')) + expect(provider).to receive(:git).with('rev-parse', resource.value(:revision)).and_return('othersha') + expect(provider).to receive(:update_references) expect(provider.revision).to eq('currentsha') end end context 'when its a ref to a remote head' do - it 'returns the ref' do + it 'and_return the ref' do resource[:revision] = 'remotebranch' - provider.stubs(:git).with('branch', '-a').returns(" remotes/origin/#{resource.value(:revision)}") - provider.expects(:git).with('rev-parse', "origin/#{resource.value(:revision)}").returns('currentsha') - provider.expects(:update_references) + allow(provider).to receive(:git).with('branch', '-a').and_return(" remotes/origin/#{resource.value(:revision)}") + expect(provider).to receive(:git).with('rev-parse', "origin/#{resource.value(:revision)}").and_return('currentsha') + expect(provider).to receive(:update_references) expect(provider.revision).to eq(resource.value(:revision)) end end context 'when its a ref to non existant remote head' do it 'fails' do resource[:revision] = 'remotebranch' - provider.stubs(:git).with('branch', '-a').returns(branch_a_list) - provider.expects(:git).with('rev-parse', '--revs-only', resource.value(:revision)).returns('') - provider.expects(:update_references) + allow(provider).to receive(:git).with('branch', '-a').and_return(branch_a_list) + expect(provider).to receive(:git).with('rev-parse', '--revs-only', resource.value(:revision)).and_return('') + expect(provider).to receive(:update_references) expect { provider.revision }.to raise_error(RuntimeError, %r{not a local or remote ref$}) end end context "when there's no source" do - it 'returns the revision' do + it 'and_return the revision' do resource[:revision] = 'localbranch' resource.delete(:source) - provider.stubs(:git).with('branch', '-a').returns(branch_a_list('localbranch')) - provider.expects(:update_references).never - provider.expects(:git).with('status') - provider.expects(:git).with('rev-parse', resource.value(:revision)).returns('currentsha') + allow(provider).to receive(:git).with('branch', '-a').and_return(branch_a_list('localbranch')) + expect(provider).to receive(:update_references).never + expect(provider).to receive(:git).with('status') + expect(provider).to receive(:git).with('rev-parse', resource.value(:revision)).and_return('currentsha') expect(provider.revision).to eq(resource.value(:revision)) end end end context 'when setting the revision property' do before(:each) do - expects_chdir + expect_chdir end context "when it's an existing local branch" do it "uses 'git fetch' and 'git reset'" do resource[:revision] = 'feature/foo' - provider.expects(:update_submodules) - provider.expects(:git).with('branch', '-a').at_least_once.returns(branch_a_list(resource.value(:revision))) - provider.expects(:git).with('checkout', '--force', resource.value(:revision)) - provider.expects(:git).with('reset', '--hard', "origin/#{resource.value(:revision)}") + expect(provider).to receive(:update_submodules) + expect(provider).to receive(:git).with('branch', '-a').at_least(:once).and_return(branch_a_list(resource.value(:revision))) + expect(provider).to receive(:git).with('checkout', '--force', resource.value(:revision)) + expect(provider).to receive(:git).with('reset', '--hard', "origin/#{resource.value(:revision)}") provider.revision = resource.value(:revision) end end context "when it's a remote branch" do it "uses 'git fetch' and 'git reset'" do resource[:revision] = 'only/remote' - provider.expects(:update_submodules) - provider.expects(:git).with('branch', '-a').at_least_once.returns(resource.value(:revision)) - provider.expects(:git).with('checkout', '--force', resource.value(:revision)) - provider.expects(:git).with('reset', '--hard', "origin/#{resource.value(:revision)}") + expect(provider).to receive(:update_submodules) + expect(provider).to receive(:git).with('branch', '-a').at_least(:once).and_return(resource.value(:revision)) + expect(provider).to receive(:git).with('checkout', '--force', resource.value(:revision)) + expect(provider).to receive(:git).with('reset', '--hard', "origin/#{resource.value(:revision)}") provider.revision = resource.value(:revision) end end context "when it's a commit or tag" do it "uses 'git fetch' and 'git reset'" do resource[:revision] = 'a-commit-or-tag' - provider.expects(:git).with('branch', '-a').at_least_once.returns(fixture(:git_branch_a)) - provider.expects(:git).with('checkout', '--force', resource.value(:revision)) - provider.expects(:git).with('branch', '-a').returns(fixture(:git_branch_a)) - provider.expects(:git).with('branch', '-a').returns(fixture(:git_branch_a)) - provider.expects(:git).with('submodule', 'update', '--init', '--recursive') + expect(provider).to receive(:git).with('branch', '-a').once.and_return(fixture(:git_branch_a)) + expect(provider).to receive(:git).with('checkout', '--force', resource.value(:revision)) + expect(provider).to receive(:git).with('branch', '-a').and_return(fixture(:git_branch_a)) + expect(provider).to receive(:git).with('branch', '-a').and_return(fixture(:git_branch_a)) + expect(provider).to receive(:git).with('submodule', 'update', '--init', '--recursive') provider.revision = resource.value(:revision) end end end context 'when checking the source property' do before(:each) do - expects_chdir('/tmp/test') - provider.stubs(:git).with('config', 'remote.origin.url').returns('') - provider.stubs(:git).with('fetch', 'origin') # FIXME - provider.stubs(:git).with('fetch', '--tags', 'origin') - provider.stubs(:git).with('rev-parse', 'HEAD').returns('currentsha') - provider.stubs(:git).with('branch', '-a').returns(branch_a_list(resource.value(:revision))) - provider.stubs(:git).with('tag', '-l').returns('Hello') + expect_chdir('/tmp/test') + allow(provider).to receive(:git).with('config', 'remote.origin.url').and_return('') + allow(provider).to receive(:git).with('fetch', 'origin') # FIXME + allow(provider).to receive(:git).with('fetch', '--tags', 'origin') + allow(provider).to receive(:git).with('rev-parse', 'HEAD').and_return('currentsha') + allow(provider).to receive(:git).with('branch', '-a').and_return(branch_a_list(resource.value(:revision))) + allow(provider).to receive(:git).with('tag', '-l').and_return('Hello') end context "when there's a single remote 'origin'" do - it 'returns the URL for the remote' do + it 'and_return the URL for the remote' do resource[:source] = 'http://example.com' - provider.expects(:git).with('remote').returns("origin\n") - provider.expects(:git).with('config', '--get', 'remote.origin.url').returns('http://example.com') + expect(provider).to receive(:git).with('remote').and_return("origin\n") + expect(provider).to receive(:git).with('config', '--get', 'remote.origin.url').and_return('http://example.com') expect(provider.source).to eq(resource.value(:source)) end end context "when there's more than one remote" do - it 'returns the remotes as a hash' do + it 'and_return the remotes as a hash' do resource[:source] = { 'origin' => 'git://git@foo.com/bar.git', 'other' => 'git://git@foo.com/baz.git' } - provider.expects(:git).with('remote').returns("origin\nother\n") - provider.expects(:git).with('config', '--get', 'remote.origin.url').returns('git://git@foo.com/bar.git') - provider.expects(:git).with('config', '--get', 'remote.other.url').returns('git://git@foo.com/baz.git') + expect(provider).to receive(:git).with('remote').and_return("origin\nother\n") + expect(provider).to receive(:git).with('config', '--get', 'remote.origin.url').and_return('git://git@foo.com/bar.git') + expect(provider).to receive(:git).with('config', '--get', 'remote.other.url').and_return('git://git@foo.com/baz.git') expect(provider.source).to eq(resource.value(:source)) end end end context 'when updating remotes' do context 'when with string to string' do it 'fails' do resource[:source] = 'git://git@foo.com/bar.git' resource[:force] = false - provider.expects(:source).returns('git://git@foo.com/foo.git') - provider.expects(:path_exists?).returns(true) - provider.expects(:path_empty?).returns(false) + expect(provider).to receive(:source).and_return('git://git@foo.com/foo.git') + expect(provider).to receive(:path_exists?).and_return(true) + expect(provider).to receive(:path_empty?).and_return(false) expect { provider.source = resource.value(:source) }.to raise_error(Puppet::Error) end end context 'when with hash to hash' do it 'adds any new remotes, update any existing remotes, remove deleted remotes' do - expects_chdir + expect_chdir resource[:source] = { 'origin' => 'git://git@foo.com/bar.git', 'new_remote' => 'git://git@foo.com/baz.git' } - provider.expects(:source).returns( + expect(provider).to receive(:source).and_return( 'origin' => 'git://git@foo.com/foo.git', 'old_remote' => 'git://git@foo.com/old.git', ) - provider.expects(:git).at_least_once.with('config', '-l').returns("remote.old_remote.url=git://git@foo.com/old.git\n", "remote.origin.url=git://git@foo.com/foo.git\n") - provider.expects(:git).with('remote', 'remove', 'old_remote') - provider.expects(:git).with('remote', 'set-url', 'origin', 'git://git@foo.com/bar.git') - provider.expects(:git).with('remote', 'add', 'new_remote', 'git://git@foo.com/baz.git') - provider.expects(:git).with('remote', 'update') + expect(provider).to receive(:git).once.with('config', '-l').and_return("remote.old_remote.url=git://git@foo.com/old.git\n", "remote.origin.url=git://git@foo.com/foo.git\n") + expect(provider).to receive(:git).with('remote', 'remove', 'old_remote') + expect(provider).to receive(:git).with('remote', 'set-url', 'origin', 'git://git@foo.com/bar.git') + expect(provider).to receive(:git).with('remote', 'add', 'new_remote', 'git://git@foo.com/baz.git') + expect(provider).to receive(:git).with('remote', 'update') provider.source = resource.value(:source) end end context 'when with string to hash' do it 'adds any new remotes, update origin remote' do - expects_chdir + expect_chdir resource[:source] = { 'origin' => 'git://git@foo.com/bar.git', 'new_remote' => 'git://git@foo.com/baz.git' } - provider.expects(:source).returns('git://git@foo.com/foo.git') - provider.expects(:git).at_least_once.with('config', '-l').returns("remote.origin.url=git://git@foo.com/foo.git\n") - provider.expects(:git).with('remote', 'set-url', 'origin', 'git://git@foo.com/bar.git') - provider.expects(:git).with('remote', 'add', 'new_remote', 'git://git@foo.com/baz.git') - provider.expects(:git).with('remote', 'update') + expect(provider).to receive(:source).and_return('git://git@foo.com/foo.git') + expect(provider).to receive(:git).at_least(:once).with('config', '-l').and_return("remote.origin.url=git://git@foo.com/foo.git\n") + expect(provider).to receive(:git).with('remote', 'set-url', 'origin', 'git://git@foo.com/bar.git') + expect(provider).to receive(:git).with('remote', 'add', 'new_remote', 'git://git@foo.com/baz.git') + expect(provider).to receive(:git).with('remote', 'update') provider.source = resource.value(:source) end end context 'when with hash to string' do it 'updates origin remote, remove deleted remotes' do - expects_chdir + expect_chdir resource[:source] = 'git://git@foo.com/baz.git' - provider.expects(:source).returns( + expect(provider).to receive(:source).and_return( 'origin' => 'git://git@foo.com/foo.git', 'old_remote' => 'git://git@foo.com/old.git', ) - provider.expects(:git).with('remote', 'remove', 'old_remote') - provider.expects(:git).at_least_once.with('config', '-l').returns("remote.origin.url=git://git@foo.com/foo.git\n", "remote.other.url=git://git@foo.com/bar.git\n") - provider.expects(:git).with('remote', 'set-url', 'origin', 'git://git@foo.com/baz.git') - provider.expects(:git).with('remote', 'update') + expect(provider).to receive(:git).with('remote', 'remove', 'old_remote') + expect(provider).to receive(:git).with('config', '-l').at_most(:twice).and_return("remote.origin.url=git://git@foo.com/foo.git\n", "remote.other.url=git://git@foo.com/bar.git\n") + expect(provider).to receive(:git).with('remote', 'set-url', 'origin', 'git://git@foo.com/baz.git') + expect(provider).to receive(:git).with('remote', 'update') provider.source = resource.value(:source) end end end # rubocop:enable RSpec/ExampleLength context 'when updating references' do it "uses 'git fetch --tags'" do resource.delete(:source) - expects_chdir - provider.expects(:git).with('fetch', 'origin') - provider.expects(:git).with('fetch', '--tags', 'origin') + expect_chdir + expect(provider).to receive(:git).with('fetch', 'origin') + expect(provider).to receive(:git).with('fetch', '--tags', 'origin') provider.update_references end end describe 'latest?' do context 'when true' do it do - provider.expects(:revision).returns('testrev') - provider.expects(:latest_revision).returns('testrev') + expect(provider).to receive(:revision).and_return('testrev') + expect(provider).to receive(:latest_revision).and_return('testrev') expect(provider).to be_latest end end context 'when false' do it do - provider.expects(:revision).returns('master') - provider.expects(:latest_revision).returns('testrev') + expect(provider).to receive(:revision).and_return('master') + expect(provider).to receive(:latest_revision).and_return('testrev') expect(provider).not_to be_latest end end end describe 'trust_server_cert' do context 'when true' do before :each do resource[:trust_server_cert] = true end it 'raises error with git 1.7.0' do - provider.stubs(:git).with('--version').returns '1.7.0' + allow(provider).to receive(:git).with('--version').and_return '1.7.0' expect { provider.create }.to raise_error RuntimeError, %r{Can't set sslVerify to false} end it 'compiles with git 2.13.0' do resource[:revision] = 'only/remote' - Dir.expects(:chdir).with('/').at_least_once.yields - Dir.expects(:chdir).with('/tmp/test').at_least_once.yields - provider.expects(:git).with('-c', 'http.sslVerify=false', 'clone', resource.value(:source), resource.value(:path)) - provider.expects(:update_submodules) - provider.expects(:update_remote_url).with('origin', resource.value(:source)).returns false - provider.expects(:git).with('-c', 'http.sslVerify=false', 'branch', '-a').returns(branch_a_list(resource.value(:revision))) - provider.expects(:git).with('-c', 'http.sslVerify=false', 'checkout', '--force', resource.value(:revision)) - - provider.stubs(:git).with('--version').returns '2.13.0' + expect(Dir).to receive(:chdir).with('/').once.and_yield + expect(Dir).to receive(:chdir).with('/tmp/test').at_least(:once).and_yield + expect(provider).to receive(:git).with('-c', 'http.sslVerify=false', 'clone', resource.value(:source), resource.value(:path)) + expect(provider).to receive(:update_submodules) + expect(provider).to receive(:update_remote_url).with('origin', resource.value(:source)).and_return false + expect(provider).to receive(:git).with('-c', 'http.sslVerify=false', 'branch', '-a').and_return(branch_a_list(resource.value(:revision))) + expect(provider).to receive(:git).with('-c', 'http.sslVerify=false', 'checkout', '--force', resource.value(:revision)) + + allow(provider).to receive(:git).with('--version').and_return '2.13.0' expect { provider.create }.not_to raise_error end end end end diff --git a/spec/unit/puppet/provider/vcsrepo/hg_spec.rb b/spec/unit/puppet/provider/vcsrepo/hg_spec.rb index 8489626..ff39fd7 100644 --- a/spec/unit/puppet/provider/vcsrepo/hg_spec.rb +++ b/spec/unit/puppet/provider/vcsrepo/hg_spec.rb @@ -1,139 +1,139 @@ require 'spec_helper' describe Puppet::Type.type(:vcsrepo).provider(:hg) do let(:resource) do Puppet::Type.type(:vcsrepo).new(name: 'test', ensure: :present, provider: :hg, path: '/tmp/vcsrepo') end let(:provider) { resource.provider } before :each do - Puppet::Util.stubs(:which).with('hg').returns('/usr/bin/hg') + allow(Puppet::Util).to receive(:which).with('hg').and_return('/usr/bin/hg') end describe 'creating' do context 'with source and revision' do it "executes 'hg clone -u' with the revision" do resource[:source] = 'something' resource[:revision] = '1' - provider.expects(:hg).with('clone', '-u', resource.value(:revision), - resource.value(:source), resource.value(:path)) + expect(provider).to receive(:hg).with('clone', '-u', resource.value(:revision), + resource.value(:source), resource.value(:path)) provider.create end end context 'without revision' do it "justs execute 'hg clone' without a revision" do resource[:source] = 'something' - provider.expects(:hg).with('clone', resource.value(:source), resource.value(:path)) + expect(provider).to receive(:hg).with('clone', resource.value(:source), resource.value(:path)) provider.create end end context 'when a source is not given' do it "executes 'hg init'" do - provider.expects(:hg).with('init', resource.value(:path)) + expect(provider).to receive(:hg).with('init', resource.value(:path)) provider.create end end context 'when basic auth is used' do it "executes 'hg clone'" do resource[:source] = 'something' resource[:basic_auth_username] = 'user' resource[:basic_auth_password] = 'pass' - provider.expects(:hg).with('clone', resource.value(:source), resource.value(:path), '--config', - 'auth.x.prefix=' + resource.value(:source), '--config', 'auth.x.username=' + resource.value(:basic_auth_username), - '--config', 'auth.x.password=' + resource.value(:basic_auth_password), '--config', 'auth.x.schemes=http https') + expect(provider).to receive(:hg).with('clone', resource.value(:source), resource.value(:path), '--config', + 'auth.x.prefix=' + resource.value(:source), '--config', 'auth.x.username=' + resource.value(:basic_auth_username), + '--config', 'auth.x.password=' + resource.value(:basic_auth_password), '--config', 'auth.x.schemes=http https') provider.create end end end describe 'destroying' do it 'removes the directory' do - expects_rm_rf + expect_rm_rf provider.destroy end end describe 'checking existence' do it 'checks for the directory' do - expects_directory?(true, resource.value(:path)) - provider.expects(:hg).with('status', resource.value(:path)) + expect_directory?(true, resource.value(:path)) + expect(provider).to receive(:hg).with('status', resource.value(:path)) provider.exists? end end describe 'checking the revision property' do before(:each) do - expects_chdir + expect_chdir end context 'when given a non-SHA as the resource revision' do before(:each) do - provider.expects(:hg).with('parents').returns(fixture(:hg_parents)) - provider.expects(:hg).with('tags').returns(fixture(:hg_tags)) + allow(provider).to receive(:hg).with('parents').and_return(fixture(:hg_parents)) + allow(provider).to receive(:hg).with('tags').and_return(fixture(:hg_tags)) end - it 'when its sha is not different from the current SHA it returns the ref' do + it 'when its sha is not different from the current SHA it and_return the ref' do resource[:revision] = '0.6' expect(provider.revision).to eq('0.6') end - it 'when its SHA is different than the current SHA it returns the current SHA' do + it 'when its SHA is different than the current SHA it and_return the current SHA' do resource[:revision] = '0.5.3' expect(provider.revision).to eq('34e6012c783a') end end context 'when given a SHA as the resource revision' do before(:each) do - provider.expects(:hg).with('parents').returns(fixture(:hg_parents)) + allow(provider).to receive(:hg).with('parents').and_return(fixture(:hg_parents)) end - it 'when it is the same as the current SHA it returns it' do + it 'when it is the same as the current SHA it and_return it' do resource[:revision] = '34e6012c783a' - provider.expects(:hg).with('tags').returns(fixture(:hg_tags)) + expect(provider).to receive(:hg).with('tags').and_return(fixture(:hg_tags)) expect(provider.revision).to eq(resource.value(:revision)) end - it 'when it is not the same as the current SHA it returns the current SHA' do + it 'when it is not the same as the current SHA it and_return the current SHA' do resource[:revision] = 'not-the-same' - provider.expects(:hg).with('tags').returns(fixture(:hg_tags)) + expect(provider).to receive(:hg).with('tags').and_return(fixture(:hg_tags)) expect(provider.revision).to eq('34e6012c783a') end end end describe 'setting the revision property' do let(:revision) { '6aa99e9b3ab1' } it "uses 'hg update ---clean -r'" do - expects_chdir - provider.expects(:hg).with('pull') - provider.expects(:hg).with('merge') - provider.expects(:hg).with('update', '--clean', '-r', revision) + expect_chdir + expect(provider).to receive(:hg).with('pull') + expect(provider).to receive(:hg).with('merge') + expect(provider).to receive(:hg).with('update', '--clean', '-r', revision) provider.revision = revision end end describe 'checking the source property' do - it 'returns the default path' do + it 'and_return the default path' do resource[:source] = 'http://selenic.com/hg' - expects_chdir - provider.expects(:hg_wrapper).with('paths').returns('default = http://selenic.com/hg') + expect_chdir + expect(provider).to receive(:hg_wrapper).with('paths').and_return('default = http://selenic.com/hg') expect(provider.source).to eq(resource.value(:source)) end end describe 'setting the source property' do it "calls 'create'" do resource[:source] = 'some-example' - provider.expects(:create) + expect(provider).to receive(:create) provider.source = resource.value(:source) end end end diff --git a/spec/unit/puppet/provider/vcsrepo/p4_spec.rb b/spec/unit/puppet/provider/vcsrepo/p4_spec.rb index 437219d..606e12e 100644 --- a/spec/unit/puppet/provider/vcsrepo/p4_spec.rb +++ b/spec/unit/puppet/provider/vcsrepo/p4_spec.rb @@ -1,97 +1,97 @@ require 'spec_helper' describe Puppet::Type.type(:vcsrepo).provider(:p4) do let(:resource) do Puppet::Type.type(:vcsrepo).new(name: 'test', ensure: :present, provider: :p4, path: '/tmp/vcsrepo') end let(:provider) { resource.provider } before :each do - Puppet::Util.stubs(:which).with('p4').returns('/usr/local/bin/p4') + allow(Puppet::Util).to receive(:which).with('p4').and_return('/usr/local/bin/p4') end spec = { input: "Description: Generated by Puppet VCSrepo\nRoot: /tmp/vcsrepo\n\nView:\n", marshal: false, } describe 'creating' do context 'with source and revision' do it "executes 'p4 sync' with the revision" do resource[:source] = 'something' resource[:revision] = '1' ENV['P4CLIENT'] = 'client_ws1' - provider.expects(:p4).with(['client', '-o', 'client_ws1']).returns({}) - provider.expects(:p4).with(['client', '-i'], spec) - provider.expects(:p4).with(['sync', resource.value(:source) + '@' + resource.value(:revision)]) + expect(provider).to receive(:p4).with(['client', '-o', 'client_ws1']).and_return({}) + expect(provider).to receive(:p4).with(['client', '-i'], spec) + expect(provider).to receive(:p4).with(['sync', resource.value(:source) + '@' + resource.value(:revision)]) provider.create end end context 'without revision' do it "justs execute 'p4 sync' without a revision" do resource[:source] = 'something' ENV['P4CLIENT'] = 'client_ws2' - provider.expects(:p4).with(['client', '-o', 'client_ws2']).returns({}) - provider.expects(:p4).with(['client', '-i'], spec) - provider.expects(:p4).with(['sync', resource.value(:source)]) + expect(provider).to receive(:p4).with(['client', '-o', 'client_ws2']).and_return({}) + expect(provider).to receive(:p4).with(['client', '-i'], spec) + expect(provider).to receive(:p4).with(['sync', resource.value(:source)]) provider.create end end context 'when a client and source are not given' do it "executes 'p4 client'" do ENV['P4CLIENT'] = nil path = resource.value(:path) host = Facter.value('hostname') default = 'puppet-' + Digest::MD5.hexdigest(path + host) - provider.expects(:p4).with(['client', '-o', default]).returns({}) - provider.expects(:p4).with(['client', '-i'], spec) + expect(provider).to receive(:p4).with(['client', '-o', default]).and_return({}) + expect(provider).to receive(:p4).with(['client', '-i'], spec) provider.create end end end describe 'destroying' do it 'removes the directory' do ENV['P4CLIENT'] = 'test_client' - provider.expects(:p4).with(['client', '-d', '-f', 'test_client']) - expects_rm_rf + expect(provider).to receive(:p4).with(['client', '-d', '-f', 'test_client']) + expect_rm_rf provider.destroy end end describe 'checking existence' do it 'checks for the directory' do - provider.expects(:p4).with(['info'], marshal: false).returns({}) - provider.expects(:p4).with(['where', resource.value(:path) + '/...'], raise: false).returns({}) + expect(provider).to receive(:p4).with(['info'], marshal: false).and_return({}) + expect(provider).to receive(:p4).with(['where', resource.value(:path) + '/...'], raise: false).and_return({}) provider.exists? end end describe 'checking the source property' do it "runs 'p4 where'" do resource[:source] = '//public/something' - provider.expects(:p4).with(['where', resource.value(:path) + '/...'], - raise: false).returns('depotFile' => '//public/something') + expect(provider).to receive(:p4).with(['where', resource.value(:path) + '/...'], + raise: false).and_return('depotFile' => '//public/something') expect(provider.source).to eq(resource.value(:source)) end end describe 'setting the source property' do it "calls 'create'" do resource[:source] = '//public/something' - provider.expects(:create) + expect(provider).to receive(:create) provider.source = resource.value(:source) end end end diff --git a/spec/unit/puppet/provider/vcsrepo/svn_spec.rb b/spec/unit/puppet/provider/vcsrepo/svn_spec.rb index 5dcbc5f..a8bfa48 100644 --- a/spec/unit/puppet/provider/vcsrepo/svn_spec.rb +++ b/spec/unit/puppet/provider/vcsrepo/svn_spec.rb @@ -1,289 +1,289 @@ require 'spec_helper' describe Puppet::Type.type(:vcsrepo).provider(:svn) do let(:resource) do Puppet::Type.type(:vcsrepo).new(name: 'test', ensure: :present, provider: :svn, path: '/tmp/vcsrepo') end let(:provider) { resource.provider } let(:test_paths) { ['path1/file1', 'path2/nested/deep/file2'] } let(:test_paths_parents) { ['path1', 'path2', 'path2/nested', 'path2/nested/deep'] } before :each do - Puppet::Util.stubs(:which).with('svn').returns('/usr/bin/svn') + allow(Puppet::Util).to receive(:which).with('svn').and_return('/usr/bin/svn') end describe 'creation/checkout' do context 'with source and revision' do it "executes 'svn checkout' with a revision" do resource[:source] = 'exists' resource[:revision] = '1' - provider.expects(:svn).with('--non-interactive', 'checkout', '-r', resource.value(:revision), - resource.value(:source), resource.value(:path)) + expect(provider).to receive(:svn).with('--non-interactive', 'checkout', '-r', resource.value(:revision), + resource.value(:source), resource.value(:path)) provider.create end end context 'with source' do it "justs execute 'svn checkout' without a revision" do resource[:source] = 'exists' - provider.expects(:svn).with('--non-interactive', 'checkout', - resource.value(:source), - resource.value(:path)) + expect(provider).to receive(:svn).with('--non-interactive', 'checkout', + resource.value(:source), + resource.value(:path)) provider.create end end context 'with fstype' do it "executes 'svnadmin create' with an '--fs-type' option" do resource[:fstype] = 'ext4' - provider.expects(:svnadmin).with('create', '--fs-type', - resource.value(:fstype), - resource.value(:path)) + expect(provider).to receive(:svnadmin).with('create', '--fs-type', + resource.value(:fstype), + resource.value(:path)) provider.create end end context 'without fstype' do it "executes 'svnadmin create' without an '--fs-type' option" do - provider.expects(:svnadmin).with('create', resource.value(:path)) + expect(provider).to receive(:svnadmin).with('create', resource.value(:path)) provider.create end end context 'with depth' do it "executes 'svn checkout' with a depth" do resource[:source] = 'exists' resource[:depth] = 'infinity' - provider.expects(:svn).with('--non-interactive', 'checkout', '--depth', 'infinity', - resource.value(:source), resource.value(:path)) + expect(provider).to receive(:svn).with('--non-interactive', 'checkout', '--depth', 'infinity', + resource.value(:source), resource.value(:path)) provider.create end end context 'with trust_server_cert' do it "executes 'svn checkout' without a trust-server-cert" do resource[:source] = 'exists' resource[:trust_server_cert] = false - provider.expects(:svn).with('--non-interactive', 'checkout', - resource.value(:source), resource.value(:path)) + expect(provider).to receive(:svn).with('--non-interactive', 'checkout', + resource.value(:source), resource.value(:path)) provider.create end it "executes 'svn checkout' with a trust-server-cert" do resource[:source] = 'exists' resource[:trust_server_cert] = true - provider.expects(:svn).with('--non-interactive', '--trust-server-cert', 'checkout', - resource.value(:source), resource.value(:path)) + expect(provider).to receive(:svn).with('--non-interactive', '--trust-server-cert', 'checkout', + resource.value(:source), resource.value(:path)) provider.create end end context 'with specific include paths' do it 'raises an error when trying to make a repo' do resource[:includes] = test_paths expect { provider.create }.to raise_error(Puppet::Error, %r{Specifying include paths on a nonexistent repo.}) end it 'performs a sparse checkout' do resource[:source] = 'exists' resource[:includes] = test_paths - Dir.expects(:chdir).with('/tmp/vcsrepo').at_least_once.yields - provider.expects(:svn).with('--non-interactive', 'checkout', '--depth', 'empty', - resource.value(:source), - resource.value(:path)) - provider.expects(:svn).with('--non-interactive', 'update', '--depth', 'empty', - *test_paths_parents) - provider.expects(:svn).with('--non-interactive', 'update', - *resource[:includes]) + expect(Dir).to receive(:chdir).with('/tmp/vcsrepo').once.and_yield + expect(provider).to receive(:svn).with('--non-interactive', 'checkout', '--depth', 'empty', + resource.value(:source), + resource.value(:path)) + expect(provider).to receive(:svn).with('--non-interactive', 'update', '--depth', 'empty', + *test_paths_parents) + expect(provider).to receive(:svn).with('--non-interactive', 'update', + *resource[:includes]) provider.create end it 'performs a sparse checkout at a specific revision' do resource[:source] = 'exists' resource[:revision] = 1 resource[:includes] = test_paths - Dir.expects(:chdir).with('/tmp/vcsrepo').at_least_once.yields - provider.expects(:svn).with('--non-interactive', 'checkout', '-r', - resource.value(:revision), - '--depth', 'empty', - resource.value(:source), - resource.value(:path)) - provider.expects(:svn).with('--non-interactive', 'update', - '--depth', 'empty', - '-r', resource.value(:revision), - *test_paths_parents) - provider.expects(:svn).with('--non-interactive', 'update', '-r', - resource.value(:revision), - *resource[:includes]) + expect(Dir).to receive(:chdir).with('/tmp/vcsrepo').once.and_yield + expect(provider).to receive(:svn).with('--non-interactive', 'checkout', '-r', + resource.value(:revision), + '--depth', 'empty', + resource.value(:source), + resource.value(:path)) + expect(provider).to receive(:svn).with('--non-interactive', 'update', + '--depth', 'empty', + '-r', resource.value(:revision), + *test_paths_parents) + expect(provider).to receive(:svn).with('--non-interactive', 'update', '-r', + resource.value(:revision), + *resource[:includes]) provider.create end it 'performs a sparse checkout with a specific depth' do resource[:source] = 'exists' resource[:depth] = 'files' resource[:includes] = test_paths - Dir.expects(:chdir).with('/tmp/vcsrepo').at_least_once.yields - provider.expects(:svn).with('--non-interactive', 'checkout', '--depth', 'empty', - resource.value(:source), - resource.value(:path)) - provider.expects(:svn).with('--non-interactive', 'update', - '--depth', 'empty', - *test_paths_parents) - provider.expects(:svn).with('--non-interactive', 'update', - '--depth', resource.value(:depth), - *resource[:includes]) + expect(Dir).to receive(:chdir).with('/tmp/vcsrepo').once.and_yield + expect(provider).to receive(:svn).with('--non-interactive', 'checkout', '--depth', 'empty', + resource.value(:source), + resource.value(:path)) + expect(provider).to receive(:svn).with('--non-interactive', 'update', + '--depth', 'empty', + *test_paths_parents) + expect(provider).to receive(:svn).with('--non-interactive', 'update', + '--depth', resource.value(:depth), + *resource[:includes]) provider.create end it 'performs a sparse checkout at a specific depth and revision' do resource[:source] = 'exists' resource[:revision] = 1 resource[:depth] = 'files' resource[:includes] = test_paths - Dir.expects(:chdir).with('/tmp/vcsrepo').at_least_once.yields - provider.expects(:svn).with('--non-interactive', 'checkout', '-r', - resource.value(:revision), - '--depth', 'empty', - resource.value(:source), - resource.value(:path)) - provider.expects(:svn).with('--non-interactive', 'update', - '--depth', 'empty', - '-r', resource.value(:revision), - *test_paths_parents) - provider.expects(:svn).with('--non-interactive', 'update', - '-r', resource.value(:revision), - '--depth', resource.value(:depth), - *resource[:includes]) + expect(Dir).to receive(:chdir).with('/tmp/vcsrepo').once.and_yield + expect(provider).to receive(:svn).with('--non-interactive', 'checkout', '-r', + resource.value(:revision), + '--depth', 'empty', + resource.value(:source), + resource.value(:path)) + expect(provider).to receive(:svn).with('--non-interactive', 'update', + '--depth', 'empty', + '-r', resource.value(:revision), + *test_paths_parents) + expect(provider).to receive(:svn).with('--non-interactive', 'update', + '-r', resource.value(:revision), + '--depth', resource.value(:depth), + *resource[:includes]) provider.create end end end describe 'destroying' do it 'removes the directory' do - expects_rm_rf + expect_rm_rf provider.destroy end end describe 'checking existence' do it "runs `svn info` on the path when there's a source" do resource[:source] = 'dummy' - expects_directory?(true, resource.value(:path)) - provider.expects(:svn).with('info', resource[:path]) + expect_directory?(true, resource.value(:path)) + expect(provider).to receive(:svn).with('info', resource[:path]) provider.exists? end it "runs `svnlook uuid` on the path when there's no source" do - expects_directory?(true, resource.value(:path)) - provider.expects(:svnlook).with('uuid', resource[:path]) + expect_directory?(true, resource.value(:path)) + expect(provider).to receive(:svnlook).with('uuid', resource[:path]) provider.exists? end end describe 'checking the revision property' do before(:each) do - provider.expects(:svn).with('--non-interactive', 'info').returns(fixture(:svn_info)) + allow(provider).to receive(:svn).with('--non-interactive', 'info').and_return(fixture(:svn_info)) end it "uses 'svn info'" do - expects_chdir + expect_chdir expect(provider.revision).to eq('4') # From 'Revision', not 'Last Changed Rev' end end describe 'setting the revision property' do let(:revision) { '30' } context 'with conflict' do it "uses 'svn update'" do resource[:conflict] = 'theirs-full' - expects_chdir - provider.expects(:svn).with('--non-interactive', 'update', - '-r', revision, '--accept', resource.value(:conflict)) + expect_chdir + expect(provider).to receive(:svn).with('--non-interactive', 'update', + '-r', revision, '--accept', resource.value(:conflict)) provider.revision = revision end end context 'without conflict' do it "uses 'svn update'" do - expects_chdir - provider.expects(:svn).with('--non-interactive', 'update', '-r', revision) + expect_chdir + expect(provider).to receive(:svn).with('--non-interactive', 'update', '-r', revision) provider.revision = revision end end end describe 'setting the revision property and repo source' do let(:revision) { '30' } context 'with conflict' do it "uses 'svn switch'" do resource[:source] = 'an-unimportant-value' resource[:conflict] = 'theirs-full' - expects_chdir - provider.expects(:svn).with('--non-interactive', 'switch', '-r', revision, 'an-unimportant-value', '--accept', resource.value(:conflict)) + expect_chdir + expect(provider).to receive(:svn).with('--non-interactive', 'switch', '-r', revision, 'an-unimportant-value', '--accept', resource.value(:conflict)) provider.revision = revision end end context 'without conflict' do it "uses 'svn switch' - variation one" do resource[:source] = 'an-unimportant-value' - expects_chdir - provider.expects(:svn).with('--non-interactive', 'switch', '-r', revision, 'an-unimportant-value') + expect_chdir + expect(provider).to receive(:svn).with('--non-interactive', 'switch', '-r', revision, 'an-unimportant-value') provider.revision = revision end it "uses 'svn switch' - variation two" do resource[:source] = 'an-unimportant-value' resource[:revision] = '30' - expects_chdir - provider.expects(:svn).with('--non-interactive', 'switch', '-r', resource.value(:revision), 'an-unimportant-value') + expect_chdir + expect(provider).to receive(:svn).with('--non-interactive', 'switch', '-r', resource.value(:revision), 'an-unimportant-value') provider.source = resource.value(:source) end end end describe 'checking the source property' do before(:each) do - provider.expects(:svn).with('--non-interactive', 'info').returns(fixture(:svn_info)) + allow(provider).to receive(:svn).with('--non-interactive', 'info').and_return(fixture(:svn_info)) end it "uses 'svn info'" do - expects_chdir + expect_chdir expect(provider.source).to eq('http://example.com/svn/trunk') # From URL end end describe 'checking the basic_auth properties' do context 'when basic_auth_username is set and basic_auth_password is not set' do it 'fails' do resource[:source] = 'an-unimportant-value' resource[:basic_auth_username] = 'dummy_user' expect { provider.create }.to raise_error RuntimeError, %r{you must specify the HTTP basic authentication password.+}i end end context 'when basic_auth_username is not set and basic_auth_password is set' do it 'fails' do resource[:source] = 'an-unimportant-value' resource[:basic_auth_password] = 'dummy_pass' expect { provider.create }.to raise_error RuntimeError, %r{you must specify the HTTP .+username.*}i end end end describe 'setting the source property' do context 'with conflict' do it "uses 'svn switch'" do resource[:source] = 'http://example.com/svn/tags/1.0' resource[:conflict] = 'theirs-full' - expects_chdir - provider.expects(:svn).with('--non-interactive', 'switch', '--accept', resource.value(:conflict), resource.value(:source)) + expect_chdir + expect(provider).to receive(:svn).with('--non-interactive', 'switch', '--accept', resource.value(:conflict), resource.value(:source)) provider.source = resource.value(:source) end end context 'without conflict' do it "uses 'svn switch'" do resource[:source] = 'http://example.com/svn/tags/1.0' - expects_chdir - provider.expects(:svn).with('--non-interactive', 'switch', - resource.value(:source)) + expect_chdir + expect(provider).to receive(:svn).with('--non-interactive', 'switch', + resource.value(:source)) provider.source = resource.value(:source) end end end end diff --git a/spec/unit/puppet/type/vcsrepo_spec.rb b/spec/unit/puppet/type/vcsrepo_spec.rb index c65ceda..cbf60da 100755 --- a/spec/unit/puppet/type/vcsrepo_spec.rb +++ b/spec/unit/puppet/type/vcsrepo_spec.rb @@ -1,151 +1,151 @@ #! /usr/bin/env ruby require 'spec_helper' describe Puppet::Type.type(:vcsrepo) do before :each do - Puppet::Type.type(:vcsrepo).stubs(:defaultprovider).returns(providerclass) + allow(Puppet::Type.type(:vcsrepo)).to receive(:defaultprovider).and_return(providerclass) end let(:providerclass) do described_class.provide(:fake_vcsrepo_provider) do attr_accessor :property_hash def create; end def destroy; end def exists? get(:ensure) != :absent end mk_resource_methods has_features :include_paths end end let(:provider) do providerclass.new(name: 'fake-vcs') end let(:resource) do described_class.new(name: '/repo', ensure: :present, source: 'http://example.com/repo/', provider: provider) end let(:ensureprop) do resource.property(:ensure) end let(:sourceprop) do resource.property(:source) end properties = [:ensure, :source] properties.each do |property| it "should have a #{property} property" do expect(described_class.attrclass(property).ancestors).to be_include(Puppet::Property) end end parameters = [:ensure] parameters.each do |parameter| it "should have a #{parameter} parameter" do expect(described_class.attrclass(parameter).ancestors).to be_include(Puppet::Parameter) end end describe "with an include path that starts with a '/'" do it 'raises a Puppet::ResourceError error' do expect { resource[:includes] = ['/path1/file1', '/path2/file2'] }.to raise_error(Puppet::ResourceError, %r{Include path '.*' starts with a '/'}) end end describe 'when using a provider that adds/removes a trailing / to the source' do it 'stays in sync when it leaves it as-is' do sourceprop.should = 'http://example.com/repo/' expect(sourceprop.safe_insync?('http://example.com/repo/')).to eq(true) end it 'stays in sync when it adds a slash' do sourceprop.should = 'http://example.com/repo' expect(sourceprop.safe_insync?('http://example.com/repo/')).to eq(true) end it 'stays in sync when it removes a slash' do sourceprop.should = 'http://example.com/repo/' expect(sourceprop.safe_insync?('http://example.com/repo')).to eq(true) end it 'is out of sync with a different source' do sourceprop.should = 'http://example.com/repo/asdf' expect(sourceprop.safe_insync?('http://example.com/repo')).to eq(false) end end describe 'default resource with required params' do it 'has a valid name parameter' do expect(resource[:name]).to eq('/repo') end it 'has ensure set to present' do expect(resource[:ensure]).to eq(:present) end it 'has path set to /repo' do expect(resource[:path]).to eq('/repo') end defaults = { owner: nil, group: nil, user: nil, revision: nil, } defaults.each_pair do |param, value| it "should have #{param} parameter set to #{value}" do expect(resource[param]).to eq(value) end end end describe 'when changing the ensure' do it 'is in sync if it is :absent and should be :absent' do ensureprop.should = :absent expect(ensureprop.safe_insync?(:absent)).to eq(true) end it 'is in sync if it is :present and should be :present' do ensureprop.should = :present expect(ensureprop.safe_insync?(:present)).to eq(true) end it 'is out of sync if it is :absent and should be :present' do ensureprop.should = :present expect(ensureprop.safe_insync?(:absent)).not_to eq(true) end it 'is out of sync if it is :present and should be :absent' do ensureprop.should = :absent expect(ensureprop.safe_insync?(:present)).not_to eq(true) end end describe 'when running the type it should autorequire packages' do let(:catalog) { Puppet::Resource::Catalog.new } let(:resource) { described_class.new(name: '/foo', provider: provider) } before :each do ['git', 'git-core', 'mercurial', 'subversion'].each do |pkg| catalog.add_resource(Puppet::Type.type(:package).new(name: pkg)) end end it 'requires package packages' do catalog.add_resource(resource) req = resource.autorequire expect(req.size).to eq(4) end end end