2017-02-04 10:35:46 +00:00
|
|
|
require "./spec_helper"
|
|
|
|
|
2018-06-30 11:16:55 +00:00
|
|
|
private def run(code)
|
|
|
|
code = <<-CR
|
|
|
|
require "./src/kemal"
|
|
|
|
#{code}
|
|
|
|
CR
|
|
|
|
String.build do |stdout|
|
2019-08-30 11:32:23 +00:00
|
|
|
stderr = String.build do |io|
|
|
|
|
Process.new("crystal", ["eval"], input: IO::Memory.new(code), output: stdout, error: io).wait
|
2018-06-30 11:16:55 +00:00
|
|
|
end
|
2019-08-30 11:32:23 +00:00
|
|
|
fail(stderr) unless stderr.empty?
|
2018-06-30 11:16:55 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2017-02-04 10:35:46 +00:00
|
|
|
describe "Run" do
|
|
|
|
it "runs a code block after starting" do
|
2018-06-30 11:16:55 +00:00
|
|
|
run(<<-CR).should eq "started\nstopped\n"
|
|
|
|
Kemal.config.env = "test"
|
|
|
|
Kemal.run do
|
|
|
|
puts "started"
|
|
|
|
Kemal.stop
|
|
|
|
puts "stopped"
|
|
|
|
end
|
|
|
|
CR
|
2017-02-04 10:35:46 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
it "runs without a block being specified" do
|
2018-06-30 11:16:55 +00:00
|
|
|
run(<<-CR).should eq "[test] Kemal is ready to lead at http://0.0.0.0:3000\ntrue\n"
|
|
|
|
Kemal.config.env = "test"
|
|
|
|
Kemal.run
|
|
|
|
puts Kemal.config.running
|
|
|
|
CR
|
|
|
|
end
|
|
|
|
|
|
|
|
it "allows custom HTTP::Server bind" do
|
|
|
|
run(<<-CR).should eq "[test] Kemal is ready to lead at http://127.0.0.1:3000, http://0.0.0.0:3001\n"
|
|
|
|
Kemal.config.env = "test"
|
|
|
|
Kemal.run do |config|
|
|
|
|
server = config.server.not_nil!
|
|
|
|
server.bind_tcp "127.0.0.1", 3000, reuse_port: true
|
|
|
|
server.bind_tcp "0.0.0.0", 3001, reuse_port: true
|
|
|
|
end
|
|
|
|
CR
|
2017-02-04 10:35:46 +00:00
|
|
|
end
|
|
|
|
end
|