Booting Your Rails Server in a Script

Posted on 02 May 2013 by Eric Oestrich

A recent API Craft Google group post has gotten me playing around with hypermedia APIs again after having an extended stay in Android land. I updated my hypermedia APIs repo, specifically the hypermedia.rb script.

I made it look similar to the nerdword-api script/client.rb which boots a server in the script instead of relying on an external server beeing booted. This was taken from how Cucumber boots capybara.

Below is the code required:

#!/usr/bin/env ruby

require File.expand_path('../config/environment',  __FILE__)
require 'capybara/server'

Capybara.server do |app, port|
  require 'rack/handler/thin'
  Thin::Logging.silent = true
  Rack::Handler::Thin.run(app, :Port => port)
end

server = Capybara::Server.new(Rails.application, 8888)
server.boot
comments powered by Disqus
Eric Oestrich
I am:
All posts
Creative Commons License
This site's content is licensed under a Creative Commons Attribution-ShareAlike 4.0 International License unless otherwise specified. Code on this site is licensed under the MIT License unless otherwise specified.