termtter 1.6.0 → 1.7.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (98) hide show
  1. data/.gitignore +5 -0
  2. data/README.rdoc +2 -2
  3. data/Rakefile +41 -75
  4. data/VERSION +1 -0
  5. data/bin/termtter +9 -2
  6. data/doc/Termtter-1.0-Release-Note-English.txt +37 -0
  7. data/doc/Termtter-1.0-Release-Note.txt +37 -0
  8. data/lib/plugins/another_prompt.rb +8 -8
  9. data/lib/plugins/ar.rb +102 -0
  10. data/lib/plugins/async.rb +1 -1
  11. data/lib/plugins/babelfish.rb +34 -0
  12. data/lib/plugins/confirm.rb +2 -0
  13. data/lib/plugins/crypt.rb +44 -0
  14. data/lib/plugins/defaults/auto_reload.rb +1 -1
  15. data/lib/plugins/defaults/command_line.rb +34 -17
  16. data/lib/plugins/defaults/confirm.rb +30 -0
  17. data/lib/plugins/defaults/hashtag.rb +1 -1
  18. data/lib/plugins/defaults/irb.rb +30 -0
  19. data/lib/plugins/defaults/keyword.rb +58 -0
  20. data/lib/plugins/defaults/list.rb +155 -0
  21. data/lib/plugins/defaults/plugin.rb +59 -0
  22. data/lib/plugins/defaults/retweet.rb +75 -23
  23. data/lib/plugins/defaults/standard_commands.rb +60 -87
  24. data/lib/plugins/defaults/standard_completion.rb +25 -15
  25. data/lib/plugins/defaults/stdout.rb +49 -10
  26. data/lib/plugins/defaults/switch.rb +1 -1
  27. data/lib/plugins/defaults/users.rb +63 -0
  28. data/lib/plugins/draft.rb +58 -0
  29. data/lib/plugins/expand-tinyurl.rb +5 -9
  30. data/lib/plugins/favotter.rb +1 -1
  31. data/lib/plugins/footer.rb +22 -0
  32. data/lib/plugins/friends.rb +5 -4
  33. data/lib/plugins/g.rb +9 -16
  34. data/lib/plugins/gem_install.rb +24 -0
  35. data/lib/plugins/gist.rb +20 -0
  36. data/lib/plugins/grass.rb +1 -1
  37. data/lib/plugins/gyazo.rb +78 -0
  38. data/lib/plugins/http_server.rb +1 -1
  39. data/lib/plugins/hugeurl.rb +6 -13
  40. data/lib/plugins/irc_gw.rb +15 -11
  41. data/lib/plugins/me.rb +1 -1
  42. data/lib/plugins/notify-send.rb +1 -1
  43. data/lib/plugins/notify-send3.rb +1 -1
  44. data/lib/plugins/open.rb +1 -1
  45. data/lib/plugins/open_url.rb +5 -1
  46. data/lib/plugins/pool.rb +1 -1
  47. data/lib/plugins/random.rb +1 -1
  48. data/lib/plugins/reply_retweet.rb +42 -0
  49. data/lib/plugins/screen-notify.rb +1 -1
  50. data/lib/plugins/sl.rb +3 -3
  51. data/lib/plugins/storage.rb +7 -10
  52. data/lib/plugins/storage/sqlite3.rb +155 -0
  53. data/lib/plugins/storage/status.rb +2 -0
  54. data/lib/plugins/stream.rb +1 -1
  55. data/lib/plugins/tinyurl.rb +3 -9
  56. data/lib/plugins/trends.rb +2 -2
  57. data/lib/plugins/truncate.rb +1 -1
  58. data/lib/plugins/w3mimg.rb +1 -1
  59. data/lib/termtter.rb +19 -20
  60. data/lib/termtter/active_rubytter.rb +4 -0
  61. data/lib/termtter/api.rb +22 -5
  62. data/lib/termtter/client.rb +55 -40
  63. data/lib/termtter/command.rb +3 -2
  64. data/lib/termtter/config_setup.rb +1 -1
  65. data/lib/termtter/config_template.erb +5 -0
  66. data/lib/termtter/default_config.rb +18 -0
  67. data/lib/termtter/hookable.rb +1 -0
  68. data/lib/termtter/httppool.rb +44 -0
  69. data/lib/termtter/memory_cache.rb +32 -0
  70. data/lib/termtter/optparse.rb +8 -15
  71. data/lib/termtter/rubytter_proxy.rb +65 -4
  72. data/lib/termtter/system_extensions.rb +40 -9
  73. data/lib/termtter/task.rb +2 -1
  74. data/spec/plugins/defaults/hashtag_spec.rb +8 -7
  75. data/spec/plugins/defaults/list_spec.rb +33 -0
  76. data/spec/plugins/defaults/plugin_spec.rb +17 -0
  77. data/spec/plugins/defaults/retweet_spec.rb +205 -0
  78. data/spec/plugins/draft_spec.rb +59 -0
  79. data/spec/plugins/expand-tinyurl_spec.rb +21 -0
  80. data/spec/plugins/footer_spec.rb +50 -0
  81. data/spec/plugins/storage/sqlite3_spec.rb +41 -0
  82. data/spec/termtter/api_spec.rb +1 -1
  83. data/spec/termtter/client_spec.rb +21 -21
  84. data/spec/termtter/command_spec.rb +8 -8
  85. data/spec/termtter/config_spec.rb +2 -2
  86. data/spec/termtter/memory_cache_spec.rb +20 -0
  87. data/spec/termtter/optparse_spec.rb +1 -1
  88. data/spec/termtter/rubytter_proxy_spec.rb +38 -0
  89. data/spec/termtter/system_extensions_spec.rb +25 -23
  90. data/spec/termtter/task_manager_spec.rb +1 -1
  91. data/spec/termtter_spec.rb +4 -2
  92. metadata +88 -19
  93. data/lib/plugins/defaults/lists.rb +0 -14
  94. data/lib/plugins/irb.rb +0 -6
  95. data/lib/plugins/storage/DB.rb +0 -37
  96. data/lib/termtter/version.rb +0 -4
  97. data/spec/plugins/defaults/lists_spec.rb +0 -34
  98. data/spec/plugins/storage/DB_spec_.rb +0 -12
@@ -0,0 +1,59 @@
1
+ require File.dirname(__FILE__) + '/../spec_helper'
2
+
3
+ module Termtter
4
+ describe 'plugin draft' do
5
+ before do
6
+ Client.setup_task_manager
7
+ Client.plug 'draft'
8
+ Client.public_storage[:drafts].clear
9
+ Client.public_storage[:drafts] << 'foo'
10
+ Client.public_storage[:drafts] << 'bar'
11
+ Client.stub!(:puts)
12
+ end
13
+
14
+ it 'should puts drafts' do
15
+ Client.should_receive(:puts).with("0: foo")
16
+ Client.should_receive(:puts).with("1: bar")
17
+ Client.execute('draft list')
18
+ end
19
+
20
+ it 'should clear drafts' do
21
+ Client.execute('draft clear')
22
+ Client.public_storage[:drafts].size.should == 0
23
+ end
24
+
25
+ it 'should exec last draft' do
26
+ Client.should_receive(:execute).with('bar')
27
+ Client.get_command(:'draft exec').call('draft exec')
28
+ end
29
+
30
+ it 'should exec specified draft' do
31
+ Client.should_receive(:execute).with('foo')
32
+ Client.get_command(:'draft exec').call('draft exec', '0')
33
+ end
34
+
35
+ it 'should not exec draft if index is wrong' do
36
+ Client.should_not_receive(:execute)
37
+ Client.get_command(:'draft exec').call('draft exec', '2')
38
+ Client.should_not_receive(:execute)
39
+ Client.get_command(:'draft exec').call('draft exec', 'a')
40
+ end
41
+
42
+ it 'should delete draft' do
43
+ Client.get_command(:'draft delete').call('draft delete')
44
+ Client.public_storage[:drafts].should == ["foo"]
45
+ end
46
+
47
+ it 'should delete specified draft' do
48
+ Client.get_command(:'draft delete').call('draft delete', '0')
49
+ Client.public_storage[:drafts].should == ["bar"]
50
+ end
51
+
52
+ it 'should not delete draft if index is wrong' do
53
+ Client.get_command(:'draft delete').call('draft delete', '2')
54
+ Client.public_storage[:drafts].should == ["foo", "bar"]
55
+ Client.get_command(:'draft delete').call('draft delete', 'a')
56
+ Client.public_storage[:drafts].should == ["foo", "bar"]
57
+ end
58
+ end
59
+ end
@@ -0,0 +1,21 @@
1
+ # -*- coding: utf-8 -*-
2
+
3
+ require File.dirname(__FILE__) + '/../spec_helper'
4
+
5
+ describe Termtter::Client, 'when the plugin expand-tinyurl is loaded' do
6
+ before do
7
+ be_quiet { Termtter::Client.plug 'expand-tinyurl' }
8
+ end
9
+
10
+ it 'should define expand_url method' do
11
+ # TODO: 直接ネットにアクセスしに行かないようにしたい。 fakeweb?
12
+
13
+ expand_url('tinyurl.com', '/kotu').should == 'http://example.com/'
14
+
15
+ expand_url('tinyurl.com', '/de5my6').should == 'http://example.com/テスト'
16
+
17
+ expand_url('is.gd', '/5oDxw').should == 'http://example.com/'
18
+
19
+ expand_url('goo.gl', '/e').should == 'http://www.google.com/'
20
+ end
21
+ end
@@ -0,0 +1,50 @@
1
+ #-*- coding: utf-8 -*-
2
+ require File.dirname(__FILE__) + '/../spec_helper.rb'
3
+
4
+ describe Termtter::Client, 'when the plugin footer is loaded' do
5
+ @r = nil
6
+ before(:all) do
7
+ @r = nil
8
+ Termtter::Client.clear_hooks
9
+ Termtter::Client.setup_task_manager
10
+
11
+ config.footer = "[termtter]"
12
+
13
+ end
14
+
15
+ before do
16
+ @r = nil
17
+ Termtter::Client.register_command(:name => :update, :aliases => [:u], :exec => lambda{|arg| @r = arg })
18
+ Termtter::Client.plug 'footer'
19
+ end
20
+
21
+ it 'should add hook add_footer and command footer' do
22
+ Termtter::Client.should_receive(:register_hook).once
23
+ Termtter::Client.should_receive(:register_command).once
24
+ Termtter::Client.plug 'footer'
25
+ end
26
+
27
+ it 'should add footer at update' do
28
+ @r.should be_nil
29
+ Termtter::Client.execute('update foo')
30
+ config.footer.should == '[termtter]'
31
+ @r.should == 'foo [termtter]'
32
+ end
33
+
34
+ it 'should call footer command to change config.footer' do
35
+ Termtter::Client.execute('footer #termtter')
36
+ config.footer.should == '#termtter'
37
+ @r.should be_nil
38
+ Termtter::Client.execute('update bar')
39
+ @r.should == 'bar #termtter'
40
+ end
41
+
42
+ it 'should call footer no argument to set config.footer to nil' do
43
+ Termtter::Client.execute('footer')
44
+ config.footer.should == nil
45
+ @r.should be_nil
46
+ Termtter::Client.execute('update hoge')
47
+ @r.should == 'hoge'
48
+ end
49
+ end
50
+
@@ -0,0 +1,41 @@
1
+ require 'tmpdir'
2
+ require File.dirname(__FILE__) + '/../../spec_helper'
3
+ require File.dirname(__FILE__) + '/../../../lib/plugins/storage/sqlite3'
4
+
5
+ module Termtter::Storage
6
+ describe "sqlite3" do
7
+ DB_FILE = File.join(Dir.tmpdir, 'test.db')
8
+ before(:each) do
9
+ File.delete(DB_FILE) if File.exists?(DB_FILE)
10
+ @db = Termtter::Storage::SQLite3.new(DB_FILE)
11
+ end
12
+
13
+ after do
14
+ File.delete(DB_FILE) if File.exists?(DB_FILE)
15
+ end
16
+
17
+ it 'update should not return false' do
18
+ h = {
19
+ :post_id => 1,
20
+ :created_at => 12345,
21
+ :in_reply_to_status_id => -1,
22
+ :in_reply_to_user_id => -1,
23
+ :text => 'bomb',
24
+ :user_id => 1
25
+ }
26
+ @db.update(h).should_not be_false
27
+ end
28
+
29
+ it 'find_id returns status' do
30
+ end
31
+
32
+ it 'find_text returns status' do
33
+ end
34
+
35
+ it 'find_user returns status' do
36
+ end
37
+
38
+ it 'size of statuses' do
39
+ end
40
+ end
41
+ end
@@ -61,7 +61,7 @@ module Termtter
61
61
  it_should_examine_with('test', nil) { nil }
62
62
  }
63
63
  result[:stdout].should ==
64
- "Please enter your Twitter login:\nPassword: \n"
64
+ "Please enter your Twitter login:\nUsername: test\nPassword: \n"
65
65
  end
66
66
 
67
67
  it 'can examine username and password (only pass)' do
@@ -48,7 +48,8 @@ module Termtter
48
48
  config.system.eval_scripts = []
49
49
  config.system.cmd_mode = false
50
50
  Client.should_receive(:call_hooks).with(:initialize)
51
- Client.should_receive(:call_hooks).with(:launched)
51
+ Client.should_receive(:call_hooks).with(:init_command_line)
52
+ # NOTE: :launched も呼ばれるはず
52
53
  Client.run
53
54
  end
54
55
 
@@ -163,9 +164,9 @@ module Termtter
163
164
  ['test foo bar ', 'foo bar'],
164
165
  ['test foo bar ', 'foo bar'],
165
166
  ].each do |input, args|
166
- status = Client.call_commands(input)
167
+ status = Client.execute(input)
167
168
  command_arg.should == args
168
- status.should == 0
169
+ status.should == true
169
170
  end
170
171
  end
171
172
 
@@ -191,7 +192,7 @@ module Termtter
191
192
  input_command.should be_nil
192
193
  input_arg.should be_nil
193
194
  decided_arg.should be_nil
194
- Client.call_commands('u foo')
195
+ Client.execute('u foo')
195
196
  input_command.should == 'u'
196
197
  input_arg.should == 'foo'
197
198
  decided_arg.should == 'FOO'
@@ -205,11 +206,11 @@ module Termtter
205
206
  Client.register_command(:name => :update, :exec => lambda{|arg|})
206
207
 
207
208
  hook_called.should == false
208
- Client.call_commands('')
209
+ Client.execute('')
209
210
  hook_called.should == true
210
211
 
211
212
  hook_called = false
212
- Client.call_commands('update foo')
213
+ Client.execute('update foo')
213
214
  hook_called.should == true
214
215
  end
215
216
 
@@ -221,10 +222,10 @@ module Termtter
221
222
  Client.register_command(:name => :update, :exec => lambda{|arg|})
222
223
 
223
224
  hook_called.should == false
224
- Client.call_commands('')
225
+ Client.execute('')
225
226
  hook_called.should == false
226
227
 
227
- Client.call_commands('update foo')
228
+ Client.execute('update foo')
228
229
  hook_called.should == true
229
230
  end
230
231
 
@@ -236,7 +237,7 @@ module Termtter
236
237
  Client.register_command(:name => :update, :exec => lambda{|arg|})
237
238
 
238
239
  hook_called.should == false
239
- Client.call_commands('update foo')
240
+ Client.execute('update foo')
240
241
  hook_called.should == true
241
242
  end
242
243
 
@@ -248,7 +249,7 @@ module Termtter
248
249
  Client.register_command(:name => :update, :exec_proc => lambda {|arg| command_called = true})
249
250
 
250
251
  command_called.should == false
251
- Client.call_commands('update foo')
252
+ Client.execute('update foo')
252
253
  command_called.should == false
253
254
  end
254
255
 
@@ -260,7 +261,7 @@ module Termtter
260
261
  Client.register_command(:name => :update, :exec_proc => lambda {|arg| 'foo'})
261
262
 
262
263
  command_result.should == nil
263
- Client.call_commands('update foo')
264
+ Client.execute('update foo')
264
265
  command_result.should == 'foo'
265
266
  end
266
267
 
@@ -444,7 +445,7 @@ module Termtter
444
445
  }
445
446
  )
446
447
  command.should_not_receive(:call)
447
- Client.call_commands('test')
448
+ Client.execute('test')
448
449
  end
449
450
 
450
451
  it 'gets default help' do
@@ -533,10 +534,8 @@ module Termtter
533
534
  text = 'text'
534
535
  command = mock('command', :null_object => true)
535
536
  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
537
+ Client.stub(:find_command).with(text).and_return(command)
538
+ Client.execute(text).should == false
540
539
  end
541
540
 
542
541
  describe 'add commands' do
@@ -545,16 +544,17 @@ module Termtter
545
544
  Client.register_command(:name => :foo1)
546
545
  Client.register_command(:name => :foo2)
547
546
  Client.register_command(:name => :bar)
547
+ Client.register_command(:name => 'bar xxx')
548
548
  end
549
549
 
550
550
  it 'commands number is 3' do
551
- Client.commands.size.should == 3
551
+ Client.commands.size.should == 4
552
552
  end
553
553
 
554
554
  it 'finds a command' do
555
- Client.find_commands('foo1').size.should == 1
556
- Client.find_commands('foo1')[0].name.should == :foo1
557
- Client.find_commands('bar').size.should == 1
555
+ Client.find_command('foo1').name.should == :foo1
556
+ Client.find_command('bar').name.should == :bar
557
+ Client.find_command('bar xxx').name.should == :'bar xxx'
558
558
  end
559
559
 
560
560
  it 'check command exists' do
@@ -565,7 +565,7 @@ module Termtter
565
565
  end
566
566
 
567
567
  it 'finds no command' do
568
- Client.find_commands('foo').size.should == 0
568
+ Client.find_command('foo').should be_nil
569
569
  end
570
570
  end
571
571
 
@@ -5,19 +5,19 @@ require File.dirname(__FILE__) + '/../spec_helper'
5
5
  module Termtter
6
6
  describe 'Command#initialize' do
7
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)
8
+ lambda { Command.new(:nama => :a) }.should raise_error(ArgumentError)
9
+ lambda { Command.new(:name => :a) }.should_not raise_error(ArgumentError)
10
10
  end
11
11
 
12
12
  it 'does not destroy the argument hash' do
13
13
  hash = {
14
- :name => 1,
14
+ :name => 'a',
15
15
  :exec => 3
16
16
  }
17
17
  Command.new hash
18
18
 
19
19
  hash.should eql(hash)
20
- hash[:name].should == 1
20
+ hash[:name].should == 'a'
21
21
  hash[:exec].should == 3
22
22
  hash[:exec_proc].should be_nil
23
23
  end
@@ -66,11 +66,9 @@ module Termtter
66
66
  it 'returns candidates for completion' do
67
67
  # complement
68
68
  [
69
- ['upd', ['update']],
70
- [' upd', []],
71
- [' upd ', []],
69
+ ['update ', ['complete1', 'complete2']],
70
+ [' update ', ['complete1', 'complete2']],
72
71
  ['update a', ['complete1', 'complete2']],
73
- [' update ', []],
74
72
  ['u foo', ['complete1', 'complete2']],
75
73
  ].each do |input, comp|
76
74
  @command.complement(input).should == comp
@@ -143,6 +141,8 @@ module Termtter
143
141
  should == ['test', 'foo bar']
144
142
  @command.split_command_line(' test foo bar ').
145
143
  should == ['test', 'foo bar']
144
+ @command.split_command_line('test ').
145
+ should == ['test', '']
146
146
  end
147
147
  end
148
148
 
@@ -72,8 +72,8 @@ module Termtter
72
72
 
73
73
  it 'can raise error when add by prohibited name' do
74
74
  lambda {
75
- @config.set_default('sub.aaa', :value)
76
- @config.sub.aaa
75
+ @config.set_default('open.aaa', :value)
76
+ @config.open.aaa
77
77
  }.should raise_error
78
78
  end
79
79
 
@@ -0,0 +1,20 @@
1
+ # -*- coding: utf-8 -*-
2
+ require File.dirname(__FILE__) + '/../spec_helper'
3
+
4
+ module Termtter
5
+ describe MemoryCache do
6
+ it 'is like Hash' do
7
+ cache = MemoryCache.new(2)
8
+ cache[:foo] = 'foo'
9
+ cache[:bar] = 'bar'
10
+
11
+ cache[:foo].should == 'foo'
12
+ cache[:foo].should == 'foo'
13
+
14
+ cache[:jugyo] = 'jugyo'
15
+ cache[:jugyo].should == 'jugyo'
16
+
17
+ cache.key?(:foo).should be_false
18
+ end
19
+ end
20
+ end
@@ -13,7 +13,7 @@ module Termtter
13
13
  end
14
14
 
15
15
  def run_termtter(opt)
16
- `./run_termtter.rb #{opt}`
16
+ `./bin/termtter #{opt}`
17
17
  end
18
18
 
19
19
  it 'accepts -h option' do
@@ -38,5 +38,43 @@ module Termtter
38
38
 
39
39
  @twitter.update('test')
40
40
  end
41
+
42
+ it 'should retry to be success' do
43
+ config.retry = 3
44
+ @rubytter_mock.stub!(:update).exactly(1).times
45
+ @twitter.update('test')
46
+ end
47
+
48
+ it 'should retry when raise TimeoutError' do
49
+ config.retry = 3
50
+ @rubytter_mock.stub!(:update).exactly(config.retry).times.and_raise(TimeoutError)
51
+ @twitter.update('test')
52
+ end
53
+
54
+ it 'should store cache when call "show"' do
55
+ status = "status"
56
+ @rubytter_mock.should_receive(:show).exactly(1).and_return(status)
57
+ @twitter.should_receive(:store_status_cache).with(status)
58
+ @twitter.show(1)
59
+ end
60
+
61
+ it 'should store cache when call "home_timeline"' do
62
+ statuses = ["1", "2"]
63
+ @rubytter_mock.should_receive(:home_timeline).exactly(1).and_return(statuses)
64
+ @twitter.should_receive(:store_status_cache).exactly(2)
65
+ @twitter.home_timeline
66
+ end
67
+
68
+ it 'should store cache when call "store_status_cache"' do
69
+ user = "user"
70
+ @twitter.should_receive(:store_user_cache).with(user)
71
+ @twitter.store_status_cache(Rubytter.structize({:user => user}))
72
+ end
73
+
74
+ it 'should not call rubytter if cache exists' do
75
+ @twitter.status_cache_store[1] = "status"
76
+ @rubytter_mock.should_receive(:show).exactly(0)
77
+ @twitter.show(1).should == "status"
78
+ end
41
79
  end
42
80
  end