diff --git a/lib/cookie_extractor/browser_detector.rb b/lib/cookie_extractor/browser_detector.rb index de67f05..17cef26 100644 --- a/lib/cookie_extractor/browser_detector.rb +++ b/lib/cookie_extractor/browser_detector.rb @@ -4,13 +4,14 @@ module CookieExtractor class NoCookieFileFoundException < Exception; end class BrowserDetector + attr_reader :cookie_locations + @cookie_locations = { "chrome" => "~/.config/google-chrome/Default/Cookies", "chromium" => "~/.config/chromium/Default/Cookies", "firefox" => "~/.mozilla/firefox/*.default/cookies.sqlite" } - # Returns the extractor of the most recently used browser's cookies # or raise NoCookieFileFoundException if there are no cookies def self.guess diff --git a/spec/browser_detector_spec.rb b/spec/browser_detector_spec.rb index 179cd5b..c01cd4c 100644 --- a/spec/browser_detector_spec.rb +++ b/spec/browser_detector_spec.rb @@ -40,4 +40,26 @@ describe CookieExtractor::BrowserDetector, "determining the correct extractor to extractor.instance_of?(CookieExtractor::ChromeCookieExtractor).should be_true end end + + describe "when no cookie files are found in the standard locations" do + before :each do + Dir.stub!(:glob).and_return([]) + end + + it "should raise NoCookieFileFoundException" do + lambda { CookieExtractor::BrowserDetector.guess }. + should raise_error(CookieExtractor::NoCookieFileFoundException) + end + end + + describe "when multiple cookie files are found in the standard locations" do + before :each do + Dir.stub!(:glob).and_return(CookieExtractor::BrowserDetector.cookie_locations.values) + end + + it "should return a ChromeCookieExtractor or FirefoxCookieExtractor" do + lambda { CookieExtractor::BrowserDetector.guess }. + should be_kind_of(CookieExtractor::Common) + end + end end