termtter 1.5.0 → 1.6.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/Rakefile +2 -1
- data/bin/termtter +1 -0
- data/lib/plugins/another_prompt.rb +131 -0
- data/lib/plugins/async.rb +23 -0
- data/lib/plugins/confirm.rb +1 -1
- data/lib/plugins/db.rb +1 -1
- data/lib/plugins/defaults/auto_reload.rb +20 -19
- data/lib/plugins/defaults/command_line.rb +10 -5
- data/lib/plugins/defaults/hashtag.rb +35 -0
- data/lib/plugins/defaults/lists.rb +14 -0
- data/lib/plugins/defaults/retweet.rb +15 -15
- data/lib/plugins/defaults/standard_commands.rb +22 -28
- data/lib/plugins/defaults/standard_completion.rb +5 -5
- data/lib/plugins/defaults/switch.rb +34 -0
- data/lib/plugins/eject.rb +15 -0
- data/lib/plugins/expand-tinyurl.rb +1 -1
- data/lib/plugins/favotter.rb +77 -0
- data/lib/plugins/friends.rb +50 -0
- data/lib/plugins/g.rb +16 -0
- data/lib/plugins/gsub.rb +17 -0
- data/lib/plugins/haml.rb +55 -0
- data/lib/plugins/hatebu_and_update.rb +2 -2
- data/lib/plugins/history.rb +9 -0
- data/lib/plugins/irc_gw.rb +11 -4
- data/lib/plugins/linefeed.rb +31 -0
- data/lib/plugins/md5pass.rb +42 -0
- data/lib/plugins/outputz.rb +1 -1
- data/lib/plugins/primes.rb +1 -1
- data/lib/plugins/quote.rb +43 -0
- data/lib/plugins/reduce_text.rb +26 -0
- data/lib/plugins/reverse.rb +7 -6
- data/lib/plugins/source.rb +31 -0
- data/lib/plugins/storage/status.rb +2 -2
- data/lib/plugins/storage.rb +1 -1
- data/lib/plugins/stream.rb +192 -0
- data/lib/plugins/switch_user.rb +1 -22
- data/lib/plugins/truncate.rb +29 -0
- data/lib/plugins/uri-open.rb +23 -9
- data/lib/plugins/w3mimg.rb +76 -0
- data/lib/termtter/active_rubytter.rb +8 -0
- data/lib/termtter/api.rb +37 -13
- data/lib/termtter/client.rb +26 -47
- data/lib/termtter/command.rb +15 -9
- data/lib/termtter/config.rb +6 -2
- data/lib/termtter/hookable.rb +59 -0
- data/lib/termtter/optparse.rb +51 -39
- data/lib/termtter/rubytter_proxy.rb +32 -0
- data/lib/termtter/system_extensions/core_compatibles.rb +16 -0
- data/lib/termtter/system_extensions/termtter_compatibles.rb +19 -0
- data/lib/termtter/system_extensions/windows.rb +86 -0
- data/lib/termtter/system_extensions.rb +8 -121
- data/lib/termtter/task_manager.rb +4 -10
- data/lib/termtter/version.rb +1 -1
- data/lib/termtter.rb +5 -3
- data/spec/plugins/defaults/hashtag_spec.rb +41 -0
- data/spec/plugins/defaults/lists_spec.rb +34 -0
- data/spec/plugins/{english_spec.rb → english_spec_.rb} +0 -0
- data/spec/plugins/{filter_spec.rb → filter_spec_.rb} +0 -0
- data/spec/plugins/gsub_spec.rb +18 -0
- data/spec/plugins/haml_spec.rb +134 -0
- data/spec/plugins/md5pass_spec.rb +13 -0
- data/spec/plugins/{primes_spec.rb → primes_spec_.rb} +0 -0
- data/spec/plugins/{sl_spec.rb → sl_spec_.rb} +0 -0
- data/spec/plugins/standard_commands_spec.rb +1 -1
- data/spec/plugins/storage/{DB_spec.rb → DB_spec_.rb} +0 -0
- data/spec/plugins/storage/{status_spec.rb → status_spec_.rb} +0 -0
- data/spec/plugins/truncate_spec.rb +27 -0
- data/spec/plugins/whois_spec_.rb +20 -0
- data/spec/spec_helper.rb +25 -0
- data/spec/termtter/active_rubytter_spec.rb +17 -0
- data/spec/termtter/api_spec.rb +107 -0
- data/spec/termtter/client_spec.rb +262 -73
- data/spec/termtter/command_spec.rb +31 -5
- data/spec/termtter/config_setup_spec.rb +19 -0
- data/spec/termtter/config_spec.rb +57 -27
- data/spec/termtter/hook_spec.rb +12 -0
- data/spec/termtter/hookable_spec.rb +53 -0
- data/spec/termtter/optparse_spec.rb +64 -9
- data/spec/termtter/rubytter_proxy_spec.rb +42 -0
- data/spec/termtter/system_extensions/windows_spec.rb +9 -0
- data/spec/termtter/system_extensions_spec.rb +61 -0
- data/spec/termtter/task_manager_spec.rb +58 -0
- data/spec/termtter_spec.rb +11 -0
- metadata +45 -20
- data/lib/termtter/connection.rb +0 -41
- data/spec/plugins/whois_spec.rb +0 -26
@@ -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
|
data/spec/spec_helper.rb
CHANGED
@@ -4,4 +4,29 @@ $:.unshift(File.dirname(__FILE__) + '/../lib')
|
|
4
4
|
ARGV.delete '-c'
|
5
5
|
require 'termtter'
|
6
6
|
|
7
|
+
def be_quiet(options = {})
|
8
|
+
out = (v = options.delete(:stdout)).nil? ? true : v
|
9
|
+
err = (v = options.delete(:stderr)).nil? ? true : v
|
10
|
+
if out
|
11
|
+
out_dummy = StringIO.new
|
12
|
+
$stdout, out_orig = out_dummy, $stdout
|
13
|
+
end
|
14
|
+
if err
|
15
|
+
err_dummy = StringIO.new
|
16
|
+
$stderr, err_orig = err_dummy, $stderr
|
17
|
+
end
|
18
|
+
yield
|
19
|
+
result = {}
|
20
|
+
if out
|
21
|
+
$stdout = out_orig
|
22
|
+
out_dummy.rewind
|
23
|
+
result[:stdout] = out_dummy.read
|
24
|
+
end
|
25
|
+
if err
|
26
|
+
$stderr = err_orig
|
27
|
+
err_dummy.rewind
|
28
|
+
result[:stderr] = err_dummy.read
|
29
|
+
end
|
30
|
+
result
|
31
|
+
end
|
7
32
|
|
@@ -12,12 +12,29 @@ module Termtter
|
|
12
12
|
d.age.should == 16
|
13
13
|
end
|
14
14
|
|
15
|
+
it 'Hashのキーでもメソッドでもないものは呼べない' do
|
16
|
+
d = ActiveRubytter.new(:name => 'termtter')
|
17
|
+
lambda{ d.undefined_method }.should raise_error(NoMethodError)
|
18
|
+
end
|
19
|
+
|
15
20
|
it '元のHashを得られること' do
|
16
21
|
data = { :test => 'test' }
|
17
22
|
d = ActiveRubytter.new(data)
|
18
23
|
d.to_hash.should == data
|
19
24
|
end
|
20
25
|
|
26
|
+
it 'idというkeyがあっても取得できる' do
|
27
|
+
data = { :id => 'test' }
|
28
|
+
d = ActiveRubytter.new(data)
|
29
|
+
d.id.should == 'test'
|
30
|
+
end
|
31
|
+
|
32
|
+
it '[]でもアクセス出来る' do
|
33
|
+
data = { :hoge => 'test' }
|
34
|
+
d = ActiveRubytter.new(data)
|
35
|
+
d[:hoge].should == 'test'
|
36
|
+
end
|
37
|
+
|
21
38
|
describe '入れ子のHashの処理' do
|
22
39
|
|
23
40
|
before(:all) do
|
@@ -0,0 +1,107 @@
|
|
1
|
+
# -*- coding: utf-8 -*-
|
2
|
+
|
3
|
+
require File.dirname(__FILE__) + '/../spec_helper'
|
4
|
+
|
5
|
+
module Termtter
|
6
|
+
|
7
|
+
describe API do
|
8
|
+
|
9
|
+
it 'tries authenticate 3 times' do
|
10
|
+
API.should_receive(:try_auth).
|
11
|
+
exactly(3).times.
|
12
|
+
and_return(false)
|
13
|
+
API.should_receive(:exit!)
|
14
|
+
API.setup
|
15
|
+
end
|
16
|
+
|
17
|
+
it 'can get twitter when success authentication' do
|
18
|
+
twitter = mock('twitter')
|
19
|
+
API.should_receive(:try_auth).and_return(twitter)
|
20
|
+
API.setup
|
21
|
+
API.twitter.should == twitter
|
22
|
+
end
|
23
|
+
|
24
|
+
def it_should_examine_with(name, pass, options = {})
|
25
|
+
config.user_name = name if name
|
26
|
+
config.password = pass if pass
|
27
|
+
|
28
|
+
dummy_out = mock('stdout')
|
29
|
+
dummy_out.stub(:ask) do |ask, _|
|
30
|
+
$stdout.puts ask
|
31
|
+
result = options.delete(
|
32
|
+
case ask
|
33
|
+
when /Username/ then :ui_name
|
34
|
+
when /Password/ then :ui_pass
|
35
|
+
end
|
36
|
+
) || ''
|
37
|
+
result
|
38
|
+
end
|
39
|
+
API.stub(:create_highline => dummy_out)
|
40
|
+
|
41
|
+
twitter = mock('twitter')
|
42
|
+
twitter.stub(:verify_credentials) do
|
43
|
+
if config.user_name.empty? || config.password.empty?
|
44
|
+
raise Rubytter::APIError.new('error')
|
45
|
+
end
|
46
|
+
end
|
47
|
+
RubytterProxy.stub(:new => twitter)
|
48
|
+
|
49
|
+
API.try_auth.should == yield(twitter)
|
50
|
+
|
51
|
+
config.__clear__(:user_name)
|
52
|
+
config.__clear__(:password)
|
53
|
+
end
|
54
|
+
|
55
|
+
it 'can examine username and password (success)' do
|
56
|
+
it_should_examine_with('test', 'pass') {|twitter| twitter }
|
57
|
+
end
|
58
|
+
|
59
|
+
it 'can examine username and password (only name)' do
|
60
|
+
result = be_quiet(:stderr => false) {
|
61
|
+
it_should_examine_with('test', nil) { nil }
|
62
|
+
}
|
63
|
+
result[:stdout].should ==
|
64
|
+
"Please enter your Twitter login:\nPassword: \n"
|
65
|
+
end
|
66
|
+
|
67
|
+
it 'can examine username and password (only pass)' do
|
68
|
+
result = be_quiet(:stderr => false) {
|
69
|
+
it_should_examine_with(nil, 'pass') { nil }
|
70
|
+
}
|
71
|
+
result[:stdout].should ==
|
72
|
+
"Please enter your Twitter login:\nUsername: \n"
|
73
|
+
end
|
74
|
+
|
75
|
+
it 'can examine username and password (both nil)' do
|
76
|
+
result = be_quiet(:stderr => false) {
|
77
|
+
it_should_examine_with(nil, nil) { nil }
|
78
|
+
}
|
79
|
+
result[:stdout].should ==
|
80
|
+
"Please enter your Twitter login:\nUsername: \nPassword: \n"
|
81
|
+
end
|
82
|
+
|
83
|
+
it 'can examine username and password (enter password)' do
|
84
|
+
be_quiet do
|
85
|
+
args = ['test', nil, {:ui_pass => 'pass'}]
|
86
|
+
it_should_examine_with(*args) {|twitter| twitter }
|
87
|
+
end
|
88
|
+
end
|
89
|
+
|
90
|
+
it 'can examine username and password (enter username)' do
|
91
|
+
be_quiet do
|
92
|
+
args = [nil, 'pass', {:ui_name => 'test'}]
|
93
|
+
it_should_examine_with(*args) {|twitter| twitter }
|
94
|
+
end
|
95
|
+
end
|
96
|
+
|
97
|
+
it 'can examine username and password (enter both)' do
|
98
|
+
be_quiet do
|
99
|
+
args = [nil, nil,
|
100
|
+
{:ui_name => 'test',
|
101
|
+
:ui_pass => 'pass' }]
|
102
|
+
it_should_examine_with(*args) {|twitter| twitter }
|
103
|
+
end
|
104
|
+
end
|
105
|
+
end
|
106
|
+
end
|
107
|
+
|
@@ -5,6 +5,83 @@ module Termtter
|
|
5
5
|
describe Client do
|
6
6
|
before do
|
7
7
|
Client.setup_logger
|
8
|
+
Client.setup_task_manager
|
9
|
+
Client.clear_filter
|
10
|
+
Client.clear_command
|
11
|
+
Client.clear_hooks
|
12
|
+
end
|
13
|
+
|
14
|
+
# FIXME: Depends recent implement
|
15
|
+
it 'can run' do
|
16
|
+
Client.should_receive(:load_config) {}
|
17
|
+
Termtter::API.should_receive(:setup) {}
|
18
|
+
Client.should_receive(:setup_logger) {}
|
19
|
+
Client.should_receive(:load_plugins) {}
|
20
|
+
Client.should_receive(:eval_init_block) {}
|
21
|
+
|
22
|
+
config.system.eval_scripts = []
|
23
|
+
config.system.cmd_mode = true
|
24
|
+
Client.run
|
25
|
+
end
|
26
|
+
|
27
|
+
it 'can run (eval script cannot eval)' do
|
28
|
+
Client.stub(:load_config) {}
|
29
|
+
Termtter::API.stub(:setup) {}
|
30
|
+
Client.stub(:setup_logger) {}
|
31
|
+
Client.stub(:load_plugins) {}
|
32
|
+
Client.stub(:eval_init_block) {}
|
33
|
+
|
34
|
+
config.system.eval_scripts = ['raise']
|
35
|
+
Client.should_receive(:handle_error)
|
36
|
+
|
37
|
+
config.system.cmd_mode = true
|
38
|
+
Client.run
|
39
|
+
end
|
40
|
+
|
41
|
+
it 'can run (eval script cannot eval)' do
|
42
|
+
Client.stub(:load_config) {}
|
43
|
+
Termtter::API.stub(:setup) {}
|
44
|
+
Client.stub(:setup_logger) {}
|
45
|
+
Client.stub(:load_plugins) {}
|
46
|
+
Client.stub(:eval_init_block) {}
|
47
|
+
|
48
|
+
config.system.eval_scripts = []
|
49
|
+
config.system.cmd_mode = false
|
50
|
+
Client.should_receive(:call_hooks).with(:initialize)
|
51
|
+
Client.should_receive(:call_hooks).with(:launched)
|
52
|
+
Client.run
|
53
|
+
end
|
54
|
+
|
55
|
+
it 'set init block' do
|
56
|
+
dummy = lambda {}
|
57
|
+
Client.init(&dummy)
|
58
|
+
Client.instance_variable_get(:@init_block).should == dummy
|
59
|
+
end
|
60
|
+
|
61
|
+
it 'can run init block' do
|
62
|
+
Client.init() {}
|
63
|
+
Client.instance_variable_get(:@init_block).
|
64
|
+
should_receive(:call).with(Client)
|
65
|
+
Client.eval_init_block
|
66
|
+
end
|
67
|
+
|
68
|
+
it 'can load plugins when initializing stage (normal)' do
|
69
|
+
config.devel = false
|
70
|
+
Client.should_receive(:plug).exactly(2).times
|
71
|
+
Client.load_plugins
|
72
|
+
end
|
73
|
+
|
74
|
+
it 'can load plugins when initializing stage (devel)' do
|
75
|
+
Client.should_receive(:plug).exactly(2).times
|
76
|
+
Client.load_plugins
|
77
|
+
end
|
78
|
+
|
79
|
+
it 'can pause and resume' do
|
80
|
+
manager = Client.instance_variable_get(:@task_manager)
|
81
|
+
manager.should_receive(:pause)
|
82
|
+
Client.pause
|
83
|
+
manager.should_receive(:resume)
|
84
|
+
Client.resume
|
8
85
|
end
|
9
86
|
|
10
87
|
it 'takes command' do
|
@@ -41,6 +118,15 @@ module Termtter
|
|
41
118
|
}.should_not raise_error
|
42
119
|
end
|
43
120
|
|
121
|
+
it 'register_command can raise error when take invalid argument' do
|
122
|
+
[1, ['hoge', 'fuga'], nil, Object.new].each do |bad|
|
123
|
+
lambda {
|
124
|
+
Client.register_command(bad)
|
125
|
+
}.should raise_error(ArgumentError)
|
126
|
+
end
|
127
|
+
end
|
128
|
+
|
129
|
+
|
44
130
|
it 'takes add_command as block' do
|
45
131
|
Client.add_command('test') do |c|
|
46
132
|
c.aliases = ['t']
|
@@ -77,51 +163,17 @@ module Termtter
|
|
77
163
|
['test foo bar ', 'foo bar'],
|
78
164
|
['test foo bar ', 'foo bar'],
|
79
165
|
].each do |input, args|
|
80
|
-
Client.call_commands(input)
|
166
|
+
status = Client.call_commands(input)
|
81
167
|
command_arg.should == args
|
168
|
+
status.should == 0
|
82
169
|
end
|
83
170
|
end
|
84
171
|
|
85
|
-
it '
|
86
|
-
|
87
|
-
Client.
|
88
|
-
Client.
|
89
|
-
|
90
|
-
|
91
|
-
it 'takes hook as Hash' do
|
92
|
-
Client.register_hook(:name => :test)
|
93
|
-
Client.get_hook(:test).name.should == :test
|
94
|
-
end
|
95
|
-
|
96
|
-
it 'calls new_hook' do
|
97
|
-
hook_called = false
|
98
|
-
Client.register_hook(:name => :test1, :points => [:point1], :exec_proc => lambda {hook_called = true})
|
99
|
-
hook_called.should == false
|
100
|
-
Client.call_hooks(:point1)
|
101
|
-
hook_called.should == true
|
102
|
-
end
|
103
|
-
|
104
|
-
it 'calls new_hook with args' do
|
105
|
-
arg1 = nil
|
106
|
-
arg2 = nil
|
107
|
-
Client.register_hook(:name => :test1, :points => [:point1], :exec_proc => lambda {|a1, a2| arg1 = a1; arg2 = a2})
|
108
|
-
arg1.should == nil
|
109
|
-
arg2.should == nil
|
110
|
-
Client.call_hooks(:point1, 'foo', 'bar')
|
111
|
-
arg1.should == 'foo'
|
112
|
-
arg2.should == 'bar'
|
113
|
-
end
|
114
|
-
|
115
|
-
it 'return hooks when call get_hooks' do
|
116
|
-
hook1 = Client.register_hook(:name => :test1, :points => [:point1])
|
117
|
-
hook2 = Client.register_hook(:name => :test2, :points => [:point1])
|
118
|
-
hook3 = Client.register_hook(:name => :test3, :points => [:point2])
|
119
|
-
|
120
|
-
hooks = Client.get_hooks(:point1)
|
121
|
-
hooks.size.should == 2
|
122
|
-
hooks.include?(hook1).should == true
|
123
|
-
hooks.include?(hook2).should == true
|
124
|
-
hooks.include?(hook3).should == false
|
172
|
+
it 'can clear commands' do
|
173
|
+
Client.instance_variable_set(:@commands, {:hoge => 'piyo'})
|
174
|
+
Client.commands.should_not be_empty
|
175
|
+
Client.clear_command
|
176
|
+
Client.commands.should be_empty
|
125
177
|
end
|
126
178
|
|
127
179
|
it 'calls decide_arg hooks' do
|
@@ -134,11 +186,11 @@ module Termtter
|
|
134
186
|
Client.register_hook( :name => :test2,
|
135
187
|
:points => [:pre_exec_update],
|
136
188
|
:exec_proc => lambda {|cmd, arg| decided_arg = arg})
|
137
|
-
Client.register_command(:name => :update, :aliases => [:u], :exec => lambda{|
|
189
|
+
Client.register_command(:name => :update, :aliases => [:u], :exec => lambda{|_|})
|
138
190
|
|
139
|
-
input_command.should
|
140
|
-
input_arg.should
|
141
|
-
decided_arg.should
|
191
|
+
input_command.should be_nil
|
192
|
+
input_arg.should be_nil
|
193
|
+
decided_arg.should be_nil
|
142
194
|
Client.call_commands('u foo')
|
143
195
|
input_command.should == 'u'
|
144
196
|
input_arg.should == 'foo'
|
@@ -222,6 +274,8 @@ module Termtter
|
|
222
274
|
|
223
275
|
hook_called.should == false
|
224
276
|
Client.should_receive(:puts)
|
277
|
+
Client.instance_variable_get(:@task_manager).
|
278
|
+
should_receive(:kill) {}
|
225
279
|
Client.exit
|
226
280
|
hook_called.should == true
|
227
281
|
end
|
@@ -234,6 +288,7 @@ module Termtter
|
|
234
288
|
|
235
289
|
hook1_called.should == false
|
236
290
|
hook2_called.should == false
|
291
|
+
Client.instance_variable_get(:@task_manager).stub(:kill)
|
237
292
|
Client.should_receive(:puts)
|
238
293
|
Client.exit
|
239
294
|
hook1_called.should == true
|
@@ -277,38 +332,105 @@ module Termtter
|
|
277
332
|
}.should_not raise_error
|
278
333
|
end
|
279
334
|
|
280
|
-
it '
|
281
|
-
|
282
|
-
|
283
|
-
|
284
|
-
|
285
|
-
|
286
|
-
|
287
|
-
|
288
|
-
|
289
|
-
|
290
|
-
|
291
|
-
|
292
|
-
|
293
|
-
|
335
|
+
it 'can apply filter' do
|
336
|
+
statuses = [
|
337
|
+
{ :id => 2,
|
338
|
+
:created_at => Time.now,
|
339
|
+
:user_id => 2,
|
340
|
+
:name => 'name',
|
341
|
+
:screen_name => 'screen name',
|
342
|
+
:source => 'termtter',
|
343
|
+
:reply_to => 1,
|
344
|
+
:text => 'hi',
|
345
|
+
:original_data => 'hi' }
|
346
|
+
]
|
347
|
+
event = :output_for_test
|
348
|
+
hook_name = :my_hook
|
349
|
+
|
350
|
+
hook = Client.register_hook(hook_name) {|s, e| s.text.should == 'hi'; e.should == event }
|
351
|
+
hook.should_receive(:call)
|
352
|
+
Client.should_receive(:get_hooks).with(hook_name).and_return([hook])
|
353
|
+
Client.apply_filters_for_hook(hook_name, statuses, event)
|
354
|
+
end
|
355
|
+
|
356
|
+
it 'can add macro' do
|
357
|
+
Client.should_receive(:register_command).
|
358
|
+
with {|arg| arg.should be_an_instance_of(Hash) }
|
359
|
+
Client.register_macro('greet', "update %s")
|
360
|
+
end
|
361
|
+
|
362
|
+
it 'can clear hooks' do
|
363
|
+
Client.instance_variable_set(:@hooks, {:hoge => 'piyo'})
|
364
|
+
Client.hooks.should_not be_empty
|
365
|
+
Client.clear_hooks
|
366
|
+
Client.hooks.should be_empty
|
367
|
+
end
|
368
|
+
|
369
|
+
it 'can load config' do
|
370
|
+
Client.should_receive(:load).with(Termtter::CONF_FILE)
|
371
|
+
Client.load_config
|
372
|
+
end
|
373
|
+
|
374
|
+
it 'can create config file when load_config' do
|
375
|
+
File.should_receive(:exist?).twice.and_return(false)
|
376
|
+
require 'termtter/config_setup'
|
377
|
+
ConfigSetup.should_receive(:run).and_return(false)
|
378
|
+
Client.stub(:load).with(Termtter::CONF_FILE)
|
379
|
+
Client.load_config
|
380
|
+
end
|
381
|
+
|
382
|
+
it 'can output status (bad)' do
|
383
|
+
Client.should_not_receive(:call_hooks)
|
384
|
+
Client.output(nil, :hoge)
|
385
|
+
Client.should_not_receive(:call_hooks)
|
386
|
+
Client.output([], :hoge)
|
387
|
+
end
|
388
|
+
|
389
|
+
# FIXME: too dirty
|
390
|
+
it 'can output status (good)' do
|
391
|
+
statuses = mock('statuses', :null_object => true)
|
392
|
+
statuses.stub(:empty? => false, :nil? => false)
|
393
|
+
event = :event
|
394
|
+
Client.should_receive(:call_hooks).with(:pre_filter, statuses, event)
|
395
|
+
Client.should_receive(:apply_filters_for_hook).exactly(2).times.
|
396
|
+
with(an_instance_of(Symbol), anything, event).
|
397
|
+
and_return(statuses)
|
398
|
+
Client.should_receive(:call_hooks).with(:post_filter, statuses, event)
|
399
|
+
hook = mock(:hook, :name => 'test')
|
400
|
+
hook.should_receive(:call).with(anything, event)
|
401
|
+
Client.should_receive(:get_hooks).with(:output).and_return([hook])
|
402
|
+
Client.output(statuses, event)
|
403
|
+
end
|
404
|
+
|
405
|
+
it 'can clear filters' do
|
406
|
+
Client.instance_variable_set(:@filters, [:hoge, :piyo])
|
407
|
+
Client.instance_variable_get(:@filters).should_not be_empty
|
408
|
+
Client.clear_filter
|
409
|
+
Client.instance_variable_get(:@filters).should be_empty
|
410
|
+
end
|
411
|
+
|
412
|
+
it 'handles error (not devel)' do
|
413
|
+
logger = Client.logger
|
414
|
+
logger.should_receive(:error).with("StandardError: error")
|
415
|
+
Client.handle_error StandardError.new('error')
|
294
416
|
end
|
295
417
|
|
296
|
-
it '
|
297
|
-
|
298
|
-
Client.
|
299
|
-
|
418
|
+
it 'handles error (devel)' do
|
419
|
+
config.devel = true
|
420
|
+
logger = Client.logger
|
421
|
+
logger.should_receive(:error).with("StandardError: error").twice
|
422
|
+
error = StandardError.new('error')
|
423
|
+
error.stub(:backtrace).and_return(["StandardError: error"])
|
424
|
+
Client.handle_error error
|
300
425
|
end
|
301
426
|
|
302
|
-
it '
|
303
|
-
|
304
|
-
|
305
|
-
Client.
|
306
|
-
|
307
|
-
|
308
|
-
|
309
|
-
logger = Client.instance_eval{@logger}
|
310
|
-
logger.should_receive(:error).with("StandardError: error")
|
311
|
-
Client.handle_error StandardError.new('error')
|
427
|
+
it 'handle_error raise error when logger is nothing' do
|
428
|
+
Client.instance_variable_set(:@logger, nil)
|
429
|
+
$stderr, old = StringIO.new, $stderr
|
430
|
+
Client.handle_error(StandardError.new('error'))
|
431
|
+
$stderr.rewind
|
432
|
+
$stderr.gets.should match(/\AError: error/)
|
433
|
+
$stderr = old
|
312
434
|
end
|
313
435
|
|
314
436
|
it 'cancels command by hook' do
|
@@ -326,6 +448,7 @@ module Termtter
|
|
326
448
|
end
|
327
449
|
|
328
450
|
it 'gets default help' do
|
451
|
+
Client.plug 'defaults' # FIXME: Do not need
|
329
452
|
$stdout, old_stdout = StringIO.new, $stdout # FIXME That suspends any debug informations!
|
330
453
|
help_command = Client.get_command(:help)
|
331
454
|
help_command.should_not be_nil
|
@@ -335,6 +458,7 @@ module Termtter
|
|
335
458
|
end
|
336
459
|
|
337
460
|
it 'gets an added help' do
|
461
|
+
Client.plug 'defaults' # FIXME: Do not need
|
338
462
|
Client.register_command(
|
339
463
|
:name => :foo,
|
340
464
|
:help => [
|
@@ -350,6 +474,71 @@ module Termtter
|
|
350
474
|
$stdout.string.should match(/foo list/)
|
351
475
|
end
|
352
476
|
|
477
|
+
it 'can confirm before update (yes default)' do
|
478
|
+
message = 'hello'
|
479
|
+
Readline.should_receive(:readline).
|
480
|
+
with("\"#{message}".strip + "\" [Y/n] ", false)
|
481
|
+
Client.confirm(message)
|
482
|
+
end
|
483
|
+
|
484
|
+
it 'can confirm before update (no default)' do
|
485
|
+
message = 'hello'
|
486
|
+
Readline.should_receive(:readline).
|
487
|
+
with("\"#{message}".strip + "\" [N/y] ", false)
|
488
|
+
Client.confirm(message, false)
|
489
|
+
end
|
490
|
+
|
491
|
+
it 'can configm before update' do
|
492
|
+
ok_pattern = [ 'y', 'Y', '' ]
|
493
|
+
ng_pattern = [
|
494
|
+
'n', 'N',
|
495
|
+
('a'..'z').to_a,
|
496
|
+
('A'..'Z').to_a ].flatten
|
497
|
+
ng_pattern -= ['y', 'Y']
|
498
|
+
|
499
|
+
ok_pattern.each do |ask|
|
500
|
+
Readline.should_receive(:readline).and_return(ask)
|
501
|
+
Client.confirm('hello').should be_true
|
502
|
+
end
|
503
|
+
ng_pattern.each do |ask|
|
504
|
+
Readline.should_receive(:readline).and_return(ask)
|
505
|
+
Client.confirm('hello').should be_false
|
506
|
+
end
|
507
|
+
end
|
508
|
+
|
509
|
+
it 'confirm can take block as callback' do
|
510
|
+
Readline.stub(:readline => 'y')
|
511
|
+
called = false
|
512
|
+
Client.confirm('hello') { called = true }
|
513
|
+
called.should be_true
|
514
|
+
end
|
515
|
+
|
516
|
+
it 'default logger can cahnge error to fit security level' do
|
517
|
+
logger = Client.default_logger
|
518
|
+
TermColor.should_receive(:parse).with(match(/blue/))
|
519
|
+
logger.debug 'hi'
|
520
|
+
TermColor.should_receive(:parse).with(match(/cyan/))
|
521
|
+
logger.info 'hi'
|
522
|
+
TermColor.should_receive(:parse).with(match(/magenta/))
|
523
|
+
logger.warn 'hi'
|
524
|
+
TermColor.should_receive(:parse).with(match(/red/))
|
525
|
+
logger.error 'hi'
|
526
|
+
TermColor.should_receive(:parse).with(match(/on_red/))
|
527
|
+
logger.fatal 'hi'
|
528
|
+
TermColor.should_receive(:parse).with(match(/white/))
|
529
|
+
logger.unknown 'hi'
|
530
|
+
end
|
531
|
+
|
532
|
+
it 'can cancel command' do
|
533
|
+
text = 'text'
|
534
|
+
command = mock('command', :null_object => true)
|
535
|
+
command.stub(:call) { raise CommandCanceled }
|
536
|
+
Client.stub(:find_commands).with(text).and_return([command])
|
537
|
+
lambda {
|
538
|
+
Client.call_commands(text).should == 1
|
539
|
+
}.should_not raise_error
|
540
|
+
end
|
541
|
+
|
353
542
|
describe 'add commands' do
|
354
543
|
before(:each) do
|
355
544
|
Client.clear_command
|
@@ -77,6 +77,11 @@ module Termtter
|
|
77
77
|
end
|
78
78
|
end
|
79
79
|
|
80
|
+
it 'returns empty array as candidates when competition_proc is nil'do
|
81
|
+
command = Command.new(:name => :foo)
|
82
|
+
command.complement('foo bar').should == []
|
83
|
+
end
|
84
|
+
|
80
85
|
it 'returns command_info when call method "match?"' do
|
81
86
|
[
|
82
87
|
['update', true],
|
@@ -123,18 +128,39 @@ module Termtter
|
|
123
128
|
end
|
124
129
|
|
125
130
|
describe '.split_command_line' do
|
131
|
+
before do
|
132
|
+
@command = Command.new(:name => 'test')
|
133
|
+
end
|
134
|
+
|
126
135
|
it 'splits from a command line string to the command name and the arg' do
|
127
|
-
|
136
|
+
@command.split_command_line('test foo bar').
|
128
137
|
should == ['test', 'foo bar']
|
129
|
-
|
138
|
+
@command.split_command_line('test foo bar').
|
130
139
|
should == ['test', 'foo bar']
|
131
|
-
|
140
|
+
@command.split_command_line('test foo bar').
|
132
141
|
should == ['test', 'foo bar']
|
133
|
-
|
142
|
+
@command.split_command_line(' test foo bar').
|
134
143
|
should == ['test', 'foo bar']
|
135
|
-
|
144
|
+
@command.split_command_line(' test foo bar ').
|
136
145
|
should == ['test', 'foo bar']
|
137
146
|
end
|
138
147
|
end
|
148
|
+
|
149
|
+
describe 'spec for split_command_line with sub command' do
|
150
|
+
before do
|
151
|
+
@command = Command.new(:name => 'foo bar')
|
152
|
+
end
|
153
|
+
|
154
|
+
it 'splits from a command line string to the command name and the arg' do
|
155
|
+
@command.split_command_line('foo bar args').
|
156
|
+
should == ['foo bar', 'args']
|
157
|
+
@command.split_command_line('foo bar args').
|
158
|
+
should == ['foo bar', 'args']
|
159
|
+
@command.split_command_line(' foo bar args ').
|
160
|
+
should == ['foo bar', 'args']
|
161
|
+
@command.split_command_line(' foo foo args ').
|
162
|
+
should == ['foo foo', 'args']
|
163
|
+
end
|
164
|
+
end
|
139
165
|
end
|
140
166
|
end
|
@@ -0,0 +1,19 @@
|
|
1
|
+
# -*- coding: utf-8 -*-
|
2
|
+
|
3
|
+
require File.dirname(__FILE__) + '/../spec_helper'
|
4
|
+
require 'termtter/config_setup'
|
5
|
+
|
6
|
+
module Termtter
|
7
|
+
describe ConfigSetup do
|
8
|
+
it "check inputed values" do
|
9
|
+
highline = mock('mock', :ask => 'username_or_password')
|
10
|
+
ConfigSetup.stub(:create_highline).and_return(highline)
|
11
|
+
File.stub(:exists?).and_return(true)
|
12
|
+
io = StringIO.new
|
13
|
+
File.stub(:open).and_yield(io)
|
14
|
+
ConfigSetup.run
|
15
|
+
io.rewind
|
16
|
+
io.read.should match(/username_or_password/)
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|