aboutsummaryrefslogtreecommitdiffstats
path: root/railties
diff options
context:
space:
mode:
authorXavier Noria <fxn@hashref.com>2011-05-13 01:41:52 +0200
committerXavier Noria <fxn@hashref.com>2011-05-13 01:41:52 +0200
commitbdbb15e5a5c647823aa6b9fd04020dab16360ae1 (patch)
tree1002c18700ef0e29104864a2f961934322b09658 /railties
parentb0062eef347199639db4eece358e7e72792a3f28 (diff)
downloadrails-bdbb15e5a5c647823aa6b9fd04020dab16360ae1.tar.gz
rails-bdbb15e5a5c647823aa6b9fd04020dab16360ae1.tar.bz2
rails-bdbb15e5a5c647823aa6b9fd04020dab16360ae1.zip
new reporting method Kernel#quietly
Diffstat (limited to 'railties')
-rw-r--r--railties/guides/source/active_support_core_extensions.textile8
-rw-r--r--railties/test/generators/app_generator_test.rb2
-rw-r--r--railties/test/generators/plugin_new_generator_test.rb4
3 files changed, 11 insertions, 3 deletions
diff --git a/railties/guides/source/active_support_core_extensions.textile b/railties/guides/source/active_support_core_extensions.textile
index f2170e120b..d82bdfee43 100644
--- a/railties/guides/source/active_support_core_extensions.textile
+++ b/railties/guides/source/active_support_core_extensions.textile
@@ -417,6 +417,14 @@ silence_stream(STDOUT) do
end
</ruby>
+The +quietly+ method addresses the common use case where you want to silence STDOUT and STDERR, even in subprocesses:
+
+<ruby>
+quietly { system 'bundle install' }
+</ruby>
+
+For example, the railties test suite uses that one in a few places to prevent command messages from being echoed intermixed with the progress status.
+
Silencing exceptions is also possible with +suppress+. This method receives an arbitrary number of exception classes. If an exception is raised during the execution of the block and is +kind_of?+ any of the arguments, +suppress+ captures it and returns silently. Otherwise the exception is reraised:
<ruby>
diff --git a/railties/test/generators/app_generator_test.rb b/railties/test/generators/app_generator_test.rb
index 5175a6e2e6..8de829b6dd 100644
--- a/railties/test/generators/app_generator_test.rb
+++ b/railties/test/generators/app_generator_test.rb
@@ -66,7 +66,7 @@ class AppGeneratorTest < Rails::Generators::TestCase
end
def test_application_new_exits_with_non_zero_code_on_invalid_application_name
- silence_stderr { `rails new test` }
+ quietly { system 'rails new test' }
assert_equal false, $?.success?
end
diff --git a/railties/test/generators/plugin_new_generator_test.rb b/railties/test/generators/plugin_new_generator_test.rb
index 673856c34d..2af728e766 100644
--- a/railties/test/generators/plugin_new_generator_test.rb
+++ b/railties/test/generators/plugin_new_generator_test.rb
@@ -122,14 +122,14 @@ class PluginNewGeneratorTest < Rails::Generators::TestCase
def test_ensure_that_tests_work
run_generator
FileUtils.cd destination_root
- `bundle install` # use backticks to silence stdout
+ quietly { system 'bundle install' }
assert_match(/1 tests, 1 assertions, 0 failures, 0 errors/, `bundle exec rake test`)
end
def test_ensure_that_tests_works_in_full_mode
run_generator [destination_root, "--full", "--skip_active_record"]
FileUtils.cd destination_root
- `bundle install` # use backticks to silence stdout
+ quietly { system 'bundle install' }
assert_match(/1 tests, 1 assertions, 0 failures, 0 errors/, `bundle exec rake test`)
end