jugyo-termtter 0.8.2 → 0.8.3

Sign up to get free protection for your applications and to get access to all the features.
Files changed (57) hide show
  1. data/README.rdoc +9 -0
  2. data/Rakefile +46 -64
  3. data/lib/filter/url_addspace.rb +16 -0
  4. data/lib/plugin/april_fool.rb +1 -1
  5. data/lib/plugin/bomb.rb +1 -1
  6. data/lib/plugin/clear.rb +14 -0
  7. data/lib/plugin/confirm.rb +1 -1
  8. data/lib/plugin/cool.rb +1 -1
  9. data/lib/plugin/devel.rb +13 -0
  10. data/lib/plugin/erb.rb +1 -1
  11. data/lib/plugin/filter.rb +4 -4
  12. data/lib/plugin/follow.rb +5 -5
  13. data/lib/plugin/grass.rb +27 -0
  14. data/lib/plugin/group.rb +8 -4
  15. data/lib/plugin/growl.rb +1 -1
  16. data/lib/plugin/hatebu.rb +2 -2
  17. data/lib/plugin/history.rb +9 -0
  18. data/lib/plugin/log.rb +14 -6
  19. data/lib/plugin/modify_arg_hook_sample.rb +1 -1
  20. data/lib/plugin/otsune.rb +2 -2
  21. data/lib/plugin/plugin.rb +3 -3
  22. data/lib/plugin/post_exec_hook_sample.rb +1 -1
  23. data/lib/plugin/pre_exec_hook_sample.rb +1 -1
  24. data/lib/plugin/reblog.rb +2 -2
  25. data/lib/plugin/scrape.rb +2 -2
  26. data/lib/plugin/shell.rb +1 -1
  27. data/lib/plugin/sl.rb +6 -6
  28. data/lib/plugin/standard_plugins.rb +62 -44
  29. data/lib/plugin/system_status.rb +2 -2
  30. data/lib/plugin/update_editor.rb +1 -1
  31. data/lib/plugin/wassr_post.rb +1 -1
  32. data/lib/plugin/yhara.rb +2 -2
  33. data/lib/plugin/yonda.rb +9 -9
  34. data/lib/termtter/client.rb +24 -7
  35. data/lib/termtter/command.rb +2 -2
  36. data/lib/termtter/hook.rb +1 -1
  37. data/lib/termtter/task.rb +1 -1
  38. data/lib/termtter/twitter.rb +51 -27
  39. data/lib/termtter/version.rb +1 -1
  40. data/spec/plugin/cool_spec.rb +10 -0
  41. data/spec/plugin/fib_spec.rb +16 -0
  42. data/spec/plugin/filter_spec.rb +18 -0
  43. data/spec/plugin/plugin_spec.rb +25 -0
  44. data/spec/plugin/shell_spec.rb +10 -0
  45. data/spec/plugin/spam_spec.rb +17 -0
  46. data/spec/plugin/standard_plugins_spec.rb +31 -0
  47. data/spec/spec_helper.rb +4 -0
  48. data/spec/termtter/client_spec.rb +175 -0
  49. data/spec/termtter/command_spec.rb +161 -0
  50. data/spec/termtter/task_manager_spec.rb +78 -0
  51. data/spec/termtter/task_spec.rb +22 -0
  52. data/spec/termtter/user_spec.rb +27 -0
  53. data/spec/termtter_spec.rb +43 -0
  54. metadata +40 -42
  55. data/Manifest.txt +0 -77
  56. data/PostInstall.txt +0 -1
  57. data/run_termtter.rb +0 -17
@@ -79,11 +79,11 @@ module Termtter
79
79
  end
80
80
 
81
81
  def register_macro(name, macro, options = {})
82
- arg = {
82
+ command = {
83
83
  :name => name.to_sym,
84
- :exec_proc => proc {|arg| call_commands(macro % arg)}
84
+ :exec_proc => lambda {|arg| call_commands(macro % arg)}
85
85
  }.merge(options)
86
- register_command(arg)
86
+ register_command(command)
87
87
  end
88
88
 
89
89
  def add_help(name, desc)
@@ -204,6 +204,10 @@ module Termtter
204
204
  def load_default_plugins
205
205
  plugin 'standard_plugins'
206
206
  plugin 'stdout'
207
+ configatron.set_default(:devel, false)
208
+ if configatron.devel
209
+ plugin 'devel'
210
+ end
207
211
  end
208
212
 
209
213
  def load_config
@@ -213,8 +217,7 @@ module Termtter
213
217
  load conf_file
214
218
  end
215
219
  else
216
- HighLine.track_eof = false
217
- ui = HighLine.new
220
+ ui = create_highline
218
221
  username = ui.ask('your twitter username: ')
219
222
  password = ui.ask('your twitter password: ') { |q| q.echo = false }
220
223
 
@@ -248,7 +251,7 @@ module Termtter
248
251
 
249
252
  def setup_readline
250
253
  Readline.basic_word_break_characters= "\t\n\"\\'`><=;|&{("
251
- Readline.completion_proc = proc {|input|
254
+ Readline.completion_proc = lambda {|input|
252
255
  begin
253
256
  # FIXME: when migrate to Termtter::Command
254
257
  completions = @@completions.map {|completion|
@@ -271,7 +274,7 @@ module Termtter
271
274
  def setup_update_timeline_task()
272
275
  register_command(
273
276
  :name => :_update_timeline,
274
- :exec_proc => proc {|arg|
277
+ :exec_proc => lambda {|arg|
275
278
  begin
276
279
  statuses = Termtter::API.twitter.get_friends_timeline(@@since_id)
277
280
  unless statuses.empty?
@@ -353,6 +356,20 @@ module Termtter
353
356
  end
354
357
  end
355
358
 
359
+ def create_highline
360
+ HighLine.track_eof = false
361
+ if $stdin.respond_to?(:getbyte) # for ruby1.9
362
+ require 'delegate'
363
+ stdin_for_highline = SimpleDelegator.new($stdin)
364
+ def stdin_for_highline.getc
365
+ getbyte
366
+ end
367
+ else
368
+ stdin_for_highline = $stdin
369
+ end
370
+ return HighLine.new(stdin_for_highline)
371
+ end
372
+
356
373
  def handle_error(e)
357
374
  call_new_hooks("on_error", e)
358
375
  rescue => e
@@ -14,8 +14,8 @@ module Termtter
14
14
  raise ArgumentError, ":name is not given." unless args.has_key?(:name)
15
15
  @name = args[:name].to_sym
16
16
  @aliases = args[:aliases] ? args[:aliases].map {|i| i.to_sym } : []
17
- @exec_proc = args[:exec_proc] || proc {|arg|}
18
- @completion_proc = args[:completion_proc] || proc {|command, arg| [] }
17
+ @exec_proc = args[:exec_proc] || lambda {|arg|}
18
+ @completion_proc = args[:completion_proc] || lambda {|command, arg| [] }
19
19
  @help = args[:help]
20
20
  end
21
21
 
data/lib/termtter/hook.rb CHANGED
@@ -8,7 +8,7 @@ module Termtter
8
8
  raise ArgumentError, ":name is not given." unless args.has_key?(:name)
9
9
  @name = args[:name].to_sym
10
10
  @points = args[:points] ? args[:points].map {|i| i.to_sym } : []
11
- @exec_proc = args[:exec_proc] || proc {}
11
+ @exec_proc = args[:exec_proc] || lambda {}
12
12
  end
13
13
 
14
14
  def match?(point)
data/lib/termtter/task.rb CHANGED
@@ -7,7 +7,7 @@ module Termtter
7
7
  @name = args[:name]
8
8
  @exec_at = Time.now + (args[:after] || 0)
9
9
  @interval = args[:interval]
10
- @exec_proc = block || proc {}
10
+ @exec_proc = block || lambda {}
11
11
  end
12
12
  def execute
13
13
  exec_proc.call
@@ -6,14 +6,15 @@ require 'time'
6
6
  module Termtter
7
7
  class Twitter
8
8
 
9
- def initialize(user_name, password, connection)
9
+ def initialize(user_name, password, connection, host = "twitter.com")
10
10
  @user_name = user_name
11
11
  @password = password
12
12
  @connection = connection
13
+ @host = host
13
14
  end
14
15
 
15
16
  def update_status(status)
16
- @connection.start("twitter.com", @connection.port) do |http|
17
+ @connection.start(@host, @connection.port) do |http|
17
18
  uri = '/statuses/update.xml'
18
19
  http.request(post_request(uri), "status=#{CGI.escape(status)}&source=#{APP_NAME}")
19
20
  end
@@ -21,7 +22,7 @@ module Termtter
21
22
  end
22
23
 
23
24
  def direct_message(user, status)
24
- @connection.start("twitter.com", @connection.port) do |http|
25
+ @connection.start(@host, @connection.port) do |http|
25
26
  uri = '/direct_messages/new.xml'
26
27
  http.request(post_request(uri), "user=#{CGI.escape(user)}&text=#{CGI.escape(status)}&source=#{APP_NAME}")
27
28
  end
@@ -29,26 +30,18 @@ module Termtter
29
30
  end
30
31
 
31
32
  def get_user_profile(screen_name)
32
- uri = "#{@connection.protocol}://twitter.com/users/show/#{screen_name}.json"
33
- result = JSON.parse(open(uri, :http_basic_authentication => [user_name, password], :proxy => @connection.proxy_uri).read)
34
- user = User.new
35
- %w[ name favourites_count url id description protected utc_offset time_zone
36
- screen_name notifications statuses_count followers_count friends_count
37
- profile_image_url location following created_at
38
- ].each do |attr|
39
- user.__send__("#{attr}=".to_sym, result[attr])
40
- end
41
- return user
33
+ result = fetch_as_json(url_for("/users/show/#{screen_name}.json"))
34
+ return hash_to_user(result)
42
35
  end
43
36
 
44
37
  def get_friends_timeline(since_id = nil)
45
- uri = "#{@connection.protocol}://twitter.com/statuses/friends_timeline.json"
38
+ uri = url_for("/statuses/friends_timeline.json")
46
39
  uri << "?since_id=#{since_id}" if since_id
47
40
  return get_timeline(uri)
48
41
  end
49
42
 
50
43
  def get_user_timeline(screen_name)
51
- return get_timeline("#{@connection.protocol}://twitter.com/statuses/user_timeline/#{screen_name}.json")
44
+ return get_timeline(url_for("/statuses/user_timeline/#{screen_name}.json"))
52
45
  rescue OpenURI::HTTPError => e
53
46
  puts "No such user: #{screen_name}"
54
47
  nears = near_users(screen_name)
@@ -57,7 +50,7 @@ module Termtter
57
50
  end
58
51
 
59
52
  def search(query)
60
- results = JSON.parse(open("#{@connection.protocol}://search.twitter.com/search.json?q=" + CGI.escape(query)).read, :proxy => @connection.proxy_uri)['results']
53
+ results = fetch_as_json(search_url_for("/search.json?q=#{CGI.escape(query)}"))['results']
61
54
  return results.map do |s|
62
55
  status = Status.new
63
56
  status.id = s['id']
@@ -69,7 +62,7 @@ module Termtter
69
62
  end
70
63
 
71
64
  def show(id, rth = false)
72
- get_status = lambda { get_timeline("#{@connection.protocol}://twitter.com/statuses/show/#{id}.json")[0] }
65
+ get_status = lambda { get_timeline(url_for("/statuses/show/#{id}.json"))[0] }
73
66
  statuses = []
74
67
  statuses << status = Array(Client.public_storage[:log]).detect(get_status) {|s| s.id == id.to_i }
75
68
  statuses << show(id, true) if rth && id = status.in_reply_to_status_id
@@ -77,11 +70,20 @@ module Termtter
77
70
  end
78
71
 
79
72
  def replies
80
- return get_timeline("#{@connection.protocol}://twitter.com/statuses/replies.json")
73
+ return get_timeline(url_for("/statuses/replies.json"))
74
+ end
75
+
76
+ def followers
77
+ users = []
78
+ page = 0
79
+ begin
80
+ users += tmp = fetch_as_json(url_for("/statuses/followers.json?page=#{page+=1}"))
81
+ end until tmp.empty?
82
+ return users.map{|u| hash_to_user(u)}
81
83
  end
82
84
 
83
85
  def get_timeline(uri)
84
- data = JSON.parse(open(uri, :http_basic_authentication => [user_name, password], :proxy => @connection.proxy_uri).read)
86
+ data = fetch_as_json(uri)
85
87
  data = [data] unless data.instance_of? Array
86
88
  return data.map do |s|
87
89
  status = Status.new
@@ -100,9 +102,7 @@ module Termtter
100
102
  # note: APILimit.reset_time_in_seconds == APILimit.reset_time.to_i
101
103
  APILIMIT = Struct.new("APILimit", :reset_time, :reset_time_in_seconds, :remaining_hits, :hourly_limit)
102
104
  def get_rate_limit_status
103
- uri = 'http://twitter.com/account/rate_limit_status.json'
104
- data = JSON.parse(open(uri, :http_basic_authentication => [user_name, password], :proxy => @connection.proxy_uri).read)
105
-
105
+ data = fetch_as_json(url_for("/account/rate_limit_status.json"))
106
106
  reset_time = Time.parse(data['reset_time'])
107
107
  reset_time_in_seconds = data['reset_time_in_seconds'].to_i
108
108
 
@@ -113,18 +113,43 @@ module Termtter
113
113
 
114
114
  private
115
115
 
116
+ def hash_to_user(hash)
117
+ user = User.new
118
+ %w[ name favourites_count url id description protected utc_offset time_zone
119
+ screen_name notifications statuses_count followers_count friends_count
120
+ profile_image_url location following created_at
121
+ ].each do |attr|
122
+ user.__send__("#{attr}=".to_sym, hash[attr])
123
+ end
124
+ return user
125
+ end
126
+
127
+ def fetch_as_json(uri)
128
+ JSON.parse(open_uri(uri).read)
129
+ end
130
+
131
+ def open_uri(uri)
132
+ return open(uri, :http_basic_authentication => [user_name, password], :proxy => @connection.proxy_uri)
133
+ end
134
+
135
+ def url_for(path)
136
+ return "#{@connection.protocol}://#{@host}/#{path.sub(/^\//, '')}"
137
+ end
138
+
139
+ def search_url_for(path)
140
+ return "#{@connection.protocol}://search.#{@host}/#{path.sub(/^\//, '')}"
141
+ end
142
+
116
143
  def user_name
117
144
  unless @user_name.instance_of? String
118
- HighLine.track_eof = false
119
- @user_name = HighLine.new.ask('your twitter username: ')
145
+ Termtter::Client.create_highline.ask('your twitter username: ')
120
146
  end
121
147
  @user_name
122
148
  end
123
149
 
124
150
  def password
125
151
  unless @password.instance_of? String
126
- HighLine.track_eof = false
127
- @password = HighLine.new.ask('your twitter password: ') { |q| q.echo = false }
152
+ @password = Termtter::Client.create_highline.ask('your twitter password: ') { |q| q.echo = false }
128
153
  end
129
154
  @password
130
155
  end
@@ -146,4 +171,3 @@ module Termtter
146
171
  end
147
172
  end
148
173
  end
149
-
@@ -1,3 +1,3 @@
1
1
  module Termtter
2
- VERSION = '0.8.2'
2
+ VERSION = '0.8.3'
3
3
  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 cool is loaded' do
6
+ it 'should add something about cool' do
7
+ Termtter::Client.should_receive(:register_macro)
8
+ plugin 'cool'
9
+ end
10
+ end
@@ -0,0 +1,16 @@
1
+ # -*- coding: utf-8 -*-
2
+
3
+ require File.dirname(__FILE__) + '/../spec_helper'
4
+
5
+ describe Termtter::Client, 'when the plugin fib is loaded' do
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+)/)
9
+ plugin 'fib'
10
+ end
11
+
12
+ it 'should define fib method' do
13
+ plugin 'fib'
14
+ (0..10).map {|i| fib i }.should == [0, 1, 1, 2, 3, 5, 8, 13, 21, 34, 55]
15
+ end
16
+ end
@@ -0,0 +1,18 @@
1
+ # -*- coding: utf-8 -*-
2
+
3
+ require File.dirname(__FILE__) + '/../spec_helper'
4
+
5
+ module Termtter
6
+ describe Client, 'when the filter plugin is loaded' do
7
+ it 'should add command filter, filters and unfilter' do
8
+ Termtter::Client.should_receive(:register_command).exactly(3)
9
+ plugin 'filter'
10
+ end
11
+
12
+ it 'should set public_storage[:filters]' do
13
+ plugin 'filter'
14
+ Client::public_storage.keys.should be_include(:filters)
15
+ end
16
+ end
17
+ end
18
+
@@ -0,0 +1,25 @@
1
+ # -*- coding: utf-8 -*-
2
+
3
+ require File.dirname(__FILE__) + '/../../lib/termtter'
4
+
5
+ module Termtter
6
+ describe Client, 'when the plugin plugin is loaded' do
7
+ it 'should add command plugin and plugins' do
8
+ Termtter::Client.should_receive(:register_command).twice
9
+ plugin 'plugin'
10
+ end
11
+
12
+ it 'should set public_storage[:plugins]' do
13
+ plugin 'plugin'
14
+ Client::public_storage[:plugins].should_not be_empty
15
+ end
16
+
17
+ describe 'after the plugin plugin is loaded' do
18
+ before { plugin 'plugin' }
19
+
20
+ it 'should load the given plugin in the command plugin'
21
+ # hmm... How can I write it...?
22
+ end
23
+ end
24
+ end
25
+
@@ -0,0 +1,10 @@
1
+ # -*- coding: utf-8 -*-
2
+
3
+ require File.dirname(__FILE__) + '/../spec_helper'
4
+
5
+ describe Termtter::Client, 'when the plugin shell is loaded' do
6
+ it 'should add command shell' do
7
+ Termtter::Client.should_receive(:register_command)
8
+ plugin 'shell'
9
+ end
10
+ end
@@ -0,0 +1,17 @@
1
+ # -*- coding: utf-8 -*-
2
+
3
+ require File.dirname(__FILE__) + '/../spec_helper'
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
+
@@ -0,0 +1,31 @@
1
+ # -*- coding: utf-8 -*-
2
+
3
+ require File.dirname(__FILE__) + '/../spec_helper'
4
+ plugin 'standard_plugins'
5
+
6
+ module Termtter
7
+ describe Client do
8
+ it 'shold return registerd commands' do
9
+ [
10
+ [:update, [:u]], [:direct, [:d]],
11
+ [:profile, [:p]], [:list, [:l]],
12
+ [:search, [:s]], [:replies, [:r]],
13
+ [:show, [ ]], [:shows, [ ]],
14
+ [:limit, [:lm]], [:pause, [ ]],
15
+ [:resume, [ ]], [:exit, [:e]],
16
+ ].each do |name, aliases|
17
+ command = Client.get_command(name)
18
+ command.name.should == name
19
+ command.aliases.should == aliases
20
+ end
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
+ end
30
+ end
31
+
@@ -0,0 +1,4 @@
1
+ # -*- coding: utf-8 -*-
2
+
3
+ $:.unshift(File.dirname(__FILE__) + '/../lib')
4
+ require 'termtter'
@@ -0,0 +1,175 @@
1
+ # -*- coding: utf-8 -*-
2
+
3
+ require File.dirname(__FILE__) + '/../spec_helper'
4
+
5
+ module Termtter
6
+
7
+ describe Client do
8
+
9
+ it 'should take new_command' do
10
+ command = Command.new(:name => :test)
11
+ Client.register_command(command)
12
+ Client.get_command(:test).should == command
13
+ end
14
+
15
+ it 'should take command as Hash' do
16
+ Client.register_command(:name => :test)
17
+ Client.get_command(:test).name.should == :test
18
+ end
19
+
20
+ it 'should call new_command' do
21
+ command_arg = nil
22
+ command = Command.new(:name => :test, :exec_proc => lambda {|arg| command_arg = arg})
23
+ Client.register_command(command)
24
+ command_arg.should == nil
25
+
26
+ [
27
+ ['test', ''],
28
+ ['test foo bar', 'foo bar'],
29
+ ['test foo bar ', 'foo bar'],
30
+ ['test foo bar ', 'foo bar'],
31
+ ].each do |input, args|
32
+ Client.call_commands(input, nil)
33
+ command_arg.should == args
34
+ end
35
+ end
36
+
37
+ it 'should take new_hook' do
38
+ hook = Hook.new(:name => :test)
39
+ Client.register_hook(hook)
40
+ Client.get_hook(:test).should == hook
41
+ end
42
+
43
+ it 'should take hook as Hash' do
44
+ Client.register_hook(:name => :test)
45
+ Client.get_hook(:test).name.should == :test
46
+ end
47
+
48
+ it 'should call new_hook' do
49
+ hook_called = false
50
+ Client.register_hook(:name => :test1, :points => [:point1], :exec_proc => lambda {hook_called = true})
51
+ hook_called.should == false
52
+ Client.call_new_hooks(:point1)
53
+ hook_called.should == true
54
+ end
55
+
56
+ it 'should call new_hook with args' do
57
+ arg1 = nil
58
+ arg2 = nil
59
+ Client.register_hook(:name => :test1, :points => [:point1], :exec_proc => lambda {|a1, a2| arg1 = a1; arg2 = a2})
60
+ arg1.should == nil
61
+ arg2.should == nil
62
+ Client.call_new_hooks(:point1, 'foo', 'bar')
63
+ arg1.should == 'foo'
64
+ arg2.should == 'bar'
65
+ end
66
+
67
+ it 'should return hooks when call get_hooks' do
68
+ hook1 = Client.register_hook(:name => :test1, :points => [:point1])
69
+ hook2 = Client.register_hook(:name => :test2, :points => [:point1])
70
+ hook3 = Client.register_hook(:name => :test3, :points => [:point2])
71
+
72
+ hooks = Client.get_hooks(:point1)
73
+ hooks.size.should == 2
74
+ hooks.include?(hook1).should == true
75
+ hooks.include?(hook2).should == true
76
+ hooks.include?(hook3).should == false
77
+ end
78
+
79
+ it 'should call decide_arg hooks' do
80
+ input_command = nil
81
+ input_arg = nil
82
+ decided_arg = nil
83
+ Client.register_hook( :name => :test1,
84
+ :points => [:modify_arg_for_update],
85
+ :exec_proc => lambda {|cmd, arg| input_command = cmd; input_arg = arg; arg.upcase})
86
+ Client.register_hook( :name => :test2,
87
+ :points => [:pre_exec_update],
88
+ :exec_proc => lambda {|cmd, arg| decided_arg = arg})
89
+ Client.register_command(:name => :update, :aliases => [:u])
90
+
91
+ input_command.should == nil
92
+ input_arg.should == nil
93
+ decided_arg.should == nil
94
+ Client.call_commands('u foo')
95
+ input_command.should == 'u'
96
+ input_arg.should == 'foo'
97
+ decided_arg.should == 'FOO'
98
+ end
99
+
100
+ it 'should call pre_exec hooks' do
101
+ hook_called = false
102
+ Client.register_hook( :name => :test,
103
+ :points => [:pre_exec_update],
104
+ :exec_proc => lambda {|cmd, arg| hook_called = true})
105
+ Client.register_command(:name => :update)
106
+
107
+ hook_called.should == false
108
+ Client.call_commands('update foo')
109
+ hook_called.should == true
110
+ end
111
+
112
+ it 'should able to cancel exec command' do
113
+ command_called = false
114
+ Client.register_hook( :name => :test,
115
+ :points => [:pre_exec_update],
116
+ :exec_proc => lambda {|cmd, arg| false})
117
+ Client.register_command(:name => :update, :exec_proc => lambda {|cmd, arg| command_called = true})
118
+
119
+ command_called.should == false
120
+ Client.call_commands('update foo')
121
+ command_called.should == false
122
+ end
123
+
124
+ it 'should call post_exec hooks' do
125
+ command_result = nil
126
+ Client.register_hook( :name => :test,
127
+ :points => [:post_exec_update],
128
+ :exec_proc => lambda {|cmd, arg, result| command_result = result })
129
+ Client.register_command(:name => :update, :exec_proc => lambda {|arg| 'foo'})
130
+
131
+ command_result.should == nil
132
+ Client.call_commands('update foo')
133
+ command_result.should == 'foo'
134
+ end
135
+
136
+ it 'should call exit hooks' do
137
+ hook_called = false
138
+ Client.register_hook(
139
+ :name => :test,
140
+ :points => [:exit],
141
+ :exec_proc => lambda { hook_called = true }
142
+ )
143
+
144
+ hook_called.should == false
145
+ Client.exit
146
+ hook_called.should == true
147
+ end
148
+
149
+ it 'should call plural hooks' do
150
+ hook1_called = false
151
+ hook2_called = false
152
+ Client.register_hook(:name => :hook1, :points => [:exit], :exec_proc => lambda {hook1_called = true})
153
+ Client.register_hook(:name => :hook2, :points => [:exit], :exec_proc => lambda {hook2_called = true})
154
+
155
+ hook1_called.should == false
156
+ hook2_called.should == false
157
+ Client.exit
158
+ hook1_called.should == true
159
+ hook2_called.should == true
160
+ end
161
+
162
+ it 'should able to override hooks' do
163
+ hook1_called = false
164
+ hook2_called = false
165
+ Client.register_hook(:name => :hook, :points => [:exit], :exec_proc => lambda {hook1_called = true})
166
+ Client.register_hook(:name => :hook, :points => [:exit], :exec_proc => lambda {hook2_called = true})
167
+
168
+ hook1_called.should == false
169
+ hook2_called.should == false
170
+ Client.exit
171
+ hook1_called.should == false
172
+ hook2_called.should == true
173
+ end
174
+ end
175
+ end