diff --git a/CHANGELOG.md b/CHANGELOG.md index 0c08f223..e9be7bcb 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,6 +4,7 @@ * Preserve comments right after the shebang line which might include magic comments such as `frozen_string_literal: true' * Fix binstub failures when Bundler's `BUNDLE_APP_CONFIG` environment variable is present (#545) * Properly suspend and resume on ctrl-z TSTP and CONT (#361) +* Allow quiet mode to be set by environment variable `SPRING_QUIET` ## 2.0.2 diff --git a/README.md b/README.md index ee5b3f07..bd3b1869 100644 --- a/README.md +++ b/README.md @@ -404,7 +404,8 @@ The following environment variables are used by Spring: * `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`. - +* `SPRING_QUIET` - If set, the "Running via Spring preloader" message will not + be shown each time a command runs (takes precedence over `Spring.quiet`). ## Troubleshooting If you want to get more information about what Spring is doing, you can diff --git a/lib/spring/configuration.rb b/lib/spring/configuration.rb index 103f0882..a583266c 100644 --- a/lib/spring/configuration.rb +++ b/lib/spring/configuration.rb @@ -2,7 +2,8 @@ module Spring class << self - attr_accessor :application_root, :quiet + attr_accessor :application_root + attr_writer :quiet def gemfile ENV['BUNDLE_GEMFILE'] || "Gemfile" @@ -16,6 +17,10 @@ def after_fork(&block) after_fork_callbacks << block end + def quiet + @quiet || ENV.key?('SPRING_QUIET') + end + def verify_environment application_root_path end diff --git a/lib/spring/test/acceptance_test.rb b/lib/spring/test/acceptance_test.rb index 4625fc64..3627ec08 100644 --- a/lib/spring/test/acceptance_test.rb +++ b/lib/spring/test/acceptance_test.rb @@ -117,6 +117,12 @@ def without_gem(name) refute_output_includes "bin/rails runner ''", stderr: 'Running via Spring preloader in process' end + test "configures quiet mode from environment" do + app.env['SPRING_QUIET'] = '1' + assert_success "bin/rails runner ''" + refute_output_includes "bin/rails runner ''", stderr: 'Running via Spring preloader in process' + end + test "test changes are picked up" do assert_speedup do assert_success app.spring_test_command, stdout: "0 failures"