Skip to content

Commit 0402044

Browse files
committed
Fix ProtectedBranches specs to not use stub for config
This also pulls up some duplicate stubs to DRY up the tests.
1 parent ab17caf commit 0402044

File tree

1 file changed

+20
-15
lines changed

1 file changed

+20
-15
lines changed

spec/overcommit/hook/pre_push/protected_branches_spec.rb

+20-15
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,14 @@
22
require 'overcommit/hook_context/pre_push'
33

44
describe Overcommit::Hook::PrePush::ProtectedBranches do
5-
let(:config) { Overcommit::ConfigurationLoader.default_configuration }
5+
let(:hook_config) { {} }
6+
let(:config) do
7+
Overcommit::ConfigurationLoader.default_configuration.merge(
8+
Overcommit::Configuration.new(
9+
'PrePush' => { 'ProtectedBranches' => hook_config }
10+
)
11+
)
12+
end
613
let(:context) { double('context') }
714
subject { described_class.new(config, context) }
815

@@ -39,38 +46,36 @@
3946

4047
shared_examples_for 'protected branch' do
4148
context 'when push is not destructive' do
49+
before do
50+
pushed_ref.stub(:destructive?).and_return(false)
51+
end
52+
4253
context 'and destructive_only set to false' do
43-
before do
44-
pushed_ref.stub(:destructive?).and_return(false)
45-
subject.stub(destructive_only?: false)
46-
end
54+
let(:hook_config) { { 'destructive_only' => false } }
4755

4856
it { should fail_hook }
4957
end
5058

5159
context 'and destructive_only set to true' do
52-
before do
53-
subject.stub(destructive_only?: true)
54-
pushed_ref.stub(:destructive?).and_return(false)
55-
end
60+
let(:hook_config) { { 'destructive_only' => true } }
5661

5762
it { should pass }
5863
end
5964
end
6065

6166
context 'when push is destructive' do
67+
before do
68+
pushed_ref.stub(:destructive?).and_return(true)
69+
end
70+
6271
context 'when destructive_only is set to true' do
63-
before do
64-
pushed_ref.stub(:destructive?).and_return(true)
65-
end
72+
let(:hook_config) { { 'destructive_only' => true } }
6673

6774
it { should fail_hook }
6875
end
6976

7077
context 'when destructive_only is set to false' do
71-
before do
72-
subject.stub(:allow_non_destructive?).and_return(true)
73-
end
78+
let(:hook_config) { { 'destructive_only' => false } }
7479

7580
it { should fail_hook }
7681
end

0 commit comments

Comments
 (0)