Created
May 17, 2010 10:38
-
-
Save workmad3/403627 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
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 |
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
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)>' |
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
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