Permalink
Browse files

Add some chefspec tests for default recipe

  • Loading branch information...
tmatilai committed Mar 21, 2013
1 parent 0c2923a commit 8f61e2559945e76211df1b53eb6de696ce017601
Showing with 61 additions and 1 deletion.
  1. +1 −0 .gitignore
  2. +2 −0 Gemfile
  3. +11 −1 Rakefile
  4. +46 −0 spec/default_spec.rb
  5. +1 −0 spec/spec_helper.rb
View
@@ -2,3 +2,4 @@
/.vagrant
/Berksfile.lock
/Gemfile.lock
+/tmp/
View
@@ -9,5 +9,7 @@ gem 'rake'
gem 'chef', chef_version
group :test do
+ gem 'berkshelf', '~> 1.3'
+ gem 'chefspec', '>= 1.0.0.rc1'
gem 'foodcritic', '~> 1.7'
end
View
@@ -1,7 +1,7 @@
require 'foodcritic'
desc "Run all tests"
-task :default => [:foodcritic, :knife]
+task :default => [:foodcritic, :knife, :chefspec]
FoodCritic::Rake::LintTask.new do |t|
t.options = {:fail_tags => ['correctness']}
@@ -12,3 +12,13 @@ task :knife do
dirname = File.basename(File.expand_path('..', __FILE__))
sh %{knife cookbook test -o .. #{dirname}}
end
+
+desc "Run ChefSpec Unit Tests"
+task :chefspec => :berks do
+ sh %{rspec --color tmp/cookbooks/debian/spec}
+end
+
+desc "Install Berkshelf shims"
+task :berks do
+ sh %{berks install --path=tmp/cookbooks}
+end
View
@@ -0,0 +1,46 @@
+require 'spec_helper'
+
+describe 'debian::default' do
+ context 'on Debian' do
+ let(:chef_run) do
+ ChefSpec::ChefRunner.new(platform: 'debian') do |node|
+ node.automatic_attrs['lsb'] = {'codename' => 'cheese'}
+ end.converge 'debian::default'
+ end
+
+ it 'includes apt recipe' do
+ chef_run.should include_recipe 'apt'
+ end
+
+ it 'triggers apt-get update' do
+ chef_run.should execute_command 'apt-get update'
+ end
+
+ it 'configures /etc/apt/sources.list file' do
+ chef_run.should create_file_with_content '/etc/apt/sources.list',
+ 'deb http://ftp.debian.org/debian cheese main contrib non-free'
+ end
+
+ it 'enables security repository' do
+ chef_run.should include_recipe 'debian::security'
+ end
+
+ it 'does not enable testing repository' do
+ chef_run.should_not include_recipe 'debian::testing'
+ end
+ end
+
+ context 'on non-Debian' do
+ let(:chef_run) do
+ ChefSpec::ChefRunner.new(platform: 'ubuntu').converge 'debian::default'
+ end
+
+ it 'warns' do
+ chef_run.should log 'recipe[debian::default] included in non-Debian platform. Skipping.'
+ end
+
+ it 'does not include apt recipe' do
+ chef_run.should_not include_recipe 'apt'
+ end
+ end
+end
View
@@ -0,0 +1 @@
+require 'chefspec'

0 comments on commit 8f61e25

Please sign in to comment.