Skip to content

Commit 47a4e71

Browse files
committed
Merge pull request #455 from sonalkr132/notif-running
print spring client pid on command run
2 parents 2fe7c18 + 20383d6 commit 47a4e71

File tree

4 files changed

+33
-2
lines changed

4 files changed

+33
-2
lines changed

bin/spring

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,4 +46,6 @@ end
4646
lib = File.expand_path("../../lib", __FILE__)
4747
$LOAD_PATH.unshift lib unless $LOAD_PATH.include?(lib) # enable local development
4848
require 'spring/client'
49+
# if the user knows that spring is called, do not show running spring
50+
Spring.quiet = true if $0.include? 'spring'
4951
Spring::Client.run(ARGV)

lib/spring/client/run.rb

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
require "spring/commands"
12
require "rbconfig"
23
require "socket"
34
require "bundler"
@@ -138,6 +139,8 @@ def run_command(client, application)
138139
if pid && !pid.empty?
139140
log "got pid: #{pid}"
140141

142+
puts "Running via Spring preloader in process #{pid}" unless Spring.quiet
143+
141144
forward_signals(pid.to_i)
142145
status = application.read.to_i
143146

lib/spring/configuration.rb

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
module Spring
44
class << self
5-
attr_accessor :application_root
5+
attr_accessor :application_root, :quiet
66

77
def gemfile
88
ENV['BUNDLE_GEMFILE'] || "Gemfile"
@@ -49,4 +49,6 @@ def find_project_root(current_dir)
4949
end
5050
end
5151
end
52+
53+
self.quiet = false
5254
end

lib/spring/test/acceptance_test.rb

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,14 @@ def assert_failure(command, expected_output = nil)
4747
assert_output artifacts, expected_output if expected_output
4848
end
4949

50+
def refute_output_includes(command, not_expected)
51+
artifacts = app.run(*Array(command))
52+
not_expected.each do |stream, output|
53+
assert !artifacts[stream].include?(output),
54+
"expected #{stream} to not include '#{output}'.\n\n#{app.debug(artifacts)}"
55+
end
56+
end
57+
5058
def assert_speedup(ratio = DEFAULT_SPEEDUP)
5159
if ENV['CI']
5260
yield
@@ -94,6 +102,22 @@ def without_gem(name)
94102
refute app.spring_env.server_running?
95103
end
96104

105+
test "tells the user that spring is being used when used automatically via binstubs" do
106+
assert_success "bin/rails runner ''", stdout: "Running via Spring preloader in process"
107+
assert_success app.spring_test_command, stdout: "Running via Spring preloader in process"
108+
end
109+
110+
test "does not tell the user that spring is being used when the user used spring manually" do
111+
refute_output_includes "spring rails runner ''", stdout: "Running via Spring preloader in process"
112+
refute_output_includes "spring rake test", stdout: "Running via Spring preloader in process"
113+
end
114+
115+
test "does not tell the user that spring is being used when used automatically via binstubs but quiet is enabled" do
116+
File.write("#{app.user_home}/.spring.rb", "Spring.quiet = true")
117+
assert_success "bin/rails runner ''"
118+
refute_output_includes "bin/rails runner ''", stdout: 'Running via Spring preloader in process'
119+
end
120+
97121
test "test changes are picked up" do
98122
assert_speedup do
99123
assert_success app.spring_test_command, stdout: "0 failures"
@@ -447,7 +471,7 @@ def exec_name
447471
system(#{app.env.inspect}, "bundle install")
448472
end
449473
output = `\#{Rails.root.join('bin/rails')} runner 'require "devise"; puts "done";'`
450-
exit output == "done\n"
474+
exit output.include? "done\n"
451475
RUBY
452476

453477
assert_success [%(bin/rails runner 'load Rails.root.join("script.rb")'), timeout: 60]

0 commit comments

Comments
 (0)