Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add lint and spec infrastructure #7

Merged
merged 1 commit into from May 20, 2014
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
13 changes: 13 additions & 0 deletions Gemfile
Expand Up @@ -2,6 +2,19 @@ source 'https://rubygems.org'

gem 'berkshelf', '~> 3.0'
gem 'chef', '~> 11.12'
gem 'chefspec', '~> 3.4'
gem 'foodcritic', '~> 3.0'
gem 'thor-foodcritic'
gem 'rake'
gem 'rubocop', '~> 0.18.1'

group :development do
gem 'guard'
gem 'guard-rspec'
gem 'guard-kitchen'
gem 'guard-rubocop'
gem 'guard-foodcritic'
end

group :integration do
gem 'test-kitchen', '~> 1.0'
Expand Down
82 changes: 82 additions & 0 deletions Gemfile.lock
Expand Up @@ -2,6 +2,7 @@ GEM
remote: https://rubygems.org/
specs:
addressable (2.3.6)
ast (2.0.0)
berkshelf (3.1.2)
addressable (~> 2.3.4)
berkshelf-api-client (~> 1.2)
Expand Down Expand Up @@ -55,6 +56,10 @@ GEM
json
mixlib-log (~> 1.3)
rack
chefspec (3.4.0)
chef (~> 11.0)
fauxhai (~> 2.0)
rspec (~> 2.14)
coderay (1.1.0)
dep-selector-libgecode (1.0.0)
dep_selector (1.0.3)
Expand All @@ -64,8 +69,39 @@ GEM
erubis (2.7.0)
faraday (0.9.0)
multipart-post (>= 1.2, < 3)
fauxhai (2.1.2)
net-ssh
ohai
ffi (1.9.3)
foodcritic (3.0.3)
erubis
gherkin (~> 2.11.7)
nokogiri (~> 1.5.4)
rake
treetop (~> 1.4.10)
yajl-ruby (~> 1.1.0)
formatador (0.2.4)
gherkin (2.11.8)
multi_json (~> 1.3)
git (1.2.6)
guard (2.6.1)
formatador (>= 0.2.4)
listen (~> 2.7)
lumberjack (~> 1.0)
pry (>= 0.9.12)
thor (>= 0.18.1)
guard-foodcritic (1.0.2)
foodcritic (>= 1.3, < 4.0)
guard (>= 1.0, < 3.0)
guard-kitchen (0.0.2)
guard
mixlib-shellout
guard-rspec (4.2.9)
guard (~> 2.1)
rspec (>= 2.14, < 4.0)
guard-rubocop (1.0.2)
guard (~> 2.0)
rubocop (~> 0.10)
hashie (2.1.1)
highline (1.6.21)
hitimes (1.2.1)
Expand All @@ -75,6 +111,11 @@ GEM
git
kitchen-vagrant (0.15.0)
test-kitchen (~> 1.0)
listen (2.7.5)
celluloid (>= 0.15.2)
rb-fsevent (>= 0.9.3)
rb-inotify (>= 0.9)
lumberjack (1.0.5)
method_source (0.8.2)
mime-types (1.25.1)
minitar (0.5.4)
Expand All @@ -84,6 +125,7 @@ GEM
mixlib-config (2.1.0)
mixlib-log (1.6.0)
mixlib-shellout (1.4.0)
multi_json (1.10.1)
multipart-post (2.0.0)
net-http-persistent (2.9.4)
net-scp (1.2.1)
Expand All @@ -95,6 +137,7 @@ GEM
net-ssh (>= 2.6.5)
net-ssh-gateway (>= 1.2.0)
nio4r (1.0.0)
nokogiri (1.5.11)
octokit (3.1.0)
sawyer (~> 0.5.3)
ohai (7.0.4)
Expand All @@ -106,11 +149,21 @@ GEM
mixlib-shellout (~> 1.2)
systemu (~> 2.5.2)
yajl-ruby
parser (2.1.9)
ast (>= 1.1, < 3.0)
slop (~> 3.4, >= 3.4.5)
polyglot (0.3.4)
powerpack (0.0.9)
pry (0.9.12.6)
coderay (~> 1.0)
method_source (~> 0.8)
slop (~> 3.4)
rack (1.5.2)
rainbow (2.0.0)
rake (10.3.2)
rb-fsevent (0.9.4)
rb-inotify (0.9.4)
ffi (>= 0.5.0)
rest-client (1.6.7)
mime-types (>= 1.16)
retryable (1.3.5)
Expand All @@ -131,6 +184,19 @@ GEM
retryable
semverse (~> 1.1)
varia_model (~> 0.3)
rspec (2.14.1)
rspec-core (~> 2.14.0)
rspec-expectations (~> 2.14.0)
rspec-mocks (~> 2.14.0)
rspec-core (2.14.8)
rspec-expectations (2.14.5)
diff-lcs (>= 1.1.3, < 2.0)
rspec-mocks (2.14.6)
rubocop (0.18.1)
json (>= 1.7.7, < 2)
parser (~> 2.1.3)
powerpack (~> 0.0.6)
rainbow (>= 1.99.1, < 3.0)
safe_yaml (1.0.3)
sawyer (0.5.4)
addressable (~> 2.3.5)
Expand All @@ -148,8 +214,14 @@ GEM
safe_yaml (~> 1.0)
thor (~> 0.18)
thor (0.19.1)
thor-foodcritic (1.1.0)
foodcritic (~> 3.0)
thor
timers (2.0.0)
hitimes
treetop (1.4.15)
polyglot
polyglot (>= 0.3.1)
varia_model (0.3.2)
buff-extensions (~> 0.2)
hashie (>= 2.0.2)
Expand All @@ -161,6 +233,16 @@ PLATFORMS
DEPENDENCIES
berkshelf (~> 3.0)
chef (~> 11.12)
chefspec (~> 3.4)
foodcritic (~> 3.0)
guard
guard-foodcritic
guard-kitchen
guard-rspec
guard-rubocop
kitchen-sharedtests (~> 0.2.0)
kitchen-vagrant
rake
rubocop (~> 0.18.1)
test-kitchen (~> 1.0)
thor-foodcritic
30 changes: 30 additions & 0 deletions Guardfile
@@ -0,0 +1,30 @@
# Guardfile

guard :rubocop do
watch(%r{.+\.rb$})
watch(%r{(?:.+/)?\.rubocop\.yml$}) { |m| File.dirname(m[0]) }
end

guard :foodcritic, cookbook_paths: '.', cli: "-f any --tags ~FC023" do
watch(%r{attributes/.+\.rb$})
watch(%r{providers/.+\.rb$})
watch(%r{recipes/.+\.rb$})
watch(%r{resources/.+\.rb$})
watch(%r{metadata.rb})
end

guard :rspec do
watch(%r{^spec/.+_spec\.rb$})
watch(%r{^(recipes)/(.+)\.rb$}) { |m| "spec/#{m[1]}_spec.rb" }
watch('spec/spec_helper.rb') { 'spec' }
end

guard :kitchen, all_on_start: false do
watch(%r{test/.+})
watch(%r{^recipes/(.+)\.rb$})
watch(%r{^attributes/(.+)\.rb$})
watch(%r{^files/(.+)})
watch(%r{^templates/(.+)})
watch(%r{^providers/(.+)\.rb})
watch(%r{^resources/(.+)\.rb})
end
57 changes: 57 additions & 0 deletions Rakefile
@@ -0,0 +1,57 @@
#!/usr/bin/env rake
require 'foodcritic'
require 'rspec/core/rake_task'
require 'rubocop/rake_task'

# General tasks

# Rubocop before rspec so we don't lint vendored cookbooks
desc "Run all tests except Kitchen (default task)"
task :integration => %w{rubocop foodcritic spec}
task :default => :unit

# Lint the cookbook
desc "Run linters"
task :lint => [ :rubocop, :foodcritic ]

# Run the whole shebang
desc "Run all tests"
task :test => [ :lint, :integration ]

# RSpec
desc 'Run chefspec tests'
task :spec do
puts "Running Chefspec tests"
RSpec::Core::RakeTask.new(:spec)
end

# Foodcritic
desc 'Run foodcritic lint checks'
task :foodcritic do
if Gem::Version.new('1.9.2') <= Gem::Version.new(RUBY_VERSION.dup)
puts "Running Foodcritic tests..."
FoodCritic::Rake::LintTask.new do |t|
t.options = { :fail_tags => ['correctness'] }
puts "done."
end
else
puts "WARN: foodcritic run is skipped as Ruby #{RUBY_VERSION} is < 1.9.2."
end
end

# Rubocop
desc 'Run Rubocop lint checks'
task :rubocop do
Rubocop::RakeTask.new
end

begin
require 'kitchen/rake_tasks'
Kitchen::RakeTasks.new

desc "Alias for kitchen:all"
task :acceptance => "kitchen:all"

rescue LoadError
puts ">>>>> Kitchen gem not loaded, omitting tasks" unless ENV['CI']
end
2 changes: 2 additions & 0 deletions Thorfile
Expand Up @@ -2,6 +2,8 @@

require 'bundler'
require 'bundler/setup'
require 'thor/foodcritic'

require 'kitchen_sharedtests'
require 'kitchen/sharedtests_thor_tasks'

Expand Down