あなたはあなた自身の単純なサーバーを転がすことができます。これはthinとrspecを使用した簡単な例です(これらのgemとラックをインストールする必要があります):
# spec/support/test_server.rb
require 'rubygems'
require 'rack'
module MyApp
module Test
class Server
def call(env)
@root = File.expand_path(File.dirname(__FILE__))
path = Rack::Utils.unescape(env['PATH_INFO'])
path += 'index.html' if path == '/'
file = @root + "#{path}"
params = Rack::Utils.parse_nested_query(env['QUERY_STRING'])
if File.exists?(file)
[ 200, {"Content-Type" => "text/html"}, File.read(file) ]
else
[ 404, {'Content-Type' => 'text/plain'}, 'file not found' ]
end
end
end
end
end
次に、あなたのspec_helper
:
# Include all files under spec/support
Dir["./spec/support/**/*.rb"].each {|f| require f}
# Start a local rack server to serve up test pages.
@server_thread = Thread.new do
Rack::Handler::Thin.run MyApp::Test::Server.new, :Port => 9292
end
sleep(1) # wait a sec for the server to be booted
これにより、ディレクトリに保存するすべてのファイルが提供されますspec/support
。それ自体を含みます。他のすべてのリクエストの場合、404が返されます。
これは基本的に、前の回答で述べたようにカピバラが行うことですが、多くの洗練されたものはありません。