Skip to content

Commit 9e13ca2

Browse files
sdsShane da Silva
authored and
Shane da Silva
committed
Add PostCheckout context specs
Change-Id: I618488922811b331bc256a88d8ace8ab23422e3a Reviewed-on: http://gerrit.causes.com/35572 Reviewed-by: Shane da Silva <shane@causes.com> Tested-by: Shane da Silva <shane@causes.com>
1 parent 5f72fe4 commit 9e13ca2

File tree

5 files changed

+59
-3
lines changed

5 files changed

+59
-3
lines changed

spec/overcommit/hook_context/base_spec.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
require 'spec_helper'
22

33
describe Overcommit::HookContext::Base do
4-
let(:config) { double('context') }
4+
let(:config) { double('config') }
55
let(:args) { [] }
66
let(:input) { '' }
77
let(:context) { described_class.new(config, args, input) }

spec/overcommit/hook_context/commit_msg_spec.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
require 'overcommit/hook_context/commit_msg'
33

44
describe Overcommit::HookContext::CommitMsg do
5-
let(:config) { double('context') }
5+
let(:config) { double('config') }
66
let(:args) { [commit_message_file] }
77
let(:input) { '' }
88
let(:context) { described_class.new(config, args, input) }
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
require 'spec_helper'
2+
require 'overcommit/hook_context/post_checkout'
3+
4+
describe Overcommit::HookContext::PostCheckout do
5+
let(:config) { double('config') }
6+
let(:args) { [previous_head, new_head, branch_flag] }
7+
let(:previous_head) { random_hash }
8+
let(:new_head) { random_hash }
9+
let(:branch_flag) { '1' }
10+
let(:input) { '' }
11+
let(:context) { described_class.new(config, args, input) }
12+
13+
describe '#previous_head' do
14+
subject { context.previous_head }
15+
16+
it { should == previous_head }
17+
end
18+
19+
describe '#new_head' do
20+
subject { context.new_head }
21+
22+
it { should == new_head }
23+
end
24+
25+
describe '#branch_checkout?' do
26+
subject { context.branch_checkout? }
27+
28+
context 'when the flag is 0' do
29+
let(:branch_flag) { '0' }
30+
31+
it { should be_false }
32+
end
33+
34+
context 'when the flag is 1' do
35+
it { should be_true }
36+
end
37+
end
38+
39+
describe '#file_checkout?' do
40+
subject { context.file_checkout? }
41+
42+
context 'when the flag is 0' do
43+
let(:branch_flag) { '0' }
44+
45+
it { should be_true }
46+
end
47+
48+
context 'when the flag is 1' do
49+
it { should be_false }
50+
end
51+
end
52+
end

spec/overcommit/hook_context/pre_commit_spec.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
require 'overcommit/hook_context/pre_commit'
33

44
describe Overcommit::HookContext::PreCommit do
5-
let(:config) { double('context') }
5+
let(:config) { double('config') }
66
let(:args) { [] }
77
let(:input) { '' }
88
let(:context) { described_class.new(config, args, input) }

spec/support/git_spec_helpers.rb

+4
Original file line numberDiff line numberDiff line change
@@ -25,4 +25,8 @@ def directory(name = 'some-dir', &block)
2525

2626
File.join(tmpdir, name)
2727
end
28+
29+
def random_hash
30+
40.times.map { (65 + rand(26)).chr }.join
31+
end
2832
end

0 commit comments

Comments
 (0)