spring 1.3.6 → 1.7.2
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.
- checksums.yaml +4 -4
- data/LICENSE.txt +2 -2
- data/README.md +59 -6
- data/bin/spring +2 -1
- data/lib/spring/application/boot.rb +2 -1
- data/lib/spring/application.rb +25 -6
- data/lib/spring/application_manager.rb +6 -4
- data/lib/spring/boot.rb +2 -0
- data/lib/spring/client/binstub.rb +23 -11
- data/lib/spring/client/run.rb +62 -39
- data/lib/spring/client/server.rb +18 -0
- data/lib/spring/client.rb +11 -1
- data/lib/spring/configuration.rb +3 -1
- data/lib/spring/env.rb +15 -8
- data/lib/spring/failsafe_thread.rb +14 -0
- data/lib/spring/process_title_updater.rb +1 -1
- data/lib/spring/server.rb +28 -8
- data/lib/spring/test/acceptance_test.rb +249 -56
- data/lib/spring/test/application.rb +9 -4
- data/lib/spring/test/application_generator.rb +22 -4
- data/lib/spring/version.rb +1 -1
- data/lib/spring/watcher/polling.rb +0 -2
- data/lib/spring/watcher.rb +1 -1
- metadata +22 -6
data/lib/spring/server.rb
CHANGED
@@ -10,19 +10,24 @@ require "spring/commands"
|
|
10
10
|
|
11
11
|
module Spring
|
12
12
|
class Server
|
13
|
-
def self.boot
|
14
|
-
new.boot
|
13
|
+
def self.boot(options = {})
|
14
|
+
new(options).boot
|
15
15
|
end
|
16
16
|
|
17
17
|
attr_reader :env
|
18
18
|
|
19
|
-
def initialize(
|
20
|
-
@
|
21
|
-
@
|
19
|
+
def initialize(options = {})
|
20
|
+
@foreground = options.fetch(:foreground, false)
|
21
|
+
@env = options[:env] || default_env
|
22
|
+
@applications = Hash.new { |h, k| h[k] = ApplicationManager.new(k, env) }
|
22
23
|
@pidfile = env.pidfile_path.open('a')
|
23
24
|
@mutex = Mutex.new
|
24
25
|
end
|
25
26
|
|
27
|
+
def foreground?
|
28
|
+
@foreground
|
29
|
+
end
|
30
|
+
|
26
31
|
def log(message)
|
27
32
|
env.log "[server] #{message}"
|
28
33
|
end
|
@@ -31,8 +36,8 @@ module Spring
|
|
31
36
|
Spring.verify_environment
|
32
37
|
|
33
38
|
write_pidfile
|
34
|
-
set_pgid
|
35
|
-
ignore_signals
|
39
|
+
set_pgid unless foreground?
|
40
|
+
ignore_signals unless foreground?
|
36
41
|
set_exit_hook
|
37
42
|
set_process_title
|
38
43
|
start_server
|
@@ -42,6 +47,7 @@ module Spring
|
|
42
47
|
server = UNIXServer.open(env.socket_name)
|
43
48
|
log "started on #{env.socket_name}"
|
44
49
|
loop { serve server.accept }
|
50
|
+
rescue Interrupt
|
45
51
|
end
|
46
52
|
|
47
53
|
def serve(client)
|
@@ -100,7 +106,7 @@ module Spring
|
|
100
106
|
end
|
101
107
|
end
|
102
108
|
|
103
|
-
@applications.values.map { |a|
|
109
|
+
@applications.values.map { |a| Spring.failsafe_thread { a.stop } }.map(&:join)
|
104
110
|
end
|
105
111
|
|
106
112
|
def write_pidfile
|
@@ -126,5 +132,19 @@ module Spring
|
|
126
132
|
"spring server | #{env.app_name} | started #{distance} ago"
|
127
133
|
}
|
128
134
|
end
|
135
|
+
|
136
|
+
private
|
137
|
+
|
138
|
+
def default_env
|
139
|
+
Env.new(log_file: default_log_file)
|
140
|
+
end
|
141
|
+
|
142
|
+
def default_log_file
|
143
|
+
if foreground? && !ENV["SPRING_LOG"]
|
144
|
+
$stdout
|
145
|
+
else
|
146
|
+
nil
|
147
|
+
end
|
148
|
+
end
|
129
149
|
end
|
130
150
|
end
|
@@ -1,9 +1,8 @@
|
|
1
|
-
# encoding: utf-8
|
2
|
-
|
3
1
|
require "io/wait"
|
4
2
|
require "timeout"
|
5
3
|
require "spring/sid"
|
6
4
|
require "spring/client"
|
5
|
+
require "active_support/core_ext/string/strip"
|
7
6
|
|
8
7
|
module Spring
|
9
8
|
module Test
|
@@ -29,6 +28,10 @@ module Spring
|
|
29
28
|
@app ||= Spring::Test::Application.new("#{Spring::Test.root}/apps/tmp")
|
30
29
|
end
|
31
30
|
|
31
|
+
def spring_env
|
32
|
+
app.spring_env
|
33
|
+
end
|
34
|
+
|
32
35
|
def assert_output(artifacts, expected)
|
33
36
|
expected.each do |stream, output|
|
34
37
|
assert artifacts[stream].include?(output),
|
@@ -48,6 +51,14 @@ module Spring
|
|
48
51
|
assert_output artifacts, expected_output if expected_output
|
49
52
|
end
|
50
53
|
|
54
|
+
def refute_output_includes(command, not_expected)
|
55
|
+
artifacts = app.run(*Array(command))
|
56
|
+
not_expected.each do |stream, output|
|
57
|
+
assert !artifacts[stream].include?(output),
|
58
|
+
"expected #{stream} to not include '#{output}'.\n\n#{app.debug(artifacts)}"
|
59
|
+
end
|
60
|
+
end
|
61
|
+
|
51
62
|
def assert_speedup(ratio = DEFAULT_SPEEDUP)
|
52
63
|
if ENV['CI']
|
53
64
|
yield
|
@@ -59,6 +70,14 @@ module Spring
|
|
59
70
|
end
|
60
71
|
end
|
61
72
|
|
73
|
+
def without_gem(name)
|
74
|
+
gem_home = app.gem_home.join('gems')
|
75
|
+
FileUtils.mv(gem_home.join(name), app.root)
|
76
|
+
yield
|
77
|
+
ensure
|
78
|
+
FileUtils.mv(app.root.join(name), gem_home)
|
79
|
+
end
|
80
|
+
|
62
81
|
setup do
|
63
82
|
generator.generate_if_missing
|
64
83
|
generator.install_spring
|
@@ -77,6 +96,25 @@ module Spring
|
|
77
96
|
|
78
97
|
test "help message when called without arguments" do
|
79
98
|
assert_success "bin/spring", stdout: 'Usage: spring COMMAND [ARGS]'
|
99
|
+
assert spring_env.server_running?
|
100
|
+
end
|
101
|
+
|
102
|
+
test "shows help" do
|
103
|
+
assert_success "bin/spring help", stdout: 'Usage: spring COMMAND [ARGS]'
|
104
|
+
assert_success "bin/spring -h", stdout: 'Usage: spring COMMAND [ARGS]'
|
105
|
+
assert_success "bin/spring --help", stdout: 'Usage: spring COMMAND [ARGS]'
|
106
|
+
refute spring_env.server_running?
|
107
|
+
end
|
108
|
+
|
109
|
+
test "tells the user that spring is being used when used automatically via binstubs" do
|
110
|
+
assert_success "bin/rails runner ''", stderr: "Running via Spring preloader in process"
|
111
|
+
assert_success app.spring_test_command, stderr: "Running via Spring preloader in process"
|
112
|
+
end
|
113
|
+
|
114
|
+
test "does not tell the user that spring is being used when used automatically via binstubs but quiet is enabled" do
|
115
|
+
File.write("#{app.user_home}/.spring.rb", "Spring.quiet = true")
|
116
|
+
assert_success "bin/rails runner ''"
|
117
|
+
refute_output_includes "bin/rails runner ''", stderr: 'Running via Spring preloader in process'
|
80
118
|
end
|
81
119
|
|
82
120
|
test "test changes are picked up" do
|
@@ -111,13 +149,13 @@ module Spring
|
|
111
149
|
test "app gets reloaded when preloaded files change" do
|
112
150
|
assert_success app.spring_test_command
|
113
151
|
|
114
|
-
File.write(app.application_config, app.application_config.read + <<-
|
152
|
+
File.write(app.application_config, app.application_config.read + <<-RUBY.strip_heredoc)
|
115
153
|
class Foo
|
116
154
|
def self.omg
|
117
155
|
raise "omg"
|
118
156
|
end
|
119
157
|
end
|
120
|
-
|
158
|
+
RUBY
|
121
159
|
File.write(app.test, app.test.read.sub("get :index", "Foo.omg"))
|
122
160
|
|
123
161
|
app.await_reload
|
@@ -150,17 +188,17 @@ module Spring
|
|
150
188
|
|
151
189
|
test "stop command kills server" do
|
152
190
|
app.run app.spring_test_command
|
153
|
-
assert
|
191
|
+
assert spring_env.server_running?, "The server should be running but it isn't"
|
154
192
|
|
155
193
|
assert_success "bin/spring stop"
|
156
|
-
assert !
|
194
|
+
assert !spring_env.server_running?, "The server should not be running but it is"
|
157
195
|
end
|
158
196
|
|
159
197
|
test "custom commands" do
|
160
198
|
# Start spring before setting up the command, to test that it gracefully upgrades itself
|
161
199
|
assert_success "bin/rails runner ''"
|
162
200
|
|
163
|
-
File.write(app.spring_config, <<-
|
201
|
+
File.write(app.spring_config, <<-RUBY.strip_heredoc)
|
164
202
|
class CustomCommand
|
165
203
|
def call
|
166
204
|
puts "omg"
|
@@ -172,7 +210,7 @@ module Spring
|
|
172
210
|
end
|
173
211
|
|
174
212
|
Spring.register_command "custom", CustomCommand.new
|
175
|
-
|
213
|
+
RUBY
|
176
214
|
|
177
215
|
assert_success "bin/spring custom", stdout: "omg"
|
178
216
|
|
@@ -193,53 +231,166 @@ module Spring
|
|
193
231
|
assert_success "bin/rake -T", stdout: "rake db:migrate"
|
194
232
|
end
|
195
233
|
|
196
|
-
test "binstub
|
197
|
-
|
198
|
-
File.
|
199
|
-
assert_success "bin/rake -T", stdout: "rake db:migrate"
|
234
|
+
test "binstub remove all" do
|
235
|
+
assert_success "bin/spring binstub --remove --all"
|
236
|
+
refute File.exist?(app.path("bin/spring"))
|
200
237
|
end
|
201
238
|
|
202
|
-
test "binstub
|
203
|
-
|
204
|
-
|
239
|
+
test "binstub when spring gem is missing" do
|
240
|
+
without_gem "spring-#{Spring::VERSION}" do
|
241
|
+
File.write(app.gemfile, app.gemfile.read.gsub(/gem 'spring.*/, ""))
|
242
|
+
assert_success "bin/rake -T", stdout: "rake db:migrate"
|
243
|
+
end
|
244
|
+
end
|
205
245
|
|
206
|
-
|
207
|
-
|
208
|
-
|
209
|
-
|
210
|
-
|
211
|
-
|
212
|
-
|
213
|
-
|
214
|
-
|
215
|
-
|
216
|
-
|
217
|
-
|
218
|
-
|
219
|
-
|
220
|
-
|
221
|
-
else
|
222
|
-
|
223
|
-
|
224
|
-
end
|
225
|
-
|
246
|
+
test "binstub when spring binary is missing" do
|
247
|
+
begin
|
248
|
+
File.rename(app.path("bin/spring"), app.path("bin/spring.bak"))
|
249
|
+
assert_success "bin/rake -T", stdout: "rake db:migrate"
|
250
|
+
ensure
|
251
|
+
File.rename(app.path("bin/spring.bak"), app.path("bin/spring"))
|
252
|
+
end
|
253
|
+
end
|
254
|
+
|
255
|
+
test "binstub upgrade with old binstub" do
|
256
|
+
File.write(app.path("bin/rake"), <<-RUBY.strip_heredoc)
|
257
|
+
#!/usr/bin/env ruby
|
258
|
+
|
259
|
+
if !Process.respond_to?(:fork) || Gem::Specification.find_all_by_name("spring").empty?
|
260
|
+
exec "bundle", "exec", "rake", *ARGV
|
261
|
+
else
|
262
|
+
ARGV.unshift "rake"
|
263
|
+
load Gem.bin_path("spring", "spring")
|
264
|
+
end
|
265
|
+
RUBY
|
266
|
+
|
267
|
+
File.write(app.path("bin/rails"), <<-RUBY.strip_heredoc)
|
268
|
+
#!/usr/bin/env ruby
|
269
|
+
|
270
|
+
if !Process.respond_to?(:fork) || Gem::Specification.find_all_by_name("spring").empty?
|
271
|
+
APP_PATH = File.expand_path('../../config/application', __FILE__)
|
272
|
+
require_relative '../config/boot'
|
273
|
+
require 'rails/commands'
|
274
|
+
else
|
275
|
+
ARGV.unshift "rails"
|
276
|
+
load Gem.bin_path("spring", "spring")
|
277
|
+
end
|
278
|
+
RUBY
|
226
279
|
|
227
280
|
assert_success "bin/spring binstub --all", stdout: "upgraded"
|
228
281
|
|
229
|
-
|
230
|
-
#!/usr/bin/env ruby
|
231
|
-
#{Spring::Client::Binstub::LOADER.strip}
|
232
|
-
require 'bundler/setup'
|
233
|
-
load Gem.bin_path('rake', 'rake')
|
234
|
-
|
282
|
+
expected = <<-RUBY.gsub(/^ /, "")
|
283
|
+
#!/usr/bin/env ruby
|
284
|
+
#{Spring::Client::Binstub::LOADER.strip}
|
285
|
+
require 'bundler/setup'
|
286
|
+
load Gem.bin_path('rake', 'rake')
|
287
|
+
RUBY
|
288
|
+
assert_equal expected, app.path("bin/rake").read
|
289
|
+
|
290
|
+
expected = <<-RUBY.gsub(/^ /, "")
|
291
|
+
#!/usr/bin/env ruby
|
292
|
+
#{Spring::Client::Binstub::LOADER.strip}
|
293
|
+
APP_PATH = File.expand_path('../../config/application', __FILE__)
|
294
|
+
require_relative '../config/boot'
|
295
|
+
require 'rails/commands'
|
296
|
+
RUBY
|
297
|
+
assert_equal expected, app.path("bin/rails").read
|
298
|
+
end
|
299
|
+
|
300
|
+
test "binstub upgrade with new binstub variations" do
|
301
|
+
expected = <<-RUBY.gsub(/^ /, "")
|
302
|
+
#!/usr/bin/env ruby
|
303
|
+
#{Spring::Client::Binstub::LOADER.strip}
|
304
|
+
require 'bundler/setup'
|
305
|
+
load Gem.bin_path('rake', 'rake')
|
306
|
+
RUBY
|
307
|
+
|
308
|
+
# older variation with double quotes
|
309
|
+
File.write(app.path("bin/rake"), <<-RUBY.strip_heredoc)
|
310
|
+
#!/usr/bin/env ruby
|
311
|
+
begin
|
312
|
+
load File.expand_path("../spring", __FILE__)
|
313
|
+
rescue LoadError
|
314
|
+
end
|
315
|
+
require 'bundler/setup'
|
316
|
+
load Gem.bin_path('rake', 'rake')
|
317
|
+
RUBY
|
318
|
+
|
319
|
+
assert_success "bin/spring binstub rake", stdout: "bin/rake: upgraded"
|
320
|
+
assert_equal expected, app.path("bin/rake").read
|
321
|
+
|
322
|
+
# newer variation with single quotes
|
323
|
+
File.write(app.path("bin/rake"), <<-RUBY.strip_heredoc)
|
324
|
+
#!/usr/bin/env ruby
|
325
|
+
begin
|
326
|
+
load File.expand_path('../spring', __FILE__)
|
327
|
+
rescue LoadError
|
328
|
+
end
|
329
|
+
require 'bundler/setup'
|
330
|
+
load Gem.bin_path('rake', 'rake')
|
331
|
+
RUBY
|
332
|
+
|
333
|
+
assert_success "bin/spring binstub rake", stdout: "bin/rake: upgraded"
|
334
|
+
assert_equal expected, app.path("bin/rake").read
|
335
|
+
|
336
|
+
# newer variation which checks end of exception message
|
337
|
+
File.write(app.path("bin/rake"), <<-RUBY.strip_heredoc)
|
338
|
+
#!/usr/bin/env ruby
|
339
|
+
begin
|
340
|
+
spring_bin_path = File.expand_path('../spring', __FILE__)
|
341
|
+
load spring_bin_path
|
342
|
+
rescue LoadError => e
|
343
|
+
raise unless e.message.end_with? spring_bin_path, 'spring/binstub'
|
344
|
+
end
|
345
|
+
require 'bundler/setup'
|
346
|
+
load Gem.bin_path('rake', 'rake')
|
347
|
+
RUBY
|
235
348
|
|
236
|
-
|
237
|
-
|
238
|
-
|
239
|
-
|
240
|
-
|
241
|
-
|
242
|
-
|
349
|
+
assert_success "bin/spring binstub rake", stdout: "bin/rake: upgraded"
|
350
|
+
assert_equal expected, app.path("bin/rake").read
|
351
|
+
end
|
352
|
+
|
353
|
+
test "binstub remove with new binstub variations" do
|
354
|
+
# older variation with double quotes
|
355
|
+
File.write(app.path("bin/rake"), <<-RUBY.strip_heredoc)
|
356
|
+
#!/usr/bin/env ruby
|
357
|
+
begin
|
358
|
+
load File.expand_path("../spring", __FILE__)
|
359
|
+
rescue LoadError
|
360
|
+
end
|
361
|
+
require 'bundler/setup'
|
362
|
+
load Gem.bin_path('rake', 'rake')
|
363
|
+
RUBY
|
364
|
+
|
365
|
+
# newer variation with single quotes
|
366
|
+
File.write(app.path("bin/rails"), <<-RUBY.strip_heredoc)
|
367
|
+
#!/usr/bin/env ruby
|
368
|
+
begin
|
369
|
+
load File.expand_path('../spring', __FILE__)
|
370
|
+
rescue LoadError
|
371
|
+
end
|
372
|
+
APP_PATH = File.expand_path('../../config/application', __FILE__)
|
373
|
+
require_relative '../config/boot'
|
374
|
+
require 'rails/commands'
|
375
|
+
RUBY
|
376
|
+
|
377
|
+
assert_success "bin/spring binstub --remove rake", stdout: "bin/rake: spring removed"
|
378
|
+
assert_success "bin/spring binstub --remove rails", stdout: "bin/rails: spring removed"
|
379
|
+
|
380
|
+
expected = <<-RUBY.strip_heredoc
|
381
|
+
#!/usr/bin/env ruby
|
382
|
+
require 'bundler/setup'
|
383
|
+
load Gem.bin_path('rake', 'rake')
|
384
|
+
RUBY
|
385
|
+
assert_equal expected, app.path("bin/rake").read
|
386
|
+
|
387
|
+
expected = <<-RUBY.strip_heredoc
|
388
|
+
#!/usr/bin/env ruby
|
389
|
+
APP_PATH = File.expand_path('../../config/application', __FILE__)
|
390
|
+
require_relative '../config/boot'
|
391
|
+
require 'rails/commands'
|
392
|
+
RUBY
|
393
|
+
assert_equal expected, app.path("bin/rails").read
|
243
394
|
end
|
244
395
|
|
245
396
|
test "after fork callback" do
|
@@ -252,6 +403,13 @@ CODE
|
|
252
403
|
assert_success "bin/rails runner 'puts 2'", stdout: "!callback!\n2"
|
253
404
|
end
|
254
405
|
|
406
|
+
test "can define client tasks" do
|
407
|
+
File.write("#{app.spring_client_config}", <<-RUBY)
|
408
|
+
Spring::Client::COMMANDS["foo"] = lambda { |args| puts "bar -- \#{args.inspect}" }
|
409
|
+
RUBY
|
410
|
+
assert_success "bin/spring foo --baz", stdout: "bar -- [\"foo\", \"--baz\"]\n"
|
411
|
+
end
|
412
|
+
|
255
413
|
test "missing config/application.rb" do
|
256
414
|
app.application_config.delete
|
257
415
|
assert_failure "bin/rake -T", stderr: "unable to find your config/application.rb"
|
@@ -278,17 +436,17 @@ CODE
|
|
278
436
|
end
|
279
437
|
|
280
438
|
test "setting env vars with rake" do
|
281
|
-
File.write(app.path("lib/tasks/env.rake"), <<-
|
439
|
+
File.write(app.path("lib/tasks/env.rake"), <<-RUBY.strip_heredoc)
|
282
440
|
task :print_rails_env => :environment do
|
283
441
|
puts Rails.env
|
284
442
|
end
|
285
443
|
|
286
444
|
task :print_env do
|
287
|
-
ENV.each { |k, v| puts "
|
445
|
+
ENV.each { |k, v| puts "\#{k}=\#{v}" }
|
288
446
|
end
|
289
447
|
|
290
448
|
task(:default).clear.enhance [:print_rails_env]
|
291
|
-
|
449
|
+
RUBY
|
292
450
|
|
293
451
|
assert_success "bin/rake RAILS_ENV=test print_rails_env", stdout: "test"
|
294
452
|
assert_success "bin/rake FOO=bar print_env", stdout: "FOO=bar"
|
@@ -305,15 +463,15 @@ CODE
|
|
305
463
|
end
|
306
464
|
|
307
465
|
test "changing the Gemfile works when spring calls into itself" do
|
308
|
-
File.write(app.path("script.rb"), <<-
|
466
|
+
File.write(app.path("script.rb"), <<-RUBY.strip_heredoc)
|
309
467
|
gemfile = Rails.root.join("Gemfile")
|
310
|
-
File.write(gemfile, "\#{gemfile.read}gem '
|
468
|
+
File.write(gemfile, "\#{gemfile.read}gem 'text'\\n")
|
311
469
|
Bundler.with_clean_env do
|
312
470
|
system(#{app.env.inspect}, "bundle install")
|
313
471
|
end
|
314
|
-
output = `\#{Rails.root.join('bin/rails')} runner 'require "
|
315
|
-
exit output
|
316
|
-
|
472
|
+
output = `\#{Rails.root.join('bin/rails')} runner 'require "text"; puts "done";'`
|
473
|
+
exit output.include? "done\n"
|
474
|
+
RUBY
|
317
475
|
|
318
476
|
assert_success [%(bin/rails runner 'load Rails.root.join("script.rb")'), timeout: 60]
|
319
477
|
end
|
@@ -341,6 +499,41 @@ CODE
|
|
341
499
|
expr = "p Kernel.private_instance_methods.include?(:raise)"
|
342
500
|
assert_success %(bin/rails runner '#{expr}'), stdout: "true"
|
343
501
|
end
|
502
|
+
|
503
|
+
test "custom bundle path" do
|
504
|
+
bundle_path = app.path(".bundle/#{Bundler.ruby_scope}")
|
505
|
+
bundle_path.dirname.mkpath
|
506
|
+
|
507
|
+
FileUtils.cp_r "#{app.gem_home}/", bundle_path.to_s
|
508
|
+
|
509
|
+
app.run! "bundle install --path .bundle --clean --local"
|
510
|
+
|
511
|
+
assert_speedup do
|
512
|
+
2.times { assert_success "bundle exec rails runner ''" }
|
513
|
+
end
|
514
|
+
end
|
515
|
+
|
516
|
+
test "booting a foreground server" do
|
517
|
+
FileUtils.cd(app.root) do
|
518
|
+
assert !spring_env.server_running?
|
519
|
+
assert_success "bin/spring server &"
|
520
|
+
|
521
|
+
Timeout.timeout(10) do
|
522
|
+
sleep 0.1 until spring_env.server_running? && spring_env.socket_path.exist?
|
523
|
+
end
|
524
|
+
|
525
|
+
assert_success app.spring_test_command
|
526
|
+
end
|
527
|
+
end
|
528
|
+
|
529
|
+
test "server boot timeout" do
|
530
|
+
app.env["SPRING_SERVER_COMMAND"] = "sleep 1"
|
531
|
+
File.write("#{app.spring_client_config}", %(
|
532
|
+
Spring::Client::Run.const_set(:BOOT_TIMEOUT, 0.1)
|
533
|
+
))
|
534
|
+
|
535
|
+
assert_failure "bin/rails runner ''", stderr: "timed out"
|
536
|
+
end
|
344
537
|
end
|
345
538
|
end
|
346
539
|
end
|
@@ -9,7 +9,8 @@ module Spring
|
|
9
9
|
|
10
10
|
def initialize(root)
|
11
11
|
@root = Pathname.new(root)
|
12
|
-
@spring_env = Spring::Env.new(root)
|
12
|
+
@spring_env = Spring::Env.new(root: root)
|
13
|
+
@times = nil
|
13
14
|
end
|
14
15
|
|
15
16
|
def exists?
|
@@ -48,7 +49,7 @@ module Spring
|
|
48
49
|
end
|
49
50
|
|
50
51
|
def gem_home
|
51
|
-
path "
|
52
|
+
path "../gems/#{RUBY_VERSION}"
|
52
53
|
end
|
53
54
|
|
54
55
|
def user_home
|
@@ -88,6 +89,10 @@ module Spring
|
|
88
89
|
path "config/spring.rb"
|
89
90
|
end
|
90
91
|
|
92
|
+
def spring_client_config
|
93
|
+
path "config/spring_client.rb"
|
94
|
+
end
|
95
|
+
|
91
96
|
def run(command, opts = {})
|
92
97
|
start_time = Time.now
|
93
98
|
|
@@ -116,8 +121,8 @@ module Spring
|
|
116
121
|
@times << (Time.now - start_time) if @times
|
117
122
|
|
118
123
|
output.merge(status: status, command: command)
|
119
|
-
rescue Timeout::Error
|
120
|
-
raise
|
124
|
+
rescue Timeout::Error
|
125
|
+
raise Timeout::Error, "While running command:\n\n#{dump_streams(command, read_streams)}"
|
121
126
|
end
|
122
127
|
|
123
128
|
def with_timing
|
@@ -8,6 +8,7 @@ module Spring
|
|
8
8
|
@version = RailsVersion.new(version_constraint.split(' ').last)
|
9
9
|
@application = Application.new(root)
|
10
10
|
@bundled = false
|
11
|
+
@installed = false
|
11
12
|
end
|
12
13
|
|
13
14
|
def test_root
|
@@ -52,19 +53,36 @@ module Spring
|
|
52
53
|
FileUtils.mkdir_p(application.user_home)
|
53
54
|
FileUtils.rm_rf(application.path("test/performance"))
|
54
55
|
|
55
|
-
|
56
|
+
append_to_file(application.gemfile, "gem 'spring', '#{Spring::VERSION}'")
|
56
57
|
|
57
58
|
if version.needs_testunit?
|
58
|
-
|
59
|
+
append_to_file(application.gemfile, "gem 'spring-commands-testunit'")
|
60
|
+
end
|
61
|
+
|
62
|
+
if RUBY_VERSION == "1.9.3"
|
63
|
+
append_to_file(application.gemfile, "gem 'mime-types', '~> 2'")
|
64
|
+
end
|
65
|
+
|
66
|
+
rewrite_file(application.gemfile) do |c|
|
67
|
+
c.sub!("https://rubygems.org", "http://rubygems.org")
|
68
|
+
c.gsub!(/(gem '(byebug|web-console|sdoc|jbuilder)')/, "# \\1")
|
69
|
+
c
|
59
70
|
end
|
60
71
|
|
61
|
-
File.write(application.gemfile, application.gemfile.read.sub("https://rubygems.org", "http://rubygems.org"))
|
62
72
|
|
63
73
|
if application.path("bin").exist?
|
64
74
|
FileUtils.cp_r(application.path("bin"), application.path("bin_original"))
|
65
75
|
end
|
66
76
|
end
|
67
77
|
|
78
|
+
def rewrite_file(file)
|
79
|
+
File.write(file, yield(file.read))
|
80
|
+
end
|
81
|
+
|
82
|
+
def append_to_file(file, add)
|
83
|
+
rewrite_file(file) { |c| c << "#{add}\n" }
|
84
|
+
end
|
85
|
+
|
68
86
|
def generate_if_missing
|
69
87
|
generate unless application.exists?
|
70
88
|
end
|
@@ -99,7 +117,7 @@ module Spring
|
|
99
117
|
system("gem build #{name}.gemspec 2>&1")
|
100
118
|
end
|
101
119
|
|
102
|
-
application.run! "gem install #{spec.gem_dir}/#{name}-*.gem", timeout: nil
|
120
|
+
application.run! "gem install #{spec.gem_dir}/#{name}-*.gem --no-ri --no-rdoc", timeout: nil
|
103
121
|
end
|
104
122
|
end
|
105
123
|
|
data/lib/spring/version.rb
CHANGED