Permalink
Browse files

Only lint cookbook directories, refs #37.

- Extend DSL for library and metadata, removing problematic globbing.
- Readability improvements.
- Add Rocco for documentation and rework comments.
- Move rake test helpers into their own module.
  • Loading branch information...
1 parent 094ec2a commit efd3d9cf24f0d6f63d4bdd3c03eb2675ba70c64a @acrmp committed Jun 22, 2012
View
@@ -14,6 +14,8 @@ group :development do
gem 'chef', '~> 0.10.8'
gem 'guard', '~> 1.0.0'
gem 'guard-cucumber', '~> 0.7.5'
+ gem 'fl-rocco', '~> 1.0.0'
+ gem 'guard-rocco', '~> 0.0.3'
gem "rake", '~> 0.9.2.2'
gem "rdiscount", '~> 1.6.8'
gem "yard", '~> 0.7.5'
View
@@ -0,0 +1,3 @@
+guard 'rocco' do
+ watch(%r{^lib/*/.*\.rb$})
+end
@@ -88,3 +88,12 @@ I want to be able to invoke the lint tool from my build
When I run the build
Then no warnings will be displayed against the tests
And the build will succeed with warnings FC002
+
+ Scenario: Exclude vendored gems
+ Given a cookbook that has style problems
+ And the cookbook has a Gemfile that includes rake and foodcritic
+ And a Rakefile that defines a lint task with no block
+ And the gems have been vendored
+ When I run the build
+ Then no warnings will be displayed against the tests
+ And the build will succeed with warnings FC002
@@ -874,6 +874,10 @@ def search(bag_name, query=nil, sort=nil, start=0, rows=1000, &block)
rule_with_version_constraint("98.10", nil) unless falls_within.include?('falls')
end
+Given 'the gems have been vendored' do
+ vendor_gems
+end
+
Given 'unit tests under a top-level test directory' do
minitest_spec_attributes
end
@@ -47,35 +47,6 @@ def self.running_in_process?
! (ENV.has_key?('FC_FORK_PROCESS') and ENV['FC_FORK_PROCESS'] == true.to_s)
end
- # Assert the build outcome
- #
- # @param [Boolean] success True if the build should succeed
- # @param [Array] warnings The warnings expected
- def assert_build_result(success, warnings)
- success ? assert_no_error_occurred : assert_error_occurred
- warnings.each do |code|
- expect_warning(code, :warning_only => true)
- end
- end
-
- # Assert that warnings have not been raised against the test code which
- # should have been excluded from linting.
- def assert_no_test_warnings
- all_output.split("\n").grep(/FC[0-9]+:/).map do |warn|
- File.basename(File.dirname(warn.split(':').take(3).last.strip))
- end.should_not include 'test'
- end
-
- # The available tasks for this build
- #
- # @return [Array] Task name and description
- def build_tasks
- all_output.split("\n").map do |task|
- next unless task.start_with? 'rake'
- task.split("#").map{|t| t.strip.sub(/^rake /, '')}
- end.compact
- end
-
# Capture an error expected when calling a command.
def capture_error
begin
@@ -141,27 +112,6 @@ def expect_usage_option(short_switch, long_switch, description)
expect_output(Regexp.new(expected_switch))
end
- # List the defined Rake tasks
- def list_available_build_tasks
- cd 'cookbooks/example'
- run "bundle exec rake -T"
- end
-
- # Create a placeholder minitest spec that would be linted due to its path
- # unless an exclusion is specified.
- def minitest_spec_attributes
- write_file 'cookbooks/example/test/attributes/default_spec.rb', %q{
- describe 'Example::Attributes::Default' do
- end
- }
- end
-
- # Run a build for a Rakefile that uses the lint rake task
- def run_build
- cd 'cookbooks/example'
- run 'bundle exec rake'
- end
-
# Assert that the usage message is displayed.
#
# @param [Boolean] is_exit_zero The exit code to check for.
@@ -244,9 +194,69 @@ def with_repl?
end
+ # For use with steps that use bundler and rake. These will always be run
+ # via Aruba.
+ module BuildHelpers
+
+ # Assert the build outcome
+ #
+ # @param [Boolean] success True if the build should succeed
+ # @param [Array] warnings The warnings expected
+ def assert_build_result(success, warnings)
+ success ? assert_no_error_occurred : assert_error_occurred
+ warnings.each do |code|
+ expect_warning(code, :warning_only => true)
+ end
+ end
+
+ # Assert that warnings have not been raised against the test code which
+ # should have been excluded from linting.
+ def assert_no_test_warnings
+ all_output.split("\n").grep(/FC[0-9]+:/).map do |warn|
+ File.basename(File.dirname(warn.split(':').take(3).last.strip))
+ end.should_not include 'test'
+ end
+
+ # The available tasks for this build
+ #
+ # @return [Array] Task name and description
+ def build_tasks
+ all_output.split("\n").map do |task|
+ next unless task.start_with? 'rake'
+ task.split("#").map{|t| t.strip.sub(/^rake /, '')}
+ end.compact
+ end
+
+ # List the defined Rake tasks
+ def list_available_build_tasks
+ cd 'cookbooks/example'
+ unset_bundler_env_vars
+ run_simple 'bundle exec rake -T'
+ end
+
+ # Run a build for a Rakefile that uses the lint rake task
+ def run_build
+ cd 'cookbooks/example'
+ run_simple "bundle exec rake", false
+ end
+
+ # We want to avoid traversing vendored gems because of the unnecessary
+ # performance hit and because gems may contain deeply-nested code which
+ # will blow the stack on parsing.
+ def vendor_gems
+ cd 'cookbooks/example'
+ unset_bundler_env_vars
+ run_simple 'bundle install --path vendor/bundle'
+ cd '../..'
+ end
+
+ end
+
# Helpers used when features are executed out of process.
module ArubaHelpers
+ include BuildHelpers
+
# Assert that the output contains the specified warning.
#
# @param [String] output The output to check for.
@@ -13,6 +13,7 @@ def attributes_with_symbols(type)
# Create a Gemfile for a cookbook
def buildable_gemfile
write_file 'cookbooks/example/Gemfile', %q{
+ source :rubygems
gem 'rake'
gem 'foodcritic', :path => '../../../..'
}
@@ -134,6 +135,15 @@ def cookbook_with_maintainer(name, email)
}
end
+ # Create a placeholder minitest spec that would be linted due to its path
+ # unless an exclusion is specified.
+ def minitest_spec_attributes
+ write_file 'cookbooks/example/test/attributes/default_spec.rb', %q{
+ describe 'Example::Attributes::Default' do
+ end
+ }
+ end
+
# Create a Rakefile that uses the linter rake task
#
# @param [Symbol] task Type of task
View
@@ -10,7 +10,10 @@
require_relative 'foodcritic/domain'
require_relative 'foodcritic/error_checker'
require_relative 'foodcritic/notifications'
+require_relative 'foodcritic/ast'
+require_relative 'foodcritic/xml'
require_relative 'foodcritic/api'
+require_relative 'foodcritic/repl'
require_relative 'foodcritic/dsl'
require_relative 'foodcritic/linter'
require_relative 'foodcritic/output'
Oops, something went wrong. Retry.

0 comments on commit efd3d9c

Please sign in to comment.