From 456ba712fe921f2387611055b67090d70dfad071 Mon Sep 17 00:00:00 2001 From: kou Date: Fri, 25 Nov 2005 03:43:48 +0000 Subject: * lib/rss/rss.rb: improved type conversion. * lib/rss/1.0.rb: ditto. * lib/rss/0.9.rb: ditto. * lib/rss/2.0.rb: ditto. * lib/rss/image.rb: ditto. * lib/rss/syndication.rb: ditto. * test/rss/test_2.0.rb: added type conversion tests. * test/rss/test_accessor.rb: ditto. * test/rss/test_to_s.rb: ditto. * test/rss/test_syndication.rb: ditto. * test/rss/test_setup_maker_2.0.rb: ditto. * test/rss/test_setup_maker_1.0.rb: ditto. * test/rss/test_setup_maker_0.9.rb: ditto. * test/rss/test_maker_sy.rb: ditto. * test/rss/test_maker_image.rb: ditto. * test/rss/test_maker_2.0.rb: ditto. * test/rss/test_maker_0.9.rb: ditto. * test/rss/test_image.rb: ditto. * test/rss/test_maker_1.0.rb: use assert instead of assert_equal. * test/rss/rss-assertions.rb: improved type conversion assertions. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@9610 b2dd03c8-39d4-4d8f-98ff-823fe69b080e --- test/rss/rss-assertions.rb | 42 ++++++++++++++++++++++++++++++++---------- 1 file changed, 32 insertions(+), 10 deletions(-) (limited to 'test/rss/rss-assertions.rb') diff --git a/test/rss/rss-assertions.rb b/test/rss/rss-assertions.rb index cb757a9ae4..f90eb7f3f2 100644 --- a/test/rss/rss-assertions.rb +++ b/test/rss/rss-assertions.rb @@ -83,7 +83,7 @@ module RSS end end - def assert_not_available_value(tag, value) + def assert_not_available_value(tag, value, attribute=nil) _wrap_assertion do begin yield @@ -91,6 +91,7 @@ module RSS rescue ::RSS::NotAvailableValueError => e assert_equal(tag, e.tag) assert_equal(value, e.value) + assert_equal(attribute, e.attribute) end end end @@ -256,14 +257,16 @@ module RSS _wrap_assertion do hours = skipHours.hours contents.each_with_index do |content, i| - assert_equal(content, hours[i].content) + assert_equal(content.to_i, hours[i].content) end end end def assert_image09(attrs, image) _wrap_assertion do - names = %w(url link title description width height) + names = %w(url link title description) + names << ["width", :integer] + names << ["height", :integer] assert_attributes(attrs, names, image) end end @@ -291,7 +294,8 @@ module RSS names = %w(title link description language copyright managingEditor webMaster pubDate - lastBuildDate generator docs ttl rating) + lastBuildDate generator docs rating) + names << ["ttl", :integer] assert_attributes(attrs, names, channel) %w(cloud categories skipHours skipDays).each do |name| @@ -314,7 +318,8 @@ module RSS def assert_channel20_cloud(attrs, cloud) _wrap_assertion do - names = %w(domain port path registerProcedure protocol) + names = %w(domain path registerProcedure protocol) + names << ["port", :integer] assert_attributes(attrs, names, cloud) end end @@ -330,7 +335,9 @@ module RSS def assert_image20(attrs, image) _wrap_assertion do - names = %w(url link title description width height) + names = %w(url link title description) + names << ["width", :integer] + names << ["height", :integer] assert_attributes(attrs, names, image) end end @@ -362,7 +369,7 @@ module RSS def assert_items20_enclosure(attrs, enclosure) _wrap_assertion do - names = %w(url length type) + names = ["url", ["length", :integer], "type"] assert_attributes(attrs, names, enclosure) end end @@ -375,7 +382,8 @@ module RSS def assert_items20_guid(attrs, guid) _wrap_assertion do - assert_attributes(attrs, %w(isPermaLink content), guid) + names = [["isPermaLink", :boolean], ["content"]] + assert_attributes(attrs, names, guid) end end @@ -408,7 +416,9 @@ module RSS def assert_syndication(elems, target) _wrap_assertion do elems.each do |name, value| - assert_equal(value, target.__send__("sy_#{name}")) + meth = "sy_#{name}" + value = value.to_i if meth == "sy_updateFrequency" + assert_equal(value, target.__send__(meth )) end end end @@ -458,13 +468,25 @@ module RSS def assert_attributes(attrs, names, target) _wrap_assertion do n_attrs = normalized_attrs(attrs) - names.each do |name| + names.each do |info| + if info.is_a?(String) + name = info + type = nil + else + name, type = info + end value = n_attrs[name] if value.is_a?(Time) actual = target.__send__(name) assert_instance_of(Time, actual) assert_equal(value.to_i, actual.to_i) elsif value + case type + when :integer + value = value.to_i + when :boolean + value = value == "true" if value.is_a?(String) + end assert_equal(value, target.__send__(name)) end end -- cgit v1.2.3