Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

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

Merge branch 'load_dotcane_options_in_rake_tasks'
  • Loading branch information...
commit 02adcd30bd240be16662ec729c3abb1507ca77a3 2 parents 373795e + b0c71dc
@xaviershay xaviershay authored
View
8 lib/cane/cli/parser.rb
@@ -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
7 lib/cane/rake_task.rb
@@ -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
15 spec/rake_task_spec.rb
@@ -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
Please sign in to comment.
Something went wrong with that request. Please try again.