spring 0.9.1 → 1.1.0
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/.travis.yml +2 -0
- data/CHANGELOG.md +51 -0
- data/README.md +118 -53
- data/bin/spring +1 -0
- data/lib/spring/application/boot.rb +16 -0
- data/lib/spring/application.rb +131 -64
- data/lib/spring/application_manager.rb +51 -40
- data/lib/spring/binstub.rb +13 -0
- data/lib/spring/boot.rb +8 -0
- data/lib/spring/client/binstub.rb +150 -39
- data/lib/spring/client/help.rb +4 -12
- data/lib/spring/client/rails.rb +1 -3
- data/lib/spring/client/version.rb +11 -0
- data/lib/spring/client.rb +8 -5
- data/lib/spring/command_wrapper.rb +86 -0
- data/lib/spring/commands/rails.rb +1 -2
- data/lib/spring/commands/rake.rb +0 -4
- data/lib/spring/commands.rb +3 -2
- data/lib/spring/configuration.rb +11 -2
- data/lib/spring/env.rb +24 -22
- data/lib/spring/errors.rb +0 -14
- data/lib/spring/server.rb +10 -34
- data/lib/spring/version.rb +1 -1
- data/lib/spring/watcher/abstract.rb +7 -8
- data/spring.gemspec +2 -1
- data/test/acceptance/app_test.rb +178 -345
- data/test/acceptance/helper.rb +329 -0
- data/test/unit/client/version_test.rb +14 -0
- data/test/unit/watcher_test.rb +12 -8
- metadata +14 -4
data/test/acceptance/app_test.rb
CHANGED
|
@@ -1,164 +1,42 @@
|
|
|
1
1
|
# encoding: utf-8
|
|
2
|
-
require
|
|
3
|
-
require
|
|
2
|
+
require "helper"
|
|
3
|
+
require "acceptance/helper"
|
|
4
|
+
require "io/wait"
|
|
4
5
|
require "timeout"
|
|
5
6
|
require "spring/sid"
|
|
6
|
-
require "spring/
|
|
7
|
+
require "spring/client"
|
|
7
8
|
|
|
8
9
|
class AppTest < ActiveSupport::TestCase
|
|
9
10
|
DEFAULT_SPEEDUP = 0.8
|
|
10
|
-
DEFAULT_TIMEOUT = ENV['CI'] ? 30 : 10
|
|
11
11
|
|
|
12
12
|
def rails_version
|
|
13
13
|
ENV['RAILS_VERSION'] || '~> 4.0.0'
|
|
14
14
|
end
|
|
15
15
|
|
|
16
|
-
def
|
|
17
|
-
|
|
16
|
+
def generator
|
|
17
|
+
@@generator ||= Spring::Test::ApplicationGenerator.new(rails_version)
|
|
18
18
|
end
|
|
19
19
|
|
|
20
|
-
def
|
|
21
|
-
|
|
22
|
-
end
|
|
23
|
-
|
|
24
|
-
def gem_home
|
|
25
|
-
app_root.join "vendor/gems/#{RUBY_VERSION}"
|
|
26
|
-
end
|
|
27
|
-
|
|
28
|
-
def user_home
|
|
29
|
-
app_root.join "user_home"
|
|
30
|
-
end
|
|
31
|
-
|
|
32
|
-
def spring
|
|
33
|
-
gem_home.join "bin/spring"
|
|
34
|
-
end
|
|
35
|
-
|
|
36
|
-
def spring_env
|
|
37
|
-
@spring_env ||= Spring::Env.new(app_root)
|
|
38
|
-
end
|
|
39
|
-
|
|
40
|
-
def stdout
|
|
41
|
-
@stdout ||= IO.pipe
|
|
42
|
-
end
|
|
43
|
-
|
|
44
|
-
def stderr
|
|
45
|
-
@stderr ||= IO.pipe
|
|
46
|
-
end
|
|
47
|
-
|
|
48
|
-
def log_file
|
|
49
|
-
@log_file ||= File.open("/tmp/spring.log", "w+")
|
|
50
|
-
end
|
|
51
|
-
|
|
52
|
-
def env
|
|
53
|
-
@env ||= {
|
|
54
|
-
"GEM_HOME" => gem_home.to_s,
|
|
55
|
-
"GEM_PATH" => "",
|
|
56
|
-
"HOME" => user_home.to_s,
|
|
57
|
-
"RAILS_ENV" => nil,
|
|
58
|
-
"RACK_ENV" => nil,
|
|
59
|
-
"SPRING_LOG" => log_file.path
|
|
60
|
-
}
|
|
61
|
-
end
|
|
62
|
-
|
|
63
|
-
def app_run(command, opts = {})
|
|
64
|
-
start_time = Time.now
|
|
65
|
-
|
|
66
|
-
Bundler.with_clean_env do
|
|
67
|
-
Process.spawn(
|
|
68
|
-
env,
|
|
69
|
-
command.to_s,
|
|
70
|
-
out: stdout.last,
|
|
71
|
-
err: stderr.last,
|
|
72
|
-
in: :close,
|
|
73
|
-
chdir: app_root.to_s,
|
|
74
|
-
)
|
|
75
|
-
end
|
|
76
|
-
|
|
77
|
-
_, status = Timeout.timeout(opts.fetch(:timeout, DEFAULT_TIMEOUT)) { Process.wait2 }
|
|
78
|
-
|
|
79
|
-
if pid = spring_env.pid
|
|
80
|
-
@server_pid = pid
|
|
81
|
-
lines = `ps -A -o ppid= -o pid= | egrep '^\\s*#{@server_pid}'`.lines
|
|
82
|
-
@application_pids = lines.map { |l| l.split.last.to_i }
|
|
83
|
-
end
|
|
84
|
-
|
|
85
|
-
output = read_streams
|
|
86
|
-
puts dump_streams(command, output) if ENV["SPRING_DEBUG"]
|
|
87
|
-
|
|
88
|
-
@times << (Time.now - start_time) if @times
|
|
89
|
-
|
|
90
|
-
output.merge(status: status, command: command)
|
|
91
|
-
rescue Timeout::Error => e
|
|
92
|
-
raise e, "Output:\n\n#{dump_streams(command, read_streams)}"
|
|
93
|
-
end
|
|
94
|
-
|
|
95
|
-
def read_streams
|
|
96
|
-
{
|
|
97
|
-
stdout: read_stream(stdout.first),
|
|
98
|
-
stderr: read_stream(stderr.first),
|
|
99
|
-
log: read_stream(log_file)
|
|
100
|
-
}
|
|
101
|
-
end
|
|
102
|
-
|
|
103
|
-
def read_stream(stream)
|
|
104
|
-
output = ""
|
|
105
|
-
while IO.select([stream], [], [], 0.5) && !stream.eof?
|
|
106
|
-
output << stream.readpartial(10240)
|
|
107
|
-
end
|
|
108
|
-
output
|
|
109
|
-
end
|
|
110
|
-
|
|
111
|
-
def dump_streams(command, streams)
|
|
112
|
-
output = "$ #{command}\n"
|
|
113
|
-
|
|
114
|
-
streams.each do |name, stream|
|
|
115
|
-
unless stream.chomp.empty?
|
|
116
|
-
output << "--- #{name} ---\n"
|
|
117
|
-
output << "#{stream.chomp}\n"
|
|
118
|
-
end
|
|
119
|
-
end
|
|
120
|
-
|
|
121
|
-
output << "\n"
|
|
122
|
-
output
|
|
123
|
-
end
|
|
124
|
-
|
|
125
|
-
def alive?(pid)
|
|
126
|
-
Process.kill 0, pid
|
|
127
|
-
true
|
|
128
|
-
rescue Errno::ESRCH
|
|
129
|
-
false
|
|
130
|
-
end
|
|
131
|
-
|
|
132
|
-
def await_reload
|
|
133
|
-
raise "no pid" if @application_pids.nil? || @application_pids.empty?
|
|
134
|
-
|
|
135
|
-
Timeout.timeout(DEFAULT_TIMEOUT) do
|
|
136
|
-
sleep 0.1 while @application_pids.any? { |p| alive?(p) }
|
|
137
|
-
end
|
|
138
|
-
end
|
|
139
|
-
|
|
140
|
-
def debug(artifacts)
|
|
141
|
-
artifacts = artifacts.dup
|
|
142
|
-
artifacts.delete :status
|
|
143
|
-
dump_streams(artifacts.delete(:command), artifacts)
|
|
20
|
+
def app
|
|
21
|
+
@app ||= Spring::Test::Application.new("#{TEST_ROOT}/apps/tmp")
|
|
144
22
|
end
|
|
145
23
|
|
|
146
24
|
def assert_output(artifacts, expected)
|
|
147
25
|
expected.each do |stream, output|
|
|
148
26
|
assert artifacts[stream].include?(output),
|
|
149
|
-
"expected #{stream} to include '#{output}'.\n\n#{debug(artifacts)}"
|
|
27
|
+
"expected #{stream} to include '#{output}'.\n\n#{app.debug(artifacts)}"
|
|
150
28
|
end
|
|
151
29
|
end
|
|
152
30
|
|
|
153
31
|
def assert_success(command, expected_output = nil)
|
|
154
|
-
artifacts =
|
|
155
|
-
assert artifacts[:status].success?, "expected successful exit status\n\n#{debug(artifacts)}"
|
|
32
|
+
artifacts = app.run(*Array(command))
|
|
33
|
+
assert artifacts[:status].success?, "expected successful exit status\n\n#{app.debug(artifacts)}"
|
|
156
34
|
assert_output artifacts, expected_output if expected_output
|
|
157
35
|
end
|
|
158
36
|
|
|
159
37
|
def assert_failure(command, expected_output = nil)
|
|
160
|
-
artifacts =
|
|
161
|
-
assert !artifacts[:status].success?, "expected unsuccessful exit status\n\n#{debug(artifacts)}"
|
|
38
|
+
artifacts = app.run(*Array(command))
|
|
39
|
+
assert !artifacts[:status].success?, "expected unsuccessful exit status\n\n#{app.debug(artifacts)}"
|
|
162
40
|
assert_output artifacts, expected_output if expected_output
|
|
163
41
|
end
|
|
164
42
|
|
|
@@ -166,279 +44,236 @@ class AppTest < ActiveSupport::TestCase
|
|
|
166
44
|
if ENV['CI']
|
|
167
45
|
yield
|
|
168
46
|
else
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
@times = nil
|
|
173
|
-
end
|
|
174
|
-
end
|
|
175
|
-
|
|
176
|
-
def spring_test_command
|
|
177
|
-
"#{spring} #{rails_3? ? 'testunit' : 'rake test'} #{@test}"
|
|
178
|
-
end
|
|
179
|
-
|
|
180
|
-
def generate_app
|
|
181
|
-
Bundler.with_clean_env do
|
|
182
|
-
assert system("(gem list rails --installed --version '#{rails_version}' || " \
|
|
183
|
-
"gem install rails --version '#{rails_version}') > /dev/null")
|
|
184
|
-
|
|
185
|
-
# Have to shell out otherwise bundler prevents us finding the gem
|
|
186
|
-
version = `ruby -e 'puts Gem::Specification.find_by_name("rails", "#{rails_version}").version'`.chomp
|
|
187
|
-
|
|
188
|
-
assert system("rails _#{version}_ new #{app_root} --skip-bundle --skip-javascript --skip-sprockets > /dev/null")
|
|
189
|
-
|
|
190
|
-
FileUtils.mkdir_p(gem_home)
|
|
191
|
-
FileUtils.mkdir_p(user_home)
|
|
192
|
-
FileUtils.rm_rf("#{app_root}/test/performance/")
|
|
193
|
-
|
|
194
|
-
if rails_3?
|
|
195
|
-
File.write(
|
|
196
|
-
"#{app_root}/Gemfile",
|
|
197
|
-
File.read("#{app_root}/Gemfile") + "gem 'spring-commands-testunit'\n"
|
|
198
|
-
)
|
|
47
|
+
app.with_timing do
|
|
48
|
+
yield
|
|
49
|
+
assert app.timing_ratio < ratio, "#{app.last_time} was not less than #{ratio} of #{app.first_time}"
|
|
199
50
|
end
|
|
200
51
|
end
|
|
201
52
|
end
|
|
202
53
|
|
|
203
|
-
def
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
assert system("gem build spring.gemspec 2>/dev/null 1>/dev/null")
|
|
207
|
-
|
|
208
|
-
assert_success ["gem install ../../../spring-#{Spring::VERSION}.gem", timeout: nil]
|
|
209
|
-
assert_success ["(gem list bundler | grep bundler) || gem install bundler", timeout: nil]
|
|
210
|
-
assert_success ["bundle check || bundle update", timeout: nil]
|
|
54
|
+
def assert_app_reloaded
|
|
55
|
+
assert_success app.spring_test_command
|
|
211
56
|
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
57
|
+
File.write(app.application_config, app.application_config.read + <<-CODE)
|
|
58
|
+
class Foo
|
|
59
|
+
def self.omg
|
|
60
|
+
raise "omg"
|
|
61
|
+
end
|
|
62
|
+
end
|
|
63
|
+
CODE
|
|
64
|
+
File.write(app.test, app.test.read.sub("get :index", "Foo.omg"))
|
|
215
65
|
|
|
216
|
-
|
|
217
|
-
|
|
66
|
+
app.await_reload
|
|
67
|
+
assert_failure app.spring_test_command, stdout: "RuntimeError: omg"
|
|
218
68
|
end
|
|
219
69
|
|
|
220
|
-
@@installed = false
|
|
221
|
-
|
|
222
70
|
setup do
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
install unless @@installed
|
|
227
|
-
|
|
228
|
-
@test_contents = File.read(@test)
|
|
229
|
-
@controller_contents = File.read(@controller)
|
|
71
|
+
generator.generate_if_missing
|
|
72
|
+
generator.install_spring
|
|
73
|
+
generator.copy_to(app.root)
|
|
230
74
|
end
|
|
231
75
|
|
|
232
76
|
teardown do
|
|
233
|
-
|
|
234
|
-
File.write(@test, @test_contents)
|
|
235
|
-
File.write(@controller, @controller_contents)
|
|
236
|
-
FileUtils.rm_f("#{app_root}/config/spring.rb")
|
|
77
|
+
app.stop_spring
|
|
237
78
|
end
|
|
238
79
|
|
|
239
80
|
test "basic" do
|
|
240
81
|
assert_speedup do
|
|
241
|
-
2.times {
|
|
82
|
+
2.times { app.run app.spring_test_command }
|
|
242
83
|
end
|
|
243
84
|
end
|
|
244
85
|
|
|
245
86
|
test "help message when called without arguments" do
|
|
246
|
-
assert_success spring, stdout: 'Usage: spring COMMAND [ARGS]'
|
|
87
|
+
assert_success "bin/spring", stdout: 'Usage: spring COMMAND [ARGS]'
|
|
247
88
|
end
|
|
248
89
|
|
|
249
90
|
test "test changes are picked up" do
|
|
250
91
|
assert_speedup do
|
|
251
|
-
assert_success spring_test_command, stdout: "0 failures"
|
|
92
|
+
assert_success app.spring_test_command, stdout: "0 failures"
|
|
252
93
|
|
|
253
|
-
File.write(
|
|
254
|
-
assert_failure spring_test_command, stdout: "RuntimeError: omg"
|
|
94
|
+
File.write(app.test, app.test.read.sub("get :index", "raise 'omg'"))
|
|
95
|
+
assert_failure app.spring_test_command, stdout: "RuntimeError: omg"
|
|
255
96
|
end
|
|
256
97
|
end
|
|
257
98
|
|
|
258
99
|
test "code changes are picked up" do
|
|
259
100
|
assert_speedup do
|
|
260
|
-
assert_success spring_test_command, stdout: "0 failures"
|
|
101
|
+
assert_success app.spring_test_command, stdout: "0 failures"
|
|
261
102
|
|
|
262
|
-
File.write(
|
|
263
|
-
assert_failure spring_test_command, stdout: "RuntimeError: omg"
|
|
103
|
+
File.write(app.controller, app.controller.read.sub("@posts = Post.all", "raise 'omg'"))
|
|
104
|
+
assert_failure app.spring_test_command, stdout: "RuntimeError: omg"
|
|
264
105
|
end
|
|
265
106
|
end
|
|
266
107
|
|
|
267
108
|
test "code changes in pre-referenced app files are picked up" do
|
|
268
|
-
|
|
269
|
-
initializer = "#{app_root}/config/initializers/load_posts_controller.rb"
|
|
270
|
-
File.write(initializer, "PostsController\n")
|
|
109
|
+
File.write(app.path("config/initializers/load_posts_controller.rb"), "PostsController\n")
|
|
271
110
|
|
|
272
|
-
|
|
273
|
-
|
|
111
|
+
assert_speedup do
|
|
112
|
+
assert_success app.spring_test_command, stdout: "0 failures"
|
|
274
113
|
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
end
|
|
278
|
-
ensure
|
|
279
|
-
FileUtils.rm_f(initializer)
|
|
114
|
+
File.write(app.controller, app.controller.read.sub("@posts = Post.all", "raise 'omg'"))
|
|
115
|
+
assert_failure app.spring_test_command, stdout: "RuntimeError: omg"
|
|
280
116
|
end
|
|
281
117
|
end
|
|
282
118
|
|
|
283
|
-
def assert_app_reloaded
|
|
284
|
-
application = "#{app_root}/config/application.rb"
|
|
285
|
-
application_contents = File.read(application)
|
|
286
|
-
|
|
287
|
-
assert_success spring_test_command
|
|
288
|
-
|
|
289
|
-
File.write(application, application_contents + <<-CODE)
|
|
290
|
-
class Foo
|
|
291
|
-
def self.omg
|
|
292
|
-
raise "omg"
|
|
293
|
-
end
|
|
294
|
-
end
|
|
295
|
-
CODE
|
|
296
|
-
File.write(@test, @test_contents.sub("get :index", "Foo.omg"))
|
|
297
|
-
|
|
298
|
-
await_reload
|
|
299
|
-
assert_failure spring_test_command, stdout: "RuntimeError: omg"
|
|
300
|
-
ensure
|
|
301
|
-
File.write(application, application_contents)
|
|
302
|
-
end
|
|
303
|
-
|
|
304
119
|
test "app gets reloaded when preloaded files change (polling watcher)" do
|
|
305
|
-
env["RAILS_ENV"] = "test"
|
|
306
|
-
assert_success "
|
|
120
|
+
app.env["RAILS_ENV"] = "test"
|
|
121
|
+
assert_success "bin/rails runner 'puts Spring.watcher.class'", stdout: "Polling"
|
|
307
122
|
assert_app_reloaded
|
|
308
123
|
end
|
|
309
124
|
|
|
310
125
|
test "app gets reloaded when preloaded files change (listen watcher)" do
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
File.write(gemfile, gemfile_contents + "\ngem 'listen', '~> 1.0'")
|
|
315
|
-
|
|
316
|
-
File.write("#{app_root}/config/spring.rb", "Spring.watch_method = :listen")
|
|
126
|
+
File.write(app.gemfile, "#{app.gemfile.read}gem 'listen', '~> 1.0'")
|
|
127
|
+
File.write(app.spring_config, "Spring.watch_method = :listen")
|
|
128
|
+
app.bundle
|
|
317
129
|
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
assert_success "#{spring} rails runner 'puts Spring.watcher.class'", stdout: "Listen"
|
|
322
|
-
|
|
323
|
-
assert_app_reloaded
|
|
324
|
-
ensure
|
|
325
|
-
File.write(gemfile, gemfile_contents)
|
|
326
|
-
assert_success "bundle check"
|
|
327
|
-
end
|
|
130
|
+
app.env["RAILS_ENV"] = "test"
|
|
131
|
+
assert_success "bin/rails runner 'puts Spring.watcher.class'", stdout: "Listen"
|
|
132
|
+
assert_app_reloaded
|
|
328
133
|
end
|
|
329
134
|
|
|
330
135
|
test "app recovers when a boot-level error is introduced" do
|
|
331
|
-
|
|
332
|
-
application = "#{app_root}/config/application.rb"
|
|
333
|
-
application_contents = File.read(application)
|
|
136
|
+
config = app.application_config.read
|
|
334
137
|
|
|
335
|
-
|
|
138
|
+
assert_success app.spring_test_command
|
|
336
139
|
|
|
337
|
-
|
|
338
|
-
|
|
140
|
+
File.write(app.application_config, "#{config}\nomg")
|
|
141
|
+
app.await_reload
|
|
339
142
|
|
|
340
|
-
|
|
143
|
+
assert_failure app.spring_test_command
|
|
341
144
|
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
ensure
|
|
345
|
-
File.write(application, application_contents)
|
|
346
|
-
end
|
|
145
|
+
File.write(app.application_config, config)
|
|
146
|
+
assert_success app.spring_test_command
|
|
347
147
|
end
|
|
348
148
|
|
|
349
149
|
test "stop command kills server" do
|
|
350
|
-
|
|
351
|
-
assert spring_env.server_running?, "The server should be running but it isn't"
|
|
150
|
+
app.run app.spring_test_command
|
|
151
|
+
assert app.spring_env.server_running?, "The server should be running but it isn't"
|
|
352
152
|
|
|
353
|
-
assert_success "
|
|
354
|
-
assert !spring_env.server_running?, "The server should not be running but it is"
|
|
153
|
+
assert_success "bin/spring stop"
|
|
154
|
+
assert !app.spring_env.server_running?, "The server should not be running but it is"
|
|
355
155
|
end
|
|
356
156
|
|
|
357
157
|
test "custom commands" do
|
|
358
|
-
File.write(
|
|
158
|
+
File.write(app.spring_config, <<-CODE)
|
|
359
159
|
class CustomCommand
|
|
360
160
|
def call
|
|
361
161
|
puts "omg"
|
|
362
162
|
end
|
|
163
|
+
|
|
164
|
+
def exec_name
|
|
165
|
+
"rake"
|
|
166
|
+
end
|
|
363
167
|
end
|
|
364
168
|
|
|
365
169
|
Spring.register_command "custom", CustomCommand.new
|
|
366
170
|
CODE
|
|
367
171
|
|
|
368
|
-
assert_success "
|
|
172
|
+
assert_success "bin/spring custom", stdout: "omg"
|
|
173
|
+
|
|
174
|
+
assert_success "bin/spring binstub custom"
|
|
175
|
+
assert_success "bin/custom", stdout: "omg"
|
|
176
|
+
|
|
177
|
+
app.env["DISABLE_SPRING"] = "1"
|
|
178
|
+
assert_success %{bin/custom -e 'puts "foo"'}, stdout: "foo"
|
|
369
179
|
end
|
|
370
180
|
|
|
371
|
-
test "
|
|
372
|
-
|
|
373
|
-
|
|
181
|
+
test "binstub" do
|
|
182
|
+
assert_success "bin/rails server --help", stdout: "Usage: rails server" # rails command fallback
|
|
183
|
+
|
|
184
|
+
assert_success "#{app.spring} binstub rake", stdout: "bin/rake: spring already present"
|
|
374
185
|
|
|
375
|
-
|
|
376
|
-
|
|
186
|
+
assert_success "#{app.spring} binstub --remove rake", stdout: "bin/rake: spring removed"
|
|
187
|
+
assert !app.path("bin/rake").read.include?(Spring::Client::Binstub::LOADER)
|
|
188
|
+
assert_success "bin/rake -T", stdout: "rake db:migrate"
|
|
189
|
+
end
|
|
377
190
|
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
191
|
+
test "binstub when spring is uninstalled" do
|
|
192
|
+
app.run! "gem uninstall --ignore-dependencies spring"
|
|
193
|
+
File.write(app.gemfile, app.gemfile.read.gsub(/gem 'spring.*/, ""))
|
|
194
|
+
assert_success "bin/rake -T", stdout: "rake db:migrate"
|
|
195
|
+
end
|
|
381
196
|
|
|
382
|
-
|
|
197
|
+
test "binstub upgrade" do
|
|
198
|
+
File.write(app.path("bin/rake"), <<CODE)
|
|
199
|
+
#!/usr/bin/env ruby
|
|
383
200
|
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
201
|
+
if !Process.respond_to?(:fork) || Gem::Specification.find_all_by_name("spring").empty?
|
|
202
|
+
exec "bundle", "exec", "rake", *ARGV
|
|
203
|
+
else
|
|
204
|
+
ARGV.unshift "rake"
|
|
205
|
+
load Gem.bin_path("spring", "spring")
|
|
206
|
+
end
|
|
207
|
+
CODE
|
|
208
|
+
|
|
209
|
+
File.write(app.path("bin/rails"), <<CODE)
|
|
210
|
+
#!/usr/bin/env ruby
|
|
211
|
+
|
|
212
|
+
if !Process.respond_to?(:fork) || Gem::Specification.find_all_by_name("spring").empty?
|
|
213
|
+
APP_PATH = File.expand_path('../../config/application', __FILE__)
|
|
214
|
+
require_relative '../config/boot'
|
|
215
|
+
require 'rails/commands'
|
|
216
|
+
else
|
|
217
|
+
ARGV.unshift "rails"
|
|
218
|
+
load Gem.bin_path("spring", "spring")
|
|
219
|
+
end
|
|
220
|
+
CODE
|
|
221
|
+
|
|
222
|
+
assert_success "bin/spring binstub --all", stdout: "upgraded"
|
|
223
|
+
|
|
224
|
+
assert_equal app.path("bin/rake").read, <<CODE
|
|
225
|
+
#!/usr/bin/env ruby
|
|
226
|
+
#{Spring::Client::Binstub::LOADER.strip}
|
|
227
|
+
require 'bundler/setup'
|
|
228
|
+
load Gem.bin_path('rake', 'rake')
|
|
229
|
+
CODE
|
|
230
|
+
|
|
231
|
+
assert_equal app.path("bin/rails").read, <<CODE
|
|
232
|
+
#!/usr/bin/env ruby
|
|
233
|
+
#{Spring::Client::Binstub::LOADER.strip}
|
|
234
|
+
APP_PATH = File.expand_path('../../config/application', __FILE__)
|
|
235
|
+
require_relative '../config/boot'
|
|
236
|
+
require 'rails/commands'
|
|
237
|
+
CODE
|
|
393
238
|
end
|
|
394
239
|
|
|
395
240
|
test "after fork callback" do
|
|
396
|
-
File.write(
|
|
397
|
-
assert_success "
|
|
241
|
+
File.write(app.spring_config, "Spring.after_fork { puts '!callback!' }")
|
|
242
|
+
assert_success "bin/rails runner 'puts 2'", stdout: "!callback!\n2"
|
|
398
243
|
end
|
|
399
244
|
|
|
400
245
|
test "global config file evaluated" do
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
assert_success "#{spring} rails runner 'puts 2'", stdout: "!callback!\n2"
|
|
404
|
-
ensure
|
|
405
|
-
FileUtils.rm_r("#{user_home}/.spring.rb")
|
|
406
|
-
end
|
|
246
|
+
File.write("#{app.user_home}/.spring.rb", "Spring.after_fork { puts '!callback!' }")
|
|
247
|
+
assert_success "bin/rails runner 'puts 2'", stdout: "!callback!\n2"
|
|
407
248
|
end
|
|
408
249
|
|
|
409
250
|
test "missing config/application.rb" do
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
assert_failure "#{spring} rake -T", stderr: "unable to find your config/application.rb"
|
|
414
|
-
ensure
|
|
415
|
-
FileUtils.mv app_root.join("config/application.rb.bak"), app_root.join("config/application.rb")
|
|
416
|
-
end
|
|
251
|
+
app.application_config.delete
|
|
252
|
+
assert_failure "bin/rake -T", stderr: "unable to find your config/application.rb"
|
|
417
253
|
end
|
|
418
254
|
|
|
419
255
|
test "piping" do
|
|
420
|
-
assert_success "
|
|
256
|
+
assert_success "bin/rake -T | grep db", stdout: "rake db:migrate"
|
|
421
257
|
end
|
|
422
258
|
|
|
423
259
|
test "status" do
|
|
424
|
-
assert_success "
|
|
425
|
-
|
|
426
|
-
assert_success "
|
|
260
|
+
assert_success "bin/spring status", stdout: "Spring is not running"
|
|
261
|
+
assert_success "bin/rails runner ''"
|
|
262
|
+
assert_success "bin/spring status", stdout: "Spring is running"
|
|
427
263
|
end
|
|
428
264
|
|
|
429
265
|
test "runner command sets Rails environment from command-line options" do
|
|
430
|
-
assert_success "
|
|
431
|
-
assert_success "
|
|
266
|
+
assert_success "bin/rails runner -e production 'puts Rails.env'", stdout: "production"
|
|
267
|
+
assert_success "bin/rails runner --environment=production 'puts Rails.env'", stdout: "production"
|
|
432
268
|
end
|
|
433
269
|
|
|
434
270
|
test "forcing rails env via environment variable" do
|
|
435
|
-
env['RAILS_ENV'] = 'production'
|
|
436
|
-
assert_success "
|
|
271
|
+
app.env['RAILS_ENV'] = 'production'
|
|
272
|
+
assert_success "bin/rake -p 'Rails.env'", stdout: "production"
|
|
437
273
|
end
|
|
438
274
|
|
|
439
275
|
test "setting env vars with rake" do
|
|
440
|
-
|
|
441
|
-
File.write("#{app_root}/lib/tasks/env.rake", <<-'CODE')
|
|
276
|
+
File.write(app.path("lib/tasks/env.rake"), <<-'CODE')
|
|
442
277
|
task :print_rails_env => :environment do
|
|
443
278
|
puts Rails.env
|
|
444
279
|
end
|
|
@@ -448,54 +283,52 @@ class AppTest < ActiveSupport::TestCase
|
|
|
448
283
|
end
|
|
449
284
|
|
|
450
285
|
task(:default).clear.enhance [:print_rails_env]
|
|
451
|
-
|
|
286
|
+
CODE
|
|
452
287
|
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
ensure
|
|
457
|
-
FileUtils.rm_f("#{app_root}/lib/tasks/env.rake")
|
|
458
|
-
end
|
|
288
|
+
assert_success "bin/rake RAILS_ENV=test print_rails_env", stdout: "test"
|
|
289
|
+
assert_success "bin/rake FOO=bar print_env", stdout: "FOO=bar"
|
|
290
|
+
assert_success "bin/rake", stdout: "test"
|
|
459
291
|
end
|
|
460
292
|
|
|
461
|
-
test "changing the Gemfile
|
|
462
|
-
|
|
463
|
-
gemfile = app_root.join("Gemfile")
|
|
464
|
-
gemfile_contents = gemfile.read
|
|
293
|
+
test "changing the Gemfile works" do
|
|
294
|
+
assert_success %(bin/rails runner 'require "sqlite3"')
|
|
465
295
|
|
|
466
|
-
|
|
296
|
+
File.write(app.gemfile, app.gemfile.read.sub(%{gem 'sqlite3'}, %{# gem 'sqlite3'}))
|
|
297
|
+
app.await_reload
|
|
467
298
|
|
|
468
|
-
|
|
469
|
-
|
|
299
|
+
assert_failure %(bin/rails runner 'require "sqlite3"'), stderr: "sqlite3"
|
|
300
|
+
end
|
|
470
301
|
|
|
471
|
-
|
|
472
|
-
|
|
473
|
-
|
|
474
|
-
File.write(gemfile,
|
|
475
|
-
|
|
476
|
-
|
|
302
|
+
test "changing the Gemfile works when spring calls into itself" do
|
|
303
|
+
File.write(app.path("script.rb"), <<-CODE)
|
|
304
|
+
gemfile = Rails.root.join("Gemfile")
|
|
305
|
+
File.write(gemfile, "\#{gemfile.read}gem 'devise'\\n")
|
|
306
|
+
Bundler.with_clean_env do
|
|
307
|
+
system(#{app.env.inspect}, "bundle install")
|
|
308
|
+
end
|
|
309
|
+
output = `\#{Rails.root.join('bin/rails')} runner 'require "devise"; puts "done";'`
|
|
310
|
+
exit output == "done\n"
|
|
311
|
+
CODE
|
|
312
|
+
|
|
313
|
+
assert_success [%(bin/rails runner 'load Rails.root.join("script.rb")'), timeout: 60]
|
|
477
314
|
end
|
|
478
315
|
|
|
479
316
|
test "changing the environment between runs" do
|
|
480
|
-
|
|
481
|
-
application = "#{app_root}/config/application.rb"
|
|
482
|
-
application_contents = File.read(application)
|
|
483
|
-
|
|
484
|
-
File.write(application, "#{application_contents}\nENV['BAR'] = 'bar'")
|
|
317
|
+
File.write(app.application_config, "#{app.application_config.read}\nENV['BAR'] = 'bar'")
|
|
485
318
|
|
|
486
|
-
|
|
487
|
-
|
|
319
|
+
app.env["OMG"] = "1"
|
|
320
|
+
app.env["FOO"] = "1"
|
|
321
|
+
app.env["RUBYOPT"] = "-rubygems"
|
|
488
322
|
|
|
489
|
-
|
|
490
|
-
|
|
323
|
+
assert_success %(bin/rails runner 'p ENV["OMG"]'), stdout: "1"
|
|
324
|
+
assert_success %(bin/rails runner 'p ENV["BAR"]'), stdout: "bar"
|
|
325
|
+
assert_success %(bin/rails runner 'p ENV.key?("BUNDLE_GEMFILE")'), stdout: "true"
|
|
326
|
+
assert_success %(bin/rails runner 'p ENV["RUBYOPT"]'), stdout: "bundler"
|
|
491
327
|
|
|
492
|
-
|
|
493
|
-
|
|
328
|
+
app.env["OMG"] = "2"
|
|
329
|
+
app.env.delete "FOO"
|
|
494
330
|
|
|
495
|
-
|
|
496
|
-
|
|
497
|
-
ensure
|
|
498
|
-
File.write(application, application_contents)
|
|
499
|
-
end
|
|
331
|
+
assert_success %(bin/rails runner 'p ENV["OMG"]'), stdout: "2"
|
|
332
|
+
assert_success %(bin/rails runner 'p ENV.key?("FOO")'), stdout: "false"
|
|
500
333
|
end
|
|
501
334
|
end
|