Permalink
Browse files

feature: Rake task can load configuration from a .cane file.

Merge branch 'load_dotcane_options_in_rake_tasks'
  • Loading branch information...
2 parents 373795e + b0c71dc commit 02adcd30bd240be16662ec729c3abb1507ca77a3 @xaviershay xaviershay committed Oct 21, 2012
Showing with 28 additions and 2 deletions.
  1. +6 −2 lib/cane/cli/parser.rb
  2. +7 −0 lib/cane/rake_task.rb
  3. +15 −0 spec/rake_task_spec.rb
View
@@ -49,8 +49,12 @@ def parse(args, ret = true)
end
def get_default_options
- if Cane::File.exists?('./.cane')
- Cane::File.contents('./.cane').split(/\s+/m)
+ read_options_from_file './.cane'
+ end
+
+ def read_options_from_file(file)
+ if Cane::File.exists?(file)
+ Cane::File.contents(file).split(/\s+/m)
else
[]
end
View
@@ -2,6 +2,7 @@
require 'rake/tasklib'
require 'cane/cli/options'
+require 'cane/cli/parser'
module Cane
# Creates a rake task to run cane with given configuration.
@@ -42,6 +43,12 @@ def use(check, options = {})
@options[:checks] = @options[:checks] + [check]
end
+ def canefile=(file)
+ canefile = Cane::CLI::Parser.new
+ canefile.parser.parse!(canefile.read_options_from_file(file))
+ options.merge! canefile.options
+ end
+
def initialize(task_name = nil)
self.name = task_name || :cane
@gte = []
View
@@ -32,6 +32,21 @@ def violations
out.should include("theopt")
end
+ it 'can be configured using a .cane file' do
+ conf = "--gte 90,99"
+
+ task = Cane::RakeTask.new(:canefile_quality) do |cane|
+ cane.canefile = make_file(conf)
+ end
+
+ task.should_receive(:abort)
+ out = capture_stdout do
+ Rake::Task['canefile_quality'].invoke
+ end
+
+ out.should include("Quality threshold crossed")
+ end
+
after do
Rake::Task.clear
end

0 comments on commit 02adcd3

Please sign in to comment.