# encoding: utf-8 require 'spec_helper' describe Command do let(:git_repo) { 'git_repo' } context '#init' do it 'creates a new repository' do switch_to_working_directory do Command.init(git_repo) end expect(path_exists?(git_repo)).to be_true end end context '#add' do it 'add dir/file to repository' do git_init(git_repo) create_file(File.join(git_repo, 'file.txt')) Dir.chdir(::File.join(working_directory, git_repo)) do Command.add('file.txt') end expect(git_status(git_repo)).to include("\tnew file: file.txt") end end context '#commit' do it 'commit dir/file to repository' do git_init(git_repo) create_file(File.join(git_repo, 'file.txt')) git_add(git_repo, 'file.txt') Dir.chdir(::File.join(working_directory, git_repo)) do Command.commit('file.txt') end expect(git_status(git_repo)).to include('nothing to commit, working directory clean') end end context '#show' do it 'show ref/sha in repository' do git_init(git_repo) create_file(File.join(git_repo, 'file.txt')) git_add(git_repo, 'file.txt') git_commit(git_repo) Dir.chdir(::File.join(working_directory, git_repo)) do expect(Command.show.first).to include('commit') end end end context '#diff_tree' do it 'diff values' do git_init(git_repo) create_file(File.join(git_repo, 'file.txt')) create_file(File.join(git_repo, 'file1.txt')) create_file(File.join(git_repo, 'file2.txt')) git_add(git_repo, 'file.txt') git_add(git_repo, 'file1.txt') git_add(git_repo, 'file2.txt') git_commit(git_repo) commit = git_show(git_repo, nil).first.split(" ")[1] Dir.chdir(::File.join(working_directory, git_repo)) do expect(Command.diff_tree(commit).last).to include('file2.txt') end end end context '#diff' do it 'diff values' do git_init(git_repo) create_file(File.join(git_repo, 'file.txt')) git_add(git_repo, 'file.txt') git_commit(git_repo) create_file(File.join(git_repo, 'file1.txt')) create_file(File.join(git_repo, 'file2.txt')) git_add(git_repo, 'file1.txt') git_add(git_repo, 'file2.txt') git_commit(git_repo) commit = git_show(git_repo, nil).first.split(" ")[1] Dir.chdir(::File.join(working_directory, git_repo)) do expect(Command.diff(commit,"#{commit}^").last).to include('file2.txt') end end end end