spin 0.1.4 → 0.1.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/bin/spin +23 -8
- metadata +4 -4
data/bin/spin
CHANGED
@@ -29,7 +29,7 @@ def socket_file
|
|
29
29
|
end
|
30
30
|
|
31
31
|
# ## spin serve
|
32
|
-
def serve(force_rspec = false)
|
32
|
+
def serve(force_rspec = false, time = false)
|
33
33
|
file = socket_file
|
34
34
|
# We delete the tmp file for the Unix socket if it already exists. The file
|
35
35
|
# is scoped to the `pwd`, so if it already exists then it must be from an
|
@@ -50,7 +50,7 @@ def serve(force_rspec = false)
|
|
50
50
|
# In my experience that's the best we can do in terms of preloading. Rails
|
51
51
|
# and the gem dependencies rarely change and so don't need to be reloaded.
|
52
52
|
# But you can't initialize the application because any non-trivial app will
|
53
|
-
# involve it's models/controllers, etc. in its initialization, which you
|
53
|
+
# involve it's models/controllers, etc. in its initialization, which you
|
54
54
|
# definitely don't want to preload.
|
55
55
|
require File.expand_path 'config/application'
|
56
56
|
}
|
@@ -68,6 +68,10 @@ def serve(force_rspec = false)
|
|
68
68
|
files = conn.gets.chomp
|
69
69
|
files = files.split(File::PATH_SEPARATOR)
|
70
70
|
|
71
|
+
# If spin is started with the time flag we will track total execution so
|
72
|
+
# you can easily compare it with time rspec spec for example
|
73
|
+
start = Time.now if time
|
74
|
+
|
71
75
|
# We fork(2) before loading the file so that our pristine preloaded
|
72
76
|
# environment is untouched. The child process will load whatever code it
|
73
77
|
# needs to, then it exits and we're back to the baseline preloaded app.
|
@@ -79,7 +83,7 @@ def serve(force_rspec = false)
|
|
79
83
|
# test file that you want to run (suddenly test/unit seems like the less
|
80
84
|
# crazy one!).
|
81
85
|
if defined?(RSpec) || force_rspec
|
82
|
-
# We pretend the filepath came in as an argument and duplicate the
|
86
|
+
# We pretend the filepath came in as an argument and duplicate the
|
83
87
|
# behaviour of the `rspec` binary.
|
84
88
|
ARGV.push files
|
85
89
|
require 'rspec/autorun'
|
@@ -94,15 +98,16 @@ def serve(force_rspec = false)
|
|
94
98
|
# that destroys the idea of being simple to use. So we wait(2) until the
|
95
99
|
# child process has finished running the test.
|
96
100
|
Process.wait
|
101
|
+
|
102
|
+
# If we are tracking time we will output it here after everything has
|
103
|
+
# finished running
|
104
|
+
puts "Total execution time was #{Time.now - start} seconds" if start
|
97
105
|
end
|
98
106
|
end
|
99
107
|
|
100
108
|
# ## spin push
|
101
109
|
def push
|
102
|
-
#
|
103
|
-
# `spin serve` will accept(2) our connection.
|
104
|
-
socket = UNIXSocket.open(socket_file)
|
105
|
-
# The filenames that we will spin up to `spin serve` are passed in as
|
110
|
+
# The filenames that we will spin up to `spin serve` are passed in as
|
106
111
|
# arguments.
|
107
112
|
files_to_load = ARGV
|
108
113
|
|
@@ -112,7 +117,12 @@ def push
|
|
112
117
|
#
|
113
118
|
# We build a string like `file1.rb:file2.rb` and pass it up to the server.
|
114
119
|
f = files_to_load.select { |f| File.exist?(f) }.join(File::PATH_SEPARATOR)
|
120
|
+
abort if f.empty?
|
115
121
|
puts "Spinning up #{f}"
|
122
|
+
|
123
|
+
# This is the other end of the socket that `spin serve` opens. At this point
|
124
|
+
# `spin serve` will accept(2) our connection.
|
125
|
+
socket = UNIXSocket.open(socket_file)
|
116
126
|
# We put the filenames on the socket for the server to read and then load.
|
117
127
|
socket.puts f
|
118
128
|
rescue Errno::ECONNREFUSED
|
@@ -120,6 +130,7 @@ rescue Errno::ECONNREFUSED
|
|
120
130
|
end
|
121
131
|
|
122
132
|
force_rspec = false
|
133
|
+
time = false
|
123
134
|
options = OptionParser.new do |opts|
|
124
135
|
opts.banner = usage
|
125
136
|
opts.separator ""
|
@@ -135,6 +146,10 @@ options = OptionParser.new do |opts|
|
|
135
146
|
|
136
147
|
opts.on('-e', 'Stub to keep kicker happy')
|
137
148
|
|
149
|
+
opts.on('-t', '--time') do |v|
|
150
|
+
time = true
|
151
|
+
end
|
152
|
+
|
138
153
|
opts.on('-h', '--help') do
|
139
154
|
$stderr.puts opts
|
140
155
|
exit 1
|
@@ -144,7 +159,7 @@ options.parse!
|
|
144
159
|
|
145
160
|
subcommand = ARGV.shift
|
146
161
|
case subcommand
|
147
|
-
when 'serve' then serve(force_rspec)
|
162
|
+
when 'serve' then serve(force_rspec, time)
|
148
163
|
when 'push' then push
|
149
164
|
else
|
150
165
|
$stderr.puts options
|
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: spin
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 17
|
5
5
|
prerelease:
|
6
6
|
segments:
|
7
7
|
- 0
|
8
8
|
- 1
|
9
|
-
-
|
10
|
-
version: 0.1.
|
9
|
+
- 5
|
10
|
+
version: 0.1.5
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- Jesse Storimer
|
@@ -15,7 +15,7 @@ autorequire:
|
|
15
15
|
bindir: bin
|
16
16
|
cert_chain: []
|
17
17
|
|
18
|
-
date: 2011-11-
|
18
|
+
date: 2011-11-15 00:00:00 -05:00
|
19
19
|
default_executable:
|
20
20
|
dependencies: []
|
21
21
|
|