Add Store#size

pull/165/head
Thibaut 10 years ago
parent da3ca7d8c7
commit 456c4cb811

@ -71,6 +71,11 @@ module Docs
file_mtime(path) if file_exist?(path)
end
def size(path)
path = expand_path(path)
file_size(path) if file_exist?(path)
end
def each(&block)
list_files(working_path, &block)
end
@ -109,6 +114,10 @@ module Docs
raise NotImplementedError
end
def file_size(path)
raise NotImplementedError
end
def list_files(path, &block)
raise NotImplementedError
end

@ -37,6 +37,10 @@ module Docs
File.mtime(path)
end
def file_size(path)
File.size(path)
end
def list_files(path)
Find.find path do |file|
next if file == path

@ -16,6 +16,7 @@ module Docs
alias_method :delete_file, :nil
alias_method :file_exist?, :nil
alias_method :file_mtime, :nil
alias_method :file_size, :nil
alias_method :list_files, :nil
end
end

@ -330,6 +330,27 @@ class DocsAbstractStoreTest < MiniTest::Spec
end
end
describe "#size" do
it "raises an error with a path outside of #working_path" do
@path = '/path'
assert_raises InvalidPathError do
store.size '../file'
end
end
it "returns nil when the file doesn't exist" do
stub(store).file_exist?('/file') { false }
dont_allow(store).file_size
assert_nil store.size('file')
end
it "returns #file_size when the file exists" do
stub(store).file_exist?('/file') { true }
stub(store).file_size('/file') { 1 }
assert_equal 1, store.size('file')
end
end
describe "#each" do
it "calls #list_files with #working_path" do
store.open 'dir'

@ -121,6 +121,13 @@ class DocsFileStoreTest < MiniTest::Spec
end
end
describe "#size" do
it "returns the file's size" do
write 'file', 'content'
assert_equal File.size(expand_path('file')), store.size('file')
end
end
describe "#each" do
let :paths do
paths = []

Loading…
Cancel
Save