twibot 0.1.2 → 0.1.3
Sign up to get free protection for your applications and to get access to all the features.
- data/Readme.rdoc +10 -11
- data/lib/twibot.rb +1 -1
- data/test/test_bot.rb +27 -24
- data/test/test_config.rb +11 -11
- data/test/test_handler.rb +63 -61
- data/test/test_hash.rb +3 -3
- data/test/test_helper.rb +2 -2
- metadata +1 -1
data/Readme.rdoc
CHANGED
@@ -1,13 +1,13 @@
|
|
1
|
-
=Twibot
|
1
|
+
= Twibot
|
2
2
|
Official URL: http://github.com/cjohansen/twibot/tree/master
|
3
3
|
Christian Johansen (http://www.cjohansen.no)
|
4
4
|
|
5
|
-
==
|
5
|
+
== Description
|
6
6
|
|
7
7
|
Twibot (pronounced like "Abbot"), is a Ruby microframework for creating Twitter
|
8
8
|
bots, heavily inspired by Sinatra.
|
9
9
|
|
10
|
-
==
|
10
|
+
== Usage
|
11
11
|
|
12
12
|
=== Simple example
|
13
13
|
|
@@ -95,22 +95,21 @@ The DSL gives you access to your Twitter client instance through "client" (or "t
|
|
95
95
|
twitter.status :post, "Hello world" # Also: client.status :post, "Hello world"
|
96
96
|
end
|
97
97
|
|
98
|
-
==
|
98
|
+
== Requirements
|
99
99
|
|
100
100
|
Twitter4r. You'll need atleast 0.3.1, which is currently only available from GitHub.
|
101
101
|
Versions of Twitter4r prior to 0.3.1 does not allow for the since_id parameter to be
|
102
102
|
appended to URLs to the REST API. Twibot needs these to only fetch fresh messages
|
103
103
|
and tweets.
|
104
104
|
|
105
|
-
==
|
105
|
+
== Installation
|
106
106
|
|
107
107
|
gem install twibot
|
108
108
|
|
109
109
|
== Is it Ruby 1.9?
|
110
110
|
|
111
|
-
|
112
|
-
|
113
|
-
away if you want to help out!
|
111
|
+
As of Twibot 0.1.3, yes it is! All tests pass, please give feedback from real world
|
112
|
+
usage if you have trouble.
|
114
113
|
|
115
114
|
== Polling
|
116
115
|
|
@@ -132,11 +131,11 @@ As long as Twibot finds any messages and/or tweets, the interval stays the same
|
|
132
131
|
sleep is increased by interval_step configuration option. This happens until it
|
133
132
|
reaches max_interval, where it will stay until Twibot finds anything.
|
134
133
|
|
135
|
-
==
|
134
|
+
== Contributors
|
136
135
|
|
137
|
-
* Dan Van Derveer (bug fixes)
|
136
|
+
* Dan Van Derveer (bug fixes) - http://dan.van.derveer.com/
|
138
137
|
|
139
|
-
==
|
138
|
+
== License
|
140
139
|
|
141
140
|
(The MIT License)
|
142
141
|
|
data/lib/twibot.rb
CHANGED
@@ -7,7 +7,7 @@ require File.join(File.dirname(__FILE__), 'hash')
|
|
7
7
|
module Twibot
|
8
8
|
|
9
9
|
# :stopdoc:
|
10
|
-
VERSION = '0.1.
|
10
|
+
VERSION = '0.1.3'
|
11
11
|
LIBPATH = ::File.expand_path(::File.dirname(__FILE__)) + ::File::SEPARATOR
|
12
12
|
PATH = ::File.dirname(LIBPATH) + ::File::SEPARATOR
|
13
13
|
# :startdoc:
|
data/test/test_bot.rb
CHANGED
@@ -2,19 +2,19 @@ require File.expand_path(File.join(File.dirname(__FILE__), 'test_helper')) unles
|
|
2
2
|
require 'fileutils'
|
3
3
|
|
4
4
|
class TestBot < Test::Unit::TestCase
|
5
|
-
|
5
|
+
should "not raise errors when initialized" do
|
6
6
|
assert_nothing_raised do
|
7
7
|
Twibot::Bot.new Twibot::Config.new
|
8
8
|
end
|
9
9
|
end
|
10
10
|
|
11
|
-
|
11
|
+
should "raise errors when initialized without config file" do
|
12
12
|
assert_raise SystemExit do
|
13
13
|
Twibot::Bot.new
|
14
14
|
end
|
15
15
|
end
|
16
16
|
|
17
|
-
|
17
|
+
should "not raise error on initialize when config file exists" do
|
18
18
|
if File.exists?("config")
|
19
19
|
FileUtils.rm("config/bot.yml")
|
20
20
|
else
|
@@ -30,17 +30,17 @@ class TestBot < Test::Unit::TestCase
|
|
30
30
|
FileUtils.rm_rf("config")
|
31
31
|
end
|
32
32
|
|
33
|
-
|
33
|
+
should "provide configuration settings as methods" do
|
34
34
|
bot = Twibot::Bot.new Twibot::Config.new(:max_interval => 3)
|
35
35
|
assert_equal 3, bot.max_interval
|
36
36
|
end
|
37
37
|
|
38
|
-
|
38
|
+
should "return logger instance" do
|
39
39
|
bot = Twibot::Bot.new(Twibot::Config.default << Twibot::Config.new)
|
40
40
|
assert bot.log.is_a?(Logger)
|
41
41
|
end
|
42
42
|
|
43
|
-
|
43
|
+
should "respect configured log level" do
|
44
44
|
bot = Twibot::Bot.new(Twibot::Config.new(:log_level => "info"))
|
45
45
|
assert_equal Logger::INFO, bot.log.level
|
46
46
|
|
@@ -48,32 +48,32 @@ class TestBot < Test::Unit::TestCase
|
|
48
48
|
assert_equal Logger::WARN, bot.log.level
|
49
49
|
end
|
50
50
|
|
51
|
-
|
51
|
+
should "should return false from receive without handlers" do
|
52
52
|
bot = Twibot::Bot.new(Twibot::Config.new)
|
53
53
|
assert !bot.receive_messages
|
54
54
|
assert !bot.receive_replies
|
55
55
|
assert !bot.receive_tweets
|
56
56
|
end
|
57
57
|
|
58
|
-
|
58
|
+
should "receive message" do
|
59
59
|
bot = Twibot::Bot.new(Twibot::Config.new(:log_level => "error"))
|
60
60
|
bot.add_handler(:message, Twibot::Handler.new)
|
61
|
-
Twitter::Client.any_instance.expects(:messages).with(:received, {}).returns([
|
61
|
+
Twitter::Client.any_instance.expects(:messages).with(:received, {}).returns([twitter_message("cjno", "Hei der!")])
|
62
62
|
|
63
63
|
assert bot.receive_messages
|
64
64
|
end
|
65
65
|
|
66
|
-
|
66
|
+
should "remember last received message" do
|
67
67
|
bot = Twibot::Bot.new(Twibot::Config.new(:log_level => "error"))
|
68
68
|
bot.add_handler(:message, Twibot::Handler.new)
|
69
|
-
Twitter::Client.any_instance.expects(:messages).with(:received, {}).returns([
|
69
|
+
Twitter::Client.any_instance.expects(:messages).with(:received, {}).returns([twitter_message("cjno", "Hei der!")])
|
70
70
|
assert_equal 1, bot.receive_messages
|
71
71
|
|
72
72
|
Twitter::Client.any_instance.expects(:messages).with(:received, { :since_id => 1 }).returns([])
|
73
73
|
assert_equal 0, bot.receive_messages
|
74
74
|
end
|
75
75
|
|
76
|
-
|
76
|
+
should "receive tweet" do
|
77
77
|
bot = Twibot::Bot.new(Twibot::Config.new(:log_level => "error"))
|
78
78
|
bot.add_handler(:tweet, Twibot::Handler.new)
|
79
79
|
Twitter::Client.any_instance.expects(:timeline_for).with(:me, {}).returns([tweet("cjno", "Hei der!")])
|
@@ -81,7 +81,7 @@ class TestBot < Test::Unit::TestCase
|
|
81
81
|
assert_equal 1, bot.receive_tweets
|
82
82
|
end
|
83
83
|
|
84
|
-
|
84
|
+
should "remember received tweets" do
|
85
85
|
bot = Twibot::Bot.new(Twibot::Config.new(:log_level => "error"))
|
86
86
|
bot.add_handler(:tweet, Twibot::Handler.new)
|
87
87
|
Twitter::Client.any_instance.expects(:timeline_for).with(:me, {}).returns([tweet("cjno", "Hei der!")])
|
@@ -91,7 +91,7 @@ class TestBot < Test::Unit::TestCase
|
|
91
91
|
assert_equal 0, bot.receive_tweets
|
92
92
|
end
|
93
93
|
|
94
|
-
|
94
|
+
should "receive reply when tweet starts with login" do
|
95
95
|
bot = Twibot::Bot.new(Twibot::Config.new(:log_level => "error", :login => "irbno"))
|
96
96
|
bot.add_handler(:reply, Twibot::Handler.new)
|
97
97
|
Twitter::Client.any_instance.expects(:status).with(:replies, {}).returns([tweet("cjno", "@irbno Hei der!")])
|
@@ -99,7 +99,7 @@ class TestBot < Test::Unit::TestCase
|
|
99
99
|
assert_equal 1, bot.receive_replies
|
100
100
|
end
|
101
101
|
|
102
|
-
|
102
|
+
should "remember received replies" do
|
103
103
|
bot = Twibot::Bot.new(Twibot::Config.new(:log_level => "error", :login => "irbno"))
|
104
104
|
bot.add_handler(:reply, Twibot::Handler.new)
|
105
105
|
Twitter::Client.any_instance.expects(:status).with(:replies, {}).returns([tweet("cjno", "@irbno Hei der!")])
|
@@ -111,11 +111,11 @@ class TestBot < Test::Unit::TestCase
|
|
111
111
|
end
|
112
112
|
|
113
113
|
class TestBotMacros < Test::Unit::TestCase
|
114
|
-
|
114
|
+
should "provide configure macro" do
|
115
115
|
assert respond_to?(:configure)
|
116
116
|
end
|
117
117
|
|
118
|
-
|
118
|
+
should "yield configuration" do
|
119
119
|
Twibot::Macros.bot = Twibot::Bot.new Twibot::Config.default
|
120
120
|
bot.prompt = false
|
121
121
|
|
@@ -124,12 +124,15 @@ class TestBotMacros < Test::Unit::TestCase
|
|
124
124
|
assert conf.is_a?(Twibot::Config)
|
125
125
|
end
|
126
126
|
|
127
|
-
|
128
|
-
|
129
|
-
|
130
|
-
|
127
|
+
should "add handler" do
|
128
|
+
Twibot::Macros.bot = Twibot::Bot.new Twibot::Config.default
|
129
|
+
bot.prompt = false
|
130
|
+
|
131
|
+
handler = add_handler(:message, ":command", :from => :cjno)
|
132
|
+
assert handler.is_a?(Twibot::Handler), handler.class
|
133
|
+
end
|
131
134
|
|
132
|
-
|
135
|
+
should "provide twitter macro" do
|
133
136
|
assert respond_to?(:twitter)
|
134
137
|
assert respond_to?(:client)
|
135
138
|
end
|
@@ -137,7 +140,7 @@ end
|
|
137
140
|
|
138
141
|
class TestBotHandlers < Test::Unit::TestCase
|
139
142
|
|
140
|
-
|
143
|
+
should "include handlers" do
|
141
144
|
bot = Twibot::Bot.new(Twibot::Config.new)
|
142
145
|
|
143
146
|
assert_not_nil bot.handlers
|
@@ -146,7 +149,7 @@ class TestBotHandlers < Test::Unit::TestCase
|
|
146
149
|
assert_not_nil bot.handlers[:tweet]
|
147
150
|
end
|
148
151
|
|
149
|
-
|
152
|
+
should "add handler" do
|
150
153
|
bot = Twibot::Bot.new(Twibot::Config.new)
|
151
154
|
bot.add_handler :message, Twibot::Handler.new
|
152
155
|
assert_equal 1, bot.handlers[:message].length
|
data/test/test_config.rb
CHANGED
@@ -2,33 +2,33 @@ require File.expand_path(File.join(File.dirname(__FILE__), 'test_helper')) unles
|
|
2
2
|
require 'stringio'
|
3
3
|
|
4
4
|
class TestConfig < Test::Unit::TestCase
|
5
|
-
|
5
|
+
should "default configuration be a hash" do
|
6
6
|
assert_not_nil Twibot::Config::DEFAULT
|
7
7
|
assert Twibot::Config::DEFAULT.is_a?(Hash)
|
8
8
|
end
|
9
9
|
|
10
|
-
|
10
|
+
should "initialize with no options" do
|
11
11
|
assert_hashes_equal({}, Twibot::Config.new.settings)
|
12
12
|
end
|
13
13
|
|
14
|
-
|
14
|
+
should "return config from add" do
|
15
15
|
config = Twibot::Config.new
|
16
16
|
assert_equal config, config.add(Twibot::Config.new)
|
17
17
|
end
|
18
18
|
|
19
|
-
|
19
|
+
should "alias add to <<" do
|
20
20
|
config = Twibot::Config.new
|
21
21
|
assert config.respond_to?(:<<)
|
22
22
|
assert config << Twibot::Config.new
|
23
23
|
end
|
24
24
|
|
25
|
-
|
25
|
+
should "mirror method_missing as config getters" do
|
26
26
|
config = Twibot::Config.default << Twibot::Config.new
|
27
27
|
assert_equal Twibot::Config::DEFAULT[:min_interval], config.min_interval
|
28
28
|
assert_equal Twibot::Config::DEFAULT[:login], config.login
|
29
29
|
end
|
30
30
|
|
31
|
-
|
31
|
+
should "mirror missing methods as config setters" do
|
32
32
|
config = Twibot::Config.default << Twibot::Config.new
|
33
33
|
assert_equal Twibot::Config::DEFAULT[:min_interval], config.min_interval
|
34
34
|
|
@@ -38,7 +38,7 @@ class TestConfig < Test::Unit::TestCase
|
|
38
38
|
assert_equal val + 5, config.min_interval
|
39
39
|
end
|
40
40
|
|
41
|
-
|
41
|
+
should "not override default hash" do
|
42
42
|
config = Twibot::Config.default
|
43
43
|
hash = Twibot::Config::DEFAULT
|
44
44
|
|
@@ -49,7 +49,7 @@ class TestConfig < Test::Unit::TestCase
|
|
49
49
|
assert_hashes_equal hash, Twibot::Config::DEFAULT
|
50
50
|
end
|
51
51
|
|
52
|
-
|
52
|
+
should "return merged configuration from to_hash" do
|
53
53
|
config = Twibot::Config.new
|
54
54
|
config.min_interval = 10
|
55
55
|
config.max_interval = 10
|
@@ -65,7 +65,7 @@ class TestConfig < Test::Unit::TestCase
|
|
65
65
|
end
|
66
66
|
|
67
67
|
class TestCliConfig < Test::Unit::TestCase
|
68
|
-
|
68
|
+
should "configure from options" do
|
69
69
|
config = Twibot::CliConfig.new %w{--min-interval 10 --max-interval 15}
|
70
70
|
assert_equal 10, config.min_interval
|
71
71
|
assert_equal 15, config.max_interval
|
@@ -73,11 +73,11 @@ class TestCliConfig < Test::Unit::TestCase
|
|
73
73
|
end
|
74
74
|
|
75
75
|
class TestFileConfig < Test::Unit::TestCase
|
76
|
-
|
76
|
+
should "subclass config for file config" do
|
77
77
|
assert Twibot::FileConfig.new(StringIO.new).is_a?(Twibot::Config)
|
78
78
|
end
|
79
79
|
|
80
|
-
|
80
|
+
should "read settings from stream" do
|
81
81
|
config = Twibot::FileConfig.new(StringIO.new <<-YAML)
|
82
82
|
min_interval: 10
|
83
83
|
max_interval: 20
|
data/test/test_handler.rb
CHANGED
@@ -1,142 +1,144 @@
|
|
1
1
|
require File.expand_path(File.join(File.dirname(__FILE__), 'test_helper')) unless defined?(Twibot)
|
2
2
|
|
3
3
|
class TestHandler < Test::Unit::TestCase
|
4
|
-
|
5
|
-
|
4
|
+
context "pattern writer" do
|
5
|
+
should "abort on empty values" do
|
6
|
+
handler = Twibot::Handler.new
|
6
7
|
|
7
|
-
|
8
|
-
|
9
|
-
|
8
|
+
handler.pattern = nil
|
9
|
+
assert_nil handler.instance_eval { @options[:pattern] }
|
10
|
+
assert_nil handler.instance_eval { @options[:tokens] }
|
10
11
|
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
12
|
+
handler.pattern = ""
|
13
|
+
assert_nil handler.instance_eval { @options[:pattern] }
|
14
|
+
assert_nil handler.instance_eval { @options[:tokens] }
|
15
|
+
end
|
15
16
|
|
16
|
-
|
17
|
-
|
18
|
-
|
17
|
+
should "turn regular pattern into regex" do
|
18
|
+
handler = Twibot::Handler.new
|
19
|
+
handler.pattern = "command"
|
19
20
|
|
20
|
-
|
21
|
-
|
22
|
-
|
21
|
+
assert_equal(/command(\s.+)?/, handler.instance_eval { @options[:pattern] })
|
22
|
+
assert_equal 0, handler.instance_eval { @options[:tokens] }.length
|
23
|
+
end
|
23
24
|
|
24
|
-
|
25
|
-
|
26
|
-
|
25
|
+
should "convert single named switch to regex" do
|
26
|
+
handler = Twibot::Handler.new
|
27
|
+
handler.pattern = ":command"
|
27
28
|
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
29
|
+
assert_equal(/([^\s]+)(\s.+)?/, handler.instance_eval { @options[:pattern] })
|
30
|
+
assert_equal 1, handler.instance_eval { @options[:tokens] }.length
|
31
|
+
assert_equal :command, handler.instance_eval { @options[:tokens].first }
|
32
|
+
end
|
32
33
|
|
33
|
-
|
34
|
-
|
35
|
-
|
34
|
+
should "convert several named switches to regexen" do
|
35
|
+
handler = Twibot::Handler.new
|
36
|
+
handler.pattern = ":command fixed_word :subcommand"
|
36
37
|
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
38
|
+
assert_equal(/([^\s]+) fixed_word ([^\s]+)(\s.+)?/, handler.instance_eval { @options[:pattern] })
|
39
|
+
assert_equal 2, handler.instance_eval { @options[:tokens] }.length
|
40
|
+
assert_equal :command, handler.instance_eval { @options[:tokens].first }
|
41
|
+
assert_equal :subcommand, handler.instance_eval { @options[:tokens][1] }
|
42
|
+
end
|
42
43
|
|
43
|
-
|
44
|
-
|
44
|
+
should "convert several named switches to regexen specified by options" do
|
45
|
+
handler = Twibot::Handler.new(":time :hour", :hour => /\d\d/)
|
45
46
|
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
47
|
+
assert_equal(/([^\s]+) ((?-mix:\d\d))(\s.+)?/, handler.instance_eval { @options[:pattern] })
|
48
|
+
assert_equal 2, handler.instance_eval { @options[:tokens] }.length
|
49
|
+
assert_equal :time, handler.instance_eval { @options[:tokens].first }
|
50
|
+
assert_equal :hour, handler.instance_eval { @options[:tokens][1] }
|
51
|
+
end
|
50
52
|
end
|
51
53
|
|
52
|
-
|
54
|
+
should "recognize empty pattern" do
|
53
55
|
handler = Twibot::Handler.new
|
54
|
-
message =
|
56
|
+
message = twitter_message "cjno", "A twitter direct message"
|
55
57
|
|
56
58
|
assert handler.recognize?(message)
|
57
59
|
end
|
58
60
|
|
59
|
-
|
61
|
+
should "recognize empty pattern and allowed user" do
|
60
62
|
handler = Twibot::Handler.new "", :from => "cjno"
|
61
|
-
message =
|
63
|
+
message = twitter_message "cjno", "A twitter direct message"
|
62
64
|
assert handler.recognize?(message)
|
63
65
|
|
64
66
|
handler = Twibot::Handler.new "", :from => ["cjno", "irbno"]
|
65
67
|
assert handler.recognize?(message)
|
66
68
|
end
|
67
69
|
|
68
|
-
|
70
|
+
should "not recognize empty pattern and disallowed user" do
|
69
71
|
handler = Twibot::Handler.new "", :from => "irbno"
|
70
|
-
message =
|
72
|
+
message = twitter_message "cjno", "A twitter direct message"
|
71
73
|
assert !handler.recognize?(message)
|
72
74
|
|
73
75
|
handler = Twibot::Handler.new "", :from => ["irbno", "satan"]
|
74
76
|
assert !handler.recognize?(message)
|
75
77
|
end
|
76
78
|
|
77
|
-
|
79
|
+
should "recognize fixed pattern and no user" do
|
78
80
|
handler = Twibot::Handler.new "time"
|
79
|
-
message =
|
81
|
+
message = twitter_message "cjno", "time oslo norway"
|
80
82
|
assert handler.recognize?(message)
|
81
83
|
end
|
82
84
|
|
83
|
-
|
85
|
+
should "recognize dynamic pattern and no user" do
|
84
86
|
handler = Twibot::Handler.new "time :city :country"
|
85
|
-
message =
|
87
|
+
message = twitter_message "cjno", "time oslo norway"
|
86
88
|
assert handler.recognize?(message)
|
87
89
|
end
|
88
90
|
|
89
|
-
|
91
|
+
should "not recognize dynamic pattern and no user" do
|
90
92
|
handler = Twibot::Handler.new "time :city :country"
|
91
|
-
message =
|
93
|
+
message = twitter_message "cjno", "oslo norway what is the time?"
|
92
94
|
assert !handler.recognize?(message)
|
93
95
|
end
|
94
96
|
|
95
|
-
|
97
|
+
should "recognize fixed pattern and user" do
|
96
98
|
handler = Twibot::Handler.new "time", :from => ["cjno", "irbno"]
|
97
|
-
message =
|
99
|
+
message = twitter_message "cjno", "time oslo norway"
|
98
100
|
assert handler.recognize?(message)
|
99
101
|
end
|
100
102
|
|
101
|
-
|
103
|
+
should "recognize dynamic pattern and user" do
|
102
104
|
handler = Twibot::Handler.new "time :city :country", :from => ["cjno", "irbno"]
|
103
|
-
message =
|
105
|
+
message = twitter_message "cjno", "time oslo norway"
|
104
106
|
assert handler.recognize?(message)
|
105
107
|
end
|
106
108
|
|
107
|
-
|
109
|
+
should "not recognize dynamic pattern and user" do
|
108
110
|
handler = Twibot::Handler.new "time :city :country", :from => ["cjno", "irbno"]
|
109
|
-
message =
|
111
|
+
message = twitter_message "dude", "time oslo norway"
|
110
112
|
assert !handler.recognize?(message)
|
111
113
|
end
|
112
114
|
|
113
|
-
|
115
|
+
should "recognize symbol users" do
|
114
116
|
handler = Twibot::Handler.new "time :city :country", :from => [:cjno, :irbno]
|
115
|
-
message =
|
117
|
+
message = twitter_message "dude", "time oslo norway"
|
116
118
|
assert !handler.recognize?(message)
|
117
119
|
|
118
|
-
message =
|
120
|
+
message = twitter_message("cjno", "time oslo norway")
|
119
121
|
assert handler.recognize?(message)
|
120
122
|
end
|
121
123
|
|
122
|
-
|
124
|
+
should "accept options as only argument" do
|
123
125
|
handler = Twibot::Handler.new :from => :cjno
|
124
126
|
assert_equal(:cjno, handler.instance_eval { @options[:from] })
|
125
127
|
assert_nil handler.instance_eval { @options[:pattern] }
|
126
128
|
end
|
127
129
|
|
128
|
-
|
130
|
+
should "provide parameters in params hash" do
|
129
131
|
handler = Twibot::Handler.new("time :city :country", :from => ["cjno", "irbno"]) do |message, params|
|
130
132
|
assert_equal "oslo", params[:city]
|
131
133
|
assert_equal "norway", params[:country]
|
132
134
|
end
|
133
135
|
|
134
|
-
message =
|
136
|
+
message = twitter_message "cjno", "time oslo norway"
|
135
137
|
assert handler.recognize?(message)
|
136
138
|
handler.dispatch(message)
|
137
139
|
end
|
138
140
|
|
139
|
-
|
141
|
+
should "should call constructor block from handle" do
|
140
142
|
handler = Twibot::Handler.new("time :city :country", :from => ["cjno", "irbno"]) do |message, params|
|
141
143
|
raise "Boom!"
|
142
144
|
end
|
data/test/test_hash.rb
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
require File.expand_path(File.join(File.dirname(__FILE__), 'test_helper')) unless defined?(Twibot)
|
2
2
|
|
3
3
|
class TestHash < Test::Unit::TestCase
|
4
|
-
|
4
|
+
should "convert string keys to symbols" do
|
5
5
|
hash = { "one" => 1, "two" => 2 }
|
6
6
|
hash.symbolize_keys!
|
7
7
|
|
@@ -11,7 +11,7 @@ class TestHash < Test::Unit::TestCase
|
|
11
11
|
assert_nil hash["two"]
|
12
12
|
end
|
13
13
|
|
14
|
-
|
14
|
+
should "convert string keys and preserve symbol keys" do
|
15
15
|
hash = { "one" => 1, :two => 2 }
|
16
16
|
hash.symbolize_keys!
|
17
17
|
|
@@ -21,7 +21,7 @@ class TestHash < Test::Unit::TestCase
|
|
21
21
|
assert_nil hash["two"]
|
22
22
|
end
|
23
23
|
|
24
|
-
|
24
|
+
should "convert hashes recursively" do
|
25
25
|
hash = { "one" => 1, :two => { "three" => 3, "four" => 4 } }
|
26
26
|
hash.symbolize_keys!
|
27
27
|
|
data/test/test_helper.rb
CHANGED
@@ -1,5 +1,5 @@
|
|
1
1
|
require 'test/unit'
|
2
|
-
require '
|
2
|
+
require 'shoulda'
|
3
3
|
require 'mocha'
|
4
4
|
require File.join(File.dirname(__FILE__), '../lib/twibot')
|
5
5
|
|
@@ -27,7 +27,7 @@ EOT
|
|
27
27
|
end
|
28
28
|
end
|
29
29
|
|
30
|
-
def
|
30
|
+
def twitter_message(from, text)
|
31
31
|
Twitter::Message.new(:id => 1,
|
32
32
|
:sender => Twitter::User.new(:screen_name => from),
|
33
33
|
:text => text,
|