From 5921be4a25e017495d534d90d178c00f54da6cc2 Mon Sep 17 00:00:00 2001 From: Joe Stump Date: Fri, 27 Dec 2013 17:42:00 -0800 Subject: [PATCH 1/3] Added a Travis config. Added matchers for chefspec. Added a few chefspec tests for python::default. --- .travis.yml | 7 +++++++ Gemfile | 14 ++------------ Rakefile | 5 +++++ libraries/matchers.rb | 25 +++++++++++++++++++++++++ spec/default_spec.rb | 23 +++++++++++++++++++++++ spec/spec_helper.rb | 2 ++ 6 files changed, 64 insertions(+), 12 deletions(-) create mode 100644 .travis.yml create mode 100644 Rakefile create mode 100644 libraries/matchers.rb create mode 100644 spec/default_spec.rb create mode 100644 spec/spec_helper.rb diff --git a/.travis.yml b/.travis.yml new file mode 100644 index 0000000..bfcd8b4 --- /dev/null +++ b/.travis.yml @@ -0,0 +1,7 @@ +rvm: + - 1.9.3 + - 2.0.0 +before_script: + - bundle exec berks install +script: + - bundle exec foodcritic -f any . diff --git a/Gemfile b/Gemfile index 2fea7a8..90bf270 100644 --- a/Gemfile +++ b/Gemfile @@ -1,15 +1,5 @@ source 'https://rubygems.org' -gem 'rake' -gem 'rspec' gem 'foodcritic' -gem 'berkshelf' -gem 'thor-foodcritic' -gem 'vagrant-wrapper' - -group :integration do - gem 'test-kitchen', :git => "git://github.com/opscode/test-kitchen.git" - gem 'kitchen-vagrant', :git => "git://github.com/opscode/kitchen-vagrant.git" - gem 'kitchen-ec2', :git => "git://github.com/opscode/kitchen-ec2.git" - gem 'kitchen-lxc', :git => "https://github.com/portertech/kitchen-lxc.git", :tag => 'v0.0.1.beta2' -end +gem 'berkshelf', '~> 2.0' +gem 'chefspec', '~> 3.0' diff --git a/Rakefile b/Rakefile new file mode 100644 index 0000000..70a846d --- /dev/null +++ b/Rakefile @@ -0,0 +1,5 @@ +require 'rspec/core/rake_task' + +RSpec::Core::RakeTask.new(:spec) + +task :default => :spec diff --git a/libraries/matchers.rb b/libraries/matchers.rb new file mode 100644 index 0000000..bb0a94c --- /dev/null +++ b/libraries/matchers.rb @@ -0,0 +1,25 @@ +if defined?(ChefSpec) + def install_python_pip(package_name) + ChefSpec::Matchers::ResourceMatcher.new(:python_pip, :install, package_name) + end + + def upgrade_python_pip(package_name) + ChefSpec::Matchers::ResourceMatcher.new(:python_pip, :upgrade, package_name) + end + + def remove_python_pip(package_name) + ChefSpec::Matchers::ResourceMatcher.new(:python_pip, :remove, package_name) + end + + def purge_python_pip(package_name) + ChefSpec::Matchers::ResourceMatcher.new(:python_pip, :purge, package_name) + end + + def create_python_virtualenv(virtualenv_name) + ChefSpec::Matchers::ResourceMatcher.new(:python_virtualenv, :create, virtualenv_name) + end + + def delete_python_virtualenv(virtualenv_name) + ChefSpec::Matchers::ResourceMatcher.new(:python_virtualenv, :delete, virtualenv_name) + end +end diff --git a/spec/default_spec.rb b/spec/default_spec.rb new file mode 100644 index 0000000..4eda06b --- /dev/null +++ b/spec/default_spec.rb @@ -0,0 +1,23 @@ +require 'spec_helper' + +describe 'python::default' do + let :chef_run do + ChefSpec::Runner.new(platform: 'ubuntu', version: '12.04').converge described_recipe + end + + before do + stub_command("/usr/bin/python -c 'import setuptools'").and_return(true) + end + + it 'includes python::package by default' do + expect(chef_run).to include_recipe('python::package') + end + + it 'includes python::pip' do + expect(chef_run).to include_recipe('python::pip') + end + + it 'includes python::virtualenv' do + expect(chef_run).to include_recipe('python::virtualenv') + end +end diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb new file mode 100644 index 0000000..1dd5126 --- /dev/null +++ b/spec/spec_helper.rb @@ -0,0 +1,2 @@ +require 'chefspec' +require 'chefspec/berkshelf' From 679c712fcf88781f830236a1dd370b6874814368 Mon Sep 17 00:00:00 2001 From: Joe Stump Date: Fri, 27 Dec 2013 18:11:44 -0800 Subject: [PATCH 2/3] Set the language in Travis. --- .travis.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.travis.yml b/.travis.yml index bfcd8b4..66c9574 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,3 +1,4 @@ +language: ruby rvm: - 1.9.3 - 2.0.0 From f3720ccd861e995219f323fa0d02f2642ce27ea4 Mon Sep 17 00:00:00 2001 From: Joe Stump Date: Fri, 27 Dec 2013 18:17:37 -0800 Subject: [PATCH 3/3] Fixed overriding the script call. --- .travis.yml | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/.travis.yml b/.travis.yml index 66c9574..21b4bce 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,8 +1,7 @@ language: ruby rvm: - - 1.9.3 - - 2.0.0 + - 1.9.3 + - 2.0.0 before_script: - - bundle exec berks install -script: - - bundle exec foodcritic -f any . + - bundle exec berks install + - bundle exec foodcritic -f any .