Permalink
Browse files

Add specs for loading cane options from a canefile

  • Loading branch information...
1 parent ac8dbdb commit 0307a86dd92f5b5a918e2a07a6e52bdc65ea4d6b @DanielHeath DanielHeath committed with xaviershay Sep 17, 2012
Showing with 24 additions and 3 deletions.
  1. +6 −2 lib/cane/cli/parser.rb
  2. +1 −1 lib/cane/rake_task.rb
  3. +17 −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
@@ -45,7 +45,7 @@ def use(check, options = {})
def canefile=(file)
canefile = Cane::CLI::Parser.new
- canefile.parser.parse!(canefile.get_default_options)
+ canefile.parser.parse!(canefile.read_options_from_file(file))
options.merge! canefile.options
end
View
@@ -32,6 +32,23 @@ def violations
out.should include("theopt")
end
+ it 'can be configured using a .cane file' do
+ fn = make_file("90").strip
+
+ task = Cane::RakeTask.new(:canefile_quality) do |cane|
+ conf = "--gte #{fn},99"
+ 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 0307a86

Please sign in to comment.