spin 0.3.0 → 0.4.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (2) hide show
  1. data/bin/spin +47 -31
  2. metadata +26 -44
data/bin/spin CHANGED
@@ -14,6 +14,8 @@ require 'digest/md5'
14
14
  require 'benchmark'
15
15
  require 'optparse'
16
16
 
17
+ SEPARATOR = '|'
18
+
17
19
  def usage
18
20
  <<-USAGE
19
21
  Usage: spin serve
@@ -94,12 +96,20 @@ def serve(force_rspec, force_testunit, time, push_results)
94
96
  puts "Pushing test results back to push processes" if push_results
95
97
 
96
98
  loop do
99
+
100
+ # Trap SIGQUIT (Ctrl+\) and re-run the last files that were pushed.
101
+ trap('QUIT') do
102
+ fork_and_run(@last_files_ran, push_results, test_framework)
103
+ # See WAIT below
104
+ Process.wait
105
+ end
106
+
97
107
  # Since `spin push` reconnects each time it has new files for us we just
98
108
  # need to accept(2) connections from it.
99
109
  conn = socket.accept
100
110
  # This should be a list of relative paths to files.
101
111
  files = conn.gets.chomp
102
- files = files.split(File::PATH_SEPARATOR)
112
+ files = files.split(SEPARATOR)
103
113
 
104
114
  # If spin is started with the time flag we will track total execution so
105
115
  # you can easily compare it with time rspec spec for example
@@ -109,35 +119,9 @@ def serve(force_rspec, force_testunit, time, push_results)
109
119
  # it immediately.
110
120
  disconnect(conn) unless push_results
111
121
 
112
- # We fork(2) before loading the file so that our pristine preloaded
113
- # environment is untouched. The child process will load whatever code it
114
- # needs to, then it exits and we're back to the baseline preloaded app.
115
- fork do
116
- # To push the test results to the push process instead of having them
117
- # displayed by the server, we reopen $stdout/$stderr to the open
118
- # connection.
119
- if push_results
120
- $stdout.reopen(conn)
121
- $stderr.reopen(conn)
122
- end
123
-
124
- puts
125
- puts "Loading #{files.inspect}"
126
-
127
- # Unfortunately rspec's interface isn't as simple as just requiring the
128
- # test file that you want to run (suddenly test/unit seems like the less
129
- # crazy one!).
130
- if test_framework == :rspec
131
- # We pretend the filepath came in as an argument and duplicate the
132
- # behaviour of the `rspec` binary.
133
- ARGV.push files
134
- else
135
- # We require the full path of the file here in the child process.
136
- files.each { |f| require File.expand_path f }
137
- end
138
- end
122
+ fork_and_run(files, push_results, test_framework)
139
123
 
140
- # We don't want the parent process handling multiple test runs at the same
124
+ # WAIT: We don't want the parent process handling multiple test runs at the same
141
125
  # time because then we'd need to deal with multiple test databases, and
142
126
  # that destroys the idea of being simple to use. So we wait(2) until the
143
127
  # child process has finished running the test.
@@ -157,6 +141,38 @@ def serve(force_rspec, force_testunit, time, push_results)
157
141
  end
158
142
  end
159
143
 
144
+ def fork_and_run(files, push_results, test_framework)
145
+ # We fork(2) before loading the file so that our pristine preloaded
146
+ # environment is untouched. The child process will load whatever code it
147
+ # needs to, then it exits and we're back to the baseline preloaded app.
148
+ fork do
149
+ # To push the test results to the push process instead of having them
150
+ # displayed by the server, we reopen $stdout/$stderr to the open
151
+ # connection.
152
+ if push_results
153
+ $stdout.reopen(conn)
154
+ $stderr.reopen(conn)
155
+ end
156
+
157
+ puts
158
+ puts "Loading #{files.inspect}"
159
+
160
+ # Unfortunately rspec's interface isn't as simple as just requiring the
161
+ # test file that you want to run (suddenly test/unit seems like the less
162
+ # crazy one!).
163
+ if test_framework == :rspec
164
+ # We pretend the filepath came in as an argument and duplicate the
165
+ # behaviour of the `rspec` binary.
166
+ ARGV.push files
167
+ else
168
+ # We require the full path of the file here in the child process.
169
+ files.each { |f| require File.expand_path f }
170
+ end
171
+
172
+ end
173
+ @last_files_ran = files
174
+ end
175
+
160
176
  # ## spin push
161
177
  def push
162
178
  # The filenames that we will spin up to `spin serve` are passed in as
@@ -167,8 +183,8 @@ def push
167
183
  # care of scripts that specify files like `spin push -r file.rb`. The `-r`
168
184
  # bit will just be ignored.
169
185
  #
170
- # We build a string like `file1.rb:file2.rb` and pass it up to the server.
171
- f = files_to_load.select { |f| File.exist?(f) }.uniq.join(File::PATH_SEPARATOR)
186
+ # We build a string like `file1.rb|file2.rb` and pass it up to the server.
187
+ f = files_to_load.select { |f| File.exist?(f.split(':')[0].to_s) }.uniq.join(SEPARATOR)
172
188
  abort if f.empty?
173
189
  puts "Spinning up #{f}"
174
190
 
metadata CHANGED
@@ -1,71 +1,53 @@
1
- --- !ruby/object:Gem::Specification
1
+ --- !ruby/object:Gem::Specification
2
2
  name: spin
3
- version: !ruby/object:Gem::Version
4
- hash: 19
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.4.1
5
5
  prerelease:
6
- segments:
7
- - 0
8
- - 3
9
- - 0
10
- version: 0.3.0
11
6
  platform: ruby
12
- authors:
7
+ authors:
13
8
  - Jesse Storimer
14
9
  autorequire:
15
10
  bindir: bin
16
11
  cert_chain: []
17
-
18
- date: 2011-12-04 00:00:00 -05:00
19
- default_executable:
12
+ date: 2011-12-13 00:00:00.000000000 Z
20
13
  dependencies: []
14
+ description: ! 'Spin preloads your Rails environment to speed up your autotest(ish)
15
+ workflow.
16
+
21
17
 
22
- description: |-
23
- Spin preloads your Rails environment to speed up your autotest(ish) workflow.
24
-
25
- By preloading your Rails environment for testing you don't load the same code over and over and over... Spin works best for an autotest(ish) workflow.
26
- email:
18
+ By preloading your Rails environment for testing you don''t load the same code over
19
+ and over and over... Spin works best for an autotest(ish) workflow.'
20
+ email:
27
21
  - jstorimer@gmail.com
28
- executables:
22
+ executables:
29
23
  - spin
30
24
  extensions: []
31
-
32
25
  extra_rdoc_files: []
33
-
34
- files:
26
+ files:
35
27
  - bin/spin
36
- has_rdoc: true
37
28
  homepage: http://jstorimer.github.com/spin
38
29
  licenses: []
39
-
40
30
  post_install_message:
41
31
  rdoc_options: []
42
-
43
- require_paths:
32
+ require_paths:
44
33
  - lib
45
- required_ruby_version: !ruby/object:Gem::Requirement
34
+ required_ruby_version: !ruby/object:Gem::Requirement
46
35
  none: false
47
- requirements:
48
- - - ">="
49
- - !ruby/object:Gem::Version
50
- hash: 3
51
- segments:
52
- - 0
53
- version: "0"
54
- required_rubygems_version: !ruby/object:Gem::Requirement
36
+ requirements:
37
+ - - ! '>='
38
+ - !ruby/object:Gem::Version
39
+ version: '0'
40
+ required_rubygems_version: !ruby/object:Gem::Requirement
55
41
  none: false
56
- requirements:
57
- - - ">="
58
- - !ruby/object:Gem::Version
59
- hash: 3
60
- segments:
61
- - 0
62
- version: "0"
42
+ requirements:
43
+ - - ! '>='
44
+ - !ruby/object:Gem::Version
45
+ version: '0'
63
46
  requirements: []
64
-
65
47
  rubyforge_project:
66
- rubygems_version: 1.6.2
48
+ rubygems_version: 1.8.11
67
49
  signing_key:
68
50
  specification_version: 3
69
51
  summary: Spin preloads your Rails environment to speed up your autotest(ish) workflow.
70
52
  test_files: []
71
-
53
+ has_rdoc: