Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Exceptions were thrown when trying to access nested property via 'get…

…' method while suppress_errors is enabled.
  • Loading branch information...
commit dfb85e82c094cc8a7ccbff8b0e2817c473a8122d 1 parent 08792a6
@toXXIc authored
Showing with 21 additions and 0 deletions.
  1. +3 −0  README.rdoc
  2. +4 −0 lib/settingslogic.rb
  3. +14 −0 spec/settingslogic_spec.rb
View
3  README.rdoc
@@ -72,6 +72,9 @@ If your default settings seem to be overwriting your environment-specific settin
>> Settings.cool.saweet
=> "nested settings"
+ >> Settings.get('cool.saweet')
+ => "nested settings"
+
>> Settings.neat_setting
=> 800
View
4 lib/settingslogic.rb
@@ -19,6 +19,10 @@ def get(key)
curs = curs.send(p)
end
curs
+ rescue
+ return nil if suppress_errors
+
+ raise
end
def source(value = nil)
View
14 spec/settingslogic_spec.rb
@@ -1,5 +1,7 @@
require File.expand_path(File.dirname(__FILE__) + "/spec_helper")
+puts "Value: #{Settings.get('setting1.deep.child.value')}"
+
describe "Settingslogic" do
it "should access settings" do
Settings.setting2.should == 5
@@ -115,6 +117,18 @@ class NoSource < Settingslogic; end
Settings4.non_existent_key.should be_nil
end
+
+ context "#get" do
+ it "should suppress errors for nonexistent nested parameters" do
+ expect { Settings4.get('non.existent.key') }.not_to raise_exception
+ end
+
+ it "should throw an exception for nonexistent nested parameters when suppress_errors=false" do
+ expect { Settings.get('non.existent.key') }.to raise_exception
+ end
+ 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.
Please sign in to comment.
Something went wrong with that request. Please try again.