spin 0.4.5 → 0.4.6

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.
Files changed (2) hide show
  1. data/bin/spin +44 -11
  2. metadata +2 -2
data/bin/spin CHANGED
@@ -13,6 +13,7 @@ require 'digest/md5'
13
13
  # environment.
14
14
  require 'benchmark'
15
15
  require 'optparse'
16
+ require 'pathname'
16
17
 
17
18
  SEPARATOR = '|'
18
19
 
@@ -46,8 +47,18 @@ def disconnect(connection)
46
47
  connection.close
47
48
  end
48
49
 
50
+ def rails_root
51
+ path = Pathname.pwd
52
+ until path.join('config/application.rb').file?
53
+ return if path.root?
54
+ path = path.parent
55
+ end
56
+ path
57
+ end
58
+
49
59
  # ## spin serve
50
60
  def serve(force_rspec, force_testunit, time, push_results)
61
+ root_path = rails_root and Dir.chdir(root_path)
51
62
  file = socket_file
52
63
 
53
64
  # We delete the tmp file for the Unix socket if it already exists. The file
@@ -62,7 +73,7 @@ def serve(force_rspec, force_testunit, time, push_results)
62
73
 
63
74
  test_framework = nil
64
75
 
65
- if File.exist? 'config/application.rb'
76
+ if root_path
66
77
  sec = Benchmark.realtime {
67
78
  # We require config/application because that file (typically) loads Rails
68
79
  # and any Bundler deps, as well as loading the initialization code for
@@ -150,6 +161,8 @@ def serve(force_rspec, force_testunit, time, push_results)
150
161
  # Don't abort if the client already disconnected
151
162
  end
152
163
  end
164
+ ensure
165
+ File.delete(file) if file && File.exist?(file)
153
166
  end
154
167
 
155
168
  def fork_and_run(files, push_results, test_framework, conn)
@@ -195,18 +208,38 @@ def push
195
208
  # bit will just be ignored.
196
209
  #
197
210
  # We build a string like `file1.rb|file2.rb` and pass it up to the server.
198
- f = files_to_load.map do |file|
199
- file = file.split(':').first.to_s
211
+ files_to_load.map! do |file|
212
+ args = file.split(':')
213
+
214
+ file_name = args.first.to_s
215
+ line_number = args.last.to_i
200
216
 
201
217
  # If the file exists then we can push it up just like it is
202
- if File.exist?(file)
203
- file
204
- # kicker-2.5.0 now gives us file names without extensions, so we have to try adding it
205
- elsif File.extname(file).empty?
206
- file = [file, 'rb'].join('.')
207
- file if File.exist?(file)
208
- end
209
- end.compact.uniq.join(SEPARATOR)
218
+ file_name = if File.exist?(file_name)
219
+ file_name
220
+ # kicker-2.5.0 now gives us file names without extensions, so we have to try adding it
221
+ elsif File.extname(file_name).empty?
222
+ full_file_name = [file_name, 'rb'].join('.')
223
+ full_file_name if File.exist?(full_file_name)
224
+ end
225
+
226
+ if line_number > 0
227
+ abort "You specified a line number. Only one file can be pushed in this case." if files_to_load.length > 1
228
+
229
+ "#{file_name}:#{line_number}"
230
+ else
231
+ file_name
232
+ end
233
+ end.compact.uniq
234
+
235
+ if root_path = rails_root
236
+ files_to_load.map! do |file|
237
+ Pathname.new(file).expand_path.relative_path_from(root_path).to_s
238
+ end
239
+ Dir.chdir root_path
240
+ end
241
+
242
+ f = files_to_load.join(SEPARATOR)
210
243
 
211
244
  abort if f.empty?
212
245
  puts "Spinning up #{f}"
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: spin
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.5
4
+ version: 0.4.6
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-03-15 00:00:00.000000000 Z
12
+ date: 2012-05-21 00:00:00.000000000 Z
13
13
  dependencies: []
14
14
  description: ! 'Spin preloads your Rails environment to speed up your autotest(ish)
15
15
  workflow.