Use strainer to isolate and test individual cookbooks

Included:
- Add strainer gem
- Update test-related gems
- Add Strainer file
- Remove run_tests.bash
- Update .gitignore
- Update README file
- Add tailor (ruby style check)

Partial fix for bug 1188345

Change-Id: Iae92a999cdfe230151795fcab5b597faa958274a
This commit is contained in:
sean 2013-06-10 13:43:49 -07:00
parent 7bf4d0151c
commit f8781d13de
7 changed files with 59 additions and 29 deletions

3
.gitignore vendored
View File

@ -1,3 +1,2 @@
.bundle
.cookbooks/
.bundle/
Berksfile.lock

25
.tailor Normal file
View File

@ -0,0 +1,25 @@
Tailor.config do |config|
config.formatters "text"
config.file_set '**/*.rb' do |style|
style.max_line_length 80, level: :off
style.allow_camel_case_methods false, level: :error
style.allow_hard_tabs false, level: :error
style.allow_screaming_snake_case_classes false, level: :error
style.allow_trailing_line_spaces false, level: :error
style.allow_invalid_ruby false, level: :warn
style.indentation_spaces 2, level: :error
style.max_code_lines_in_class 300, level: :error
style.max_code_lines_in_method 30, level: :error
style.spaces_after_comma 1, level: :error
style.spaces_after_lbrace 1, level: :error
style.spaces_after_lbracket 0, level: :error
style.spaces_after_lparen 0, level: :error
style.spaces_before_comma 0, level: :error
style.spaces_before_lbrace 1, level: :error
style.spaces_before_rbrace 1, level: :error
style.spaces_before_rbracket 0, level: :error
style.spaces_before_rparen 0, level: :error
style.spaces_in_empty_braces 0, level: :error
style.trailing_newlines 1, level: :error
end
end

View File

@ -2,6 +2,8 @@ source "https://rubygems.org"
gem "chef", "~> 11.4.4"
gem "json", "<= 1.7.7" # chef 11 dependency
gem "berkshelf", "~> 1.4.0"
gem "berkshelf", "~> 1.4.5"
gem "chefspec", "~> 1.2.0"
gem "foodcritic", "~> 2.1.0"
gem "foodcritic"
gem "strainer"
gem "tailor"

View File

@ -88,6 +88,7 @@ GEM
ipaddress (0.8.0)
json (1.7.7)
little-plugger (1.1.3)
log_switch (0.4.0)
logging (1.6.2)
little-plugger (>= 1.1.3)
mime-types (1.23)
@ -164,9 +165,19 @@ GEM
wasabi (~> 1.0)
solve (0.4.4)
json
strainer (2.1.0)
berkshelf (~> 1.3)
systemu (2.5.2)
tailor (1.2.1)
log_switch (>= 0.3.0)
term-ansicolor (>= 1.0.5)
text-table (>= 1.2.2)
term-ansicolor (1.2.2)
tins (~> 0.8)
text-table (1.2.3)
thor (0.18.1)
timers (1.1.0)
tins (0.8.0)
treetop (1.4.14)
polyglot
polyglot (>= 0.3.1)
@ -187,8 +198,10 @@ PLATFORMS
ruby
DEPENDENCIES
berkshelf (~> 1.4.0)
berkshelf (~> 1.4.5)
chef (~> 11.4.4)
chefspec (~> 1.2.0)
foodcritic (~> 2.1.0)
foodcritic
json (<= 1.7.7)
strainer
tailor

View File

@ -164,11 +164,15 @@ in your recipe.
Testing
=====
This cookbook is using [ChefSpec](https://github.com/acrmp/chefspec) for
testing. Should run the following before commiting. It will run your tests,
and check for lint errors.
This cookbook uses [bundler](http://gembundler.com/), [berkshelf](http://berkshelf.com/), and [strainer](https://github.com/customink/strainer) to isolate dependencies and run tests.
$ ./run_tests.bash
Tests are defined in Strainerfile.
To run tests:
$ bundle install # install gem dependencies
$ bundle exec berks install # install cookbook dependencies
$ bundle exec strainer test # run tests
License and Author
==================
@ -179,6 +183,7 @@ License and Author
| **Author** | John Dewey (<jdewey@att.com>) |
| **Author** | Matt Ray (<matt@opscode.com>) |
| **Author** | Craig Tracey (<craigtracey@gmail.com>) |
| **Author** | Sean Gallagher (<sean.gallagher@att.com>) |
| | |
| **Copyright** | Copyright (c) 2012-2013, AT&T Services, Inc. |
| **Copyright** | Copyright (c) 2013, Opscode, Inc. |

5
Strainerfile Normal file
View File

@ -0,0 +1,5 @@
# Strainerfile
tailor: bundle exec tailor
knife test: bundle exec knife cookbook test $COOKBOOK
foodcritic: bundle exec foodcritic -f any -t ~FC003 -t ~FC023 $SANDBOX/$COOKBOOK
chefspec: bundle exec rspec $SANDBOX/$COOKBOOK/spec

View File

@ -1,19 +0,0 @@
#!/usr/bin/env bash
# A script to run tests locally before committing.
set -e
COOKBOOK=$(awk '/^name/ {print $NF}' metadata.rb |tr -d \"\')
if [ -z $COOKBOOK ]; then
echo "Cookbook name not defined in metadata.rb"
exit 1
fi
BUNDLE_PATH=${BUNDLE_PATH:-.bundle}
BERKSHELF_PATH=${BERKSHELF_PATH:-.cookbooks}
bundle install --path=${BUNDLE_PATH}
bundle exec berks install --path=${BERKSHELF_PATH}
bundle exec foodcritic -f any -t ~FC003 -t ~FC023 ${BERKSHELF_PATH}/${COOKBOOK}
bundle exec rspec ${BERKSHELF_PATH}/${COOKBOOK}