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/core_ext | |
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/core_ext')
20 files changed, 108 insertions, 138 deletions
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 |