Skip to content

Commit

Permalink
First socket spec
Browse files Browse the repository at this point in the history
  • Loading branch information
jstorimer committed Jun 11, 2012
1 parent 2cc4995 commit c5b4774
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 1 deletion.
6 changes: 5 additions & 1 deletion bin/spin
@@ -1,6 +1,10 @@
#!/usr/bin/env ruby

require 'spin/socket'

# requires
# parse options
# at_exit { rm socketfile }
at_exit { File.delete(Spin::Socket.filepath) }
# signal handlers
# spawn file watcher w/ pipe
# preload rails
Expand Down
16 changes: 16 additions & 0 deletions lib/spin/socket.rb
@@ -0,0 +1,16 @@
# A Spin::Socket wraps a Unix socket

require 'tempfile' # for Dir::tmpdir
require 'digest/md5'

module Spin
class Socket
# This returns a path in the top level of the tmpdir with
# a name unique to spin and the pwd.
def self.filepath
slug = Digest::MD5.hexdigest ['spin', Dir.pwd].join('-')
[Dir::tmpdir, slug].join('/')
end
end
end

24 changes: 24 additions & 0 deletions spec/spin/socket_spec.rb
@@ -0,0 +1,24 @@
require 'minitest/autorun'
require_relative '../../lib/spin/socket'

describe Spin::Socket do
describe '#filepath' do
before do
@filepath = Spin::Socket.filepath
end

it 'is in the tmpdir' do
p @filepath
@filepath.must_include Dir::tmpdir
end

it "includes a digested version of 'spin' and the pwd" do
@filepath.must_include digest("spin-#{Dir.pwd}")
end

def digest(string)
Digest::MD5.hexdigest(string)
end
end
end

0 comments on commit c5b4774

Please sign in to comment.