Skip to content

Commit

Permalink
Add spec rake test; add spec_helper
Browse files Browse the repository at this point in the history
Change-Id: I20096e4b3009e60f8fc9d3f41ece03dd6a0e739a
  • Loading branch information
David Snyder committed May 1, 2014
1 parent cdbe88d commit d1722e6
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 109 deletions.
105 changes: 11 additions & 94 deletions Rakefile
@@ -1,98 +1,15 @@
#
# Rakefile for Ironfan Pantry
#
# Author:: Nathaniel Eliot
# Copyright:: Copyright (c) 2012 Infochimps, Inc.
# License:: Apache License, Version 2.0
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#

require 'rubygems' unless defined?(Gem)
require 'bundler'
begin
Bundler.setup(:default, :development)
rescue Bundler::BundlerError => e
$stderr.puts e.message
$stderr.puts "Run `bundle install` to install missing gems"
exit e.status_code
end

require 'rake/version_task'
paths = Dir.glob(File.join('cookbooks','*','VERSION'))
cookbooks = paths.map {|path| File.basename(File.split(path)[0]) }
cookbooks.each do |ckbk|
namespace ckbk do
Rake::VersionTask.new do |task|
task.with_git = true
task.filename = File.join('cookbooks',ckbk,'VERSION')
end
end
end

namespace :all do
namespace :version do
desc "Bump all cookbooks to next patch version"
task :bump => cookbooks.map {|ckbk| ckbk+':version:bump' }

namespace :bump do
desc "Bump all cookbooks to next major version"
task :major => cookbooks.map {|ckbk| ckbk+':version:bump:major' }

desc "Bump all cookbooks to next minor version"
task :minor => cookbooks.map {|ckbk| ckbk+':version:bump:minor' }

desc "Bump all cookbooks to next prerelease patch version"
task :pre => cookbooks.map {|ckbk| ckbk+':version:bump:pre' }

namespace :pre do
desc "Bump all cookbooks to next prerelease major version"
task :major => cookbooks.map {|ckbk| ckbk+':version:bump:pre:major' }

desc "Bump all cookbooks to next prerelease minor version"
task :minor => cookbooks.map {|ckbk| ckbk+':version:bump:pre:minor' }
end
end
desc "Run all cookbook specs in their own environment (cookbook_name is optional)"
task :spec,[:cookbook_name] do |t,args|
cookbooks_to_run = args[:cookbook_name] ? [File.join("cookbooks",args[:cookbook_name],"spec")] : Dir["cookbooks/**/spec/"]
spec_helper_path = File.expand_path("spec/spec_helper.rb")
gemfile_path = File.expand_path("Gemfile")
exit_statuses = cookbooks_to_run.map do |cbk_path|
cbk_path = File.join(cbk_path,"..")
sh_command = "cd #{cbk_path}; BUNDLE_GEMFILE=#{gemfile_path} bundle exec rspec -r #{spec_helper_path} --format documentation"
sh(sh_command){ |ok,status| ok}
end
exit exit_statuses.all?
end

desc "Install the postcommit hook that ensures VERSION bumps happen"
task :ensure_postcommit_hook do
hook = <<-eos.gsub(/^ {#{4}}/, '')
#!/usr/bin/env bash
#
# Ensure that all cookbook changes include a bump to the relevant
# cookbook's VERSION file.
#
echo "Looking for version bumps in changed code"
timeout 5s git fetch origin
changes=`git diff --name-only master origin/testing -- cookbooks/*/ | cut -d/ -f2 | sort | uniq`
if [ "x$changes" = "x" ]; then
echo "No cookbook changes between master and testing"
exit 0
fi
for cookbook in $changes; do
if git diff --quiet master origin/testing -- cookbooks/$cookbook/VERSION; then
echo "INFO: changes found without VERSION, bumping version in $cookbook"
bundle exec rake $cookbook:version:bump
fi
done
eos
target = File.join('.git','hooks','post-commit')
File.open(target,'w') {|f| f.write(hook) }
File.chmod(0775,target)
end
task :default => :spec
14 changes: 0 additions & 14 deletions cookbooks/volumes/spec/volumes_spec.rb
@@ -1,17 +1,3 @@
require 'chefspec'

RSpec.configure do |config|
# Specify the Chef log_level (default: :warn)
#config.log_level = :debug

# Specify the operating platform to mock Ohai data from (default: nil)
config.platform = 'ubuntu'

# Specify the operating version to mock Ohai data from (default: nil)
config.version = '12.04'
end


# Information about volumes are supplied by ironfan through various roles
# These settings are from a typical setup, and then altered subtly for
# maximal test coverage
Expand Down
2 changes: 1 addition & 1 deletion cookbooks/zookeeper/spec/install_from_package_spec.rb
Expand Up @@ -3,7 +3,7 @@
describe 'zookeeper::install_from_package' do
let (:chef_run) { ChefSpec::Runner.new.converge('zookeeper::install_from_package') }

it "installs hadoop-zookeeper" do
it "installs zookeeper" do
expect(chef_run).to install_package('zookeeper')
end

Expand Down
11 changes: 11 additions & 0 deletions spec/spec_helper.rb
@@ -0,0 +1,11 @@
require 'chefspec'

COOKBOOK_PATH = ENV['COOKBOOK_PATH'] || File.expand_path("../../cookbooks", __FILE__)

RSpec.configure do |config|
config.cookbook_path = [COOKBOOK_PATH]

config.tty = true
config.color = true
config.order = 'random'
end

0 comments on commit d1722e6

Please sign in to comment.