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.
Files changed (86) hide show
  1. data/Rakefile +2 -1
  2. data/bin/termtter +1 -0
  3. data/lib/plugins/another_prompt.rb +131 -0
  4. data/lib/plugins/async.rb +23 -0
  5. data/lib/plugins/confirm.rb +1 -1
  6. data/lib/plugins/db.rb +1 -1
  7. data/lib/plugins/defaults/auto_reload.rb +20 -19
  8. data/lib/plugins/defaults/command_line.rb +10 -5
  9. data/lib/plugins/defaults/hashtag.rb +35 -0
  10. data/lib/plugins/defaults/lists.rb +14 -0
  11. data/lib/plugins/defaults/retweet.rb +15 -15
  12. data/lib/plugins/defaults/standard_commands.rb +22 -28
  13. data/lib/plugins/defaults/standard_completion.rb +5 -5
  14. data/lib/plugins/defaults/switch.rb +34 -0
  15. data/lib/plugins/eject.rb +15 -0
  16. data/lib/plugins/expand-tinyurl.rb +1 -1
  17. data/lib/plugins/favotter.rb +77 -0
  18. data/lib/plugins/friends.rb +50 -0
  19. data/lib/plugins/g.rb +16 -0
  20. data/lib/plugins/gsub.rb +17 -0
  21. data/lib/plugins/haml.rb +55 -0
  22. data/lib/plugins/hatebu_and_update.rb +2 -2
  23. data/lib/plugins/history.rb +9 -0
  24. data/lib/plugins/irc_gw.rb +11 -4
  25. data/lib/plugins/linefeed.rb +31 -0
  26. data/lib/plugins/md5pass.rb +42 -0
  27. data/lib/plugins/outputz.rb +1 -1
  28. data/lib/plugins/primes.rb +1 -1
  29. data/lib/plugins/quote.rb +43 -0
  30. data/lib/plugins/reduce_text.rb +26 -0
  31. data/lib/plugins/reverse.rb +7 -6
  32. data/lib/plugins/source.rb +31 -0
  33. data/lib/plugins/storage/status.rb +2 -2
  34. data/lib/plugins/storage.rb +1 -1
  35. data/lib/plugins/stream.rb +192 -0
  36. data/lib/plugins/switch_user.rb +1 -22
  37. data/lib/plugins/truncate.rb +29 -0
  38. data/lib/plugins/uri-open.rb +23 -9
  39. data/lib/plugins/w3mimg.rb +76 -0
  40. data/lib/termtter/active_rubytter.rb +8 -0
  41. data/lib/termtter/api.rb +37 -13
  42. data/lib/termtter/client.rb +26 -47
  43. data/lib/termtter/command.rb +15 -9
  44. data/lib/termtter/config.rb +6 -2
  45. data/lib/termtter/hookable.rb +59 -0
  46. data/lib/termtter/optparse.rb +51 -39
  47. data/lib/termtter/rubytter_proxy.rb +32 -0
  48. data/lib/termtter/system_extensions/core_compatibles.rb +16 -0
  49. data/lib/termtter/system_extensions/termtter_compatibles.rb +19 -0
  50. data/lib/termtter/system_extensions/windows.rb +86 -0
  51. data/lib/termtter/system_extensions.rb +8 -121
  52. data/lib/termtter/task_manager.rb +4 -10
  53. data/lib/termtter/version.rb +1 -1
  54. data/lib/termtter.rb +5 -3
  55. data/spec/plugins/defaults/hashtag_spec.rb +41 -0
  56. data/spec/plugins/defaults/lists_spec.rb +34 -0
  57. data/spec/plugins/{english_spec.rb → english_spec_.rb} +0 -0
  58. data/spec/plugins/{filter_spec.rb → filter_spec_.rb} +0 -0
  59. data/spec/plugins/gsub_spec.rb +18 -0
  60. data/spec/plugins/haml_spec.rb +134 -0
  61. data/spec/plugins/md5pass_spec.rb +13 -0
  62. data/spec/plugins/{primes_spec.rb → primes_spec_.rb} +0 -0
  63. data/spec/plugins/{sl_spec.rb → sl_spec_.rb} +0 -0
  64. data/spec/plugins/standard_commands_spec.rb +1 -1
  65. data/spec/plugins/storage/{DB_spec.rb → DB_spec_.rb} +0 -0
  66. data/spec/plugins/storage/{status_spec.rb → status_spec_.rb} +0 -0
  67. data/spec/plugins/truncate_spec.rb +27 -0
  68. data/spec/plugins/whois_spec_.rb +20 -0
  69. data/spec/spec_helper.rb +25 -0
  70. data/spec/termtter/active_rubytter_spec.rb +17 -0
  71. data/spec/termtter/api_spec.rb +107 -0
  72. data/spec/termtter/client_spec.rb +262 -73
  73. data/spec/termtter/command_spec.rb +31 -5
  74. data/spec/termtter/config_setup_spec.rb +19 -0
  75. data/spec/termtter/config_spec.rb +57 -27
  76. data/spec/termtter/hook_spec.rb +12 -0
  77. data/spec/termtter/hookable_spec.rb +53 -0
  78. data/spec/termtter/optparse_spec.rb +64 -9
  79. data/spec/termtter/rubytter_proxy_spec.rb +42 -0
  80. data/spec/termtter/system_extensions/windows_spec.rb +9 -0
  81. data/spec/termtter/system_extensions_spec.rb +61 -0
  82. data/spec/termtter/task_manager_spec.rb +58 -0
  83. data/spec/termtter_spec.rb +11 -0
  84. metadata +45 -20
  85. data/lib/termtter/connection.rb +0 -41
  86. data/spec/plugins/whois_spec.rb +0 -26
@@ -8,28 +8,54 @@ module Termtter
8
8
  @config = Config.new
9
9
  end
10
10
 
11
- it 'should be able to store value to new storage' do
11
+ it 'can store value to new storage' do
12
12
  @config.new_storage = :value
13
13
  @config.new_storage.should == :value
14
14
  end
15
15
 
16
- it 'should be able to make subb.key and store value' do
16
+ it 'can make subb.key and store value' do
17
17
  @config.subb.key = :value
18
18
  @config.subb.key.should == :value
19
19
  end
20
20
 
21
- it 'should be able to make multiple storage' do
21
+ it 'can make multiple storage' do
22
22
  @config.subb.more.for.test = 'value'
23
23
  @config.subb.more.for.test.should == 'value'
24
24
  end
25
25
 
26
- it 'should be able to change value in storage' do
26
+ it 'can change value in storage' do
27
27
  @config.storage = :value1
28
28
  @config.storage = :value2
29
29
  @config.storage.should == :value2
30
30
  end
31
31
 
32
- it 'should be able to store any data' do
32
+ it 'can inspect' do
33
+ @config.storage = :value
34
+ @config.inspect.should == {:storage => :value}.inspect
35
+ end
36
+
37
+ it 'can get __values__' do
38
+ @config.storage = :value
39
+ @config.__values__.should == {:storage => :value}
40
+ end
41
+
42
+ it 'can __clear__' do
43
+ @config.storage = :value
44
+ @config.storage.should == :value
45
+ @config.__clear__
46
+ result = @config.__values__
47
+ result.should be_empty
48
+ result.should be_an_instance_of Hash
49
+ end
50
+
51
+ it 'can be called __clear__ with name' do
52
+ @config.foo = 'foo'
53
+ @config.foo.should_not be_empty
54
+ @config.__clear__(:foo)
55
+ @config.foo.should be_empty
56
+ end
57
+
58
+ it 'can store any data' do
33
59
  [
34
60
  ['string', 'value' ],
35
61
  ['symbol', :value ],
@@ -44,14 +70,14 @@ module Termtter
44
70
  end
45
71
  end
46
72
 
47
- it 'should raise error when add by prohibited name' do
73
+ it 'can raise error when add by prohibited name' do
48
74
  lambda {
49
75
  @config.set_default('sub.aaa', :value)
50
76
  @config.sub.aaa
51
77
  }.should raise_error
52
78
  end
53
79
 
54
- it 'should raise error when add subb-storage to existed key' do
80
+ it 'can raise error when add subb-storage to existed key' do
55
81
  @config.subb = 'original value'
56
82
  lambda {
57
83
  @config.subb.key = 'invalid subbstitution'
@@ -61,7 +87,7 @@ module Termtter
61
87
  )
62
88
  end
63
89
 
64
- it 'should set intermediate defult configs' do
90
+ it 'can set intermediate defult configs' do
65
91
  @config.set_default 'subb.more', 'value'
66
92
  @config.subb.class.should == Config
67
93
  @config.subb.more.should == 'value'
@@ -70,31 +96,29 @@ module Termtter
70
96
  @config.proxy.port.should == 'value'
71
97
  end
72
98
 
73
- # FIXME: not work
99
+ # FIXME: Is this need spec?
74
100
  # it 'should have :undefined value in un-assigned key' do
75
101
  # @config.aaaa.should == :undefined
76
102
  # end
77
103
 
78
- it 'should be empty when something is assigned' do
79
- @config.empty?.should be_true
80
-
104
+ it 'can examin that storage is empty' do
105
+ @config.should be_empty
81
106
  @config.aaa = 1
82
- @config.empty?.should be_false
83
-
84
- @config.bbb.empty?.should be_true
107
+ @config.should_not be_empty
108
+ @config.bbb.should be_empty
85
109
  end
86
110
 
87
- it 'should be empty when assigned nil' do
111
+ it 'can examin that storage is not empty (nil)' do
88
112
  @config.bbb = nil
89
- @config.empty?.should be_false
113
+ @config.should_not be_empty
90
114
  end
91
115
 
92
- it 'should be empty when set_defaulted' do
116
+ it 'can examin that storage is not empty (default)' do
93
117
  @config.set_default('aaa', 1)
94
- @config.empty?.should be_false
118
+ @config.should_not be_empty
95
119
  end
96
120
 
97
- it 'should use in expression' do
121
+ it 'can use in expression' do
98
122
  @config.set_default(:ssb, 'hoge')
99
123
  lambda {
100
124
  res = @config.ssb + ' piyo'
@@ -102,20 +126,26 @@ module Termtter
102
126
  }.should_not raise_error
103
127
  end
104
128
 
105
- it 'should not change value when call set_default twice' do
129
+ it 'can not change value when call set_default twice' do
106
130
  @config.plugins.set_default :only, 'before_value'
107
131
  @config.plugins.set_default :only, 'after_value'
108
132
  @config.plugins.only.should == 'before_value'
109
133
  end
110
134
 
111
- it 'should be called set_default with int multiple times' do
112
- @config.set_default(:foo, 1)
113
- @config.set_default(:foo, 2)
135
+ it 'can be called set_default with int multiple times' do
136
+ lambda {
137
+ @config.set_default(:foo, 1)
138
+ @config.set_default(:foo, 2)
139
+ @config.foo.should == 1
140
+ }.should_not raise_error
114
141
  end
115
142
 
116
- it 'should be called set_default with string multiple times' do
117
- @config.set_default(:foo, 'foo')
118
- @config.set_default(:foo, 'bar')
143
+ it 'can be called set_default with string multiple times' do
144
+ lambda {
145
+ @config.set_default(:foo, 'foo')
146
+ @config.set_default(:foo, 'bar')
147
+ @config.foo.should == 'foo'
148
+ }.should_not raise_error
119
149
  end
120
150
  end
121
151
  end
@@ -62,6 +62,18 @@ module Termtter
62
62
  hook.match?(:'_bar_').should == false
63
63
  end
64
64
 
65
+ it 'should not match invalid point' do
66
+ hook = Hook.new(
67
+ :name => :spam,
68
+ :points => [1, { }, nil],
69
+ :exec_proc => lambda{|cmd, arg|
70
+ }
71
+ )
72
+ hook.match?(1).should == false
73
+ hook.match?({ }).should == false
74
+ hook.match?(nil).should == false
75
+ end
76
+
65
77
  it 'call hook proc' do
66
78
  proc_args = nil
67
79
  hook = Hook.new(
@@ -0,0 +1,53 @@
1
+ # -*- coding: utf-8 -*-
2
+ require File.dirname(__FILE__) + '/../spec_helper'
3
+
4
+ module Dummy
5
+ include Termtter::Hookable
6
+ end
7
+
8
+ module Termtter
9
+ describe Hookable do
10
+
11
+ it 'takes new_hook' do
12
+ hook = Hook.new(:name => :test)
13
+ Dummy.register_hook(hook)
14
+ Dummy.get_hook(:test).should == hook
15
+ end
16
+
17
+ it 'takes hook as Hash' do
18
+ Dummy.register_hook(:name => :test)
19
+ Dummy.get_hook(:test).name.should == :test
20
+ end
21
+
22
+ it 'calls new_hook' do
23
+ hook_called = false
24
+ Dummy.register_hook(:name => :test1, :points => [:point1], :exec_proc => lambda {hook_called = true})
25
+ hook_called.should == false
26
+ Dummy.call_hooks(:point1)
27
+ hook_called.should == true
28
+ end
29
+
30
+ it 'calls new_hook with args' do
31
+ arg1 = nil
32
+ arg2 = nil
33
+ Dummy.register_hook(:name => :test1, :points => [:point1], :exec_proc => lambda {|a1, a2| arg1 = a1; arg2 = a2})
34
+ arg1.should == nil
35
+ arg2.should == nil
36
+ Dummy.call_hooks(:point1, 'foo', 'bar')
37
+ arg1.should == 'foo'
38
+ arg2.should == 'bar'
39
+ end
40
+
41
+ it 'return hooks when call get_hooks' do
42
+ hook1 = Dummy.register_hook(:name => :test1, :points => [:point1])
43
+ hook2 = Dummy.register_hook(:name => :test2, :points => [:point1])
44
+ hook3 = Dummy.register_hook(:name => :test3, :points => [:point2])
45
+
46
+ hooks = Dummy.get_hooks(:point1)
47
+ hooks.size.should == 2
48
+ hooks.include?(hook1).should == true
49
+ hooks.include?(hook2).should == true
50
+ hooks.include?(hook3).should == false
51
+ end
52
+ end
53
+ end
@@ -1,16 +1,71 @@
1
1
  # -*- coding: utf-8 -*-
2
2
  require File.dirname(__FILE__) + '/../spec_helper'
3
3
 
4
- describe 'optparse' do
5
- def run_termtter(opt)
6
- `./run_termtter.rb #{opt}`
7
- end
4
+ module Termtter
5
+ describe OptParser do
8
6
 
9
- it 'accepts -h option' do
10
- run_termtter('-h').should match(/Usage/)
11
- end
7
+ before do
8
+ @original_conf ||= config
9
+ end
10
+
11
+ after do
12
+ conf = @original_conf
13
+ end
14
+
15
+ def run_termtter(opt)
16
+ `./run_termtter.rb #{opt}`
17
+ end
18
+
19
+ it 'accepts -h option' do
20
+ run_termtter('-h').should match(/Usage/)
21
+ end
22
+
23
+ it 'accepts -f option' do
24
+ Termtter::OptParser::parse!(%w{-f ~/config})
25
+ config.system.conf_file.should == '~/config'
26
+ end
27
+
28
+ it 'accepts -t option' do
29
+ Termtter::OptParser::parse!(%w{-t ~/termtter_directory})
30
+ config.system.conf_dir.should == '~/termtter_directory'
31
+ end
32
+
33
+ it 'accepts -d option' do
34
+ Termtter::OptParser::parse!(%w{-d})
35
+ config.devel.should be_true
36
+ end
37
+
38
+ it 'accepts -c option' do
39
+ Termtter::OptParser::parse!(%w{-c})
40
+ config.system.cmd_mode.should be_true
41
+ end
42
+
43
+ it 'accepts -r option' do
44
+ Termtter::OptParser::parse!(%w{-r cool})
45
+ config.system.run_commands.should == %w{cool}
46
+ end
47
+
48
+ it 'accepts -p option' do
49
+ Termtter::OptParser::parse!(%w{-p cool})
50
+ config.system.load_plugins.should == %w{cool}
51
+ end
52
+
53
+ it 'accepts -e option' do
54
+ Termtter::OptParser::parse!(%w{-e foo})
55
+ config.system.eval_scripts.should == %w{foo}
56
+ end
57
+
58
+ it 'accepts -m option' do
59
+ require 'termcolor'
60
+ TermColor.parse('<red>cool</red>').should == "\e[31mcool\e[0m"
61
+ Termtter::OptParser::parse!(%w{-m})
62
+ TermColor.parse('<red>cool</red>').should == 'cool'
63
+ module ::TermColor
64
+ class << self
65
+ alias parse parse_orig
66
+ end
67
+ end
68
+ end
12
69
 
13
- it 'accepts -m option' do
14
- pending
15
70
  end
16
71
  end
@@ -0,0 +1,42 @@
1
+ # -*- coding: utf-8 -*-
2
+ require File.dirname(__FILE__) + '/../spec_helper'
3
+
4
+ module Termtter
5
+ describe RubytterProxy do
6
+ before do
7
+ @rubytter_mock = Object.new
8
+ Rubytter.stub!(:new).and_return(@rubytter_mock)
9
+ @twitter = RubytterProxy.new('foo', 'bar', {})
10
+ end
11
+
12
+ it 'should call a Rubytter\'s method' do
13
+ @rubytter_mock.should_receive(:update).with('test').once
14
+ @twitter.update('test')
15
+ end
16
+
17
+ it 'should call a Rubytter\'s method with block' do
18
+ block = Proc.new{}
19
+ @rubytter_mock.should_receive(:update).with('test').once
20
+ @twitter.update('test')
21
+ end
22
+
23
+ it 'should call hooks' do
24
+ pre_hook = RubytterProxy.register_hook(:pre, :point => :pre_update) {}
25
+ pre_hook.should_receive(:call).with('test').and_return(["TEST"])
26
+ post_hook = RubytterProxy.register_hook(:post, :point => :post_update) {}
27
+ post_hook.should_receive(:call).with('test')
28
+ @rubytter_mock.should_receive(:update).with("TEST")
29
+
30
+ @twitter.update('test')
31
+ end
32
+
33
+ it 'should cancel to call method' do
34
+ pre_hook = RubytterProxy.register_hook(:pre, :point => :pre_update) {raise HookCanceled}
35
+ post_hook = RubytterProxy.register_hook(:post, :point => :post_update) {}
36
+ post_hook.should_receive(:call).with('test').never
37
+ @rubytter_mock.should_receive(:update).never
38
+
39
+ @twitter.update('test')
40
+ end
41
+ end
42
+ end
@@ -0,0 +1,9 @@
1
+ # -*- coding: utf-8 -*-
2
+
3
+ require File.dirname(__FILE__) + '/../../spec_helper'
4
+
5
+ describe 'Extensions for Windows' do
6
+
7
+ it 'needs spec'
8
+ end
9
+
@@ -0,0 +1,61 @@
1
+ # -*- coding: utf-8 -*-
2
+
3
+ require File.dirname(__FILE__) + '/../spec_helper'
4
+ require 'highline'
5
+
6
+ describe Termtter do
7
+
8
+ it 'provides create_highline' do
9
+ h = create_highline
10
+ h.class.should == HighLine
11
+ end
12
+
13
+ it 'provides win?' do
14
+ be_quiet do
15
+ original_ruby_platform = RUBY_PLATFORM
16
+ RUBY_PLATFORM = 'darwin'
17
+ win?.should == false
18
+ RUBY_PLATFORM = 'mswin'
19
+ win?.should == true
20
+ RUBY_PLATFORM = original_ruby_platform
21
+ end
22
+ end
23
+
24
+ it 'Readline can refresh line' do
25
+ Readline::LIBREADLINE.should_receive(:rl_refresh_line).with(0, 0)
26
+ Readline.refresh_line
27
+ end
28
+
29
+ it 'extend DL::Impoter when not be able to find DL::Importable' do
30
+ DL::Importer = mock(:importer)
31
+ DL.stub(:const_defined?).with(:Importable).and_return(false)
32
+ Readline::LIBREADLINE.should_receive(:extend).with(DL::Importer)
33
+ load 'termtter/system_extensions.rb'
34
+ end
35
+
36
+ it 'can handle error when difine LIBREADLINE' do
37
+ Readline::LIBREADLINE.stub(:extend) { raise }
38
+ load 'termtter/system_extensions.rb'
39
+ Readline::LIBREADLINE.should_not_receive(:rl_refresh_line)
40
+ Readline.refresh_line
41
+ end
42
+
43
+ it 'can open browser that suites platform' do
44
+ be_quiet(:stdout => false) do
45
+ url = 'example.com'
46
+ [
47
+ ['linux', 'firefox'],
48
+ ['mswin', 'explorer'],
49
+ ['mingw', 'explorer'],
50
+ ['bccwin', 'explorer'],
51
+ ['darwin', 'open'],
52
+ ['hogehog', 'open'],
53
+ ].each do |platform, browser|
54
+ RUBY_PLATFORM = platform
55
+ self.should_receive(:system).with(browser, url)
56
+ open_browser(url)
57
+ end
58
+ end
59
+ end
60
+ end
61
+
@@ -68,11 +68,69 @@ module Termtter
68
68
  @task_manager.instance_eval('@tasks').size.should == 1
69
69
  end
70
70
 
71
+ it 'should run (not pause)' do
72
+ be_quiet do
73
+ counter = 0
74
+ TaskManager::INTERVAL = 0
75
+ @task_manager.stub(:step) { counter += 1 }
76
+ @task_manager.instance_variable_set(:@work, true)
77
+ @task_manager.run
78
+ 100.times do
79
+ break if counter != 0
80
+ sleep 0.1
81
+ end
82
+ @task_manager.instance_variable_set(:@work, false)
83
+ counter.should > 0
84
+ end
85
+ end
86
+
87
+ it 'should run (pause)' do
88
+ be_quiet do
89
+ counter = 0
90
+ TaskManager::INTERVAL = 0.1
91
+ @task_manager.stub(:step) { counter += 1 }
92
+ @task_manager.instance_variable_set(:@work, true)
93
+ @task_manager.instance_variable_set(:@pause, true)
94
+ @task_manager.run
95
+ sleep 0.1
96
+ counter.should == 0
97
+ @task_manager.instance_variable_set(:@pause, false)
98
+ 100.times do
99
+ break if counter != 0
100
+ sleep 0.1
101
+ end
102
+ @task_manager.instance_variable_set(:@work, false)
103
+ counter.should > 0
104
+ end
105
+ end
106
+
71
107
  it 'should add task with :name' do
72
108
  @task_manager.add_task(:name => 'foo')
73
109
  @task_manager.get_task('foo').name.should == 'foo'
74
110
  @task_manager.delete_task('foo')
75
111
  @task_manager.get_task('foo').should == nil
76
112
  end
113
+
114
+ it 'should be killed' do
115
+ @task_manager.instance_eval('@work').should == true
116
+ @task_manager.kill
117
+ @task_manager.instance_eval('@work').should == false
118
+ end
119
+
120
+ it 'should be paused or resumed' do
121
+ @task_manager.instance_eval('@pause').should == false
122
+ @task_manager.pause
123
+ @task_manager.instance_eval('@pause').should == true
124
+ @task_manager.resume
125
+ @task_manager.instance_eval('@pause').should == false
126
+ end
127
+
128
+ it 'invoke_later calls invoke_and_wait' do
129
+ called = false
130
+ block = lambda { called = true}
131
+ @task_manager.should_receive(:invoke_and_wait).with(&block)
132
+ @task_manager.invoke_later &block
133
+ called.should be_true
134
+ end
77
135
  end
78
136
  end
@@ -26,3 +26,14 @@ describe Termtter, 'when plugin is called (with init option)' do
26
26
  config.plugins.aaa.bbb.should == :ccc
27
27
  end
28
28
  end
29
+
30
+ describe Termtter, 'when termtter is loaded' do
31
+ it 'will add load path' do
32
+ termtter_path = File.expand_path(File.dirname(__FILE__) + '/../lib/termtter.rb')
33
+ original_load_path = $:.dup
34
+ $:.clear
35
+ be_quiet { load termtter_path }
36
+ $:.include?(File.dirname(termtter_path)).should == true
37
+ $:.concat(original_load_path)
38
+ end
39
+ end