Skip to content

Commit 41f0d21

Browse files
committed
Add support for SPRING_QUIET environment variable.
Closes #467
1 parent 184ecda commit 41f0d21

File tree

4 files changed

+22
-2
lines changed

4 files changed

+22
-2
lines changed

CHANGELOG.md

+2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
## Next Release
22

3+
* Add support for `SPRING_QUIET` environment variable.
4+
35
## 4.0.0
46

57
* Stop requiring `set` before bundler can select the proper version. This could result in

README.md

+8
Original file line numberDiff line numberDiff line change
@@ -388,6 +388,12 @@ a command runs:
388388
Spring.quiet = true
389389
```
390390

391+
You can also set the initial state of the `quiet` configuration option to true
392+
by setting the `SPRING_QUIET` environment variable before executing Spring.
393+
This is useful if you want to set quiet mode when invoking the Spring executable
394+
in a subprocess, and cannot or prefer not to set it programmatically
395+
via the `Spring.quiet` option in `~/.spring.rb` or the app's `config/spring.rb`.
396+
391397
### Environment variables
392398

393399
The following environment variables are used by Spring:
@@ -412,6 +418,8 @@ The following environment variables are used by Spring:
412418
the long-running Spring server process. By default, this is related to
413419
the socket path; if the socket path is `/foo/bar/spring.sock` the
414420
pidfile will be `/foo/bar/spring.pid`.
421+
* `SPRING_QUIET` - If set, the initial state of the `Spring.quiet`
422+
configuration option will default to `true`.
415423
* `SPRING_SERVER_COMMAND` - The command to run to start up the Spring
416424
server when it is not already running. Defaults to `spring _[version]_
417425
server --background`.

lib/spring/configuration.rb

+6-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,8 @@
22

33
module Spring
44
class << self
5-
attr_accessor :application_root, :quiet
5+
attr_accessor :application_root
6+
attr_writer :quiet
67

78
def gemfile
89
require "bundler"
@@ -52,6 +53,10 @@ def project_root_path
5253
@project_root_path ||= find_project_root(Pathname.new(File.expand_path(Dir.pwd)))
5354
end
5455

56+
def quiet
57+
@quiet ||= ENV.key?('SPRING_QUIET')
58+
end
59+
5560
private
5661

5762
def find_project_root(current_dir)

test/support/acceptance_test.rb

+6-1
Original file line numberDiff line numberDiff line change
@@ -125,12 +125,17 @@ def without_gem(name)
125125
assert_success app.spring_test_command, stderr: "Running via Spring preloader in process"
126126
end
127127

128-
test "does not tell the user that Spring is being used when used automatically via binstubs but quiet is enabled" do
128+
test "does not tell the user that Spring is being used when quiet is enabled via Spring.quiet" do
129129
File.write("#{app.user_home}/.spring.rb", "Spring.quiet = true")
130130
assert_success "bin/rails runner ''"
131131
refute_output_includes "bin/rails runner ''", stderr: 'Running via Spring preloader in process'
132132
end
133133

134+
test "does not tell the user that Spring is being used when quiet is enabled via SPRING_QUIET ENV var" do
135+
assert_success "SPRING_QUIET=true bin/rails runner ''"
136+
refute_output_includes "bin/rails runner ''", stderr: 'Running via Spring preloader in process'
137+
end
138+
134139
test "raises if config.cache_classes is true" do
135140
config_path = app.path("config/environments/development.rb")
136141
config = File.read(config_path)

0 commit comments

Comments
 (0)