Sha256: c702a1362c439de865d2d6ee791ae82387a4204a9759bce29c421afc931a40ef

Contents?: true

Size: 1.37 KB

Versions: 1

Compression:

Stored size: 1.37 KB

Contents

require 'test/unit'

require 'puma'
require 'puma/configuration'

class TestConfigFile < Test::Unit::TestCase
  def test_app_from_rackup
    opts = {:rackup => "test/hello-bind.ru"}
    conf = Puma::Configuration.new opts
    conf.load

    conf.app

    assert_equal ["tcp://127.0.0.1:9292"], conf.options[:binds]
  end

  def test_app_from_app_DSL
    opts = { :config_file => "test/config/app.rb" }
    conf = Puma::Configuration.new opts
    conf.load

    app = conf.app

    assert_equal [200, {}, ["embedded app"]], app.call({})
  end

  def test_double_bind_port
    port = rand(30_000..40_000).to_s
    with_env("PORT" => port) do
      opts = { :binds => ["tcp://#{Configuration::DefaultTCPHost}:#{port}"], :config_file => "test/config/app.rb"}
      conf = Puma::Configuration.new opts
      conf.load

      assert_equal ["tcp://0.0.0.0:#{port}"], conf.options[:binds]
    end
  end

  def test_lowleve_error_handler_DSL
    opts = { :config_file => "test/config/app.rb" }
    conf = Puma::Configuration.new opts
    conf.load

    app = conf.options[:lowlevel_error_handler]

    assert_equal [200, {}, ["error page"]], app.call({})
  end

  private

    def with_env(env = {})
      original_env = {}
      env.each do |k, v|
        original_env[k] = ENV[k]
        ENV[k] = v
      end
      yield
    ensure
      original_env.each do |k, v|
        ENV[k] = v
      end
    end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
puma-2.12.0-java test/test_config.rb