Added RSpec tests, although these are untested and should be checked over by someone who actually knows anything about RSpec before being pulled

master
Ben Eills 2013-07-01 16:59:25 +01:00
parent 3217c96dd6
commit e8a4ab5f22
2 changed files with 24 additions and 1 deletions

View File

@ -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

View File

@ -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