Sha256: 57e79d89aa487db2c33e359edefe7b564d4d1fe44202f8e4c7a50a524e4aac0f

Contents?: true

Size: 1.29 KB

Versions: 6

Compression:

Stored size: 1.29 KB

Contents

RSpec.describe "Dry::Web::Container" do
  subject(:container) { Dry::Web::Container }

  describe "settings" do
    # Do some acrobatics to make the container reload a setting from scratch
    # and apply a new default
    def reload_setting_for(key)
      if Dry::Web::Container.instance_variables.include?(:@_config)
        Dry::Web::Container.remove_instance_variable(:@_config)
      end

      Dry::Web::Container.instance_variable_get(:@_settings)[key] = nil
      load "dry/web/container.rb"
    end

    describe ".config.env" do
      context "existing RACK_ENV environment variable" do
        before do
          @rack_env = ENV["RACK_ENV"]
          ENV["RACK_ENV"] = "production"

          reload_setting_for :env
        end

        after do
          ENV["RACK_ENV"] = @rack_env
        end

        it "returns the RACK_ENV" do
          expect(Dry::Web::Container.config.env).to eq :production
        end
      end

      context "no RACK_ENV set" do
        before do
          @rack_env = ENV["RACK_ENV"]
          ENV.delete("RACK_ENV")

          reload_setting_for :env
        end

        after do
          ENV["RACK_ENV"] = @rack_env
        end

        it "defaults to development" do
          expect(Dry::Web::Container.config.env).to eq :development
        end
      end
    end
  end
end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
dry-web-0.5.0 spec/unit/container_spec.rb
dry-web-0.4.1 spec/unit/container_spec.rb
dry-web-0.4.0 spec/unit/container_spec.rb
dry-web-0.3.1 spec/unit/container_spec.rb
dry-web-0.3.0 spec/unit/container_spec.rb
dry-web-0.2.0 spec/unit/container_spec.rb