rubypodder 0.1.1 → 0.1.2

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/Rakefile CHANGED
@@ -4,7 +4,7 @@ require 'rake/gempackagetask'
4
4
  spec = Gem::Specification.new do |s|
5
5
  s.platform = Gem::Platform::RUBY
6
6
  s.name = "rubypodder"
7
- s.version = "0.1.1"
7
+ s.version = "0.1.2"
8
8
  s.author = "Lex Miller"
9
9
  s.email = "lex.miller @nospam@ gmail.com"
10
10
  s.summary = "A podcast aggregator without an interface"
data/bin/rubypodder CHANGED
@@ -1,2 +1,8 @@
1
+ $:.unshift File.join(File.dirname(__FILE__), "..", "lib")
1
2
  require 'rubypodder'
3
+ require 'optparse'
4
+ opts = OptionParser.new
5
+ opts.on("-v", "--version") { puts RubyPodder::Version; exit }
6
+ opts.on("-h", "--help") { puts opts.to_s + "See http://rubypodder.rubyforge.org/\n"; exit }
7
+ opts.parse(*ARGV)
2
8
  RubyPodder.new.run
data/lib/rubypodder.rb CHANGED
@@ -17,6 +17,8 @@ end
17
17
 
18
18
  class RubyPodder
19
19
 
20
+ Version = 'rubypodder v0.1.2'
21
+
20
22
  attr_reader :conf_file, :log_file, :done_file, :date_dir
21
23
 
22
24
  def initialize(file_base="~/.rubypodder/rp")
@@ -78,9 +80,13 @@ class RubyPodder
78
80
  def download(url)
79
81
  return if already_downloaded(url)
80
82
  @log.info(" Downloading: #{url}")
81
- file_name = dest_file_name(url)
82
- rio(file_name) < rio(url)
83
- record_download(url)
83
+ begin
84
+ file_name = dest_file_name(url)
85
+ rio(file_name) < rio(url)
86
+ record_download(url)
87
+ rescue
88
+ @log.error(" Failed to download #{url}")
89
+ end
84
90
  end
85
91
 
86
92
  def remove_dir_if_empty(dirname)
@@ -94,9 +100,14 @@ class RubyPodder
94
100
  end
95
101
 
96
102
  def run
97
- @log.info("Starting")
103
+ @log.info("Starting (#{Version})")
98
104
  read_feeds.each do |url|
99
- http_body = rio(url).contents
105
+ begin
106
+ http_body = rio(url).contents
107
+ rescue
108
+ @log.error(" Can't read from #{url}")
109
+ next
110
+ end
100
111
  rss = parse_rss(http_body)
101
112
  @log.info("Channel: #{rss.channel.title}")
102
113
  rss.items.each do |item|
@@ -189,6 +189,13 @@ class TC_RubyPodder < Test::Unit::TestCase
189
189
  assert(!File.exists?(dest_file))
190
190
  end
191
191
 
192
+ def test_download_error_is_logged
193
+ @rp.download("http://very.very.broken.url/oh/no/oh/dear.xml")
194
+ File.open( @rp.log_file ) do |f|
195
+ assert(f.any? { |line| line =~ /ERROR/ }, "Error in download should be logged")
196
+ end
197
+ end
198
+
192
199
  def test_remove_dir_if_empty
193
200
  system("mkdir -p " + @subdir)
194
201
  @rp.remove_dir_if_empty(@subdir)
@@ -199,4 +206,22 @@ class TC_RubyPodder < Test::Unit::TestCase
199
206
  assert(File.exists?(@subdir))
200
207
  end
201
208
 
209
+ def test_log_contains_version
210
+ File.open("/tmp/test_rp.conf", "w") { |file| file.write("# Empty config file\n") }
211
+ @rp = RubyPodder.new("/tmp/test_rp")
212
+ @rp.run
213
+ File.open( @rp.log_file ) do |f|
214
+ assert(f.any? { |line| line =~ /Starting.+#{RubyPodder::Version}/ }, "'Starting' log entry should contain '#{RubyPodder::Version}'")
215
+ end
216
+ end
217
+
218
+ def test_log_contains_error_for_unreadable_feed_url
219
+ File.open("/tmp/test_rp.conf", "w") { |file| file.write("http://very.very.broken.url/oh/no/oh/dear.xml\n") }
220
+ @rp = RubyPodder.new("/tmp/test_rp")
221
+ @rp.run
222
+ File.open( @rp.log_file ) do |f|
223
+ assert(f.any? { |line| line =~ /ERROR/ }, "Error in feed url should be logged")
224
+ end
225
+ end
226
+
202
227
  end
@@ -0,0 +1,52 @@
1
+ require 'test/unit'
2
+
3
+ class StringStream < String
4
+ def write(message)
5
+ self.<< message
6
+ end
7
+ end
8
+
9
+ def wrap(&b)
10
+ raise "Expected block!" unless block_given?
11
+ s = StringStream.new
12
+ old = $stdout.clone
13
+ $stdout = s
14
+ b.call
15
+ $stdout = old
16
+ s
17
+ end
18
+
19
+ def last_log
20
+ log = '/tmp/.rubypodder/rp.log'
21
+ File.exists?(log) ? File.mtime('/tmp/.rubypodder/rp.log') : Time.at(0)
22
+ end
23
+
24
+ def exits_without_doing_anything(&b)
25
+ raise "Expected block!" unless block_given?
26
+ before = last_log
27
+ b.call
28
+ after = last_log
29
+ before == after
30
+ end
31
+
32
+ class TC_stdout < Test::Unit::TestCase
33
+ def setup
34
+ ENV['HOME'] = "/tmp"
35
+ @bindir = File.join(File.dirname(__FILE__), "..", "bin")
36
+ end
37
+
38
+ def teardown
39
+ system("rm -rf " + "/tmp/.rubypodder")
40
+ end
41
+
42
+ def test_version
43
+ assert_equal "rubypodder v0.1.2\n", wrap { puts `ruby #{@bindir}/rubypodder --version` }
44
+ assert exits_without_doing_anything { `ruby #{@bindir}/rubypodder --version` }, "--version doesn't exit immediately"
45
+ end
46
+
47
+ def test_help
48
+ assert_match %r{See http://rubypodder.rubyforge.org/}, wrap { puts `ruby #{@bindir}/rubypodder --help` }
49
+ assert exits_without_doing_anything { `ruby #{@bindir}/rubypodder --help` }, "--help doesn't exit immediately"
50
+ end
51
+
52
+ end
@@ -0,0 +1,4 @@
1
+ $:.unshift File.join(File.dirname(__FILE__), "..", "tests")
2
+ require 'test/unit'
3
+ require 'tc_rubypodder.rb'
4
+ require 'tc_stdout.rb'
metadata CHANGED
@@ -3,8 +3,8 @@ rubygems_version: 0.8.11
3
3
  specification_version: 1
4
4
  name: rubypodder
5
5
  version: !ruby/object:Gem::Version
6
- version: 0.1.1
7
- date: 2007-01-22 00:00:00 +13:00
6
+ version: 0.1.2
7
+ date: 2007-02-25 00:00:00 +13:00
8
8
  summary: A podcast aggregator without an interface
9
9
  require_paths:
10
10
  - lib
@@ -31,11 +31,15 @@ authors:
31
31
  files:
32
32
  - lib/rubypodder.rb
33
33
  - tests/tc_rubypodder.rb
34
+ - tests/ts_rubypodder.rb
35
+ - tests/tc_stdout.rb
34
36
  - Rakefile
35
37
  - README
36
38
  - MIT-LICENSE
37
39
  test_files:
38
40
  - tests/tc_rubypodder.rb
41
+ - tests/ts_rubypodder.rb
42
+ - tests/tc_stdout.rb
39
43
  rdoc_options: []
40
44
  extra_rdoc_files:
41
45
  - README