shard-kemal/spec/config_spec.cr
Ben Jolitz 1f809c68c8 Support additional options as part of the Config
This commit adds the ability to add a closure suitable for adding
additional options. It is expected to allow someone to set global,
module or class level variables so they can pass changes/options
suitable for making decisions.
2016-03-30 13:33:51 -07:00

46 lines
1 KiB
Crystal

require "./spec_helper"
describe "Config" do
it "sets default port to 3000" do
config = Kemal.config
config.port.should eq 3000
end
it "sets default environment to development" do
config = Kemal.config
config.env.should eq "development"
end
it "sets environment to production" do
config = Kemal.config
config.env = "production"
config.env.should eq "production"
end
it "sets host binding" do
config = Kemal.config
config.host_binding = "127.0.0.1"
config.host_binding.should eq "127.0.0.1"
end
it "adds a custom handler" do
config = Kemal.config
config.add_handler CustomTestHandler.new
config.handlers.size.should eq(5)
end
it "adds custom options" do
config = Kemal.config
ARGV.push("--test")
ARGV.push("FOOBAR")
$test_option = nil
config.on_options = ->(parser : OptionParser) {
parser.on("--test TEST_OPTION", "Test an option") do |opt|
$test_option = opt
end
}
Kemal::CLI.new
$test_option.should eq("FOOBAR")
end
end