Permalink
Browse files

Added Kernel#silence_warnings and puts it into use throughout the fra…

…mework

git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@2179 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
  • Loading branch information...
dhh committed Sep 11, 2005
1 parent 4b53e26 commit 3cf7a0a46037f32b95b5ffb358cb898233d5c5db
@@ -48,6 +48,4 @@
helper MailHelper
end
-old_verbose, $VERBOSE = $VERBOSE, nil
-TMail::Encoder.const_set("MAX_LINE_LEN", 200)
-$VERBOSE = old_verbose
+silence_warnings { TMail::Encoder.const_set("MAX_LINE_LEN", 200) }
@@ -121,9 +121,7 @@ def missing_methods
end
def test_helper=(helper_module)
- old_verbose, $VERBOSE = $VERBOSE, nil
- self.class.const_set('TestHelper', helper_module)
- $VERBOSE = old_verbose
+ silence_warnings { self.class.const_set('TestHelper', helper_module) }
end
end
@@ -6,14 +6,14 @@
class FormHelperTest < Test::Unit::TestCase
include ActionView::Helpers::FormHelper
- old_verbose, $VERBOSE = $VERBOSE, nil
- Post = Struct.new("Post", :title, :author_name, :body, :secret, :written_on, :cost)
- Post.class_eval do
- alias_method :title_before_type_cast, :title unless respond_to?(:title_before_type_cast)
- alias_method :body_before_type_cast, :body unless respond_to?(:body_before_type_cast)
- alias_method :author_name_before_type_cast, :author_name unless respond_to?(:author_name_before_type_cast)
+ silence_warnings do
+ Post = Struct.new("Post", :title, :author_name, :body, :secret, :written_on, :cost)
+ Post.class_eval do
+ alias_method :title_before_type_cast, :title unless respond_to?(:title_before_type_cast)
+ alias_method :body_before_type_cast, :body unless respond_to?(:body_before_type_cast)
+ alias_method :author_name_before_type_cast, :author_name unless respond_to?(:author_name_before_type_cast)
+ end
end
- $VERBOSE = old_verbose
def setup
@post = Post.new
@@ -25,12 +25,12 @@ def to_s
class FormOptionsHelperTest < Test::Unit::TestCase
include ActionView::Helpers::FormOptionsHelper
- old_verbose, $VERBOSE = $VERBOSE, nil
- Post = Struct.new('Post', :title, :author_name, :body, :secret, :written_on, :category, :origin)
- Continent = Struct.new('Continent', :continent_name, :countries)
- Country = Struct.new('Country', :country_id, :country_name)
- Firm = Struct.new('Firm', :time_zone)
- $VERBOSE = old_verbose
+ silence_warnings do
+ Post = Struct.new('Post', :title, :author_name, :body, :secret, :written_on, :category, :origin)
+ Continent = Struct.new('Continent', :continent_name, :countries)
+ Country = Struct.new('Country', :country_id, :country_name)
+ Firm = Struct.new('Firm', :time_zone)
+ end
def test_collection_options
@posts = [
View
@@ -1,5 +1,7 @@
*SVN*
+* Added Kernel#silence_warnings to turn off warnings temporarily for the passed block
+
* Added String#starts_with? and String#ends_with? #2118 [thijs@vandervossen.net]
* Added easy extendability to the inflector through Inflector.inflections (using the Inflector::Inflections singleton class). Examples:
@@ -29,7 +29,6 @@
require 'active_support/core_ext'
require 'active_support/clean_logger'
-require 'active_support/misc'
require 'active_support/dependencies'
require 'active_support/values/time_zone'
@@ -14,4 +14,18 @@ def returning(value)
yield
value
end
+
+ # Sets $VERBOSE to nil for the duration of the block and back to its original value afterwards.
+ #
+ # silence_warnings do
+ # noisy_call # no warning voiced
+ # end
+ #
+ # noisy_call # warning voiced
+ def silence_warnings
+ old_verbose, $VERBOSE = $VERBOSE, nil
+ yield
+ ensure
+ $VERBOSE = old_verbose
+ end
end
@@ -1,8 +0,0 @@
-def silence_warnings
- old_verbose, $VERBOSE = $VERBOSE, nil
- begin
- yield
- ensure
- $VERBOSE = old_verbose
- end
-end
@@ -1,7 +1,7 @@
require 'test/unit'
-require File.dirname(__FILE__) + '/../lib/active_support/misc'
+require File.dirname(__FILE__) + '/../../lib/active_support/core_ext/kernel'
-class MiscTest < Test::Unit::TestCase
+class KernelTest < Test::Unit::TestCase
def test_silence_warnings
silence_warnings { assert_nil $VERBOSE }
assert_equal 1234, silence_warnings { 1234 }
@@ -1,6 +1,7 @@
require 'test/unit'
+require 'date'
require File.dirname(__FILE__) + '/../../lib/active_support/core_ext/string'
-require File.dirname(__FILE__) + '/../../lib/active_support/misc'
+require File.dirname(__FILE__) + '/../../lib/active_support/core_ext/kernel'
silence_warnings do
require File.dirname(__FILE__) + '/../inflector_test'
@@ -1,6 +1,5 @@
require 'test/unit'
$LOAD_PATH.unshift File.dirname(__FILE__) + '/../lib/active_support/'
-require 'misc'
require 'dependencies'
class DependenciesTest < Test::Unit::TestCase
@@ -76,9 +76,7 @@ def initialize_logger
)
end
- old_verbose, $VERBOSE = $VERBOSE, nil
- Object.const_set "RAILS_DEFAULT_LOGGER", logger
- $VERBOSE = old_verbose
+ silence_warnings { Object.const_set "RAILS_DEFAULT_LOGGER", logger }
end
def initialize_framework_logging

0 comments on commit 3cf7a0a

Please sign in to comment.