diff options
author | Jeremy Kemper <jeremy@bitsweat.net> | 2006-07-08 18:14:49 +0000 |
---|---|---|
committer | Jeremy Kemper <jeremy@bitsweat.net> | 2006-07-08 18:14:49 +0000 |
commit | 71234daef1517cf190adfc5978e56882d2a57ea6 (patch) | |
tree | 71763eb04ed0a82e315e85272ea1f8064df64673 /activesupport/test | |
parent | a3f459eecfec2beda2f51fb6d62eca4e5d5fbd70 (diff) | |
download | rails-71234daef1517cf190adfc5978e56882d2a57ea6.tar.gz rails-71234daef1517cf190adfc5978e56882d2a57ea6.tar.bz2 rails-71234daef1517cf190adfc5978e56882d2a57ea6.zip |
r4487@asus: jeremy | 2006-04-29 12:21:39 -0700
Check whether @flash is defined? for warnings-safety.
r4488@asus: jeremy | 2006-04-29 12:23:15 -0700
Check whether @flash is defined? for warnings-safety. Obviates nil? check.
r4489@asus: jeremy | 2006-04-29 12:45:18 -0700
Check whether @session is defined? for warnings-safety.
r4490@asus: jeremy | 2006-04-29 12:50:41 -0700
Check whether @rendering_runtime is defined? for warnings-safety.
r4491@asus: jeremy | 2006-04-29 12:55:01 -0700
Check whether @_cycles is defined? for warnings-safety.
r4492@asus: jeremy | 2006-04-29 12:59:19 -0700
Check whether instance variables are defined? for warnings-safety.
r4493@asus: jeremy | 2006-04-29 13:14:09 -0700
Add nil @template to PrototypeHelperTest to suppress unitialized instance variable warning.
r4494@asus: jeremy | 2006-04-29 13:31:34 -0700
Check whether @auto_index defined? for warnings-safety.
r4495@asus: jeremy | 2006-04-29 13:32:24 -0700
Wrap content_columns redefinitions with silence_warnings.
r4496@asus: jeremy | 2006-04-29 13:35:28 -0700
Wrap more redefinitions with silence_warnings.
r4829@asus: jeremy | 2006-07-08 10:59:20 -0700
abstract unit, fix warnings
r4830@asus: jeremy | 2006-07-08 11:06:12 -0700
Use parens to silence warning.
r4831@asus: jeremy | 2006-07-08 11:06:48 -0700
Use parens to silence warning.
git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@4595 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
Diffstat (limited to 'activesupport/test')
32 files changed, 195 insertions, 246 deletions
diff --git a/activesupport/test/abstract_unit.rb b/activesupport/test/abstract_unit.rb new file mode 100644 index 0000000000..7e3ff50ac9 --- /dev/null +++ b/activesupport/test/abstract_unit.rb @@ -0,0 +1,4 @@ +require 'test/unit' + +$:.unshift "#{File.dirname(__FILE__)}/../lib" +require 'active_support' diff --git a/activesupport/test/caching_tools_test.rb b/activesupport/test/caching_tools_test.rb index 9f3e42e496..c9890e4d13 100644 --- a/activesupport/test/caching_tools_test.rb +++ b/activesupport/test/caching_tools_test.rb @@ -1,11 +1,9 @@ -require 'test/unit' -require File.dirname(__FILE__)+'/../lib/active_support/caching_tools' +require File.dirname(__FILE__) + '/abstract_unit' class HashCachingTests < Test::Unit::TestCase - def cached(&proc) - return @cached if @cached - + return @cached if defined?(@cached) + @cached_class = Class.new(&proc) @cached_class.class_eval do extend ActiveSupport::CachingTools::HashCaching @@ -13,14 +11,14 @@ class HashCachingTests < Test::Unit::TestCase end @cached = @cached_class.new end - + def test_cache_access_should_call_method cached do def slow_method(a) raise "I should be here: #{a}"; end end assert_raises(RuntimeError) { cached.slow_method_cache[1] } end - + def test_cache_access_should_actually_cache cached do def slow_method(a) @@ -37,7 +35,7 @@ class HashCachingTests < Test::Unit::TestCase assert_equal 11, cached.slow_method_cache[10] assert_equal 12, cached.slow_method_cache[11] end - + def test_cache_should_be_clearable cached do def slow_method(a) @@ -48,18 +46,18 @@ class HashCachingTests < Test::Unit::TestCase assert_equal 1, cached.slow_method_cache[:a] assert_equal 2, cached.slow_method_cache[:b] assert_equal 3, cached.slow_method_cache[:c] - + assert_equal 1, cached.slow_method_cache[:a] assert_equal 2, cached.slow_method_cache[:b] assert_equal 3, cached.slow_method_cache[:c] - + cached.slow_method_cache.clear - + assert_equal 4, cached.slow_method_cache[:a] assert_equal 5, cached.slow_method_cache[:b] assert_equal 6, cached.slow_method_cache[:c] end - + def test_deep_caches_should_work_too cached do def slow_method(a, b, c) @@ -70,12 +68,11 @@ class HashCachingTests < Test::Unit::TestCase assert_equal 7, cached.slow_method_cache[1][2][4] assert_equal 7, cached.slow_method_cache[1][2][4] assert_equal 7, cached.slow_method_cache[4][2][1] - + assert_equal({ 1 => {1 => {1 => 3}, 2 => {4 => 7}}, 4 => {2 => {1 => 7}}}, cached.slow_method_cache ) end - end diff --git a/activesupport/test/class_inheritable_attributes_test.rb b/activesupport/test/class_inheritable_attributes_test.rb index 36914e2bbf..54e533e964 100644 --- a/activesupport/test/class_inheritable_attributes_test.rb +++ b/activesupport/test/class_inheritable_attributes_test.rb @@ -1,5 +1,4 @@ -require 'test/unit' -require File.dirname(__FILE__) + '/../lib/active_support/core_ext/class/inheritable_attributes' +require File.dirname(__FILE__) + '/abstract_unit' class ClassInheritableAttributesTest < Test::Unit::TestCase def setup diff --git a/activesupport/test/clean_logger_test.rb b/activesupport/test/clean_logger_test.rb index fabbc4af03..a15bfbca3b 100644 --- a/activesupport/test/clean_logger_test.rb +++ b/activesupport/test/clean_logger_test.rb @@ -1,7 +1,5 @@ -require 'test/unit' +require File.dirname(__FILE__) + '/abstract_unit' require 'stringio' -require File.dirname(__FILE__) + '/../lib/active_support/clean_logger' -require File.dirname(__FILE__) + '/../lib/active_support/core_ext/kernel.rb' unless defined? silence_warnings class CleanLoggerTest < Test::Unit::TestCase def setup diff --git a/activesupport/test/core_ext/array_ext_test.rb b/activesupport/test/core_ext/array_ext_test.rb index 492e59bf21..955b2b30c1 100644 --- a/activesupport/test/core_ext/array_ext_test.rb +++ b/activesupport/test/core_ext/array_ext_test.rb @@ -1,5 +1,4 @@ -require 'test/unit' -require File.dirname(__FILE__) + '/../../lib/active_support' +require File.dirname(__FILE__) + '/../abstract_unit' class ArrayExtToParamTests < Test::Unit::TestCase def test_string_array @@ -7,7 +6,7 @@ class ArrayExtToParamTests < Test::Unit::TestCase assert_equal 'hello/world', %w(hello world).to_param assert_equal 'hello/10', %w(hello 10).to_param end - + def test_number_array assert_equal '10/20', [10, 20].to_param end @@ -19,13 +18,13 @@ class ArrayExtToSentenceTests < Test::Unit::TestCase assert_equal "one", ['one'].to_sentence assert_equal "one and two", ['one', 'two'].to_sentence assert_equal "one, two, and three", ['one', 'two', 'three'].to_sentence - + end - + def test_to_sentence_with_connector assert_equal "one, two, and also three", ['one', 'two', 'three'].to_sentence(:connector => 'and also') end - + def test_to_sentence_with_skip_last_comma assert_equal "one, two, and three", ['one', 'two', 'three'].to_sentence(:skip_last_comma => false) end @@ -33,7 +32,7 @@ class ArrayExtToSentenceTests < Test::Unit::TestCase def test_two_elements assert_equal "one and two", ['one', 'two'].to_sentence end - + def test_one_element assert_equal "one", ['one'].to_sentence end @@ -46,7 +45,7 @@ class ArrayExtToSTests < Test::Unit::TestCase Class.new { def id() 2 end }.new, Class.new { def id() 3 end }.new ] - + assert_equal "null", [].to_s(:db) assert_equal "1,2,3", collection.to_s(:db) end @@ -87,16 +86,16 @@ class ArraySplitTests < Test::Unit::TestCase def test_split_with_empty_array assert_equal [[]], [].split(0) end - + def test_split_with_argument assert_equal [[1, 2], [4, 5]], [1, 2, 3, 4, 5].split(3) assert_equal [[1, 2, 3, 4, 5]], [1, 2, 3, 4, 5].split(0) end - + def test_split_with_block assert_equal [[1, 2], [4, 5], [7, 8], [10]], (1..10).to_a.split { |i| i % 3 == 0 } end - + def test_split_with_edge_values assert_equal [[], [2, 3, 4, 5]], [1, 2, 3, 4, 5].split(1) assert_equal [[1, 2, 3, 4], []], [1, 2, 3, 4, 5].split(5) @@ -124,9 +123,9 @@ class ArrayToXmlTests < Test::Unit::TestCase assert_equal "<people><person>", xml.first(16) end - + def test_to_xml_with_options - xml = [ + xml = [ { :name => "David", :street_address => "Paulina" }, { :name => "Jason", :street_address => "Evergreen" } ].to_xml(:skip_instruct => true, :skip_types => true, :indent => 0) @@ -138,7 +137,7 @@ class ArrayToXmlTests < Test::Unit::TestCase end def test_to_xml_with_dasherize_false - xml = [ + xml = [ { :name => "David", :street_address => "Paulina" }, { :name => "Jason", :street_address => "Evergreen" } ].to_xml(:skip_instruct => true, :skip_types => true, :indent => 0, :dasherize => false) @@ -148,7 +147,7 @@ class ArrayToXmlTests < Test::Unit::TestCase end def test_to_xml_with_dasherize_true - xml = [ + xml = [ { :name => "David", :street_address => "Paulina" }, { :name => "Jason", :street_address => "Evergreen" } ].to_xml(:skip_instruct => true, :skip_types => true, :indent => 0, :dasherize => true) diff --git a/activesupport/test/core_ext/blank_test.rb b/activesupport/test/core_ext/blank_test.rb index ff7345e774..0fce470fd5 100644 --- a/activesupport/test/core_ext/blank_test.rb +++ b/activesupport/test/core_ext/blank_test.rb @@ -1,6 +1,4 @@ -require 'test/unit' -require File.dirname(__FILE__) + '/../../lib/active_support/core_ext/object' -require File.dirname(__FILE__) + '/../../lib/active_support/core_ext/blank' +require File.dirname(__FILE__) + '/../abstract_unit' class BlankTest < Test::Unit::TestCase BLANK = [nil, false, '', ' ', " \n\t \r ", [], {}] diff --git a/activesupport/test/core_ext/cgi_ext_test.rb b/activesupport/test/core_ext/cgi_ext_test.rb index ec9bb41334..229715c28e 100644 --- a/activesupport/test/core_ext/cgi_ext_test.rb +++ b/activesupport/test/core_ext/cgi_ext_test.rb @@ -1,5 +1,4 @@ -require 'test/unit' -require File.dirname(__FILE__) + '/../../lib/active_support/core_ext/cgi' +require File.dirname(__FILE__) + '/../abstract_unit' class EscapeSkippingSlashesTest < Test::Unit::TestCase def test_array diff --git a/activesupport/test/core_ext/class_test.rb b/activesupport/test/core_ext/class_test.rb index 6e956fa45d..bcb96f5e33 100644 --- a/activesupport/test/core_ext/class_test.rb +++ b/activesupport/test/core_ext/class_test.rb @@ -1,5 +1,4 @@ -require 'test/unit' -require File.dirname(__FILE__) + '/../../lib/active_support/core_ext/class' +require File.dirname(__FILE__) + '/../abstract_unit' class A end diff --git a/activesupport/test/core_ext/date_ext_test.rb b/activesupport/test/core_ext/date_ext_test.rb index 63a0cf5e6d..71c2ed1f3a 100644 --- a/activesupport/test/core_ext/date_ext_test.rb +++ b/activesupport/test/core_ext/date_ext_test.rb @@ -1,17 +1,16 @@ -require 'test/unit' -require File.dirname(__FILE__) + '/../../lib/active_support/core_ext/date' +require File.dirname(__FILE__) + '/../abstract_unit' class DateExtCalculationsTest < Test::Unit::TestCase def test_to_s assert_equal "21 Feb", Date.new(2005, 2, 21).to_s(:short) assert_equal "February 21, 2005", Date.new(2005, 2, 21).to_s(:long) end - + def test_to_time assert_equal Time.local(2005, 2, 21), Date.new(2005, 2, 21).to_time end - + def test_to_date assert_equal Date.new(2005, 2, 21), Date.new(2005, 2, 21).to_date end -end
\ No newline at end of file +end diff --git a/activesupport/test/core_ext/enumerable_test.rb b/activesupport/test/core_ext/enumerable_test.rb index 3d116e8d93..3180755e5f 100644 --- a/activesupport/test/core_ext/enumerable_test.rb +++ b/activesupport/test/core_ext/enumerable_test.rb @@ -1,6 +1,4 @@ -require 'test/unit' -require File.dirname(__FILE__) + '/../../lib/active_support/core_ext/symbol' -require File.dirname(__FILE__) + '/../../lib/active_support/core_ext/enumerable' +require File.dirname(__FILE__) + '/../abstract_unit' Payment = Struct.new(:price) class SummablePayment < Payment @@ -12,7 +10,7 @@ class EnumerableTests < Test::Unit::TestCase names = %w(marcel sam david jeremy) klass = Class.new klass.send(:attr_accessor, :name) - objects = (1..50).inject([]) do |people,| + objects = (1..50).inject([]) do |people,| p = klass.new p.name = names.sort_by { rand }.first people << p diff --git a/activesupport/test/core_ext/exception_test.rb b/activesupport/test/core_ext/exception_test.rb index 9b7afb1913..952ac04e2e 100644 --- a/activesupport/test/core_ext/exception_test.rb +++ b/activesupport/test/core_ext/exception_test.rb @@ -1,33 +1,32 @@ -require 'test/unit' -require File.dirname(__FILE__) + '/../../lib/active_support/core_ext/exception' +require File.dirname(__FILE__) + '/../abstract_unit' class ExceptionExtTests < Test::Unit::TestCase - + def get_exception(cls = RuntimeError, msg = nil, trace = nil) begin raise cls, msg, (trace || caller) rescue Object => e return e end end - + def setup Exception::TraceSubstitutions.clear end - + def test_clean_backtrace Exception::TraceSubstitutions << [/\s*hidden.*/, ''] e = get_exception RuntimeError, 'RAWR', ['bhal.rb', 'rawh hid den stuff is not here', 'almost all'] assert_kind_of Exception, e assert_equal ['bhal.rb', 'rawh hid den stuff is not here', 'almost all'], e.clean_backtrace end - + def test_app_backtrace Exception::TraceSubstitutions << [/\s*hidden.*/, ''] e = get_exception RuntimeError, 'RAWR', ['bhal.rb', ' vendor/file.rb some stuff', 'almost all'] assert_kind_of Exception, e assert_equal ['bhal.rb', 'almost all'], e.application_backtrace end - + def test_app_backtrace_with_before Exception::TraceSubstitutions << [/\s*hidden.*/, ''] e = get_exception RuntimeError, 'RAWR', ['vendor/file.rb some stuff', 'bhal.rb', ' vendor/file.rb some stuff', 'almost all'] @@ -41,21 +40,21 @@ class ExceptionExtTests < Test::Unit::TestCase assert_kind_of Exception, e assert_equal ['vendor/file.rb some stuff', ' vendor/file.rb some stuff'], e.framework_backtrace end - + def test_backtrace_should_clean_paths Exception::TraceSubstitutions << [/\s*hidden.*/, ''] e = get_exception RuntimeError, 'RAWR', ['a/b/c/../d/../../../bhal.rb', 'rawh hid den stuff is not here', 'almost all'] assert_kind_of Exception, e assert_equal ['bhal.rb', 'rawh hid den stuff is not here', 'almost all'], e.clean_backtrace end - + def test_clean_message_should_clean_paths Exception::TraceSubstitutions << [/\s*hidden.*/, ''] e = get_exception RuntimeError, "I dislike a/z/x/../../b/y/../c", ['a/b/c/../d/../../../bhal.rb', 'rawh hid den stuff is not here', 'almost all'] assert_kind_of Exception, e assert_equal "I dislike a/b/c", e.clean_message end - + def test_app_trace_should_be_empty_when_no_app_frames Exception::TraceSubstitutions << [/\s*hidden.*/, ''] e = get_exception RuntimeError, 'RAWR', ['vendor/file.rb some stuff', 'generated/bhal.rb', ' vendor/file.rb some stuff', 'generated/almost all'] diff --git a/activesupport/test/core_ext/hash_ext_test.rb b/activesupport/test/core_ext/hash_ext_test.rb index 28b4304500..2afdf95c4d 100644 --- a/activesupport/test/core_ext/hash_ext_test.rb +++ b/activesupport/test/core_ext/hash_ext_test.rb @@ -1,5 +1,4 @@ -require 'test/unit' -require File.dirname(__FILE__) + '/../../lib/active_support' +require File.dirname(__FILE__) + '/../abstract_unit' class HashExtTest < Test::Unit::TestCase def setup diff --git a/activesupport/test/core_ext/integer_ext_test.rb b/activesupport/test/core_ext/integer_ext_test.rb index 4435bc79d3..6d6b796865 100644 --- a/activesupport/test/core_ext/integer_ext_test.rb +++ b/activesupport/test/core_ext/integer_ext_test.rb @@ -1,11 +1,10 @@ -require 'test/unit' -require File.dirname(__FILE__) + '/../../lib/active_support/core_ext/integer' +require File.dirname(__FILE__) + '/../abstract_unit' class IntegerExtTest < Test::Unit::TestCase def test_even assert [ -2, 0, 2, 4 ].all? { |i| i.even? } assert ![ -1, 1, 3 ].all? { |i| i.even? } - + assert 22953686867719691230002707821868552601124472329079.odd? assert !22953686867719691230002707821868552601124472329079.even? assert 22953686867719691230002707821868552601124472329080.even? @@ -17,7 +16,7 @@ class IntegerExtTest < Test::Unit::TestCase assert [ -1, 1, 3 ].all? { |i| i.odd? } assert 1000000000000000000000000000000000000000000000000000000001.odd? end - + def test_multiple_of [ -7, 0, 7, 14 ].each { |i| assert i.multiple_of?(7) } [ -7, 7, 14 ].each { |i| assert ! i.multiple_of?(6) } diff --git a/activesupport/test/core_ext/kernel_test.rb b/activesupport/test/core_ext/kernel_test.rb index 44e3b87241..92d9047061 100644 --- a/activesupport/test/core_ext/kernel_test.rb +++ b/activesupport/test/core_ext/kernel_test.rb @@ -1,5 +1,4 @@ -require 'test/unit' -require File.dirname(__FILE__) + '/../../lib/active_support/core_ext/kernel' unless defined? silence_warnings +require File.dirname(__FILE__) + '/../abstract_unit' class KernelTest < Test::Unit::TestCase def test_silence_warnings diff --git a/activesupport/test/core_ext/load_error_tests.rb b/activesupport/test/core_ext/load_error_tests.rb index 0b24c47112..34c5cb4cda 100644 --- a/activesupport/test/core_ext/load_error_tests.rb +++ b/activesupport/test/core_ext/load_error_tests.rb @@ -1,5 +1,4 @@ -require 'test/unit' -require File.dirname(__FILE__) + '/../../lib/active_support/core_ext/load_error' +require File.dirname(__FILE__) + '/../abstract_unit' class TestMissingSourceFile < Test::Unit::TestCase def test_with_require @@ -14,4 +13,4 @@ class TestMissingSourceFile < Test::Unit::TestCase assert_equal 'nor/this/one.rb', e.path end end -end
\ No newline at end of file +end diff --git a/activesupport/test/core_ext/module_test.rb b/activesupport/test/core_ext/module_test.rb index 66e4afc918..5507ef3120 100644 --- a/activesupport/test/core_ext/module_test.rb +++ b/activesupport/test/core_ext/module_test.rb @@ -1,6 +1,4 @@ -require 'test/unit' -require File.dirname(__FILE__) + '/../../lib/active_support/core_ext/class' -require File.dirname(__FILE__) + '/../../lib/active_support/core_ext/module' +require File.dirname(__FILE__) + '/../abstract_unit' module One end @@ -67,33 +65,33 @@ class ModuleTest < Test::Unit::TestCase assert_equal "Paulina", david.street assert_equal "Chicago", david.city end - + def test_delegation_down_hierarchy david = Someone.new("David", Somewhere.new("Paulina", "Chicago")) assert_equal "CHICAGO", david.upcase end - + def test_delegation_to_instance_variable david = Name.new("David", "Hansson") assert_equal "DAVID HANSSON", david.upcase end - + def test_missing_delegation_target assert_raises(ArgumentError) { eval($nowhere) } assert_raises(ArgumentError) { eval($noplace) } end - + def test_parent assert_equal Yz::Zy, Yz::Zy::Cd.parent assert_equal Yz, Yz::Zy.parent assert_equal Object, Yz.parent end - + def test_parents assert_equal [Yz::Zy, Yz, Object], Yz::Zy::Cd.parents assert_equal [Yz, Object], Yz::Zy.parents end - + def test_as_load_path assert_equal 'yz/zy', Yz::Zy.as_load_path assert_equal 'yz', Yz.as_load_path @@ -156,7 +154,7 @@ class MethodAliasingTest < Test::Unit::TestCase FooClassWithBarMethod.send(:include, BarMethodAliaser) FooClassWithBarMethod.alias_method_chain :quux!, :baz assert @instance.respond_to?(:quux_with_baz!) - + assert_equal 'quux_with_baz!', @instance.quux! assert_equal 'quux', @instance.quux_without_baz! end @@ -166,11 +164,11 @@ class MethodAliasingTest < Test::Unit::TestCase FooClassWithBarMethod.send(:define_method, 'quux?', Proc.new { true }) assert !@instance.respond_to?(:quux_with_baz!) assert !@instance.respond_to?(:quux_with_baz?) - + FooClassWithBarMethod.send(:include, BarMethodAliaser) FooClassWithBarMethod.alias_method_chain :quux!, :baz FooClassWithBarMethod.alias_method_chain :quux?, :baz - + assert @instance.respond_to?(:quux_with_baz!) assert @instance.respond_to?(:quux_with_baz?) assert_equal 'quux_with_baz!', @instance.quux! diff --git a/activesupport/test/core_ext/numeric_ext_test.rb b/activesupport/test/core_ext/numeric_ext_test.rb index 828276d46a..1d04cf7fe8 100644 --- a/activesupport/test/core_ext/numeric_ext_test.rb +++ b/activesupport/test/core_ext/numeric_ext_test.rb @@ -1,5 +1,4 @@ -require 'test/unit' -require File.dirname(__FILE__) + '/../../lib/active_support/core_ext/numeric' +require File.dirname(__FILE__) + '/../abstract_unit' class NumericExtTimeTest < Test::Unit::TestCase def setup 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 a1e5ea79db..73121ca966 100644 --- a/activesupport/test/core_ext/object_and_class_ext_test.rb +++ b/activesupport/test/core_ext/object_and_class_ext_test.rb @@ -1,6 +1,4 @@ -require 'test/unit' -require File.dirname(__FILE__) + '/../../lib/active_support/core_ext/object' -require File.dirname(__FILE__) + '/../../lib/active_support/core_ext/class' +require File.dirname(__FILE__) + '/../abstract_unit' class ClassA; end class ClassB < ClassA; end @@ -41,24 +39,24 @@ class ClassExtTest < Test::Unit::TestCase assert !defined?(ClassC) assert !defined?(ClassD) end - + def test_subclasses_of assert_equal [ClassJ], Object.subclasses_of(ClassI) ClassI.remove_subclasses assert_equal [], Object.subclasses_of(ClassI) end - + def test_subclasses_of_should_find_nested_classes assert Object.subclasses_of(ClassK).include?(Nested::ClassL) end - + def test_subclasses_of_should_not_return_removed_classes # First create the removed class old_class = Nested.send :remove_const, :ClassL new_class = Class.new(ClassK) Nested.const_set :ClassL, new_class assert_equal "Nested::ClassL", new_class.name # Sanity check - + subclasses = Object.subclasses_of(ClassK) assert subclasses.include?(new_class) assert ! subclasses.include?(old_class) @@ -75,23 +73,23 @@ class ObjectTests < Test::Unit::TestCase suppress(LoadError, ArgumentError) { raise LoadError } suppress(LoadError, ArgumentError) { raise ArgumentError } end - + def test_extended_by foo = Foo.new assert foo.extended_by.include?(Bar) foo.extend(Baz) assert ([Bar, Baz] - foo.extended_by).empty?, "Expected Bar, Baz in #{foo.extended_by.inspect}" end - + def test_extend_with_included_modules_from foo, object = Foo.new, Object.new assert !object.respond_to?(:bar) assert !object.respond_to?(:baz) - + object.extend_with_included_modules_from(foo) assert object.respond_to?(:bar) assert !object.respond_to?(:baz) - + foo.extend(Baz) object.extend_with_included_modules_from(foo) assert object.respond_to?(:bar) @@ -113,17 +111,17 @@ class ObjectInstanceVariableTest < Test::Unit::TestCase assert_equal %w(@bar @baz), @dest.instance_variables.sort %w(@bar @baz).each do |name| - assert_equal @source.instance_variable_get(name).object_id, + assert_equal @source.instance_variable_get(name).object_id, @dest.instance_variable_get(name).object_id end end - + def test_copy_instance_variables_from_with_explicit_excludes @dest.copy_instance_variables_from(@source, ['@baz']) assert !@dest.instance_variables.include?('@baz') assert_equal 'bar', @dest.instance_variable_get('@bar') end - + def test_copy_instance_variables_automatically_excludes_protected_instance_variables @source.instance_variable_set(:@quux, 'quux') class << @source @@ -131,23 +129,23 @@ class ObjectInstanceVariableTest < Test::Unit::TestCase ['@bar', :@quux] end end - + @dest.copy_instance_variables_from(@source) assert !@dest.instance_variables.include?('@bar') assert !@dest.instance_variables.include?('@quux') assert_equal 'baz', @dest.instance_variable_get('@baz') end - + def test_instance_values object = Object.new object.instance_variable_set :@a, 1 object.instance_variable_set :@b, 2 assert_equal({'a' => 1, 'b' => 2}, object.instance_values) end - + def test_instance_exec_passes_arguments_to_block block = Proc.new { |value| [self, value] } assert_equal %w(hello goodbye), 'hello'.instance_exec('goodbye', &block) end - + end diff --git a/activesupport/test/core_ext/pathname_test.rb b/activesupport/test/core_ext/pathname_test.rb index 3f49b665b2..2933e2d610 100644 --- a/activesupport/test/core_ext/pathname_test.rb +++ b/activesupport/test/core_ext/pathname_test.rb @@ -1,12 +1,9 @@ -require 'test/unit' -require File.dirname(__FILE__) + '/../../lib/active_support/core_ext/pathname' +require File.dirname(__FILE__) + '/../abstract_unit' class TestPathname < Test::Unit::TestCase - def test_clean_within assert_equal "Hi", Pathname.clean_within("Hi") assert_equal "Hi", Pathname.clean_within("Hi/a/b/../..") assert_equal "Hello\nWorld", Pathname.clean_within("Hello/a/b/../..\na/b/../../World/c/..") end - end diff --git a/activesupport/test/core_ext/proc_test.rb b/activesupport/test/core_ext/proc_test.rb index ca91a257b7..f63cd82d22 100644 --- a/activesupport/test/core_ext/proc_test.rb +++ b/activesupport/test/core_ext/proc_test.rb @@ -1,5 +1,4 @@ -require 'test/unit' -require File.dirname(__FILE__) + '/../../lib/active_support/core_ext/proc' +require File.dirname(__FILE__) + '/../abstract_unit' class ProcTests < Test::Unit::TestCase def test_bind_returns_method_with_changed_self @@ -9,4 +8,4 @@ class ProcTests < Test::Unit::TestCase assert_not_equal block, bound_block assert_equal "hello", bound_block.call end -end
\ No newline at end of file +end diff --git a/activesupport/test/core_ext/range_ext_test.rb b/activesupport/test/core_ext/range_ext_test.rb index 49cbb10be6..e8890ac835 100644 --- a/activesupport/test/core_ext/range_ext_test.rb +++ b/activesupport/test/core_ext/range_ext_test.rb @@ -1,7 +1,4 @@ -require 'test/unit' -require File.dirname(__FILE__) + '/../../lib/active_support/core_ext/date' -require File.dirname(__FILE__) + '/../../lib/active_support/core_ext/time' -require File.dirname(__FILE__) + '/../../lib/active_support/core_ext/range' +require File.dirname(__FILE__) + '/../abstract_unit' class RangeTest < Test::Unit::TestCase def test_to_s_from_dates diff --git a/activesupport/test/core_ext/string_ext_test.rb b/activesupport/test/core_ext/string_ext_test.rb index e09eb02188..c7c4d1a05f 100644 --- a/activesupport/test/core_ext/string_ext_test.rb +++ b/activesupport/test/core_ext/string_ext_test.rb @@ -1,7 +1,5 @@ -require 'test/unit' require 'date' -require File.dirname(__FILE__) + '/../../lib/active_support/core_ext/string' -require File.dirname(__FILE__) + '/../inflector_test' unless defined? InflectorTest +require File.dirname(__FILE__) + '/../abstract_unit' class StringInflectionsTest < Test::Unit::TestCase def test_pluralize @@ -28,7 +26,7 @@ class StringInflectionsTest < Test::Unit::TestCase InflectorTest::CamelToUnderscore.each do |camel, underscore| assert_equal(underscore, camel.underscore) end - + assert_equal "html_tidy", "HTMLTidy".underscore assert_equal "html_tidy_generator", "HTMLTidyGenerator".underscore end @@ -58,26 +56,26 @@ class StringInflectionsTest < Test::Unit::TestCase assert_equal(class_name, table_name.classify) end end - + def test_string_to_time assert_equal Time.utc(2005, 2, 27, 23, 50), "2005-02-27 23:50".to_time assert_equal Time.local(2005, 2, 27, 23, 50), "2005-02-27 23:50".to_time(:local) assert_equal Date.new(2005, 2, 27), "2005-02-27".to_date end - + def test_access s = "hello" assert_equal "h", s.at(0) - + assert_equal "llo", s.from(2) assert_equal "hel", s.to(2) - + assert_equal "h", s.first assert_equal "he", s.first(2) assert_equal "o", s.last assert_equal "llo", s.last(3) - + assert_equal 'x', 'x'.first assert_equal 'x', 'x'.first(4) @@ -86,14 +84,14 @@ class StringInflectionsTest < Test::Unit::TestCase end def test_starts_ends_with - s = "hello" - assert s.starts_with?('h') - assert s.starts_with?('hel') - assert !s.starts_with?('el') - - assert s.ends_with?('o') - assert s.ends_with?('lo') - assert !s.ends_with?('el') + s = "hello" + assert s.starts_with?('h') + assert s.starts_with?('hel') + assert !s.starts_with?('el') + + assert s.ends_with?('o') + assert s.ends_with?('lo') + assert !s.ends_with?('el') end def test_each_char_with_utf8_string_when_kcode_is_utf8 diff --git a/activesupport/test/core_ext/symbol_test.rb b/activesupport/test/core_ext/symbol_test.rb index b30bd0b985..943133496a 100644 --- a/activesupport/test/core_ext/symbol_test.rb +++ b/activesupport/test/core_ext/symbol_test.rb @@ -1,5 +1,4 @@ -require 'test/unit' -require File.dirname(__FILE__) + '/../../lib/active_support/core_ext/symbol' +require File.dirname(__FILE__) + '/../abstract_unit' class SymbolTests < Test::Unit::TestCase def test_to_proc diff --git a/activesupport/test/core_ext/time_ext_test.rb b/activesupport/test/core_ext/time_ext_test.rb index dee0a1f84e..ab76348967 100644 --- a/activesupport/test/core_ext/time_ext_test.rb +++ b/activesupport/test/core_ext/time_ext_test.rb @@ -1,6 +1,4 @@ -require 'test/unit' -require File.dirname(__FILE__) + '/../../lib/active_support/core_ext/numeric' -require File.dirname(__FILE__) + '/../../lib/active_support/core_ext/time' +require File.dirname(__FILE__) + '/../abstract_unit' class TimeExtCalculationsTest < Test::Unit::TestCase def test_seconds_since_midnight @@ -19,35 +17,35 @@ class TimeExtCalculationsTest < Test::Unit::TestCase assert_equal Time.local(2005,11,28), Time.local(2005,12,01,0,0,0).beginning_of_week #thursday assert_equal Time.local(2005,11,28), Time.local(2005,12,02,0,0,0).beginning_of_week #friday assert_equal Time.local(2005,11,28), Time.local(2005,12,03,0,0,0).beginning_of_week #saturday - assert_equal Time.local(2005,11,28), Time.local(2005,12,04,0,0,0).beginning_of_week #sunday + assert_equal Time.local(2005,11,28), Time.local(2005,12,04,0,0,0).beginning_of_week #sunday end - + def test_beginning_of_day assert_equal Time.local(2005,2,4,0,0,0), Time.local(2005,2,4,10,10,10).beginning_of_day end - + def test_beginning_of_month assert_equal Time.local(2005,2,1,0,0,0), Time.local(2005,2,22,10,10,10).beginning_of_month end - + def test_beginning_of_quarter assert_equal Time.local(2005,1,1,0,0,0), Time.local(2005,2,15,10,10,10).beginning_of_quarter assert_equal Time.local(2005,1,1,0,0,0), Time.local(2005,1,1,0,0,0).beginning_of_quarter assert_equal Time.local(2005,10,1,0,0,0), Time.local(2005,12,31,10,10,10).beginning_of_quarter assert_equal Time.local(2005,4,1,0,0,0), Time.local(2005,6,30,23,59,59).beginning_of_quarter end - + def test_end_of_month assert_equal Time.local(2005,3,31,0,0,0), Time.local(2005,3,20,10,10,10).end_of_month assert_equal Time.local(2005,2,28,0,0,0), Time.local(2005,2,20,10,10,10).end_of_month assert_equal Time.local(2005,4,30,0,0,0), Time.local(2005,4,20,10,10,10).end_of_month - + end - + def test_beginning_of_year assert_equal Time.local(2005,1,1,0,0,0), Time.local(2005,2,22,10,10,10).beginning_of_year end - + def test_months_ago assert_equal Time.local(2005,5,5,10), Time.local(2005,6,5,10,0,0).months_ago(1) assert_equal Time.local(2004,11,5,10), Time.local(2005,6,5,10,0,0).months_ago(7) @@ -65,31 +63,31 @@ class TimeExtCalculationsTest < Test::Unit::TestCase assert_equal Time.local(2006,6,5,10), Time.local(2005,6,5,10,0,0).months_since(12) assert_equal Time.local(2007,6,5,10), Time.local(2005,6,5,10,0,0).months_since(24) end - + def test_years_ago assert_equal Time.local(2004,6,5,10), Time.local(2005,6,5,10,0,0).years_ago(1) assert_equal Time.local(1998,6,5,10), Time.local(2005,6,5,10,0,0).years_ago(7) end - + def test_years_since assert_equal Time.local(2006,6,5,10), Time.local(2005,6,5,10,0,0).years_since(1) assert_equal Time.local(2012,6,5,10), Time.local(2005,6,5,10,0,0).years_since(7) # Failure because of size limitations of numeric? - # assert_equal Time.local(2182,6,5,10), Time.local(2005,6,5,10,0,0).years_since(177) + # assert_equal Time.local(2182,6,5,10), Time.local(2005,6,5,10,0,0).years_since(177) end def test_last_year assert_equal Time.local(2004,6,5,10), Time.local(2005,6,5,10,0,0).last_year end - + def test_ago assert_equal Time.local(2005,2,22,10,10,9), Time.local(2005,2,22,10,10,10).ago(1) assert_equal Time.local(2005,2,22,9,10,10), Time.local(2005,2,22,10,10,10).ago(3600) assert_equal Time.local(2005,2,20,10,10,10), Time.local(2005,2,22,10,10,10).ago(86400*2) assert_equal Time.local(2005,2,20,9,9,45), Time.local(2005,2,22,10,10,10).ago(86400*2 + 3600 + 25) - end - + end + def test_since assert_equal Time.local(2005,2,22,10,10,11), Time.local(2005,2,22,10,10,10).since(1) assert_equal Time.local(2005,2,22,11,10,10), Time.local(2005,2,22,10,10,10).since(3600) @@ -101,12 +99,12 @@ class TimeExtCalculationsTest < Test::Unit::TestCase assert_equal Time.local(2005,2,21,10,10,10), Time.local(2005,2,22,10,10,10).yesterday assert_equal Time.local(2005,2,28,10,10,10), Time.local(2005,3,2,10,10,10).yesterday.yesterday end - + def test_tomorrow assert_equal Time.local(2005,2,23,10,10,10), Time.local(2005,2,22,10,10,10).tomorrow assert_equal Time.local(2005,3,2,10,10,10), Time.local(2005,2,28,10,10,10).tomorrow.tomorrow end - + def test_change assert_equal Time.local(2006,2,22,15,15,10), Time.local(2005,2,22,15,15,10).change(:year => 2006) assert_equal Time.local(2005,6,22,15,15,10), Time.local(2005,2,22,15,15,10).change(:month => 6) @@ -120,7 +118,7 @@ class TimeExtCalculationsTest < Test::Unit::TestCase assert_equal Time.local(2005,1,2,11,22, 7, 0), Time.local(2005,1,2,11,22,33,44).change(:sec => 7) assert_equal Time.local(2005,1,2,11,22,33, 8), Time.local(2005,1,2,11,22,33,44).change(:usec => 8) end - + def test_utc_change assert_equal Time.utc(2006,2,22,15,15,10), Time.utc(2005,2,22,15,15,10).change(:year => 2006) assert_equal Time.utc(2005,6,22,15,15,10), Time.utc(2005,2,22,15,15,10).change(:month => 6) @@ -136,7 +134,7 @@ class TimeExtCalculationsTest < Test::Unit::TestCase assert_equal Time.local(2012,9,28,15,15,10), Time.local(2005,2,28,15,15,10).advance(:years => 7, :months => 7) assert_equal Time.local(2013,10,3,15,15,10), Time.local(2005,2,28,15,15,10).advance(:years => 7, :months => 19, :days => 5) end - + def test_utc_plus assert_equal Time.utc(2006,2,22,15,15,10), Time.utc(2005,2,22,15,15,10).advance(:years => 1) assert_equal Time.utc(2005,6,22,15,15,10), Time.utc(2005,2,22,15,15,10).advance(:months => 4) @@ -159,11 +157,11 @@ class TimeExtCalculationsTest < Test::Unit::TestCase time = Time.utc(2005, 2, 21, 17, 44, 30) assert_equal "Mon, 21 Feb 2005 17:44:30 +0000", time.to_s(:rfc822) end - + def test_to_date assert_equal Date.new(2005, 2, 21), Time.local(2005, 2, 21, 17, 44, 30).to_date end - + def test_to_time assert_equal Time.local(2005, 2, 21, 17, 44, 30), Time.local(2005, 2, 21, 17, 44, 30).to_time end @@ -202,7 +200,7 @@ class TimeExtCalculationsTest < Test::Unit::TestCase def test_last_month_on_31st assert_equal Time.local(2004, 2, 29), Time.local(2004, 3, 31).last_month end - + def test_xmlschema_is_available assert_nothing_raised { Time.now.xmlschema } end diff --git a/activesupport/test/dependencies_test.rb b/activesupport/test/dependencies_test.rb index f5651eddcc..397548973a 100644 --- a/activesupport/test/dependencies_test.rb +++ b/activesupport/test/dependencies_test.rb @@ -1,13 +1,11 @@ -require 'test/unit' -$LOAD_PATH.unshift File.dirname(__FILE__) + '/../lib/active_support/' -require 'core_ext/string' -require 'dependencies' +require File.dirname(__FILE__) + '/abstract_unit' +#require 'dependencies' class DependenciesTest < Test::Unit::TestCase def teardown Dependencies.clear end - + def with_loading(from_dir = nil) prior_path = $LOAD_PATH.clone $LOAD_PATH.unshift "#{File.dirname(__FILE__)}/#{from_dir}" if from_dir @@ -103,11 +101,11 @@ class DependenciesTest < Test::Unit::TestCase assert_equal 2, $mutual_dependencies_count end end - + def test_as_load_path assert_equal '', DependenciesTest.as_load_path end - + def test_module_loading with_loading 'autoloading_fixtures' do assert_kind_of Module, A @@ -116,7 +114,7 @@ class DependenciesTest < Test::Unit::TestCase assert_kind_of Class, A::C::E::F end end - + def test_non_existing_const_raises_name_error with_loading 'autoloading_fixtures' do assert_raises(NameError) { DoesNotExist } @@ -125,21 +123,21 @@ class DependenciesTest < Test::Unit::TestCase assert_raises(NameError) { A::B::DoesNotExist } end end - + def test_directories_should_manifest_as_modules with_loading 'autoloading_fixtures' do assert_kind_of Module, ModuleFolder Object.send :remove_const, :ModuleFolder end end - + def test_nested_class_access with_loading 'autoloading_fixtures' do assert_kind_of Class, ModuleFolder::NestedClass Object.send :remove_const, :ModuleFolder end end - + def test_nested_class_can_access_sibling with_loading 'autoloading_fixtures' do sibling = ModuleFolder::NestedClass.class_eval "NestedSibling" @@ -148,7 +146,7 @@ class DependenciesTest < Test::Unit::TestCase Object.send :remove_const, :ModuleFolder end end - + def failing_test_access_thru_and_upwards_fails with_loading 'autoloading_fixtures' do assert ! defined?(ModuleFolder) @@ -157,5 +155,4 @@ class DependenciesTest < Test::Unit::TestCase Object.send :remove_const, :ModuleFolder end end - end diff --git a/activesupport/test/inflector_test.rb b/activesupport/test/inflector_test.rb index e1676281ad..f8a665c1ed 100644 --- a/activesupport/test/inflector_test.rb +++ b/activesupport/test/inflector_test.rb @@ -1,5 +1,4 @@ -require 'test/unit' -require File.dirname(__FILE__) + '/../lib/active_support/inflector' unless defined? Inflector +require File.dirname(__FILE__) + '/abstract_unit' module Ace module Base @@ -63,14 +62,14 @@ class InflectorTest < Test::Unit::TestCase "old_news" => "old_news", "news" => "news", - + "series" => "series", "species" => "species", "quiz" => "quizzes", "perspective" => "perspectives", - + "ox" => "oxen", "photo" => "photos", "buffalo" => "buffaloes", @@ -79,7 +78,7 @@ class InflectorTest < Test::Unit::TestCase "elf" => "elves", "information" => "information", "equipment" => "equipment", - "bus" => "buses", + "bus" => "buses", "status" => "statuses", "status_code" => "status_codes", "mouse" => "mice", @@ -90,17 +89,17 @@ class InflectorTest < Test::Unit::TestCase "virus" => "viri", "alias" => "aliases", "portfolio" => "portfolios", - + "vertex" => "vertices", "matrix" => "matrices", - + "axis" => "axes", "testis" => "testes", "crisis" => "crises", - + "rice" => "rice", "shoe" => "shoes", - + "horse" => "horses", "prize" => "prizes", "edge" => "edges" @@ -117,16 +116,16 @@ class InflectorTest < Test::Unit::TestCase "product" => "product", "special_guest" => "specialGuest", "application_controller" => "applicationController", - "area51_controller" => "area51Controller" + "area51_controller" => "area51Controller" } - + CamelToUnderscoreWithoutReverse = { "HTMLTidy" => "html_tidy", "HTMLTidyGenerator" => "html_tidy_generator", "FreeBSD" => "free_bsd", "HTML" => "html", } - + CamelWithModuleToUnderscoreWithSlash = { "Admin::Product" => "admin/product", "Users::Commission::Department" => "users/commission/department", @@ -142,12 +141,12 @@ class InflectorTest < Test::Unit::TestCase "Person" => "personid", "MyApplication::Billing::Account" => "accountid" } - + ClassNameToTableName = { "PrimarySpokesman" => "primary_spokesmen", "NodeChild" => "node_children" } - + UnderscoreToHuman = { "employee_salary" => "Employee salary", "employee_id" => "Employee", @@ -194,7 +193,7 @@ class InflectorTest < Test::Unit::TestCase "1000" => "1000th", "1001" => "1001st" } - + UnderscoresToDashes = { "street" => "street", "street_address" => "street-address", @@ -246,7 +245,7 @@ class InflectorTest < Test::Unit::TestCase assert_equal(camel, Inflector.camelize(underscore)) end end - + def test_underscore_with_slashes CamelWithModuleToUnderscoreWithSlash.each do |camel, underscore| assert_equal(underscore, Inflector.underscore(camel)) @@ -284,13 +283,13 @@ class InflectorTest < Test::Unit::TestCase assert_equal 'FooBar', Inflector.classify(:foo_bar) end end - + def test_humanize UnderscoreToHuman.each do |underscore, human| assert_equal(human, Inflector.humanize(underscore)) end end - + def test_constantize assert_equal Ace::Base::Case, Inflector.constantize("Ace::Base::Case") assert_equal Ace::Base::Case, Inflector.constantize("::Ace::Base::Case") @@ -299,7 +298,7 @@ class InflectorTest < Test::Unit::TestCase assert_raises(NameError) { Inflector.constantize("UnknownClass") } assert_raises(NameError) { Inflector.constantize("An invalid string") } end - + def test_constantize_doesnt_look_in_parent assert_raises(NameError) { Inflector.constantize("Ace::Base::InflectorTest") } end diff --git a/activesupport/test/json.rb b/activesupport/test/json.rb index fc4d7705b1..d9c3cebf32 100644 --- a/activesupport/test/json.rb +++ b/activesupport/test/json.rb @@ -1,6 +1,4 @@ -$:.unshift File.dirname(__FILE__) + '/../lib' -require 'active_support' -require 'test/unit' +require File.dirname(__FILE__) + '/abstract_unit' class Foo def initialize(a, b) @@ -14,15 +12,15 @@ class TestJSONEmitters < Test::Unit::TestCase NilTests = [[ nil, %(null) ]] NumericTests = [[ 1, %(1) ], [ 2.5, %(2.5) ]] - + StringTests = [[ 'this is the string', %("this is the string") ], [ 'a "string" with quotes', %("a \\"string\\" with quotes") ]] - + ArrayTests = [[ ['a', 'b', 'c'], %([\"a\", \"b\", \"c\"]) ], [ [1, 'a', :b, nil, false], %([1, \"a\", \"b\", null, false]) ]] - + HashTests = [[ {:a => :b, :c => :d}, %({\"c\": \"d\", \"a\": \"b\"}) ]] - + SymbolTests = [[ :a, %("a") ], [ :this, %("this") ], [ :"a b", %("a b") ]] @@ -40,7 +38,7 @@ class TestJSONEmitters < Test::Unit::TestCase end end end - + def test_utf8_string_encoded_properly_when_kcode_is_utf8 old_kcode, $KCODE = $KCODE, 'UTF8' assert_equal '"\\u20ac2.99"', '€2.99'.to_json @@ -48,7 +46,7 @@ class TestJSONEmitters < Test::Unit::TestCase ensure $KCODE = old_kcode end - + def test_exception_raised_when_encoding_circular_reference a = [1] a << a diff --git a/activesupport/test/option_merger_test.rb b/activesupport/test/option_merger_test.rb index e97a4f918b..db32d4f6c1 100644 --- a/activesupport/test/option_merger_test.rb +++ b/activesupport/test/option_merger_test.rb @@ -1,25 +1,20 @@ -require 'test/unit' - -unless defined? ActiveSupport::OptionMerger - require File.dirname(__FILE__) + '/../lib/active_support/option_merger' - require File.dirname(__FILE__) + '/../lib/active_support/core_ext/object' -end +require File.dirname(__FILE__) + '/abstract_unit' class OptionMergerTest < Test::Unit::TestCase def setup @options = {:hello => 'world'} end - + def test_method_with_options_merges_options_when_options_are_present local_options = {:cool => true} - + with_options(@options) do |o| assert_equal local_options, method_with_options(local_options) - assert_equal @options.merge(local_options), + assert_equal @options.merge(local_options), o.method_with_options(local_options) end end - + def test_method_with_options_appends_options_when_options_are_missing with_options(@options) do |o| assert_equal Hash.new, method_with_options @@ -30,10 +25,10 @@ class OptionMergerTest < Test::Unit::TestCase def test_method_with_options_allows_to_overwrite_options local_options = {:hello => 'moon'} assert_equal @options.keys, local_options.keys - + with_options(@options) do |o| assert_equal local_options, method_with_options(local_options) - assert_equal @options.merge(local_options), + assert_equal @options.merge(local_options), o.method_with_options(local_options) assert_equal local_options, o.method_with_options(local_options) end diff --git a/activesupport/test/ordered_options_test.rb b/activesupport/test/ordered_options_test.rb index 05bd5ef932..903c730ce4 100644 --- a/activesupport/test/ordered_options_test.rb +++ b/activesupport/test/ordered_options_test.rb @@ -1,6 +1,4 @@ -require 'test/unit' - -require File.dirname(__FILE__) + '/../lib/active_support/ordered_options' +require File.dirname(__FILE__) + '/abstract_unit' class OrderedHashTest < Test::Unit::TestCase def setup @@ -8,19 +6,19 @@ class OrderedHashTest < Test::Unit::TestCase @values = %w( 000099 009900 aa0000 cc0066 cc6633 ) @ordered_hash = ActiveSupport::OrderedHash.new(@keys.zip(@values)) end - + def test_order assert_equal @keys, @ordered_hash.keys assert_equal @values, @ordered_hash.values end - + def test_access assert @keys.zip(@values).all? { |k, v| @ordered_hash[k] == v } end - + def test_assignment key, value = 'purple', '5422a8' - + @ordered_hash[key] = value assert_equal @keys.length + 1, @ordered_hash.length assert_equal key, @ordered_hash.keys.last @@ -35,7 +33,7 @@ class OrderedOptionsTest < Test::Unit::TestCase assert_nil a[:not_set] - a[:allow_concurreny] = true + a[:allow_concurreny] = true assert_equal 1, a.size assert a[:allow_concurreny] @@ -47,27 +45,27 @@ class OrderedOptionsTest < Test::Unit::TestCase assert_equal 2, a.size assert_equal 56, a[:else_where] end - + def test_looping a = OrderedOptions.new - a[:allow_concurreny] = true + a[:allow_concurreny] = true a["else_where"] = 56 - + test = [[:allow_concurreny, true], [:else_where, 56]] - + a.each_with_index do |(key, value), index| assert_equal test[index].first, key assert_equal test[index].last, value end end - + def test_method_access a = OrderedOptions.new assert_nil a.not_set - a.allow_concurreny = true + a.allow_concurreny = true assert_equal 1, a.size assert a.allow_concurreny diff --git a/activesupport/test/reloadable_test.rb b/activesupport/test/reloadable_test.rb index 1b147e0d18..c330394b29 100644 --- a/activesupport/test/reloadable_test.rb +++ b/activesupport/test/reloadable_test.rb @@ -1,10 +1,7 @@ -require 'test/unit' -require File.dirname(__FILE__) + '/../lib/active_support/core_ext/class' -require File.dirname(__FILE__) + '/../lib/active_support/core_ext/module' -require File.dirname(__FILE__) + '/../lib/active_support/reloadable' +require File.dirname(__FILE__) + '/abstract_unit' module ReloadableTestSandbox - + class AReloadableClass include Reloadable end @@ -24,17 +21,17 @@ module ReloadableTestSandbox end include Reloadable end - + class SubclassesReloadable include Reloadable::Subclasses end class ASubclassOfSubclassesReloadable < SubclassesReloadable end - + class AnOnlySubclassReloadableClassSubclassingAReloadableClass include Reloadable::Subclasses end - + class ASubclassofAOnlySubclassReloadableClassWhichWasSubclassingAReloadableClass < AnOnlySubclassReloadableClassSubclassingAReloadableClass end end @@ -49,17 +46,17 @@ class ReloadableTest < Test::Unit::TestCase def test_reloadable_is_not_overwritten_if_present assert_equal 10, ReloadableTestSandbox::AClassWhichDefinesItsOwnReloadable.reloadable? end - + def test_only_subclass_reloadable assert ! ReloadableTestSandbox::SubclassesReloadable.reloadable? assert ReloadableTestSandbox::ASubclassOfSubclassesReloadable.reloadable? end - + def test_inside_hierarchy_only_subclass_reloadable assert ! ReloadableTestSandbox::AnOnlySubclassReloadableClassSubclassingAReloadableClass.reloadable? assert ReloadableTestSandbox::ASubclassofAOnlySubclassReloadableClassWhichWasSubclassingAReloadableClass.reloadable? end - + def test_removable_classes reloadables = %w( AReloadableClass @@ -72,7 +69,7 @@ class ReloadableTest < Test::Unit::TestCase ANonReloadableSubclass SubclassesReloadable ) - + results = Reloadable.reloadable_classes reloadables.each do |name| assert results.include?(ReloadableTestSandbox.const_get(name)), "Expected #{name} to be reloadable" @@ -81,4 +78,4 @@ class ReloadableTest < Test::Unit::TestCase assert ! results.include?(ReloadableTestSandbox.const_get(name)), "Expected #{name} NOT to be reloadable" end end -end
\ No newline at end of file +end diff --git a/activesupport/test/time_zone_test.rb b/activesupport/test/time_zone_test.rb index 3e35c327e0..3cdf5582bf 100644 --- a/activesupport/test/time_zone_test.rb +++ b/activesupport/test/time_zone_test.rb @@ -1,5 +1,4 @@ -require 'test/unit' -require File.dirname(__FILE__)+'/../lib/active_support/values/time_zone' +require File.dirname(__FILE__) + '/abstract_unit' class TimeZoneTest < Test::Unit::TestCase class MockTime diff --git a/activesupport/test/whiny_nil_test.rb b/activesupport/test/whiny_nil_test.rb index 9ed31bfef5..4483134be1 100644 --- a/activesupport/test/whiny_nil_test.rb +++ b/activesupport/test/whiny_nil_test.rb @@ -1,6 +1,4 @@ -require 'test/unit' - -# mock to enable testing without activerecord +# Stub to enable testing without Active Record module ActiveRecord class Base def save! @@ -8,8 +6,8 @@ module ActiveRecord end end -require File.dirname(__FILE__) + '/../lib/active_support/inflector' -require File.dirname(__FILE__) + '/../lib/active_support/whiny_nil' +require File.dirname(__FILE__) + '/abstract_unit' +require 'active_support/whiny_nil' class WhinyNilTest < Test::Unit::TestCase def test_unchanged @@ -17,14 +15,14 @@ class WhinyNilTest < Test::Unit::TestCase rescue NoMethodError => nme assert_match(/nil.method_thats_not_in_whiners/, nme.message) end - + def test_active_record nil.save! rescue NoMethodError => nme assert(!(nme.message =~ /nil:NilClass/)) assert_match(/nil\.save!/, nme.message) end - + def test_array nil.each rescue NoMethodError => nme |