require 'helper' require 'test_channel_xml' require 'open3' require 'uri' require 'json' # # End-to-end test # # Same as TestChannelXML, but with the XML generated by calling the bin script # class TestApp < TestChannelXML include DropcasterTest APP_SCRIPT = 'ruby bin/dropcaster' def channel_rss %x[#{APP_SCRIPT} #{FIXTURE_ITUNES_MP3}] end def test_overwrite_title test_title = 'Alice and Bob in Wonderland' channel = channel_node(%x[#{APP_SCRIPT} #{FIXTURE_ITUNES_MP3} --title '#{test_title}']) assert_equal(test_title, channel.find('title').first.content) end def test_overwrite_link test_link = 'http://www.example.com/foo/bar' channel = channel_node(%x[#{APP_SCRIPT} #{FIXTURE_ITUNES_MP3} --url '#{test_link}']) assert_equal(test_link, channel.find('link').first.content) end def test_dir_only channel = channel_node(%x[#{APP_SCRIPT} #{FIXTURES_DIR}]) assert_equal(1, channel.find('item').size) end def test_overwrite_enclosures_url test_enclosures_url = 'http://www.example.com/foo/bar/episodes/' channel = channel_node(%x[#{APP_SCRIPT} #{FIXTURE_ITUNES_MP3} --enclosures '#{test_enclosures_url}']) item = channel.find("item").first assert(item) enclosure = item.find('enclosure').first assert(enclosure) assert_equal(URI.join(test_enclosures_url, FIXTURE_ITUNES_MP3).to_s, enclosure['url']) end def test_overwrite_image_url_channel test_image_url = 'http://www.example.com/foo/bar/override.gif' channel = channel_node(%x[#{APP_SCRIPT} #{FIXTURE_ITUNES_MP3} --image '#{test_image_url}']) assert_equal(test_image_url, channel.find('itunes:image').first['href']) end def test_overwrite_image_url_enclosure # TODO Implement test end def test_overwrite_description test_description = 'Testing commandline apps is not that hard.' channel = channel_node(%x[#{APP_SCRIPT} #{FIXTURE_ITUNES_MP3} --description '#{test_description}']) assert_equal(test_description, channel.find('description').first.content) assert_equal(test_description, channel.find('itunes:summary', NS_ITUNES).first.content) end def test_no_channel_file Open3.popen3(APP_SCRIPT){|stdin, stdout, stderr| assert_match(/ERROR: No channel file found/, stderr.read) } unless Kernel.is_windows? end def test_overwrite_all test_title = 'Bob and Alice in Wonderland' test_link = 'http://www.example.com/bar/foot' test_description = 'Testing commandline apps is really not that hard.' channel = channel_node(%x[#{APP_SCRIPT} #{FIXTURE_ITUNES_MP3} --title '#{test_title}' --url '#{test_link}' --description '#{test_description}']) assert_equal(test_title, channel.find('title').first.content) assert_equal(test_link, channel.find('link').first.content) assert_equal(test_description, channel.find('description').first.content) assert_equal(test_description, channel.find('itunes:summary', NS_ITUNES).first.content) end def test_channel_template_not_found Open3.popen3("#{APP_SCRIPT} #{FIXTURE_ITUNES_MP3} --channel-template foo/bar/42"){|stdin, stdout, stderr| assert_match(/Unable to load template file/, stderr.read) } unless Kernel.is_windows? end # # We supply an alternative channel template that produces JSON, parse it back and make some basic assertions on the results # def test_overwrite_channel_template channel_template = File.join(FIXTURES_DIR, 'test_template.json.erb') channel = JSON.parse(%x[#{APP_SCRIPT} #{FIXTURE_ITUNES_MP3} --channel-template #{channel_template}]) assert_equal("All About Everything", channel['channel']['title']) end # TODO --channel end