这是我的机架应用程序:
class MainAppLogic
def initialize
Rack::Server.start(:app =>Server, :server => "WEBrick", :Port => "8080")
end
end
class Server
def self.call(env)
return [200, {},["Hello, World"]]
end
end
实际运行时,它会按应有的方式运行并向所有请求返回“Hello World”。我无法说服 rack-test 使用它。这是我的测试:
require "rspec"
require "rack/test"
require "app"
# Rspec config source: https://github.com/shiroyasha/sinatra_rspec
RSpec.configure do |config|
config.include Rack::Test::Methods
end
describe MainAppLogic do
# App method source: https://github.com/shiroyasha/sinatra_rspec
def app
MainAppLogic.new
end
it "starts a server when initialized" do
get "/", {}, "SERVER_PORT" => "8080"
last_response.body.should be != nil
end
end
当我对此进行测试时,它无法抱怨MainAppLogic
不是机架服务器,特别是它没有响应MainAppLogic.call
. 我怎样才能让它知道忽略这MainAppLogic
不是机架服务器而只是向 发出请求localhost:8080
,因为那里的服务器已经启动?