From e8a4ab5f22aa5d332fc072ed8795953993f45749 Mon Sep 17 00:00:00 2001 From: Ben Eills Date: Mon, 1 Jul 2013 16:59:25 +0100 Subject: [PATCH] Added RSpec tests, although these are untested and should be checked over by someone who actually knows anything about RSpec before being pulled --- lib/cookie_extractor/browser_detector.rb | 3 ++- spec/browser_detector_spec.rb | 22 ++++++++++++++++++++++ 2 files changed, 24 insertions(+), 1 deletion(-) 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