Skip to content

Commit e04755f

Browse files
committed
Improve debugging
1 parent 138a0eb commit e04755f

File tree

2 files changed

+18
-12
lines changed

2 files changed

+18
-12
lines changed

test/acceptance/app_test.rb

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -21,28 +21,22 @@ def app
2121
@app ||= Spring::Test::Application.new("#{TEST_ROOT}/apps/tmp")
2222
end
2323

24-
def debug(artifacts)
25-
artifacts = artifacts.dup
26-
artifacts.delete :status
27-
app.dump_streams(artifacts.delete(:command), artifacts)
28-
end
29-
3024
def assert_output(artifacts, expected)
3125
expected.each do |stream, output|
3226
assert artifacts[stream].include?(output),
33-
"expected #{stream} to include '#{output}'.\n\n#{debug(artifacts)}"
27+
"expected #{stream} to include '#{output}'.\n\n#{app.debug(artifacts)}"
3428
end
3529
end
3630

3731
def assert_success(command, expected_output = nil)
3832
artifacts = app.run(*Array(command))
39-
assert artifacts[:status].success?, "expected successful exit status\n\n#{debug(artifacts)}"
33+
assert artifacts[:status].success?, "expected successful exit status\n\n#{app.debug(artifacts)}"
4034
assert_output artifacts, expected_output if expected_output
4135
end
4236

4337
def assert_failure(command, expected_output = nil)
4438
artifacts = app.run(*Array(command))
45-
assert !artifacts[:status].success?, "expected unsuccessful exit status\n\n#{debug(artifacts)}"
39+
assert !artifacts[:status].success?, "expected unsuccessful exit status\n\n#{app.debug(artifacts)}"
4640
assert_output artifacts, expected_output if expected_output
4741
end
4842

test/acceptance/helper.rb

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -57,8 +57,12 @@ def stderr
5757
@stderr ||= IO.pipe
5858
end
5959

60+
def log_file_path
61+
path("tmp/spring.log")
62+
end
63+
6064
def log_file
61-
@log_file ||= path("tmp/spring.log").open("w+")
65+
@log_file ||= log_file_path.open("w+")
6266
end
6367

6468
def env
@@ -68,7 +72,7 @@ def env
6872
"HOME" => user_home.to_s,
6973
"RAILS_ENV" => nil,
7074
"RACK_ENV" => nil,
71-
"SPRING_LOG" => log_file.path
75+
"SPRING_LOG" => log_file_path.to_s
7276
}
7377
end
7478

@@ -202,6 +206,12 @@ def dump_streams(command, streams)
202206
output
203207
end
204208

209+
def debug(artifacts)
210+
artifacts = artifacts.dup
211+
artifacts.delete :status
212+
dump_streams(artifacts.delete(:command), artifacts)
213+
end
214+
205215
def await_reload
206216
raise "no pid" if @application_pids.nil? || @application_pids.empty?
207217

@@ -212,7 +222,9 @@ def await_reload
212222

213223
def run!(*args)
214224
artifacts = run(*args)
215-
raise "command failed" unless artifacts[:status].success?
225+
unless artifacts[:status].success?
226+
raise "command failed\n\n#{debug(artifacts)}"
227+
end
216228
artifacts
217229
end
218230

0 commit comments

Comments
 (0)