aboutsummaryrefslogtreecommitdiffstats
path: root/activesupport/test
diff options
context:
space:
mode:
Diffstat (limited to 'activesupport/test')
-rw-r--r--activesupport/test/callback_inheritance_test.rb1
-rw-r--r--activesupport/test/callbacks_test.rb1
-rw-r--r--activesupport/test/core_ext/duplicable_test.rb3
-rw-r--r--activesupport/test/core_ext/hash_ext_test.rb3
-rw-r--r--activesupport/test/core_ext/kernel_test.rb46
-rw-r--r--activesupport/test/core_ext/object_and_class_ext_test.rb8
-rw-r--r--activesupport/test/dependencies_test.rb2
-rw-r--r--activesupport/test/deprecation_test.rb2
-rw-r--r--activesupport/test/file_update_checker_test.rb1
-rw-r--r--activesupport/test/flush_cache_on_private_memoization_test.rb1
-rw-r--r--activesupport/test/load_paths_test.rb3
-rw-r--r--activesupport/test/message_encryptor_test.rb2
-rw-r--r--activesupport/test/notifications_test.rb2
-rw-r--r--activesupport/test/secure_random_test.rb19
-rw-r--r--activesupport/test/xml_mini/jdom_engine_test.rb164
15 files changed, 143 insertions, 115 deletions
diff --git a/activesupport/test/callback_inheritance_test.rb b/activesupport/test/callback_inheritance_test.rb
index d569cbb4fb..06259c648c 100644
--- a/activesupport/test/callback_inheritance_test.rb
+++ b/activesupport/test/callback_inheritance_test.rb
@@ -1,6 +1,5 @@
require 'abstract_unit'
require 'test/unit'
-require 'active_support'
class GrandParent
include ActiveSupport::Callbacks
diff --git a/activesupport/test/callbacks_test.rb b/activesupport/test/callbacks_test.rb
index 816dcad968..2b4adda4d1 100644
--- a/activesupport/test/callbacks_test.rb
+++ b/activesupport/test/callbacks_test.rb
@@ -1,6 +1,5 @@
require 'abstract_unit'
require 'test/unit'
-require 'active_support'
module CallbacksTest
class Phone
diff --git a/activesupport/test/core_ext/duplicable_test.rb b/activesupport/test/core_ext/duplicable_test.rb
index 6e1f876959..24e0ccd9b3 100644
--- a/activesupport/test/core_ext/duplicable_test.rb
+++ b/activesupport/test/core_ext/duplicable_test.rb
@@ -1,9 +1,10 @@
require 'abstract_unit'
require 'bigdecimal'
require 'active_support/core_ext/object/duplicable'
+require 'active_support/core_ext/numeric/time'
class DuplicableTest < Test::Unit::TestCase
- NO = [nil, false, true, :symbol, 1, 2.3, BigDecimal.new('4.56'), Class.new]
+ NO = [nil, false, true, :symbol, 1, 2.3, BigDecimal.new('4.56'), Class.new, Module.new, 5.seconds]
YES = ['1', Object.new, /foo/, [], {}, Time.now]
def test_duplicable
diff --git a/activesupport/test/core_ext/hash_ext_test.rb b/activesupport/test/core_ext/hash_ext_test.rb
index b2c85f15cb..0b3f18faec 100644
--- a/activesupport/test/core_ext/hash_ext_test.rb
+++ b/activesupport/test/core_ext/hash_ext_test.rb
@@ -971,9 +971,10 @@ class HashToXmlTest < Test::Unit::TestCase
assert_nil hash_wia.default
end
- def test_should_return_self_for_with_indifferent_access
+ def test_should_return_dup_for_with_indifferent_access
hash_wia = HashWithIndifferentAccess.new
assert_equal hash_wia, hash_wia.with_indifferent_access
+ assert_not_same hash_wia, hash_wia.with_indifferent_access
end
def test_should_copy_the_default_value_when_converting_to_hash_with_indifferent_access
diff --git a/activesupport/test/core_ext/kernel_test.rb b/activesupport/test/core_ext/kernel_test.rb
index ede9b0a6aa..995bc0751a 100644
--- a/activesupport/test/core_ext/kernel_test.rb
+++ b/activesupport/test/core_ext/kernel_test.rb
@@ -52,10 +52,10 @@ class KernelTest < Test::Unit::TestCase
class << o; @x = 1; end
assert_equal 1, o.class_eval { @x }
end
-
+
def test_capture
- assert_equal 'STDERR', capture(:stderr) {$stderr.print 'STDERR'}
- assert_equal 'STDOUT', capture(:stdout) {print 'STDOUT'}
+ assert_equal 'STDERR', capture(:stderr) { $stderr.print 'STDERR' }
+ assert_equal 'STDOUT', capture(:stdout) { print 'STDOUT' }
end
end
@@ -73,3 +73,43 @@ class KernelSuppressTest < Test::Unit::TestCase
suppress(LoadError, ArgumentError) { raise ArgumentError }
end
end
+
+class MockStdErr
+ attr_reader :output
+ def puts(message)
+ @output ||= []
+ @output << message
+ end
+
+ def info(message)
+ puts(message)
+ end
+
+ def write(message)
+ puts(message)
+ end
+end
+
+class KernelDebuggerTest < Test::Unit::TestCase
+ def test_debugger_not_available_message_to_stderr
+ old_stderr = $stderr
+ $stderr = MockStdErr.new
+ debugger
+ assert_match(/Debugger requested/, $stderr.output.first)
+ ensure
+ $stderr = old_stderr
+ end
+
+ def test_debugger_not_available_message_to_rails_logger
+ rails = Class.new do
+ def self.logger
+ @logger ||= MockStdErr.new
+ end
+ end
+ Object.const_set("Rails", rails)
+ debugger
+ assert_match(/Debugger requested/, rails.logger.output.first)
+ ensure
+ Object.send(:remove_const, "Rails")
+ end
+end \ No newline at end of file
diff --git a/activesupport/test/core_ext/object_and_class_ext_test.rb b/activesupport/test/core_ext/object_and_class_ext_test.rb
index 5d68b198f2..beb371d987 100644
--- a/activesupport/test/core_ext/object_and_class_ext_test.rb
+++ b/activesupport/test/core_ext/object_and_class_ext_test.rb
@@ -99,7 +99,13 @@ class ObjectTryTest < Test::Unit::TestCase
def test_nonexisting_method
method = :undefined_method
assert !@string.respond_to?(method)
- assert_raise(NoMethodError) { @string.try(method) }
+ assert_nil @string.try(method)
+ end
+
+ def test_nonexisting_method_with_arguments
+ method = :undefined_method
+ assert !@string.respond_to?(method)
+ assert_nil @string.try(method, 'llo', 'y')
end
def test_valid_method
diff --git a/activesupport/test/dependencies_test.rb b/activesupport/test/dependencies_test.rb
index ef017d7436..2ddbce5150 100644
--- a/activesupport/test/dependencies_test.rb
+++ b/activesupport/test/dependencies_test.rb
@@ -24,11 +24,13 @@ class DependenciesTest < Test::Unit::TestCase
old_mechanism, ActiveSupport::Dependencies.mechanism = ActiveSupport::Dependencies.mechanism, :load
this_dir = File.dirname(__FILE__)
parent_dir = File.dirname(this_dir)
+ path_copy = $LOAD_PATH.dup
$LOAD_PATH.unshift(parent_dir) unless $LOAD_PATH.include?(parent_dir)
prior_autoload_paths = ActiveSupport::Dependencies.autoload_paths
ActiveSupport::Dependencies.autoload_paths = from.collect { |f| "#{this_dir}/#{f}" }
yield
ensure
+ $LOAD_PATH.replace(path_copy)
ActiveSupport::Dependencies.autoload_paths = prior_autoload_paths
ActiveSupport::Dependencies.mechanism = old_mechanism
ActiveSupport::Dependencies.explicitly_unloadable_constants = []
diff --git a/activesupport/test/deprecation_test.rb b/activesupport/test/deprecation_test.rb
index cad0810241..d77a62f108 100644
--- a/activesupport/test/deprecation_test.rb
+++ b/activesupport/test/deprecation_test.rb
@@ -62,7 +62,7 @@ class DeprecationTest < ActiveSupport::TestCase
end
def test_deprecate_class_method
- assert_deprecated(/none is deprecated.*test_deprecate_class_method/) do
+ assert_deprecated(/none is deprecated/) do
assert_equal 1, @dtc.none
end
diff --git a/activesupport/test/file_update_checker_test.rb b/activesupport/test/file_update_checker_test.rb
index baf29cc337..b65bb1d024 100644
--- a/activesupport/test/file_update_checker_test.rb
+++ b/activesupport/test/file_update_checker_test.rb
@@ -1,6 +1,5 @@
require 'abstract_unit'
require 'test/unit'
-require 'active_support'
require 'fileutils'
MTIME_FIXTURES_PATH = File.expand_path("../fixtures", __FILE__)
diff --git a/activesupport/test/flush_cache_on_private_memoization_test.rb b/activesupport/test/flush_cache_on_private_memoization_test.rb
index 91b856ed7c..a7db96eb71 100644
--- a/activesupport/test/flush_cache_on_private_memoization_test.rb
+++ b/activesupport/test/flush_cache_on_private_memoization_test.rb
@@ -1,5 +1,4 @@
require 'abstract_unit'
-require 'active_support'
require 'test/unit'
class FlashCacheOnPrivateMemoizationTest < Test::Unit::TestCase
diff --git a/activesupport/test/load_paths_test.rb b/activesupport/test/load_paths_test.rb
index 36e3726a02..a2d8da726a 100644
--- a/activesupport/test/load_paths_test.rb
+++ b/activesupport/test/load_paths_test.rb
@@ -10,6 +10,7 @@ class LoadPathsTest < Test::Unit::TestCase
}
load_paths_count[File.expand_path('../../lib', __FILE__)] -= 1
- assert load_paths_count.select { |k, v| v > 1 }.empty?, $LOAD_PATH.inspect
+ filtered = load_paths_count.select { |k, v| v > 1 }
+ assert filtered.empty?, filtered.inspect
end
end
diff --git a/activesupport/test/message_encryptor_test.rb b/activesupport/test/message_encryptor_test.rb
index 419ac14283..e45d5ecd59 100644
--- a/activesupport/test/message_encryptor_test.rb
+++ b/activesupport/test/message_encryptor_test.rb
@@ -11,7 +11,7 @@ require 'active_support/time'
class MessageEncryptorTest < Test::Unit::TestCase
def setup
- @encryptor = ActiveSupport::MessageEncryptor.new(ActiveSupport::SecureRandom.hex(64))
+ @encryptor = ActiveSupport::MessageEncryptor.new(SecureRandom.hex(64))
@data = { :some => "data", :now => Time.local(2010) }
end
diff --git a/activesupport/test/notifications_test.rb b/activesupport/test/notifications_test.rb
index 7b48b3f85b..cc0dc564f7 100644
--- a/activesupport/test/notifications_test.rb
+++ b/activesupport/test/notifications_test.rb
@@ -215,7 +215,7 @@ module Notifications
protected
def random_id
- @random_id ||= ActiveSupport::SecureRandom.hex(10)
+ @random_id ||= SecureRandom.hex(10)
end
end
end
diff --git a/activesupport/test/secure_random_test.rb b/activesupport/test/secure_random_test.rb
deleted file mode 100644
index 44694cd811..0000000000
--- a/activesupport/test/secure_random_test.rb
+++ /dev/null
@@ -1,19 +0,0 @@
-require 'abstract_unit'
-
-class SecureRandomTest < Test::Unit::TestCase
- def test_random_bytes
- b1 = ActiveSupport::SecureRandom.random_bytes(64)
- b2 = ActiveSupport::SecureRandom.random_bytes(64)
- assert_not_equal b1, b2
- end
-
- def test_hex
- b1 = ActiveSupport::SecureRandom.hex(64)
- b2 = ActiveSupport::SecureRandom.hex(64)
- assert_not_equal b1, b2
- end
-
- def test_random_number
- assert ActiveSupport::SecureRandom.random_number(5000) < 5000
- end
-end
diff --git a/activesupport/test/xml_mini/jdom_engine_test.rb b/activesupport/test/xml_mini/jdom_engine_test.rb
index b745228994..3fe5e4fd78 100644
--- a/activesupport/test/xml_mini/jdom_engine_test.rb
+++ b/activesupport/test/xml_mini/jdom_engine_test.rb
@@ -1,38 +1,38 @@
-require 'abstract_unit'
-require 'active_support/xml_mini'
-
if RUBY_PLATFORM =~ /java/
+ require 'abstract_unit'
+ require 'active_support/xml_mini'
+ require 'active_support/core_ext/hash/conversions'
-class JDOMEngineTest < Test::Unit::TestCase
- include ActiveSupport
+ class JDOMEngineTest < Test::Unit::TestCase
+ include ActiveSupport
- def setup
- @default_backend = XmlMini.backend
- XmlMini.backend = 'JDOM'
- end
+ def setup
+ @default_backend = XmlMini.backend
+ XmlMini.backend = 'JDOM'
+ end
- def teardown
- XmlMini.backend = @default_backend
- end
+ def teardown
+ XmlMini.backend = @default_backend
+ end
- # def test_file_from_xml
- # hash = Hash.from_xml(<<-eoxml)
- # <blog>
- # <logo type="file" name="logo.png" content_type="image/png">
- # </logo>
- # </blog>
- # eoxml
- # assert hash.has_key?('blog')
- # assert hash['blog'].has_key?('logo')
- #
- # file = hash['blog']['logo']
- # assert_equal 'logo.png', file.original_filename
- # assert_equal 'image/png', file.content_type
- # end
-
- def test_exception_thrown_on_expansion_attack
- assert_raise NativeException do
- attack_xml = <<-EOT
+ # def test_file_from_xml
+ # hash = Hash.from_xml(<<-eoxml)
+ # <blog>
+ # <logo type="file" name="logo.png" content_type="image/png">
+ # </logo>
+ # </blog>
+ # eoxml
+ # assert hash.has_key?('blog')
+ # assert hash['blog'].has_key?('logo')
+ #
+ # file = hash['blog']['logo']
+ # assert_equal 'logo.png', file.original_filename
+ # assert_equal 'image/png', file.content_type
+ # end
+
+ def test_exception_thrown_on_expansion_attack
+ assert_raise NativeException do
+ attack_xml = <<-EOT
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE member [
<!ENTITY a "&b;&b;&b;&b;&b;&b;&b;&b;&b;&b;">
@@ -46,91 +46,91 @@ class JDOMEngineTest < Test::Unit::TestCase
<member>
&a;
</member>
- EOT
- Hash.from_xml(attack_xml)
+ EOT
+ Hash.from_xml(attack_xml)
+ end
end
- end
- def test_setting_JDOM_as_backend
- XmlMini.backend = 'JDOM'
- assert_equal XmlMini_JDOM, XmlMini.backend
- end
+ def test_setting_JDOM_as_backend
+ XmlMini.backend = 'JDOM'
+ assert_equal XmlMini_JDOM, XmlMini.backend
+ end
- def test_blank_returns_empty_hash
- assert_equal({}, XmlMini.parse(nil))
- assert_equal({}, XmlMini.parse(''))
- end
+ def test_blank_returns_empty_hash
+ assert_equal({}, XmlMini.parse(nil))
+ assert_equal({}, XmlMini.parse(''))
+ end
- def test_array_type_makes_an_array
- assert_equal_rexml(<<-eoxml)
+ def test_array_type_makes_an_array
+ assert_equal_rexml(<<-eoxml)
<blog>
<posts type="array">
<post>a post</post>
<post>another post</post>
</posts>
</blog>
- eoxml
- end
+ eoxml
+ end
- def test_one_node_document_as_hash
- assert_equal_rexml(<<-eoxml)
+ def test_one_node_document_as_hash
+ assert_equal_rexml(<<-eoxml)
<products/>
- eoxml
- end
+ eoxml
+ end
- def test_one_node_with_attributes_document_as_hash
- assert_equal_rexml(<<-eoxml)
+ def test_one_node_with_attributes_document_as_hash
+ assert_equal_rexml(<<-eoxml)
<products foo="bar"/>
- eoxml
- end
+ eoxml
+ end
- def test_products_node_with_book_node_as_hash
- assert_equal_rexml(<<-eoxml)
+ def test_products_node_with_book_node_as_hash
+ assert_equal_rexml(<<-eoxml)
<products>
<book name="awesome" id="12345" />
</products>
- eoxml
- end
+ eoxml
+ end
- def test_products_node_with_two_book_nodes_as_hash
- assert_equal_rexml(<<-eoxml)
+ def test_products_node_with_two_book_nodes_as_hash
+ assert_equal_rexml(<<-eoxml)
<products>
<book name="awesome" id="12345" />
<book name="america" id="67890" />
</products>
- eoxml
- end
+ eoxml
+ end
- def test_single_node_with_content_as_hash
- assert_equal_rexml(<<-eoxml)
+ def test_single_node_with_content_as_hash
+ assert_equal_rexml(<<-eoxml)
<products>
hello world
</products>
- eoxml
- end
+ eoxml
+ end
- def test_children_with_children
- assert_equal_rexml(<<-eoxml)
+ def test_children_with_children
+ assert_equal_rexml(<<-eoxml)
<root>
<products>
<book name="america" id="67890" />
</products>
</root>
- eoxml
- end
+ eoxml
+ end
- def test_children_with_text
- assert_equal_rexml(<<-eoxml)
+ def test_children_with_text
+ assert_equal_rexml(<<-eoxml)
<root>
<products>
hello everyone
</products>
</root>
- eoxml
- end
+ eoxml
+ end
- def test_children_with_non_adjacent_text
- assert_equal_rexml(<<-eoxml)
+ def test_children_with_non_adjacent_text
+ assert_equal_rexml(<<-eoxml)
<root>
good
<products>
@@ -138,15 +138,15 @@ class JDOMEngineTest < Test::Unit::TestCase
</products>
morning
</root>
- eoxml
- end
+ eoxml
+ end
- private
- def assert_equal_rexml(xml)
- hash = XmlMini.with_backend('REXML') { XmlMini.parse(xml) }
- assert_equal(hash, XmlMini.parse(xml))
+ private
+ def assert_equal_rexml(xml)
+ hash = XmlMini.with_backend('REXML') { XmlMini.parse(xml) }
+ assert_equal(hash, XmlMini.parse(xml))
+ end
end
-end
else
# don't run these test because we aren't running in JRuby