Sha256: ff8c9aa5874c3713851af03457acdfffd34e0f1b91774528684ce3dad7ea98e3

Contents?: true

Size: 1.67 KB

Versions: 14

Compression:

Stored size: 1.67 KB

Contents

require "spec_helper"

describe Mongoid::Config::Environment do

  after(:all) do
    Rails = RailsTemp
    Object.send(:remove_const, :RailsTemp)
  end

  describe "#env_name" do

    context "when using rails" do

      before do
        module Rails
          class << self
            def env; "production"; end
          end
        end
      end

      after do
        RailsTemp = Rails
        Object.send(:remove_const, :Rails)
      end

      it "returns the rails environment" do
        expect(described_class.env_name).to eq("production")
      end
    end

    context "when using sinatra" do

      before do
        Object.send(:remove_const, :Rails) if defined?(Rails)

        module Sinatra
          module Base
            extend self
            def environment; :staging; end
          end
        end
      end

      after do
        Object.send(:remove_const, :Sinatra)
      end

      it "returns the sinatra environment" do
        expect(described_class.env_name).to eq("staging")
      end
    end

    context "when the rack env variable is defined" do

      before do
        Object.send(:remove_const, :Rails) if defined?(Rails)
        ENV["RACK_ENV"] = "acceptance"
      end

      after do
        ENV["RACK_ENV"] = nil
      end

      it "returns the rack environment" do
        expect(described_class.env_name).to eq("acceptance")
      end
    end

    context "when no environment information is found" do

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

      it "raises an error" do
        expect { described_class.env_name }.to raise_error(
          Mongoid::Errors::NoEnvironment
        )
      end
    end
  end
end

Version data entries

14 entries across 14 versions & 5 rubygems

Version Path
ish_lib_manager-0.0.1 test/dummy/vendor/bundle/ruby/2.3.0/gems/mongoid-4.0.2/spec/mongoid/config/environment_spec.rb
mongoid-4.0.2 spec/mongoid/config/environment_spec.rb
mongoid-4.0.1 spec/mongoid/config/environment_spec.rb
mongoid-4.0.0 spec/mongoid/config/environment_spec.rb
mongoid-4.0.0.rc2 spec/mongoid/config/environment_spec.rb
mongoid-4.0.0.rc1 spec/mongoid/config/environment_spec.rb
mongoid-4.0.0.beta2 spec/mongoid/config/environment_spec.rb
mongoid-4.0.0.beta1 spec/mongoid/config/environment_spec.rb
mongoid-4.0.0.alpha2 spec/mongoid/config/environment_spec.rb
mongoid-4.0.0.alpha1 spec/mongoid/config/environment_spec.rb
sepastian-mongoid-rails4-4.0.1.alpha spec/mongoid/config/environment_spec.rb
sepastian-mongoid-rails4-4.0.0.alpha spec/mongoid/config/environment_spec.rb
mongoid_heroku_stable-4.0.0 spec/mongoid/config/environment_spec.rb
mongoid_rails4-4.0.0 spec/mongoid/config/environment_spec.rb