summaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
Diffstat (limited to 'test')
-rw-r--r--test/rss/rss-assertions.rb685
-rw-r--r--test/rss/test_atom.rb413
-rw-r--r--test/rss/test_image.rb10
-rw-r--r--test/rss/test_inherit.rb5
-rw-r--r--test/rss/test_itunes.rb347
-rw-r--r--test/rss/test_maker_0.9.rb44
-rw-r--r--test/rss/test_maker_1.0.rb92
-rw-r--r--test/rss/test_maker_2.0.rb12
-rw-r--r--test/rss/test_maker_atom_feed.rb11
-rw-r--r--test/rss/test_maker_itunes.rb471
-rw-r--r--test/rss/test_maker_xml-stylesheet.rb4
-rw-r--r--test/rss/test_parser.rb14
-rw-r--r--test/rss/test_setup_maker_1.0.rb8
-rw-r--r--test/rss/test_setup_maker_atom_feed.rb4
-rw-r--r--test/rss/test_setup_maker_itunes.rb144
-rw-r--r--test/rss/test_to_s.rb232
-rw-r--r--test/rss/test_version.rb2
17 files changed, 1755 insertions, 743 deletions
diff --git a/test/rss/rss-assertions.rb b/test/rss/rss-assertions.rb
index 01f68678f0d..3b212c794de 100644
--- a/test/rss/rss-assertions.rb
+++ b/test/rss/rss-assertions.rb
@@ -1,3 +1,5 @@
+require 'erb'
+
module RSS
module Assertions
def assert_parse(rss, assert_method, *args)
@@ -90,6 +92,7 @@ module RSS
flunk("Not raise NotSetError")
rescue ::RSS::NotSetError => e
assert_equal(name, e.name)
+ assert_kind_of(Array, variables)
assert_equal(variables.sort, e.variables.sort)
end
end
@@ -152,237 +155,6 @@ module RSS
end
end
-
- def assert_channel10(attrs, channel)
- _wrap_assertion do
- n_attrs = normalized_attrs(attrs)
-
- names = %w(about title link description)
- assert_attributes(attrs, names, channel)
-
- %w(image items textinput).each do |name|
- value = n_attrs[name]
- if value
- target = channel.__send__(name)
- __send__("assert_channel10_#{name}", value, target)
- end
- end
- end
- end
-
- def assert_channel10_image(attrs, image)
- _wrap_assertion do
- assert_attributes(attrs, %w(resource), image)
- end
- end
-
- def assert_channel10_textinput(attrs, textinput)
- _wrap_assertion do
- assert_attributes(attrs, %w(resource), textinput)
- end
- end
-
- def assert_channel10_items(attrs, items)
- _wrap_assertion do
- assert_equal(items.resources, items.Seq.lis.collect {|x| x.resource})
- items.Seq.lis.each_with_index do |li, i|
- assert_attributes(attrs[i], %w(resource), li)
- end
- end
- end
-
- def assert_image10(attrs, image)
- _wrap_assertion do
- names = %w(about title url link)
- assert_attributes(attrs, names, image)
- end
- end
-
- def assert_items10(attrs, items)
- _wrap_assertion do
- names = %w(about title link description)
- items.each_with_index do |item, i|
- assert_attributes(attrs[i], names, item)
- end
- end
- end
-
- def assert_textinput10(attrs, textinput)
- _wrap_assertion do
- names = %w(about title description name link)
- assert_attributes(attrs, names, textinput)
- end
- end
-
-
- def assert_channel09(attrs, channel)
- _wrap_assertion do
- n_attrs = normalized_attrs(attrs)
-
- names = %w(title description link language rating
- copyright pubDate lastBuildDate docs
- managingEditor webMaster)
- assert_attributes(attrs, names, channel)
-
- %w(skipHours skipDays).each do |name|
- value = n_attrs[name]
- if value
- target = channel.__send__(name)
- __send__("assert_channel09_#{name}", value, target)
- end
- end
- end
- end
-
- def assert_channel09_skipDays(contents, skipDays)
- _wrap_assertion do
- days = skipDays.days
- contents.each_with_index do |content, i|
- assert_equal(content, days[i].content)
- end
- end
- end
-
- def assert_channel09_skipHours(contents, skipHours)
- _wrap_assertion do
- hours = skipHours.hours
- contents.each_with_index do |content, i|
- 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)
- names << ["width", :integer]
- names << ["height", :integer]
- assert_attributes(attrs, names, image)
- end
- end
-
- def assert_items09(attrs, items)
- _wrap_assertion do
- names = %w(title link description)
- items.each_with_index do |item, i|
- assert_attributes(attrs[i], names, item)
- end
- end
- end
-
- def assert_textinput09(attrs, textinput)
- _wrap_assertion do
- names = %w(title description name link)
- assert_attributes(attrs, names, textinput)
- end
- end
-
-
- def assert_channel20(attrs, channel)
- _wrap_assertion do
- n_attrs = normalized_attrs(attrs)
-
- names = %w(title link description language copyright
- managingEditor webMaster pubDate
- lastBuildDate generator docs rating)
- names << ["ttl", :integer]
- assert_attributes(attrs, names, channel)
-
- %w(cloud categories skipHours skipDays).each do |name|
- value = n_attrs[name]
- if value
- target = channel.__send__(name)
- __send__("assert_channel20_#{name}", value, target)
- end
- end
- end
- end
-
- def assert_channel20_skipDays(contents, skipDays)
- assert_channel09_skipDays(contents, skipDays)
- end
-
- def assert_channel20_skipHours(contents, skipHours)
- assert_channel09_skipHours(contents, skipHours)
- end
-
- def assert_channel20_cloud(attrs, cloud)
- _wrap_assertion do
- names = %w(domain path registerProcedure protocol)
- names << ["port", :integer]
- assert_attributes(attrs, names, cloud)
- end
- end
-
- def assert_channel20_categories(attrs, categories)
- _wrap_assertion do
- names = %w(domain content)
- categories.each_with_index do |category, i|
- assert_attributes(attrs[i], names, category)
- end
- end
- end
-
- def assert_image20(attrs, image)
- _wrap_assertion do
- names = %w(url link title description)
- names << ["width", :integer]
- names << ["height", :integer]
- assert_attributes(attrs, names, image)
- end
- end
-
- def assert_items20(attrs, items)
- _wrap_assertion do
- names = %w(about title link description)
- items.each_with_index do |item, i|
- assert_attributes(attrs[i], names, item)
-
- n_attrs = normalized_attrs(attrs[i])
-
- %w(source enclosure categories guid).each do |name|
- value = n_attrs[name]
- if value
- target = item.__send__(name)
- __send__("assert_items20_#{name}", value, target)
- end
- end
- end
- end
- end
-
- def assert_items20_source(attrs, source)
- _wrap_assertion do
- assert_attributes(attrs, %w(url content), source)
- end
- end
-
- def assert_items20_enclosure(attrs, enclosure)
- _wrap_assertion do
- names = ["url", ["length", :integer], "type"]
- assert_attributes(attrs, names, enclosure)
- end
- end
-
- def assert_items20_categories(attrs, categories)
- _wrap_assertion do
- assert_channel20_categories(attrs, categories)
- end
- end
-
- def assert_items20_guid(attrs, guid)
- _wrap_assertion do
- names = [["isPermaLink", :boolean], ["content"]]
- assert_attributes(attrs, names, guid)
- end
- end
-
- def assert_textinput20(attrs, textinput)
- _wrap_assertion do
- names = %w(title description name link)
- assert_attributes(attrs, names, textinput)
- end
- end
def assert_atom_person(tag_name, generator)
_wrap_assertion do
@@ -1146,401 +918,6 @@ EOA
end
end
-
- def assert_atom_person_to_s(target_class)
- _wrap_assertion do
- name = "A person"
- uri = "http://example.com/person/"
- email = "person@example.com"
-
- target = target_class.new
- assert_equal("", target.to_s)
-
- target = target_class.new
- person_name = target_class::Name.new
- person_name.content = name
- target.name = person_name
- xml_target = REXML::Document.new(target.to_s).root
- assert_equal(["name"], xml_target.elements.collect {|e| e.name})
- assert_equal([name], xml_target.elements.collect {|e| e.text})
-
- person_uri = target_class::Uri.new
- person_uri.content = uri
- target.uri = person_uri
- xml_target = REXML::Document.new(target.to_s).root
- assert_equal(["name", "uri"], xml_target.elements.collect {|e| e.name})
- assert_equal([name, uri], xml_target.elements.collect {|e| e.text})
-
- person_email = target_class::Email.new
- person_email.content = email
- target.email = person_email
- xml_target = REXML::Document.new(target.to_s).root
- assert_equal(["name", "uri", "email"],
- xml_target.elements.collect {|e| e.name})
- assert_equal([name, uri, email],
- xml_target.elements.collect {|e| e.text})
- end
- end
-
- def assert_atom_category_to_s(target_class)
- _wrap_assertion do
- term = "music"
- scheme = "http://example.com/music"
- label = "Music"
-
- category = target_class.new
- assert_equal("", category.to_s)
-
- category = target_class.new
- category.scheme = scheme
- assert_equal("", category.to_s)
-
- category = target_class.new
- category.label = label
- assert_equal("", category.to_s)
-
- category = target_class.new
- category.scheme = scheme
- category.label = label
- assert_equal("", category.to_s)
-
- category = target_class.new
- category.term = term
- xml = REXML::Document.new(category.to_s).root
- assert_rexml_element([], {"term" => term}, nil, xml)
-
- category = target_class.new
- category.term = term
- category.scheme = scheme
- xml = REXML::Document.new(category.to_s).root
- assert_rexml_element([], {"term" => term, "scheme" => scheme}, nil, xml)
-
- category = target_class.new
- category.term = term
- category.label = label
- xml = REXML::Document.new(category.to_s).root
- assert_rexml_element([], {"term" => term, "label" => label}, nil, xml)
-
- category = target_class.new
- category.term = term
- category.scheme = scheme
- category.label = label
- xml = REXML::Document.new(category.to_s).root
- attrs = {"term" => term, "scheme" => scheme, "label" => label}
- assert_rexml_element([], attrs, nil, xml)
- end
- end
-
- def assert_atom_generator_to_s(target_class)
- _wrap_assertion do
- content = "Feed generator"
- uri = "http://example.com/generator"
- version = "0.0.1"
-
- generator = target_class.new
- assert_equal("", generator.to_s)
-
- generator = target_class.new
- generator.uri = uri
- assert_equal("", generator.to_s)
-
- generator = target_class.new
- generator.version = version
- assert_equal("", generator.to_s)
-
- generator = target_class.new
- generator.uri = uri
- generator.version = version
- assert_equal("", generator.to_s)
-
- generator = target_class.new
- generator.content = content
- xml = REXML::Document.new(generator.to_s).root
- assert_rexml_element([], {}, content, xml)
-
- generator = target_class.new
- generator.content = content
- generator.uri = uri
- xml = REXML::Document.new(generator.to_s).root
- assert_rexml_element([], {"uri" => uri}, content, xml)
-
- generator = target_class.new
- generator.content = content
- generator.version = version
- xml = REXML::Document.new(generator.to_s).root
- assert_rexml_element([], {"version" => version}, content, xml)
-
- generator = target_class.new
- generator.content = content
- generator.uri = uri
- generator.version = version
- xml = REXML::Document.new(generator.to_s).root
- assert_rexml_element([], {"uri" => uri, "version" => version},
- content, xml)
- end
- end
-
- def assert_atom_icon_to_s(target_class)
- _wrap_assertion do
- content = "http://example.com/icon.png"
-
- icon = target_class.new
- assert_equal("", icon.to_s)
-
- icon = target_class.new
- icon.content = content
- xml = REXML::Document.new(icon.to_s).root
- assert_rexml_element([], {}, content, xml)
- end
- end
-
- def assert_atom_id_to_s(target_class)
- _wrap_assertion do
- content = "http://example.com/1"
-
- id = target_class.new
- assert_equal("", id.to_s)
-
- id = target_class.new
- id.content = content
- xml = REXML::Document.new(id.to_s).root
- assert_rexml_element([], {}, content, xml)
- end
- end
-
- def assert_atom_link_to_s(target_class)
- _wrap_assertion do
- href = "http://example.com/atom.xml"
- rel = "self"
- type = "application/atom+xml"
- hreflang = "ja"
- title = "Atom Feed"
- length = "801"
-
- link = target_class.new
- assert_equal("", link.to_s)
-
- link = target_class.new
- link.href = href
- xml = REXML::Document.new(link.to_s).root
- assert_rexml_element([], {"href" => href}, nil, xml)
-
- optional_arguments = %w(rel type hreflang title length)
- optional_arguments.each do |name|
- rest = optional_arguments.reject {|x| x == name}
-
- link = target_class.new
- link.__send__("#{name}=", eval(name))
- assert_equal("", link.to_s)
-
- rest.each do |n|
- link.__send__("#{n}=", eval(n))
- assert_equal("", link.to_s)
- end
-
- link = target_class.new
- link.href = href
- link.__send__("#{name}=", eval(name))
- attrs = [["href", href], [name, eval(name)]]
- xml = REXML::Document.new(link.to_s).root
- assert_rexml_element([], attrs, nil, xml)
-
- rest.each do |n|
- link.__send__("#{n}=", eval(n))
- attrs << [n, eval(n)]
- xml = REXML::Document.new(link.to_s).root
- assert_rexml_element([], attrs, nil, xml)
- end
- end
- end
- end
-
- def assert_atom_logo_to_s(target_class)
- _wrap_assertion do
- content = "http://example.com/logo.png"
-
- logo = target_class.new
- assert_equal("", logo.to_s)
-
- logo = target_class.new
- logo.content = content
- xml = REXML::Document.new(logo.to_s).root
- assert_rexml_element([], {}, content, xml)
- end
- end
-
- def assert_atom_text_construct_to_s(target_class)
- _wrap_assertion do
- text_content = "plain text"
- html_content = "<em>#{text_content}</em>"
- xhtml_uri = "http://www.w3.org/1999/xhtml"
- xhtml_em = RSS::XML::Element.new("em", nil, xhtml_uri, {}, text_content)
- xhtml_content = RSS::XML::Element.new("div", nil, xhtml_uri,
- {"xmlns" => xhtml_uri},
- [xhtml_em])
-
- text = target_class.new
- assert_equal("", text.to_s)
-
- text = target_class.new
- text.type = "text"
- assert_equal("", text.to_s)
-
- text = target_class.new
- text.content = text_content
- xml = REXML::Document.new(text.to_s).root
- assert_rexml_element([], {}, text_content, xml)
-
- text = target_class.new
- text.type = "text"
- text.content = text_content
- xml = REXML::Document.new(text.to_s).root
- assert_rexml_element([], {"type" => "text"}, text_content, xml)
-
- text = target_class.new
- text.type = "html"
- text.content = html_content
- xml = REXML::Document.new(text.to_s).root
- assert_rexml_element([], {"type" => "html"}, html_content, xml)
-
- text = target_class.new
- text.type = "xhtml"
- text.content = xhtml_content
- assert_equal("", text.to_s)
-
- text = target_class.new
- text.type = "xhtml"
- text.__send__(target_class.xml_setter, xhtml_content)
- xml = REXML::Document.new(text.to_s).root
- assert_rexml_element([[xhtml_uri, "div"]], {"type" => "xhtml"},
- nil, xml)
- assert_rexml_element([[xhtml_uri, "em"]], nil, nil, xml.elements[1])
- assert_rexml_element([], {}, text_content, xml.elements[1].elements[1])
-
- text = target_class.new
- text.type = "xhtml"
- text.__send__(target_class.xml_setter, xhtml_em)
- xml = REXML::Document.new(text.to_s).root
- assert_rexml_element([[xhtml_uri, "div"]], {"type" => "xhtml"},
- nil, xml)
- assert_rexml_element([[xhtml_uri, "em"]], nil, nil, xml.elements[1])
- assert_rexml_element([], {}, text_content, xml.elements[1].elements[1])
- end
- end
-
- def assert_atom_date_construct_to_s(target_class)
- _wrap_assertion do
- date = target_class.new
- assert_equal("", date.to_s)
-
- [
- "2003-12-13T18:30:02Z",
- "2003-12-13T18:30:02.25Z",
- "2003-12-13T18:30:02+01:00",
- "2003-12-13T18:30:02.25+01:00",
- ].each do |content|
- date = target_class.new
- date.content = content
- xml = REXML::Document.new(date.to_s).root
- assert_rexml_element([], {}, content, xml, :time)
-
- date = target_class.new
- date.content = Time.parse(content)
- xml = REXML::Document.new(date.to_s).root
- assert_rexml_element([], {}, content, xml, :time)
- end
- end
- end
-
- def assert_atom_content_to_s(target_class)
- _wrap_assertion do
- assert_atom_text_construct_to_s(target_class)
- assert_atom_content_inline_other_xml_to_s(target_class)
- assert_atom_content_inline_other_text_to_s(target_class)
- assert_atom_content_inline_other_base64_to_s(target_class)
- assert_atom_content_out_of_line_to_s(target_class)
- end
- end
-
- def assert_atom_content_inline_other_xml_to_s(target_class)
- _wrap_assertion do
- content = target_class.new
- content.type = "text/xml"
- assert_equal("", content.to_s)
-
- content = target_class.new
- content.type = "text/xml"
- content.xml = RSS::XML::Element.new("em")
- xml = REXML::Document.new(content.to_s).root
- assert_rexml_element([["", "em"]], {"type" => "text/xml"}, nil, xml)
- end
- end
-
- def assert_atom_content_inline_other_text_to_s(target_class)
- _wrap_assertion do
- content = target_class.new
- content.type = "text/plain"
- assert_equal("", content.to_s)
-
- content = target_class.new
- content.type = "text/plain"
- content.xml = RSS::XML::Element.new("em")
- assert_equal("", content.to_s)
-
- content = target_class.new
- content.type = "text/plain"
- content.content = "content"
- xml = REXML::Document.new(content.to_s).root
- assert_rexml_element([], {"type" => "text/plain"}, "content", xml)
- end
- end
-
- def assert_atom_content_inline_other_base64_to_s(target_class)
- _wrap_assertion do
- require "zlib"
-
- text = ""
- char = "a"
- 100.times do |i|
- text << char
- char.succ!
- end
-
- type = "application/zip"
- original_content = Zlib::Deflate.deflate(text)
-
- content = target_class.new
- content.type = type
- content.content = original_content
- xml = REXML::Document.new(content.to_s).root
- assert_rexml_element([], {"type" => type},
- Base64.encode64(original_content), xml)
- end
- end
-
- def assert_atom_content_out_of_line_to_s(target_class)
- _wrap_assertion do
- type = "application/zip"
- src = "http://example.com/xxx.zip"
-
- content = target_class.new
- assert(!content.out_of_line?)
- content.src = src
- assert(content.out_of_line?)
- xml = REXML::Document.new(content.to_s).root
- assert_rexml_element([], {"src" => src}, nil, xml)
-
- content = target_class.new
- assert(!content.out_of_line?)
- content.type = type
- assert(!content.out_of_line?)
- content.src = src
- assert(content.out_of_line?)
- xml = REXML::Document.new(content.to_s).root
- assert_rexml_element([], {"type" => type, "src" => src}, nil, xml)
- end
- end
-
def _assert_maker_atom_persons(feed_type, maker_readers, feed_readers)
_wrap_assertion do
persons = []
@@ -1565,7 +942,6 @@ EOA
:email => person.email ? person.email.content : nil,
}
end
- p [feed_readers, feed.source.authors] unless persons == actual_persons
assert_equal(persons, actual_persons)
end
end
@@ -1765,7 +1141,7 @@ EOA
assert_not_set_error(not_set_error_name, %w(content)) do
_assert_maker_atom_text_construct(*args) do |maker|
yield maker
- target = chain_reader(maker, maker_readers)
+ target = chain_reader(maker, maker_readers) {|x| x}
target.type = "text"
end
end
@@ -1773,7 +1149,7 @@ EOA
assert_not_set_error(not_set_error_name, %w(content)) do
_assert_maker_atom_text_construct(*args) do |maker|
yield maker
- target = chain_reader(maker, maker_readers)
+ target = chain_reader(maker, maker_readers) {|x| x}
target.type = "html"
end
end
@@ -1781,7 +1157,7 @@ EOA
assert_not_set_error(not_set_error_name, %w(xml_content)) do
_assert_maker_atom_text_construct(*args) do |maker|
yield maker
- target = chain_reader(maker, maker_readers)
+ target = chain_reader(maker, maker_readers) {|x| x}
target.type = "xhtml"
end
end
@@ -1789,7 +1165,7 @@ EOA
assert_not_set_error(not_set_error_name, %w(xml_content)) do
_assert_maker_atom_text_construct(*args) do |maker|
yield maker
- target = chain_reader(maker, maker_readers)
+ target = chain_reader(maker, maker_readers) {|x| x}
target.type = "xhtml"
target.content = "Content"
end
@@ -1797,28 +1173,28 @@ EOA
_assert_maker_atom_text_construct(*args) do |maker|
yield maker
- target = chain_reader(maker, maker_readers)
+ target = chain_reader(maker, maker_readers) {|x| x}
target.type = "text"
target.content = "Content"
end
_assert_maker_atom_text_construct(*args) do |maker|
yield maker
- target = chain_reader(maker, maker_readers)
+ target = chain_reader(maker, maker_readers) {|x| x}
target.type = "html"
target.content = "<em>Content</em>"
end
_assert_maker_atom_text_construct(*args) do |maker|
yield maker
- target = chain_reader(maker, maker_readers)
+ target = chain_reader(maker, maker_readers) {|x| x}
target.type = "xhtml"
target.xml_content = "text only"
end
_assert_maker_atom_text_construct(*args) do |maker|
yield maker
- target = chain_reader(maker, maker_readers)
+ target = chain_reader(maker, maker_readers) {|x| x}
target.type = "xhtml"
target.xml_content = RSS::XML::Element.new("unknown")
end
@@ -1877,7 +1253,7 @@ EOA
element = nil
feed = RSS::Maker.make("atom:#{feed_type}") do |maker|
yield maker
- target = chain_reader(maker, maker_readers)
+ target = chain_reader(maker, maker_readers) {|x| x}
element = maker_extractor.call(target)
end
@@ -1942,7 +1318,7 @@ EOA
__send__(assert_method_name, feed_type, maker_readers,
feed_readers, *additional_args) do |maker|
yield maker
- target = chain_reader(maker, maker_readers)
+ target = chain_reader(maker, maker_readers) {|x| x}
setup_target.call(target, have)
end
end
@@ -1950,7 +1326,7 @@ EOA
__send__(assert_method_name, feed_type, maker_readers, feed_readers,
*additional_args) do |maker|
yield maker
- target = chain_reader(maker, maker_readers)
+ target = chain_reader(maker, maker_readers) {|x| x}
setup_target.call(target, have_required_variable_too)
end
end
@@ -2302,14 +1678,14 @@ EOA
:src => target.src,
:content => target.content,
:xml => target.xml,
- :inline_text => target.__send!(:inline_text?),
- :inline_html => target.__send!(:inline_html?),
- :inline_xhtml => target.__send!(:inline_xhtml?),
- :inline_other => target.__send!(:inline_other?),
- :inline_other_text => target.__send!(:inline_other_text?),
- :inline_other_xml => target.__send!(:inline_other_xml?),
- :inline_other_base64 => target.__send!(:inline_other_base64?),
- :out_of_line => target.__send!(:out_of_line?),
+ :inline_text => target.inline_text?,
+ :inline_html => target.inline_html?,
+ :inline_xhtml => target.inline_xhtml?,
+ :inline_other => target.inline_other?,
+ :inline_other_text => target.inline_other_text?,
+ :inline_other_xml => target.inline_other_xml?,
+ :inline_other_base64 => target.inline_other_base64?,
+ :out_of_line => target.out_of_line?,
}
content[:src] = nil if content[:src] and content[:content]
if content[:type] or content[:content]
@@ -2642,10 +2018,10 @@ EOA
end
end
- def chain_reader(target, readers)
+ def chain_reader(target, readers, &block)
readers.inject(target) do |result, reader|
return nil if result.nil?
- result.__send__(reader)
+ result.__send__(reader, &block)
end
end
@@ -2669,5 +2045,18 @@ EOA
end + combination(rest, n)
end
end
+
+ def tag(name, content=nil, attributes={})
+ attributes = attributes.collect do |key, value|
+ "#{ERB::Util.h(key)}=\"#{ERB::Util.h(value)}\""
+ end.join(" ")
+ begin_tag = "<#{name}"
+ begin_tag << " #{attributes}" unless attributes.empty?
+ if content
+ "#{begin_tag}>#{content}</#{name}>\n"
+ else
+ "#{begin_tag}/>\n"
+ end
+ end
end
end
diff --git a/test/rss/test_atom.rb b/test/rss/test_atom.rb
index aea05bebbef..c442c753b2a 100644
--- a/test/rss/test_atom.rb
+++ b/test/rss/test_atom.rb
@@ -217,7 +217,7 @@ module RSS
end
- def test_to_xml
+ def test_to_xml(with_convenience_way=true)
atom = RSS::Parser.parse(make_feed)
assert_equal(atom.to_s, atom.to_xml)
assert_equal(atom.to_s, atom.to_xml("atom"))
@@ -228,7 +228,11 @@ module RSS
rss09_xml = atom.to_xml("0.91") do |maker|
maker.channel.language = "en-us"
maker.channel.link = "http://example.com/"
- maker.channel.description.content = atom.title.content
+ if with_convenience_way
+ maker.channel.description = atom.title.content
+ else
+ maker.channel.description {|d| d.content = atom.title.content}
+ end
maker.image.url = "http://example.com/logo.png"
maker.image.title = "Logo"
@@ -238,13 +242,21 @@ module RSS
rss20_xml = atom.to_xml("2.0") do |maker|
maker.channel.link = "http://example.com/"
- maker.channel.description.content = atom.title.content
+ if with_convenience_way
+ maker.channel.description = atom.title.content
+ else
+ maker.channel.description {|d| d.content = atom.title.content}
+ end
end
rss20 = RSS::Parser.parse(rss20_xml)
assert_equal("2.0", rss20.rss_version)
assert_equal(["rss", "2.0", nil], rss20.feed_info)
end
+ def test_to_xml_with_new_api_since_018
+ test_to_xml(false)
+ end
+
private
def setup_entry(entry)
_wrap_assertion do
@@ -277,5 +289,400 @@ module RSS
assert_not_equal("", entry.to_s)
end
end
+
+
+ def assert_atom_person_to_s(target_class)
+ _wrap_assertion do
+ name = "A person"
+ uri = "http://example.com/person/"
+ email = "person@example.com"
+
+ target = target_class.new
+ assert_equal("", target.to_s)
+
+ target = target_class.new
+ person_name = target_class::Name.new
+ person_name.content = name
+ target.name = person_name
+ xml_target = REXML::Document.new(target.to_s).root
+ assert_equal(["name"], xml_target.elements.collect {|e| e.name})
+ assert_equal([name], xml_target.elements.collect {|e| e.text})
+
+ person_uri = target_class::Uri.new
+ person_uri.content = uri
+ target.uri = person_uri
+ xml_target = REXML::Document.new(target.to_s).root
+ assert_equal(["name", "uri"], xml_target.elements.collect {|e| e.name})
+ assert_equal([name, uri], xml_target.elements.collect {|e| e.text})
+
+ person_email = target_class::Email.new
+ person_email.content = email
+ target.email = person_email
+ xml_target = REXML::Document.new(target.to_s).root
+ assert_equal(["name", "uri", "email"],
+ xml_target.elements.collect {|e| e.name})
+ assert_equal([name, uri, email],
+ xml_target.elements.collect {|e| e.text})
+ end
+ end
+
+ def assert_atom_category_to_s(target_class)
+ _wrap_assertion do
+ term = "music"
+ scheme = "http://example.com/music"
+ label = "Music"
+
+ category = target_class.new
+ assert_equal("", category.to_s)
+
+ category = target_class.new
+ category.scheme = scheme
+ assert_equal("", category.to_s)
+
+ category = target_class.new
+ category.label = label
+ assert_equal("", category.to_s)
+
+ category = target_class.new
+ category.scheme = scheme
+ category.label = label
+ assert_equal("", category.to_s)
+
+ category = target_class.new
+ category.term = term
+ xml = REXML::Document.new(category.to_s).root
+ assert_rexml_element([], {"term" => term}, nil, xml)
+
+ category = target_class.new
+ category.term = term
+ category.scheme = scheme
+ xml = REXML::Document.new(category.to_s).root
+ assert_rexml_element([], {"term" => term, "scheme" => scheme}, nil, xml)
+
+ category = target_class.new
+ category.term = term
+ category.label = label
+ xml = REXML::Document.new(category.to_s).root
+ assert_rexml_element([], {"term" => term, "label" => label}, nil, xml)
+
+ category = target_class.new
+ category.term = term
+ category.scheme = scheme
+ category.label = label
+ xml = REXML::Document.new(category.to_s).root
+ attrs = {"term" => term, "scheme" => scheme, "label" => label}
+ assert_rexml_element([], attrs, nil, xml)
+ end
+ end
+
+ def assert_atom_generator_to_s(target_class)
+ _wrap_assertion do
+ content = "Feed generator"
+ uri = "http://example.com/generator"
+ version = "0.0.1"
+
+ generator = target_class.new
+ assert_equal("", generator.to_s)
+
+ generator = target_class.new
+ generator.uri = uri
+ assert_equal("", generator.to_s)
+
+ generator = target_class.new
+ generator.version = version
+ assert_equal("", generator.to_s)
+
+ generator = target_class.new
+ generator.uri = uri
+ generator.version = version
+ assert_equal("", generator.to_s)
+
+ generator = target_class.new
+ generator.content = content
+ xml = REXML::Document.new(generator.to_s).root
+ assert_rexml_element([], {}, content, xml)
+
+ generator = target_class.new
+ generator.content = content
+ generator.uri = uri
+ xml = REXML::Document.new(generator.to_s).root
+ assert_rexml_element([], {"uri" => uri}, content, xml)
+
+ generator = target_class.new
+ generator.content = content
+ generator.version = version
+ xml = REXML::Document.new(generator.to_s).root
+ assert_rexml_element([], {"version" => version}, content, xml)
+
+ generator = target_class.new
+ generator.content = content
+ generator.uri = uri
+ generator.version = version
+ xml = REXML::Document.new(generator.to_s).root
+ assert_rexml_element([], {"uri" => uri, "version" => version},
+ content, xml)
+ end
+ end
+
+ def assert_atom_icon_to_s(target_class)
+ _wrap_assertion do
+ content = "http://example.com/icon.png"
+
+ icon = target_class.new
+ assert_equal("", icon.to_s)
+
+ icon = target_class.new
+ icon.content = content
+ xml = REXML::Document.new(icon.to_s).root
+ assert_rexml_element([], {}, content, xml)
+ end
+ end
+
+ def assert_atom_id_to_s(target_class)
+ _wrap_assertion do
+ content = "http://example.com/1"
+
+ id = target_class.new
+ assert_equal("", id.to_s)
+
+ id = target_class.new
+ id.content = content
+ xml = REXML::Document.new(id.to_s).root
+ assert_rexml_element([], {}, content, xml)
+ end
+ end
+
+ def assert_atom_link_to_s(target_class)
+ _wrap_assertion do
+ href = "http://example.com/atom.xml"
+ rel = "self"
+ type = "application/atom+xml"
+ hreflang = "ja"
+ title = "Atom Feed"
+ length = "801"
+
+ link = target_class.new
+ assert_equal("", link.to_s)
+
+ link = target_class.new
+ link.href = href
+ xml = REXML::Document.new(link.to_s).root
+ assert_rexml_element([], {"href" => href}, nil, xml)
+
+ optional_arguments = %w(rel type hreflang title length)
+ optional_arguments.each do |name|
+ rest = optional_arguments.reject {|x| x == name}
+
+ link = target_class.new
+ link.__send__("#{name}=", eval(name))
+ assert_equal("", link.to_s)
+
+ rest.each do |n|
+ link.__send__("#{n}=", eval(n))
+ assert_equal("", link.to_s)
+ end
+
+ link = target_class.new
+ link.href = href
+ link.__send__("#{name}=", eval(name))
+ attrs = [["href", href], [name, eval(name)]]
+ xml = REXML::Document.new(link.to_s).root
+ assert_rexml_element([], attrs, nil, xml)
+
+ rest.each do |n|
+ link.__send__("#{n}=", eval(n))
+ attrs << [n, eval(n)]
+ xml = REXML::Document.new(link.to_s).root
+ assert_rexml_element([], attrs, nil, xml)
+ end
+ end
+ end
+ end
+
+ def assert_atom_logo_to_s(target_class)
+ _wrap_assertion do
+ content = "http://example.com/logo.png"
+
+ logo = target_class.new
+ assert_equal("", logo.to_s)
+
+ logo = target_class.new
+ logo.content = content
+ xml = REXML::Document.new(logo.to_s).root
+ assert_rexml_element([], {}, content, xml)
+ end
+ end
+
+ def assert_atom_text_construct_to_s(target_class)
+ _wrap_assertion do
+ text_content = "plain text"
+ html_content = "<em>#{text_content}</em>"
+ xhtml_uri = "http://www.w3.org/1999/xhtml"
+ xhtml_em = RSS::XML::Element.new("em", nil, xhtml_uri, {}, text_content)
+ xhtml_content = RSS::XML::Element.new("div", nil, xhtml_uri,
+ {"xmlns" => xhtml_uri},
+ [xhtml_em])
+
+ text = target_class.new
+ assert_equal("", text.to_s)
+
+ text = target_class.new
+ text.type = "text"
+ assert_equal("", text.to_s)
+
+ text = target_class.new
+ text.content = text_content
+ xml = REXML::Document.new(text.to_s).root
+ assert_rexml_element([], {}, text_content, xml)
+
+ text = target_class.new
+ text.type = "text"
+ text.content = text_content
+ xml = REXML::Document.new(text.to_s).root
+ assert_rexml_element([], {"type" => "text"}, text_content, xml)
+
+ text = target_class.new
+ text.type = "html"
+ text.content = html_content
+ xml = REXML::Document.new(text.to_s).root
+ assert_rexml_element([], {"type" => "html"}, html_content, xml)
+
+ text = target_class.new
+ text.type = "xhtml"
+ text.content = xhtml_content
+ assert_equal("", text.to_s)
+
+ text = target_class.new
+ text.type = "xhtml"
+ text.__send__(target_class.xml_setter, xhtml_content)
+ xml = REXML::Document.new(text.to_s).root
+ assert_rexml_element([[xhtml_uri, "div"]], {"type" => "xhtml"},
+ nil, xml)
+ assert_rexml_element([[xhtml_uri, "em"]], nil, nil, xml.elements[1])
+ assert_rexml_element([], {}, text_content, xml.elements[1].elements[1])
+
+ text = target_class.new
+ text.type = "xhtml"
+ text.__send__(target_class.xml_setter, xhtml_em)
+ xml = REXML::Document.new(text.to_s).root
+ assert_rexml_element([[xhtml_uri, "div"]], {"type" => "xhtml"},
+ nil, xml)
+ assert_rexml_element([[xhtml_uri, "em"]], nil, nil, xml.elements[1])
+ assert_rexml_element([], {}, text_content, xml.elements[1].elements[1])
+ end
+ end
+
+ def assert_atom_date_construct_to_s(target_class)
+ _wrap_assertion do
+ date = target_class.new
+ assert_equal("", date.to_s)
+
+ [
+ "2003-12-13T18:30:02Z",
+ "2003-12-13T18:30:02.25Z",
+ "2003-12-13T18:30:02+01:00",
+ "2003-12-13T18:30:02.25+01:00",
+ ].each do |content|
+ date = target_class.new
+ date.content = content
+ xml = REXML::Document.new(date.to_s).root
+ assert_rexml_element([], {}, content, xml, :time)
+
+ date = target_class.new
+ date.content = Time.parse(content)
+ xml = REXML::Document.new(date.to_s).root
+ assert_rexml_element([], {}, content, xml, :time)
+ end
+ end
+ end
+
+ def assert_atom_content_to_s(target_class)
+ _wrap_assertion do
+ assert_atom_text_construct_to_s(target_class)
+ assert_atom_content_inline_other_xml_to_s(target_class)
+ assert_atom_content_inline_other_text_to_s(target_class)
+ assert_atom_content_inline_other_base64_to_s(target_class)
+ assert_atom_content_out_of_line_to_s(target_class)
+ end
+ end
+
+ def assert_atom_content_inline_other_xml_to_s(target_class)
+ _wrap_assertion do
+ content = target_class.new
+ content.type = "text/xml"
+ assert_equal("", content.to_s)
+
+ content = target_class.new
+ content.type = "text/xml"
+ content.xml = RSS::XML::Element.new("em")
+ xml = REXML::Document.new(content.to_s).root
+ assert_rexml_element([["", "em"]], {"type" => "text/xml"}, nil, xml)
+ end
+ end
+
+ def assert_atom_content_inline_other_text_to_s(target_class)
+ _wrap_assertion do
+ content = target_class.new
+ content.type = "text/plain"
+ assert_equal("", content.to_s)
+
+ content = target_class.new
+ content.type = "text/plain"
+ content.xml = RSS::XML::Element.new("em")
+ assert_equal("", content.to_s)
+
+ content = target_class.new
+ content.type = "text/plain"
+ content.content = "content"
+ xml = REXML::Document.new(content.to_s).root
+ assert_rexml_element([], {"type" => "text/plain"}, "content", xml)
+ end
+ end
+
+ def assert_atom_content_inline_other_base64_to_s(target_class)
+ _wrap_assertion do
+ require "zlib"
+
+ text = ""
+ char = "a"
+ 100.times do |i|
+ text << char
+ char.succ!
+ end
+
+ type = "application/zip"
+ original_content = Zlib::Deflate.deflate(text)
+
+ content = target_class.new
+ content.type = type
+ content.content = original_content
+ xml = REXML::Document.new(content.to_s).root
+ assert_rexml_element([], {"type" => type},
+ Base64.encode64(original_content), xml)
+ end
+ end
+
+ def assert_atom_content_out_of_line_to_s(target_class)
+ _wrap_assertion do
+ type = "application/zip"
+ src = "http://example.com/xxx.zip"
+
+ content = target_class.new
+ assert(!content.out_of_line?)
+ content.src = src
+ assert(content.out_of_line?)
+ xml = REXML::Document.new(content.to_s).root
+ assert_rexml_element([], {"src" => src}, nil, xml)
+
+ content = target_class.new
+ assert(!content.out_of_line?)
+ content.type = type
+ assert(!content.out_of_line?)
+ content.src = src
+ assert(content.out_of_line?)
+ xml = REXML::Document.new(content.to_s).root
+ assert_rexml_element([], {"type" => type, "src" => src}, nil, xml)
+ end
+ end
end
end
diff --git a/test/rss/test_image.rb b/test/rss/test_image.rb
index e4e50c0115c..45e99c3c23a 100644
--- a/test/rss/test_image.rb
+++ b/test/rss/test_image.rb
@@ -65,12 +65,12 @@ EOR
@rss = Parser.parse(@rss_source)
end
-
+
def test_parser
assert_nothing_raised do
Parser.parse(@rss_source)
end
-
+
assert_too_much_tag("favicon", "channel") do
Parser.parse(make_RDF(<<-EOR, @ns))
#{make_channel(@channel_nodes * 2)}
@@ -88,7 +88,7 @@ EOR
EOR
end
end
-
+
def test_favicon_accessor
favicon = @rss.channel.image_favicon
[
@@ -145,7 +145,7 @@ EOR
image_item.__send__("#{name}=", attrs[full_name])
assert_equal(attrs[full_name], image_item.__send__(name))
end
-
+
[
["width", "image:width", "111"],
["image_width", "image:width", "44"],
@@ -188,7 +188,7 @@ EOR
actual = REXML::Document.new(item.image_item.to_s(false, ""))
assert_equal(expected[0].attributes, actual[0].attributes)
-
+
%w(image:height image:width dc:title).each do |name|
actual_target = actual.elements["//#{name}"]
expected_target = expected.elements["//#{name}"]
diff --git a/test/rss/test_inherit.rb b/test/rss/test_inherit.rb
index fc4bbbe76a1..f73096f4780 100644
--- a/test/rss/test_inherit.rb
+++ b/test/rss/test_inherit.rb
@@ -9,7 +9,7 @@ module RSS
def self.indent_size; 1; end
def self.tag_name; 'image'; end
end
-
+
def setup
@rss = make_RDF(<<-EOR)
#{make_channel}
@@ -18,7 +18,7 @@ module RSS
#{make_textinput}
EOR
end
-
+
def test_inherit
rss = RSS::Parser.parse(@rss)
orig_image = rss.image
@@ -36,6 +36,5 @@ EOR
assert_equal("#{prefix} #{orig_image.url}", new_image.url)
assert_equal("#{prefix} #{orig_image.link}", new_image.link)
end
-
end
end
diff --git a/test/rss/test_itunes.rb b/test/rss/test_itunes.rb
new file mode 100644
index 00000000000..3663e2c77a2
--- /dev/null
+++ b/test/rss/test_itunes.rb
@@ -0,0 +1,347 @@
+require "cgi"
+require "rexml/document"
+
+require "rss-testcase"
+
+require "rss/2.0"
+require "rss/itunes"
+
+module RSS
+ class TestITunes < TestCase
+ def test_author
+ assert_itunes_author(%w(channel)) do |content, xmlns|
+ make_rss20(make_channel20(content), xmlns)
+ end
+
+ assert_itunes_author(%w(items last)) do |content, xmlns|
+ make_rss20(make_channel20(make_item20(content)), xmlns)
+ end
+ end
+
+ def test_block
+ assert_itunes_block(%w(items last)) do |content, xmlns|
+ make_rss20(make_channel20(make_item20(content)), xmlns)
+ end
+ end
+
+ def test_category
+ assert_itunes_category(%w(channel)) do |content, xmlns|
+ make_rss20(make_channel20(content), xmlns)
+ end
+ end
+
+ def test_image
+ assert_itunes_image(%w(channel)) do |content, xmlns|
+ make_rss20(make_channel20(content), xmlns)
+ end
+ end
+
+ def test_duration
+ assert_itunes_duration(%w(items last)) do |content, xmlns|
+ make_rss20(make_channel20(make_item20(content)), xmlns)
+ end
+ end
+
+ def test_explicit
+ assert_itunes_explicit(%w(channel)) do |content, xmlns|
+ make_rss20(make_channel20(content), xmlns)
+ end
+
+ assert_itunes_explicit(%w(items last)) do |content, xmlns|
+ make_rss20(make_channel20(make_item20(content)), xmlns)
+ end
+ end
+
+ def test_keywords
+ assert_itunes_keywords(%w(channel)) do |content, xmlns|
+ make_rss20(make_channel20(content), xmlns)
+ end
+
+ assert_itunes_keywords(%w(items last)) do |content, xmlns|
+ make_rss20(make_channel20(make_item20(content)), xmlns)
+ end
+ end
+
+ def test_new_feed_url
+ assert_itunes_new_feed_url(%w(channel)) do |content, xmlns|
+ make_rss20(make_channel20(content), xmlns)
+ end
+ end
+
+ def test_owner
+ assert_itunes_owner(%w(channel)) do |content, xmlns|
+ make_rss20(make_channel20(content), xmlns)
+ end
+ end
+
+ def test_subtitle
+ assert_itunes_subtitle(%w(channel)) do |content, xmlns|
+ make_rss20(make_channel20(content), xmlns)
+ end
+
+ assert_itunes_subtitle(%w(items last)) do |content, xmlns|
+ make_rss20(make_channel20(make_item20(content)), xmlns)
+ end
+ end
+
+ def test_summary
+ assert_itunes_summary(%w(channel)) do |content, xmlns|
+ make_rss20(make_channel20(content), xmlns)
+ end
+
+ assert_itunes_summary(%w(items last)) do |content, xmlns|
+ make_rss20(make_channel20(make_item20(content)), xmlns)
+ end
+ end
+
+ private
+ def itunes_rss20_parse(content, &maker)
+ xmlns = {"itunes" => "http://www.itunes.com/dtds/podcast-1.0.dtd"}
+ rss20_xml = maker.call(content, xmlns)
+ ::RSS::Parser.parse(rss20_xml)
+ end
+
+ def assert_itunes_author(readers, &rss20_maker)
+ _wrap_assertion do
+ author = "John Lennon"
+ rss20 = itunes_rss20_parse(tag("itunes:author", author), &rss20_maker)
+ target = chain_reader(rss20, readers)
+ assert_equal(author, target.itunes_author)
+ end
+ end
+
+ def _assert_itunes_block(value, boolean_value, readers, &rss20_maker)
+ rss20 = itunes_rss20_parse(tag("itunes:block", value), &rss20_maker)
+ target = chain_reader(rss20, readers)
+ assert_equal(value, target.itunes_block)
+ assert_equal(boolean_value, target.itunes_block?)
+ end
+
+ def assert_itunes_block(readers, &rss20_maker)
+ _wrap_assertion do
+ _assert_itunes_block("yes", true, readers, &rss20_maker)
+ _assert_itunes_block("Yes", true, readers, &rss20_maker)
+ _assert_itunes_block("no", false, readers, &rss20_maker)
+ _assert_itunes_block("", false, readers, &rss20_maker)
+ end
+ end
+
+ def _assert_itunes_category(categories, readers, &rss20_maker)
+ cats = categories.collect do |category|
+ if category.is_a?(Array)
+ category, sub_category = category
+ tag("itunes:category",
+ tag("itunes:category", nil, {"text" => sub_category}),
+ {"text" => category})
+ else
+ tag("itunes:category", nil, {"text" => category})
+ end
+ end.join
+ rss20 = itunes_rss20_parse(cats, &rss20_maker)
+ target = chain_reader(rss20, readers)
+ actual_categories = target.itunes_categories.collect do |category|
+ cat = category.text
+ if category.itunes_categories.empty?
+ cat
+ else
+ [cat, *category.itunes_categories.collect {|c| c.text}]
+ end
+ end
+ assert_equal(categories, actual_categories)
+ end
+
+ def assert_itunes_category(readers, &rss20_maker)
+ _wrap_assertion do
+ _assert_itunes_category(["Audio Blogs"], readers, &rss20_maker)
+ _assert_itunes_category([["Arts & Entertainment", "Games"]],
+ readers, &rss20_maker)
+ _assert_itunes_category([["Arts & Entertainment", "Games"],
+ ["Technology", "Computers"],
+ "Audio Blogs"],
+ readers, &rss20_maker)
+ end
+ end
+
+ def assert_itunes_image(readers, &rss20_maker)
+ _wrap_assertion do
+ url = "http://example.com/podcasts/everything/AllAboutEverything.jpg"
+ content = tag("itunes:image", nil, {"href" => url})
+ rss20 = itunes_rss20_parse(content, &rss20_maker)
+ target = chain_reader(rss20, readers)
+ assert_not_nil(target.itunes_image)
+ assert_equal(url, target.itunes_image.href)
+
+ assert_missing_attribute("image", "href") do
+ content = tag("itunes:image")
+ itunes_rss20_parse(content, &rss20_maker)
+ end
+ end
+ end
+
+ def _assert_itunes_duration(hour, minute, second, value,
+ readers, &rss20_maker)
+ content = tag("itunes:duration", value)
+ rss20 = itunes_rss20_parse(content, &rss20_maker)
+ duration = chain_reader(rss20, readers).itunes_duration
+ assert_equal(value, duration.content)
+ assert_equal(hour, duration.hour)
+ assert_equal(minute, duration.minute)
+ assert_equal(second, duration.second)
+ end
+
+ def _assert_itunes_duration_not_available_value(value, &rss20_maker)
+ assert_not_available_value("duration", value) do
+ content = tag("itunes:duration", value)
+ itunes_rss20_parse(content, &rss20_maker)
+ end
+ end
+
+ def assert_itunes_duration(readers, &rss20_maker)
+ _wrap_assertion do
+ _assert_itunes_duration(7, 14, 5, "07:14:05", readers, &rss20_maker)
+ _assert_itunes_duration(7, 14, 5, "7:14:05", readers, &rss20_maker)
+ _assert_itunes_duration(0, 4, 55, "04:55", readers, &rss20_maker)
+ _assert_itunes_duration(0, 4, 5, "4:05", readers, &rss20_maker)
+
+ _assert_itunes_duration_not_available_value("5", &rss20_maker)
+ _assert_itunes_duration_not_available_value("09:07:14:05", &rss20_maker)
+ _assert_itunes_duration_not_available_value("10:5", &rss20_maker)
+ _assert_itunes_duration_not_available_value("10:03:5", &rss20_maker)
+ _assert_itunes_duration_not_available_value("10:3:05", &rss20_maker)
+
+ _assert_itunes_duration_not_available_value("xx:xx:xx", &rss20_maker)
+ end
+ end
+
+ def _assert_itunes_explicit(explicit, value, readers, &rss20_maker)
+ content = tag("itunes:explicit", value)
+ rss20 = itunes_rss20_parse(content, &rss20_maker)
+ target = chain_reader(rss20, readers)
+ assert_equal(value, target.itunes_explicit)
+ assert_equal(explicit, target.itunes_explicit?)
+ end
+
+ def assert_itunes_explicit(readers, &rss20_maker)
+ _wrap_assertion do
+ _assert_itunes_explicit(true, "yes", readers, &rss20_maker)
+ _assert_itunes_explicit(false, "clean", readers, &rss20_maker)
+ _assert_itunes_explicit(nil, "no", readers, &rss20_maker)
+ end
+ end
+
+ def _assert_itunes_keywords(keywords, value, readers, &rss20_maker)
+ content = tag("itunes:keywords", value)
+ rss20 = itunes_rss20_parse(content, &rss20_maker)
+ target = chain_reader(rss20, readers)
+ assert_equal(keywords, target.itunes_keywords)
+ end
+
+ def assert_itunes_keywords(readers, &rss20_maker)
+ _wrap_assertion do
+ _assert_itunes_keywords(["salt"], "salt", readers, &rss20_maker)
+ _assert_itunes_keywords(["salt"], " salt ", readers, &rss20_maker)
+ _assert_itunes_keywords(["salt", "pepper", "shaker", "exciting"],
+ "salt, pepper, shaker, exciting",
+ readers, &rss20_maker)
+ _assert_itunes_keywords(["metric", "socket", "wrenches", "toolsalt"],
+ "metric, socket, wrenches, toolsalt",
+ readers, &rss20_maker)
+ _assert_itunes_keywords(["olitics", "red", "blue", "state"],
+ "olitics, red, blue, state",
+ readers, &rss20_maker)
+ end
+ end
+
+ def assert_itunes_new_feed_url(readers, &rss20_maker)
+ _wrap_assertion do
+ url = "http://newlocation.com/example.rss"
+ content = tag("itunes:new-feed-url", url)
+ rss20 = itunes_rss20_parse(content, &rss20_maker)
+ target = chain_reader(rss20, readers)
+ assert_equal(url, target.itunes_new_feed_url)
+ end
+ end
+
+ def _assert_itunes_owner(name, email, readers, &rss20_maker)
+ content = tag("itunes:owner",
+ tag("itunes:name", name) + tag("itunes:email", email))
+ rss20 = itunes_rss20_parse(content, &rss20_maker)
+ owner = chain_reader(rss20, readers).itunes_owner
+ assert_equal(name, owner.itunes_name)
+ assert_equal(email, owner.itunes_email)
+ end
+
+ def assert_itunes_owner(readers, &rss20_maker)
+ _wrap_assertion do
+ _assert_itunes_owner("John Doe", "john.doe@example.com",
+ readers, &rss20_maker)
+
+ assert_missing_tag("name", "owner") do
+ content = tag("itunes:owner")
+ itunes_rss20_parse(content, &rss20_maker)
+ end
+
+ assert_missing_tag("name", "owner") do
+ content = tag("itunes:owner",
+ tag("itunes:email", "john.doe@example.com"))
+ itunes_rss20_parse(content, &rss20_maker)
+ end
+
+ assert_missing_tag("email", "owner") do
+ content = tag("itunes:owner", tag("itunes:name", "John Doe"))
+ itunes_rss20_parse(content, &rss20_maker)
+ end
+ end
+ end
+
+ def _assert_itunes_subtitle(value, readers, &rss20_maker)
+ content = tag("itunes:subtitle", value)
+ rss20 = itunes_rss20_parse(content, &rss20_maker)
+ target = chain_reader(rss20, readers)
+ assert_equal(value, target.itunes_subtitle)
+ end
+
+ def assert_itunes_subtitle(readers, &rss20_maker)
+ _wrap_assertion do
+ _assert_itunes_subtitle("A show about everything", readers, &rss20_maker)
+ _assert_itunes_subtitle("A short primer on table spices",
+ readers, &rss20_maker)
+ _assert_itunes_subtitle("Comparing socket wrenches is fun!",
+ readers, &rss20_maker)
+ _assert_itunes_subtitle("Red + Blue != Purple", readers, &rss20_maker)
+ end
+ end
+
+ def _assert_itunes_summary(value, readers, &rss20_maker)
+ content = tag("itunes:summary", value)
+ rss20 = itunes_rss20_parse(content, &rss20_maker)
+ target = chain_reader(rss20, readers)
+ assert_equal(value, target.itunes_summary)
+ end
+
+ def assert_itunes_summary(readers, &rss20_maker)
+ _wrap_assertion do
+ _assert_itunes_summary("All About Everything is a show about " +
+ "everything. Each week we dive into any " +
+ "subject known to man and talk about it as " +
+ "much as we can. Look for our Podcast in " +
+ "the iTunes Music Store",
+ readers, &rss20_maker)
+ _assert_itunes_summary("This week we talk about salt and pepper " +
+ "shakers, comparing and contrasting pour " +
+ "rates, construction materials, and overall " +
+ "aesthetics. Come and join the party!",
+ readers, &rss20_maker)
+ _assert_itunes_summary("This week we talk about metric vs. old " +
+ "english socket wrenches. Which one is " +
+ "better? Do you really need both? Get all " +
+ "of your answers here.",
+ readers, &rss20_maker)
+ _assert_itunes_summary("This week we talk about surviving in a " +
+ "Red state if you’re a Blue person. Or " +
+ "vice versa.",
+ readers, &rss20_maker)
+ end
+ end
+ end
+end
diff --git a/test/rss/test_maker_0.9.rb b/test/rss/test_maker_0.9.rb
index 0551dc28006..df92945a86a 100644
--- a/test/rss/test_maker_0.9.rb
+++ b/test/rss/test_maker_0.9.rb
@@ -267,7 +267,7 @@ module RSS
end
end
- def test_items
+ def test_items(with_convenience_way=true)
title = "TITLE"
link = "http://hoge.com/"
description = "text hoge fuga"
@@ -301,10 +301,10 @@ module RSS
setup_dummy_channel(maker)
item_size.times do |i|
- maker.items.new_item do |item|
- item.title = "#{title}#{i}"
- item.link = "#{link}#{i}"
- item.description = "#{description}#{i}"
+ maker.items.new_item do |_item|
+ _item.title = "#{title}#{i}"
+ _item.link = "#{link}#{i}"
+ _item.description = "#{description}#{i}"
end
end
maker.items.do_sort = true
@@ -312,36 +312,44 @@ module RSS
setup_dummy_image(maker)
end
assert_equal(item_size, rss.items.size)
- rss.channel.items.each_with_index do |item, i|
- assert_equal("#{title}#{i}", item.title)
- assert_equal("#{link}#{i}", item.link)
- assert_equal("#{description}#{i}", item.description)
+ rss.channel.items.each_with_index do |_item, i|
+ assert_equal("#{title}#{i}", _item.title)
+ assert_equal("#{link}#{i}", _item.link)
+ assert_equal("#{description}#{i}", _item.description)
end
rss = RSS::Maker.make("0.91") do |maker|
setup_dummy_channel(maker)
item_size.times do |i|
- maker.items.new_item do |item|
- item.title = "#{title}#{i}"
- item.link = "#{link}#{i}"
- item.description = "#{description}#{i}"
+ maker.items.new_item do |_item|
+ _item.title = "#{title}#{i}"
+ _item.link = "#{link}#{i}"
+ _item.description = "#{description}#{i}"
end
end
maker.items.do_sort = Proc.new do |x, y|
- y.title.content[-1] <=> x.title.content[-1]
+ if with_convenience_way
+ y.title[-1] <=> x.title[-1]
+ else
+ y.title {|t| t.content[-1]} <=> x.title {|t| t.content[-1]}
+ end
end
setup_dummy_image(maker)
end
assert_equal(item_size, rss.items.size)
- rss.channel.items.reverse.each_with_index do |item, i|
- assert_equal("#{title}#{i}", item.title)
- assert_equal("#{link}#{i}", item.link)
- assert_equal("#{description}#{i}", item.description)
+ rss.channel.items.reverse.each_with_index do |_item, i|
+ assert_equal("#{title}#{i}", _item.title)
+ assert_equal("#{link}#{i}", _item.link)
+ assert_equal("#{description}#{i}", _item.description)
end
end
+ def test_items_with_new_api_since_018
+ test_items(false)
+ end
+
def test_textInput
title = "fugafuga"
description = "text hoge fuga"
diff --git a/test/rss/test_maker_1.0.rb b/test/rss/test_maker_1.0.rb
index cc1e58c1a20..60cc3708a72 100644
--- a/test/rss/test_maker_1.0.rb
+++ b/test/rss/test_maker_1.0.rb
@@ -209,7 +209,7 @@ module RSS
end
end
- def test_items
+ def test_items(with_convenience_way=true)
title = "TITLE"
link = "http://hoge.com/"
description = "text hoge fuga"
@@ -242,42 +242,46 @@ module RSS
setup_dummy_channel(maker)
item_size.times do |i|
- maker.items.new_item do |item|
- item.title = "#{title}#{i}"
- item.link = "#{link}#{i}"
- item.description = "#{description}#{i}"
+ maker.items.new_item do |_item|
+ _item.title = "#{title}#{i}"
+ _item.link = "#{link}#{i}"
+ _item.description = "#{description}#{i}"
end
end
maker.items.do_sort = true
end
assert_equal(item_size, rss.items.size)
- rss.items.each_with_index do |item, i|
- assert_equal("#{link}#{i}", item.about)
- assert_equal("#{title}#{i}", item.title)
- assert_equal("#{link}#{i}", item.link)
- assert_equal("#{description}#{i}", item.description)
+ rss.items.each_with_index do |_item, i|
+ assert_equal("#{link}#{i}", _item.about)
+ assert_equal("#{title}#{i}", _item.title)
+ assert_equal("#{link}#{i}", _item.link)
+ assert_equal("#{description}#{i}", _item.description)
end
rss = RSS::Maker.make("1.0") do |maker|
setup_dummy_channel(maker)
item_size.times do |i|
- maker.items.new_item do |item|
- item.title = "#{title}#{i}"
- item.link = "#{link}#{i}"
- item.description = "#{description}#{i}"
+ maker.items.new_item do |_item|
+ _item.title = "#{title}#{i}"
+ _item.link = "#{link}#{i}"
+ _item.description = "#{description}#{i}"
end
end
maker.items.do_sort = Proc.new do |x, y|
- y.title.content[-1] <=> x.title.content[-1]
+ if with_convenience_way
+ y.title[-1] <=> x.title[-1]
+ else
+ y.title {|t| t.content[-1]} <=> x.title {|t| t.content[-1]}
+ end
end
end
assert_equal(item_size, rss.items.size)
- rss.items.reverse.each_with_index do |item, i|
- assert_equal("#{link}#{i}", item.about)
- assert_equal("#{title}#{i}", item.title)
- assert_equal("#{link}#{i}", item.link)
- assert_equal("#{description}#{i}", item.description)
+ rss.items.reverse.each_with_index do |_item, i|
+ assert_equal("#{link}#{i}", _item.about)
+ assert_equal("#{title}#{i}", _item.title)
+ assert_equal("#{link}#{i}", _item.link)
+ assert_equal("#{description}#{i}", _item.description)
end
max_size = item_size / 2
@@ -285,20 +289,20 @@ module RSS
setup_dummy_channel(maker)
item_size.times do |i|
- maker.items.new_item do |item|
- item.title = "#{title}#{i}"
- item.link = "#{link}#{i}"
- item.description = "#{description}#{i}"
+ maker.items.new_item do |_item|
+ _item.title = "#{title}#{i}"
+ _item.link = "#{link}#{i}"
+ _item.description = "#{description}#{i}"
end
end
maker.items.max_size = max_size
end
assert_equal(max_size, rss.items.size)
- rss.items.each_with_index do |item, i|
- assert_equal("#{link}#{i}", item.about)
- assert_equal("#{title}#{i}", item.title)
- assert_equal("#{link}#{i}", item.link)
- assert_equal("#{description}#{i}", item.description)
+ rss.items.each_with_index do |_item, i|
+ assert_equal("#{link}#{i}", _item.about)
+ assert_equal("#{title}#{i}", _item.title)
+ assert_equal("#{link}#{i}", _item.link)
+ assert_equal("#{description}#{i}", _item.description)
end
max_size = 0
@@ -307,10 +311,10 @@ module RSS
setup_dummy_channel(maker)
item_size.times do |i|
- maker.items.new_item do |item|
- item.title = "#{title}#{i}"
- item.link = "#{link}#{i}"
- item.description = "#{description}#{i}"
+ maker.items.new_item do |_item|
+ _item.title = "#{title}#{i}"
+ _item.link = "#{link}#{i}"
+ _item.description = "#{description}#{i}"
end
end
maker.items.max_size = max_size
@@ -322,23 +326,27 @@ module RSS
setup_dummy_channel(maker)
item_size.times do |i|
- maker.items.new_item do |item|
- item.title = "#{title}#{i}"
- item.link = "#{link}#{i}"
- item.description = "#{description}#{i}"
+ maker.items.new_item do |_item|
+ _item.title = "#{title}#{i}"
+ _item.link = "#{link}#{i}"
+ _item.description = "#{description}#{i}"
end
end
maker.items.max_size = max_size
end
assert_equal(item_size + max_size + 1, rss.items.size)
- rss.items.each_with_index do |item, i|
- assert_equal("#{link}#{i}", item.about)
- assert_equal("#{title}#{i}", item.title)
- assert_equal("#{link}#{i}", item.link)
- assert_equal("#{description}#{i}", item.description)
+ rss.items.each_with_index do |_item, i|
+ assert_equal("#{link}#{i}", _item.about)
+ assert_equal("#{title}#{i}", _item.title)
+ assert_equal("#{link}#{i}", _item.link)
+ assert_equal("#{description}#{i}", _item.description)
end
end
+ def test_items_with_new_api_since_018
+ test_items(false)
+ end
+
def test_not_valid_items
title = "TITLE"
link = "http://hoge.com/"
diff --git a/test/rss/test_maker_2.0.rb b/test/rss/test_maker_2.0.rb
index 605d439a680..8fd9134f701 100644
--- a/test/rss/test_maker_2.0.rb
+++ b/test/rss/test_maker_2.0.rb
@@ -353,7 +353,7 @@ module RSS
assert_nil(rss.image)
end
- def test_items
+ def test_items(with_convenience_way=true)
title = "TITLE"
link = "http://hoge.com/"
description = "text hoge fuga"
@@ -407,7 +407,11 @@ module RSS
end
end
maker.items.do_sort = Proc.new do |x, y|
- y.title.content[-1] <=> x.title.content[-1]
+ if with_convenience_way
+ y.title[-1] <=> x.title[-1]
+ else
+ y.title {|t| t.content[-1]} <=> x.title {|t| t.content[-1]}
+ end
end
end
assert_equal(item_size, rss.items.size)
@@ -422,6 +426,10 @@ module RSS
end
end
+ def test_items_with_new_api_since_018
+ test_items(false)
+ end
+
def test_guid
isPermaLink = "true"
content = "http://inessential.com/2002/09/01.php#a2"
diff --git a/test/rss/test_maker_atom_feed.rb b/test/rss/test_maker_atom_feed.rb
index f4c5cc2a3da..e5bf0e23b27 100644
--- a/test/rss/test_maker_atom_feed.rb
+++ b/test/rss/test_maker_atom_feed.rb
@@ -268,7 +268,16 @@ module RSS
nil, nil,
"maker.channel.description") do |maker|
setup_dummy_channel_atom(maker)
- maker.channel.description.content = nil
+ maker.channel.description = nil
+ end
+
+ assert_maker_atom_text_construct("feed",
+ ["channel", "subtitle"],
+ ["subtitle"],
+ nil, nil,
+ "maker.channel.description") do |maker|
+ setup_dummy_channel_atom(maker)
+ maker.channel.description {|d| d.content = nil}
end
assert_maker_atom_text_construct("feed",
diff --git a/test/rss/test_maker_itunes.rb b/test/rss/test_maker_itunes.rb
new file mode 100644
index 00000000000..1d4e323057a
--- /dev/null
+++ b/test/rss/test_maker_itunes.rb
@@ -0,0 +1,471 @@
+require "rss-testcase"
+
+require "rss/maker"
+
+module RSS
+ class TestMakerITunes < TestCase
+ def test_author
+ assert_maker_itunes_author(%w(channel))
+ assert_maker_itunes_author(%w(items last))
+ end
+
+ def test_block
+ assert_maker_itunes_block(%w(channel))
+ assert_maker_itunes_block(%w(items last))
+ end
+
+ def test_category
+ assert_maker_itunes_category(%w(channel))
+ end
+
+ def test_image
+ assert_maker_itunes_image(%w(channel))
+ end
+
+ def test_duration
+ assert_maker_itunes_duration(%w(items last))
+ end
+
+ def test_explicit
+ assert_maker_itunes_explicit(%w(channel))
+ assert_maker_itunes_explicit(%w(items last))
+ end
+
+ def test_keywords
+ assert_maker_itunes_keywords(%w(channel))
+ assert_maker_itunes_keywords(%w(items last))
+ end
+
+ def test_new_feed_url
+ assert_maker_itunes_new_feed_url(%w(channel))
+ end
+
+ def test_owner
+ assert_maker_itunes_owner(%w(channel))
+ end
+
+ def test_subtitle
+ assert_maker_itunes_subtitle(%w(channel))
+ assert_maker_itunes_subtitle(%w(items last))
+ end
+
+ def test_summary
+ assert_maker_itunes_summary(%w(channel))
+ assert_maker_itunes_summary(%w(items last))
+ end
+
+ private
+
+ def assert_maker_itunes_author(maker_readers, feed_readers=nil)
+ _wrap_assertion do
+ feed_readers ||= maker_readers
+ author = "John Doe"
+ rss20 = ::RSS::Maker.make("rss2.0") do |maker|
+ setup_dummy_channel(maker)
+ setup_dummy_item(maker)
+
+ target = chain_reader(maker, maker_readers)
+ target.itunes_author = author
+ end
+ target = chain_reader(rss20, feed_readers)
+ assert_equal(author, target.itunes_author)
+ end
+ end
+
+ def _assert_maker_itunes_block(value, boolean_value, maker_readers,
+ feed_readers)
+ rss20 = ::RSS::Maker.make("rss2.0") do |maker|
+ setup_dummy_channel(maker)
+ setup_dummy_item(maker)
+
+ target = chain_reader(maker, maker_readers)
+ target.itunes_block = value
+ assert_equal(value, target.itunes_block)
+ assert_equal(boolean_value, target.itunes_block?)
+ end
+ target = chain_reader(rss20, feed_readers)
+ if [true, false].include?(value)
+ feed_expected_value = value = value ? "yes" : "no"
+ else
+ feed_expected_value = value
+ end
+ assert_equal(value, target.itunes_block)
+ assert_equal(boolean_value, target.itunes_block?)
+ end
+
+ def assert_maker_itunes_block(maker_readers, feed_readers=nil)
+ _wrap_assertion do
+ feed_readers ||= maker_readers
+ _assert_maker_itunes_block("yes", true, maker_readers, feed_readers)
+ _assert_maker_itunes_block("Yes", true, maker_readers, feed_readers)
+ _assert_maker_itunes_block("no", false, maker_readers, feed_readers)
+ _assert_maker_itunes_block("", false, maker_readers, feed_readers)
+ _assert_maker_itunes_block(true, true, maker_readers, feed_readers)
+ _assert_maker_itunes_block(false, false, maker_readers, feed_readers)
+ _assert_maker_itunes_block(nil, false, maker_readers, feed_readers)
+ end
+ end
+
+ def _assert_maker_itunes_category(categories, maker_readers, feed_readers)
+ rss20 = ::RSS::Maker.make("rss2.0") do |maker|
+ setup_dummy_channel(maker)
+ setup_dummy_item(maker)
+
+ target = chain_reader(maker, maker_readers)
+ categories.each do |category|
+ sub_target = target.itunes_categories
+ if category.is_a?(Array)
+ category.each do |sub_category|
+ sub_target = sub_target.new_category
+ sub_target.text = sub_category
+ end
+ else
+ sub_target.new_category.text = category
+ end
+ end
+ end
+
+ target = chain_reader(rss20, feed_readers)
+ actual_categories = target.itunes_categories.collect do |category|
+ cat = category.text
+ if category.itunes_categories.empty?
+ cat
+ else
+ [cat, *category.itunes_categories.collect {|c| c.text}]
+ end
+ end
+ assert_equal(categories, actual_categories)
+ end
+
+ def assert_maker_itunes_category(maker_readers, feed_readers=nil)
+ _wrap_assertion do
+ feed_readers ||= maker_readers
+ _assert_maker_itunes_category(["Audio Blogs"],
+ maker_readers, feed_readers)
+ _assert_maker_itunes_category([["Arts & Entertainment", "Games"]],
+ maker_readers, feed_readers)
+ _assert_maker_itunes_category([["Arts & Entertainment", "Games"],
+ ["Technology", "Computers"],
+ "Audio Blogs"],
+ maker_readers, feed_readers)
+ end
+ end
+
+ def assert_maker_itunes_image(maker_readers, feed_readers=nil)
+ _wrap_assertion do
+ feed_readers ||= maker_readers
+ url = "http://example.com/podcasts/everything/AllAboutEverything.jpg"
+
+ rss20 = ::RSS::Maker.make("rss2.0") do |maker|
+ setup_dummy_channel(maker)
+ setup_dummy_item(maker)
+
+ target = chain_reader(maker, maker_readers)
+ target.itunes_image = url
+ end
+
+ target = chain_reader(rss20, feed_readers)
+ assert_not_nil(target.itunes_image)
+ assert_equal(url, target.itunes_image.href)
+ end
+ end
+
+ def _assert_maker_itunes_duration(hour, minute, second, value,
+ maker_readers, feed_readers)
+ _assert_maker_itunes_duration_by_value(hour, minute, second, value,
+ maker_readers, feed_readers)
+ _assert_maker_itunes_duration_by_hour_minute_second(hour, minute, second,
+ value,
+ maker_readers,
+ feed_readers)
+ end
+
+ def _assert_maker_itunes_duration_by(hour, minute, second, value,
+ maker_readers, feed_readers)
+ expected_value = nil
+ rss20 = ::RSS::Maker.make("rss2.0") do |maker|
+ setup_dummy_channel(maker)
+ setup_dummy_item(maker)
+
+ target = chain_reader(maker, maker_readers)
+ expected_value = yield(target)
+ assert_equal(expected_value, target.itunes_duration)
+ target.itunes_duration do |duration|
+ assert_equal([hour, minute, second, expected_value],
+ [duration.hour, duration.minute,
+ duration.second, duration.content])
+ end
+ end
+ target = chain_reader(rss20, feed_readers)
+ duration = target.itunes_duration
+ assert_not_nil(duration)
+ assert_equal([hour, minute, second, expected_value],
+ [duration.hour, duration.minute,
+ duration.second, duration.content])
+ end
+
+ def _assert_maker_itunes_duration_by_value(hour, minute, second, value,
+ maker_readers, feed_readers)
+ _assert_maker_itunes_duration_by(hour, minute, second, value,
+ maker_readers, feed_readers) do |target|
+ target.itunes_duration = value
+ value
+ end
+ end
+
+ def _assert_maker_itunes_duration_by_hour_minute_second(hour, minute, second,
+ value,
+ maker_readers,
+ feed_readers)
+ _assert_maker_itunes_duration_by(hour, minute, second, value,
+ maker_readers, feed_readers) do |target|
+ target.itunes_duration do |duration|
+ duration.hour = hour
+ duration.minute = minute
+ duration.second = second
+ end
+ value.split(":").collect {|v| "%02d" % v.to_i}.join(":")
+ end
+ end
+
+ def _assert_maker_itunes_duration_invalid_value(value, maker_readers)
+ assert_raise(ArgumentError) do
+ ::RSS::Maker.make("rss2.0") do |maker|
+ setup_dummy_channel(maker)
+ setup_dummy_item(maker)
+
+ target = chain_reader(maker, maker_readers)
+ target.itunes_duration = value
+ end
+ end
+ end
+
+ def assert_maker_itunes_duration(maker_readers, feed_readers=nil)
+ _wrap_assertion do
+ feed_readers ||= maker_readers
+ _assert_maker_itunes_duration(7, 14, 5, "07:14:05", maker_readers,
+ feed_readers)
+ _assert_maker_itunes_duration(7, 14, 5, "7:14:05", maker_readers,
+ feed_readers)
+ _assert_maker_itunes_duration(0, 4, 55, "04:55", maker_readers,
+ feed_readers)
+ _assert_maker_itunes_duration(0, 4, 5, "4:05", maker_readers,
+ feed_readers)
+
+ _assert_maker_itunes_duration_invalid_value("5", maker_readers)
+ _assert_maker_itunes_duration_invalid_value("09:07:14:05", maker_readers)
+ _assert_maker_itunes_duration_invalid_value("10:5", maker_readers)
+ _assert_maker_itunes_duration_invalid_value("10:03:5", maker_readers)
+ _assert_maker_itunes_duration_invalid_value("10:3:05", maker_readers)
+
+ _assert_maker_itunes_duration_invalid_value("xx:xx:xx", maker_readers)
+ end
+ end
+
+ def _assert_maker_itunes_explicit(explicit, value,
+ maker_readers, feed_readers)
+ rss20 = ::RSS::Maker.make("rss2.0") do |maker|
+ setup_dummy_channel(maker)
+ setup_dummy_item(maker)
+
+ target = chain_reader(maker, maker_readers)
+ target.itunes_explicit = value
+ assert_equal(explicit, target.itunes_explicit?)
+ end
+ target = chain_reader(rss20, feed_readers)
+ assert_equal(value, target.itunes_explicit)
+ assert_equal(explicit, target.itunes_explicit?)
+ end
+
+ def assert_maker_itunes_explicit(maker_readers, feed_readers=nil)
+ _wrap_assertion do
+ feed_readers ||= maker_readers
+ _assert_maker_itunes_explicit(true, "yes", maker_readers, feed_readers)
+ _assert_maker_itunes_explicit(false, "clean",
+ maker_readers, feed_readers)
+ _assert_maker_itunes_explicit(nil, "no", maker_readers, feed_readers)
+ end
+ end
+
+ def _assert_maker_itunes_keywords(keywords, value,
+ maker_readers, feed_readers)
+ _assert_maker_itunes_keywords_by_value(keywords, value,
+ maker_readers, feed_readers)
+ _assert_maker_itunes_keywords_by_keywords(keywords, maker_readers,
+ feed_readers)
+ end
+
+ def _assert_maker_itunes_keywords_by(keywords, maker_readers, feed_readers)
+ rss20 = ::RSS::Maker.make("rss2.0") do |maker|
+ setup_dummy_channel(maker)
+ setup_dummy_item(maker)
+
+ target = chain_reader(maker, maker_readers)
+ yield(target)
+ end
+ assert_nothing_raised do
+ rss20 = ::RSS::Parser.parse(rss20.to_s)
+ end
+ target = chain_reader(rss20, feed_readers)
+ assert_equal(keywords, target.itunes_keywords)
+ end
+
+ def _assert_maker_itunes_keywords_by_value(keywords, value,
+ maker_readers, feed_readers)
+ _assert_maker_itunes_keywords_by(keywords, maker_readers,
+ feed_readers) do |target|
+ target.itunes_keywords = value
+ end
+ end
+
+ def _assert_maker_itunes_keywords_by_keywords(keywords,
+ maker_readers, feed_readers)
+ _assert_maker_itunes_keywords_by(keywords, maker_readers,
+ feed_readers) do |target|
+ target.itunes_keywords = keywords
+ end
+ end
+
+ def assert_maker_itunes_keywords(maker_readers, feed_readers=nil)
+ _wrap_assertion do
+ feed_readers ||= maker_readers
+ _assert_maker_itunes_keywords(["salt"], "salt",
+ maker_readers, feed_readers)
+ _assert_maker_itunes_keywords(["salt"], " salt ",
+ maker_readers, feed_readers)
+ _assert_maker_itunes_keywords(["salt", "pepper", "shaker", "exciting"],
+ "salt, pepper, shaker, exciting",
+ maker_readers, feed_readers)
+ _assert_maker_itunes_keywords(["metric", "socket", "wrenches",
+ "toolsalt"],
+ "metric, socket, wrenches, toolsalt",
+ maker_readers, feed_readers)
+ _assert_maker_itunes_keywords(["olitics", "red", "blue", "state"],
+ "olitics, red, blue, state",
+ maker_readers, feed_readers)
+ end
+ end
+
+ def assert_maker_itunes_new_feed_url(maker_readers, feed_readers=nil)
+ feed_readers ||= maker_readers
+ url = "http://newlocation.com/example.rss"
+
+ rss20 = ::RSS::Maker.make("rss2.0") do |maker|
+ setup_dummy_channel(maker)
+ setup_dummy_item(maker)
+
+ target = chain_reader(maker, maker_readers)
+ target.itunes_new_feed_url = url
+ end
+ target = chain_reader(rss20, feed_readers)
+ assert_equal(url, target.itunes_new_feed_url)
+ end
+
+ def _assert_maker_itunes_owner(name, email, maker_readers, feed_readers)
+ rss20 = ::RSS::Maker.make("rss2.0") do |maker|
+ setup_dummy_channel(maker)
+ setup_dummy_item(maker)
+
+ target = chain_reader(maker, maker_readers)
+ owner = target.itunes_owner
+ owner.itunes_name = name
+ owner.itunes_email = email
+ end
+ owner = chain_reader(rss20, feed_readers).itunes_owner
+ if name.nil? and email.nil?
+ assert_nil(owner)
+ else
+ assert_not_nil(owner)
+ assert_equal(name, owner.itunes_name)
+ assert_equal(email, owner.itunes_email)
+ end
+ end
+
+ def assert_maker_itunes_owner(maker_readers, feed_readers=nil)
+ _wrap_assertion do
+ feed_readers ||= maker_readers
+ _assert_maker_itunes_owner("John Doe", "john.doe@example.com",
+ maker_readers, feed_readers)
+
+ not_set_name = (["maker"] + maker_readers + ["itunes_owner"]).join(".")
+ assert_not_set_error(not_set_name, ["itunes_name"]) do
+ _assert_maker_itunes_owner(nil, "john.doe@example.com",
+ maker_readers, feed_readers)
+ end
+ assert_not_set_error(not_set_name, ["itunes_email"]) do
+ _assert_maker_itunes_owner("John Doe", nil,
+ maker_readers, feed_readers)
+ end
+
+ _assert_maker_itunes_owner(nil, nil, maker_readers, feed_readers)
+ end
+ end
+
+ def _assert_maker_itunes_subtitle(subtitle, maker_readers, feed_readers)
+ rss20 = ::RSS::Maker.make("rss2.0") do |maker|
+ setup_dummy_channel(maker)
+ setup_dummy_item(maker)
+
+ target = chain_reader(maker, maker_readers)
+ target.itunes_subtitle = subtitle
+ end
+
+ target = chain_reader(rss20, feed_readers)
+ assert_equal(subtitle, target.itunes_subtitle)
+ end
+
+ def assert_maker_itunes_subtitle(maker_readers, feed_readers=nil)
+ _wrap_assertion do
+ feed_readers ||= maker_readers
+ _assert_maker_itunes_subtitle("A show about everything",
+ maker_readers, feed_readers)
+ _assert_maker_itunes_subtitle("A short primer on table spices",
+ maker_readers, feed_readers)
+ _assert_maker_itunes_subtitle("Comparing socket wrenches is fun!",
+ maker_readers, feed_readers)
+ _assert_maker_itunes_subtitle("Red + Blue != Purple",
+ maker_readers, feed_readers)
+ end
+ end
+
+ def _assert_maker_itunes_summary(summary, maker_readers, feed_readers)
+ rss20 = ::RSS::Maker.make("rss2.0") do |maker|
+ setup_dummy_channel(maker)
+ setup_dummy_item(maker)
+
+ target = chain_reader(maker, maker_readers)
+ target.itunes_summary = summary
+ end
+
+ target = chain_reader(rss20, feed_readers)
+ assert_equal(summary, target.itunes_summary)
+ end
+
+ def assert_maker_itunes_summary(maker_readers, feed_readers=nil)
+ _wrap_assertion do
+ feed_readers ||= maker_readers
+ _assert_maker_itunes_summary("All About Everything is a show about " +
+ "everything. Each week we dive into any " +
+ "subject known to man and talk about it " +
+ "as much as we can. Look for our Podcast " +
+ "in the iTunes Music Store",
+ maker_readers, feed_readers)
+ _assert_maker_itunes_summary("This week we talk about salt and pepper " +
+ "shakers, comparing and contrasting pour " +
+ "rates, construction materials, and " +
+ "overall aesthetics. Come and join the " +
+ "party!",
+ maker_readers, feed_readers)
+ _assert_maker_itunes_summary("This week we talk about metric vs. old " +
+ "english socket wrenches. Which one is " +
+ "better? Do you really need both? Get " +
+ "all of your answers here.",
+ maker_readers, feed_readers)
+ _assert_maker_itunes_summary("This week we talk about surviving in a " +
+ "Red state if you’re a Blue person. Or " +
+ "vice versa.",
+ maker_readers, feed_readers)
+ end
+ end
+ end
+end
diff --git a/test/rss/test_maker_xml-stylesheet.rb b/test/rss/test_maker_xml-stylesheet.rb
index 9d45e520388..81d97ddc0e0 100644
--- a/test/rss/test_maker_xml-stylesheet.rb
+++ b/test/rss/test_maker_xml-stylesheet.rb
@@ -39,8 +39,8 @@ module RSS
href = 'http://example.com/index.xsl'
type = 'text/xsl'
rss = RSS::Maker.make("1.0") do |maker|
- maker.xml_stylesheets.new_xml_stylesheet do |xss|
- xss.href = href
+ maker.xml_stylesheets.new_xml_stylesheet do |_xss|
+ _xss.href = href
end
setup_dummy_channel(maker)
diff --git a/test/rss/test_parser.rb b/test/rss/test_parser.rb
index 49b441bf96b..45f31e20145 100644
--- a/test/rss/test_parser.rb
+++ b/test/rss/test_parser.rb
@@ -1,14 +1,4 @@
-begin
- require "fileutils"
-rescue LoadError
- module FileUtils
- module_function
- def rm_f(target)
- File.unlink(target)
- rescue Errno::ENOENT
- end
- end
-end
+require 'fileutils'
require "rss-testcase"
@@ -28,7 +18,7 @@ EOR
@rss_file = "rss10.rdf"
File.open(@rss_file, "w") {|f| f.print(@rss10)}
end
-
+
def teardown
Parser.default_parser = @_default_parser
FileUtils.rm_f(@rss_file)
diff --git a/test/rss/test_setup_maker_1.0.rb b/test/rss/test_setup_maker_1.0.rb
index 539749bf20c..0b960d91c8c 100644
--- a/test/rss/test_setup_maker_1.0.rb
+++ b/test/rss/test_setup_maker_1.0.rb
@@ -262,8 +262,8 @@ module RSS
assert_equal(@trackback_elems[:ping], item.trackback_ping)
assert_equal(@trackback_elems[:about].size, item.trackback_abouts.size)
- item.trackback_abouts.each_with_index do |about, i|
- assert_equal(@trackback_elems[:about][i], about.value)
+ item.trackback_abouts.each_with_index do |about, j|
+ assert_equal(@trackback_elems[:about][j], about.value)
end
end
end
@@ -538,8 +538,8 @@ module RSS
assert_equal(@trackback_elems[:ping], item.trackback_ping)
assert_equal(@trackback_elems[:about].size, item.trackback_abouts.size)
- item.trackback_abouts.each_with_index do |about, i|
- assert_equal(@trackback_elems[:about][i], about.value)
+ item.trackback_abouts.each_with_index do |about, j|
+ assert_equal(@trackback_elems[:about][j], about.value)
end
end
diff --git a/test/rss/test_setup_maker_atom_feed.rb b/test/rss/test_setup_maker_atom_feed.rb
index 0caed6cec8f..03d33dbb9c6 100644
--- a/test/rss/test_setup_maker_atom_feed.rb
+++ b/test/rss/test_setup_maker_atom_feed.rb
@@ -104,7 +104,9 @@ module RSS
end
generator.each do |key, value|
- maker.channel.generator.__send__("#{key}=", value)
+ maker.channel.generator do |g|
+ g.__send__("#{key}=", value)
+ end
end
maker.channel.icon = icon
diff --git a/test/rss/test_setup_maker_itunes.rb b/test/rss/test_setup_maker_itunes.rb
new file mode 100644
index 00000000000..1f0372d6e72
--- /dev/null
+++ b/test/rss/test_setup_maker_itunes.rb
@@ -0,0 +1,144 @@
+require "rss-testcase"
+
+require "rss/maker"
+
+module RSS
+ class TestSetupMakerITunes < TestCase
+ def test_setup_maker_simple
+ author = "John Doe"
+ block = true
+ categories = ["Audio Blogs"]
+ image = "http://example.com/podcasts/everything/AllAboutEverything.jpg"
+ duration = "4:05"
+ duration_components = [0, 4, 5]
+ explicit = true
+ keywords = ["salt", "pepper", "shaker", "exciting"]
+ new_feed_url = "http://newlocation.com/example.rss"
+ owner = {:name => "John Doe", :email => "john.doe@example.com"}
+ subtitle = "A show about everything"
+ summary = "All About Everything is a show about " +
+ "everything. Each week we dive into any " +
+ "subject known to man and talk about it " +
+ "as much as we can. Look for our Podcast " +
+ "in the iTunes Music Store"
+
+ feed = RSS::Maker.make("rss2.0") do |maker|
+ setup_dummy_channel(maker)
+ setup_dummy_item(maker)
+
+ channel = maker.channel
+ channel.itunes_author = author
+ channel.itunes_block = block
+ categories.each do |category|
+ channel.itunes_categories.new_category.text = category
+ end
+ channel.itunes_image = image
+ channel.itunes_explicit = explicit
+ channel.itunes_keywords = keywords
+ channel.itunes_owner.itunes_name = owner[:name]
+ channel.itunes_owner.itunes_email = owner[:email]
+ channel.itunes_subtitle = subtitle
+ channel.itunes_summary = summary
+
+ item = maker.items.last
+ item.itunes_author = author
+ item.itunes_block = block
+ item.itunes_duration = duration
+ item.itunes_explicit = explicit
+ item.itunes_keywords = keywords
+ item.itunes_subtitle = subtitle
+ item.itunes_summary = summary
+ end
+ assert_not_nil(feed)
+
+ new_feed = RSS::Maker.make("rss2.0") do |maker|
+ feed.setup_maker(maker)
+ end
+ assert_not_nil(new_feed)
+
+ channel = new_feed.channel
+ item = new_feed.items.last
+
+ assert_equal(author, channel.itunes_author)
+ assert_equal(author, item.itunes_author)
+
+ assert_equal(block, channel.itunes_block?)
+ assert_equal(block, item.itunes_block?)
+
+ assert_equal(categories,
+ collect_itunes_categories(channel.itunes_categories))
+
+ assert_equal(image, channel.itunes_image.href)
+
+ assert_equal(duration_components,
+ [item.itunes_duration.hour,
+ item.itunes_duration.minute,
+ item.itunes_duration.second])
+
+ assert_equal(explicit, channel.itunes_explicit?)
+ assert_equal(explicit, item.itunes_explicit?)
+
+ assert_equal(keywords, channel.itunes_keywords)
+ assert_equal(keywords, item.itunes_keywords)
+
+ assert_equal(owner,
+ {
+ :name => channel.itunes_owner.itunes_name,
+ :email => channel.itunes_owner.itunes_email
+ })
+
+ assert_equal(subtitle, channel.itunes_subtitle)
+ assert_equal(subtitle, item.itunes_subtitle)
+
+ assert_equal(summary, channel.itunes_summary)
+ assert_equal(summary, item.itunes_summary)
+ end
+
+ def test_setup_maker_with_nested_categories
+ categories = [["Arts & Entertainment", "Games"],
+ ["Technology", "Computers"],
+ "Audio Blogs"]
+
+ feed = RSS::Maker.make("rss2.0") do |maker|
+ setup_dummy_channel(maker)
+ setup_dummy_item(maker)
+
+ channel = maker.channel
+ categories.each do |category|
+ target = channel.itunes_categories
+ if category.is_a?(Array)
+ category.each do |sub_category|
+ target = target.new_category
+ target.text = sub_category
+ end
+ else
+ target.new_category.text = category
+ end
+ end
+ end
+ assert_not_nil(feed)
+
+ new_feed = RSS::Maker.make("rss2.0") do |maker|
+ feed.setup_maker(maker)
+ end
+ assert_not_nil(new_feed)
+
+ channel = new_feed.channel
+
+ assert_equal(categories,
+ collect_itunes_categories(channel.itunes_categories))
+ end
+
+ private
+ def collect_itunes_categories(categories)
+ categories.collect do |c|
+ rest = collect_itunes_categories(c.itunes_categories)
+ if rest.empty?
+ c.text
+ else
+ [c.text, *rest]
+ end
+ end
+ end
+ end
+end
diff --git a/test/rss/test_to_s.rb b/test/rss/test_to_s.rb
index 1538534034d..66739591ea1 100644
--- a/test/rss/test_to_s.rb
+++ b/test/rss/test_to_s.rb
@@ -12,7 +12,6 @@ require "rss/trackback"
module RSS
class TestToS < TestCase
-
def setup
@image_url = "http://example.com/foo.png"
@textinput_link = "http://example.com/search.cgi"
@@ -435,6 +434,237 @@ module RSS
new_about.value = about
end
end
+
+
+ def assert_channel10(attrs, channel)
+ _wrap_assertion do
+ n_attrs = normalized_attrs(attrs)
+
+ names = %w(about title link description)
+ assert_attributes(attrs, names, channel)
+
+ %w(image items textinput).each do |name|
+ value = n_attrs[name]
+ if value
+ target = channel.__send__(name)
+ __send__("assert_channel10_#{name}", value, target)
+ end
+ end
+ end
+ end
+
+ def assert_channel10_image(attrs, image)
+ _wrap_assertion do
+ assert_attributes(attrs, %w(resource), image)
+ end
+ end
+
+ def assert_channel10_textinput(attrs, textinput)
+ _wrap_assertion do
+ assert_attributes(attrs, %w(resource), textinput)
+ end
+ end
+
+ def assert_channel10_items(attrs, items)
+ _wrap_assertion do
+ assert_equal(items.resources, items.Seq.lis.collect {|x| x.resource})
+ items.Seq.lis.each_with_index do |li, i|
+ assert_attributes(attrs[i], %w(resource), li)
+ end
+ end
+ end
+
+ def assert_image10(attrs, image)
+ _wrap_assertion do
+ names = %w(about title url link)
+ assert_attributes(attrs, names, image)
+ end
+ end
+
+ def assert_items10(attrs, items)
+ _wrap_assertion do
+ names = %w(about title link description)
+ items.each_with_index do |item, i|
+ assert_attributes(attrs[i], names, item)
+ end
+ end
+ end
+
+ def assert_textinput10(attrs, textinput)
+ _wrap_assertion do
+ names = %w(about title description name link)
+ assert_attributes(attrs, names, textinput)
+ end
+ end
+
+
+ def assert_channel09(attrs, channel)
+ _wrap_assertion do
+ n_attrs = normalized_attrs(attrs)
+
+ names = %w(title description link language rating
+ copyright pubDate lastBuildDate docs
+ managingEditor webMaster)
+ assert_attributes(attrs, names, channel)
+
+ %w(skipHours skipDays).each do |name|
+ value = n_attrs[name]
+ if value
+ target = channel.__send__(name)
+ __send__("assert_channel09_#{name}", value, target)
+ end
+ end
+ end
+ end
+
+ def assert_channel09_skipDays(contents, skipDays)
+ _wrap_assertion do
+ days = skipDays.days
+ contents.each_with_index do |content, i|
+ assert_equal(content, days[i].content)
+ end
+ end
+ end
+
+ def assert_channel09_skipHours(contents, skipHours)
+ _wrap_assertion do
+ hours = skipHours.hours
+ contents.each_with_index do |content, i|
+ 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)
+ names << ["width", :integer]
+ names << ["height", :integer]
+ assert_attributes(attrs, names, image)
+ end
+ end
+
+ def assert_items09(attrs, items)
+ _wrap_assertion do
+ names = %w(title link description)
+ items.each_with_index do |item, i|
+ assert_attributes(attrs[i], names, item)
+ end
+ end
+ end
+ def assert_textinput09(attrs, textinput)
+ _wrap_assertion do
+ names = %w(title description name link)
+ assert_attributes(attrs, names, textinput)
+ end
+ end
+
+
+ def assert_channel20(attrs, channel)
+ _wrap_assertion do
+ n_attrs = normalized_attrs(attrs)
+
+ names = %w(title link description language copyright
+ managingEditor webMaster pubDate
+ lastBuildDate generator docs rating)
+ names << ["ttl", :integer]
+ assert_attributes(attrs, names, channel)
+
+ %w(cloud categories skipHours skipDays).each do |name|
+ value = n_attrs[name]
+ if value
+ target = channel.__send__(name)
+ __send__("assert_channel20_#{name}", value, target)
+ end
+ end
+ end
+ end
+
+ def assert_channel20_skipDays(contents, skipDays)
+ assert_channel09_skipDays(contents, skipDays)
+ end
+
+ def assert_channel20_skipHours(contents, skipHours)
+ assert_channel09_skipHours(contents, skipHours)
+ end
+
+ def assert_channel20_cloud(attrs, cloud)
+ _wrap_assertion do
+ names = %w(domain path registerProcedure protocol)
+ names << ["port", :integer]
+ assert_attributes(attrs, names, cloud)
+ end
+ end
+
+ def assert_channel20_categories(attrs, categories)
+ _wrap_assertion do
+ names = %w(domain content)
+ categories.each_with_index do |category, i|
+ assert_attributes(attrs[i], names, category)
+ end
+ end
+ end
+
+ def assert_image20(attrs, image)
+ _wrap_assertion do
+ names = %w(url link title description)
+ names << ["width", :integer]
+ names << ["height", :integer]
+ assert_attributes(attrs, names, image)
+ end
+ end
+
+ def assert_items20(attrs, items)
+ _wrap_assertion do
+ names = %w(about title link description)
+ items.each_with_index do |item, i|
+ assert_attributes(attrs[i], names, item)
+
+ n_attrs = normalized_attrs(attrs[i])
+
+ %w(source enclosure categories guid).each do |name|
+ value = n_attrs[name]
+ if value
+ target = item.__send__(name)
+ __send__("assert_items20_#{name}", value, target)
+ end
+ end
+ end
+ end
+ end
+
+ def assert_items20_source(attrs, source)
+ _wrap_assertion do
+ assert_attributes(attrs, %w(url content), source)
+ end
+ end
+
+ def assert_items20_enclosure(attrs, enclosure)
+ _wrap_assertion do
+ names = ["url", ["length", :integer], "type"]
+ assert_attributes(attrs, names, enclosure)
+ end
+ end
+
+ def assert_items20_categories(attrs, categories)
+ _wrap_assertion do
+ assert_channel20_categories(attrs, categories)
+ end
+ end
+
+ def assert_items20_guid(attrs, guid)
+ _wrap_assertion do
+ names = [["isPermaLink", :boolean], ["content"]]
+ assert_attributes(attrs, names, guid)
+ end
+ end
+
+ def assert_textinput20(attrs, textinput)
+ _wrap_assertion do
+ names = %w(title description name link)
+ assert_attributes(attrs, names, textinput)
+ end
+ end
end
end
diff --git a/test/rss/test_version.rb b/test/rss/test_version.rb
index 2c7d2e0f7a3..cb60faae79e 100644
--- a/test/rss/test_version.rb
+++ b/test/rss/test_version.rb
@@ -3,7 +3,7 @@ require "rss-testcase"
module RSS
class TestVersion < TestCase
def test_version
- assert_equal("0.1.7", ::RSS::VERSION)
+ assert_equal("0.1.8", ::RSS::VERSION)
end
end
end