forked from sds/overcommit
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcli_spec.rb
More file actions
127 lines (104 loc) · 3.82 KB
/
cli_spec.rb
File metadata and controls
127 lines (104 loc) · 3.82 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
require 'spec_helper'
require 'overcommit/cli'
require 'overcommit/hook_context/run_all'
describe Overcommit::CLI do
describe '#run' do
let(:logger) { Overcommit::Logger.silent }
let(:input) { double('input') }
let(:cli) { described_class.new(arguments, input, logger) }
subject { cli.run }
before do
Overcommit::Utils.stub(:repo_root).and_return('current-dir')
end
context 'with no arguments' do
let(:arguments) { [] }
it 'attempts to install in the current directory' do
Overcommit::Installer.any_instance.
should_receive(:run).
with('current-dir',
hash_including(action: :install))
subject
end
end
context 'with the --list-hooks option specified' do
let(:arguments) { ['--list-hooks'] }
let(:contexts) do
Overcommit::ConfigurationLoader.new(logger).load_repo_config.all_hook_configs.keys
end
before { cli.stub(:halt) }
it 'prints the installed hooks' do
logger.should_receive(:log).at_least(contexts.count)
subject
end
end
context 'with the uninstall switch specified' do
let(:arguments) { ['--uninstall'] }
it 'uninstalls hooks from the current directory' do
Overcommit::Installer.any_instance.
should_receive(:run).
with('current-dir',
hash_including(action: :uninstall))
subject
end
context 'and an explicit target' do
let(:arguments) { super() + ['target-dir'] }
it 'uninstalls hooks from the target directory' do
Overcommit::Installer.any_instance.
should_receive(:run).
with('target-dir',
hash_including(action: :uninstall))
subject
end
end
end
context 'with the install switch specified' do
let(:arguments) { ['--install'] }
it 'installs hooks into the current directory' do
Overcommit::Installer.any_instance.
should_receive(:run).
with('current-dir',
hash_including(action: :install))
subject
end
context 'and an explicit target' do
let(:arguments) { super() + ['target-dir'] }
it 'installs hooks from the target directory' do
Overcommit::Installer.any_instance.
should_receive(:run).
with('target-dir',
hash_including(action: :install))
subject
end
end
end
context 'with the template directory switch specified' do
let(:arguments) { ['--template-dir'] }
before do
cli.stub(:halt)
end
it 'prints the location of the template directory' do
capture_stdout { subject }.chomp.should end_with 'template-dir'
end
end
context 'with the run switch specified' do
let(:arguments) { ['--run'] }
let(:config) { Overcommit::ConfigurationLoader.default_configuration }
before do
cli.stub(:halt)
end
it 'creates a HookRunner with the run-all context' do
Overcommit::HookRunner.should_receive(:new).
with(config,
logger,
instance_of(Overcommit::HookContext::RunAll),
instance_of(Overcommit::Printer)).
and_call_original
subject
end
it 'runs the HookRunner' do
Overcommit::HookRunner.any_instance.should_receive(:run)
subject
end
end
end
end