Added RSpec tests, although these are untested and should be checked over by someone who actually knows anything about RSpec before being pulled
This commit is contained in:
parent
3217c96dd6
commit
e8a4ab5f22
2 changed files with 24 additions and 1 deletions
|
@ -4,13 +4,14 @@ module CookieExtractor
|
||||||
class NoCookieFileFoundException < Exception; end
|
class NoCookieFileFoundException < Exception; end
|
||||||
|
|
||||||
class BrowserDetector
|
class BrowserDetector
|
||||||
|
attr_reader :cookie_locations
|
||||||
|
|
||||||
@cookie_locations = {
|
@cookie_locations = {
|
||||||
"chrome" => "~/.config/google-chrome/Default/Cookies",
|
"chrome" => "~/.config/google-chrome/Default/Cookies",
|
||||||
"chromium" => "~/.config/chromium/Default/Cookies",
|
"chromium" => "~/.config/chromium/Default/Cookies",
|
||||||
"firefox" => "~/.mozilla/firefox/*.default/cookies.sqlite"
|
"firefox" => "~/.mozilla/firefox/*.default/cookies.sqlite"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
# Returns the extractor of the most recently used browser's cookies
|
# Returns the extractor of the most recently used browser's cookies
|
||||||
# or raise NoCookieFileFoundException if there are no cookies
|
# or raise NoCookieFileFoundException if there are no cookies
|
||||||
def self.guess
|
def self.guess
|
||||||
|
|
|
@ -40,4 +40,26 @@ describe CookieExtractor::BrowserDetector, "determining the correct extractor to
|
||||||
extractor.instance_of?(CookieExtractor::ChromeCookieExtractor).should be_true
|
extractor.instance_of?(CookieExtractor::ChromeCookieExtractor).should be_true
|
||||||
end
|
end
|
||||||
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
|
end
|
||||||
|
|
Loading…
Reference in a new issue