termtter 0.8.14 → 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (115) hide show
  1. data/README.rdoc +8 -8
  2. data/Rakefile +3 -5
  3. data/lib/{plugin → plugins}/april_fool.rb +0 -0
  4. data/lib/plugins/bomb.rb +42 -0
  5. data/lib/{plugin → plugins}/clear.rb +0 -0
  6. data/lib/{plugin → plugins}/confirm.rb +0 -0
  7. data/lib/{plugin → plugins}/cool.rb +0 -0
  8. data/lib/{plugin → plugins}/devel.rb +0 -0
  9. data/lib/{filter → plugins}/en2ja.rb +1 -1
  10. data/lib/plugins/english.rb +25 -0
  11. data/lib/{plugin → plugins}/erb.rb +0 -0
  12. data/lib/{filter → plugins}/expand-tinyurl.rb +6 -6
  13. data/lib/plugins/favorite.rb +63 -0
  14. data/lib/plugins/fib.rb +28 -0
  15. data/lib/{filter/fib.rb → plugins/fib_filter.rb} +1 -2
  16. data/lib/{plugin → plugins}/filter.rb +0 -0
  17. data/lib/{plugin → plugins}/graduatter.rb +1 -2
  18. data/lib/{plugin → plugins}/grass.rb +2 -2
  19. data/lib/{plugin → plugins}/group.rb +9 -9
  20. data/lib/{plugin → plugins}/growl.rb +11 -12
  21. data/lib/{plugin → plugins}/hatebu.rb +5 -5
  22. data/lib/{plugin → plugins}/history.rb +13 -13
  23. data/lib/plugins/ignore.rb +19 -0
  24. data/lib/plugins/keyword.rb +18 -0
  25. data/lib/{plugin → plugins}/log.rb +18 -12
  26. data/lib/{plugin → plugins}/me.rb +1 -2
  27. data/lib/{plugin → plugins}/modify_arg_hook_sample.rb +0 -0
  28. data/lib/{plugin → plugins}/msagent.rb +1 -1
  29. data/lib/plugins/multi_reply.rb +27 -0
  30. data/lib/{plugin → plugins}/notify-send.rb +1 -1
  31. data/lib/{plugin → plugins}/otsune.rb +0 -0
  32. data/lib/plugins/outputz.rb +33 -0
  33. data/lib/{plugin → plugins}/pause.rb +0 -0
  34. data/lib/{plugin → plugins}/plugin.rb +0 -0
  35. data/lib/{plugin → plugins}/post_exec_hook_sample.rb +0 -0
  36. data/lib/{plugin → plugins}/pre_exec_hook_sample.rb +0 -0
  37. data/lib/{plugin → plugins}/primes.rb +9 -2
  38. data/lib/plugins/quicklook.rb +41 -0
  39. data/lib/{plugin → plugins}/random.rb +0 -0
  40. data/lib/{plugin → plugins}/reblog.rb +3 -3
  41. data/lib/{plugin → plugins}/reload.rb +0 -0
  42. data/lib/{filter → plugins}/reply.rb +0 -0
  43. data/lib/{filter → plugins}/reverse.rb +1 -1
  44. data/lib/{plugin → plugins}/say.rb +1 -1
  45. data/lib/{plugin → plugins}/scrape.rb +4 -4
  46. data/lib/plugins/screen-notify.rb +13 -0
  47. data/lib/plugins/screen.rb +24 -0
  48. data/lib/{plugin → plugins}/shell.rb +0 -0
  49. data/lib/{plugin → plugins}/sl.rb +4 -4
  50. data/lib/plugins/spam.rb +13 -0
  51. data/lib/{plugin → plugins}/standard_plugins.rb +72 -18
  52. data/lib/plugins/stdout.rb +80 -0
  53. data/lib/plugins/storage/DB.rb +37 -0
  54. data/lib/plugins/storage/status.rb +48 -0
  55. data/lib/plugins/storage/status_mook.rb +30 -0
  56. data/lib/plugins/storage.rb +47 -0
  57. data/lib/plugins/system_status.rb +33 -0
  58. data/lib/{plugin → plugins}/translation.rb +15 -5
  59. data/lib/{plugin → plugins}/update_editor.rb +6 -6
  60. data/lib/plugins/uri-open.rb +64 -0
  61. data/lib/{filter → plugins}/url_addspace.rb +0 -0
  62. data/lib/{plugin → plugins}/wassr_post.rb +1 -1
  63. data/lib/{plugin → plugins}/yhara.rb +1 -1
  64. data/lib/plugins/yhara_filter.rb +8 -0
  65. data/lib/plugins/yonda.rb +21 -0
  66. data/lib/termtter/api.rb +28 -2
  67. data/lib/termtter/client.rb +91 -102
  68. data/lib/termtter/command.rb +32 -31
  69. data/lib/termtter/config.rb +64 -0
  70. data/lib/termtter/connection.rb +9 -7
  71. data/lib/termtter/hook.rb +11 -2
  72. data/lib/termtter/optparse.rb +14 -0
  73. data/lib/termtter/version.rb +1 -1
  74. data/lib/termtter.rb +19 -22
  75. data/spec/plugin/english_spec.rb +19 -0
  76. data/spec/plugin/favorite_spec.rb +10 -0
  77. data/spec/plugin/fib_spec.rb +1 -2
  78. data/spec/plugin/pause_spec.rb +8 -0
  79. data/spec/plugin/plugin_spec.rb +1 -1
  80. data/spec/plugin/primes_spec.rb +15 -0
  81. data/spec/plugin/sl_spec.rb +8 -0
  82. data/spec/plugin/spam_spec.rb +0 -13
  83. data/spec/plugin/standard_plugins_spec.rb +0 -7
  84. data/spec/plugin/storage/DB_spec.rb +12 -0
  85. data/spec/plugin/storage/status_spec.rb +24 -0
  86. data/spec/spec_helper.rb +3 -0
  87. data/spec/termtter/client_spec.rb +63 -1
  88. data/spec/termtter/command_spec.rb +6 -68
  89. data/spec/termtter/config_spec.rb +111 -0
  90. data/spec/termtter/hook_spec.rb +69 -0
  91. data/spec/termtter_spec.rb +22 -34
  92. metadata +82 -73
  93. data/lib/filter/english.rb +0 -8
  94. data/lib/filter/ignore.rb +0 -19
  95. data/lib/filter/yhara.rb +0 -20
  96. data/lib/plugin/bomb.rb +0 -29
  97. data/lib/plugin/english.rb +0 -59
  98. data/lib/plugin/favorite.rb +0 -75
  99. data/lib/plugin/fib.rb +0 -8
  100. data/lib/plugin/follow.rb +0 -60
  101. data/lib/plugin/keyword.rb +0 -18
  102. data/lib/plugin/multi_reply.rb +0 -36
  103. data/lib/plugin/outputz.rb +0 -35
  104. data/lib/plugin/quicklook.rb +0 -38
  105. data/lib/plugin/screen.rb +0 -24
  106. data/lib/plugin/spam.rb +0 -9
  107. data/lib/plugin/stdout.rb +0 -63
  108. data/lib/plugin/system_status.rb +0 -33
  109. data/lib/plugin/uri-open.rb +0 -69
  110. data/lib/plugin/yonda.rb +0 -20
  111. data/lib/termtter/status.rb +0 -26
  112. data/lib/termtter/twitter.rb +0 -188
  113. data/lib/termtter/user.rb +0 -13
  114. data/spec/termtter/user_spec.rb +0 -27
  115. data/test/test_termtter.rb +0 -86
@@ -1,7 +1,9 @@
1
1
  # -*- coding: utf-8 -*-
2
2
 
3
3
  module Termtter
4
+
4
5
  class Command
6
+
5
7
  attr_accessor :name, :aliases, :exec_proc, :completion_proc, :help
6
8
 
7
9
  # args
@@ -12,43 +14,33 @@ module Termtter
12
14
  # help: help text for the command (Optional)
13
15
  def initialize(args)
14
16
  raise ArgumentError, ":name is not given." unless args.has_key?(:name)
15
- @name = args[:name].to_sym
16
- @aliases = args[:aliases] ? args[:aliases].map {|i| i.to_sym } : []
17
- @exec_proc = args[:exec_proc] || lambda {|arg|}
18
- @completion_proc = args[:completion_proc] || lambda {|command, arg| [] }
19
- @help = args[:help]
17
+ cfg = {
18
+ :aliases => [],
19
+ :exec_proc => lambda {|arg| },
20
+ :comletion_proc => lambda {|command, arg| [] }
21
+ }.merge(args)
22
+
23
+ set cfg
20
24
  end
21
25
 
22
- def complement(input)
23
- command_info = match?(input)
24
- if command_info
25
- [completion_proc.call(command_info[0], command_info[1] || '')].flatten.compact
26
- else
27
- [name.to_s].grep(/^#{Regexp.quote(input)}/)
28
- end
26
+ def set(cfg)
27
+ @name = cfg[:name].to_sym
28
+ @aliases = cfg[:aliases].map {|e| e.to_sym }
29
+ @exec_proc = cfg[:exec_proc]
30
+ @completion_proc = cfg[:completion_proc]
31
+ @help = cfg[:help]
29
32
  end
30
33
 
31
- # MEMO: Termtter:Client からはこのメソッドを呼び出すことになると思う。
32
- def exec_if_match(input)
33
- command_info = match?(input)
34
- if command_info
35
- result = execute(command_info[1])
36
- unless result.nil?
37
- return result
34
+ def complement(input)
35
+ command_str, command_arg = match?(input)
36
+ if command_arg
37
+ if completion_proc
38
+ [completion_proc.call(command_str, command_arg || '')].flatten.compact
38
39
  else
39
- return true
40
+ []
40
41
  end
41
42
  else
42
- return nil
43
- end
44
- end
45
-
46
- # return array like [command, arg]
47
- def match?(input)
48
- if pattern =~ input
49
- [$2 || $3, $4] # $2 or $3 => command, $4 => argument
50
- else
51
- nil
43
+ [name.to_s, aliases.to_s].grep(/^#{Regexp.quote(input)}/)
52
44
  end
53
45
  end
54
46
 
@@ -64,8 +56,17 @@ module Termtter
64
56
  exec_proc.call(arg)
65
57
  end
66
58
 
59
+ # return array like [command, arg]
60
+ def match?(input)
61
+ if pattern =~ input
62
+ [$2 || $3, $4] # $2 or $3 => command, $4 => argument
63
+ else
64
+ [nil, nil]
65
+ end
66
+ end
67
+
67
68
  def pattern
68
- commands_regex = commands.map {|i| Regexp.quote(i.to_s) }.join('|')
69
+ commands_regex = commands.map {|name| Regexp.quote(name.to_s) }.join('|')
69
70
  /^((#{commands_regex})|(#{commands_regex})\s+(.*?))\s*$/
70
71
  end
71
72
 
@@ -0,0 +1,64 @@
1
+ # -*- coding: utf-8 -*-
2
+ #
3
+ module Termtter
4
+ class Config
5
+ def initialize
6
+ @store = Hash.new(:undefined)
7
+ end
8
+
9
+ def inspect
10
+ @store.inspect
11
+ end
12
+
13
+ # set_default :: (Symbol | String) -> a -> IO ()
14
+ def set_default(name, value)
15
+ match_p, init, last = *name.to_s.match(/^(.+)\.([^\.]+)$/)
16
+ if match_p
17
+ tmp = eval(init)
18
+ if tmp.__refer__(last.to_sym).empty?
19
+ tmp.__assign__(last.to_sym, value)
20
+ end
21
+ else
22
+ __assign__(name.to_sym, value) if __refer__(name.to_sym).empty?
23
+ end
24
+ end
25
+
26
+ # empty? :: Boolean
27
+ def empty?
28
+ @store.empty?
29
+ end
30
+
31
+ def method_missing(name, *args)
32
+ case name.to_s
33
+ when /(.*)=$/
34
+ __assign__($1.to_sym, args.first)
35
+ else
36
+ __refer__(name.to_sym)
37
+ end
38
+ end
39
+
40
+ # __assign__ :: Symbol -> a -> IO ()
41
+ def __assign__(name, value)
42
+ @store[name] = value
43
+ end
44
+
45
+ # __refer__ :: Symbol -> IO a
46
+ def __refer__(name)
47
+ @store[name] == :undefined ? @store[name] = Termtter::Config.new : @store[name]
48
+ end
49
+
50
+ __instance = self.new
51
+ (class << self; self end).
52
+ __send__(:define_method, :instance) { __instance }
53
+ end
54
+ end
55
+
56
+ def config
57
+ Termtter::Config.instance
58
+ end
59
+
60
+ def configatron
61
+ # remove this method until Termtter-1.2.0
62
+ warn "configatron method will be removed. Use config instead. (#{caller.first})"
63
+ Termtter::Config.instance
64
+ end
@@ -5,16 +5,18 @@ module Termtter
5
5
  attr_reader :protocol, :port, :proxy_uri
6
6
 
7
7
  def initialize
8
- @proxy_host = configatron.proxy.host
9
- @proxy_port = configatron.proxy.port
10
- @proxy_user = configatron.proxy.user_name
11
- @proxy_password = configatron.proxy.password
12
- @proxy_uri = nil
13
- @enable_ssl = configatron.enable_ssl
8
+ unless config.proxy.empty?
9
+ @proxy_host = config.proxy.host
10
+ @proxy_port = config.proxy.port
11
+ @proxy_user = config.proxy.user_name
12
+ @proxy_password = config.proxy.password
13
+ @proxy_uri = nil
14
+ @enable_ssl = config.enable_ssl
15
+ end
14
16
  @protocol = "http"
15
17
  @port = 80
16
18
 
17
- unless @proxy_host.empty?
19
+ if @proxy_host
18
20
  @http_class = Net::HTTP::Proxy(@proxy_host, @proxy_port,
19
21
  @proxy_user, @proxy_password)
20
22
  @proxy_uri = "http://" + @proxy_host + ":" + @proxy_port + "/"
data/lib/termtter/hook.rb CHANGED
@@ -7,12 +7,21 @@ module Termtter
7
7
  def initialize(args)
8
8
  raise ArgumentError, ":name is not given." unless args.has_key?(:name)
9
9
  @name = args[:name].to_sym
10
- @points = args[:points] ? args[:points].map {|i| i.to_sym } : []
10
+ @points = args[:points] ? args[:points].map {|i| i } : []
11
11
  @exec_proc = args[:exec_proc] || lambda {}
12
12
  end
13
13
 
14
14
  def match?(point)
15
- points.include?(point.to_sym)
15
+ !points.select{|pt|
16
+ case pt
17
+ when String, Symbol
18
+ pt.to_s == point.to_s
19
+ when Regexp
20
+ (pt =~ point.to_s) ? true : false
21
+ else
22
+ false
23
+ end
24
+ }.empty?
16
25
  end
17
26
  end
18
27
  end
@@ -0,0 +1,14 @@
1
+ OptionParser.new { |opt|
2
+ opt.on('-f', '--file config_file', 'Set path to configfile') do |val|
3
+ config.system.__assign__(:conf_file, val)
4
+ end
5
+ opt.on('-t', '--termtter-directory directory', 'Set termtter directory') do |val|
6
+ config.system.__assign__(:conf_dir, val)
7
+ end
8
+ opt.on('-d', '--devel', 'Start in developer mode') do |flg|
9
+ config.system.__assign__(:devel, true) if flg
10
+ end
11
+
12
+ Version = Termtter::VERSION
13
+ opt.parse!(ARGV)
14
+ }
@@ -1,4 +1,4 @@
1
1
  # -*- coding: utf-8 -*-
2
2
  module Termtter
3
- VERSION = '0.8.14'
3
+ VERSION = '1.0.0'
4
4
  end
data/lib/termtter.rb CHANGED
@@ -12,12 +12,12 @@ require 'open-uri'
12
12
  require 'cgi'
13
13
  require 'readline'
14
14
  require 'enumerator'
15
- require 'configatron'
15
+ require 'optparse'
16
16
 
17
- require 'termtter/twitter'
17
+ require 'termtter/config'
18
+ require 'termtter/version'
19
+ require 'termtter/optparse'
18
20
  require 'termtter/connection'
19
- require 'termtter/status'
20
- require 'termtter/user'
21
21
  require 'termtter/command'
22
22
  require 'termtter/hook'
23
23
  require 'termtter/task'
@@ -25,12 +25,15 @@ require 'termtter/task_manager'
25
25
  require 'termtter/client'
26
26
  require 'termtter/api'
27
27
  require 'termtter/system_extensions'
28
- require 'termtter/version'
29
28
 
30
29
  module Termtter
31
30
  APP_NAME = 'termtter'
32
- CONF_FILE = '~/.termtterrc' # still does not use
33
- CONF_DIR = '~/.termtter' # still does not use
31
+
32
+ config.system.set_default :conf_dir, File.expand_path('~/.termtter')
33
+ CONF_DIR = config.system.conf_dir
34
+
35
+ config.system.set_default :conf_file, CONF_DIR + '/config'
36
+ CONF_FILE = config.system.conf_file
34
37
  end
35
38
 
36
39
  if RUBY_VERSION < '1.8.7'
@@ -39,26 +42,20 @@ if RUBY_VERSION < '1.8.7'
39
42
  end
40
43
  end
41
44
 
42
- def plugin(s, init = {})
45
+ def plugin(name, init = {})
43
46
  unless init.empty?
44
47
  init.each do |key, value|
45
- eval("configatron.plugins.#{s}").__send__("#{key}=", value)
48
+ config.plugins.__refer__(name.to_sym).__assign__(key.to_sym, value)
46
49
  end
47
50
  end
48
- require "plugin/#{s}"
49
- rescue => e
50
- Termtter::Client.handle_error(e)
51
- end
52
-
53
- def filter(s)
54
- load "filter/#{s}.rb"
55
- rescue => e
51
+ # FIXME: below path should be replaced by optparsed path
52
+ if File.exist?(path = File.expand_path("~/.termtter/plugins/#{name}"))
53
+ require path
54
+ else
55
+ require "plugins/#{name}"
56
+ end
57
+ rescue LoadError => e
56
58
  Termtter::Client.handle_error(e)
57
- else
58
- Termtter::Client.public_storage[:filters] ||= []
59
- Termtter::Client.public_storage[:filters] << s
60
- true
61
59
  end
62
60
 
63
61
  $:.unshift(Termtter::CONF_DIR) # still does not use
64
-
@@ -0,0 +1,19 @@
1
+ # -*- coding: utf-8 -*-
2
+ # vim: set fenc=utf-8
3
+ require File.dirname(__FILE__) + '/../spec_helper'
4
+
5
+ describe Termtter do
6
+ it 'english? method' do
7
+ Termtter::Client.should_receive(:add_filter)
8
+ plugin 'english'
9
+ Termtter::English.english?('This is a pen.').should be_true
10
+ Termtter::English.english?('これはペンです.').should be_false
11
+ Termtter::English.english?('これはpenです.').should be_false
12
+ end
13
+
14
+ it 'apply filter english only update_friends_timeline'
15
+ # NOTE: when below code is evaluated,
16
+ # plugin 'english', :only => [:update_friends_timeline]
17
+ # in update_friends_timeline there are English posts only but in replies there are both Japanese posts and English posts.
18
+ # It's too difficult for me to write that spec, so this spec is pending now. Please write this spec, hey, you, a cool hacker!
19
+ end
@@ -0,0 +1,10 @@
1
+ # -*- coding: utf-8 -*-
2
+
3
+ require File.dirname(__FILE__) + '/../spec_helper'
4
+
5
+ describe Termtter::Client, 'when the plugin favorite is loaded' do
6
+ it 'should add command favorite' do
7
+ Termtter::Client.should_receive(:register_command).once
8
+ plugin 'favorite'
9
+ end
10
+ end
@@ -4,8 +4,7 @@ require File.dirname(__FILE__) + '/../spec_helper'
4
4
 
5
5
  describe Termtter::Client, 'when the plugin fib is loaded' do
6
6
  it 'should add command fib' do
7
- Termtter::Client.should_receive(:add_command).with(/^fib\s+(\d+)/)
8
- Termtter::Client.should_receive(:add_command).with(/^fibyou\s(\w+)\s(\d+)/)
7
+ Termtter::Client.should_receive(:register_command).twice
9
8
  plugin 'fib'
10
9
  end
11
10
 
@@ -0,0 +1,8 @@
1
+ # -*- coding: utf-8 -*-
2
+ require File.dirname(__FILE__) + '/../spec_helper'
3
+ describe Termtter do
4
+ it 'pause plugin' do
5
+ Termtter::Client.should_receive(:pause)
6
+ plugin 'pause'
7
+ end
8
+ end
@@ -1,6 +1,6 @@
1
1
  # -*- coding: utf-8 -*-
2
2
 
3
- require File.dirname(__FILE__) + '/../../lib/termtter'
3
+ require File.dirname(__FILE__) + '/../spec_helper'
4
4
 
5
5
  module Termtter
6
6
  describe Client, 'when the plugin plugin is loaded' do
@@ -0,0 +1,15 @@
1
+ # -*- coding: utf-8 -*-
2
+
3
+ require File.dirname(__FILE__) + '/../spec_helper'
4
+
5
+ describe Termtter::Client, 'when the plugin primes is loaded' do
6
+ it 'should add command primes' do
7
+ Termtter::Client.should_receive(:register_command).once
8
+ plugin 'primes'
9
+ end
10
+
11
+ it 'should define primes method' do
12
+ plugin 'primes'
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
+ end
15
+ end
@@ -0,0 +1,8 @@
1
+ # -*- coding: utf-8 -*-
2
+ require File.dirname(__FILE__) + '/../spec_helper'
3
+ describe Termtter do
4
+ it 'plugin sl' do
5
+ Termtter::Client.should_receive(:register_command).exactly(4).times
6
+ plugin 'sl'
7
+ end
8
+ end
@@ -2,16 +2,3 @@
2
2
 
3
3
  require File.dirname(__FILE__) + '/../spec_helper'
4
4
 
5
- describe Termtter::Client, 'when the plugin spam is loaded' do
6
- it 'should add command spam and post immediately' do
7
- connection = mock('connection', :null_object => true)
8
- t = Termtter::Twitter.new('a', 'b', connection)
9
- Termtter::Twitter.should_receive(:new).and_return(t)
10
- t.should_receive(:update_status).with('*super spam time*')
11
-
12
- Termtter::Client.should_receive(:clear_commands)
13
- Termtter::Client.should_receive(:add_command).with(/.+/)
14
- plugin 'spam'
15
- end
16
- end
17
-
@@ -19,13 +19,6 @@ module Termtter
19
19
  command.aliases.should == aliases
20
20
  end
21
21
  end
22
-
23
- it 'should return candidates when call find_status_id_candidates' do
24
- Client.public_storage[:status_ids] = %w[1 2 22 3 4 5]
25
- Client.find_status_id_candidates("1", "%s").should == ["1"]
26
- Client.find_status_id_candidates("2", "%s").should == ["2", "22"]
27
- #TODO: more spec for like "jugyo:1113830"
28
- end
29
22
  end
30
23
  end
31
24
 
@@ -0,0 +1,12 @@
1
+ # -*- coding: utf-8 -*-
2
+
3
+ require File.dirname(__FILE__) + '/../../spec_helper'
4
+ require File.dirname(__FILE__) + '/../../../lib/plugins/storage/DB'
5
+
6
+ module Termtter::Storage
7
+ describe DB do
8
+ before do
9
+ @db = DB.instance.db
10
+ end
11
+ end
12
+ end
@@ -0,0 +1,24 @@
1
+ # -*- coding: utf-8 -*-
2
+
3
+ require File.dirname(__FILE__) + '/../../spec_helper'
4
+ require File.dirname(__FILE__) + '/../../../lib/plugins/storage/status'
5
+
6
+ module Termtter::Storage
7
+ describe Status do
8
+ before do
9
+ @status = Status.new
10
+ end
11
+ end
12
+
13
+ describe Status do
14
+ it 'self.insert should not return false' do
15
+ Status.insert(
16
+ :post_id => 1,
17
+ :created_at => 12345,
18
+ :in_reply_to_status_id => -1,
19
+ :in_reply_to_user_id => -1,
20
+ :post_text => 'bomb',
21
+ :user_id => 1).should_not be_false
22
+ end
23
+ end
24
+ end
data/spec/spec_helper.rb CHANGED
@@ -1,4 +1,7 @@
1
1
  # -*- coding: utf-8 -*-
2
2
 
3
3
  $:.unshift(File.dirname(__FILE__) + '/../lib')
4
+ ARGV.delete '-c'
4
5
  require 'termtter'
6
+
7
+
@@ -142,6 +142,7 @@ module Termtter
142
142
  )
143
143
 
144
144
  hook_called.should == false
145
+ Client.should_receive(:puts)
145
146
  Client.exit
146
147
  hook_called.should == true
147
148
  end
@@ -154,12 +155,13 @@ module Termtter
154
155
 
155
156
  hook1_called.should == false
156
157
  hook2_called.should == false
158
+ Client.should_receive(:puts)
157
159
  Client.exit
158
160
  hook1_called.should == true
159
161
  hook2_called.should == true
160
162
  end
161
163
 
162
- it 'should able to override hooks' do
164
+ it 'should be able to override hooks' do
163
165
  hook1_called = false
164
166
  hook2_called = false
165
167
  Client.register_hook(:name => :hook, :points => [:exit], :exec_proc => lambda {hook1_called = true})
@@ -167,9 +169,69 @@ module Termtter
167
169
 
168
170
  hook1_called.should == false
169
171
  hook2_called.should == false
172
+ Client.should_receive(:puts)
170
173
  Client.exit
171
174
  hook1_called.should == false
172
175
  hook2_called.should == true
173
176
  end
177
+
178
+ it 'run' do
179
+ Client.should_receive(:puts)
180
+ Client.should_receive(:load_default_plugins)
181
+ Client.should_receive(:load_config)
182
+ Termtter::API.should_receive(:setup)
183
+ Client.should_receive(:pre_config_load)
184
+ Client.should_receive(:call_hooks)
185
+ Client.should_receive(:call_new_hooks)
186
+ Client.should_receive(:setup_update_timeline_task)
187
+ Client.should_receive(:call_commands)
188
+ Client.should_receive(:start_input_thread)
189
+ Client.run
190
+ end
191
+
192
+ it 'load_config'
193
+
194
+ it 'should do nothing when ~/.termtter is directory' do
195
+ File.should_receive(:ftype).and_return('directory')
196
+ Client.should_not_receive(:move_legacy_config_file)
197
+ Client.legacy_config_support
198
+ end
199
+
200
+ it 'should do "move_legacy_config_file" when ~/.termtter is file' do
201
+ File.should_receive(:ftype).and_return('file')
202
+ Client.should_receive(:move_legacy_config_file)
203
+ Client.legacy_config_support
204
+ end
205
+
206
+ it 'should move legacy config file' do
207
+ FileUtils.should_receive(:mv).twice
208
+ Dir.should_receive(:mkdir)
209
+ Client.move_legacy_config_file
210
+ end
211
+
212
+ it 'should handle error' do
213
+ $stderr, old = StringIO.new, $stderr
214
+ Client.handle_error StandardError.new('error')
215
+ $stderr.string.should == "[ERROR] Something wrong: error\n"
216
+ $stderr = old
217
+ end
218
+
219
+ it 'should handle Rubytte::APIError' do
220
+ $stderr, old = StringIO.new, $stderr
221
+ class Rubytter::APIError < StandardError; end
222
+ [
223
+ ['401', "[ERROR] Unauthorized: maybe you tried to show protected user status\n"],
224
+ ['403', "[ERROR] Access denied: maybe that user is protected\n"],
225
+ ['404', "[ERROR] Not found: maybe there is no such user\n"],
226
+ ].each do |code, message|
227
+ res = mock('res', :code => code)
228
+ excep = Rubytter::APIError.new('error')
229
+ excep.should_receive(:response).and_return(res)
230
+ Client.handle_error excep
231
+ $stderr.string.should == message
232
+ $stderr.string = ''
233
+ end
234
+ $stderr = old
235
+ end
174
236
  end
175
237
  end