Sha256: 4da3dda100d63da6836acfa8ee5ff1663e58cd405e56b9bd2ac89aa81f553f8f

Contents?: true

Size: 1.68 KB

Versions: 4

Compression:

Stored size: 1.68 KB

Contents

require 'spec_helper'

describe Enviro::Environment do
  before(:each) do
    Object.send(:remove_const, :TestEnviroEnvironment) if defined?(TestEnviroEnvironment)
    class TestEnviroEnvironment
      include Enviro::Environment
    end
  end

  it "should have the environment attribute set the default when no session ENV setting is set" do
    ENV['ENVY_ENV'] = nil
    ENV['ENVY_ENV'].should be_nil
    TestEnviroEnvironment.environment.should == :development
  end

  it "should have the environment attribute set the same as the session ENV setting" do
    ENV['ENVY_ENV'] = 'production'
    ENV['ENVY_ENV'].should == "production"
    TestEnviroEnvironment.environment.should == :production
  end

  it "should alias env to environment" do
    ENV['ENVY_ENV'] = nil
    ENV['ENVY_ENV'].should be_nil
    TestEnviroEnvironment.env.should == :development
  end

  it "should return true on env?(value) when value is environment" do
    ENV['ENVY_ENV'] = nil
    ENV['ENVY_ENV'].should be_nil
    TestEnviroEnvironment.env?('development').should be_true
  end

  it "should return false on env?(value) when value is not environment" do
    ENV['ENVY_ENV'] = nil
    ENV['ENVY_ENV'].should be_nil
    TestEnviroEnvironment.env?('production').should be_false
  end

  context "within Rails" do
    before(:each) do
      module Rails
        def self.env
          :production
        end
      end
    end

    after(:each) do
      Object.send(:remove_const, :Rails) if defined?(Rails)
    end

    it "should inherit the environment from Rails should it be loaded" do
      ENV['ENVY_ENV'] = nil
      ENV['ENVY_ENV'].should be_nil
      TestEnviroEnvironment.environment.should == :production
    end
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
enviro-0.0.4 spec/enviro/environment_spec.rb
enviro-0.0.3 spec/enviro/environment_spec.rb
enviro-0.0.2 spec/enviro/environment_spec.rb
enviro-0.0.1 spec/enviro/environment_spec.rb