dropcaster 0.0.2 → 0.0.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/.document +5 -5
- data/Gemfile +11 -11
- data/Gemfile.lock +26 -26
- data/LICENSE.txt +20 -20
- data/README.md +155 -147
- data/Rakefile +47 -47
- data/TODO +14 -13
- data/VERSION +1 -1
- data/bin/dropcaster +117 -111
- data/bin/lstags +45 -45
- data/doc/sample-channel.yml +79 -77
- data/doc/sample-sidecar.yml +19 -19
- data/dropcaster.gemspec +88 -87
- data/lib/dropcaster/channel.rb +96 -86
- data/lib/dropcaster/channel_file_locator.rb +48 -48
- data/lib/dropcaster/errors.rb +25 -19
- data/lib/dropcaster/hashkeys.rb +12 -12
- data/lib/dropcaster/item.rb +43 -43
- data/lib/dropcaster.rb +18 -18
- data/templates/{channel.rss.erb → iTunes.rss.erb} +57 -57
- data/test/extensions/windows.rb +12 -0
- data/test/fixtures/channel.yml +13 -14
- data/test/helper.rb +14 -10
- data/test/unit/test_app.rb +84 -59
- data/test/unit/test_channel.rb +32 -32
- data/test/unit/test_channel_locator.rb +91 -91
- data/test/unit/test_channel_xml.rb +87 -69
- data/test/unit/test_item.rb +63 -61
- metadata +24 -19
@@ -1,57 +1,57 @@
|
|
1
|
-
<?xml version="1.0" encoding="UTF-8"?>
|
2
|
-
<!-- This file was automatically generated by Dropcaster <%= Dropcaster::VERSION%> -->
|
3
|
-
<rss xmlns:itunes="http://www.itunes.com/dtds/podcast-1.0.dtd" version="2.0">
|
4
|
-
<channel>
|
5
|
-
<title><%= title %></title>
|
6
|
-
<link><%= url %></link>
|
7
|
-
<description><%= description %></description>
|
8
|
-
<itunes:summary><%= description %></itunes:summary>
|
9
|
-
<% unless language.blank? %>
|
10
|
-
<language><%= language %></language>
|
11
|
-
<% end %>
|
12
|
-
<% unless copyright.blank? %>
|
13
|
-
<copyright><%= copyright %></copyright>
|
14
|
-
<% end %>
|
15
|
-
<% unless subtitle.blank? %>
|
16
|
-
<itunes:subtitle><%= subtitle %></itunes:subtitle>
|
17
|
-
<% end %>
|
18
|
-
<% unless author.blank? %>
|
19
|
-
<itunes:author><%= author %></itunes:author>
|
20
|
-
<% end %>
|
21
|
-
<% unless owner.nil? %>
|
22
|
-
<itunes:owner>
|
23
|
-
<itunes:name><%= owner[:name] %></itunes:name>
|
24
|
-
<itunes:email><%= owner[:email] %></itunes:email>
|
25
|
-
</itunes:owner>
|
26
|
-
<% end %>
|
27
|
-
<% unless image_url.blank? %>
|
28
|
-
<itunes:image href="<%= image_url %>"/>
|
29
|
-
<% end %>
|
30
|
-
<% categories.each{|category| %>
|
31
|
-
<itunes:category text="<%= category %>"/>
|
32
|
-
<% } %>
|
33
|
-
<% unless explicit.blank? %>
|
34
|
-
<itunes:explicit><%= explicit %></itunes:explicit>
|
35
|
-
<% end %>
|
36
|
-
<% items.each{|item| %>
|
37
|
-
<item>
|
38
|
-
<title><%= item.tag.title || item.tag2.TIT2%></title>
|
39
|
-
<itunes:author><%= item.tag2.TP1 || item.tag2.TPE1 %></itunes:author>
|
40
|
-
<% unless item.tag2.SUBTITLE.blank? %>
|
41
|
-
<itunes:subtitle><%= item.tag2.SUBTITLE %></itunes:subtitle>
|
42
|
-
<% end %>
|
43
|
-
<% unless item.tag2.TT3.blank? %>
|
44
|
-
<itunes:summary><%= item.tag2.TT3 %></itunes:summary>
|
45
|
-
<% end %>
|
46
|
-
<itunes:image href="<%= item.image_url %>"/>
|
47
|
-
<enclosure url="<%= item.url %>" length="<%= item.file_size %>" type="audio/mp3"/>
|
48
|
-
<guid isPermaLink="false"><%= item.uuid %></guid>
|
49
|
-
<pubDate><%= item.pub_date.to_formatted_s(:rfc822) %></pubDate>
|
50
|
-
<itunes:duration><%= item.duration.to_i %></itunes:duration>
|
51
|
-
<% unless item.keywords.blank? %>
|
52
|
-
<itunes:keywords><%= item.keywords %></itunes:keywords>
|
53
|
-
<% end %>
|
54
|
-
</item>
|
55
|
-
<% } %>
|
56
|
-
</channel>
|
57
|
-
</rss>
|
1
|
+
<?xml version="1.0" encoding="UTF-8"?>
|
2
|
+
<!-- This file was automatically generated by Dropcaster <%= Dropcaster::VERSION%> -->
|
3
|
+
<rss xmlns:itunes="http://www.itunes.com/dtds/podcast-1.0.dtd" version="2.0">
|
4
|
+
<channel>
|
5
|
+
<title><%= title %></title>
|
6
|
+
<link><%= url %></link>
|
7
|
+
<description><%= description %></description>
|
8
|
+
<itunes:summary><%= description %></itunes:summary>
|
9
|
+
<% unless language.blank? %>
|
10
|
+
<language><%= language %></language>
|
11
|
+
<% end %>
|
12
|
+
<% unless copyright.blank? %>
|
13
|
+
<copyright><%= copyright %></copyright>
|
14
|
+
<% end %>
|
15
|
+
<% unless subtitle.blank? %>
|
16
|
+
<itunes:subtitle><%= subtitle %></itunes:subtitle>
|
17
|
+
<% end %>
|
18
|
+
<% unless author.blank? %>
|
19
|
+
<itunes:author><%= author %></itunes:author>
|
20
|
+
<% end %>
|
21
|
+
<% unless owner.nil? %>
|
22
|
+
<itunes:owner>
|
23
|
+
<itunes:name><%= owner[:name] %></itunes:name>
|
24
|
+
<itunes:email><%= owner[:email] %></itunes:email>
|
25
|
+
</itunes:owner>
|
26
|
+
<% end %>
|
27
|
+
<% unless image_url.blank? %>
|
28
|
+
<itunes:image href="<%= image_url %>"/>
|
29
|
+
<% end %>
|
30
|
+
<% categories.each{|category| %>
|
31
|
+
<itunes:category text="<%= category %>"/>
|
32
|
+
<% } %>
|
33
|
+
<% unless explicit.blank? %>
|
34
|
+
<itunes:explicit><%= explicit %></itunes:explicit>
|
35
|
+
<% end %>
|
36
|
+
<% items.each{|item| %>
|
37
|
+
<item>
|
38
|
+
<title><%= item.tag.title || item.tag2.TIT2%></title>
|
39
|
+
<itunes:author><%= item.tag2.TP1 || item.tag2.TPE1 %></itunes:author>
|
40
|
+
<% unless item.tag2.SUBTITLE.blank? %>
|
41
|
+
<itunes:subtitle><%= item.tag2.SUBTITLE %></itunes:subtitle>
|
42
|
+
<% end %>
|
43
|
+
<% unless item.tag2.TT3.blank? %>
|
44
|
+
<itunes:summary><%= item.tag2.TT3 %></itunes:summary>
|
45
|
+
<% end %>
|
46
|
+
<itunes:image href="<%= item.image_url %>"/>
|
47
|
+
<enclosure url="<%= item.url %>" length="<%= item.file_size %>" type="audio/mp3"/>
|
48
|
+
<guid isPermaLink="false"><%= item.uuid %></guid>
|
49
|
+
<pubDate><%= item.pub_date.to_formatted_s(:rfc822) %></pubDate>
|
50
|
+
<itunes:duration><%= item.duration.to_i %></itunes:duration>
|
51
|
+
<% unless item.keywords.blank? %>
|
52
|
+
<itunes:keywords><%= item.keywords %></itunes:keywords>
|
53
|
+
<% end %>
|
54
|
+
</item>
|
55
|
+
<% } %>
|
56
|
+
</channel>
|
57
|
+
</rss>
|
@@ -0,0 +1,12 @@
|
|
1
|
+
# Returns true if we run on a windows platform
|
2
|
+
#
|
3
|
+
# Sample:
|
4
|
+
#
|
5
|
+
# puts "Windows" if Kernel.is_windows?
|
6
|
+
#
|
7
|
+
# http://snippets.dzone.com/posts/show/2112
|
8
|
+
#
|
9
|
+
def Kernel.is_windows?
|
10
|
+
processor, platform, *rest = RUBY_PLATFORM.split("-")
|
11
|
+
platform == 'mingw32'
|
12
|
+
end
|
data/test/fixtures/channel.yml
CHANGED
@@ -1,14 +1,13 @@
|
|
1
|
-
:title: 'All About Everything'
|
2
|
-
:subtitle: 'A show about everything'
|
3
|
-
:url: 'http://www.example.com/podcasts/everything/
|
4
|
-
:
|
5
|
-
:
|
6
|
-
:
|
7
|
-
:
|
8
|
-
:
|
9
|
-
:
|
10
|
-
:
|
11
|
-
|
12
|
-
:
|
13
|
-
:
|
14
|
-
:explicit: 'No'
|
1
|
+
:title: 'All About Everything'
|
2
|
+
:subtitle: 'A show about everything'
|
3
|
+
:url: 'http://www.example.com/podcasts/everything/'
|
4
|
+
:language: 'en-us'
|
5
|
+
:copyright: '© 2011 John Doe and Family'
|
6
|
+
:author: 'John Doe'
|
7
|
+
:description: '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 Store!'
|
8
|
+
:owner:
|
9
|
+
:name: 'John Doe'
|
10
|
+
:email: 'john.doe@example.com'
|
11
|
+
:image_url: 'AllAboutEverything.jpg'
|
12
|
+
:categories: ['Technology', 'Gadgets']
|
13
|
+
:explicit: 'No'
|
data/test/helper.rb
CHANGED
@@ -1,10 +1,14 @@
|
|
1
|
-
require 'rubygems'
|
2
|
-
require 'test/unit'
|
3
|
-
require 'dropcaster'
|
4
|
-
|
5
|
-
$:.unshift File.join(File.dirname(__FILE__), *%w[.. test unit])
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
1
|
+
require 'rubygems'
|
2
|
+
require 'test/unit'
|
3
|
+
require 'dropcaster'
|
4
|
+
|
5
|
+
$:.unshift File.join(File.dirname(__FILE__), *%w[.. test unit])
|
6
|
+
$:.unshift File.join(File.dirname(__FILE__), *%w[.. test extensions])
|
7
|
+
|
8
|
+
require 'windows'
|
9
|
+
|
10
|
+
module DropcasterTest
|
11
|
+
FIXTURES_DIR = File.join(File.dirname(__FILE__), 'fixtures')
|
12
|
+
FIXTURE_ITUNES_MP3 = File.join(FIXTURES_DIR, 'iTunes.mp3')
|
13
|
+
NS_ITUNES = "itunes:http://www.itunes.com/dtds/podcast-1.0.dtd"
|
14
|
+
end
|
data/test/unit/test_app.rb
CHANGED
@@ -1,59 +1,84 @@
|
|
1
|
-
require 'helper'
|
2
|
-
require 'test_channel_xml'
|
3
|
-
require '
|
4
|
-
require '
|
5
|
-
|
6
|
-
#
|
7
|
-
# End-to-end test
|
8
|
-
#
|
9
|
-
# Same as TestChannelXML, but with the XML generated by calling the bin script
|
10
|
-
#
|
11
|
-
class TestApp < TestChannelXML
|
12
|
-
include DropcasterTest
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
end
|
18
|
-
|
19
|
-
def test_overwrite_title
|
20
|
-
test_title = 'Alice and Bob in Wonderland'
|
21
|
-
channel =
|
22
|
-
assert_equal(test_title, channel.find('title').first.content)
|
23
|
-
end
|
24
|
-
|
25
|
-
def test_overwrite_link
|
26
|
-
test_link = 'http://www.example.com/foo/bar'
|
27
|
-
channel =
|
28
|
-
assert_equal(test_link, channel.find('link').first.content)
|
29
|
-
end
|
30
|
-
|
31
|
-
def
|
32
|
-
|
33
|
-
channel =
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
1
|
+
require 'helper'
|
2
|
+
require 'test_channel_xml'
|
3
|
+
require 'open3'
|
4
|
+
require 'uri'
|
5
|
+
|
6
|
+
#
|
7
|
+
# End-to-end test
|
8
|
+
#
|
9
|
+
# Same as TestChannelXML, but with the XML generated by calling the bin script
|
10
|
+
#
|
11
|
+
class TestApp < TestChannelXML
|
12
|
+
include DropcasterTest
|
13
|
+
APP_SCRIPT = 'ruby bin/dropcaster'
|
14
|
+
|
15
|
+
def channel_rss
|
16
|
+
%x[#{APP_SCRIPT} #{FIXTURE_ITUNES_MP3}]
|
17
|
+
end
|
18
|
+
|
19
|
+
def test_overwrite_title
|
20
|
+
test_title = 'Alice and Bob in Wonderland'
|
21
|
+
channel = channel_node(%x[#{APP_SCRIPT} #{FIXTURE_ITUNES_MP3} --title '#{test_title}'])
|
22
|
+
assert_equal(test_title, channel.find('title').first.content)
|
23
|
+
end
|
24
|
+
|
25
|
+
def test_overwrite_link
|
26
|
+
test_link = 'http://www.example.com/foo/bar'
|
27
|
+
channel = channel_node(%x[#{APP_SCRIPT} #{FIXTURE_ITUNES_MP3} --url '#{test_link}'])
|
28
|
+
assert_equal(test_link, channel.find('link').first.content)
|
29
|
+
end
|
30
|
+
|
31
|
+
def test_overwrite_enclosures_url
|
32
|
+
test_enclosures_url = 'http://www.example.com/foo/bar/episodes/'
|
33
|
+
channel = channel_node(%x[#{APP_SCRIPT} #{FIXTURE_ITUNES_MP3} --enclosures '#{test_enclosures_url}'])
|
34
|
+
item = channel.find("item").first
|
35
|
+
assert(item)
|
36
|
+
enclosure = item.find('enclosure').first
|
37
|
+
assert(enclosure)
|
38
|
+
assert_equal(URI.join(test_enclosures_url, FIXTURE_ITUNES_MP3).to_s, enclosure['url'])
|
39
|
+
end
|
40
|
+
|
41
|
+
def test_overwrite_image_url_channel
|
42
|
+
test_image_url = 'http://www.example.com/foo/bar/override.gif'
|
43
|
+
channel = channel_node(%x[#{APP_SCRIPT} #{FIXTURE_ITUNES_MP3} --image '#{test_image_url}'])
|
44
|
+
assert_equal(test_image_url, channel.find('itunes:image').first['href'])
|
45
|
+
end
|
46
|
+
|
47
|
+
def test_overwrite_image_url_enclosure
|
48
|
+
# TODO Implement test
|
49
|
+
end
|
50
|
+
|
51
|
+
def test_overwrite_description
|
52
|
+
test_description = 'Testing commandline apps is not that hard.'
|
53
|
+
channel = channel_node(%x[#{APP_SCRIPT} #{FIXTURE_ITUNES_MP3} --description '#{test_description}'])
|
54
|
+
assert_equal(test_description, channel.find('description').first.content)
|
55
|
+
assert_equal(test_description, channel.find('itunes:summary', NS_ITUNES).first.content)
|
56
|
+
end
|
57
|
+
|
58
|
+
def test_no_channel_file
|
59
|
+
Open3.popen3(APP_SCRIPT){|stdin, stdout, stderr|
|
60
|
+
assert_match(/No \.\/channel.yml found/, stderr.read)
|
61
|
+
} unless Kernel.is_windows?
|
62
|
+
end
|
63
|
+
|
64
|
+
def test_overwrite_all
|
65
|
+
test_title = 'Bob and Alice in Wonderland'
|
66
|
+
test_link = 'http://www.example.com/bar/foot'
|
67
|
+
test_description = 'Testing commandline apps is really not that hard.'
|
68
|
+
|
69
|
+
channel = channel_node(%x[#{APP_SCRIPT} #{FIXTURE_ITUNES_MP3} --title '#{test_title}' --url '#{test_link}' --description '#{test_description}'])
|
70
|
+
|
71
|
+
assert_equal(test_title, channel.find('title').first.content)
|
72
|
+
assert_equal(test_link, channel.find('link').first.content)
|
73
|
+
assert_equal(test_description, channel.find('description').first.content)
|
74
|
+
assert_equal(test_description, channel.find('itunes:summary', NS_ITUNES).first.content)
|
75
|
+
end
|
76
|
+
|
77
|
+
def test_channel_template_not_found
|
78
|
+
Open3.popen3("#{APP_SCRIPT} #{FIXTURE_ITUNES_MP3} --channel-template foo/bar/42"){|stdin, stdout, stderr|
|
79
|
+
assert_match(/Unable to load template file/, stderr.read)
|
80
|
+
} unless Kernel.is_windows?
|
81
|
+
end
|
82
|
+
|
83
|
+
# TODO --channel
|
84
|
+
end
|
data/test/unit/test_channel.rb
CHANGED
@@ -1,32 +1,32 @@
|
|
1
|
-
require 'helper'
|
2
|
-
|
3
|
-
class TestChannel < Test::Unit::TestCase
|
4
|
-
include DropcasterTest
|
5
|
-
|
6
|
-
def setup
|
7
|
-
@options = YAML.load_file(File.join(FIXTURES_DIR, Dropcaster::CHANNEL_YML))
|
8
|
-
@channel = Dropcaster::Channel.new(FIXTURES_DIR, @options)
|
9
|
-
end
|
10
|
-
|
11
|
-
def test_item_count
|
12
|
-
assert_equal(1, @channel.items.size)
|
13
|
-
end
|
14
|
-
|
15
|
-
def test_channel
|
16
|
-
assert_equal(@options[:title], @channel.title)
|
17
|
-
assert_equal(@options[:url], @channel.url)
|
18
|
-
assert_equal(@options[:description], @channel.description)
|
19
|
-
assert_equal(@options[:subtitle], @channel.subtitle)
|
20
|
-
assert_equal(@options[:language], @channel.language)
|
21
|
-
assert_equal(@options[:copyright], @channel.copyright)
|
22
|
-
assert_equal(@options[:author], @channel.author)
|
23
|
-
|
24
|
-
owner = @channel.owner
|
25
|
-
assert_equal(@options[:owner][:name], owner[:name])
|
26
|
-
assert_equal(@options[:owner][:email], owner[:email])
|
27
|
-
|
28
|
-
assert_equal(@options[:image_url], @channel.image_url)
|
29
|
-
# TODO :categories: ['Technology', 'Gadgets']
|
30
|
-
assert_equal(@options[:explicit], @channel.explicit)
|
31
|
-
end
|
32
|
-
end
|
1
|
+
require 'helper'
|
2
|
+
|
3
|
+
class TestChannel < Test::Unit::TestCase
|
4
|
+
include DropcasterTest
|
5
|
+
|
6
|
+
def setup
|
7
|
+
@options = YAML.load_file(File.join(FIXTURES_DIR, Dropcaster::CHANNEL_YML))
|
8
|
+
@channel = Dropcaster::Channel.new(FIXTURES_DIR, @options)
|
9
|
+
end
|
10
|
+
|
11
|
+
def test_item_count
|
12
|
+
assert_equal(1, @channel.items.size)
|
13
|
+
end
|
14
|
+
|
15
|
+
def test_channel
|
16
|
+
assert_equal(@options[:title], @channel.title)
|
17
|
+
assert_equal(@options[:url], @channel.url)
|
18
|
+
assert_equal(@options[:description], @channel.description)
|
19
|
+
assert_equal(@options[:subtitle], @channel.subtitle)
|
20
|
+
assert_equal(@options[:language], @channel.language)
|
21
|
+
assert_equal(@options[:copyright], @channel.copyright)
|
22
|
+
assert_equal(@options[:author], @channel.author)
|
23
|
+
|
24
|
+
owner = @channel.owner
|
25
|
+
assert_equal(@options[:owner][:name], owner[:name])
|
26
|
+
assert_equal(@options[:owner][:email], owner[:email])
|
27
|
+
|
28
|
+
assert_equal(URI.join(@options[:url], @options[:image_url]).to_s, @channel.image_url)
|
29
|
+
# TODO :categories: ['Technology', 'Gadgets']
|
30
|
+
assert_equal(@options[:explicit], @channel.explicit)
|
31
|
+
end
|
32
|
+
end
|
@@ -1,91 +1,91 @@
|
|
1
|
-
require 'helper'
|
2
|
-
require 'tmpdir'
|
3
|
-
|
4
|
-
class TestChannelLocator < Test::Unit::TestCase
|
5
|
-
include DropcasterTest
|
6
|
-
|
7
|
-
class << self
|
8
|
-
attr_reader :temp_dir
|
9
|
-
|
10
|
-
def startup
|
11
|
-
@temp_dir = Dir.mktmpdir
|
12
|
-
end
|
13
|
-
|
14
|
-
def shutdown
|
15
|
-
FileUtils.remove_entry_secure(@temp_dir)
|
16
|
-
end
|
17
|
-
|
18
|
-
def suite
|
19
|
-
# from http://stackoverflow.com/questions/255969#778701
|
20
|
-
_suite = super
|
21
|
-
|
22
|
-
def _suite.run(*args)
|
23
|
-
TestChannelLocator.startup()
|
24
|
-
super
|
25
|
-
TestChannelLocator.shutdown()
|
26
|
-
end
|
27
|
-
|
28
|
-
_suite
|
29
|
-
end
|
30
|
-
end
|
31
|
-
|
32
|
-
def test_single_file
|
33
|
-
sources = File.join(TestChannelLocator.temp_dir, 'single_file.mp3')
|
34
|
-
assert_location(sources)
|
35
|
-
end
|
36
|
-
|
37
|
-
def test_current_directory
|
38
|
-
sources = File.join(TestChannelLocator.temp_dir, '.')
|
39
|
-
assert_location(sources)
|
40
|
-
end
|
41
|
-
|
42
|
-
def test_single_directory
|
43
|
-
sources = File.join(TestChannelLocator.temp_dir, 'single_dir')
|
44
|
-
assert_location(sources)
|
45
|
-
end
|
46
|
-
|
47
|
-
def test_array_of_files_same_dir
|
48
|
-
sources = Array.new
|
49
|
-
sources << File.join(TestChannelLocator.temp_dir, 'file1.mp3')
|
50
|
-
sources << File.join(TestChannelLocator.temp_dir, 'file2.mp3')
|
51
|
-
sources << File.join(TestChannelLocator.temp_dir, 'file3.mp3')
|
52
|
-
|
53
|
-
assert_location(sources)
|
54
|
-
end
|
55
|
-
|
56
|
-
def test_array_of_files_different_dir
|
57
|
-
sources = Array.new
|
58
|
-
sources << File.join(TestChannelLocator.temp_dir, 'foo', 'file1.mp3')
|
59
|
-
sources << File.join(TestChannelLocator.temp_dir, 'bar', 'file1.mp3')
|
60
|
-
sources << File.join(TestChannelLocator.temp_dir, 'baz', 'file1.mp3')
|
61
|
-
|
62
|
-
assert_raises Dropcaster::AmbiguousSourcesError do
|
63
|
-
Dropcaster::ChannelFileLocator.locate(sources)
|
64
|
-
end
|
65
|
-
end
|
66
|
-
|
67
|
-
def test_array_with_one_directory
|
68
|
-
assert_location(File.join(TestChannelLocator.temp_dir, ['single_dir']))
|
69
|
-
end
|
70
|
-
|
71
|
-
def test_array_with_more_than_a_single_directory
|
72
|
-
Dir.mktmpdir{|tmp_dir1|
|
73
|
-
Dir.mktmpdir{|tmp_dir2|
|
74
|
-
sources = Array.new
|
75
|
-
sources << File.join(tmp_dir1, 'another_dir')
|
76
|
-
sources << File.join(tmp_dir2, 'another_dir')
|
77
|
-
|
78
|
-
assert_raises Dropcaster::AmbiguousSourcesError do
|
79
|
-
Dropcaster::ChannelFileLocator.locate(sources)
|
80
|
-
end
|
81
|
-
}
|
82
|
-
}
|
83
|
-
end
|
84
|
-
|
85
|
-
private
|
86
|
-
|
87
|
-
def assert_location(sources)
|
88
|
-
channel_file = Dropcaster::ChannelFileLocator.locate(sources)
|
89
|
-
assert_equal(File.join(TestChannelLocator.temp_dir, Dropcaster::CHANNEL_YML), channel_file)
|
90
|
-
end
|
91
|
-
end
|
1
|
+
require 'helper'
|
2
|
+
require 'tmpdir'
|
3
|
+
|
4
|
+
class TestChannelLocator < Test::Unit::TestCase
|
5
|
+
include DropcasterTest
|
6
|
+
|
7
|
+
class << self
|
8
|
+
attr_reader :temp_dir
|
9
|
+
|
10
|
+
def startup
|
11
|
+
@temp_dir = Dir.mktmpdir
|
12
|
+
end
|
13
|
+
|
14
|
+
def shutdown
|
15
|
+
FileUtils.remove_entry_secure(@temp_dir)
|
16
|
+
end
|
17
|
+
|
18
|
+
def suite
|
19
|
+
# from http://stackoverflow.com/questions/255969#778701
|
20
|
+
_suite = super
|
21
|
+
|
22
|
+
def _suite.run(*args)
|
23
|
+
TestChannelLocator.startup()
|
24
|
+
super
|
25
|
+
TestChannelLocator.shutdown()
|
26
|
+
end
|
27
|
+
|
28
|
+
_suite
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
def test_single_file
|
33
|
+
sources = File.join(TestChannelLocator.temp_dir, 'single_file.mp3')
|
34
|
+
assert_location(sources)
|
35
|
+
end
|
36
|
+
|
37
|
+
def test_current_directory
|
38
|
+
sources = File.join(TestChannelLocator.temp_dir, '.')
|
39
|
+
assert_location(sources)
|
40
|
+
end
|
41
|
+
|
42
|
+
def test_single_directory
|
43
|
+
sources = File.join(TestChannelLocator.temp_dir, 'single_dir')
|
44
|
+
assert_location(sources)
|
45
|
+
end
|
46
|
+
|
47
|
+
def test_array_of_files_same_dir
|
48
|
+
sources = Array.new
|
49
|
+
sources << File.join(TestChannelLocator.temp_dir, 'file1.mp3')
|
50
|
+
sources << File.join(TestChannelLocator.temp_dir, 'file2.mp3')
|
51
|
+
sources << File.join(TestChannelLocator.temp_dir, 'file3.mp3')
|
52
|
+
|
53
|
+
assert_location(sources)
|
54
|
+
end
|
55
|
+
|
56
|
+
def test_array_of_files_different_dir
|
57
|
+
sources = Array.new
|
58
|
+
sources << File.join(TestChannelLocator.temp_dir, 'foo', 'file1.mp3')
|
59
|
+
sources << File.join(TestChannelLocator.temp_dir, 'bar', 'file1.mp3')
|
60
|
+
sources << File.join(TestChannelLocator.temp_dir, 'baz', 'file1.mp3')
|
61
|
+
|
62
|
+
assert_raises Dropcaster::AmbiguousSourcesError do
|
63
|
+
Dropcaster::ChannelFileLocator.locate(sources)
|
64
|
+
end
|
65
|
+
end
|
66
|
+
|
67
|
+
def test_array_with_one_directory
|
68
|
+
assert_location(File.join(TestChannelLocator.temp_dir, ['single_dir']))
|
69
|
+
end
|
70
|
+
|
71
|
+
def test_array_with_more_than_a_single_directory
|
72
|
+
Dir.mktmpdir{|tmp_dir1|
|
73
|
+
Dir.mktmpdir{|tmp_dir2|
|
74
|
+
sources = Array.new
|
75
|
+
sources << File.join(tmp_dir1, 'another_dir')
|
76
|
+
sources << File.join(tmp_dir2, 'another_dir')
|
77
|
+
|
78
|
+
assert_raises Dropcaster::AmbiguousSourcesError do
|
79
|
+
Dropcaster::ChannelFileLocator.locate(sources)
|
80
|
+
end
|
81
|
+
}
|
82
|
+
}
|
83
|
+
end
|
84
|
+
|
85
|
+
private
|
86
|
+
|
87
|
+
def assert_location(sources)
|
88
|
+
channel_file = Dropcaster::ChannelFileLocator.locate(sources)
|
89
|
+
assert_equal(File.join(TestChannelLocator.temp_dir, Dropcaster::CHANNEL_YML), channel_file)
|
90
|
+
end
|
91
|
+
end
|