How to test unicorn.rb

83 Views Asked by At

I've actually been Unicorn for a few years now, but I've never really run any proper tests on my basic code for running a Unicorn application. So one of the first things I want to test is unicorn.rb. At the very least, I'd like to make sure it compiles, but, of course, I want to eventually run more detailed tests on it.

But I can't figure out how to load the file. Obviously just running it from the command line doesn't accomplish anything. I'd like to run the code in the file without having to run Unicorn itself. That is, I want to do some basic unit testing before going much further with my application.

So the question is how do I load and run unicorn.rb by itself, with minimal extra required code.

If you're interested, here's my current unicorn.rb. I welcome your feedback, but my main goal right now is to find a way to run tests on just that file.

# Snout is a tiny application for experimenting with Unicorn.
# Nothing more, nothing less.

# path to data directory
snout_data_root = '/srv/apps/snout'

# path to app that will be used to configure unicorn
@dir = File.dirname(__FILE__)

# workers
worker_processes 5
working_directory @dir

# timeout
timeout 30

# set user and group
user 'www-data', 'www-data'

# Specify path to socket unicorn listens to
listen "#{snout_data_root}/sockets/unicorn.sock", :backlog => 64

# Set process id path
pid "#{snout_data_root}/pids/unicorn.pid"

# Not exactly sure what this does, but the following page suggests it's
# generally a good idea to have this setting.
# https://bogomips.org/unicorn/Unicorn/Configurator.html
rewindable_input false

# avoid spawn loops
preload_app true

# paths to which Unicorn sends STDOUT and STDERR
stderr_path "#{snout_data_root}/logs/unicorn.log"
stdout_path "#{snout_data_root}/logs/unicorn.log"
0

There are 0 best solutions below