-
Notifications
You must be signed in to change notification settings - Fork 481
/
cli_spec.rb
187 lines (143 loc) · 5.05 KB
/
cli_spec.rb
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
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
require 'spec_helper'
require 'guard/cli'
describe Guard::CLI do
let(:guard) { Guard }
let(:ui) { Guard::UI }
let(:dsl_describer) { double('DslDescriber instance') }
describe '#start' do
before { Guard.stub(:start) }
it 'delegates to Guard.start' do
expect(Guard).to receive(:start)
subject.start
end
context 'with a Gemfile in the project dir' do
before do
File.stub(:exists?).with('Gemfile').and_return true
end
context 'when running with Bundler' do
before do
@bundler_env = ENV['BUNDLE_GEMFILE']
ENV['BUNDLE_GEMFILE'] = 'Gemfile'
end
after { ENV['BUNDLE_GEMFILE'] = @bundler_env }
it 'does not show the Bundler warning' do
expect(Guard::UI).to_not receive(:info).with(/Guard here!/)
subject.start
end
end
context 'when running without Bundler' do
before do
@bundler_env = ENV['BUNDLE_GEMFILE']
ENV['BUNDLE_GEMFILE'] = nil
end
after { ENV['BUNDLE_GEMFILE'] = @bundler_env }
it 'does show the Bundler warning' do
expect(Guard::UI).to receive(:info).with(/Guard here!/)
subject.start
end
it 'does not show the Bundler warning with the :no_bundler_warning flag' do
expect(Guard::UI).to_not receive(:info).with(/Guard here!/)
subject.options = { no_bundler_warning: true }
subject.start
end
end
end
context 'without a Gemfile in the project dir' do
before do
expect(File).to receive(:exists?).with('Gemfile').and_return false
@bundler_env = ENV['BUNDLE_GEMFILE']
ENV['BUNDLE_GEMFILE'] = nil
end
after { ENV['BUNDLE_GEMFILE'] = @bundler_env }
it 'does not show the Bundler warning' do
expect(Guard::UI).to_not receive(:info).with(/Guard here!/)
subject.start
end
end
end
describe '#list' do
it 'outputs the Guard plugins list' do
expect(::Guard::DslDescriber).to receive(:new) { dsl_describer }
expect(dsl_describer).to receive(:list)
subject.list
end
end
describe '#notifiers' do
it 'outputs the notifiers list' do
expect(::Guard::DslDescriber).to receive(:new) { dsl_describer }
expect(dsl_describer).to receive(:notifiers)
subject.notifiers
end
end
describe '#version' do
it 'shows the current version' do
expect(subject).to receive(:puts).with(/#{ ::Guard::VERSION }/)
subject.version
end
end
describe '#init' do
let(:options) { { bare: false } }
before do
subject.stub(options: options)
Guard::Guardfile.stub(:create_guardfile)
Guard::Guardfile.stub(:initialize_all_templates)
end
it 'creates a Guardfile by delegating to Guardfile.create_guardfile' do
expect(Guard::Guardfile).to receive(:create_guardfile).with(abort_on_existence: options[:bare])
subject.init
end
it 'initializes the templates of all installed Guards by delegating to Guardfile.initialize_all_templates' do
expect(Guard::Guardfile).to receive(:initialize_all_templates)
subject.init
end
it 'initializes each passed template by delegating to Guardfile.initialize_template' do
expect(Guard::Guardfile).to receive(:initialize_template).with('rspec')
expect(Guard::Guardfile).to receive(:initialize_template).with('pow')
subject.init 'rspec','pow'
end
context 'when passed a guard name' do
it 'initializes the template of the passed Guard by delegating to Guardfile.initialize_template' do
expect(Guard::Guardfile).to receive(:initialize_template).with('rspec')
subject.init 'rspec'
end
end
context 'with the bare option' do
let(:options) { {bare: true} }
it 'Only creates the Guardfile and does not initialize any Guard template' do
expect(Guard::Guardfile).to receive(:create_guardfile)
expect(Guard::Guardfile).to_not receive(:initialize_template)
expect(Guard::Guardfile).to_not receive(:initialize_all_templates)
subject.init
end
end
context 'when running with Bundler' do
before do
@bundler_env = ENV['BUNDLE_GEMFILE']
ENV['BUNDLE_GEMFILE'] = 'Gemfile'
end
after { ENV['BUNDLE_GEMFILE'] = @bundler_env }
it 'does not show the Bundler warning' do
expect(Guard::UI).to_not receive(:info).with(/Guard here!/)
subject.init
end
end
context 'when running without Bundler' do
before do
@bundler_env = ENV['BUNDLE_GEMFILE']
ENV['BUNDLE_GEMFILE'] = nil
end
after { ENV['BUNDLE_GEMFILE'] = @bundler_env }
it 'does not show the Bundler warning' do
expect(Guard::UI).to receive(:info).with(/Guard here!/)
subject.init
end
end
end
describe '#show' do
it 'outputs the Guard::DslDescriber.list result' do
expect(::Guard::DslDescriber).to receive(:new) { dsl_describer }
expect(dsl_describer).to receive(:show)
subject.show
end
end
end