Browse files

handling of nil (missing) file specified as source

  • Loading branch information...
1 parent 872a103 commit eeadde31f7995f4a2fffa14364a0de5deb37d512 Nate Wiger committed with Feb 12, 2010
Showing with 14 additions and 1 deletion.
  1. +3 −1 lib/settingslogic.rb
  2. +11 −0 spec/settingslogic_spec.rb
View
4 lib/settingslogic.rb
@@ -9,7 +9,7 @@ class << self
def name # :nodoc:
instance.key?("name") ? instance.name : super
end
-
+
# Enables Settings.get('nested.key.name') for dynamic access
def get(key)
parts = key.split('.')
@@ -97,6 +97,8 @@ def create_accessor_for(key)
def initialize(hash_or_file = self.class.source, section = nil)
#puts "new! #{hash_or_file}"
case hash_or_file
+ when nil
+ raise Errno::ENOENT, "No file specified as Settingslogic source"
when Hash
self.replace hash_or_file
else
View
11 spec/settingslogic_spec.rb
@@ -96,6 +96,17 @@
Settings.toplevel.should == '42'
end
+ it "should raise an error on a nil source argument" do
+ class NoSource < Settingslogic; end
+ e = nil
+ begin
+ NoSource.foo.bar
+ rescue => e
+ e.should be_kind_of Errno::ENOENT
+ end
+ e.should_not be_nil
+ end
+
# This one edge case currently does not pass, because it requires very
# esoteric code in order to make it pass. It was judged not worth fixing,
# as it introduces significant complexity for minor gain.

0 comments on commit eeadde3

Please sign in to comment.