vimius 0.0.1.beta1

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,19 @@
1
+ module TechnoGate
2
+ module Vimius
3
+ module Shell
4
+ extend self
5
+
6
+ def shell(command, debug = false)
7
+ if debug
8
+ `#{command}`
9
+ else
10
+ `#{command} 2> /dev/null`
11
+ end
12
+ end
13
+
14
+ alias :exec :shell
15
+ end
16
+
17
+ include Shell
18
+ end
19
+ end
@@ -0,0 +1,175 @@
1
+ module TechnoGate
2
+ module Vimius
3
+ class Submodules < TgConfig
4
+
5
+ # Return the submodules
6
+ #
7
+ # @return [Hash]
8
+ def submodules
9
+ @submodules ||= self[:submodules].map { |k, v| v.merge(:name => k) }
10
+ end
11
+
12
+ # Return the submodules bu group
13
+ #
14
+ # @param [HashWithIndifferentAccess] submodules
15
+ # @return [Hash]
16
+ def submodules_by_group(submodules = nil)
17
+ submodules ||= self.submodules
18
+
19
+ submodules.group_by { |submodule| submodule[:group] }
20
+ end
21
+
22
+ # Return the submodules bu name
23
+ #
24
+ # @param [HashWithIndifferentAccess] submodules
25
+ # @return [Hash]
26
+ def submodules_by_name(submodules = nil)
27
+ submodules ||= self.submodules
28
+
29
+ res = {}
30
+ submodules.each do |submodule|
31
+ res[submodule[:name]] = submodule
32
+ end
33
+ res
34
+ end
35
+
36
+ # Return the active submodules by group
37
+ #
38
+ # @return [Hash]
39
+ def active_by_group
40
+ submodules_by_group(active)
41
+ end
42
+
43
+ # Return the active submodules by name
44
+ #
45
+ # @return [Hash]
46
+ def active_by_name
47
+ submodules_by_name(active)
48
+ end
49
+
50
+ # Return the inactive submodules by group
51
+ #
52
+ # @return [Hash]
53
+ def inactive_by_group
54
+ submodules_by_group(inactive)
55
+ end
56
+
57
+ # Return the inactive submodules by name
58
+ #
59
+ # @return [Hash]
60
+ def inactive_by_name
61
+ submodules_by_name(inactive)
62
+ end
63
+
64
+ # Return a submodule along with all its dependencies
65
+ #
66
+ # @return [Array]
67
+ def submodule_with_dependencies(name)
68
+ res = [submodule(name)]
69
+ dependencies(name).each do |dependency|
70
+ res << submodule(dependency)
71
+ end
72
+
73
+ res.flatten.uniq
74
+ end
75
+
76
+ # Find the submodule given bu the name
77
+ #
78
+ # @param [String] name
79
+ # @return [Hash]
80
+ def submodule(name)
81
+ submodules.select { |s| s[:name].to_s == name.to_s }.
82
+ first
83
+ end
84
+
85
+ # Return an array of active submodules
86
+ #
87
+ # @return [Array]
88
+ def active
89
+ Vimius.config[:submodules].map do |submodule|
90
+ submodule(submodule)
91
+ end
92
+ end
93
+
94
+ # Return an array of inactive submodiles
95
+ #
96
+ # @return [Array]
97
+ def inactive
98
+ submodules - active
99
+ end
100
+
101
+ # Return all available groups
102
+ #
103
+ # @return [Array]
104
+ def groups
105
+ submodules.map { |submodule| submodule[:group] }.uniq.sort
106
+ end
107
+
108
+ # Activate a submodule
109
+ #
110
+ # @param [String] Submodule's name
111
+ def activate(submodule_name)
112
+ Vimius.config[:submodules] ||= []
113
+ Vimius.config[:submodules] += [submodule_name] unless active?(submodule_name)
114
+ end
115
+
116
+ # Deactive a submodule
117
+ #
118
+ # @param [String] Submodule's name
119
+ def deactivate(submodule_name)
120
+ return unless Vimius.config[:submodules]
121
+ return unless active?(submodule_name)
122
+
123
+ Vimius.config[:submodules] -= [submodule_name]
124
+ end
125
+
126
+ # Check if a submodule is active
127
+ #
128
+ # @param [String] Submodule's name
129
+ # @return [Boolean] true if submodule is active
130
+ def active?(submodule_name)
131
+ active_by_name.map {|k, v| k.to_s}.include?(submodule_name.to_s)
132
+ end
133
+
134
+ # Check if a submodule is inactive
135
+ #
136
+ # @param [String] Submodule's name
137
+ # @return [Boolean] true if submodule is inactive
138
+ def inactive?(submodule_name)
139
+ !!!active?(submodule_name) && submodule(submodule_name).present?
140
+ end
141
+
142
+ # Toggle a submodule
143
+ #
144
+ # @param [String] Submodule's name
145
+ # @raise [SubmoduleNotFoundError]
146
+ def toggle(submodule_name)
147
+ if active?(submodule_name)
148
+ deactivate(submodule_name)
149
+ elsif inactive?(submodule_name)
150
+ activate(submodule_name)
151
+ else
152
+ raise SubmoduleNotFoundError
153
+ end
154
+ end
155
+
156
+ protected
157
+ # Return a list of all dependencies of a submodule (recursive)
158
+ #
159
+ # @param [String] name
160
+ # @return [Array]
161
+ def dependencies(name)
162
+ dependencies = []
163
+ submodule = submodule(name)
164
+ if submodule.has_key?(:dependencies)
165
+ submodule[:dependencies].each do |dependency|
166
+ dependencies << dependency
167
+ dependencies << dependencies(dependency)
168
+ end
169
+ end
170
+
171
+ dependencies.flatten.uniq.sort
172
+ end
173
+ end
174
+ end
175
+ end
@@ -0,0 +1,17 @@
1
+ module TechnoGate
2
+ module Vimius
3
+ MAJOR = 0
4
+ MINOR = 0
5
+ TINY = 1
6
+ PRE = 'beta1'
7
+
8
+ def self.version
9
+ # Init the version
10
+ version = [MAJOR, MINOR, TINY]
11
+ # Add the pre if available
12
+ version << PRE unless PRE.nil? || PRE !~ /\S/
13
+ # Return the version joined by a dot
14
+ version.join('.')
15
+ end
16
+ end
17
+ end
data/lib/vimius/vim.rb ADDED
@@ -0,0 +1,12 @@
1
+ module TechnoGate
2
+ module Vimius
3
+ module VIM
4
+ extend self
5
+
6
+ # Folders
7
+ def folders
8
+ %w[ _backup _temp ]
9
+ end
10
+ end
11
+ end
12
+ end
@@ -0,0 +1,13 @@
1
+
2
+ ___ __ ______
3
+ __ | / /_____ ___ /_____________ _______ ___ _____
4
+ __ | /| / / _ _ \__ / _ ___/_ __ \__ __ `__ \_ _ \
5
+ __ |/ |/ / / __/_ / / /__ / /_/ /_ / / / / // __/
6
+ ____/|__/ \___/ /_/ \___/ \____/ /_/ /_/ /_/ \___/
7
+
8
+
9
+ _____ ___ _______ _____ ______
10
+ __ /_______ __ | / /___(_)_______ ___ ___(_)____ _____________ /
11
+ _ __/_ __ \ __ | / / __ / __ __ `__ \__ / _ / / /__ ___/__ /
12
+ / /_ / /_/ / __ |/ / _ / _ / / / / /_ / / /_/ / _(__ ) /_/
13
+ \__/ \____/ _____/ /_/ /_/ /_/ /_/ /_/ \__,_/ /____/ (_)
@@ -0,0 +1,90 @@
1
+ require 'spec_helper'
2
+
3
+ class CliInstallTestClass < ::Thor
4
+ include CLI::Install
5
+ end
6
+
7
+ module CLI
8
+ describe Install do
9
+ subject { CliInstallTestClass.new }
10
+
11
+ before(:each) do
12
+ @file_handler = mock "File Handler"
13
+ @file_handler.stubs(:write)
14
+ ::File.stubs(:open).with('/tmp/vimius_bootstrap.sh', 'w').yields(@file_handler)
15
+ Shell.stubs(:exec)
16
+ end
17
+
18
+ context "#install" do
19
+ it { should respond_to :install }
20
+
21
+ it "should call sanity_check" do
22
+ subject.expects(:sanity_check).once
23
+
24
+ subject.install
25
+ end
26
+
27
+ it "should write the bootstrap" do
28
+ ::File.expects(:open).with('/tmp/vimius_bootstrap.sh', 'w').
29
+ yields(@file_handler).once
30
+
31
+ subject.install
32
+ end
33
+
34
+ it "should call Shell.exec" do
35
+ Shell.expects(:exec).with("cat /tmp/vimius_bootstrap.sh | sh", true).once
36
+
37
+ subject.install
38
+ end
39
+ end
40
+
41
+ context '#sanity_check' do
42
+ before(:each) do
43
+ ::File.stubs(:exists?).with(USER_GVIMRC_PATH).returns(true)
44
+ ::File.stubs(:exists?).with(USER_VIMRC_PATH).returns(true)
45
+ ::File.stubs(:exists?).with(USER_VIM_PATH).returns(true)
46
+ end
47
+
48
+ it "should check that USER_VIM_PATH exists" do
49
+ ::File.expects(:exists?).with(USER_VIM_PATH).returns(true).once
50
+
51
+ subject.send :sanity_check
52
+ end
53
+
54
+ it "should check that USER_VIMRC_PATH exists" do
55
+ ::File.expects(:exists?).with(USER_VIMRC_PATH).returns(true).once
56
+
57
+ subject.send :sanity_check
58
+ end
59
+
60
+ it "should check that USER_GVIMRC_PATH exists" do
61
+ ::File.expects(:exists?).with(USER_GVIMRC_PATH).returns(true).once
62
+
63
+ subject.send :sanity_check
64
+ end
65
+
66
+ context 'failure' do
67
+ it "should abort if USER_VIM_PATH exists." do
68
+ ::File.expects(:exists?).with(USER_VIM_PATH).returns(false).once
69
+
70
+ subject.send(:sanity_check).should be_false
71
+ "#{USER_VIM_PATH} exists, cannot continue.".should be_in_output
72
+ end
73
+
74
+ it "should abort if USER_VIMRC_PATH exists." do
75
+ ::File.expects(:exists?).with(USER_VIMRC_PATH).returns(false).once
76
+
77
+ subject.send(:sanity_check).should be_false
78
+ "#{USER_VIMRC_PATH} exists, cannot continue.".should be_in_output
79
+ end
80
+
81
+ it "should abort if USER_GVIMRC_PATH exists." do
82
+ ::File.expects(:exists?).with(USER_GVIMRC_PATH).returns(false).once
83
+
84
+ subject.send(:sanity_check).should be_false
85
+ "#{USER_GVIMRC_PATH} exists, cannot continue.".should be_in_output
86
+ end
87
+ end
88
+ end
89
+ end
90
+ end
File without changes
@@ -0,0 +1,22 @@
1
+ require 'spec_helper'
2
+
3
+ class CliVersionTestClass < ::Thor
4
+ include CLI::Version
5
+ end
6
+
7
+ module CLI
8
+ describe Version do
9
+ subject { CliVersionTestClass.new }
10
+
11
+ context "#version#" do
12
+ it { should respond_to :version }
13
+
14
+ it "should prints Vimius version" do
15
+ subject.version
16
+
17
+ "Vimius version #{Vimius.version}".
18
+ should be_in_output
19
+ end
20
+ end
21
+ end
22
+ end
@@ -0,0 +1,11 @@
1
+ require 'spec_helper'
2
+
3
+ module CLI
4
+ describe Runner do
5
+ subject { Runner }
6
+
7
+ context 'Thor' do
8
+ it { should respond_to :start }
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,9 @@
1
+ require 'spec_helper'
2
+
3
+ describe Shell do
4
+ it { should respond_to :shell }
5
+
6
+ it "should include the shell method into the Vimius module" do
7
+ Vimius.should respond_to :shell
8
+ end
9
+ end
@@ -0,0 +1,474 @@
1
+ require 'spec_helper'
2
+
3
+ describe Submodules do
4
+ let(:submodules) do
5
+ {
6
+ "submodules" => {
7
+ "pathogen" => {
8
+ "path" => "vimius/vim/core/pathogen",
9
+ "group" => "core",
10
+ },
11
+ "tlib" => {
12
+ "path" => "vimius/vim/tools/tlib",
13
+ "group" => "tools",
14
+ "dependencies" => ["pathogen"],
15
+ },
16
+ "github" => {
17
+ "path" => "vimius/vim/tools/github",
18
+ "group" => "tools",
19
+ "dependencies" => ["tlib", "pathogen"],
20
+ },
21
+ "command-t" => {
22
+ "path" => "vimius/vim/tools/command-t",
23
+ "group" => "tools",
24
+ "dependencies" => ["tlib"],
25
+ },
26
+ },
27
+ }
28
+ end
29
+
30
+ let(:expected_submodules) do
31
+ [
32
+ {
33
+ "path" => "vimius/vim/core/pathogen",
34
+ "group" => "core",
35
+ "name" => "pathogen",
36
+ },
37
+ {
38
+ "path" => "vimius/vim/tools/tlib",
39
+ "group" => "tools",
40
+ "dependencies" => ["pathogen"],
41
+ "name" => "tlib",
42
+ },
43
+ {
44
+ "path" => "vimius/vim/tools/github",
45
+ "group" => "tools",
46
+ "dependencies" => ["tlib", "pathogen"],
47
+ "name" => "github",
48
+ },
49
+ {
50
+ "path" => "vimius/vim/tools/command-t",
51
+ "group" => "tools",
52
+ "dependencies" => ["tlib"],
53
+ "name" => "command-t",
54
+ },
55
+ ]
56
+ end
57
+
58
+ let(:expected_active_submodules) do
59
+ [
60
+ {
61
+ "path" => "vimius/vim/core/pathogen",
62
+ "group" => "core",
63
+ "name" => "pathogen",
64
+ },
65
+ {
66
+ "path" => "vimius/vim/tools/tlib",
67
+ "group" => "tools",
68
+ "dependencies" => ["pathogen"],
69
+ "name" => "tlib",
70
+ },
71
+ {
72
+ "path" => "vimius/vim/tools/github",
73
+ "group" => "tools",
74
+ "dependencies" => ["tlib", "pathogen"],
75
+ "name" => "github",
76
+ },
77
+ ]
78
+ end
79
+
80
+ let(:expected_inactive_submodules) do
81
+ [
82
+ {
83
+ "path" => "vimius/vim/tools/command-t",
84
+ "group" => "tools",
85
+ "dependencies" => ["tlib"],
86
+ "name" => "command-t",
87
+ },
88
+ ]
89
+ end
90
+
91
+ let(:submodules_by_group) do
92
+ {
93
+ "core" =>
94
+ [
95
+ {
96
+ "path" => "vimius/vim/core/pathogen",
97
+ "group" => "core",
98
+ "name" => "pathogen",
99
+ },
100
+ ],
101
+ "tools" =>
102
+ [
103
+ {
104
+ "path" => "vimius/vim/tools/tlib",
105
+ "group" => "tools",
106
+ "dependencies" => ["pathogen"],
107
+ "name" => "tlib",
108
+ },
109
+ {
110
+ "path" => "vimius/vim/tools/github",
111
+ "group" => "tools",
112
+ "dependencies" => ["tlib", "pathogen"],
113
+ "name" => "github",
114
+ },
115
+ {
116
+ "path" => "vimius/vim/tools/command-t",
117
+ "group" => "tools",
118
+ "dependencies" => ["tlib"],
119
+ "name" => "command-t",
120
+ },
121
+ ],
122
+ }
123
+ end
124
+
125
+ let (:submodules_by_name) do
126
+ {
127
+ "pathogen" => {
128
+ "path" => "vimius/vim/core/pathogen",
129
+ "group" => "core",
130
+ "name" => "pathogen",
131
+ },
132
+ "tlib" => {
133
+ "path" => "vimius/vim/tools/tlib",
134
+ "group" => "tools",
135
+ "dependencies" => ["pathogen"],
136
+ "name" => "tlib",
137
+ },
138
+ "github" => {
139
+ "path" => "vimius/vim/tools/github",
140
+ "group" => "tools",
141
+ "dependencies" => ["tlib", "pathogen"],
142
+ "name" => "github",
143
+ },
144
+ "command-t" => {
145
+ "path" => "vimius/vim/tools/command-t",
146
+ "group" => "tools",
147
+ "dependencies" => ["tlib"],
148
+ "name" => "command-t",
149
+ },
150
+ }
151
+ end
152
+
153
+ let(:active_by_group) do
154
+ {
155
+ "core" =>
156
+ [
157
+ {
158
+ "path" => "vimius/vim/core/pathogen",
159
+ "group" => "core",
160
+ "name" => "pathogen",
161
+ },
162
+ ],
163
+ "tools" =>
164
+ [
165
+ {
166
+ "path" => "vimius/vim/tools/tlib",
167
+ "group" => "tools",
168
+ "dependencies" => ["pathogen"],
169
+ "name" => "tlib",
170
+ },
171
+ {
172
+ "path" => "vimius/vim/tools/github",
173
+ "group" => "tools",
174
+ "dependencies" => ["tlib", "pathogen"],
175
+ "name" => "github",
176
+ },
177
+ ],
178
+ }
179
+ end
180
+
181
+ let (:active_by_name) do
182
+ {
183
+ "pathogen" => {
184
+ "path" => "vimius/vim/core/pathogen",
185
+ "group" => "core",
186
+ "name" => "pathogen",
187
+ },
188
+ "tlib" => {
189
+ "path" => "vimius/vim/tools/tlib",
190
+ "group" => "tools",
191
+ "dependencies" => ["pathogen"],
192
+ "name" => "tlib",
193
+ },
194
+ "github" => {
195
+ "path" => "vimius/vim/tools/github",
196
+ "group" => "tools",
197
+ "dependencies" => ["tlib", "pathogen"],
198
+ "name" => "github",
199
+ },
200
+ }
201
+ end
202
+
203
+ let(:inactive_by_group) do
204
+ {
205
+ "tools" =>
206
+ [
207
+ {
208
+ "path" => "vimius/vim/tools/command-t",
209
+ "group" => "tools",
210
+ "dependencies" => ["tlib"],
211
+ "name" => "command-t",
212
+ },
213
+ ],
214
+ }
215
+ end
216
+
217
+ let (:inactive_by_name) do
218
+ {
219
+ "command-t" => {
220
+ "path" => "vimius/vim/tools/command-t",
221
+ "group" => "tools",
222
+ "dependencies" => ["tlib"],
223
+ "name" => "command-t",
224
+ },
225
+ }
226
+ end
227
+
228
+ before(:each) do
229
+ ::File.stubs(:exists?).with(MODULES_FILE).returns(true)
230
+ ::File.stubs(:readable?).with(MODULES_FILE).returns(true)
231
+ ::File.stubs(:writable?).with(MODULES_FILE).returns(true)
232
+
233
+ ::File.stubs(:exists?).with(CONFIG_FILE).returns(true)
234
+ ::File.stubs(:readable?).with(CONFIG_FILE).returns(true)
235
+ ::File.stubs(:writable?).with(CONFIG_FILE).returns(true)
236
+
237
+ Vimius::Submodules.any_instance.stubs(:parse_config_file).
238
+ returns(submodules.with_indifferent_access)
239
+ TgConfig.any_instance.stubs(:parse_config_file).
240
+ returns({"submodules" => ["pathogen", "tlib", "github"]}.with_indifferent_access)
241
+ end
242
+
243
+ after(:each) do
244
+ Vimius.config.send(:instance_variable_set, :@config, nil)
245
+ subject.send(:instance_variable_set, :@config, nil)
246
+ end
247
+
248
+ subject { Submodules.new MODULES_FILE }
249
+
250
+ context "#submodules" do
251
+ it { should respond_to :submodules }
252
+
253
+ it "should return submodules" do
254
+ subject.submodules.should == expected_submodules
255
+ end
256
+
257
+ it "should add the name for each submodule" do
258
+ subject.submodules.first["name"].should == "pathogen"
259
+ end
260
+ end
261
+
262
+ context "#dependencies" do
263
+ it {should respond_to :dependencies}
264
+
265
+ it "should return tlib and pathogen as dependencies of command-t" do
266
+ subject.send(:dependencies, 'command-t').should == ["pathogen", "tlib"]
267
+ end
268
+ end
269
+
270
+ context "#submodule" do
271
+ it { should respond_to :submodule }
272
+
273
+ it "should return the submodule we're looking for" do
274
+ subject.send(:submodule, :pathogen).should == expected_submodules.first
275
+ end
276
+ end
277
+
278
+ context "#submodule_with_dependencies" do
279
+ it { should respond_to :submodule_with_dependencies}
280
+
281
+ it "should return the correct module from the submodules hash" do
282
+ subject.submodule_with_dependencies("pathogen").first.should == expected_submodules.first
283
+ end
284
+
285
+ it "should return the name with the submodule" do
286
+ subject.submodule_with_dependencies("pathogen").first["name"].should == "pathogen"
287
+ end
288
+
289
+ it "should return all dependencies when getting the module command-t" do
290
+ subject.submodule_with_dependencies("command-t").should include expected_submodules[1]
291
+ subject.submodule_with_dependencies("command-t").should include expected_submodules.first
292
+ end
293
+
294
+ it "should not include the same dependency twice" do
295
+ subject.submodule_with_dependencies("github").select { |c| c["name"] == "pathogen"}.size.should == 1
296
+ end
297
+ end
298
+
299
+ context "#groups" do
300
+ it { should respond_to :groups }
301
+
302
+ it "should return core and tools " do
303
+ subject.groups.should == ["core", "tools"]
304
+ end
305
+ end
306
+
307
+ context "#active" do
308
+ it { should respond_to :active }
309
+
310
+ its(:active) { should == expected_active_submodules }
311
+ end
312
+
313
+ context "#inactive" do
314
+ it { should respond_to :inactive }
315
+
316
+ its(:inactive) { should == expected_inactive_submodules }
317
+ end
318
+
319
+ context "#submodules_by_group" do
320
+ it { should respond_to :submodules_by_group }
321
+
322
+ it "should return submodules_by_group" do
323
+ subject.submodules_by_group.should == submodules_by_group
324
+ end
325
+ end
326
+
327
+ context "#submodules_by_name" do
328
+ it { should respond_to :submodules_by_name }
329
+
330
+ it "should return submodules_by_name" do
331
+ subject.submodules_by_name.should == submodules_by_name
332
+ end
333
+ end
334
+
335
+ context "#active_by_group" do
336
+ it { should respond_to :active_by_group }
337
+
338
+ it "should return active_by_group" do
339
+ subject.active_by_group.should == active_by_group
340
+ end
341
+ end
342
+
343
+ context "#active_by_name" do
344
+ it { should respond_to :active_by_name }
345
+
346
+ it "should return active_by_name" do
347
+ subject.active_by_name.should == active_by_name
348
+ end
349
+ end
350
+
351
+ context "#active_by_name" do
352
+ it { should respond_to :active_by_name }
353
+
354
+ it "should return active_by_name" do
355
+ subject.active_by_name.should == active_by_name
356
+ end
357
+ end
358
+
359
+ context "#active_by_name" do
360
+ it { should respond_to :active_by_name }
361
+
362
+ it "should return active_by_name" do
363
+ subject.active_by_name.should == active_by_name
364
+ end
365
+ end
366
+
367
+ context "#active?" do
368
+ it { should respond_to :active? }
369
+
370
+ it "should return true for tlib" do
371
+ subject.active?(:tlib).should be_true
372
+ end
373
+
374
+ it "should return false for command-t" do
375
+ subject.active?("command-t").should be_false
376
+ end
377
+ end
378
+
379
+ context "#inactive?" do
380
+ it { should respond_to :inactive? }
381
+
382
+ it "should return false for tlib" do
383
+ subject.inactive?(:tlib).should be_false
384
+ end
385
+
386
+ it "should return true for command-t" do
387
+ subject.inactive?("command-t").should be_true
388
+ end
389
+ end
390
+
391
+ context "#activate" do
392
+ it { should respond_to :activate }
393
+
394
+ it "should activate a module" do
395
+ subject.active.should == expected_active_submodules
396
+
397
+ subject.activate("command-t")
398
+
399
+ subject.active.should == expected_submodules # => expected_submodules includes command-t
400
+ # and all activated submodules
401
+ end
402
+
403
+ it "should not call save on the config" do
404
+ Vimius.config.expects(:save).never
405
+
406
+ subject.activate("command-t")
407
+ end
408
+
409
+ it "should not blow if there's no initially active submodules" do
410
+ TgConfig.any_instance.stubs(:parse_config_file). returns({}.with_indifferent_access)
411
+
412
+ Vimius.config[:submodules].should be_nil
413
+
414
+ lambda { subject.activate("command-t") }.should_not raise_error NoMethodError
415
+ end
416
+
417
+ it "should not activate an existing active submodule" do
418
+ subject.activate("tlib")
419
+
420
+ subject.active.should == expected_active_submodules
421
+ end
422
+ end
423
+
424
+ context "#deactivate" do
425
+ it { should respond_to :deactivate }
426
+
427
+ it "should deactivate a module" do
428
+ subject.activate("command-t")
429
+ subject.active.should == expected_submodules
430
+ subject.deactivate("command-t")
431
+ subject.active.should == expected_active_submodules
432
+ end
433
+
434
+ it "should not call save on the config" do
435
+ Vimius.config.expects(:save).never
436
+
437
+ subject.deactivate("command-t")
438
+ end
439
+
440
+ it "should not blow if there's no initially active submodules" do
441
+ TgConfig.any_instance.stubs(:parse_config_file). returns({}.with_indifferent_access)
442
+
443
+ Vimius.config[:submodules].should be_nil
444
+
445
+ lambda { subject.deactivate("command-t") }.should_not raise_error NoMethodError
446
+ end
447
+
448
+ it "should not deactivate an inactive submodule" do
449
+ subject.deactivate("command-t")
450
+
451
+ subject.active.should == expected_active_submodules
452
+ end
453
+ end
454
+
455
+ context "#toggle" do
456
+ it { should respond_to :toggle }
457
+
458
+ it "should call activate if the submodule is inactive" do
459
+ subject.expects(:activate).with("command-t").once
460
+
461
+ subject.toggle("command-t")
462
+ end
463
+
464
+ it "should call deactivate if the submodule is inactive" do
465
+ subject.expects(:deactivate).with("tlib").once
466
+
467
+ subject.toggle("tlib")
468
+ end
469
+
470
+ it "should raise SubmoduleNotFoundError if no submodule by that name exists" do
471
+ lambda {subject.toggle("invalid-submodule") }.should raise_error SubmoduleNotFoundError
472
+ end
473
+ end
474
+ end