From f8781d13de30fb3a191e97e91b13a3ccac139d6f Mon Sep 17 00:00:00 2001 From: sean Date: Mon, 10 Jun 2013 13:43:49 -0700 Subject: [PATCH] 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 --- .gitignore | 3 +-- .tailor | 25 +++++++++++++++++++++++++ Gemfile | 6 ++++-- Gemfile.lock | 17 +++++++++++++++-- README.md | 13 +++++++++---- Strainerfile | 5 +++++ run_tests.bash | 19 ------------------- 7 files changed, 59 insertions(+), 29 deletions(-) create mode 100644 .tailor create mode 100644 Strainerfile delete mode 100755 run_tests.bash diff --git a/.gitignore b/.gitignore index 1142e2d4..c6ba7b77 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,2 @@ -.bundle -.cookbooks/ +.bundle/ Berksfile.lock diff --git a/.tailor b/.tailor new file mode 100644 index 00000000..99f0dcf1 --- /dev/null +++ b/.tailor @@ -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 diff --git a/Gemfile b/Gemfile index e5ab73c4..7de4657f 100644 --- a/Gemfile +++ b/Gemfile @@ -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" diff --git a/Gemfile.lock b/Gemfile.lock index c81dc1c2..08e2917e 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -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 diff --git a/README.md b/README.md index 594c7781..29225d9f 100644 --- a/README.md +++ b/README.md @@ -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 () | | **Author** | Matt Ray () | | **Author** | Craig Tracey () | +| **Author** | Sean Gallagher () | | | | | **Copyright** | Copyright (c) 2012-2013, AT&T Services, Inc. | | **Copyright** | Copyright (c) 2013, Opscode, Inc. | diff --git a/Strainerfile b/Strainerfile new file mode 100644 index 00000000..7e292b43 --- /dev/null +++ b/Strainerfile @@ -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 diff --git a/run_tests.bash b/run_tests.bash deleted file mode 100755 index 141e8ee5..00000000 --- a/run_tests.bash +++ /dev/null @@ -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}