will create output directory if doesn't exist

This commit is contained in:
Tomasz Gieniusz 2012-11-01 18:23:44 +01:00
parent 4807e11353
commit b5f198a240
3 changed files with 7 additions and 13 deletions

View file

@ -5,7 +5,7 @@ module GitStats
delegate :render_all, to: :@view
def initialize(repo_path, out_path)
validate_paths(repo_path, out_path)
validate_repo_path(repo_path)
@repo = GitData::Repo.new(path: repo_path)
view_data = StatsView::ViewData.new(@repo)
@ -15,18 +15,12 @@ module GitStats
end
private
def validate_paths(repo_path, out_path)
validate_repo_path(repo_path)
validate_out_path(out_path)
end
def validate_repo_path(repo_path)
raise ArgumentError, "#{repo_path} is not a git repository" unless Dir.exists?("#{repo_path}/.git")
end
def validate_out_path(out_path)
raise ArgumentError, "#{out_path} is not a directory" unless Dir.exists?(out_path)
end
end
end

View file

@ -60,9 +60,14 @@ module GitStats
end
def prepare_static_content
create_out_dir
FileUtils.cp_r(Dir["../../../../templates/static/*".absolute_path], @out_path)
end
def create_out_dir
FileUtils.mkdir_p(@out_path) unless Dir.exists?(@out_path)
end
def prepare_assets
FileUtils.cp_r('../../../../templates/assets'.absolute_path, @out_path)
end

View file

@ -13,11 +13,6 @@ describe GitStats::Generator do
expect { generator }.to raise_error(ArgumentError)
end
it "should raise exception if given out directory doesn't exist" do
Dir.should_receive(:exists?).with(out_path).and_return(false)
expect { generator }.to raise_error(ArgumentError)
end
it 'should pass command observer to repo' do
repo = double('repo')
GitStats::GitData::Repo.should_receive(:new).with(path: repo_path).and_return(repo)