Skip to content

Instantly share code, notes, and snippets.

@agross
Created May 29, 2014 11:45
Show Gist options
  • Save agross/278d26aefd6033b5bc7f to your computer and use it in GitHub Desktop.
Save agross/278d26aefd6033b5bc7f to your computer and use it in GitHub Desktop.
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
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