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.
Files changed (81) hide show
  1. data/ChangeLog +115 -0
  2. data/README.rdoc +25 -10
  3. data/Rakefile +53 -34
  4. data/lib/plugins/cool.rb +2 -5
  5. data/lib/plugins/curry.rb +43 -0
  6. data/lib/plugins/db.rb +91 -0
  7. data/lib/plugins/{auto_reload.rb → defaults/auto_reload.rb} +5 -1
  8. data/lib/plugins/defaults/command_line.rb +111 -0
  9. data/lib/plugins/{exec.rb → defaults/exec.rb} +2 -7
  10. data/lib/plugins/{fib.rb → defaults/fib.rb} +1 -4
  11. data/lib/plugins/defaults/retweet.rb +34 -0
  12. data/lib/plugins/{standard_commands.rb → defaults/standard_commands.rb} +88 -162
  13. data/lib/plugins/defaults/standard_completion.rb +67 -0
  14. data/lib/plugins/defaults/stdout.rb +148 -0
  15. data/lib/plugins/defaults.rb +14 -0
  16. data/lib/plugins/en2ja.rb +11 -5
  17. data/lib/plugins/english.rb +2 -2
  18. data/lib/plugins/expand-tinyurl.rb +27 -6
  19. data/lib/plugins/github-issues.rb +192 -0
  20. data/lib/plugins/group.rb +30 -4
  21. data/lib/plugins/growl.rb +10 -1
  22. data/lib/plugins/http_server/favicon.ico +0 -0
  23. data/lib/plugins/http_server/index.html +117 -0
  24. data/lib/plugins/http_server.rb +82 -0
  25. data/lib/plugins/irb.rb +6 -0
  26. data/lib/plugins/l2.rb +1 -1
  27. data/lib/plugins/list_with_opts.rb +0 -3
  28. data/lib/plugins/log.rb +6 -9
  29. data/lib/plugins/modify_arg_hook_sample.rb +3 -5
  30. data/lib/plugins/multi_reply.rb +0 -5
  31. data/lib/plugins/notify-send.rb +1 -1
  32. data/lib/plugins/notify-send2.rb +1 -1
  33. data/lib/plugins/notify-send3.rb +11 -3
  34. data/lib/plugins/open_url.rb +5 -17
  35. data/lib/plugins/otsune.rb +3 -9
  36. data/lib/plugins/outputz.rb +1 -1
  37. data/lib/plugins/pool.rb +30 -0
  38. data/lib/plugins/protected_filter.rb +9 -0
  39. data/lib/plugins/quicklook.rb +1 -1
  40. data/lib/plugins/saykanji.rb +81 -0
  41. data/lib/plugins/shell.rb +1 -6
  42. data/lib/plugins/sl.rb +8 -8
  43. data/lib/plugins/tinyurl.rb +26 -7
  44. data/lib/plugins/trends.rb +84 -0
  45. data/lib/plugins/twitpic.rb +46 -0
  46. data/lib/plugins/uri-open.rb +33 -28
  47. data/lib/plugins/wassr.rb +0 -3
  48. data/lib/plugins/whois.rb +45 -0
  49. data/lib/plugins/yhara.rb +2 -6
  50. data/lib/termtter/client.rb +91 -103
  51. data/lib/termtter/command.rb +24 -9
  52. data/lib/termtter/config.rb +8 -6
  53. data/lib/termtter/config_setup.rb +1 -1
  54. data/lib/termtter/config_template.erb +1 -4
  55. data/lib/termtter/hook.rb +2 -2
  56. data/lib/termtter/optparse.rb +14 -1
  57. data/lib/termtter/system_extensions.rb +3 -2
  58. data/lib/termtter/task_manager.rb +1 -5
  59. data/lib/termtter/version.rb +1 -1
  60. data/spec/plugins/cool_spec.rb +1 -1
  61. data/spec/plugins/curry_spec.rb +13 -0
  62. data/spec/plugins/db_spec.rb +62 -0
  63. data/spec/plugins/english_spec.rb +2 -2
  64. data/spec/plugins/fib_spec.rb +2 -2
  65. data/spec/plugins/filter_spec.rb +2 -2
  66. data/spec/plugins/pause_spec.rb +1 -1
  67. data/spec/plugins/primes_spec.rb +2 -2
  68. data/spec/plugins/shell_spec.rb +1 -1
  69. data/spec/plugins/sl_spec.rb +1 -1
  70. data/spec/plugins/{standard_plugins_spec.rb → standard_commands_spec.rb} +2 -2
  71. data/spec/plugins/whois_spec.rb +20 -0
  72. data/spec/termtter/client_spec.rb +151 -33
  73. data/spec/termtter/command_spec.rb +68 -35
  74. data/spec/termtter/config_spec.rb +10 -0
  75. data/spec/termtter/optparse_spec.rb +16 -0
  76. data/spec/termtter_spec.rb +7 -8
  77. metadata +48 -19
  78. data/History.txt +0 -4
  79. data/lib/plugins/direct_messages.rb +0 -36
  80. data/lib/plugins/retweet.rb +0 -46
  81. data/lib/plugins/stdout.rb +0 -77
@@ -14,7 +14,6 @@ module Termtter
14
14
  @commands = {}
15
15
  @filters = []
16
16
  @since_id = nil
17
- @input_thread = nil
18
17
  @task_manager = Termtter::TaskManager.new
19
18
 
20
19
  config.set_default(:logger, nil)
@@ -28,11 +27,14 @@ module Termtter
28
27
 
29
28
  attr_reader :commands, :hooks
30
29
 
30
+ # plug :: Name -> (Hash) -> IO () where NAME = String | Symbol | [NAME]
31
31
  def plug(name, options = {})
32
- unless options.empty?
33
- options.each do |key, value|
34
- config.plugins.__refer__(name.to_sym).__assign__(key.to_sym, value)
35
- end
32
+ if Array === name # Obviously `name.respond_to?(:each)` is better, but for 1.8.6 compatibility we cannot.
33
+ name.each {|i| plug(i, options) }
34
+ return
35
+ end
36
+ options.each do |key, value|
37
+ config.plugins.__refer__(name.gsub(/-/, '_').to_sym).__assign__(key.to_sym, value)
36
38
  end
37
39
  load "plugins/#{name}.rb"
38
40
  rescue Exception => e
@@ -52,14 +54,19 @@ module Termtter
52
54
  @filters.clear
53
55
  end
54
56
 
55
- def register_hook(arg)
57
+ def register_hook(arg, opts = {}, &block)
56
58
  hook = case arg
57
59
  when Hook
58
60
  arg
59
61
  when Hash
60
62
  Hook.new(arg)
63
+ when String, Symbol
64
+ options = { :name => arg }
65
+ options.merge!(opts)
66
+ options[:exec_proc] = block
67
+ Hook.new(options)
61
68
  else
62
- raise ArgumentError, 'must be given Termtter::Hook or Hash'
69
+ raise ArgumentError, 'must be given Termtter::Hook, Hash, String or Symbol'
63
70
  end
64
71
  @hooks[hook.name] = hook
65
72
  end
@@ -69,23 +76,39 @@ module Termtter
69
76
  end
70
77
 
71
78
  def get_hooks(point)
79
+ # TODO: sort by alphabet
72
80
  @hooks.values.select do |hook|
73
81
  hook.match?(point)
74
82
  end
75
83
  end
76
84
 
77
- def register_command(arg)
85
+ def register_command(arg, opts = {}, &block)
78
86
  command = case arg
79
87
  when Command
80
88
  arg
81
89
  when Hash
82
90
  Command.new(arg)
91
+ when String, Symbol
92
+ options = { :name => arg }
93
+ options.merge!(opts)
94
+ options[:exec_proc] = block
95
+ Command.new(options)
83
96
  else
84
- raise ArgumentError, 'must be given Termtter::Command or Hash'
97
+ raise ArgumentError, 'must be given Termtter::Command, Hash or String(Symbol) with block'
85
98
  end
86
99
  @commands[command.name] = command
87
100
  end
88
101
 
102
+ def add_command(name)
103
+ if block_given?
104
+ command = Command.new(:name => name)
105
+ yield command
106
+ @commands[command.name] = command
107
+ else
108
+ raise ArgumentError, 'must be given block to set parameters'
109
+ end
110
+ end
111
+
89
112
  def clear_command
90
113
  @commands.clear
91
114
  end
@@ -117,14 +140,14 @@ module Termtter
117
140
  def output(statuses, event)
118
141
  return if statuses.nil? || statuses.empty?
119
142
 
120
- statuses = statuses.sort_by{|s|s.id}
143
+ statuses = statuses.sort_by(&:id)
121
144
  call_hooks(:pre_filter, statuses, event)
122
145
 
123
- filtered = statuses.map(&:dup)
146
+ filtered = apply_filters_for_hook(:filter_for_output, statuses.map(&:dup), event)
147
+
124
148
  @filters.each do |f| # TODO: code for compatibility. delete someday.
125
- statuses = f.call(statuses, event)
149
+ filtered = f.call(filtered, event)
126
150
  end
127
- apply_filters_for_hook(:filter_for_output, statuses, event)
128
151
 
129
152
  call_hooks(:post_filter, filtered, event)
130
153
  get_hooks(:output).each do |hook|
@@ -136,10 +159,9 @@ module Termtter
136
159
  end
137
160
 
138
161
  def apply_filters_for_hook(hook_name, statuses, event)
139
- get_hooks(hook_name).each do |hook|
140
- statuses = hook.call(statuses, event)
141
- end
142
- statuses
162
+ get_hooks(hook_name).inject(statuses) {|s, hook|
163
+ hook.call(s, event)
164
+ }
143
165
  end
144
166
 
145
167
  # return last hook return value
@@ -153,36 +175,41 @@ module Termtter
153
175
  end
154
176
 
155
177
  def call_commands(text)
156
- return if text.empty?
157
-
158
- commands = find_commands(text)
159
- raise CommandNotFound, text if commands.empty?
160
-
161
- commands.each do |command|
162
- command_found = true
163
- command_str, command_arg = Command.split_command_line(text)
164
-
165
- modified_arg = call_hooks(
166
- "modify_arg_for_#{command.name.to_s}",
167
- command_str,
168
- command_arg) || command_arg || ''
178
+ @task_manager.invoke_and_wait do
179
+ call_hooks("pre_command", text)
180
+ # FIXME: This block can become Maybe Monad
181
+ get_hooks("pre_command").each {|hook|
182
+ break if text == nil # interrupt if hook returns nil
183
+ text = hook.call(text)
184
+ }
185
+ return if text.empty?
186
+
187
+ commands = find_commands(text)
188
+ raise CommandNotFound, text if commands.empty?
189
+
190
+ commands.each do |command|
191
+ command_str, command_arg = Command.split_command_line(text)
192
+
193
+ modified_arg = command_arg
194
+ # FIXME: This block can become Maybe Monad
195
+ get_hooks("modify_arg_for_#{command.name.to_s}").each {|hook|
196
+ break if modified_arg == false # interrupt if hook return false
197
+ modified_arg = hook.call(command_str, modified_arg)
198
+ }
169
199
 
170
- @task_manager.invoke_and_wait do
171
200
  begin
172
201
  call_hooks("pre_exec_#{command.name.to_s}", command, modified_arg)
173
- # exec command
174
- result = command.call(command_str, modified_arg, text)
175
- if result
176
- call_hooks("post_exec_#{command.name.to_s}", command_str, modified_arg, result)
177
- end
202
+ result = command.call(command_str, modified_arg, text) # exec command
203
+ call_hooks("post_exec_#{command.name.to_s}", command_str, modified_arg, result)
178
204
  rescue CommandCanceled
179
205
  end
180
206
  end
207
+ call_hooks("post_command", text)
181
208
  end
182
209
  end
183
210
 
184
211
  def find_commands(text)
185
- @commands.values.select { |command| command.match?(text) }
212
+ @commands.values.select {|command| command.match?(text) }
186
213
  end
187
214
 
188
215
  def pause
@@ -199,10 +226,8 @@ module Termtter
199
226
 
200
227
  def exit
201
228
  puts 'finalizing...'
202
-
203
229
  call_hooks(:exit)
204
230
  @task_manager.kill
205
- @input_thread.kill if @input_thread
206
231
  end
207
232
 
208
233
  def load_config
@@ -233,56 +258,6 @@ module Termtter
233
258
  Termtter::CONF_FILE)
234
259
  end
235
260
 
236
- def setup_readline
237
- if Readline.respond_to?(:basic_word_break_characters=)
238
- Readline.basic_word_break_characters= "\t\n\"\\'`><=;|&{("
239
- end
240
- Readline.completion_proc = lambda {|input|
241
- begin
242
- @commands.map {|name, command| command.complement(input) }.flatten.compact
243
- rescue => e
244
- handle_error(e)
245
- end
246
- }
247
- vi_or_emacs = config.editing_mode
248
- unless vi_or_emacs.empty?
249
- Readline.__send__("#{vi_or_emacs}_editing_mode")
250
- end
251
- end
252
-
253
- def trap_setting()
254
- begin
255
- stty_save = `stty -g`.chomp
256
- trap("INT") do
257
- begin
258
- system "stty", stty_save
259
- ensure
260
- exit
261
- end
262
- end
263
- rescue Errno::ENOENT
264
- end
265
- end
266
-
267
- def start_input_thread
268
- setup_readline()
269
- trap_setting()
270
- @input_thread = Thread.new do
271
- while buf = Readline.readline(ERB.new(config.prompt).result(API.twitter.__send__(:binding)), true)
272
- Readline::HISTORY.pop if buf.empty?
273
- begin
274
- call_commands(buf)
275
- rescue CommandNotFound => e
276
- warn "Unknown command \"#{e}\""
277
- warn 'Enter "help" for instructions'
278
- rescue => e
279
- handle_error e
280
- end
281
- end
282
- end
283
- @input_thread.join
284
- end
285
-
286
261
  def logger
287
262
  @logger
288
263
  end
@@ -293,7 +268,7 @@ module Termtter
293
268
 
294
269
  def default_logger
295
270
  logger = Logger.new(STDOUT)
296
- logger.formatter = lambda { |severity, time, progname, message|
271
+ logger.formatter = lambda {|severity, time, progname, message|
297
272
  color =
298
273
  case severity
299
274
  when /^DEBUG/
@@ -325,17 +300,9 @@ module Termtter
325
300
 
326
301
  @init_block.call(self) if @init_block
327
302
 
328
- unless @init_block # compatibility for old style config file
329
- plug 'stdout'
330
- plug 'standard_commands'
331
- plug 'auto_reload'
332
- end
333
-
303
+ plug 'defaults'
334
304
  plug 'devel' if config.devel
335
-
336
- config.system.load_plugins.each do |plugin|
337
- plug plugin
338
- end
305
+ plug config.system.load_plugins
339
306
 
340
307
  config.system.eval_scripts.each do |script|
341
308
  begin
@@ -345,12 +312,12 @@ module Termtter
345
312
  end
346
313
  end
347
314
 
348
- config.system.run_commands.each { |cmd| call_commands(cmd) }
315
+ config.system.run_commands.each {|cmd| call_commands(cmd) }
349
316
 
350
317
  unless config.system.cmd_mode
351
- call_hooks(:initialize)
352
318
  @task_manager.run()
353
- start_input_thread()
319
+ call_hooks(:initialize)
320
+ call_hooks(:launched)
354
321
  end
355
322
  end
356
323
 
@@ -366,6 +333,27 @@ module Termtter
366
333
  puts "Error: #{e}"
367
334
  puts e.backtrace.join("\n")
368
335
  end
336
+
337
+ def confirm(message, default_yes = true, &block)
338
+ pause # TODO: TaskManager から呼ばれるならこれいらないなぁ
339
+
340
+ result = # Boolean in duck typing
341
+ if default_yes
342
+ prompt = "\"#{message}".strip + "\" [Y/n] "
343
+ /^y?$/i =~ Readline.readline(prompt, false)
344
+ else
345
+ prompt = "\"#{message}".strip + "\" [N/y] "
346
+ /^n?$/i =~ Readline.readline(prompt, false)
347
+ end
348
+
349
+ if result && block
350
+ block.call
351
+ end
352
+
353
+ result
354
+ ensure
355
+ resume # TODO: TaskManager から呼ばれるならこれいらないなぁ
356
+ end
369
357
  end
370
358
  end
371
359
  end
@@ -1,19 +1,18 @@
1
1
  # -*- coding: utf-8 -*-
2
2
 
3
3
  module Termtter
4
-
5
4
  class Command
6
-
7
5
  attr_accessor :name, :aliases, :exec_proc, :completion_proc, :help
8
6
 
9
7
  # args
10
- # name: Symbol as command name
8
+ # name: (required) Symbol as command name
11
9
  # aliases: Array of command alias (ex. ['u', 'up'])
12
10
  # exec_proc: Proc for procedure of the command. If need the proc must return object for hook.
13
11
  # completion_proc: Proc for input completion. The proc must return Array of candidates (Optional)
14
12
  # help: help text for the command (Optional)
15
13
  def initialize(args)
16
14
  raise ArgumentError, ":name is not given." unless args.has_key?(:name)
15
+ args = args.dup
17
16
  args[:exec_proc] ||= args[:exec]
18
17
  args[:completion_proc] ||= args[:completion]
19
18
  args[:aliases] ||= [args[:alias]].compact
@@ -27,14 +26,16 @@ module Termtter
27
26
  set cfg
28
27
  end
29
28
 
29
+ # set :: Hash -> ()
30
30
  def set(cfg)
31
- @name = cfg[:name].to_sym
32
- @aliases = cfg[:aliases].map {|e| e.to_sym }
33
- @exec_proc = cfg[:exec_proc]
34
- @completion_proc = cfg[:completion_proc]
35
- @help = cfg[:help]
31
+ self.name = cfg[:name].to_sym
32
+ self.aliases = cfg[:aliases]
33
+ self.exec_proc = cfg[:exec_proc]
34
+ self.completion_proc = cfg[:completion_proc]
35
+ self.help = cfg[:help]
36
36
  end
37
37
 
38
+ # complement :: String -> [String]
38
39
  def complement(input)
39
40
  if match?(input) && input =~ /^[^\s]+\s/
40
41
  if completion_proc
@@ -48,6 +49,7 @@ module Termtter
48
49
  end
49
50
  end
50
51
 
52
+ # call :: ???
51
53
  def call(cmd = nil, arg = nil, original_text = nil)
52
54
  arg = case arg
53
55
  when nil
@@ -60,19 +62,32 @@ module Termtter
60
62
  exec_proc.call(arg)
61
63
  end
62
64
 
65
+ # match? :: String -> Boolean
63
66
  def match?(input)
64
- (pattern =~ input) != nil
67
+ !(pattern !~input)
65
68
  end
66
69
 
70
+ # pattern :: Regexp
67
71
  def pattern
68
72
  commands_regex = commands.map {|name| Regexp.quote(name.to_s) }.join('|')
69
73
  /^((#{commands_regex})|(#{commands_regex})\s+(.*?))\s*$/
70
74
  end
71
75
 
76
+ # commands :: [Symbol]
72
77
  def commands
73
78
  [name] + aliases
74
79
  end
75
80
 
81
+ def aliases=(as)
82
+ @aliases = as.map { |a| a.to_sym }
83
+ end
84
+
85
+ # alias= :: Symbol -> ()
86
+ def alias=(a)
87
+ self.aliases = [a]
88
+ end
89
+
90
+ # split_command_line :: String -> (String, String)
76
91
  def self.split_command_line(line)
77
92
  line.strip.split(/\s+/, 2)
78
93
  end
@@ -19,7 +19,10 @@ module Termtter
19
19
  tmp.__assign__(last.to_sym, value)
20
20
  end
21
21
  else
22
- __assign__(name.to_sym, value) if __refer__(name.to_sym).empty?
22
+ current_value = __refer__(name.to_sym)
23
+ if current_value.kind_of?(self.class) && current_value.empty?
24
+ __assign__(name.to_sym, value)
25
+ end
23
26
  end
24
27
  end
25
28
 
@@ -51,6 +54,10 @@ module Termtter
51
54
  @store.dup
52
55
  end
53
56
 
57
+ def __clear__
58
+ @store.clear
59
+ end
60
+
54
61
  __instance = self.new
55
62
  (class << self; self end).
56
63
  __send__(:define_method, :instance) { __instance }
@@ -61,8 +68,3 @@ def config
61
68
  Termtter::Config.instance
62
69
  end
63
70
 
64
- def configatron
65
- # remove this method until Termtter-1.2.0
66
- warn "configatron method will be removed. Use config instead. (#{caller.first})"
67
- Termtter::Config.instance
68
- end
@@ -19,7 +19,7 @@ module Termtter
19
19
  config = ERB.new(template, nil, '-').result(binding) # trim_mode => '-'
20
20
 
21
21
  Dir.mkdir(Termtter::CONF_DIR) unless File.exists?(Termtter::CONF_DIR)
22
- File.open(Termtter::CONF_FILE, 'w') {|io|
22
+ File.open(Termtter::CONF_FILE, 'w', 0600) {|io|
23
23
  io << config
24
24
  }
25
25
 
@@ -9,10 +9,7 @@ config.password = '<%= password %>'
9
9
  #config.proxy.password = 'proxy password'
10
10
 
11
11
  Termtter::Client.init do |t|
12
- <%- standard_plugins.each do |plugin| -%>
13
- t.plug '<%= plugin %>'
14
- <%- end -%>
15
12
  <%- (plugins - standard_plugins).each do |plugin| -%>
16
- # t.plug '<%= plugin %>'
13
+ # t.plug '<%= plugin %>'
17
14
  <%- end -%>
18
15
  end
data/lib/termtter/hook.rb CHANGED
@@ -12,7 +12,7 @@ module Termtter
12
12
  end
13
13
 
14
14
  def match?(point)
15
- !points.select{|pt|
15
+ points.any? {|pt|
16
16
  case pt
17
17
  when String, Symbol
18
18
  pt.to_s == point.to_s
@@ -21,7 +21,7 @@ module Termtter
21
21
  else
22
22
  false
23
23
  end
24
- }.empty?
24
+ }
25
25
  end
26
26
 
27
27
  def call(*args)
@@ -10,7 +10,7 @@ OptionParser.new { |opt|
10
10
  end
11
11
 
12
12
  opt.on('-d', '--devel', 'Start in developer mode') do |flg|
13
- config.system.__assign__(:devel, true) if flg
13
+ config.__assign__(:devel, true) if flg
14
14
  end
15
15
 
16
16
  config.system.cmd_mode = false
@@ -33,6 +33,19 @@ OptionParser.new { |opt|
33
33
  config.system.eval_scripts << script
34
34
  end
35
35
 
36
+ config.system.eval_scripts = []
37
+ opt.on('-m', '--monochrome', 'No shell escapes for color highlightings') do |script|
38
+ require 'termcolor'
39
+ module TermColor
40
+ class << self
41
+ alias parse_orig parse
42
+ def parse(o)
43
+ o.gsub(/<.+?>(.*?)<\/.+?>/, '\1')
44
+ end
45
+ end
46
+ end
47
+ end
48
+
36
49
  opt.version = Termtter::VERSION
37
50
  opt.parse!(ARGV)
38
51
  }
@@ -108,8 +108,9 @@ if win?
108
108
  str.to_s.gsub("\xef\xbd\x9e", "\xe3\x80\x9c").split(/(\e\[\d*[a-zA-Z])/).each do |token|
109
109
  case token
110
110
  when /\e\[(\d+)m/
111
- $wSetConsoleTextAttribute.call $hStdOut, $colorMap[$1.to_i].to_i
112
- when /\e\[\d*[a-zA-Z]/
111
+ color = $1.to_i > 90 ? ($1.to_i % 60) : $1.to_i
112
+ $wSetConsoleTextAttribute.call $hStdOut, $colorMap[color].to_i
113
+ when /\e\[\d*[a-zA-Z]/
113
114
  # do nothing
114
115
  else
115
116
  loop do
@@ -51,11 +51,7 @@ module Termtter
51
51
 
52
52
  def invoke_and_wait(&block)
53
53
  synchronize do
54
- begin
55
- yield
56
- rescue Exception => e
57
- Termtter::Client.handle_error(e)
58
- end
54
+ yield
59
55
  end
60
56
  end
61
57
 
@@ -1,4 +1,4 @@
1
1
  # -*- coding: utf-8 -*-
2
2
  module Termtter
3
- VERSION = '1.1.3'
3
+ VERSION = '1.3.0'
4
4
  end
@@ -5,6 +5,6 @@ require File.dirname(__FILE__) + '/../spec_helper'
5
5
  describe Termtter::Client, 'when the plugin cool is loaded' do
6
6
  it 'should add something about cool' do
7
7
  Termtter::Client.should_receive(:register_macro)
8
- plugin 'cool'
8
+ Termtter::Client.plug 'cool'
9
9
  end
10
10
  end
@@ -0,0 +1,13 @@
1
+ # -*- coding: utf-8 -*-
2
+
3
+ require File.dirname(__FILE__) + '/../spec_helper'
4
+
5
+ describe Termtter::Client, 'when the plugin curry is loaded' do
6
+ it 'should add command curry' do
7
+ Termtter::Client.should_receive(:register_command).twice
8
+ Termtter::Client.should_receive(:register_hook).twice
9
+ Termtter::Client.plug 'curry'
10
+ end
11
+ end
12
+
13
+ # FIXME: Lack of specs
@@ -0,0 +1,62 @@
1
+ # -*- coding: utf-8 -*-
2
+
3
+ require File.dirname(__FILE__) + '/../spec_helper'
4
+
5
+ describe 'db' do
6
+ DB_PATH = '/tmp/termtter.db'
7
+
8
+ before(:each) do
9
+ File.delete(DB_PATH) if File.exists?(DB_PATH)
10
+ config.plugins.db.path = DB_PATH
11
+ load 'plugins/db.rb'
12
+ end
13
+
14
+ after do
15
+ File.delete(DB_PATH) if File.exists?(DB_PATH)
16
+ end
17
+
18
+ it 'should created db file' do
19
+ File.exists?(DB_PATH)
20
+ end
21
+
22
+ it 'saves statuses' do
23
+ now = Time.now.to_s
24
+ Status << {:user_id => 1, :text => 'foo', :created_at => now}
25
+ dataset = Status.all
26
+ dataset.size.should == 1
27
+ dataset[0].user_id.should == 1
28
+ dataset[0].text.should == 'foo'
29
+ dataset[0].created_at.should == now
30
+ end
31
+
32
+ it 'saves users' do
33
+ User << {:screen_name => 'jugyo'}
34
+ dataset = User.all
35
+ dataset.size.should == 1
36
+ dataset[0].screen_name.should == 'jugyo'
37
+ end
38
+
39
+ it 'calls hook' do
40
+ user_struct = Struct.new(:id, :screen_name)
41
+ user_1 = user_struct.new(1, 'jugyo')
42
+ user_2 = user_struct.new(2, 'oyguj')
43
+
44
+ status_struct = Struct.new(:id, :text, :source, :user, :in_reply_to_status_id,
45
+ :in_reply_to_user_id, :created_at)
46
+ statuses = []
47
+ statuses << status_struct.new(1, 'foo', 'termtter', user_1, 100, Time.now.to_s)
48
+ statuses << status_struct.new(2, 'bar', 'termtter', user_1, nil, nil, Time.now.to_s)
49
+ statuses << status_struct.new(3, 'xxx', 'web', user_2, nil, nil, Time.now.to_s)
50
+
51
+ Termtter::Client.hooks[:collect_statuses_for_db].call(statuses, :update_friends_timeline)
52
+
53
+ dataset = User.all
54
+ dataset.size.should == 2
55
+
56
+ dataset = Status.all
57
+ dataset.size.should == 3
58
+
59
+ User[:id => 1].statuses.size.should == 2
60
+ Status[:id => 1].user.id.should == 1
61
+ end
62
+ end
@@ -5,7 +5,7 @@ require File.dirname(__FILE__) + '/../spec_helper'
5
5
  describe Termtter do
6
6
  it 'english? method' do
7
7
  Termtter::Client.should_receive(:add_filter)
8
- plugin 'english'
8
+ Termtter::Client.plug 'english'
9
9
  Termtter::English.english?('This is a pen.').should be_true
10
10
  Termtter::English.english?('これはペンです.').should be_false
11
11
  Termtter::English.english?('これはpenです.').should be_false
@@ -13,7 +13,7 @@ describe Termtter do
13
13
 
14
14
  it 'apply filter english only update_friends_timeline'
15
15
  # NOTE: when below code is evaluated,
16
- # plugin 'english', :only => [:update_friends_timeline]
16
+ # t.plug 'english', :only => [:update_friends_timeline]
17
17
  # in update_friends_timeline there are English posts only but in replies there are both Japanese posts and English posts.
18
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
19
  end
@@ -5,11 +5,11 @@ require File.dirname(__FILE__) + '/../spec_helper'
5
5
  describe Termtter::Client, 'when the plugin fib is loaded' do
6
6
  it 'should add command fib' do
7
7
  Termtter::Client.should_receive(:register_command).twice
8
- plugin 'fib'
8
+ Termtter::Client.plug 'defaults/fib'
9
9
  end
10
10
 
11
11
  it 'should define fib method' do
12
- plugin 'fib'
12
+ Termtter::Client.plug 'defaults/fib'
13
13
  (0..10).map {|i| fib i }.should == [0, 1, 1, 2, 3, 5, 8, 13, 21, 34, 55]
14
14
  end
15
15
  end
@@ -6,11 +6,11 @@ module Termtter
6
6
  describe Client, 'when the filter plugin is loaded' do
7
7
  it 'should add command filter, filters and unfilter' do
8
8
  Termtter::Client.should_receive(:register_command).exactly(3)
9
- plugin 'filter'
9
+ Termtter::Client.plug 'filter'
10
10
  end
11
11
 
12
12
  it 'should set public_storage[:filters]' do
13
- plugin 'filter'
13
+ Termtter::Client.plug 'filter'
14
14
  Client::public_storage.keys.should be_include(:filters)
15
15
  end
16
16
  end