diff --git a/lib/merb-core.rb b/lib/merb-core.rb index 8c4c3d0c..e5bea48b 100644 --- a/lib/merb-core.rb +++ b/lib/merb-core.rb @@ -235,6 +235,18 @@ def testing? $TESTING || Merb::Config[:testing] end + # Ask the question about which environment you're in. + # ==== Parameters + # env:: Name of the environment to query + # + # ==== Examples + # Merb.env #=> production + # Merb.env?(:production) #=> true + # Merb.env?(:development) #=> false + def env?(env) + Merb.env == env.to_s + end + # If block was given configures using the block. # # ==== Parameters @@ -299,6 +311,10 @@ def add_rakefiles(*rakefiles) @rakefiles ||= ['merb-core/test/tasks/spectasks'] @rakefiles += rakefiles end + + + + end end diff --git a/spec/public/core/merb_core_spec.rb b/spec/public/core/merb_core_spec.rb new file mode 100644 index 00000000..d4ac9f41 --- /dev/null +++ b/spec/public/core/merb_core_spec.rb @@ -0,0 +1,34 @@ +require File.join(File.dirname(__FILE__), "..", "..", "spec_helper") + +describe "Merb.env helpers" do + before(:all) do + @orig_env = Merb.environment + end + after(:all) do + Merb.environment = @orig_env + end + + it "should pickup the environment from env" do + %w(development test production staging demo).each do |e| + Merb.environment = e + Merb.env.should == e + end + end + + it "should correctly answer the question about which env it's in with symbol or string" do + %w(development test production staging demo custom).each do |e| + Merb.environment = e + Merb.env?(e).should be true + Merb.env?(e.to_sym).should be_true + end + end + + it "should answer false if asked for an environment that is not current" do + %w(development test production staging demo custom).each do |e| + Merb.environment = e + Merb.env?(:not_it).should be_false + end + end + + +end \ No newline at end of file