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
@@ -0,0 +1,32 @@
1
+ module Termtter
2
+ class RubytterProxy
3
+ include Hookable
4
+
5
+ def initialize(*args)
6
+ @rubytter = Rubytter.new(*args)
7
+ end
8
+
9
+ def method_missing(method, *args, &block)
10
+ if @rubytter.methods.include?(method.to_s)
11
+ result = nil
12
+ begin
13
+ modified_args = args
14
+ hooks = self.class.get_hooks("pre_#{method}")
15
+ hooks.each do |hook|
16
+ modified_args = hook.call(*modified_args)
17
+ end
18
+
19
+ timeout(config.timeout) do
20
+ result = @rubytter.__send__(method, *modified_args)
21
+ end
22
+
23
+ self.class.call_hooks("post_#{method}", *args)
24
+ rescue HookCanceled
25
+ end
26
+ result
27
+ else
28
+ super
29
+ end
30
+ end
31
+ end
32
+ end
@@ -0,0 +1,16 @@
1
+ # -*- coding: utf-8 -*-
2
+
3
+ unless Array.instance_methods.include?('take')
4
+ class Array
5
+ def take(n) self[0...n] end
6
+ end
7
+ end
8
+
9
+ unless Symbol.instance_methods.include?('to_proc')
10
+ class Symbol
11
+ def to_proc
12
+ Proc.new { |*args| args.shift.__send__(self, *args) }
13
+ end
14
+ end
15
+ end
16
+
@@ -0,0 +1,19 @@
1
+ # -*- coding: utf-8 -*-
2
+
3
+ def plugin(name, init = {})
4
+ warn "plugin method will be removed. Use Termtter::Client.plug instead."
5
+ unless init.empty?
6
+ init.each do |key, value|
7
+ config.plugins.__refer__(name.to_sym).__assign__(key.to_sym, value)
8
+ end
9
+ end
10
+ load "plugins/#{name}.rb"
11
+ rescue Exception => e
12
+ Termtter::Client.handle_error(e)
13
+ end
14
+
15
+ def filter(name, init = {})
16
+ warn "filter method will be removed. Use plugin instead."
17
+ plugin(name, init)
18
+ end
19
+
@@ -0,0 +1,86 @@
1
+ # -*- coding: utf-8 -*-
2
+
3
+ require 'iconv'
4
+ require 'Win32API'
5
+ $wGetACP = Win32API.new('kernel32','GetACP','','I')
6
+
7
+ module Readline
8
+ $iconv_sj_to_u8 = Iconv.new('UTF-8', "CP#{$wGetACP.call()}")
9
+ alias :old_readline :readline
10
+ def readline(*a)
11
+ str = old_readline(*a)
12
+ out = ''
13
+ loop do
14
+ begin
15
+ out << $iconv_sj_to_u8.iconv(str)
16
+ break
17
+ rescue Iconv::Failure
18
+ out << "#{$!.success}?"
19
+ str = $!.failed[1..-1]
20
+ end
21
+ end
22
+ return out
23
+ end
24
+ module_function :old_readline, :readline
25
+ end
26
+
27
+ $wSetConsoleTextAttribute = Win32API.new('kernel32','SetConsoleTextAttribute','II','I')
28
+ $wGetConsoleScreenBufferInfo = Win32API.new("kernel32", "GetConsoleScreenBufferInfo", ['l', 'p'], 'i')
29
+ $wGetStdHandle = Win32API.new('kernel32','GetStdHandle','I','I')
30
+ $wGetACP = Win32API.new('kernel32','GetACP','','I')
31
+
32
+ $hStdOut = $wGetStdHandle.call(0xFFFFFFF5)
33
+ lpBuffer = ' ' * 22
34
+ $wGetConsoleScreenBufferInfo.call($hStdOut, lpBuffer)
35
+ $oldColor = lpBuffer.unpack('SSSSSssssSS')[4]
36
+
37
+ $colorMap = {
38
+ 0 => 0x07|0x00|0x00|0x00, # black/white
39
+ 37 => 0x08|0x00|0x00|0x00, # white/intensity
40
+ 31 => 0x04|0x08|0x00|0x00, # red/red
41
+ 32 => 0x02|0x08|0x00|0x00, # green/green
42
+ 33 => 0x06|0x08|0x00|0x00, # yellow/yellow
43
+ 34 => 0x01|0x08|0x00|0x00, # blue/blue
44
+ 35 => 0x05|0x08|0x00|0x00, # magenta/purple
45
+ 36 => 0x03|0x08|0x00|0x00, # cyan/aqua
46
+ 39 => 0x07, # default
47
+ 40 => 0x00|0x00|0xf0|0x00, # background:white
48
+ 41 => 0x07|0x00|0x40|0x00, # background:red
49
+ 42 => 0x07|0x00|0x20|0x00, # background:green
50
+ 43 => 0x07|0x00|0x60|0x00, # background:yellow
51
+ 44 => 0x07|0x00|0x10|0x00, # background:blue
52
+ 45 => 0x07|0x00|0x50|0x80, # background:magenta
53
+ 46 => 0x07|0x00|0x30|0x80, # background:cyan
54
+ 47 => 0x07|0x00|0x70|0x80, # background:gray
55
+ 49 => 0x70, # default
56
+ 90 => 0x07|0x00|0x00|0x00, # erase/white
57
+ }
58
+ $iconv_u8_to_sj = Iconv.new("CP#{$wGetACP.call()}", 'UTF-8')
59
+ def print(str)
60
+ str.to_s.gsub("\xef\xbd\x9e", "\xe3\x80\x9c").split(/(\e\[\d*[a-zA-Z])/).each do |token|
61
+ case token
62
+ when /\e\[(\d+)m/
63
+ color = $1.to_i > 90 ? ($1.to_i % 60) : $1.to_i
64
+ $wSetConsoleTextAttribute.call $hStdOut, $colorMap[color].to_i
65
+ when /\e\[\d*[a-zA-Z]/
66
+ # do nothing
67
+ else
68
+ loop do
69
+ begin
70
+ STDOUT.print $iconv_u8_to_sj.iconv(token)
71
+ break
72
+ rescue Iconv::Failure
73
+ STDOUT.print "#{$!.success}?"
74
+ token = $!.failed[1..-1]
75
+ end
76
+ end
77
+ end
78
+ end
79
+ $wSetConsoleTextAttribute.call $hStdOut, $oldColor
80
+ $iconv_u8_to_sj.iconv(nil)
81
+ end
82
+ def puts(str)
83
+ print str
84
+ STDOUT.puts
85
+ end
86
+
@@ -1,21 +1,12 @@
1
1
  # -*- coding: utf-8 -*-
2
2
 
3
- def plugin(name, init = {})
4
- warn "plugin method will be removed. Use Termtter::Client.plug instead."
5
- unless init.empty?
6
- init.each do |key, value|
7
- config.plugins.__refer__(name.to_sym).__assign__(key.to_sym, value)
8
- end
9
- end
10
- load "plugins/#{name}.rb"
11
- rescue Exception => e
12
- Termtter::Client.handle_error(e)
3
+ def win?
4
+ !!(RUBY_PLATFORM.downcase =~ /mswin(?!ce)|mingw|bccwin|cygwin/)
13
5
  end
14
6
 
15
- def filter(name, init = {})
16
- warn "filter method will be removed. Use plugin instead."
17
- plugin(name, init)
18
- end
7
+ require 'termtter/system_extensions/windows' if win?
8
+ require 'termtter/system_extensions/core_compatibles'
9
+ require 'termtter/system_extensions/termtter_compatibles'
19
10
 
20
11
  require 'dl/import'
21
12
  module Readline
@@ -43,122 +34,17 @@ module Readline
43
34
  end
44
35
  end
45
36
 
46
- def win?
47
- RUBY_PLATFORM.downcase =~ /mswin(?!ce)|mingw|bccwin|cygwin/
48
- end
49
-
50
- if win?
51
- require 'iconv'
52
- require 'Win32API'
53
- $wGetACP = Win32API.new('kernel32','GetACP','','I')
54
-
55
- module Readline
56
- $iconv_sj_to_u8 = Iconv.new('UTF-8', "CP#{$wGetACP.call()}")
57
- alias :old_readline :readline
58
- def readline(*a)
59
- str = old_readline(*a)
60
- out = ''
61
- loop do
62
- begin
63
- out << $iconv_sj_to_u8.iconv(str)
64
- break
65
- rescue Iconv::Failure
66
- out << "#{$!.success}?"
67
- str = $!.failed[1..-1]
68
- end
69
- end
70
- return out
71
- end
72
- module_function :old_readline, :readline
73
- end
74
-
75
- $wSetConsoleTextAttribute = Win32API.new('kernel32','SetConsoleTextAttribute','II','I')
76
- $wGetConsoleScreenBufferInfo = Win32API.new("kernel32", "GetConsoleScreenBufferInfo", ['l', 'p'], 'i')
77
- $wGetStdHandle = Win32API.new('kernel32','GetStdHandle','I','I')
78
- $wGetACP = Win32API.new('kernel32','GetACP','','I')
79
-
80
- $hStdOut = $wGetStdHandle.call(0xFFFFFFF5)
81
- lpBuffer = ' ' * 22
82
- $wGetConsoleScreenBufferInfo.call($hStdOut, lpBuffer)
83
- $oldColor = lpBuffer.unpack('SSSSSssssSS')[4]
84
-
85
- $colorMap = {
86
- 0 => 0x07|0x00|0x00|0x00, # black/white
87
- 37 => 0x08|0x00|0x00|0x00, # white/intensity
88
- 31 => 0x04|0x08|0x00|0x00, # red/red
89
- 32 => 0x02|0x08|0x00|0x00, # green/green
90
- 33 => 0x06|0x08|0x00|0x00, # yellow/yellow
91
- 34 => 0x01|0x08|0x00|0x00, # blue/blue
92
- 35 => 0x05|0x08|0x00|0x00, # magenta/purple
93
- 36 => 0x03|0x08|0x00|0x00, # cyan/aqua
94
- 39 => 0x07, # default
95
- 40 => 0x00|0x00|0xf0|0x00, # background:white
96
- 41 => 0x07|0x00|0x40|0x00, # background:red
97
- 42 => 0x07|0x00|0x20|0x00, # background:green
98
- 43 => 0x07|0x00|0x60|0x00, # background:yellow
99
- 44 => 0x07|0x00|0x10|0x00, # background:blue
100
- 45 => 0x07|0x00|0x50|0x80, # background:magenta
101
- 46 => 0x07|0x00|0x30|0x80, # background:cyan
102
- 47 => 0x07|0x00|0x70|0x80, # background:gray
103
- 49 => 0x70, # default
104
- 90 => 0x07|0x00|0x00|0x00, # erase/white
105
- }
106
- $iconv_u8_to_sj = Iconv.new("CP#{$wGetACP.call()}", 'UTF-8')
107
- def print(str)
108
- str.to_s.gsub("\xef\xbd\x9e", "\xe3\x80\x9c").split(/(\e\[\d*[a-zA-Z])/).each do |token|
109
- case token
110
- when /\e\[(\d+)m/
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]/
114
- # do nothing
115
- else
116
- loop do
117
- begin
118
- STDOUT.print $iconv_u8_to_sj.iconv(token)
119
- break
120
- rescue Iconv::Failure
121
- STDOUT.print "#{$!.success}?"
122
- token = $!.failed[1..-1]
123
- end
124
- end
125
- end
126
- end
127
- $wSetConsoleTextAttribute.call $hStdOut, $oldColor
128
- $iconv_u8_to_sj.iconv(nil)
129
- end
130
- def puts(str)
131
- print str
132
- STDOUT.puts
133
- end
134
- end
135
-
136
- unless Array.instance_methods.include?('take')
137
- class Array
138
- def take(n) self[0...n] end
139
- end
140
- end
141
-
142
- unless Symbol.instance_methods.include?('to_proc')
143
- class Symbol
144
- def to_proc
145
- Proc.new { |*args| args.shift.__send__(self, *args) }
146
- end
147
- end
148
- end
149
-
150
37
  require 'highline'
151
38
  def create_highline
152
39
  HighLine.track_eof = false
153
40
  if $stdin.respond_to?(:getbyte) # for ruby1.9
154
- def $stdin.getc
155
- getbyte
41
+ def $stdin.getc; getbyte
156
42
  end
157
43
  end
158
44
  HighLine.new($stdin)
159
45
  end
160
46
 
161
- def open_brawser(url)
47
+ def open_browser(url)
162
48
  case RUBY_PLATFORM
163
49
  when /linux/
164
50
  system 'firefox', url
@@ -168,3 +54,4 @@ def open_brawser(url)
168
54
  system 'open', url
169
55
  end
170
56
  end
57
+
@@ -1,11 +1,8 @@
1
1
  # -*- coding: utf-8 -*-
2
-
3
2
  module Termtter
4
3
  class TaskManager
5
-
6
- INTERVAL = 1
7
-
8
- def initialize()
4
+ def initialize(interval = 1)
5
+ @interval = interval
9
6
  @tasks = {}
10
7
  @work = true
11
8
  @mutex = Mutex.new
@@ -28,7 +25,7 @@ module Termtter
28
25
  Thread.new do
29
26
  while @work
30
27
  step unless @pause
31
- sleep INTERVAL
28
+ sleep @interval
32
29
  end
33
30
  end
34
31
  end
@@ -43,9 +40,7 @@ module Termtter
43
40
 
44
41
  def invoke_later
45
42
  Thread.new do
46
- invoke_and_wait do
47
- yield
48
- end
43
+ invoke_and_wait { yield }
49
44
  end
50
45
  end
51
46
 
@@ -107,6 +102,5 @@ module Termtter
107
102
  return due_tasks
108
103
  end
109
104
  end
110
-
111
105
  end
112
106
  end
@@ -1,4 +1,4 @@
1
1
  # -*- coding: utf-8 -*-
2
2
  module Termtter
3
- VERSION = '1.5.0'
3
+ VERSION = '1.6.0'
4
4
  end
data/lib/termtter.rb CHANGED
@@ -2,8 +2,8 @@
2
2
 
3
3
  $KCODE = "u" unless Object.const_defined? :Encoding
4
4
 
5
- $:.unshift(File.dirname(__FILE__)) unless
6
- $:.include?(File.dirname(__FILE__)) || $:.include?(File.expand_path(File.dirname(__FILE__)))
5
+ $:.unshift(File.dirname(__FILE__)) unless $:.include?(File.dirname(__FILE__)) ||
6
+ $:.include?(File.expand_path(File.dirname(__FILE__)))
7
7
 
8
8
  require 'rubygems'
9
9
 
@@ -16,15 +16,17 @@ require 'optparse'
16
16
  require 'readline'
17
17
  gem 'rubytter', '>= 0.9.2'
18
18
  require 'rubytter'
19
+ require 'timeout'
19
20
 
20
21
  require 'termtter/config'
21
22
  require 'termtter/version'
22
23
  require 'termtter/optparse'
23
- require 'termtter/connection'
24
24
  require 'termtter/command'
25
25
  require 'termtter/hook'
26
26
  require 'termtter/task'
27
27
  require 'termtter/task_manager'
28
+ require 'termtter/hookable'
29
+ require 'termtter/rubytter_proxy'
28
30
  require 'termtter/client'
29
31
  require 'termtter/api'
30
32
  require 'termtter/system_extensions'
@@ -0,0 +1,41 @@
1
+ require File.dirname(__FILE__) + '/../../spec_helper'
2
+
3
+ describe 'plugin hashtag' do
4
+ before do
5
+ Termtter::Client.setup_task_manager
6
+ Termtter::Client.plug 'defaults'
7
+ end
8
+
9
+ describe 'spec for "hashtag add"' do
10
+ before do
11
+ Termtter::Client.public_storage[:hashtags].clear
12
+ end
13
+
14
+ it 'should add hashtag "test"' do
15
+ Termtter::Client.call_commands('hashtag add test')
16
+ Termtter::Client.public_storage[:hashtags].should == Set.new('#test')
17
+ end
18
+
19
+ it 'should add hashtag "#test"' do
20
+ Termtter::Client.call_commands('hashtag add #test')
21
+ Termtter::Client.public_storage[:hashtags].should == Set.new('#test')
22
+ end
23
+
24
+ it 'should add hashtags "foo", "bar"' do
25
+ Termtter::Client.call_commands('hashtag add foo bar')
26
+ Termtter::Client.public_storage[:hashtags].should == Set.new(["#foo", "#bar"])
27
+ end
28
+ end
29
+
30
+ describe 'spec for hook of hashtag' do
31
+ before do
32
+ Termtter::Client.call_commands('hashtag add foo bar')
33
+ end
34
+
35
+ it 'add hashtags as args of command' do
36
+ @update_command = Termtter::Client.commands[:update]
37
+ @update_command.exec_proc.should_receive(:call).with("test #foo #bar")
38
+ Termtter::Client.call_commands('update test')
39
+ end
40
+ end
41
+ end
@@ -0,0 +1,34 @@
1
+ require File.dirname(__FILE__) + '/../../spec_helper'
2
+
3
+ describe 'plugin lists' do
4
+ before do
5
+ config.user_name = 'jugyo'
6
+ @twitter_stub = Object.new
7
+ Termtter::API.stub!(:twitter).and_return(@twitter_stub)
8
+ end
9
+
10
+ describe 'command lists' do
11
+ before do
12
+ Termtter::Client.plug 'defaults'
13
+ @command = Termtter::Client.commands[:lists]
14
+ end
15
+
16
+ it 'command name is :lists' do
17
+ @command.name.should == :lists
18
+ end
19
+
20
+ it 'should call with no user_name' do
21
+ response = Object.new
22
+ response.stub!(:lists).and_return({})
23
+ @twitter_stub.should_receive(:lists).with('jugyo').and_return(response)
24
+ Termtter::Client.call_commands('lists')
25
+ end
26
+
27
+ it 'should call with user_name' do
28
+ response = Object.new
29
+ response.stub!(:lists).and_return({})
30
+ @twitter_stub.should_receive(:lists).with('termtter').and_return(response)
31
+ Termtter::Client.call_commands('lists termtter')
32
+ end
33
+ end
34
+ end
File without changes
File without changes
@@ -0,0 +1,18 @@
1
+ # -*- coding: utf-8 -*-
2
+ require File.dirname(__FILE__) + '/../spec_helper'
3
+ describe Termtter::Client, 'when the plugin gsub is loaded' do
4
+ it 'plugin gsub' do
5
+ f = nil
6
+ Termtter::Client.should_receive(:register_hook).once do |params|
7
+ f = params[:exec]
8
+ end
9
+ config.plugins.gsub.table = [[/^foo/, 'FOO'], ['bar']]
10
+ Termtter::Client.plug 'gsub'
11
+ f.should_not be_nil
12
+ status_struct = Struct.new(:text)
13
+ statuses = []
14
+ statuses << status_struct.new('foobarbaz')
15
+ f.call(statuses, nil)
16
+ statuses[0].text.should == 'FOObaz'
17
+ end
18
+ end
@@ -0,0 +1,134 @@
1
+ # coding: utf-8
2
+
3
+ require File.dirname(__FILE__) + '/../spec_helper'
4
+ require 'plugins/haml'
5
+
6
+ describe Termtter::Plugins::Haml do
7
+ before do
8
+ Termtter::API.stub!(:twitter).and_return(@twitter = mock(:twitter))
9
+ end
10
+
11
+ subject do
12
+ @config = Termtter::Config.new
13
+ @logger = mock(:logger)
14
+
15
+ Termtter::Plugins::Haml.new(@config, @logger)
16
+ end
17
+
18
+ describe '#run' do
19
+ context 'happy case' do
20
+ before do
21
+ @status = '<hamlified string>'
22
+ subject.should_receive(:haml).with('xhtml').and_return(@status)
23
+ end
24
+
25
+ it 'update status with hamlified string' do
26
+ @twitter.should_receive(:update).with(@status)
27
+ subject.should_receive(:puts).with("=> #{@status}")
28
+
29
+ subject.run('xhtml')
30
+ end
31
+ end
32
+
33
+ context 'error occured in #haml' do
34
+ before do
35
+ subject.should_receive(:haml).and_raise(@error = StandardError.new)
36
+ end
37
+
38
+ it 'records the log' do
39
+ @logger.should_receive(:error).with(@error)
40
+
41
+ subject.run('xhtml')
42
+ end
43
+ end
44
+
45
+ context '#haml returned nil' do
46
+ before do
47
+ subject.should_receive(:haml).and_return(nil)
48
+ end
49
+
50
+ it 'do nothing' do
51
+ subject.run('xhtml')
52
+ end
53
+ end
54
+
55
+ context '#haml returned empty string' do
56
+ before do
57
+ subject.should_receive(:haml).and_return('')
58
+ end
59
+
60
+ it 'do nothing' do
61
+ subject.run('xhtml')
62
+ end
63
+ end
64
+ end
65
+
66
+ describe '#haml' do
67
+ context 'neither argument nor options were specified' do
68
+ before do
69
+ subject.should_receive(:editor).with(:haml).and_return('!!!')
70
+ end
71
+
72
+ it 'render Haml with default options' do
73
+ subject.haml('').should == <<-DTD.chomp
74
+ <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
75
+ DTD
76
+ end
77
+ end
78
+
79
+ context 'argument was specified' do
80
+ before do
81
+ subject.should_receive(:editor).with(:haml).and_return('!!!')
82
+ end
83
+
84
+ it do
85
+ subject.haml('html5').should == '<!DOCTYPE html>'
86
+ end
87
+ end
88
+
89
+ context 'options was specified' do
90
+ before do
91
+ subject.should_receive(:editor).with(:haml).and_return('!!!')
92
+ end
93
+
94
+ it do
95
+ @config.plugins.haml.options = {:format => :html5}
96
+ subject.haml('').should == '<!DOCTYPE html>'
97
+ end
98
+ end
99
+
100
+ context 'both argument and options were specified' do
101
+ before do
102
+ subject.should_receive(:editor).with(:haml).and_return('!!!')
103
+ end
104
+
105
+ it 'gives priority to argument' do
106
+ @config.plugins.haml.options = {:format => :html5}
107
+
108
+ subject.haml('xhtml').should == <<-DTD.chomp
109
+ <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
110
+ DTD
111
+ end
112
+ end
113
+
114
+ context 'argument was invalid' do
115
+ before do
116
+ subject.should_receive(:editor).with(:haml).and_return('!!!')
117
+ end
118
+
119
+ it do
120
+ expect { subject.haml('hoge') }.to raise_error
121
+ end
122
+ end
123
+
124
+ context '#editor returned nil' do
125
+ before do
126
+ subject.should_receive(:editor).with(:haml).and_return(nil)
127
+ end
128
+
129
+ it do
130
+ subject.haml('').should be_nil
131
+ end
132
+ end
133
+ end
134
+ end
@@ -0,0 +1,13 @@
1
+ # -*- coding: utf-8 -*-
2
+ require File.dirname(__FILE__) + '/../spec_helper'
3
+ describe Termtter::Client, 'when the plugin md5pass is loaded' do
4
+ it 'plugin md5pass' do
5
+ config.user_name = 'foo'
6
+ Termtter::Client.should_receive(:register_command).once
7
+ Termtter::Client.should_receive(:create_highline).and_return(
8
+ mock(Termtter::Client, :ask => 'bar')
9
+ )
10
+ Termtter::Client.plug 'md5pass'
11
+ config.password.should == "BuCE5l6YBVd2"
12
+ end
13
+ end
File without changes
File without changes
@@ -5,7 +5,7 @@ Termtter::Client.plug 'defaults/standard_commands'
5
5
 
6
6
  module Termtter
7
7
  describe Client do
8
- it 'shold return registerd commands' do
8
+ it 'returns registerd commands' do
9
9
  [
10
10
  [:update, [:u]], [:direct, [:d]],
11
11
  [:profile, [:p]], [:list, [:l]],
File without changes
@@ -0,0 +1,27 @@
1
+ # -*- coding: utf-8 -*-
2
+
3
+ require File.dirname(__FILE__) + '/../spec_helper'
4
+
5
+ describe Termtter::Client, 'when the plugin truncate is loaded' do
6
+
7
+ it 'should add command truncate' do
8
+ Termtter::RubytterProxy.should_receive(:register_hook).once
9
+ be_quiet { Termtter::Client.plug 'truncate' }
10
+ end
11
+
12
+ it 'should define truncate method' do
13
+ be_quiet { Termtter::Client.plug 'truncate' }
14
+
15
+ truncate('11111').should == '11111'
16
+
17
+ truncate('1' * 140).should == '1' * 140
18
+
19
+ truncate('1' * 141).should == '1' * 137 + '...'
20
+
21
+ truncate('あああああ').should == 'あああああ'
22
+
23
+ truncate('あ' * 140).should == 'あ' * 140
24
+
25
+ truncate('あ' * 141).should == 'あ' * 137 + '...'
26
+ end
27
+ end