Hello list,
I had a hard time to find out a way to mock the singleton feed method of
the
following class:
class RssReader
def self.feed(feed_url)
output = []
open(feed_url) do |http|
response = http.read
result = RSS::Parser.parse(response, false)
result.items.each_with_index do |item, i|
output << {:title => item.title, :description =>
item.description,
:pubDate => item.pubDate, :link => item.link}
end unless result.nil?
end
output
end
end
Since it is being passed a block, I could not intercept the code inside
the
block, the specific code I’d like to stub is the http.read. I have tried
to
do:
Http.should_receive(:read).and_return(xml) #xml being a fixture, loaded
from
a file.
However, the stub is not applied.
Any ideas on how this could be solved? The only way I could think is to
avoid using the block…
Thanks,
Marcelo.