|
2 | 2 | require 'overcommit/hook_context/pre_push'
|
3 | 3 |
|
4 | 4 | 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 |
6 | 13 | let(:context) { double('context') }
|
7 | 14 | subject { described_class.new(config, context) }
|
8 | 15 |
|
|
39 | 46 |
|
40 | 47 | shared_examples_for 'protected branch' do
|
41 | 48 | context 'when push is not destructive' do
|
| 49 | + before do |
| 50 | + pushed_ref.stub(:destructive?).and_return(false) |
| 51 | + end |
| 52 | + |
42 | 53 | 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 } } |
47 | 55 |
|
48 | 56 | it { should fail_hook }
|
49 | 57 | end
|
50 | 58 |
|
51 | 59 | 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 } } |
56 | 61 |
|
57 | 62 | it { should pass }
|
58 | 63 | end
|
59 | 64 | end
|
60 | 65 |
|
61 | 66 | context 'when push is destructive' do
|
| 67 | + before do |
| 68 | + pushed_ref.stub(:destructive?).and_return(true) |
| 69 | + end |
| 70 | + |
62 | 71 | 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 } } |
66 | 73 |
|
67 | 74 | it { should fail_hook }
|
68 | 75 | end
|
69 | 76 |
|
70 | 77 | 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 } } |
74 | 79 |
|
75 | 80 | it { should fail_hook }
|
76 | 81 | end
|
|
0 commit comments