Created
October 4, 2009 06:46
-
-
Save jsmestad/201206 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require File.dirname(__FILE__) + '/../spec_helper' | |
# FYI this is using StaleFish, but tests should run regardless. | |
describe TvRage do | |
context '.full_schedule' do | |
it 'should call required functions' do | |
TvRage.should_receive(:fetch_xml).once | |
TvRage.full_schedule | |
end | |
end | |
context '.fetch' do | |
it 'should not require parameters' do | |
lambda { TvRage.send(:fetch_xml, 'http://services.tvrage.com/feeds/fullschedule.php') }.should_not raise_error(ArgumentError) | |
end | |
it 'should return xml document' do | |
TvRage.send(:fetch_xml, | |
'http://services.tvrage.com/feeds/fullschedule.php', | |
'country' => 'US', | |
'24_format' => '1').should be_a_kind_of(Hpricot::Doc) | |
end | |
end | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class TvRage | |
def self.full_schedule(country='US') | |
doc = self.fetch_xml('http://services.tvrage.com/feeds/fullschedule.php', 'country' => country, '24_format' => '1') | |
p "full_schedule - #{doc.class}" | |
#doc.search('//show').each {|show| process_show(show) } | |
end | |
protected | |
def self.fetch_xml(url, params={}) | |
uri = url | |
unless params.empty? | |
uri << '?' + params.to_a.collect { |param| param.join('=') }.join('&') | |
end | |
doc = Hpricot::XML(open(uri)) | |
p "fetch_xml - #{doc.class}" | |
return doc | |
end | |
def self.process_show(show_node) | |
end | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Output: | |
fetch_xml - Hpricot::Doc | |
full_schedule - NilClass | |
Any idea why I cannot get fetch_xml to return anything but nil? | |
but if I do the doc.search in the fetch_xml function, it works flawlessly. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'hpricot' | |
require 'open-uri' | |
class TvRage | |
class << self | |
attr_accessor :doc | |
end | |
def self.full_schedule(country='US') | |
fetch_xml('http://services.tvrage.com/feeds/fullschedule.php', 'country' => country, '24_format' => '1') | |
doc.search('//show').each {|show| process_show(show) } | |
end | |
protected | |
def self.fetch_xml(uri, params={}) | |
unless params.empty? | |
uri << '?' + params.to_a.collect { |param| param.join('=') }.join('&') | |
end | |
self.doc = open(uri) { |f| Hpricot::XML(f) } | |
end | |
def self.process_show(show_node) | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment