Created
May 29, 2014 11:45
-
-
Save agross/278d26aefd6033b5bc7f to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'configatron' | |
class Configatron::Store | |
def safe! | |
protect_all! | |
self << def to_s | |
name = "configatron.#{heirarchy}" | |
raise "Configuration key not found: #{name}" unless @_store.has_key?(sym) | |
end | |
end | |
end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'erb' | |
require 'configatron/extensions/safe' | |
describe "configatron extensions" do | |
describe "when a safe configuration is used in a templating scenario" do | |
before(:all) do | |
@config = Configatron::Store.new({}) | |
@config.configure_from_hash({ :nested => { :key => "value" } }) | |
@config.safe! | |
end | |
context "when the dereferenced key does not exists" do | |
before(:all) do | |
@template = ERB.new "The value of key is: <%= @config.nested.does.not.exist %>" | |
end | |
it "should fail when accessing an unassigned key" do | |
expect { @template.result(binding) }.to raise_error | |
end | |
end | |
context "when the dereferenced key does exists" do | |
before(:all) do | |
template = ERB.new "The value of key is: <%= @config.nested.key %>" | |
@result = template.result(binding) | |
end | |
it "should create the template result" do | |
@result.should include("The value of key is: value") | |
end | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment