# encoding: utf-8 # # This file is part of the pincerna gem. Copyright (C) 2013 and above Shogun . # Licensed under the MIT license, which can be found at https://choosealicense.com/licenses/mit. # require "spec_helper" describe Pincerna::SafariBookmark do subject { Pincerna::SafariBookmark.new("QUERY", "yml") } describe "#read_bookmarks" do before(:each) do @plutil = < Children Title History WebBookmarkIdentifier History WebBookmarkType WebBookmarkTypeProxy WebBookmarkUUID CCC Children Children Children Sync Key "C=AAA" ServerID AAA URIDictionary title NAME 1 URLString URL 1 WebBookmarkType WebBookmarkTypeLeaf WebBookmarkUUID AAA Sync Key "C=AAA" ServerID AAA URIDictionary title NAME 2 URLString URL 2 WebBookmarkType WebBookmarkTypeLeaf WebBookmarkUUID AAA Sync Data CCC Key AAA ServerID BBB Title FOLDER 2 WebBookmarkType WebBookmarkTypeList WebBookmarkUUID CCC Sync Key "C=AAA" ServerID AAA URIDictionary title NAME 3 URLString URL 3 WebBookmarkType WebBookmarkTypeLeaf WebBookmarkUUID AAA Sync Data DDD Key CCC ServerID DDD Title FOLDER 1 WebBookmarkType WebBookmarkTypeList WebBookmarkUUID AAA Sync ServerID CCC Title BookmarksBar WebBookmarkType WebBookmarkTypeList WebBookmarkUUID DDD Sync ServerID CCC Title BookmarksMenu WebBookmarkType WebBookmarkTypeList WebBookmarkUUID DDD Children Sync Key "C=AAA" ServerID AAA URIDictionary title NAME 4 URLString URL 4 WebBookmarkType WebBookmarkTypeLeaf WebBookmarkUUID AAA ShouldOmitFromUI Sync ServerID CCC Title com.apple.ReadingList WebBookmarkType WebBookmarkTypeList WebBookmarkUUID DDD Sync ServerData BBB Title WebBookmarkFileVersion 1 WebBookmarkType WebBookmarkTypeList WebBookmarkUUID AAA EOPLUTIL end it "should call plutil to get latest bookmarks" do expect(subject).to receive(:execute_command).with("/usr/bin/plutil", "-convert", "xml1", "-o", "-", File.expand_path("~/Library/Safari/Bookmarks.plist")) subject.read_bookmarks end it "should return the correct list of bookmarks" do expect(subject.instance_variable_set(:@bookmarks, [])) allow(subject).to receive(:execute_command).and_return(@plutil) subject.read_bookmarks expect(subject.instance_variable_get(:@bookmarks)).to eq([ {name: "NAME 1", url: "URL 1", path: " \u2192 BookmarksBar \u2192 FOLDER 1 \u2192 FOLDER 2"}, {name: "NAME 2", url: "URL 2", path: " \u2192 BookmarksBar \u2192 FOLDER 1 \u2192 FOLDER 2"}, {name: "NAME 3", url: "URL 3", path: " \u2192 BookmarksBar \u2192 FOLDER 1"}, {name: "NAME 4", url: "URL 4", path: " \u2192 BookmarksMenu"} ]) end end end