diff options
author | Jeremy Kemper <jeremy@bitsweat.net> | 2007-09-14 00:34:43 +0000 |
---|---|---|
committer | Jeremy Kemper <jeremy@bitsweat.net> | 2007-09-14 00:34:43 +0000 |
commit | 041b9b8a1c1661f90e8e586fddce981bfdb17f11 (patch) | |
tree | ef4778f501ee2a64b47d3eb2cc60236e8266e94d /activesupport/test | |
parent | e6941149abbee39dbbe9898b0dc45e95046f7a70 (diff) | |
download | rails-041b9b8a1c1661f90e8e586fddce981bfdb17f11.tar.gz rails-041b9b8a1c1661f90e8e586fddce981bfdb17f11.tar.bz2 rails-041b9b8a1c1661f90e8e586fddce981bfdb17f11.zip |
Some 1.9 forward compatibility
git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@7474 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
Diffstat (limited to 'activesupport/test')
-rw-r--r-- | activesupport/test/core_ext/array_ext_test.rb | 8 | ||||
-rw-r--r-- | activesupport/test/core_ext/enumerable_test.rb | 10 | ||||
-rw-r--r-- | activesupport/test/core_ext/file_test.rb | 6 |
3 files changed, 13 insertions, 11 deletions
diff --git a/activesupport/test/core_ext/array_ext_test.rb b/activesupport/test/core_ext/array_ext_test.rb index 6552ffcbd8..8c2edfc457 100644 --- a/activesupport/test/core_ext/array_ext_test.rb +++ b/activesupport/test/core_ext/array_ext_test.rb @@ -179,15 +179,15 @@ class ArrayToXmlTests < Test::Unit::TestCase assert_match(/^<\?xml [^>]*/, xml) assert_equal 0, xml.rindex(/<\?xml /) end - + def test_to_xml_with_block xml = [ { :name => "David", :age => 26, :age_in_millis => 820497600000 }, { :name => "Jason", :age => 31, :age_in_millis => BigDecimal.new('1.0') } - ].to_xml(:skip_instruct => true, :indent => 0) do |xml| - xml.count 2 + ].to_xml(:skip_instruct => true, :indent => 0) do |builder| + builder.count 2 end - + assert xml.include?(%(<count>2</count>)), xml end end diff --git a/activesupport/test/core_ext/enumerable_test.rb b/activesupport/test/core_ext/enumerable_test.rb index 0590846b7b..55fdcf32ce 100644 --- a/activesupport/test/core_ext/enumerable_test.rb +++ b/activesupport/test/core_ext/enumerable_test.rb @@ -8,8 +8,7 @@ end class EnumerableTests < Test::Unit::TestCase def test_group_by names = %w(marcel sam david jeremy) - klass = Class.new - klass.send(:attr_accessor, :name) + klass = Struct.new(:name) objects = (1..50).inject([]) do |people,| p = klass.new p.name = names.sort_by { rand }.first @@ -38,10 +37,13 @@ class EnumerableTests < Test::Unit::TestCase end def test_nil_sums - assert_raise(TypeError) { [5, 15, nil].sum } + expected_raise = RUBY_VERSION < '1.9.0' ? TypeError : NoMethodError + + assert_raise(expected_raise) { [5, 15, nil].sum } payments = [ Payment.new(5), Payment.new(15), Payment.new(10), Payment.new(nil) ] - assert_raise(TypeError) { payments.sum(&:price) } + assert_raise(expected_raise) { payments.sum(&:price) } + assert_equal 60, payments.sum { |p| p.price.to_i * 2 } end diff --git a/activesupport/test/core_ext/file_test.rb b/activesupport/test/core_ext/file_test.rb index 77930cd3e9..1102538876 100644 --- a/activesupport/test/core_ext/file_test.rb +++ b/activesupport/test/core_ext/file_test.rb @@ -6,9 +6,9 @@ class AtomicWriteTest < Test::Unit::TestCase contents = "Atomic Text" File.atomic_write(file_name, Dir.pwd) do |file| file.write(contents) - assert !File.exists?(file_name) + assert !File.exist?(file_name) end - assert File.exists?(file_name) + assert File.exist?(file_name) assert_equal contents, File.read(file_name) ensure File.unlink(file_name) rescue nil @@ -20,7 +20,7 @@ class AtomicWriteTest < Test::Unit::TestCase raise "something bad" end rescue - assert !File.exists?(file_name) + assert !File.exist?(file_name) end def file_name |