jugyo-termtter 1.1.3 → 1.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/ChangeLog +115 -0
- data/README.rdoc +25 -10
- data/Rakefile +53 -34
- data/lib/plugins/cool.rb +2 -5
- data/lib/plugins/curry.rb +43 -0
- data/lib/plugins/db.rb +91 -0
- data/lib/plugins/{auto_reload.rb → defaults/auto_reload.rb} +5 -1
- data/lib/plugins/defaults/command_line.rb +111 -0
- data/lib/plugins/{exec.rb → defaults/exec.rb} +2 -7
- data/lib/plugins/{fib.rb → defaults/fib.rb} +1 -4
- data/lib/plugins/defaults/retweet.rb +34 -0
- data/lib/plugins/{standard_commands.rb → defaults/standard_commands.rb} +88 -162
- data/lib/plugins/defaults/standard_completion.rb +67 -0
- data/lib/plugins/defaults/stdout.rb +148 -0
- data/lib/plugins/defaults.rb +14 -0
- data/lib/plugins/en2ja.rb +11 -5
- data/lib/plugins/english.rb +2 -2
- data/lib/plugins/expand-tinyurl.rb +27 -6
- data/lib/plugins/github-issues.rb +192 -0
- data/lib/plugins/group.rb +30 -4
- data/lib/plugins/growl.rb +10 -1
- data/lib/plugins/http_server/favicon.ico +0 -0
- data/lib/plugins/http_server/index.html +117 -0
- data/lib/plugins/http_server.rb +82 -0
- data/lib/plugins/irb.rb +6 -0
- data/lib/plugins/l2.rb +1 -1
- data/lib/plugins/list_with_opts.rb +0 -3
- data/lib/plugins/log.rb +6 -9
- data/lib/plugins/modify_arg_hook_sample.rb +3 -5
- data/lib/plugins/multi_reply.rb +0 -5
- data/lib/plugins/notify-send.rb +1 -1
- data/lib/plugins/notify-send2.rb +1 -1
- data/lib/plugins/notify-send3.rb +11 -3
- data/lib/plugins/open_url.rb +5 -17
- data/lib/plugins/otsune.rb +3 -9
- data/lib/plugins/outputz.rb +1 -1
- data/lib/plugins/pool.rb +30 -0
- data/lib/plugins/protected_filter.rb +9 -0
- data/lib/plugins/quicklook.rb +1 -1
- data/lib/plugins/saykanji.rb +81 -0
- data/lib/plugins/shell.rb +1 -6
- data/lib/plugins/sl.rb +8 -8
- data/lib/plugins/tinyurl.rb +26 -7
- data/lib/plugins/trends.rb +84 -0
- data/lib/plugins/twitpic.rb +46 -0
- data/lib/plugins/uri-open.rb +33 -28
- data/lib/plugins/wassr.rb +0 -3
- data/lib/plugins/whois.rb +45 -0
- data/lib/plugins/yhara.rb +2 -6
- data/lib/termtter/client.rb +91 -103
- data/lib/termtter/command.rb +24 -9
- data/lib/termtter/config.rb +8 -6
- data/lib/termtter/config_setup.rb +1 -1
- data/lib/termtter/config_template.erb +1 -4
- data/lib/termtter/hook.rb +2 -2
- data/lib/termtter/optparse.rb +14 -1
- data/lib/termtter/system_extensions.rb +3 -2
- data/lib/termtter/task_manager.rb +1 -5
- data/lib/termtter/version.rb +1 -1
- data/spec/plugins/cool_spec.rb +1 -1
- data/spec/plugins/curry_spec.rb +13 -0
- data/spec/plugins/db_spec.rb +62 -0
- data/spec/plugins/english_spec.rb +2 -2
- data/spec/plugins/fib_spec.rb +2 -2
- data/spec/plugins/filter_spec.rb +2 -2
- data/spec/plugins/pause_spec.rb +1 -1
- data/spec/plugins/primes_spec.rb +2 -2
- data/spec/plugins/shell_spec.rb +1 -1
- data/spec/plugins/sl_spec.rb +1 -1
- data/spec/plugins/{standard_plugins_spec.rb → standard_commands_spec.rb} +2 -2
- data/spec/plugins/whois_spec.rb +20 -0
- data/spec/termtter/client_spec.rb +151 -33
- data/spec/termtter/command_spec.rb +68 -35
- data/spec/termtter/config_spec.rb +10 -0
- data/spec/termtter/optparse_spec.rb +16 -0
- data/spec/termtter_spec.rb +7 -8
- metadata +48 -19
- data/History.txt +0 -4
- data/lib/plugins/direct_messages.rb +0 -36
- data/lib/plugins/retweet.rb +0 -46
- data/lib/plugins/stdout.rb +0 -77
data/spec/plugins/pause_spec.rb
CHANGED
data/spec/plugins/primes_spec.rb
CHANGED
@@ -5,11 +5,11 @@ require File.dirname(__FILE__) + '/../spec_helper'
|
|
5
5
|
describe Termtter::Client, 'when the plugin primes is loaded' do
|
6
6
|
it 'should add command primes' do
|
7
7
|
Termtter::Client.should_receive(:register_command).once
|
8
|
-
|
8
|
+
Termtter::Client.plug 'primes'
|
9
9
|
end
|
10
10
|
|
11
11
|
it 'should define primes method' do
|
12
|
-
|
12
|
+
Termtter::Client.plug 'primes'
|
13
13
|
(0..10).map {|i| primes i }.should == ["", "", "", "2, 3", "2, 3", "2, 3, 5", "2, 3, 5", "2, 3, 5, 7", "2, 3, 5, 7", "2, 3, 5, 7", "2, 3, 5, 7"]
|
14
14
|
end
|
15
15
|
end
|
data/spec/plugins/shell_spec.rb
CHANGED
data/spec/plugins/sl_spec.rb
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
# -*- coding: utf-8 -*-
|
2
2
|
|
3
3
|
require File.dirname(__FILE__) + '/../spec_helper'
|
4
|
-
|
4
|
+
Termtter::Client.plug 'defaults/standard_commands'
|
5
5
|
|
6
6
|
module Termtter
|
7
7
|
describe Client do
|
@@ -12,7 +12,7 @@ module Termtter
|
|
12
12
|
[:search, [:s]], [:replies, [:r]],
|
13
13
|
[:show, [ ]], [:shows, [ ]],
|
14
14
|
[:limit, [:lm]], [:pause, [ ]],
|
15
|
-
[:resume, [ ]], [:exit, [:
|
15
|
+
[:resume, [ ]], [:exit, [:quit]],
|
16
16
|
].each do |name, aliases|
|
17
17
|
command = Client.get_command(name)
|
18
18
|
command.name.should == name
|
@@ -0,0 +1,20 @@
|
|
1
|
+
# -*- coding: utf-8 -*-
|
2
|
+
|
3
|
+
require File.dirname(__FILE__) + '/../spec_helper'
|
4
|
+
|
5
|
+
describe Termtter::Client, 'when the plugin whois is loaded' do
|
6
|
+
it 'should add command whois' do
|
7
|
+
Termtter::Client.should_receive(:register_command).once
|
8
|
+
Termtter::Client.plug 'whois'
|
9
|
+
end
|
10
|
+
|
11
|
+
it 'should be whois define' do
|
12
|
+
Termtter::Client.plug 'whois'
|
13
|
+
name = "jp-in-f104.google.com"
|
14
|
+
ip = "66.249.89.104"
|
15
|
+
|
16
|
+
whois?(name).should == ip
|
17
|
+
whois?(ip).should == name
|
18
|
+
end
|
19
|
+
|
20
|
+
end
|
@@ -1,27 +1,71 @@
|
|
1
1
|
# -*- coding: utf-8 -*-
|
2
|
-
|
3
2
|
require File.dirname(__FILE__) + '/../spec_helper'
|
4
3
|
|
5
4
|
module Termtter
|
6
|
-
|
7
5
|
describe Client do
|
8
|
-
|
9
6
|
before do
|
10
7
|
Client.setup_logger
|
11
8
|
end
|
12
9
|
|
13
|
-
it '
|
10
|
+
it 'takes command' do
|
14
11
|
command = Command.new(:name => :test)
|
15
12
|
Client.register_command(command)
|
16
13
|
Client.get_command(:test).should == command
|
17
14
|
end
|
18
15
|
|
19
|
-
it '
|
16
|
+
it 'takes command as Hash' do
|
20
17
|
Client.register_command(:name => :test)
|
21
18
|
Client.get_command(:test).name.should == :test
|
22
19
|
end
|
23
20
|
|
24
|
-
it '
|
21
|
+
it 'takes register_command as block' do
|
22
|
+
process = lambda {}
|
23
|
+
Client.register_command('test', &process)
|
24
|
+
command = Client.get_command(:test)
|
25
|
+
command.name.should == :test
|
26
|
+
command.exec_proc.should == process
|
27
|
+
end
|
28
|
+
|
29
|
+
it 'takes register_command as block with options' do
|
30
|
+
process = lambda {}
|
31
|
+
Client.register_command('test', :help => 'help', &process)
|
32
|
+
command = Client.get_command(:test)
|
33
|
+
command.name.should == :test
|
34
|
+
command.exec_proc.should == process
|
35
|
+
command.help.should == 'help'
|
36
|
+
end
|
37
|
+
|
38
|
+
it 'takes register command as block with symbol name' do
|
39
|
+
lambda {
|
40
|
+
Client.register_command(:name) {}
|
41
|
+
}.should_not raise_error
|
42
|
+
end
|
43
|
+
|
44
|
+
it 'takes add_command as block' do
|
45
|
+
Client.add_command('test') do |c|
|
46
|
+
c.aliases = ['t']
|
47
|
+
c.help = 'test command is a test'
|
48
|
+
end
|
49
|
+
command = Client.get_command(:test)
|
50
|
+
command.name.should == :test
|
51
|
+
command.aliases.should == [:t]
|
52
|
+
command.help.should == 'test command is a test'
|
53
|
+
end
|
54
|
+
|
55
|
+
it 'takes add_command as block without past config' do
|
56
|
+
Client.add_command('past') do |c|
|
57
|
+
c.help = 'past help'
|
58
|
+
end
|
59
|
+
Client.get_command(:past).help.should == 'past help'
|
60
|
+
Client.add_command('new') {}
|
61
|
+
Client.get_command(:new).help.should_not == 'past help'
|
62
|
+
end
|
63
|
+
|
64
|
+
it 'raises ArgumentError when call add_command without block' do
|
65
|
+
lambda { Client.add_command('past') }.should raise_error(ArgumentError)
|
66
|
+
end
|
67
|
+
|
68
|
+
it 'calls command' do
|
25
69
|
command_arg = nil
|
26
70
|
command = Command.new(:name => :test, :exec_proc => lambda {|arg| command_arg = arg})
|
27
71
|
Client.register_command(command)
|
@@ -38,18 +82,18 @@ module Termtter
|
|
38
82
|
end
|
39
83
|
end
|
40
84
|
|
41
|
-
it '
|
85
|
+
it 'takes new_hook' do
|
42
86
|
hook = Hook.new(:name => :test)
|
43
87
|
Client.register_hook(hook)
|
44
88
|
Client.get_hook(:test).should == hook
|
45
89
|
end
|
46
90
|
|
47
|
-
it '
|
91
|
+
it 'takes hook as Hash' do
|
48
92
|
Client.register_hook(:name => :test)
|
49
93
|
Client.get_hook(:test).name.should == :test
|
50
94
|
end
|
51
95
|
|
52
|
-
it '
|
96
|
+
it 'calls new_hook' do
|
53
97
|
hook_called = false
|
54
98
|
Client.register_hook(:name => :test1, :points => [:point1], :exec_proc => lambda {hook_called = true})
|
55
99
|
hook_called.should == false
|
@@ -57,7 +101,7 @@ module Termtter
|
|
57
101
|
hook_called.should == true
|
58
102
|
end
|
59
103
|
|
60
|
-
it '
|
104
|
+
it 'calls new_hook with args' do
|
61
105
|
arg1 = nil
|
62
106
|
arg2 = nil
|
63
107
|
Client.register_hook(:name => :test1, :points => [:point1], :exec_proc => lambda {|a1, a2| arg1 = a1; arg2 = a2})
|
@@ -68,7 +112,7 @@ module Termtter
|
|
68
112
|
arg2.should == 'bar'
|
69
113
|
end
|
70
114
|
|
71
|
-
it '
|
115
|
+
it 'return hooks when call get_hooks' do
|
72
116
|
hook1 = Client.register_hook(:name => :test1, :points => [:point1])
|
73
117
|
hook2 = Client.register_hook(:name => :test2, :points => [:point1])
|
74
118
|
hook3 = Client.register_hook(:name => :test3, :points => [:point2])
|
@@ -80,7 +124,7 @@ module Termtter
|
|
80
124
|
hooks.include?(hook3).should == false
|
81
125
|
end
|
82
126
|
|
83
|
-
it '
|
127
|
+
it 'calls decide_arg hooks' do
|
84
128
|
input_command = nil
|
85
129
|
input_arg = nil
|
86
130
|
decided_arg = nil
|
@@ -90,7 +134,7 @@ module Termtter
|
|
90
134
|
Client.register_hook( :name => :test2,
|
91
135
|
:points => [:pre_exec_update],
|
92
136
|
:exec_proc => lambda {|cmd, arg| decided_arg = arg})
|
93
|
-
Client.register_command(:name => :update, :aliases => [:u])
|
137
|
+
Client.register_command(:name => :update, :aliases => [:u], :exec => lambda{|arg|})
|
94
138
|
|
95
139
|
input_command.should == nil
|
96
140
|
input_arg.should == nil
|
@@ -101,31 +145,62 @@ module Termtter
|
|
101
145
|
decided_arg.should == 'FOO'
|
102
146
|
end
|
103
147
|
|
104
|
-
it '
|
148
|
+
it 'calls pre_command hooks' do
|
149
|
+
hook_called = false
|
150
|
+
Client.register_hook( :name => :test,
|
151
|
+
:points => [:pre_command],
|
152
|
+
:exec_proc => lambda {|text| hook_called = true; text})
|
153
|
+
Client.register_command(:name => :update, :exec => lambda{|arg|})
|
154
|
+
|
155
|
+
hook_called.should == false
|
156
|
+
Client.call_commands('')
|
157
|
+
hook_called.should == true
|
158
|
+
|
159
|
+
hook_called = false
|
160
|
+
Client.call_commands('update foo')
|
161
|
+
hook_called.should == true
|
162
|
+
end
|
163
|
+
|
164
|
+
it 'calls post_command hooks' do
|
165
|
+
hook_called = false
|
166
|
+
Client.register_hook( :name => :test,
|
167
|
+
:points => [:post_command],
|
168
|
+
:exec_proc => lambda {|text| hook_called = true})
|
169
|
+
Client.register_command(:name => :update, :exec => lambda{|arg|})
|
170
|
+
|
171
|
+
hook_called.should == false
|
172
|
+
Client.call_commands('')
|
173
|
+
hook_called.should == false
|
174
|
+
|
175
|
+
Client.call_commands('update foo')
|
176
|
+
hook_called.should == true
|
177
|
+
end
|
178
|
+
|
179
|
+
it 'calls pre_exec hooks' do
|
105
180
|
hook_called = false
|
106
181
|
Client.register_hook( :name => :test,
|
107
182
|
:points => [:pre_exec_update],
|
108
183
|
:exec_proc => lambda {|cmd, arg| hook_called = true})
|
109
|
-
Client.register_command(:name => :update)
|
184
|
+
Client.register_command(:name => :update, :exec => lambda{|arg|})
|
110
185
|
|
111
186
|
hook_called.should == false
|
112
187
|
Client.call_commands('update foo')
|
113
188
|
hook_called.should == true
|
114
189
|
end
|
115
190
|
|
116
|
-
it '
|
191
|
+
it 'able to cancel exec command' do
|
117
192
|
command_called = false
|
118
193
|
Client.register_hook( :name => :test,
|
119
194
|
:points => [:pre_exec_update],
|
120
|
-
:exec_proc => lambda {|cmd, arg|
|
121
|
-
Client.register_command(:name => :update, :exec_proc => lambda {|
|
195
|
+
:exec_proc => lambda {|cmd, arg| raise CommandCanceled})
|
196
|
+
Client.register_command(:name => :update, :exec_proc => lambda {|arg| command_called = true})
|
122
197
|
|
123
198
|
command_called.should == false
|
124
199
|
Client.call_commands('update foo')
|
125
200
|
command_called.should == false
|
126
201
|
end
|
127
202
|
|
128
|
-
it '
|
203
|
+
it 'calls post_exec hooks' do
|
129
204
|
command_result = nil
|
130
205
|
Client.register_hook( :name => :test,
|
131
206
|
:points => [:post_exec_update],
|
@@ -137,7 +212,7 @@ module Termtter
|
|
137
212
|
command_result.should == 'foo'
|
138
213
|
end
|
139
214
|
|
140
|
-
it '
|
215
|
+
it 'calls exit hooks' do
|
141
216
|
hook_called = false
|
142
217
|
Client.register_hook(
|
143
218
|
:name => :test,
|
@@ -151,7 +226,7 @@ module Termtter
|
|
151
226
|
hook_called.should == true
|
152
227
|
end
|
153
228
|
|
154
|
-
it '
|
229
|
+
it 'calls plural hooks' do
|
155
230
|
hook1_called = false
|
156
231
|
hook2_called = false
|
157
232
|
Client.register_hook(:name => :hook1, :points => [:exit], :exec_proc => lambda {hook1_called = true})
|
@@ -165,7 +240,7 @@ module Termtter
|
|
165
240
|
hook2_called.should == true
|
166
241
|
end
|
167
242
|
|
168
|
-
it '
|
243
|
+
it 'is able to override hooks' do
|
169
244
|
hook1_called = false
|
170
245
|
hook2_called = false
|
171
246
|
Client.register_hook(:name => :hook, :points => [:exit], :exec_proc => lambda {hook1_called = true})
|
@@ -179,7 +254,31 @@ module Termtter
|
|
179
254
|
hook2_called.should == true
|
180
255
|
end
|
181
256
|
|
182
|
-
it '
|
257
|
+
it 'takes register_hook as block' do
|
258
|
+
process = lambda {}
|
259
|
+
Client.register_hook('test', &process)
|
260
|
+
hook = Client.get_hook(:test)
|
261
|
+
hook.name.should == :test
|
262
|
+
hook.exec_proc.should == process
|
263
|
+
end
|
264
|
+
|
265
|
+
it 'takes register_hook as block with options' do
|
266
|
+
process = lambda {}
|
267
|
+
Client.register_hook('test', :point => :foo, &process)
|
268
|
+
hook = Client.get_hook(:test)
|
269
|
+
hook.name.should == :test
|
270
|
+
hook.exec_proc.should == process
|
271
|
+
hook.points.should == [:foo]
|
272
|
+
end
|
273
|
+
|
274
|
+
it 'takes register hook as block with symbol name' do
|
275
|
+
lambda {
|
276
|
+
Client.register_hook(:name) {}
|
277
|
+
}.should_not raise_error
|
278
|
+
end
|
279
|
+
|
280
|
+
it 'runs' do
|
281
|
+
pending
|
183
282
|
Client.should_receive(:load_config)
|
184
283
|
Termtter::API.should_receive(:setup)
|
185
284
|
Client.should_receive(:start_input_thread)
|
@@ -188,31 +287,31 @@ module Termtter
|
|
188
287
|
|
189
288
|
it 'load_config'
|
190
289
|
|
191
|
-
it '
|
290
|
+
it 'does nothing when ~/.termtter is directory' do
|
192
291
|
File.should_receive(:ftype).and_return('directory')
|
193
292
|
Client.should_not_receive(:move_legacy_config_file)
|
194
293
|
Client.legacy_config_support
|
195
294
|
end
|
196
295
|
|
197
|
-
it '
|
296
|
+
it 'does "move_legacy_config_file" when ~/.termtter is file' do
|
198
297
|
File.should_receive(:ftype).and_return('file')
|
199
298
|
Client.should_receive(:move_legacy_config_file)
|
200
299
|
Client.legacy_config_support
|
201
300
|
end
|
202
301
|
|
203
|
-
it '
|
302
|
+
it 'moves legacy config file' do
|
204
303
|
FileUtils.should_receive(:mv).twice
|
205
304
|
Dir.should_receive(:mkdir)
|
206
305
|
Client.move_legacy_config_file
|
207
306
|
end
|
208
307
|
|
209
|
-
it '
|
308
|
+
it 'handles error' do
|
210
309
|
logger = Client.instance_eval{@logger}
|
211
310
|
logger.should_receive(:error).with("StandardError: error")
|
212
311
|
Client.handle_error StandardError.new('error')
|
213
312
|
end
|
214
313
|
|
215
|
-
it '
|
314
|
+
it 'cancels command by hook' do
|
216
315
|
command = Command.new(:name => :test)
|
217
316
|
Client.register_command(command)
|
218
317
|
Client.register_hook(
|
@@ -226,7 +325,7 @@ module Termtter
|
|
226
325
|
Client.call_commands('test')
|
227
326
|
end
|
228
327
|
|
229
|
-
it '
|
328
|
+
it 'gets default help' do
|
230
329
|
$stdout, old_stdout = StringIO.new, $stdout # FIXME That suspends any debug informations!
|
231
330
|
help_command = Client.get_command(:help)
|
232
331
|
help_command.should_not be_nil
|
@@ -235,7 +334,7 @@ module Termtter
|
|
235
334
|
$stdout = old_stdout
|
236
335
|
end
|
237
336
|
|
238
|
-
it '
|
337
|
+
it 'gets an added help' do
|
239
338
|
Client.register_command(
|
240
339
|
:name => :foo,
|
241
340
|
:help => [
|
@@ -263,13 +362,13 @@ module Termtter
|
|
263
362
|
Client.commands.size.should == 3
|
264
363
|
end
|
265
364
|
|
266
|
-
it '
|
365
|
+
it 'finds a command' do
|
267
366
|
Client.find_commands('foo1').size.should == 1
|
268
367
|
Client.find_commands('foo1')[0].name.should == :foo1
|
269
368
|
Client.find_commands('bar').size.should == 1
|
270
369
|
end
|
271
370
|
|
272
|
-
it '
|
371
|
+
it 'finds no command' do
|
273
372
|
Client.find_commands('foo').size.should == 0
|
274
373
|
end
|
275
374
|
end
|
@@ -279,9 +378,28 @@ module Termtter
|
|
279
378
|
Client.clear_command
|
280
379
|
end
|
281
380
|
|
282
|
-
it '
|
381
|
+
it 'no command' do
|
283
382
|
Client.commands.size.should == 0
|
284
383
|
end
|
285
384
|
end
|
385
|
+
|
386
|
+
describe '.plug' do
|
387
|
+
it 'loads a plugin' do
|
388
|
+
Client.should_receive(:load).with('plugins/aaa.rb')
|
389
|
+
Client.plug 'aaa'
|
390
|
+
end
|
391
|
+
|
392
|
+
it 'loads a plugin with plugin name as Symbol' do
|
393
|
+
Client.should_receive(:load).with('plugins/aaa.rb')
|
394
|
+
Client.plug :aaa
|
395
|
+
end
|
396
|
+
|
397
|
+
it 'loads plugins' do
|
398
|
+
Client.should_receive(:load).with('plugins/aaa.rb')
|
399
|
+
Client.should_receive(:load).with('plugins/bbb.rb')
|
400
|
+
Client.should_receive(:load).with('plugins/ccc.rb')
|
401
|
+
Client.plug ['aaa', 'bbb', 'ccc']
|
402
|
+
end
|
403
|
+
end
|
286
404
|
end
|
287
405
|
end
|
@@ -3,52 +3,73 @@
|
|
3
3
|
require File.dirname(__FILE__) + '/../spec_helper'
|
4
4
|
|
5
5
|
module Termtter
|
6
|
+
describe 'Command#initialize' do
|
7
|
+
it 'requires the name element in the argument hash' do
|
8
|
+
lambda { Command.new(:nama => 1) }.should raise_error(ArgumentError)
|
9
|
+
lambda { Command.new(:name => 1) }.should_not raise_error(ArgumentError)
|
10
|
+
end
|
6
11
|
|
7
|
-
|
12
|
+
it 'does not destroy the argument hash' do
|
13
|
+
hash = {
|
14
|
+
:name => 1,
|
15
|
+
:exec => 3
|
16
|
+
}
|
17
|
+
Command.new hash
|
18
|
+
|
19
|
+
hash.should eql(hash)
|
20
|
+
hash[:name].should == 1
|
21
|
+
hash[:exec].should == 3
|
22
|
+
hash[:exec_proc].should be_nil
|
23
|
+
end
|
24
|
+
end
|
8
25
|
|
26
|
+
describe Command do
|
9
27
|
before do
|
10
28
|
params = {
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
29
|
+
:name => 'update',
|
30
|
+
:aliases => ['u', 'up'],
|
31
|
+
:exec_proc => lambda {|arg| arg },
|
32
|
+
:completion_proc => lambda {|command, arg| %w[complete1 complete2] },
|
33
|
+
:help => ['update,u TEXT', 'test command']
|
16
34
|
}
|
17
35
|
@command = Command.new(params)
|
18
36
|
end
|
19
37
|
|
20
|
-
|
21
|
-
|
38
|
+
describe '#pattern' do
|
39
|
+
it 'returns command regex' do
|
40
|
+
@command.pattern.
|
41
|
+
should == /^((update|u|up)|(update|u|up)\s+(.*?))\s*$/
|
42
|
+
end
|
22
43
|
end
|
23
44
|
|
24
|
-
it '
|
45
|
+
it 'is given name as String or Symbol' do
|
25
46
|
Command.new(:name => 'foo').name.should == :foo
|
26
47
|
Command.new(:name => :foo).name.should == :foo
|
27
48
|
end
|
28
49
|
|
29
|
-
it '
|
50
|
+
it 'returns name' do
|
30
51
|
@command.name.should == :update
|
31
52
|
end
|
32
53
|
|
33
|
-
it '
|
54
|
+
it 'returns aliases' do
|
34
55
|
@command.aliases.should == [:u, :up]
|
35
56
|
end
|
36
57
|
|
37
|
-
it '
|
58
|
+
it 'returns commands' do
|
38
59
|
@command.commands.should == [:update, :u, :up]
|
39
60
|
end
|
40
61
|
|
41
|
-
it '
|
62
|
+
it 'returns help' do
|
42
63
|
@command.help.should == ['update,u TEXT', 'test command']
|
43
64
|
end
|
44
65
|
|
45
|
-
it '
|
66
|
+
it 'returns candidates for completion' do
|
46
67
|
# complement
|
47
68
|
[
|
48
69
|
['upd', ['update']],
|
49
70
|
[' upd', []],
|
50
71
|
[' upd ', []],
|
51
|
-
['update a',
|
72
|
+
['update a', ['complete1', 'complete2']],
|
52
73
|
[' update ', []],
|
53
74
|
['u foo', ['complete1', 'complete2']],
|
54
75
|
].each do |input, comp|
|
@@ -56,7 +77,7 @@ module Termtter
|
|
56
77
|
end
|
57
78
|
end
|
58
79
|
|
59
|
-
it '
|
80
|
+
it 'returns command_info when call method "match?"' do
|
60
81
|
[
|
61
82
|
['update', true],
|
62
83
|
['up', true],
|
@@ -75,33 +96,45 @@ module Termtter
|
|
75
96
|
end
|
76
97
|
end
|
77
98
|
|
78
|
-
it '
|
79
|
-
lambda { Command.new }.should raise_error(ArgumentError)
|
80
|
-
lambda { Command.new(:exec_proc => lambda {|args|}) }.should raise_error(ArgumentError)
|
81
|
-
lambda { Command.new(:aliases => ['u']) }.should raise_error(ArgumentError)
|
82
|
-
end
|
83
|
-
|
84
|
-
it 'should call exec_proc when call method "call"' do
|
99
|
+
it 'calls exec_proc when call method "call"' do
|
85
100
|
@command.call('foo', 'test', 'foo test').should == 'test'
|
86
101
|
@command.call('foo', ' test', 'foo test').should == ' test'
|
87
102
|
@command.call('foo', ' test ', 'foo test ').should == ' test '
|
88
103
|
@command.call('foo', 'test test', 'foo test test').should == 'test test'
|
89
104
|
end
|
90
105
|
|
91
|
-
it '
|
92
|
-
lambda { @command.call('foo', nil, 'foo') }.
|
93
|
-
|
94
|
-
lambda { @command.call('foo',
|
95
|
-
|
106
|
+
it 'raises ArgumentError at call' do
|
107
|
+
lambda { @command.call('foo', nil, 'foo') }.
|
108
|
+
should_not raise_error(ArgumentError)
|
109
|
+
lambda { @command.call('foo', 'foo', 'foo') }.
|
110
|
+
should_not raise_error(ArgumentError)
|
111
|
+
lambda { @command.call('foo', false, 'foo') }.
|
112
|
+
should raise_error(ArgumentError)
|
113
|
+
lambda { @command.call('foo', Array.new, 'foo') }.
|
114
|
+
should raise_error(ArgumentError)
|
96
115
|
end
|
97
116
|
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
117
|
+
describe '#alias=' do
|
118
|
+
it 'wraps aliases=' do
|
119
|
+
a = :ujihisa
|
120
|
+
@command.should_receive(:aliases=).with([a])
|
121
|
+
@command.alias = a
|
122
|
+
end
|
123
|
+
end
|
124
|
+
|
125
|
+
describe '.split_command_line' do
|
126
|
+
it 'splits from a command line string to the command name and the arg' do
|
127
|
+
Command.split_command_line('test foo bar').
|
128
|
+
should == ['test', 'foo bar']
|
129
|
+
Command.split_command_line('test foo bar').
|
130
|
+
should == ['test', 'foo bar']
|
131
|
+
Command.split_command_line('test foo bar').
|
132
|
+
should == ['test', 'foo bar']
|
133
|
+
Command.split_command_line(' test foo bar').
|
134
|
+
should == ['test', 'foo bar']
|
135
|
+
Command.split_command_line(' test foo bar ').
|
136
|
+
should == ['test', 'foo bar']
|
137
|
+
end
|
104
138
|
end
|
105
139
|
end
|
106
140
|
end
|
107
|
-
|
@@ -107,5 +107,15 @@ module Termtter
|
|
107
107
|
@config.plugins.set_default :only, 'after_value'
|
108
108
|
@config.plugins.only.should == 'before_value'
|
109
109
|
end
|
110
|
+
|
111
|
+
it 'should be called set_default with int multiple times' do
|
112
|
+
@config.set_default(:foo, 1)
|
113
|
+
@config.set_default(:foo, 2)
|
114
|
+
end
|
115
|
+
|
116
|
+
it 'should be called set_default with string multiple times' do
|
117
|
+
@config.set_default(:foo, 'foo')
|
118
|
+
@config.set_default(:foo, 'bar')
|
119
|
+
end
|
110
120
|
end
|
111
121
|
end
|
@@ -0,0 +1,16 @@
|
|
1
|
+
# -*- coding: utf-8 -*-
|
2
|
+
require File.dirname(__FILE__) + '/../spec_helper'
|
3
|
+
|
4
|
+
describe 'optparse' do
|
5
|
+
def run_termtter(opt)
|
6
|
+
`./run_termtter.rb #{opt}`
|
7
|
+
end
|
8
|
+
|
9
|
+
it 'accepts -h option' do
|
10
|
+
run_termtter('-h').should match(/Usage/)
|
11
|
+
end
|
12
|
+
|
13
|
+
it 'accepts -m option' do
|
14
|
+
pending
|
15
|
+
end
|
16
|
+
end
|
data/spec/termtter_spec.rb
CHANGED
@@ -4,26 +4,25 @@ require File.dirname(__FILE__) + '/spec_helper'
|
|
4
4
|
|
5
5
|
describe Termtter, 'when plugin is called (without init option)' do
|
6
6
|
it 'should require global plugin if exist' do
|
7
|
-
should_receive(:load).with('plugins/aaa.rb')
|
8
|
-
|
7
|
+
Termtter::Client.should_receive(:load).with('plugins/aaa.rb')
|
8
|
+
Termtter::Client.plug 'aaa'
|
9
9
|
end
|
10
10
|
|
11
11
|
it 'should require user plugin if not exist' do
|
12
|
-
should_receive(:load).with('plugins/aaa.rb')
|
13
|
-
|
12
|
+
Termtter::Client.should_receive(:load).with('plugins/aaa.rb')
|
13
|
+
Termtter::Client.plug 'aaa'
|
14
14
|
end
|
15
15
|
|
16
16
|
it 'should handle_error if there are no plugins in global or user' do
|
17
17
|
Termtter::Client.should_receive(:handle_error)
|
18
|
-
|
18
|
+
Termtter::Client.plug 'not-exist-plugin-hehehehehehe'
|
19
19
|
end
|
20
20
|
end
|
21
21
|
|
22
22
|
describe Termtter, 'when plugin is called (with init option)' do
|
23
23
|
it 'init option will become config' do
|
24
|
-
should_receive(:load)
|
25
|
-
|
26
|
-
plugin 'aaa', :bbb => :ccc
|
24
|
+
Termtter::Client.should_receive(:load)
|
25
|
+
Termtter::Client.plug 'aaa', :bbb => :ccc
|
27
26
|
config.plugins.aaa.bbb.should == :ccc
|
28
27
|
end
|
29
28
|
end
|