Skip to content

Instantly share code, notes, and snippets.

@workmad3
Created May 17, 2010 10:38
Show Gist options
  • Save workmad3/403627 to your computer and use it in GitHub Desktop.
Save workmad3/403627 to your computer and use it in GitHub Desktop.
class Delicious::BookmarkList
def initialize(username, bookmarks)
@bookmarks = parse_bookmarks(bookmarks)
end
def parse_bookmarks(bookmarks)
bookmarks.xpath('//item').map do |item|
{:title => get_xpath_text('./title', item),
:link => get_xpath_text('./link', item),
:description => get_xpath_text('./description', item)}
end
end
def get_xpath_text(xpath, node)
node.xpath(xpath).each {|n| return n.text}
end
def bookmarks
@bookmarks
end
end
1) Delicious::BookmarkList should find the bookmark title, address and description of the bookmark list provided
Failure/Error: bookmark_list.bookmarks.should == [{:title => "Access to MySQL", :link => "http://www.bullzip.com/products/a2m/info.php", :description => "Bullzip Utility Source - Free software for printing PDF documents and converting Microsoft Access databases to MySQL."}]
expected: [{:title=>"Access to MySQL", :link=>"http://www.bullzip.com/products/a2m/info.php", :description=>"Bullzip Utility Source - Free software for printing PDF documents and converting Microsoft Access databases to MySQL."}],
got: [{:title=>"Access To MySQL", :link=>"http://www.bullzip.com/products/a2m/info.php", :description=>"Bullzip Utility Source - Free software for printing PDF documents and converting Microsoft Access databases to MySQL."}] (using ==)
# ./spec/models/delicious/bookmark_list_spec.rb:7:in `block (2 levels) in <top (required)>'
it "should find the bookmark title, address and description of the bookmark list provided" do
noko = Nokogiri::XML("<rss><channel><item><title>Access To MySQL</title><link>http://www.bullzip.com/products/a2m/info.php</link><description>Bullzip Utility Source - Free software for printing PDF documents and converting Microsoft Access databases to MySQL.</description></item></channel></rss>")
bookmark_list = ::Delicious::BookmarkList.new("username", noko)
bookmark_list.bookmarks.should == [{:title => "Access to MySQL", :link => "http://www.bullzip.com/products/a2m/info.php", :description => "Bullzip Utility Source - Free software for printing PDF documents and converting Microsoft Access databases to MySQL."}]
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment