Permalink
Browse files

Merge pull request #4 from jimhopp/expect

Convert to rspec expect syntax
  • Loading branch information...
2 parents 58cf922 + b8651e3 commit 7d7b76280e52301b844dbd1d595e307f006120c4 @jimhopp committed Apr 22, 2013
View
@@ -1,4 +1,4 @@
# A sample Gemfile
-source "http://rubygems.org"
+source "https://rubygems.org"
gem "chefspec", "~>0.9"
View
@@ -1,5 +1,5 @@
GEM
- remote: http://rubygems.org/
+ remote: https://rubygems.org/
specs:
builder (3.1.4)
bunny (0.7.9)
@@ -9,3 +9,7 @@
package 'git-core' do
action :install
end
+
+log "this message is at INFO" do
+ level :info
+end
@@ -0,0 +1,15 @@
+#
+# Cookbook Name:: mytestcookbook
+# Recipe:: log_level
+#
+# Copyright 2012, YOUR_COMPANY_NAME
+#
+# All rights reserved - Do Not Redistribute
+#
+
+Chef::Log.warn("This message is at WARN level")
+Chef::Log.info("This message is at INFO level")
+
+log "this message is at INFO" do
+ level :info
+end
@@ -5,3 +5,7 @@
gem_package 'mongo' do
action :install
end
+
+chef_gem 'statsd' do
+ action :install
+end
@@ -5,13 +5,20 @@
it 'chefspec converge picks up default attr values' do
runner = ChefSpec::ChefRunner.new
runner.converge 'mytestcookbook::default'
- runner.node.mytestcookbook.attr_a.should eq 'default value'
+ expect(runner.node.mytestcookbook.attr_a).to eq 'default value'
end
it 'can set values for default attributes' do
runner = ChefSpec::ChefRunner.new do |node|
node.set["mytestcookbook"] = { :attr_a => 'bar' }
end
runner.converge 'mytestcookbook::default'
- runner.node.mytestcookbook.attr_a.should eq 'bar'
+ expect(runner.node.mytestcookbook.attr_a).to eq 'bar'
+ end
+ it 'can set values for ohai attributes' do
+ runner = ChefSpec::ChefRunner.new do |node|
+ node.automatic_attrs["platform"] = "precise"
+ end
+ runner.converge 'mytestcookbook::default'
+ expect(runner.node.automatic_attrs.platform).to eq 'precise'
end
end
@@ -2,9 +2,9 @@
require 'chefspec'
describe 'cookbook_file tests' do
- let (:chef_run) { ChefSpec::ChefRunner.new.converge 'mytestcookbook::cookbook_files' }
+ let (:chef_run) { ChefSpec::ChefRunner.new.converge 'mytestcookbook::cookbook_files' }
it 'cookbook file copied with correct content' do
- chef_run.should create_cookbook_file 'my-test-cookbook-file.cnf'
- chef_run.should create_file_with_content 'my-test-cookbook-file.cnf', 'some useful content'
+ expect(chef_run).to create_cookbook_file 'my-test-cookbook-file.cnf'
+ expect(chef_run).to create_file_with_content 'my-test-cookbook-file.cnf', 'some useful content'
end
end
@@ -1,9 +1,9 @@
-require 'bundler/setup'
+require 'bundler/setup'
require 'chefspec'
describe 'mytestcookbook::default' do
let (:chef_run) { ChefSpec::ChefRunner.new.converge 'mytestcookbook::default' }
it 'should always install git-core' do
- chef_run.should install_package 'git-core'
+ expect(chef_run).to install_package 'git-core'
end
end
@@ -2,9 +2,9 @@
require 'chefspec'
describe 'file tests' do
- let (:chef_run) { ChefSpec::ChefRunner.new.converge 'mytestcookbook::files' }
+ let (:chef_run) { ChefSpec::ChefRunner.new.converge 'mytestcookbook::files' }
it 'file copied with correct content' do
- chef_run.should create_file 'my-test-file.cnf'
- chef_run.should create_file_with_content 'my-test-file.cnf', 'some useful content'
+ expect(chef_run).to create_file 'my-test-file.cnf'
+ expect(chef_run).to create_file_with_content 'my-test-file.cnf', 'some useful content'
end
end
@@ -2,8 +2,8 @@
require 'chefspec'
describe 'include_recipe tests' do
- let (:chef_run) { ChefSpec::ChefRunner.new.converge 'mytestcookbook::include_recipes' }
+ let (:chef_run) { ChefSpec::ChefRunner.new.converge 'mytestcookbook::include_recipes' }
it 'includes another recipe' do
- chef_run.should include_recipe 'mytestcookbook::included_recipe'
+ expect(chef_run).to include_recipe 'mytestcookbook::included_recipe'
end
end
@@ -1,20 +1,18 @@
-require 'bundler/setup'
+require 'bundler/setup'
require 'chefspec'
-describe 'mytestcookbook::default' do
+describe 'mytestcookbook::log_level' do
it 'note that warning log msg shows up but not info' do
- chef_run = ChefSpec::ChefRunner.new.converge 'mytestcookbook::default'
- chef_run.should install_package 'git-core'
+ chef_run = ChefSpec::ChefRunner.new.converge 'mytestcookbook::log_level'
Chef::Log.warn("warn msg shows up but not info")
- Chef::Log.info("this msg does not appear")
end
it 'info and warning log msgs show up' do
- # note setting log_level in the CherRunner initializer.
+ # note setting log_level in the CherRunner initializer.
# 'info' messages include all of the execution messages
- chef_run = ChefSpec::ChefRunner.new(:log_level => :info).converge 'mytestcookbook::default'
- chef_run.should install_package 'git-core'
+ chef_run = ChefSpec::ChefRunner.new(:log_level => :info).converge 'mytestcookbook::log_level'
Chef::Log.warn("warn msg shows up as well as info")
- Chef::Log.info("this msg does not appear")
+ expect(chef_run).to log "this message is at INFO"
end
+
end
@@ -10,12 +10,12 @@
runner.converge 'mytestcookbook::lwrp'
}
it 'should install foo' do
- chef_run.should install_package 'foo'
+ expect(chef_run).to install_package 'foo'
end
it 'executes stuff' do
cmd = 'echo "hello!"'
runner.node.set["mytestcookbook"] = { :cmd => cmd }
runner.converge 'mytestcookbook::lwrp'
- runner.should execute_command cmd
+ expect(runner).to execute_command cmd
end
end
@@ -4,6 +4,12 @@
describe 'mytestcookbook::packages' do
let (:chef_run) { ChefSpec::ChefRunner.new.converge 'mytestcookbook::packages' }
it 'should always install git-core' do
- chef_run.should install_package 'git-core'
+ expect(chef_run).to install_package 'git-core'
+ end
+ it 'should always install mongo gem' do
+ expect(chef_run).to install_gem_package 'mongo'
+ end
+ it 'should install statsd gem for use during chef run' do
+ expect(chef_run).to install_chef_gem 'statsd'
end
end
@@ -1,11 +1,11 @@
-require 'bundler/setup'
+require 'bundler/setup'
require 'chefspec'
describe 'stub out databags' do
let (:chef_run) { ChefSpec::ChefRunner.new.converge 'mytestcookbook::databag_demo' }
it 'stub out data_bag_item' do
Chef::Recipe.any_instance.stub(:data_bag_item).and_return(Hash.new)
Chef::Recipe.any_instance.stub(:data_bag_item).with("my_data_bag", "my_item").and_return({"id" => "my_item", "fun data" => "whatever"})
- chef_run.should create_file_with_content('/etc/my_file', 'whatever')
+ expect(chef_run).to create_file_with_content('/etc/my_file', 'whatever')
end
end
@@ -1,9 +1,9 @@
-require 'bundler/setup'
+require 'bundler/setup'
require 'chefspec'
describe 'template tests' do
- let (:chef_run) { ChefSpec::ChefRunner.new.converge 'mytestcookbook::template_test' }
+ let (:chef_run) { ChefSpec::ChefRunner.new.converge 'mytestcookbook::template_test' }
it 'template generated with correct attr value' do
- chef_run.should create_file_with_content '/etc/my-template', 'bar'
+ expect(chef_run).to create_file_with_content '/etc/my-template', 'bar'
end
end

0 comments on commit 7d7b762

Please sign in to comment.