Skip to content

Commit

Permalink
Merge pull request #674 from thewoolleyman/main
Browse files Browse the repository at this point in the history
Add support for SPRING_QUIET environment variable.
  • Loading branch information
rafaelfranca authored Sep 20, 2022
2 parents 7022377 + 41f0d21 commit 67492f2
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 2 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
## Next Release

* Add support for `SPRING_QUIET` environment variable.

## 4.0.0

* Stop requiring `set` before bundler can select the proper version. This could result in
Expand Down
8 changes: 8 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -389,6 +389,12 @@ a command runs:
Spring.quiet = true
```

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

### Environment variables

The following environment variables are used by Spring:
Expand All @@ -413,6 +419,8 @@ The following environment variables are used by Spring:
the long-running Spring server process. By default, this is related to
the socket path; if the socket path is `/foo/bar/spring.sock` the
pidfile will be `/foo/bar/spring.pid`.
* `SPRING_QUIET` - If set, the initial state of the `Spring.quiet`
configuration option will default to `true`.
* `SPRING_SERVER_COMMAND` - The command to run to start up the Spring
server when it is not already running. Defaults to `spring _[version]_
server --background`.
Expand Down
7 changes: 6 additions & 1 deletion lib/spring/configuration.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@

module Spring
class << self
attr_accessor :application_root, :quiet
attr_accessor :application_root
attr_writer :quiet

def gemfile
require "bundler"
Expand Down Expand Up @@ -52,6 +53,10 @@ def project_root_path
@project_root_path ||= find_project_root(Pathname.new(File.expand_path(Dir.pwd)))
end

def quiet
@quiet ||= ENV.key?('SPRING_QUIET')
end

private

def find_project_root(current_dir)
Expand Down
7 changes: 6 additions & 1 deletion test/support/acceptance_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -125,12 +125,17 @@ def without_gem(name)
assert_success app.spring_test_command, stderr: "Running via Spring preloader in process"
end

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

test "does not tell the user that Spring is being used when quiet is enabled via SPRING_QUIET ENV var" do
assert_success "SPRING_QUIET=true bin/rails runner ''"
refute_output_includes "bin/rails runner ''", stderr: 'Running via Spring preloader in process'
end

test "raises if config.cache_classes is true" do
config_path = app.path("config/environments/development.rb")
config = File.read(config_path)
Expand Down

0 comments on commit 67492f2

Please sign in to comment.