spec/lib/ruby-conf_spec.rb in ruby-conf-2.4.0 vs spec/lib/ruby-conf_spec.rb in ruby-conf-2.5.0

- old
+ new

@@ -1,7 +1,6 @@ require 'spec_helper' -require 'ruby-conf' describe RubyConf do before do RubyConf.clear @@ -193,12 +192,14 @@ end context ":inherit" do let(:inherited_config) do RubyConf.define "inherited_config" do basic do + movie "b" thing do origin "swamp" + type "monster" end end laboritory :inherits => basic do thing do @@ -207,18 +208,29 @@ end city :inherits => basic do thing do origin "ocean" + name "bob" end end + chained :inherits => city do + thing do + origin "space" + end + end end end it "pre-loads a config with a existing config" do inherited_config.laboritory.thing.origin.should == inherited_config.basic.thing.origin end + it "chains inherited configs" do + inherited_config.chained.movie.should == "b" + inherited_config.chained.thing.origin.should == "space" + inherited_config.chained.thing.name.should == "bob" + end it "does not overwrite values" do inherited_config.city.thing.origin.should == "ocean" end end @@ -363,53 +375,87 @@ end end describe "Automatically sets the RAILS_CONF variable" do + after do + dir = Dir["./**/test_conf.rb.tmpl"].first[/^(.*?)\/test_conf.rb.tmpl$/, 1] + File.delete("#{dir}/test_conf.rb") if File.exists?("#{dir}/test_conf.rb") + end + + it "will autoload the first ruby-conf that it can find if none is provided" do + dir = Dir["./**/test_conf.rb.tmpl"].first[/^(.*?)\/test_conf.rb.tmpl$/, 1] + + val = Random.rand.to_s + File.write("#{dir}/test_conf.rb", File.read("#{dir}/test_conf.rb.tmpl").gsub('{{VALUE}}', val)) + + RUBY_CONF.should be_nil + RUBY_CONF.ident.should == "FOUND AND LOADED BASIC CONFIG #{val}" + loaded = RUBY_CONF.__rc_loaded_conf + + FileUtils.touch(loaded[:path], mtime: 100) + File.mtime(loaded[:path]).to_i.should_not == loaded[:mtime] + RUBY_CONF.ident.should == "FOUND AND LOADED BASIC CONFIG #{val}" + RUBY_CONF.__rc_loaded_conf[:mtime].should == loaded[:mtime] + + val = Random.rand.to_s + File.write("#{dir}/test_conf.rb", File.read("#{dir}/test_conf.rb.tmpl").gsub('{{VALUE}}', val)) + FileUtils.touch(loaded[:path], mtime: 100) + RUBY_CONF.ident.should == "FOUND AND LOADED BASIC CONFIG #{val}" + RUBY_CONF.__rc_loaded_conf[:mtime].should_not == loaded[:mtime] + + RubyConf.clear + module ::Rails + def self.env() "foo" end + end + ::Object.const_defined?(:Rails).should be_true + RUBY_CONF.should be_nil + RUBY_CONF.ident.should == "FOUND AND LOADED RAILS ENV CONFIG #{val}" + end + it "sets the first unnamed config as default" do - $RUBY_CONF.should be_nil + RUBY_CONF.should be_nil first = RubyConf.define { ident "first" } - $RUBY_CONF.should_not be_nil + RUBY_CONF.should_not be_nil second = RubyConf.define { ident "second" } - $RUBY_CONF.should == first - $RUBY_CONF.ident.should == "first" + RUBY_CONF.__rc_conf.should == first + RUBY_CONF.ident.should == "first" end it "sets the proper config based on Rails environment and detaches, if it exists" do module ::Rails def self.env() "foo" end end ::Object.const_defined?(:Rails).should be_true - $RUBY_CONF.should be_nil + RUBY_CONF.should be_nil RubyConf.define do foo { ident "correct" } bar { ident "wrong" } end - $RUBY_CONF.ident.should == "correct" + RUBY_CONF.ident.should == "correct" RubyConf.clear - $RUBY_CONF.should be_nil + RUBY_CONF.should be_nil RubyConf.define do foo_conf { ident "correct" } bar_conf { ident "wrong" } end - $RUBY_CONF.ident.should == "correct" + RUBY_CONF.ident.should == "correct" RubyConf.clear - $RUBY_CONF.should be_nil + RUBY_CONF.should be_nil RubyConf.define do foo_config { ident "correct" } bar_config { ident "wrong" } end - $RUBY_CONF.ident.should == "correct" + RUBY_CONF.ident.should == "correct" RubyConf.clear - $RUBY_CONF.should be_nil + RUBY_CONF.should be_nil RubyConf.define do ident "correct" end - $RUBY_CONF.ident.should == "correct" - + RUBY_CONF.ident.should == "correct" end end end