Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Loading…

Properly initialize whitelist and ignore_groups if no config/license_finder.yml is found #1

Merged
merged 1 commit into from

2 participants

@loginx

When no config/license_finder.yml file exists, LicenseFinder will crash when running from the supplied rake task. This commit provides a failing test for that condition, and a fix that properly initializes those instance variables.

@pivotalcommon pivotalcommon merged commit 5fca324 into from
@pivotalcommon

Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Apr 7, 2011
  1. Properly initialize whitelist and ignore_groups if no config/license_…

    Xavier Spriet authored
    …finder.yml is found
This page is out of date. Refresh to see the latest.
Showing with 18 additions and 6 deletions.
  1. +9 −5 lib/license_finder/finder.rb
  2. +9 −1 spec/finder_spec.rb
View
14 lib/license_finder/finder.rb
@@ -3,11 +3,15 @@ class Finder
attr_reader :whitelist, :ignore_groups
def initialize
- if File.exists?('./config/license_finder.yml')
- config = YAML.load(File.open('./config/license_finder.yml').readlines.join)
- @whitelist = config['whitelist'] || []
- @ignore_groups = config['ignore_groups'] ? config['ignore_groups'].map{|g| g.to_sym} : []
+ config = case
+ when File.exists?('./config/license_finder.yml')
+ YAML.load(File.open('./config/license_finder.yml').readlines.join)
+ else
+ {'whitelist' => [], 'ignore_groups' => []}
end
+
+ @whitelist = config['whitelist']
+ @ignore_groups = config['ignore_groups'].map{|g| g.to_sym}
end
def from_bundler
@@ -45,4 +49,4 @@ def generate_list
end
end
end
-end
+end
View
10 spec/finder_spec.rb
@@ -1,6 +1,14 @@
require 'spec_helper'
describe LicenseFinder::Finder do
+
+ it "should properly initialize whitelist and ignore_groups" do
+ stub(File).exists?('./config/license_finder.yml') {false}
+ finder = LicenseFinder::Finder.new
+ finder.whitelist.should_not be_nil
+ finder.ignore_groups.should_not be_nil
+ end
+
it "should generate a yml file and txt file" do
stub(File).exists?('./config/license_finder.yml') {false}
stub(File).exists?('./dependencies.yml') {false}
@@ -41,4 +49,4 @@
stub(File).open('./config/license_finder.yml').stub!.readlines.stub!.join {"--- \nwhitelist: \n- MIT\n- Apache\nignore_groups: \n- test\n- development\n"}
LicenseFinder::Finder.new.ignore_groups.should == [:test, :development]
end
-end
+end
Something went wrong with that request. Please try again.