Hello all,
In yet another attempt to learn Ruby on Rails and Rspec I have started writing a simple life streaming app with will aggregate feeds from several places and save them in a database for later use.
An internet search eventually led me to the following method for looping through the feeds in the database, getting the contents of the URL and then passing this into another model to prepare and save it.
def self.cache_all
feeds = self.find(:all)
for feed in feeds
xml = REXML::Document.new Net::HTTP.get(URI.parse(feed.url))
xml.elements.each '//item' do |item|
Item.prepare_and_save(feed, item)
end
end
end
Problems are now beginning to arise when trying to write the specs for this method. I started from scratch slowly building up the specs but it has led to an awful amount of mocks and stubs, and I am not even sure whether they are asking the correct things of the method.
Can anyone give me some pointers on how to write useful, meaningful specs for this method?
The other thing I have found is that I seem to have incorrectly stubbed xml.elements.each meaning that the contents of the block are never called, how should I be specifying this behavior?
I have pastied the complete code for the Feed model, the spec and a little helper at:
http://pastie.caboo.se/203941Thanks in advance,
Andy