spec/config_loader_spec.rb in configloader-0.2.2 vs spec/config_loader_spec.rb in configloader-0.3.0

- old
+ new

@@ -1,35 +1,39 @@ require File.expand_path(File.dirname(__FILE__) + '/spec_helper') describe "ConfigLoader" do - - describe ".load" do - - def prepare_mocks(running_env, project_root) - Rails.stub!(:env).and_return(running_env) - Rails.stub!(:root).and_return('/home/user/project') - ConfigLoader::Map.should_receive(:new).with('database', running_env, project_root).and_return(@map_mock) - @map_mock.should_receive(:load).and_return('config') + before(:each) do + @root_dir = File.expand_path(File.join(File.dirname(__FILE__), "..", "spec", "root_dir")) + Rails.stub!(:root).and_return(@root_dir) + Rails.stub!(:env).and_return('development') + end + + describe ".load" do + it "raises exception when no config file name is given" do + lambda { ConfigLoader.load(nil) }.should raise_error(ConfigLoader::MissingConfigFileNameError) end - before(:each) do - @map_mock = mock('ConfigLoader::Map') + it "raises exception when the config file can't be found" do + lambda { ConfigLoader.load('database', 'development', 'invalid_location') }.should raise_error(ConfigLoader::MissingConfigFileError) end - it "should delegate to ConfigLoader::Map.populate" do - prepare_mocks('development', '/home/user/project') - ConfigLoader.load('database').should == 'config' + it "loads keys for Rails.env from the config file located in Rails.root/config" do + ConfigLoader.load('database')['name'].should == 'customers_development' end - it "should delegate to ConfigLoader::Map.populate with the given running_env" do - prepare_mocks('production', '/home/user/project') - ConfigLoader.load('database', 'production').should == 'config' + it "loads keys for the given environament from the config file located in Rails.root/config" do + ConfigLoader.load('database', 'test')['name'].should == 'customers_test' end - it "should delegate to ConfigLoader::Map.populate with the given project_root" do - prepare_mocks('development', '/home/user/another_project') - ConfigLoader.load('database', 'development', '/home/user/another_project').should == 'config' + it "loads keys for the given environmanent from the config file located under the given directory/config" do + alternative_root_dir = File.expand_path(File.join(File.dirname(__FILE__), "..", "spec", "alternative_root_dir")) + ConfigLoader.load('database', 'development', alternative_root_dir)['name'].should == 'alternative_customers_development' end + it "loads dinamic keys" do + # KEY: + # name: <%= "CUSTOMERS".downcase %>_test + config = ConfigLoader.load('database', 'test') + config['name'].should == 'customers_test' + end end - end