From 1fde2760ceba793af22fc55d51195d7abb1fa33e Mon Sep 17 00:00:00 2001 From: kou Date: Sat, 17 Jun 2006 00:53:21 +0000 Subject: * lib/rss, test/rss: backported from trunk. (2005-11-16 - now) * test/rss/test_2.0.rb: added RSS 2.0 tests. * test/rss/rss-assertions.rb: extended XML stylesheet assertion. * lib/rss/0.9.rb: added initialize method. * test/rss/test_1.0.rb: cleanup. git-svn-id: http://svn.ruby-lang.org/repos/ruby/branches/ruby_1_8@10296 b2dd03c8-39d4-4d8f-98ff-823fe69b080e --- ChangeLog | 5 ++++ lib/rss/0.9.rb | 19 +++++++++++++++ test/rss/rss-assertions.rb | 8 +++--- test/rss/test_1.0.rb | 24 +----------------- test/rss/test_2.0.rb | 61 +++++++++++++++++----------------------------- 5 files changed, 52 insertions(+), 65 deletions(-) diff --git a/ChangeLog b/ChangeLog index 2fb7ee356..691d31fa3 100644 --- a/ChangeLog +++ b/ChangeLog @@ -68,6 +68,11 @@ Sat Jun 17 09:03:47 2006 Kouhei Sutou * test/rss/test_parser.rb: added an entity handling test. + * test/rss/test_2.0.rb: added RSS 2.0 tests. + * test/rss/rss-assertions.rb: extended XML stylesheet assertion. + * lib/rss/0.9.rb: added initialize method. + * test/rss/test_1.0.rb: cleanup. + Sat Jun 17 02:01:00 2006 Tanaka Akira * lib/pp.rb (Kernel#pretty_inspect): defined for pretty printed diff --git a/lib/rss/0.9.rb b/lib/rss/0.9.rb index 56fdfb361..a4b2ba9b8 100644 --- a/lib/rss/0.9.rb +++ b/lib/rss/0.9.rb @@ -339,6 +339,17 @@ module RSS install_model(name, "?") end + def initialize(url=nil, title=nil, link=nil, width=nil, height=nil, + description=nil) + super() + @url = url + @title = title + @link = link + @width = width + @height = height + @description = description + end + def to_s(need_convert=true, indent=calc_indent) rv = tag(indent) do |next_indent| [ @@ -618,6 +629,14 @@ module RSS install_model(name, nil) end + def initialize(title=nil, description=nil, name=nil, link=nil) + super() + @title = title + @description = description + @name = name + @link = link + end + def to_s(need_convert=true, indent=calc_indent) rv = tag(indent) do |next_indent| [ diff --git a/test/rss/rss-assertions.rb b/test/rss/rss-assertions.rb index 435f893e8..cb757a9ae 100644 --- a/test/rss/rss-assertions.rb +++ b/test/rss/rss-assertions.rb @@ -139,16 +139,16 @@ module RSS end end - def assert_xml_stylesheet_pis(attrs_ary) + def assert_xml_stylesheet_pis(attrs_ary, rss=nil) _wrap_assertion do - rdf = ::RSS::RDF.new() + rss ||= ::RSS::RDF.new() xss_strs = [] attrs_ary.each do |attrs| xss = ::RSS::XMLStyleSheet.new(*attrs) xss_strs.push(xss.to_s) - rdf.xml_stylesheets.push(xss) + rss.xml_stylesheets.push(xss) end - pi_str = rdf.to_s.gsub(/<\?xml .*\n/, "").gsub(/\s* "rpc.sys.com", - :port => "80", + :port => 80, :path => "/RPC2", :registerProcedure => "myCloud.rssPleaseNotify", :protocol => "xml-rpc", @@ -137,15 +134,14 @@ module RSS cloud_params[:path], cloud_params[:registerProcedure], cloud_params[:protocol]) - cloud_params[:port] = cloud.port - + doc = REXML::Document.new(cloud.to_s) cloud_elem = doc.root actual = {} cloud_elem.attributes.each do |name, value| value = value.to_i if name == "port" - actual[name.intern] = value + actual[name.to_sym] = value end assert_equal(cloud_params, actual) end @@ -155,8 +151,8 @@ module RSS :url => "http://hoge.com/hoge.png", :title => "fugafuga", :link => "http://hoge.com", - :width => "144", - :height => "400", + :width => 144, + :height => 400, :description => "an image", } image = Rss::Channel::Image.new(image_params[:url], @@ -170,7 +166,6 @@ module RSS image_elem = doc.root image_params.each do |name, value| - value = image.__send__(name) actual = image_elem.elements[name.to_s].text actual = actual.to_i if [:width, :height].include?(name) assert_equal(value, actual) @@ -218,8 +213,8 @@ module RSS def test_channel_skip_hours skipHours_values = [ - "0", - "13", + 0, + 13, ] skipHours = Rss::Channel::SkipHours.new skipHours_values.each do |value| @@ -230,8 +225,7 @@ module RSS hours_elem = doc.root skipHours_values.each_with_index do |value, i| - expected = skipHours.hours[i].content - assert_equal(expected, hours_elem.elements[i + 1].text.to_i) + assert_equal(value, hours_elem.elements[i + 1].text.to_i) end end @@ -258,9 +252,7 @@ module RSS elems = %w(title link description author comments pubDate) elems.each do |x| - value = instance_eval(x) - value = value.rfc822 if x == "pubDate" - item.__send__("#{x}=", value) + item.__send__("#{x}=", instance_eval(x)) end categories.each do |cat| item.categories << Rss::Channel::Category.new(cat[:domain], @@ -298,22 +290,24 @@ module RSS def test_item_enclosure enclosure_params = { :url => "http://www.scripting.com/mp3s/weatherReportSuite.mp3", - :length => "12216320", + :length => 12216320, :type => "audio/mpeg", } enclosure = Rss::Channel::Item::Enclosure.new(enclosure_params[:url], enclosure_params[:length], enclosure_params[:type]) - enclosure_params[:length] = enclosure.length - + doc = REXML::Document.new(enclosure.to_s) enclosure_elem = doc.root actual = {} enclosure_elem.attributes.each do |name, value| - value = value.to_i if name == "length" - actual[name.intern] = value + if name == "length" + enclosure_params[name.to_sym] = value.to_i + value = value.to_i + end + actual[name.to_sym] = value end assert_equal(enclosure_params, actual) end @@ -332,23 +326,14 @@ module RSS test_params.each do |guid_params| guid = Rss::Channel::Item::Guid.new(guid_params[:isPermaLink], guid_params[:content]) - if guid_params.has_key?(:isPermaLink) - guid_params[:isPermaLink] = guid.isPermaLink - end - if guid.isPermaLink.nil? - assert_equal(true, guid.PermaLink?) - else - assert_equal(guid.isPermaLink, guid.PermaLink?) - end - + doc = REXML::Document.new(guid.to_s) guid_elem = doc.root actual = {} actual[:content] = guid_elem.text if guid_elem.text guid_elem.attributes.each do |name, value| - value = value == "true" if name == "isPermaLink" - actual[name.intern] = value + actual[name.to_sym] = value end assert_equal(guid_params, actual) end @@ -369,7 +354,7 @@ module RSS actual = {} actual[:content] = source_elem.text source_elem.attributes.each do |name, value| - actual[name.intern] = value + actual[name.to_sym] = value end assert_equal(source_params, actual) end -- cgit