Skip to content

Commit

Permalink
Adds a question method to determine environment. eg Merb.env?(:produc…
Browse files Browse the repository at this point in the history
…tion)
  • Loading branch information
Daniel Neighman committed Apr 25, 2008
1 parent dfecddf commit 4bb3861
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 0 deletions.
16 changes: 16 additions & 0 deletions lib/merb-core.rb
Expand Up @@ -235,6 +235,18 @@ def testing?
$TESTING || Merb::Config[:testing]
end

# Ask the question about which environment you're in.
# ==== Parameters
# env<Symbol, String>:: 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
Expand Down Expand Up @@ -299,6 +311,10 @@ def add_rakefiles(*rakefiles)
@rakefiles ||= ['merb-core/test/tasks/spectasks']
@rakefiles += rakefiles
end




end
end

Expand Down
34 changes: 34 additions & 0 deletions 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

0 comments on commit 4bb3861

Please sign in to comment.