1
0
Fork 0
mirror of https://github.com/puma/puma.git synced 2022-11-09 13:48:40 -05:00
puma--puma/test/test_launcher.rb
Dave Allie 809a3f4c7b Allow extra runtime deps to be defined when using prune_bundler (#1105)
* Allow extra runtime deps to be defined when using prune_bundler

* Check extra_runtime_dependencies is set before iterating over them

* Load additional paths for extra runtime dep gems

* Don't load extra dependencies, just add their paths to $LOAD_PATH

* Fix typos and extraneous checks and rescues

* Use Gem::Specification#full_require_paths when available

* Prevent use of prune_bundler and extra_runtime_dependencies with early versions of RubyGems

* Ensure LOAD_PATH is modified by extra_runtime_dependencies

* Refactor prune_bundler in launcher.rb and write some unit tests
2019-09-02 16:10:33 +00:00

63 lines
2.4 KiB
Ruby

require_relative "helper"
require "puma/configuration"
require "puma/const"
require "puma/launcher"
class TestLauncher < Minitest::Test
def test_dependencies_and_files_to_require_after_prune_is_correctly_built_for_no_extra_deps
skip_on :appveyor, suffix: " - bundler not used in appveyor so prune bundler logic tests unavailable"
l = Puma::Launcher.new Puma::Configuration.new
deps, dirs = l.send(:dependencies_and_files_to_require_after_prune)
assert_equal(1, deps.length)
assert_match(%r{^nio4r:[\d.]+$}, deps.first)
assert_equal(2, dirs.length)
assert_match(%r{puma/lib$}, dirs[0]) # lib dir
assert_match(%r{puma-#{Puma::Const::PUMA_VERSION}$}, dirs[1]) # native extension dir
end
def test_dependencies_and_files_to_require_after_prune_is_correctly_built_with_extra_deps
skip_on :appveyor, suffix: " - bundler not used in appveyor so prune bundler logic tests unavailable"
conf = Puma::Configuration.new do |c|
c.extra_runtime_dependencies ['rdoc']
end
l = Puma::Launcher.new conf
deps, dirs = l.send(:dependencies_and_files_to_require_after_prune)
assert_equal(1, deps.length)
assert_match(%r{^nio4r:[\d.]+$}, deps.first)
assert_equal(3, dirs.length)
assert_match(%r{puma/lib$}, dirs[0]) # lib dir
assert_match(%r{puma-#{Puma::Const::PUMA_VERSION}$}, dirs[1]) # native extension dir
assert_match(%r{gems/rdoc-[\d.]+/lib$}, dirs[2]) # rdoc dir
end
def test_extra_runtime_deps_directories_is_empty_for_no_config
l = Puma::Launcher.new Puma::Configuration.new
assert_equal([], l.send(:extra_runtime_deps_directories))
end
def test_extra_runtime_deps_directories_is_correctly_built
skip_on :appveyor, suffix: " - bundler not used in appveyor so prune bundler logic tests unavailable"
conf = Puma::Configuration.new do |c|
c.extra_runtime_dependencies ['rdoc']
end
l = Puma::Launcher.new conf
dep_dirs = l.send(:extra_runtime_deps_directories)
assert_equal(1, dep_dirs.length)
assert_match(%r{gems/rdoc-[\d.]+/lib$}, dep_dirs.first)
end
def test_puma_wild_location_is_an_absolute_path
skip_on :appveyor, suffix: " - bundler not used in appveyor so prune bundler logic tests unavailable"
l = Puma::Launcher.new Puma::Configuration.new
puma_wild_location = l.send(:puma_wild_location)
assert_match(%r{bin/puma-wild$}, puma_wild_location)
# assert no "/../" in path
refute_match(%r{/\.\./}, puma_wild_location)
end
end