summaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authorkou <kou@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2006-06-17 00:53:21 +0000
committerkou <kou@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2006-06-17 00:53:21 +0000
commit7461f297e92c2451b62a8797dff6562e52e3f746 (patch)
tree58ed280d46280b524dab8b8a6f6f739461f97589 /test
parent88dd1e4c993e661b0d52c40d0eff567b00bf6ffd (diff)
* 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: svn+ssh://ci.ruby-lang.org/ruby/branches/ruby_1_8@10296 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'test')
-rw-r--r--test/rss/rss-assertions.rb8
-rw-r--r--test/rss/test_1.0.rb24
-rw-r--r--test/rss/test_2.0.rb61
3 files changed, 28 insertions, 65 deletions
diff --git a/test/rss/rss-assertions.rb b/test/rss/rss-assertions.rb
index 435f893e8d..cb757a9ae4 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*<rdf:RDF.*\z/m, "")
+ pi_str = rss.to_s.gsub(/<\?xml .*\n/, "").gsub(/\s*<[^\?].*\z/m, "")
assert_equal(xss_strs.join("\n"), pi_str)
end
end
diff --git a/test/rss/test_1.0.rb b/test/rss/test_1.0.rb
index 5a01e9f5c3..b905ba6e94 100644
--- a/test/rss/test_1.0.rb
+++ b/test/rss/test_1.0.rb
@@ -5,18 +5,15 @@ require "rss-testcase"
require "rss/1.0"
module RSS
- class TestCore < TestCase
+ class TestRSS10Core < TestCase
def setup
-
@rdf_prefix = "rdf"
@rdf_uri = "http://www.w3.org/1999/02/22-rdf-syntax-ns#"
@uri = "http://purl.org/rss/1.0/"
-
end
def test_RDF
-
version = "1.0"
encoding = "UTF-8"
standalone = false
@@ -33,7 +30,6 @@ module RSS
assert_equal(standalone, !xmldecl.standalone.nil?)
assert_equal(@rdf_uri, doc.root.namespace)
-
end
def test_not_displayed_xml_stylesheets
@@ -93,11 +89,9 @@ module RSS
end
assert_equal(@uri, c.elements["items"].namespace)
assert_equal("items", c.elements["items"].name)
-
end
def test_channel_image
-
resource = "http://hoge.com/hoge.png"
image = RDF::Channel::Image.new(resource)
@@ -111,11 +105,9 @@ module RSS
assert_equal(@rdf_uri, res.namespace)
assert_equal(resource, res.value)
-
end
def test_channel_textinput
-
resource = "http://hoge.com/hoge.png"
textinput = RDF::Channel::Textinput.new(resource)
@@ -129,11 +121,9 @@ module RSS
assert_equal(@rdf_uri, res.namespace)
assert_equal(resource, res.value)
-
end
def test_items
-
items = RDF::Channel::Items.new
doc = REXML::Document.new(make_RDF(items.to_s))
@@ -145,11 +135,9 @@ module RSS
assert_equal(1, i.elements.size)
assert_equal("Seq", i.elements[1].name)
assert_equal(@rdf_uri, i.elements[1].namespace)
-
end
def test_seq
-
seq = RDF::Seq.new
doc = REXML::Document.new(make_RDF(seq.to_s))
@@ -157,11 +145,9 @@ module RSS
assert_equal("Seq", s.name)
assert_equal(@rdf_uri, s.namespace)
-
end
def test_li
-
resource = "http://hoge.com/"
li = RDF::Li.new(resource)
@@ -175,11 +161,9 @@ module RSS
assert_equal('', res.instance_eval("@prefix"))
assert_equal(resource, res.value)
-
end
def test_image
-
about = "http://hoge.com"
title = "fugafuga"
url = "http://hoge.com/hoge"
@@ -200,11 +184,9 @@ module RSS
assert_equal(@uri, elem.namespace)
assert_equal(instance_eval(x), elem.text)
end
-
end
def test_item
-
about = "http://hoge.com"
title = "fugafuga"
link = "http://hoge.com/fuga"
@@ -225,11 +207,9 @@ module RSS
assert_equal(@uri, elem.namespace)
assert_equal(instance_eval(x), elem.text)
end
-
end
def test_textinput
-
about = "http://hoge.com"
title = "fugafuga"
link = "http://hoge.com/fuga"
@@ -251,7 +231,6 @@ module RSS
assert_equal(@uri, elem.namespace)
assert_equal(instance_eval(x), elem.text)
end
-
end
def test_indent_size
@@ -264,6 +243,5 @@ module RSS
assert_equal(1, RDF::Item.indent_size)
assert_equal(1, RDF::Textinput.indent_size)
end
-
end
end
diff --git a/test/rss/test_2.0.rb b/test/rss/test_2.0.rb
index 2027e5344a..238d3efaa9 100644
--- a/test/rss/test_2.0.rb
+++ b/test/rss/test_2.0.rb
@@ -75,9 +75,9 @@ module RSS
generator = "MightyInHouse Content System v2.3"
docs = "http://blogs.law.harvard.edu/tech/rss"
- ttl = "60"
+ ttl = 60
- rating = '(PICS-1.1 "http://www.rsac.org/ratingsv01.html" l gen true comment "RSACi North America Server" for "http://www.rsac.org" on "1996.04.16T08:15-0500" r (n 0 s 0 v 0 l 0))'
+ rating = 6
channel = Rss::Channel.new
@@ -85,9 +85,7 @@ module RSS
managingEditor webMaster pubDate lastBuildDate
generator docs ttl rating)
elems.each do |x|
- value = instance_eval(x)
- value = value.rfc822 if %w(pubDate lastBuildDate).include?(x)
- channel.__send__("#{x}=", value)
+ channel.__send__("#{x}=", instance_eval(x))
end
categories.each do |cat|
channel.categories << Rss::Channel::Category.new(cat[:domain],
@@ -105,8 +103,7 @@ module RSS
case x
when "pubDate", "lastBuildDate"
assert_equal(expected, Time.parse(elem.text))
- when "ttl"
- expected = channel.__send__(x)
+ when "ttl", "rating"
assert_equal(expected, elem.text.to_i)
else
assert_equal(expected, elem.text)
@@ -127,7 +124,7 @@ module RSS
def test_channel_cloud
cloud_params = {
:domain => "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