From f308ce451412c0569a1c4b726f185fa4cc1a5b3e Mon Sep 17 00:00:00 2001 From: Melissa Stone Date: Fri, 18 May 2018 10:36:33 -0700 Subject: (maint) Bump pdk to 1.5.0 --- spec/spec_helper.rb | 6 ++++++ 1 file changed, 6 insertions(+) (limited to 'spec') diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index efd225b..e117192 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -1,3 +1,4 @@ + require 'puppetlabs_spec_helper/module_spec_helper' require 'rspec-puppet-facts' @@ -27,4 +28,9 @@ 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 end -- cgit v1.2.3 From 99b8aef830b2eabaf3a217eb08da6deb12e5f8c7 Mon Sep 17 00:00:00 2001 From: Melissa Stone Date: Fri, 18 May 2018 10:41:13 -0700 Subject: (maint) Mock with rspec not mocha --- .sync.yml | 3 +++ spec/shared_behaviours/all_parsedfile_providers.rb | 2 +- spec/spec_helper.rb | 3 +++ spec/unit/type/mailalias_spec.rb | 4 ++-- 4 files changed, 9 insertions(+), 3 deletions(-) (limited to 'spec') diff --git a/.sync.yml b/.sync.yml index 367f666..34b1c2f 100644 --- a/.sync.yml +++ b/.sync.yml @@ -26,3 +26,6 @@ Gemfile: Rakefile: requires: - puppet-lint/tasks/puppet-lint + +spec/spec_helper.rb: + mock_with: ':rspec' diff --git a/spec/shared_behaviours/all_parsedfile_providers.rb b/spec/shared_behaviours/all_parsedfile_providers.rb index d697a14..1701fe3 100644 --- a/spec/shared_behaviours/all_parsedfile_providers.rb +++ b/spec/shared_behaviours/all_parsedfile_providers.rb @@ -5,7 +5,7 @@ shared_examples_for 'all parsedfile providers' do |provider, *files| files.flatten.each do |file| it "should rewrite #{file} reasonably unchanged" do - provider.stubs(:default_target).returns(file) + allow(provider).to receive(:default_target).and_return(file) provider.prefetch text = provider.to_file(provider.target_records(file)) diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index e117192..b71d71e 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -1,3 +1,6 @@ +RSpec.configure do |c| + c.mock_with :rspec +end require 'puppetlabs_spec_helper/module_spec_helper' require 'rspec-puppet-facts' diff --git a/spec/unit/type/mailalias_spec.rb b/spec/unit/type/mailalias_spec.rb index 1fb195e..80b838c 100644 --- a/spec/unit/type/mailalias_spec.rb +++ b/spec/unit/type/mailalias_spec.rb @@ -29,13 +29,13 @@ describe Puppet::Type.type(:mailalias) do it 'tries and set the recipient when it does the sync' do expect(recipient_resource.retrieve_resource[:recipient]).to eq(:absent) - recipient_resource.property(:recipient).expects(:set).with(['yay']) + expect(recipient_resource.property(:recipient)).to receive(:set).with(['yay']) recipient_resource.property(:recipient).sync end it 'tries and set the included file when it does the sync' do expect(file_resource.retrieve_resource[:file]).to eq(:absent) - file_resource.property(:file).expects(:set).with(tmpfile_path) + expect(file_resource.property(:file)).to receive(:set).with(tmpfile_path) file_resource.property(:file).sync end -- cgit v1.2.3 From e55b0f02e3e4ef300a5c3e96caf755f518d91c4b Mon Sep 17 00:00:00 2001 From: Melissa Stone Date: Fri, 18 May 2018 11:28:42 -0700 Subject: (maint) Update the acceptance tests Prior to this commit, the acceptance tests for mailalias were broken up in a way that was not logical. The tests had been broken up simply following the 'steps' from the previous iteration. This new structure did not work, since later steps were dependent on earlier steps. The tests could not be run in isolation. This commit changes the test set up so that we can more easily run tests in isolation and in random order. --- spec/acceptance/tests/create_spec.rb | 6 +++--- spec/acceptance/tests/destroy_spec.rb | 8 ++++---- spec/acceptance/tests/modify_spec.rb | 9 ++++----- 3 files changed, 11 insertions(+), 12 deletions(-) (limited to 'spec') diff --git a/spec/acceptance/tests/create_spec.rb b/spec/acceptance/tests/create_spec.rb index 82adfec..80fe8d3 100644 --- a/spec/acceptance/tests/create_spec.rb +++ b/spec/acceptance/tests/create_spec.rb @@ -16,13 +16,13 @@ RSpec.context 'Mailalias: should create an email alias' do end non_windows_agents.each do |agent| - it 'creates a mailalias with puppet' do + it 'creates a mailalias resource' do + # create a mailalias with puppet args = ['ensure=present', 'recipient="foo,bar,baz"'] on(agent, puppet_resource('mailalias', name, args)) - end - it 'verifies the alias exists' do + # verify the alias exists on(agent, 'cat /etc/aliases') do |res| assert_match(%r{#{name}:.*foo,bar,baz}, res.stdout, 'mailalias not in aliases file') end diff --git a/spec/acceptance/tests/destroy_spec.rb b/spec/acceptance/tests/destroy_spec.rb index 0f805a5..a5cb122 100644 --- a/spec/acceptance/tests/destroy_spec.rb +++ b/spec/acceptance/tests/destroy_spec.rb @@ -1,6 +1,6 @@ require 'spec_helper_acceptance' -RSpec.context 'should delete an email alias' do +RSpec.context 'Mailalias: should delete an email alias' do name = "pl#{rand(999_999).to_i}" before(:all) do @@ -26,13 +26,13 @@ RSpec.context 'should delete an email alias' do end non_windows_agents.each do |agent| - it 'deletes the aliases database with puppet' do + it 'deletes a mailalias resource' do + # delete the aliases database with puppet args = ['ensure=absent', 'recipient="foo,bar,baz"'] on(agent, puppet_resource('mailalias', name, args)) - end - it 'verifies the alias is absent' do + # verify the alias is absent on(agent, 'cat /etc/aliases') do |res| assert_no_match(%r{#{name}:.*foo,bar,baz}, res.stdout, 'mailalias was not removed from aliases file') end diff --git a/spec/acceptance/tests/modify_spec.rb b/spec/acceptance/tests/modify_spec.rb index f4ea7bf..24903b6 100644 --- a/spec/acceptance/tests/modify_spec.rb +++ b/spec/acceptance/tests/modify_spec.rb @@ -1,11 +1,10 @@ require 'spec_helper_acceptance' -RSpec.context 'should modify an email alias' do +RSpec.context 'Mailalias: should modify an email alias' do name = "pl#{rand(999_999).to_i}" before(:all) do non_windows_agents.each do |agent| - #------- SETUP -------# # (setup) backup alias file on(agent, 'cp /etc/aliases /tmp/aliases', acceptable_exit_codes: [0, 1]) @@ -27,13 +26,13 @@ RSpec.context 'should modify an email alias' do end non_windows_agents.each do |agent| - it 'modifies the aliases database with puppet' do + it 'modifies an existing mailalias resource' do + # modify the aliases database with puppet args = ['ensure=present', 'recipient="foo,bar,baz,blarvitz"'] on(agent, puppet_resource('mailalias', name, args)) - end - it 'verifies the updated alias is present' do + # verify the updated alias is present on(agent, 'cat /etc/aliases') do |res| assert_match(%r{#{name}:.*foo,bar,baz,blarvitz}, res.stdout, 'updated mailalias not in aliases file') end -- cgit v1.2.3 From 900733b1bd4b4ccc2381da28314ce367aad6c508 Mon Sep 17 00:00:00 2001 From: Melissa Stone Date: Mon, 16 Jul 2018 16:02:39 -0700 Subject: (maint) Ensure module is installed for testing `hosts_as` takes a role type, not an array of hosts. Unfortunately, `install_module_on` only takes one host as an argument. We were lucky that `hosts_as('default')` was returning only one host, but we should be explicitly installing this on each host individually. --- spec/spec_helper_acceptance.rb | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) (limited to 'spec') diff --git a/spec/spec_helper_acceptance.rb b/spec/spec_helper_acceptance.rb index 0adde24..e7060a0 100644 --- a/spec/spec_helper_acceptance.rb +++ b/spec/spec_helper_acceptance.rb @@ -17,7 +17,9 @@ RSpec.configure do |c| c.before :suite do unless ENV['BEAKER_provision'] == 'no' run_puppet_install_helper - install_module_on(hosts_as(hosts)) + hosts.each do |host| + install_module_on(host) + end install_module_dependencies_on(hosts) end end -- cgit v1.2.3 From d2c9b0c3ca4f62b62b6679758f9de28d1d697aaa Mon Sep 17 00:00:00 2001 From: Josh Cooper Date: Tue, 17 Jul 2018 20:03:13 -0700 Subject: Pass hosts array to install_modules_on --- spec/spec_helper_acceptance.rb | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) (limited to 'spec') diff --git a/spec/spec_helper_acceptance.rb b/spec/spec_helper_acceptance.rb index e7060a0..24d3b9d 100644 --- a/spec/spec_helper_acceptance.rb +++ b/spec/spec_helper_acceptance.rb @@ -17,9 +17,7 @@ RSpec.configure do |c| c.before :suite do unless ENV['BEAKER_provision'] == 'no' run_puppet_install_helper - hosts.each do |host| - install_module_on(host) - end + install_module_on(hosts) install_module_dependencies_on(hosts) end end -- cgit v1.2.3