require 'spec_helper' require 'grit' require 'fileutils' describe Hillary::Repo do shared_context 'specific time' do around(:each) do |example| Timecop.freeze(Time.at(0)) do example.call end end end describe '.rc_tag_name' do include_context 'specific time' it 'generates an RC tag name' do expect(described_class.rc_tag_name).to eq('RC1969_12_31_19_00_00') end it 'matches the RC tag format' do expect(described_class.rc_tag_name).to match(described_class::RC_TAG_REGEX) end end describe '.production_tag_name' do include_context 'specific time' it 'generates an production tag name' do expect(described_class.production_tag_name).to eq('1969_12_31_19_00_00') end it 'matches the production tag format' do expect(described_class.production_tag_name).to match(described_class::PRODUCTION_TAG_REGEX) end end describe '#checkout' do include_context 'git repository' context 'when called with a branch that exists' do before(:each) do local_repo.git.branch({}, 'dev') remote_repo.git.branch({}, 'dev') add_file_to_remote('chicken.txt', 'chicken', 'dev') repo.checkout('dev') end it 'checks out the specified branch' do expect(local_repo.head.name).to eq('dev') end it 'updates the local branch from remote' do expect(File.exist?('chicken.txt')).to eq(true) end it 'displays information about what is happening' do expect(out.string).to eq("Checking out dev and updating from origin\n") end end context 'when called with a branch that does not exist' do it 'raises MissingHeadError' do expect{repo.checkout('dev')}.to raise_error(Hillary::Repo::MissingHeadError) end it 'displays information about what is happening' do repo.checkout('dev') rescue nil expect(out.string).to eq("Checking out dev and updating from origin\n") end end context 'when called on a repository that is dirty' do before(:each) do FileUtils.touch('blah') local_repo.add('blah') end it 'raises DirtyProjectError' do expect{repo.checkout('dev')}.to raise_error(Hillary::Repo::DirtyProjectError) end end end describe '#create_rc_tag' do include_context 'git repository' before(:each){repo.create_rc_tag('master', 'RC1969_12_31_19_00_00')} let(:local_master){local_repo.get_head('master')} let(:local_tag){local_repo.tags.first} let(:remote_tag){remote_repo.tags.first} it 'creates a tag pointing to the same commit as master' do expect(local_tag.commit.sha).to eq(local_master.commit.sha) end it 'pushes the tag to origin' do expect(remote_tag.commit.sha).to eq(local_master.commit.sha) end it 'displays information about what is happening' do expect(out.string).to match( %r{Tagging origin/master \([\da-f]+\) as RC1969_12_31_19_00_00\nPushing RC1969_12_31_19_00_00 to origin\n} ) end end describe '#create_production_tag' do include_context 'git repository' before(:each) do repo.create_rc_tag('master', 'RC1969_12_31_19_00_00') repo.create_production_tag('2001_11_11_11_11_11') end let(:local_rc_tag){local_repo.tags.find{|tag| tag.name == 'RC1969_12_31_19_00_00'}} let(:local_production_tag){local_repo.tags.find{|tag| tag.name == '2001_11_11_11_11_11'}} let(:remote_production_tag){remote_repo.tags.find{|tag| tag.name == '2001_11_11_11_11_11'}} it 'creates a tag pointing to the last RC' do expect(local_production_tag.commit.sha).to eq(local_rc_tag.commit.sha) end it 'pushes the tag to origin' do expect(remote_production_tag.commit.sha).to eq(local_rc_tag.commit.sha) end it 'displays information about what is happening' do expect(out.string).to match( %r{Tagging origin/master \([\da-f]+\) as RC1969_12_31_19_00_00\nPushing RC1969_12_31_19_00_00 to origin\nTagging RC1969_12_31_19_00_00 \([\da-f]+\) as 2001_11_11_11_11_11\nPushing 2001_11_11_11_11_11 to origin\n} ) end end end