Permalink
Browse files

Needed to have a check for if "roodi.yml" exists in the project

Related to #21
  • Loading branch information...
evjan committed Nov 9, 2013
1 parent e5ddf21 commit cfe288bef3bc8618c7891bbad63bac3dec0fe662
Showing with 48 additions and 23 deletions.
  1. +17 −4 lib/roodi/core/runner.rb
  2. +31 −19 spec/roodi/core/runner_spec.rb
View
@@ -8,16 +8,26 @@
module Roodi
module Core
class Runner
- DEFAULT_CONFIG = "roodi.yml"
-
attr_writer :config
attr_reader :files_checked
def initialize(*checks)
- @config = DEFAULT_CONFIG
+ @config = default_config
@checks = checks unless checks.empty?
end
+ def default_config
+ project_config ? project_config : roodi_gem_config
+ end
+
+ def roodi_gem_config
+ File.join(File.dirname(__FILE__), "..", "..", "..", "roodi.yml")
+ end
+
+ def project_config
+ File.exists?("roodi.yml") ? "roodi.yml" : nil
+ end
+
def start(paths)
puts "\nRunning Roodi checks"
@@ -112,14 +122,17 @@ def parsing_errors
def load_checks
check_objects = []
- checks = YAML.load_file @config
+ checks = load_config(@config)
checks.each do |check_class_name, options|
check_class = Roodi::Checks.const_get(check_class_name)
check_objects << check_class.make(options || {})
end
check_objects
end
+ def load_config(config_file)
+ YAML.load_file config_file
+ end
end
end
end
@@ -3,25 +3,6 @@
describe Roodi::Core::Runner do
subject { Roodi::Core::Runner.new }
- describe "given a custom config file" do
- before do
- subject.config= File.expand_path(File.dirname(__FILE__) + '/../roodi.yml')
- end
-
- it "uses check from it" do
- content = <<-RUBY
- class TestClass
-
- def METHOD
-
- end
- end
- RUBY
- subject.check_content(content)
- subject.errors.should be_empty
- end
- end
-
describe "running against a file" do
it "adds an error if file is not valid ruby" do
content = <<-END
@@ -53,4 +34,35 @@ def METHOD
end
end
+ describe "configuration" do
+ context "given a custom config file" do
+ before do
+ subject.config= File.expand_path(File.dirname(__FILE__) + '/../roodi.yml')
+ end
+
+ it "uses check from it" do
+ content = <<-RUBY
+ class TestClass
+
+ def METHOD
+
+ end
+ end
+ RUBY
+ subject.check_content(content)
+ subject.errors.should be_empty
+ end
+ end
+
+ it "uses the default config if none given" do
+ subject.stub(:project_config) { nil }
+ expect(subject.default_config).to eq subject.default_config
+ end
+
+ it "uses roodi.yml if it exists" do
+ subject.stub(:project_config) { "roodi.yml" }
+ expect(subject.default_config).to eq "roodi.yml"
+ end
+ end
+
end

0 comments on commit cfe288b

Please sign in to comment.