From 797f6d1a31da300231722ef091728f458fd0d8af Mon Sep 17 00:00:00 2001 From: Arnold Krille Date: Mon, 16 Dec 2013 18:21:52 +0100 Subject: [PATCH 1/5] Depend on chefspec 3.1.0.beta.1 --- Gemfile | 2 +- spec/spec_helper.rb | 10 ++++++---- 2 files changed, 7 insertions(+), 5 deletions(-) diff --git a/Gemfile b/Gemfile index 6f5b9fe..f1449b4 100644 --- a/Gemfile +++ b/Gemfile @@ -1,7 +1,7 @@ source 'https://rubygems.org' gem 'berkshelf', '~> 2.0' -gem 'chefspec', '~> 2.0' +gem 'chefspec', '~> 3.1.0.beta.1' gem 'foodcritic', '~> 3.0' gem 'rubocop', '~> 0.12' diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index e0c3685..f3fbdfe 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -1,6 +1,8 @@ -require 'berkshelf' +#require 'berkshelf' require 'chefspec' +require 'chefspec/deprecations' +require 'chefspec/berkshelf' -Berkshelf.ui.mute do - Berkshelf::Berksfile.from_file('Berksfile').install(path: 'vendor/cookbooks') -end +#Berkshelf.ui.mute do +# Berkshelf::Berksfile.from_file('Berksfile').install(path: 'vendor/cookbooks') +#end From 23098b354c7fed8affc9b5c280a7dcebc95161da Mon Sep 17 00:00:00 2001 From: Arnold Krille Date: Mon, 16 Dec 2013 18:22:38 +0100 Subject: [PATCH 2/5] port to chefspec3.1 --- spec/spec_helper.rb | 5 ----- spec/unit/recipes/client_spec.rb | 8 ++++---- spec/unit/recipes/server_spec.rb | 17 ++++++++++++++++- 3 files changed, 20 insertions(+), 10 deletions(-) diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index f3fbdfe..2251d5d 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -1,8 +1,3 @@ -#require 'berkshelf' require 'chefspec' -require 'chefspec/deprecations' require 'chefspec/berkshelf' -#Berkshelf.ui.mute do -# Berkshelf::Berksfile.from_file('Berksfile').install(path: 'vendor/cookbooks') -#end diff --git a/spec/unit/recipes/client_spec.rb b/spec/unit/recipes/client_spec.rb index e2b9e40..7d36a92 100644 --- a/spec/unit/recipes/client_spec.rb +++ b/spec/unit/recipes/client_spec.rb @@ -1,7 +1,7 @@ require 'spec_helper' describe 'munin::client' do - let(:chef_run) { ChefSpec::ChefRunner.new.converge(described_recipe) } + let(:chef_run) { ChefSpec::Runner.new.converge(described_recipe) } it 'installs the munin-node package' do expect(chef_run).to install_package('munin-node') @@ -12,11 +12,11 @@ expect(template).to be expect(template.source).to eq('munin-node.conf.erb') expect(template.mode).to eq('0644') - expect(template).to notify('service[munin-node]', :restart) + notify('service[munin-node]').to(:restart) end it 'starts and enables the service' do - expect(chef_run).to start_service('munin-node') - expect(chef_run).to set_service_to_start_on_boot('munin-node') + notify('service[munin-node]').to(:start) + expect(chef_run).to enable_service('munin-node') end end diff --git a/spec/unit/recipes/server_spec.rb b/spec/unit/recipes/server_spec.rb index c0b3574..1318340 100644 --- a/spec/unit/recipes/server_spec.rb +++ b/spec/unit/recipes/server_spec.rb @@ -1,7 +1,13 @@ require 'spec_helper' describe 'munin::server' do - let(:chef_run) { ChefSpec::ChefRunner.new.converge(described_recipe) } + let(:chef_run) do + run = ChefSpec::Runner.new do |node| + node.set['munin']['server_auth_method'] = 'htpasswd' + end + run.converge(described_recipe) + return run + end before do Chef::Recipe.any_instance.stub(:data_bag).with('users').and_return(%w[seth nathen]) @@ -34,4 +40,13 @@ pending 'This recipe is pretty much untestable' end end + + context 'server-parts' do + it 'creates a server config' do + expect(chef_run).to render_file('/etc/munin/munin.conf').with_content(/generated by Chef/) + end + it 'finds itself as munin-node as fallback' do + expect(chef_run).to render_file('/etc/munin/munin.conf').with_content(/chefspec.local/) + end + end end From 4bb5ac339bac8dae62d7d3dfc2af79e1a50ce742 Mon Sep 17 00:00:00 2001 From: Arnold Krille Date: Mon, 16 Dec 2013 18:32:58 +0100 Subject: [PATCH 3/5] Make rubocop happy. --- spec/spec_helper.rb | 1 - 1 file changed, 1 deletion(-) diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index 2251d5d..1dd5126 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -1,3 +1,2 @@ require 'chefspec' require 'chefspec/berkshelf' - From 170fb603cfcf4b5c42c5444f3c0a66b1a3ebc0cf Mon Sep 17 00:00:00 2001 From: Arnold Krille Date: Tue, 7 Jan 2014 14:54:27 +0100 Subject: [PATCH 4/5] adopt required chefspec version --- Gemfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Gemfile b/Gemfile index f1449b4..8d55beb 100644 --- a/Gemfile +++ b/Gemfile @@ -1,7 +1,7 @@ source 'https://rubygems.org' gem 'berkshelf', '~> 2.0' -gem 'chefspec', '~> 3.1.0.beta.1' +gem 'chefspec', '~> 3.1.0' gem 'foodcritic', '~> 3.0' gem 'rubocop', '~> 0.12' From 53f402a82b251945260cd8d129d2ebe1d24e82a8 Mon Sep 17 00:00:00 2001 From: Arnold Krille Date: Tue, 28 Jan 2014 22:55:56 +0100 Subject: [PATCH 5/5] Incorporate most of sethvargos comments - depend on chefspec ~>3.1 instead of ~>3.1.0 - simplify the preparation of the runner in server_spec.rb - linebreaks for server_spec.rb - improve the template and service tests in client_spec.rb --- Gemfile | 2 +- spec/unit/recipes/client_spec.rb | 12 +++++++----- spec/unit/recipes/server_spec.rb | 14 ++++++++------ 3 files changed, 16 insertions(+), 12 deletions(-) diff --git a/Gemfile b/Gemfile index 8d55beb..7e87ca7 100644 --- a/Gemfile +++ b/Gemfile @@ -1,7 +1,7 @@ source 'https://rubygems.org' gem 'berkshelf', '~> 2.0' -gem 'chefspec', '~> 3.1.0' +gem 'chefspec', '~> 3.1' gem 'foodcritic', '~> 3.0' gem 'rubocop', '~> 0.12' diff --git a/spec/unit/recipes/client_spec.rb b/spec/unit/recipes/client_spec.rb index 7d36a92..783d5f2 100644 --- a/spec/unit/recipes/client_spec.rb +++ b/spec/unit/recipes/client_spec.rb @@ -8,15 +8,17 @@ end it 'writes the munin-node.conf' do + expect(chef_run).to create_template('/etc/munin/munin-node.conf').with( + source: 'munin-node.conf.erb', + mode: '0644' + ) + template = chef_run.template('/etc/munin/munin-node.conf') - expect(template).to be - expect(template.source).to eq('munin-node.conf.erb') - expect(template.mode).to eq('0644') - notify('service[munin-node]').to(:restart) + expect(template).to notify('service[munin-node]').to(:restart) end it 'starts and enables the service' do - notify('service[munin-node]').to(:start) + expect(chef_run).to start_service('munin-node') expect(chef_run).to enable_service('munin-node') end end diff --git a/spec/unit/recipes/server_spec.rb b/spec/unit/recipes/server_spec.rb index 1318340..24b6219 100644 --- a/spec/unit/recipes/server_spec.rb +++ b/spec/unit/recipes/server_spec.rb @@ -2,11 +2,9 @@ describe 'munin::server' do let(:chef_run) do - run = ChefSpec::Runner.new do |node| + ChefSpec::Runner.new do |node| node.set['munin']['server_auth_method'] = 'htpasswd' - end - run.converge(described_recipe) - return run + end.converge(described_recipe) end before do @@ -43,10 +41,14 @@ context 'server-parts' do it 'creates a server config' do - expect(chef_run).to render_file('/etc/munin/munin.conf').with_content(/generated by Chef/) + expect(chef_run).to render_file('/etc/munin/munin.conf').with_content( + /generated by Chef/ + ) end it 'finds itself as munin-node as fallback' do - expect(chef_run).to render_file('/etc/munin/munin.conf').with_content(/chefspec.local/) + expect(chef_run).to render_file('/etc/munin/munin.conf').with_content( + /chefspec.local/ + ) end end end