4
# For backward compatibility
5
unless instance_methods.include?("assert_raise")
6
def assert_raise(*args, &block)
7
assert_raises(*args, &block)
17
def assert_parse(rss, assert_method, *args)
18
__send__("assert_#{assert_method}", *args) do
19
::RSS::Parser.parse(rss)
21
__send__("assert_#{assert_method}", *args) do
22
::RSS::Parser.parse(rss, false).validate
26
def assert_ns(prefix, uri)
30
flunk("Not raise NSError")
31
rescue ::RSS::NSError => e
32
assert_equal(prefix, e.prefix)
33
assert_equal(uri, e.uri)
38
def assert_missing_tag(tag, parent)
42
flunk("Not raise MissingTagError")
43
rescue ::RSS::MissingTagError => e
44
assert_equal(tag, e.tag)
45
assert_equal(parent, e.parent)
50
def assert_too_much_tag(tag, parent)
54
flunk("Not raise TooMuchTagError")
55
rescue ::RSS::TooMuchTagError => e
56
assert_equal(tag, e.tag)
57
assert_equal(parent, e.parent)
62
def assert_missing_attribute(tag, attrname)
66
flunk("Not raise MissingAttributeError")
67
rescue ::RSS::MissingAttributeError => e
68
assert_equal(tag, e.tag)
69
assert_equal(attrname, e.attribute)
74
def assert_not_expected_tag(tag, uri, parent)
78
flunk("Not raise NotExpectedTagError")
79
rescue ::RSS::NotExpectedTagError => e
80
assert_equal(tag, e.tag)
81
assert_equal(uri, e.uri)
82
assert_equal(parent, e.parent)
87
def assert_not_available_value(tag, value, attribute=nil)
91
flunk("Not raise NotAvailableValueError")
92
rescue ::RSS::NotAvailableValueError => e
93
assert_equal(tag, e.tag)
94
assert_equal(value, e.value)
95
assert_equal(attribute, e.attribute)
100
def assert_not_set_error(name, variables)
104
flunk("Not raise NotSetError")
105
rescue ::RSS::NotSetError => e
106
assert_equal(name, e.name)
107
assert_equal(variables.sort, e.variables.sort)
112
def assert_xml_declaration(version, encoding, standalone, rss)
114
assert_equal(version, rss.version)
115
assert_equal(encoding, rss.encoding)
116
assert_equal(standalone, rss.standalone)
120
def assert_xml_stylesheet_attrs(attrs, xsl)
122
n_attrs = normalized_attrs(attrs)
123
::RSS::XMLStyleSheet::ATTRIBUTES.each do |name|
124
assert_equal(n_attrs[name], xsl.__send__(name))
129
def assert_xml_stylesheet(target, attrs, xsl)
131
if attrs.has_key?(:href)
132
if !attrs.has_key?(:type) and attrs.has_key?(:guess_type)
133
attrs[:type] = attrs[:guess_type]
135
assert_equal("xml-stylesheet", target)
136
assert_xml_stylesheet_attrs(attrs, xsl)
139
assert_equal("", xsl.to_s)
144
def assert_xml_stylesheet_pis(attrs_ary, rss=nil)
146
rss ||= ::RSS::RDF.new()
148
attrs_ary.each do |attrs|
149
xss = ::RSS::XMLStyleSheet.new(*attrs)
150
xss_strs.push(xss.to_s)
151
rss.xml_stylesheets.push(xss)
153
pi_str = rss.to_s.gsub(/<\?xml .*\n/, "").gsub(/\s*<[^\?].*\z/m, "")
154
assert_equal(xss_strs.join("\n"), pi_str)
158
def assert_xml_stylesheets(attrs, xss)
160
xss.each_with_index do |xs, i|
161
assert_xml_stylesheet_attrs(attrs[i], xs)
167
def assert_channel10(attrs, channel)
169
n_attrs = normalized_attrs(attrs)
171
names = %w(about title link description)
172
assert_attributes(attrs, names, channel)
174
%w(image items textinput).each do |name|
175
value = n_attrs[name]
177
target = channel.__send__(name)
178
__send__("assert_channel10_#{name}", value, target)
184
def assert_channel10_image(attrs, image)
186
assert_attributes(attrs, %w(resource), image)
190
def assert_channel10_textinput(attrs, textinput)
192
assert_attributes(attrs, %w(resource), textinput)
196
def assert_channel10_items(attrs, items)
198
assert_equal(items.resources, items.Seq.lis.collect {|x| x.resource})
199
items.Seq.lis.each_with_index do |li, i|
200
assert_attributes(attrs[i], %w(resource), li)
205
def assert_image10(attrs, image)
207
names = %w(about title url link)
208
assert_attributes(attrs, names, image)
212
def assert_items10(attrs, items)
214
names = %w(about title link description)
215
items.each_with_index do |item, i|
216
assert_attributes(attrs[i], names, item)
221
def assert_textinput10(attrs, textinput)
223
names = %w(about title description name link)
224
assert_attributes(attrs, names, textinput)
229
def assert_channel09(attrs, channel)
231
n_attrs = normalized_attrs(attrs)
233
names = %w(title description link language rating
234
copyright pubDate lastBuildDate docs
235
managingEditor webMaster)
236
assert_attributes(attrs, names, channel)
238
%w(skipHours skipDays).each do |name|
239
value = n_attrs[name]
241
target = channel.__send__(name)
242
__send__("assert_channel09_#{name}", value, target)
248
def assert_channel09_skipDays(contents, skipDays)
251
contents.each_with_index do |content, i|
252
assert_equal(content, days[i].content)
257
def assert_channel09_skipHours(contents, skipHours)
259
hours = skipHours.hours
260
contents.each_with_index do |content, i|
261
assert_equal(content.to_i, hours[i].content)
266
def assert_image09(attrs, image)
268
names = %w(url link title description)
269
names << ["width", :integer]
270
names << ["height", :integer]
271
assert_attributes(attrs, names, image)
275
def assert_items09(attrs, items)
277
names = %w(title link description)
278
items.each_with_index do |item, i|
279
assert_attributes(attrs[i], names, item)
284
def assert_textinput09(attrs, textinput)
286
names = %w(title description name link)
287
assert_attributes(attrs, names, textinput)
292
def assert_channel20(attrs, channel)
294
n_attrs = normalized_attrs(attrs)
296
names = %w(title link description language copyright
297
managingEditor webMaster pubDate
298
lastBuildDate generator docs rating)
299
names << ["ttl", :integer]
300
assert_attributes(attrs, names, channel)
302
%w(cloud categories skipHours skipDays).each do |name|
303
value = n_attrs[name]
305
target = channel.__send__(name)
306
__send__("assert_channel20_#{name}", value, target)
312
def assert_channel20_skipDays(contents, skipDays)
313
assert_channel09_skipDays(contents, skipDays)
316
def assert_channel20_skipHours(contents, skipHours)
317
assert_channel09_skipHours(contents, skipHours)
320
def assert_channel20_cloud(attrs, cloud)
322
names = %w(domain path registerProcedure protocol)
323
names << ["port", :integer]
324
assert_attributes(attrs, names, cloud)
328
def assert_channel20_categories(attrs, categories)
330
names = %w(domain content)
331
categories.each_with_index do |category, i|
332
assert_attributes(attrs[i], names, category)
337
def assert_image20(attrs, image)
339
names = %w(url link title description)
340
names << ["width", :integer]
341
names << ["height", :integer]
342
assert_attributes(attrs, names, image)
346
def assert_items20(attrs, items)
348
names = %w(about title link description)
349
items.each_with_index do |item, i|
350
assert_attributes(attrs[i], names, item)
352
n_attrs = normalized_attrs(attrs[i])
354
%w(source enclosure categories guid).each do |name|
355
value = n_attrs[name]
357
target = item.__send__(name)
358
__send__("assert_items20_#{name}", value, target)
365
def assert_items20_source(attrs, source)
367
assert_attributes(attrs, %w(url content), source)
371
def assert_items20_enclosure(attrs, enclosure)
373
names = ["url", ["length", :integer], "type"]
374
assert_attributes(attrs, names, enclosure)
378
def assert_items20_categories(attrs, categories)
380
assert_channel20_categories(attrs, categories)
384
def assert_items20_guid(attrs, guid)
386
names = [["isPermaLink", :boolean], ["content"]]
387
assert_attributes(attrs, names, guid)
391
def assert_textinput20(attrs, textinput)
393
names = %w(title description name link)
394
assert_attributes(attrs, names, textinput)
399
def assert_dublin_core(elems, target)
401
elems.each do |name, value|
402
assert_equal(value, target.__send__("dc_#{name}"))
407
def assert_multiple_dublin_core(elems, target)
409
elems.each do |name, values, plural|
410
plural ||= "#{name}s"
411
actual = target.__send__("dc_#{plural}").collect{|x| x.value}
412
assert_equal(values, actual)
417
def assert_syndication(elems, target)
419
elems.each do |name, value|
421
value = value.to_i if meth == "sy_updateFrequency"
422
assert_equal(value, target.__send__(meth ))
427
def assert_content(elems, target)
429
elems.each do |name, value|
430
assert_equal(value, target.__send__("content_#{name}"))
435
def assert_trackback(attrs, target)
437
n_attrs = normalized_attrs(attrs)
439
assert_equal(n_attrs["ping"], target.trackback_ping)
442
n_attrs["abouts"].each_with_index do |about, i|
443
assert_equal(about, target.trackback_abouts[i].value)
449
def assert_taxo_topic(topics, target)
451
topics.each_with_index do |topic, i|
452
taxo_topic = target.taxo_topics[i]
453
topic.each do |name, value|
456
assert_equal(value, taxo_topic.about)
457
assert_equal(value, taxo_topic.taxo_link)
459
assert_equal(value, taxo_topic.taxo_topics.resources)
461
assert_equal(value, taxo_topic.__send__("dc_#{name}"))
469
def assert_attributes(attrs, names, target)
471
n_attrs = normalized_attrs(attrs)
473
if info.is_a?(String)
479
value = n_attrs[name]
481
actual = target.__send__(name)
482
assert_instance_of(Time, actual)
483
assert_equal(value.to_i, actual.to_i)
489
value = value == "true" if value.is_a?(String)
491
assert_equal(value, target.__send__(name))
497
def normalized_attrs(attrs)
499
attrs.each do |name, value|
500
n_attrs[name.to_s] = value