Sha256: 07fdd35840fe1edd0d76ca0db61d0deda623452d554122627e54572e62d04d21

Contents?: true

Size: 1.38 KB

Versions: 1

Compression:

Stored size: 1.38 KB

Contents

# frozen_string_literal: true

require_relative "helper"
require_relative "../lib/tynn/environment"

class EnvironmentTest < Minitest::Test
  def setup
    @app = Class.new(Tynn)
  end

  def test_without_rack_env
    env, ENV["RACK_ENV"] = ENV.to_h, nil

    @app.plugin(Tynn::Environment)

    assert_equal :development, @app.environment
  ensure
    ENV.replace(env)
  end

  def test_with_rack_env
    env, ENV["RACK_ENV"] = ENV.to_h, "test"

    @app.plugin(Tynn::Environment)

    assert_equal :test, @app.environment
  ensure
    ENV.replace(env)
  end

  def test_set_environment
    @app.plugin(Tynn::Environment, env: :development)

    @app.set(:environment, :test)

    assert_equal :test, @app.environment
  end

  def test_predicate_methods
    @app.plugin(Tynn::Environment, env: :development)

    assert_equal true, @app.development?
    assert_equal false, @app.production?
    assert_equal false, @app.test?
    assert_equal false, @app.staging?
  end

  def test_configure
    @app.plugin(Tynn::Environment)

    @app.set(:environment, :test)

    @app.configure(:test) do
      @app.set(:test, true)
    end

    @app.configure(:development, :test) do |app|
      app.set(:production, false)
    end

    @app.configure(:production) do
      raise "This should not be executed"
    end

    assert_equal true, @app.settings[:test]
    assert_equal false, @app.settings[:production]
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
tynn-2.0.0.alpha test/environment_test.rb