diff options
Diffstat (limited to 'activesupport/test')
22 files changed, 84 insertions, 130 deletions
diff --git a/activesupport/test/abstract_unit.rb b/activesupport/test/abstract_unit.rb index f390c66838..dda139372e 100644 --- a/activesupport/test/abstract_unit.rb +++ b/activesupport/test/abstract_unit.rb @@ -1,22 +1,15 @@ ORIG_ARGV = ARGV.dup -root = File.expand_path('../../..', __FILE__) + begin - require "#{root}/vendor/gems/environment" + require File.expand_path('../../../vendor/gems/environment', __FILE__) rescue LoadError - $:.unshift("#{root}/activesupport/lib") - $:.unshift("#{root}/activerecord/lib") end +lib = File.expand_path("#{File.dirname(__FILE__)}/../lib") +$:.unshift(lib) unless $:.include?('lib') || $:.include?(lib) require 'test/unit' - -begin - require 'mocha' -rescue LoadError - $stderr.puts 'Loading rubygems' - require 'rubygems' - require 'mocha' -end +require 'mocha' ENV['NO_RELOAD'] = '1' require 'active_support' diff --git a/activesupport/test/caching_test.rb b/activesupport/test/caching_test.rb index 6a51ce9402..00e05f76fe 100644 --- a/activesupport/test/caching_test.rb +++ b/activesupport/test/caching_test.rb @@ -30,7 +30,9 @@ class CacheStoreSettingTest < ActiveSupport::TestCase def test_mem_cache_fragment_cache_store_with_given_mem_cache_like_object MemCache.expects(:new).never - store = ActiveSupport::Cache.lookup_store :mem_cache_store, stub("memcache", :get => true) + memcache = Object.new + def memcache.get() true end + store = ActiveSupport::Cache.lookup_store :mem_cache_store, memcache assert_kind_of(ActiveSupport::Cache::MemCacheStore, store) end diff --git a/activesupport/test/core_ext/array_ext_test.rb b/activesupport/test/core_ext/array_ext_test.rb index 8198b9bd2c..f5f91ddd80 100644 --- a/activesupport/test/core_ext/array_ext_test.rb +++ b/activesupport/test/core_ext/array_ext_test.rb @@ -339,6 +339,11 @@ class ArrayWrapperTests < Test::Unit::TestCase end end + class Proxy + def initialize(target) @target = target end + def method_missing(*a) @target.send(*a) end + end + def test_array ary = %w(foo bar) assert_same ary, Array.wrap(ary) @@ -364,4 +369,19 @@ class ArrayWrapperTests < Test::Unit::TestCase def test_object_with_to_ary assert_equal ["foo", "bar"], Array.wrap(FakeCollection.new) end + + def test_proxy_object + p = Proxy.new(Object.new) + assert_equal [p], Array.wrap(p) + end + + def test_proxy_to_object_with_to_ary + p = Proxy.new(FakeCollection.new) + assert_equal [p], Array.wrap(p) + end + + def test_struct + o = Struct.new(:foo).new(123) + assert_equal [o], Array.wrap(o) + end end diff --git a/activesupport/test/core_ext/date_ext_test.rb b/activesupport/test/core_ext/date_ext_test.rb index 18422d68bc..23c9bc7fb1 100644 --- a/activesupport/test/core_ext/date_ext_test.rb +++ b/activesupport/test/core_ext/date_ext_test.rb @@ -1,5 +1,5 @@ require 'abstract_unit' -require 'active_support/core_ext/date' +require 'active_support/time' class DateExtCalculationsTest < Test::Unit::TestCase def test_to_s diff --git a/activesupport/test/core_ext/date_time_ext_test.rb b/activesupport/test/core_ext/date_time_ext_test.rb index a7b179b2be..4341ead488 100644 --- a/activesupport/test/core_ext/date_time_ext_test.rb +++ b/activesupport/test/core_ext/date_time_ext_test.rb @@ -1,5 +1,5 @@ require 'abstract_unit' -require 'active_support/core_ext/date_time' +require 'active_support/time' class DateTimeExtCalculationsTest < Test::Unit::TestCase def test_to_s diff --git a/activesupport/test/core_ext/enumerable_test.rb b/activesupport/test/core_ext/enumerable_test.rb index 4170de3dce..66f5f9fbde 100644 --- a/activesupport/test/core_ext/enumerable_test.rb +++ b/activesupport/test/core_ext/enumerable_test.rb @@ -1,6 +1,5 @@ require 'abstract_unit' require 'active_support/core_ext/array' -require 'active_support/core_ext/symbol' require 'active_support/core_ext/enumerable' Payment = Struct.new(:price) @@ -90,15 +89,4 @@ class EnumerableTests < Test::Unit::TestCase assert ![ 1, 2 ].many? {|x| x > 1 } assert [ 1, 2, 2 ].many? {|x| x > 1 } end - - def test_none - assert [].none? - assert [nil, false].none? - assert ![1].none? - - assert [].none? {|x| x > 1 } - assert ![ 2 ].none? {|x| x > 1 } - assert ![ 1, 2 ].none? {|x| x > 1 } - assert [ 1, 1 ].none? {|x| x > 1 } - end end diff --git a/activesupport/test/core_ext/integer_ext_test.rb b/activesupport/test/core_ext/integer_ext_test.rb index 956ae5189d..e1591089f5 100644 --- a/activesupport/test/core_ext/integer_ext_test.rb +++ b/activesupport/test/core_ext/integer_ext_test.rb @@ -2,22 +2,6 @@ require 'abstract_unit' require 'active_support/core_ext/integer' 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? - assert !22953686867719691230002707821868552601124472329080.odd? - end - - def test_odd - assert ![ -2, 0, 2, 4 ].all? { |i| i.odd? } - 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/name_error_test.rb b/activesupport/test/core_ext/name_error_test.rb index 10913e2ade..6352484d04 100644 --- a/activesupport/test/core_ext/name_error_test.rb +++ b/activesupport/test/core_ext/name_error_test.rb @@ -3,23 +3,19 @@ require 'active_support/core_ext/name_error' class NameErrorTest < Test::Unit::TestCase def test_name_error_should_set_missing_name - begin - SomeNameThatNobodyWillUse____Really ? 1 : 0 - flunk "?!?!" - rescue NameError => exc - assert_equal "NameErrorTest::SomeNameThatNobodyWillUse____Really", exc.missing_name - assert exc.missing_name?(:SomeNameThatNobodyWillUse____Really) - assert exc.missing_name?("NameErrorTest::SomeNameThatNobodyWillUse____Really") - end + SomeNameThatNobodyWillUse____Really ? 1 : 0 + flunk "?!?!" + rescue NameError => exc + assert_equal "NameErrorTest::SomeNameThatNobodyWillUse____Really", exc.missing_name + assert exc.missing_name?(:SomeNameThatNobodyWillUse____Really) + assert exc.missing_name?("NameErrorTest::SomeNameThatNobodyWillUse____Really") end def test_missing_method_should_ignore_missing_name - begin - some_method_that_does_not_exist - flunk "?!?!" - rescue NameError => exc - assert_equal nil, exc.missing_name - assert ! exc.missing_name?(:Foo) - end + some_method_that_does_not_exist + flunk "?!?!" + rescue NameError => exc + assert !exc.missing_name?(:Foo) + assert_nil exc.missing_name end end 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 f0121b862d..e6fbdb637b 100644 --- a/activesupport/test/core_ext/object_and_class_ext_test.rb +++ b/activesupport/test/core_ext/object_and_class_ext_test.rb @@ -182,13 +182,6 @@ class ObjectInstanceVariableTest < Test::Unit::TestCase assert_equal %w(@bar @baz), @source.instance_variable_names.sort end - def test_instance_variable_defined - assert @source.instance_variable_defined?('@bar') - assert @source.instance_variable_defined?(:@bar) - assert !@source.instance_variable_defined?(:@foo) - assert !@source.instance_variable_defined?('@foo') - end - def test_copy_instance_variables_from_without_explicit_excludes assert_equal [], @dest.instance_variables @dest.copy_instance_variables_from(@source) diff --git a/activesupport/test/core_ext/object_ext_test.rb b/activesupport/test/core_ext/object_ext_test.rb deleted file mode 100644 index 04c19ed2aa..0000000000 --- a/activesupport/test/core_ext/object_ext_test.rb +++ /dev/null @@ -1,9 +0,0 @@ -require 'abstract_unit' -require 'active_support/core_ext/object/metaclass' - -class ObjectExtTest < Test::Unit::TestCase - def test_tap_yields_and_returns_self - foo = Object.new - assert_equal foo, foo.tap { |x| assert_equal foo, x; :bar } - end -end diff --git a/activesupport/test/core_ext/range_ext_test.rb b/activesupport/test/core_ext/range_ext_test.rb index 2565c56b8a..5701eeef28 100644 --- a/activesupport/test/core_ext/range_ext_test.rb +++ b/activesupport/test/core_ext/range_ext_test.rb @@ -1,6 +1,6 @@ require 'abstract_unit' +require 'active_support/time' require 'active_support/core_ext/range' -require 'active_support/core_ext/date/conversions' 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 584a41b631..56ed296dac 100644 --- a/activesupport/test/core_ext/string_ext_test.rb +++ b/activesupport/test/core_ext/string_ext_test.rb @@ -4,7 +4,8 @@ require 'abstract_unit' require 'inflector_test_cases' require 'active_support/core_ext/string' -require 'active_support/core_ext/time' +require 'active_support/time' +require 'active_support/core_ext/kernel/reporting' class StringInflectionsTest < Test::Unit::TestCase include InflectorTestCases @@ -185,17 +186,9 @@ class StringInflectionsTest < Test::Unit::TestCase assert s.starts_with?('hel') assert !s.starts_with?('el') - assert s.start_with?('h') - assert s.start_with?('hel') - assert !s.start_with?('el') - assert s.ends_with?('o') assert s.ends_with?('lo') assert !s.ends_with?('el') - - assert s.end_with?('o') - assert s.end_with?('lo') - assert !s.end_with?('el') end def test_string_squish @@ -214,17 +207,6 @@ class StringInflectionsTest < Test::Unit::TestCase # And changes the original string: assert_equal original, expected end - - if RUBY_VERSION < '1.9' - def test_each_char_with_utf8_string_when_kcode_is_utf8 - with_kcode('UTF8') do - '€2.99'.each_char do |char| - assert_not_equal 1, char.length - break - end - end - end - end end class StringBehaviourTest < Test::Unit::TestCase @@ -350,13 +332,6 @@ class TestGetTextString < Test::Unit::TestCase end end -class StringBytesizeTest < Test::Unit::TestCase - def test_bytesize - assert_respond_to 'foo', :bytesize - assert_equal 3, 'foo'.bytesize - end -end - class OutputSafetyTest < ActiveSupport::TestCase def setup @string = "hello" diff --git a/activesupport/test/core_ext/symbol_test.rb b/activesupport/test/core_ext/symbol_test.rb deleted file mode 100644 index 1eaccb9965..0000000000 --- a/activesupport/test/core_ext/symbol_test.rb +++ /dev/null @@ -1,9 +0,0 @@ -require 'abstract_unit' - -class SymbolTests < Test::Unit::TestCase - def test_to_proc - assert_equal %w(one two three), [:one, :two, :three].map(&:to_s) - assert_equal(%w(one two three), - {1 => "one", 2 => "two", 3 => "three"}.sort_by(&:first).map(&:last)) - end -end diff --git a/activesupport/test/dependencies_test.rb b/activesupport/test/dependencies_test.rb index 97d70cf8c4..0fcf1eaf00 100644 --- a/activesupport/test/dependencies_test.rb +++ b/activesupport/test/dependencies_test.rb @@ -3,7 +3,6 @@ require 'pp' require 'active_support/dependencies' require 'active_support/core_ext/module/loading' require 'active_support/core_ext/kernel/reporting' -require 'active_support/core_ext/symbol/to_proc' module ModuleWithMissing mattr_accessor :missing_count diff --git a/activesupport/test/i18n_test.rb b/activesupport/test/i18n_test.rb index 9868f1e87d..dfcd4f822d 100644 --- a/activesupport/test/i18n_test.rb +++ b/activesupport/test/i18n_test.rb @@ -9,8 +9,8 @@ class I18nTest < Test::Unit::TestCase end def test_time_zone_localization_with_default_format - Time.zone.stubs(:now).returns Time.local(2000) - assert_equal Time.zone.now.strftime("%a, %d %b %Y %H:%M:%S %z"), I18n.localize(Time.zone.now) + now = Time.local(2000) + assert_equal now.strftime("%a, %d %b %Y %H:%M:%S %z"), I18n.localize(now) end def test_date_localization_should_use_default_format diff --git a/activesupport/test/json/decoding_test.rb b/activesupport/test/json/decoding_test.rb index 7b5a4d0416..8fcb16abfb 100644 --- a/activesupport/test/json/decoding_test.rb +++ b/activesupport/test/json/decoding_test.rb @@ -1,6 +1,7 @@ # encoding: UTF-8 require 'abstract_unit' require 'active_support/json' +require 'active_support/time' require 'active_support/core_ext/kernel/reporting' class TestJSONDecoding < ActiveSupport::TestCase diff --git a/activesupport/test/message_encryptor_test.rb b/activesupport/test/message_encryptor_test.rb index ed3461571a..5c2b44f188 100644 --- a/activesupport/test/message_encryptor_test.rb +++ b/activesupport/test/message_encryptor_test.rb @@ -1,4 +1,5 @@ require 'abstract_unit' +require 'active_support/time' class MessageEncryptorTest < Test::Unit::TestCase def setup diff --git a/activesupport/test/message_verifier_test.rb b/activesupport/test/message_verifier_test.rb index ef300e4e26..714a3b3a39 100644 --- a/activesupport/test/message_verifier_test.rb +++ b/activesupport/test/message_verifier_test.rb @@ -7,6 +7,8 @@ rescue LoadError, NameError $stderr.puts "Skipping MessageVerifier test: broken OpenSSL install" else +require 'active_support/time' + class MessageVerifierTest < Test::Unit::TestCase def setup @verifier = ActiveSupport::MessageVerifier.new("Hey, I'm a secret!") diff --git a/activesupport/test/multibyte_chars_test.rb b/activesupport/test/multibyte_chars_test.rb index 4ff74abf61..0e489c10e1 100644 --- a/activesupport/test/multibyte_chars_test.rb +++ b/activesupport/test/multibyte_chars_test.rb @@ -228,10 +228,10 @@ class MultibyteCharsUTF8BehaviourTest < Test::Unit::TestCase assert !@chars.include?('a') end - def test_include_raises_type_error_when_nil_is_passed - assert_raise(TypeError) do - @chars.include?(nil) - end + def test_include_raises_when_nil_is_passed + @chars.include?(nil) + flunk "Expected chars.include?(nil) to raise TypeError or NoMethodError" + rescue Exception => e end def test_index_should_return_character_offset @@ -659,4 +659,4 @@ class MultibyteInternalsTest < ActiveSupport::TestCase "Expected byte offset #{byte_offset} to translate to #{character_offset}" end end -end
\ No newline at end of file +end diff --git a/activesupport/test/multibyte_utils_test.rb b/activesupport/test/multibyte_utils_test.rb index 0a2f20d282..1dff944922 100644 --- a/activesupport/test/multibyte_utils_test.rb +++ b/activesupport/test/multibyte_utils_test.rb @@ -2,6 +2,7 @@ require 'abstract_unit' require 'multibyte_test_helpers' +require 'active_support/core_ext/kernel/reporting' class MultibyteUtilsTest < ActiveSupport::TestCase include MultibyteTestHelpers diff --git a/activesupport/test/notifications_test.rb b/activesupport/test/notifications_test.rb index 9175c8f26e..01106e83e9 100644 --- a/activesupport/test/notifications_test.rb +++ b/activesupport/test/notifications_test.rb @@ -75,7 +75,7 @@ class NotificationsMainTest < Test::Unit::TestCase 1 + 1 end - sleep(0.1) + drain assert_equal 1, @events.size assert_equal :awesome, @events.last.name @@ -88,19 +88,18 @@ class NotificationsMainTest < Test::Unit::TestCase 1 + 1 end - sleep(0.1) + drain assert_equal 1, @events.size assert_equal :wot, @events.first.name assert_equal Hash[:payload => "child"], @events.first.payload end - sleep(0.1) + drain assert_equal 2, @events.size assert_equal :awesome, @events.last.name assert_equal Hash[:payload => "notifications"], @events.last.payload - assert_in_delta 100, @events.last.duration, 70 end def test_event_is_pushed_even_if_block_fails @@ -108,7 +107,7 @@ class NotificationsMainTest < Test::Unit::TestCase raise "OMG" end rescue RuntimeError - sleep(0.1) + drain assert_equal 1, @events.size assert_equal :awesome, @events.last.name @@ -117,7 +116,7 @@ class NotificationsMainTest < Test::Unit::TestCase def test_event_is_pushed_even_without_block ActiveSupport::Notifications.instrument(:awesome, :payload => "notifications") - sleep(0.1) + drain assert_equal 1, @events.size assert_equal :awesome, @events.last.name @@ -137,8 +136,9 @@ class NotificationsMainTest < Test::Unit::TestCase end ActiveSupport::Notifications.instrument(:cache){ 1 } - sleep 0.1 + drain + assert_equal 3, @another.size before, during, after = @another.map {|e| e.transaction_id } assert_equal before, after assert_not_equal before, during @@ -153,7 +153,7 @@ class NotificationsMainTest < Test::Unit::TestCase ActiveSupport::Notifications.instrument(:cache){ 1 } - sleep(0.1) + drain assert_equal 1, @another.size assert_equal :cache, @another.first.name @@ -169,7 +169,7 @@ class NotificationsMainTest < Test::Unit::TestCase ActiveSupport::Notifications.instrument(:something){ 0 } ActiveSupport::Notifications.instrument(:cache){ 1 } - sleep(0.1) + drain assert_equal 1, @another.size assert_equal :cache, @another.first.name @@ -186,7 +186,7 @@ class NotificationsMainTest < Test::Unit::TestCase ActiveSupport::Notifications.instrument(:value){ i } end - sleep 0.1 + drain assert_equal 100, @events.size assert_equal :value, @events.first.name @@ -198,4 +198,9 @@ class NotificationsMainTest < Test::Unit::TestCase assert_equal 1, @another.first.result assert_equal 100, @another.last.result end + + private + def drain + sleep(0.1) until ActiveSupport::Notifications.queue.drained? + end end diff --git a/activesupport/test/whiny_nil_test.rb b/activesupport/test/whiny_nil_test.rb index 4cb22c41b2..009d97940f 100644 --- a/activesupport/test/whiny_nil_test.rb +++ b/activesupport/test/whiny_nil_test.rb @@ -13,7 +13,7 @@ class WhinyNilTest < Test::Unit::TestCase def test_unchanged nil.method_thats_not_in_whiners rescue NoMethodError => nme - assert_match(/nil.method_thats_not_in_whiners/, nme.message) + assert(nme.message =~ /nil:NilClass/) end def test_active_record @@ -35,4 +35,16 @@ class WhinyNilTest < Test::Unit::TestCase rescue RuntimeError => nme assert(!(nme.message =~ /nil:NilClass/)) end + + def test_no_to_ary_coercion + nil.to_ary + rescue NoMethodError => nme + assert(nme.message =~ /nil:NilClass/) + end + + def test_no_to_str_coercion + nil.to_str + rescue NoMethodError => nme + assert(nme.message =~ /nil:NilClass/) + end end |