chatterbot 0.7.0 → 0.7.1

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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 51a25308f3bbee15e4d9a39112c36f437aacb940
4
- data.tar.gz: 688235a797f6cc29d4ba9f140d4b0860df22e29e
3
+ metadata.gz: 6a201bdebfa6dbcffa480ca035bc84053a6c6a10
4
+ data.tar.gz: 611a0e13a984bdb0afc67a208a011aa6b113e750
5
5
  SHA512:
6
- metadata.gz: 245ebb9adb24c50cb231f200eabb25b8797776f160426a4939dad9514476b4e02cbbe246f58486f67f53ff3d38fe2ef539130a58adb2f470f512d502ded19f91
7
- data.tar.gz: 20f78bcef37a7f3afbbc05c5365acec51e84f282992868ab28f8b29dd29bc068b7d8b0fb8f56cff82d9c788a4e4e5583764ba7921eba23a3fbc1df3e85d07d8d
6
+ metadata.gz: e2fc941f17f82850bef55c0af704b66b65cd1986640f8bdaa2b3ac53c528028a5f9feda5826822eccbc567b1f900ad03bb3a4872ae369b386f88c1d2430ea573
7
+ data.tar.gz: 4d605782e35d922cca012873ef32ea9c82e4aafb1e80a6424074467fdd26c280120f0e9276eff5f3f94826dcc5765265f59f93dbf2473f4666590be0445a205d
data/Gemfile CHANGED
@@ -12,6 +12,8 @@ group :development do
12
12
 
13
13
  gem "shoulda", ">= 0"
14
14
  gem "rspec"
15
+ gem "rake"
16
+ #gem "twitter", "~> 4.4.0"
15
17
 
16
18
  gem "watchr"
17
19
  end
@@ -64,8 +64,10 @@ unless @bot.screen_name.nil?
64
64
  end
65
65
 
66
66
  puts "Storing config info"
67
+ puts @bot.config.inspect
67
68
  @bot.update_config
68
-
69
+ @bot.config = nil
70
+
69
71
  if @skeleton
70
72
  skel_dest = File.join(Dir.getwd, "#{@bot.botname}.rb")
71
73
  if File.exist?(skel_dest)
data/chatterbot.gemspec CHANGED
@@ -29,12 +29,13 @@ Gem::Specification.new do |s|
29
29
  end
30
30
 
31
31
  s.add_runtime_dependency(%q<oauth>, [">= 0"])
32
- s.add_runtime_dependency(%q<twitter>, [">= 4.4.0"])
32
+ s.add_runtime_dependency(%q<twitter>, ["4.8.1"])
33
33
  s.add_runtime_dependency(%q<launchy>, [">= 2.1.2"])
34
34
  s.add_development_dependency(%q<yard>, [">= 0"])
35
35
  s.add_development_dependency(%q<shoulda>, [">= 0"])
36
36
  s.add_development_dependency(%q<rake>, [">= 0"])
37
37
  s.add_development_dependency(%q<rspec>, [">= 2.14.1"])
38
+ s.add_development_dependency(%q<rspec-mocks>, [">= 2.14.1"])
38
39
  s.add_development_dependency(%q<rdoc>, [">= 0"])
39
40
  s.add_development_dependency(%q<simplecov>, [">= 0"])
40
41
  s.add_development_dependency(%q<watchr>, [">= 0"])
@@ -49,6 +49,15 @@ module Chatterbot
49
49
  result = client.search("a")
50
50
  update_since_id(result)
51
51
  end
52
+
53
+ #
54
+ # resets the since_id_reply for this bot to the last mention received
55
+ #
56
+ def reset_since_id_reply
57
+ config[:tmp_since_id_reply] = 0
58
+ result = client.mentions.max_by(&:id)
59
+ update_since_id_reply(result)
60
+ end
52
61
 
53
62
 
54
63
  #
@@ -67,6 +76,7 @@ module Chatterbot
67
76
  :result_type => "recent"
68
77
  }
69
78
  opts[:since_id] = since_id if since_id > 0
79
+ opts[:since_id_reply] = since_id_reply if since_id_reply > 0
70
80
 
71
81
  opts
72
82
  end
@@ -161,14 +171,15 @@ module Chatterbot
161
171
  @access_token = request_token.get_access_token(:oauth_verifier => pin.chomp)
162
172
  get_screen_name
163
173
 
164
- config[:token] = @access_token.token
165
- config[:secret] = @access_token.secret
174
+ self.config[:token] = @access_token.token
175
+ self.config[:secret] = @access_token.secret
166
176
 
167
177
  update_config unless ! do_update_config
168
178
  reset_client
169
179
 
170
180
  rescue OAuth::Unauthorized => e
171
181
  display_oauth_error
182
+ puts e.inspect
172
183
  return false
173
184
  end
174
185
  end
@@ -38,6 +38,7 @@ module Chatterbot
38
38
  def debug_mode=(d)
39
39
  config[:debug_mode] = d
40
40
  end
41
+
41
42
  def no_update=(d)
42
43
  config[:no_update] = d
43
44
  end
@@ -92,7 +93,20 @@ module Chatterbot
92
93
  # return the ID of the most recent tweet pulled up in searches
93
94
  def since_id
94
95
  config[:since_id] || 0
95
- end
96
+ end
97
+
98
+ #
99
+ # store since_id_reply to a different key so that it doesn't actually
100
+ # get updated until the bot is done running
101
+ def since_id_reply=(x)
102
+ config[:tmp_since_id_reply] = x
103
+ end
104
+
105
+ #
106
+ # return the ID of the most recent tweet pulled up in mentions or since_id if since_id_reply is nil
107
+ def since_id_reply
108
+ config[:since_id_reply] || since_id
109
+ end
96
110
 
97
111
  #
98
112
  # write out our config file
@@ -115,6 +129,18 @@ module Chatterbot
115
129
  def max_id_from(s)
116
130
  s.max { |a, b| a.id <=> b.id }.id
117
131
  end
132
+
133
+ #
134
+ # update the since_id_reply with the id of the given tweet,
135
+ # unless it is lower thant what we have already
136
+ #
137
+ def update_since_id_reply(tweet)
138
+ return if tweet.nil? or tweet.class != Twitter::Tweet
139
+
140
+ tmp_id = tweet.id
141
+
142
+ config[:tmp_since_id_reply] = [config[:tmp_since_id_reply].to_i, tmp_id].max
143
+ end
118
144
 
119
145
  #
120
146
  # update the since_id with either the highest ID of the specified
@@ -268,6 +294,7 @@ module Chatterbot
268
294
 
269
295
  # update the since_id now
270
296
  tmp[:since_id] = tmp.delete(:tmp_since_id) unless ! tmp.has_key?(:tmp_since_id)
297
+ tmp[:since_id_reply] = tmp.delete(:tmp_since_id_reply) unless ! tmp.has_key?(:tmp_since_id_reply)
271
298
 
272
299
  tmp
273
300
  end
@@ -302,6 +329,7 @@ module Chatterbot
302
329
  configs = db[:config]
303
330
  data = {
304
331
  :since_id => config.has_key?(:tmp_since_id) ? config[:tmp_since_id] : config[:since_id],
332
+ :since_id_reply => config.has_key?(:tmp_since_id_reply) ? config[:tmp_since_id_reply] : config[:since_id_reply],
305
333
  :token => config[:token],
306
334
  :secret => config[:secret],
307
335
  :consumer_secret => config[:consumer_secret],
data/lib/chatterbot/db.rb CHANGED
@@ -58,6 +58,7 @@ module Chatterbot
58
58
  String :id, :primary_key => true
59
59
 
60
60
  Bignum :since_id
61
+ Bignum :since_id_reply
61
62
 
62
63
  String :secret
63
64
  String :token
@@ -5,7 +5,10 @@ module Chatterbot
5
5
  #
6
6
  # very basic DSL to handle the common stuff you would want to do with a bot.
7
7
  module DSL
8
-
8
+ def client
9
+ bot.client
10
+ end
11
+
9
12
  #
10
13
  # search twitter for the specified terms, then pass any matches to
11
14
  # the block.
@@ -84,6 +87,7 @@ module Chatterbot
84
87
  opts.on('-v', '--verbose', "verbose output to stdout") { params[:verbose] = true }
85
88
  opts.on('--dry-run', "Run the bot in test mode, and also don't update the database") { params[:debug_mode] = true ; params[:no_update] = true }
86
89
  opts.on('-s', '--since_id [ARG]', "Check for tweets since tweet id #[ARG]") { |s| params[:since_id] = s.to_i }
90
+ opts.on('-m', '--since_id_reply [ARG]', "Check for mentions since tweet id #[ARG]") { |s| params[:since_id_reply] = s.to_i }
87
91
  opts.on('-r', '--reset', "Reset your bot to ignore old tweets") {
88
92
  params[:debug_mode] = true
89
93
  params[:reset_since_id] = true
@@ -145,6 +149,11 @@ module Chatterbot
145
149
  end
146
150
  end
147
151
 
152
+ #
153
+ # return a list of users following the bot. This passes directly
154
+ # to the underlying Twitter API call
155
+ # @see http://rdoc.info/gems/twitter/Twitter/API/FriendsAndFollowers#followers-instance_method
156
+ #
148
157
  def followers(opts={})
149
158
  bot.followers(opts)
150
159
  end
@@ -171,7 +180,10 @@ module Chatterbot
171
180
  #
172
181
  # The ID of the most recent tweet processed by the bot
173
182
  #
174
- def since_id
183
+ def since_id(s=nil)
184
+ if s
185
+ bot.config[:since_id] = s
186
+ end
175
187
  bot.config[:since_id]
176
188
  end
177
189
 
@@ -189,7 +201,11 @@ module Chatterbot
189
201
  def token(s)
190
202
  bot.config[:token] = s
191
203
  end
192
-
204
+
205
+ def since_id_reply
206
+ bot.config[:since_id_reply]
207
+ end
208
+
193
209
  #
194
210
  # explicitly save the configuration/state of the bot.
195
211
  #
@@ -8,15 +8,15 @@ module Chatterbot
8
8
  def replies(&block)
9
9
  return unless require_login
10
10
 
11
- debug "check for replies since #{since_id}"
11
+ debug "check for replies since #{since_id_reply}"
12
12
 
13
- opts = since_id > 0 ? {:since_id => since_id} : {}
13
+ opts = since_id_reply > 0 ? {:since_id => since_id_reply} : {}
14
14
  opts[:count] = 200
15
15
 
16
16
  results = client.mentions(opts)
17
17
  results.each { |s|
18
+ update_since_id_reply(s)
18
19
  unless ! block_given? || on_blacklist?(s) || skip_me?(s)
19
- update_since_id(s)
20
20
  yield s
21
21
  end
22
22
  }
@@ -7,11 +7,14 @@ module Chatterbot
7
7
  def generate(bot)
8
8
  path = File.join(Chatterbot.libdir, "..", "templates", "skeleton.txt")
9
9
  src = File.read(path)
10
+ puts bot.config.inspect
10
11
  opts = bot.config.merge({
11
12
  :name => bot.botname,
12
13
  :timestamp => Time.now
13
14
  })
14
15
 
16
+ puts opts.inspect
17
+
15
18
  if RUBY_VERSION =~ /^1\.8\./
16
19
  apply_vars(src, opts)
17
20
  else
@@ -1,3 +1,3 @@
1
1
  module Chatterbot
2
- VERSION = "0.7.0"
2
+ VERSION = "0.7.1"
3
3
  end
@@ -10,7 +10,7 @@ describe "Chatterbot::Blacklist" do
10
10
  describe "skip_me?" do
11
11
  before(:each) do
12
12
  @bot = test_bot
13
- @bot.stub!(:exclude).and_return(["junk", "i hate bots", "foobar", "spam"])
13
+ @bot.stub(:exclude).and_return(["junk", "i hate bots", "foobar", "spam"])
14
14
  end
15
15
 
16
16
  it "blocks tweets with phrases we don't want" do
@@ -35,7 +35,7 @@ describe "Chatterbot::Blacklist" do
35
35
  describe "on_blacklist?" do
36
36
  before(:each) do
37
37
  @bot = test_bot
38
- @bot.stub!(:blacklist).and_return(["skippy", "blippy", "dippy"])
38
+ @bot.stub(:blacklist).and_return(["skippy", "blippy", "dippy"])
39
39
  end
40
40
 
41
41
  it "blocks users we don't want" do
@@ -68,20 +68,20 @@ describe "Chatterbot::Blacklist" do
68
68
  end
69
69
 
70
70
  it "collects name from the db if it exists" do
71
- @bot.stub!(:has_db?).and_return(true)
72
- blacklist_table = mock(Object)
73
- mock_dataset = mock(Object, {:count => 1})
71
+ @bot.stub(:has_db?).and_return(true)
72
+ blacklist_table = double(Object)
73
+ double_dataset = double(Object, {:count => 1})
74
74
  blacklist_table.should_receive(:where).
75
75
  with({ :user => "a"}).
76
- and_return( mock_dataset )
76
+ and_return( double_dataset )
77
77
 
78
78
 
79
- missing_dataset = mock(Object, {:count => 0})
79
+ missing_dataset = double(Object, {:count => 0})
80
80
  blacklist_table.should_receive(:where).
81
81
  with({ :user => "b"}).
82
82
  and_return( missing_dataset )
83
83
 
84
- @bot.stub!(:db).and_return({
84
+ @bot.stub(:db).and_return({
85
85
  :blacklist => blacklist_table
86
86
  })
87
87
  @bot.on_global_blacklist?("a").should == true
data/spec/client_spec.rb CHANGED
@@ -3,14 +3,27 @@ require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
3
3
  describe "Chatterbot::Client" do
4
4
  before(:each) do
5
5
  @bot = Chatterbot::Bot.new
6
- @bot.client = mock(Object)
6
+ @bot.client = double(Object)
7
+ end
8
+
9
+ describe "reset_since_id_reply" do
10
+ it "gets the id of the last reply" do
11
+ bot = test_bot
12
+ bot.stub(:client).and_return(fake_replies(1, 1000))
13
+ bot.client.should_receive(:mentions)
14
+
15
+ bot.reset_since_id_reply
16
+
17
+ bot.config[:tmp_since_id_reply].should == 1000
18
+ end
19
+
7
20
  end
8
21
 
9
22
  describe "reset_since_id" do
10
23
  it "runs a search to get a new max_id" do
11
24
  bot = test_bot
12
25
 
13
- bot.stub!(:client).and_return(fake_search(100, 1))
26
+ bot.stub(:client).and_return(fake_search(100, 1))
14
27
  bot.client.should_receive(:search).with("a")
15
28
  # bot.search("a")
16
29
  bot.reset_since_id
@@ -27,7 +40,7 @@ describe "Chatterbot::Client" do
27
40
 
28
41
  describe "init_client" do
29
42
  before(:each) do
30
- @client = mock(Twitter::Client)
43
+ @client = double(Twitter::Client)
31
44
  @bot.should_receive(:client).and_return(@client)
32
45
  end
33
46
 
@@ -65,14 +78,14 @@ describe "Chatterbot::Client" do
65
78
  end
66
79
 
67
80
  it "handles getting an auth token" do
68
- token = mock(Object,
81
+ token = double(Object,
69
82
  :token => "token",
70
83
  :secret => "secret"
71
84
  )
72
85
 
73
86
  @bot.should_receive(:request_token).and_return(token)
74
87
  token.should_receive(:get_access_token).with(:oauth_verifier => "pin").
75
- and_return(mock(:token => "access_token", :secret => "access_secret"))
88
+ and_return(double(:token => "access_token", :secret => "access_secret"))
76
89
 
77
90
  @bot.should_receive(:get_screen_name)
78
91
  @bot.should_receive(:update_config)
@@ -91,16 +104,16 @@ describe "Chatterbot::Client" do
91
104
 
92
105
  describe "get_screen_name" do
93
106
  before(:each) do
94
- @json = '{"id":12345,"screen_name":"mockbot"}'
107
+ @json = '{"id":12345,"screen_name":"bot"}'
95
108
 
96
- @token = mock(Object)
97
- response = mock(Object, :body => @json)
109
+ @token = double(Object)
110
+ response = double(Object, :body => @json)
98
111
  @token.should_receive(:get).with("/1.1/account/verify_credentials.json").and_return(response)
99
112
  end
100
113
 
101
114
  it "should work" do
102
115
  @bot.get_screen_name(@token)
103
- @bot.screen_name.should == "mockbot"
116
+ @bot.screen_name.should == "bot"
104
117
  end
105
118
  end
106
119
 
data/spec/config_spec.rb CHANGED
@@ -125,13 +125,46 @@ describe "Chatterbot::Config" do
125
125
  end
126
126
  end
127
127
 
128
+ describe "since_id_reply=" do
129
+ it "works" do
130
+
131
+ @bot.since_id_reply = 123
132
+ @bot.config[:tmp_since_id_reply].should == 123
133
+ end
134
+ end
135
+
136
+ describe "update_since_id_reply" do
137
+ it "works with tweets" do
138
+ @bot.config[:tmp_since_id_reply] = 100
139
+
140
+ data = fake_tweet(1000, 1000, true)
141
+ @bot.update_since_id_reply(data)
142
+ @bot.config[:tmp_since_id_reply].should == 1000
143
+ end
144
+
145
+ it "doesn't work with searches" do
146
+ data = fake_search(1000, 1).search
147
+
148
+ @bot.config[:tmp_since_id_reply] = 100
149
+ @bot.update_since_id_reply(data)
150
+ @bot.config[:tmp_since_id_reply].should == 100
151
+ end
152
+
153
+ it "never rolls back" do
154
+ @bot.config[:tmp_since_id_reply] = 100
155
+ data = fake_tweet(50, 50, true)
156
+ @bot.update_since_id(data)
157
+ @bot.config[:tmp_since_id_reply].should == 100
158
+ end
159
+ end
160
+
128
161
  describe "since_id=" do
129
162
  it "works" do
130
163
  @bot.since_id = 123
131
164
  @bot.config[:tmp_since_id].should == 123
132
165
  end
133
166
  end
134
-
167
+
135
168
  describe "update_since_id" do
136
169
  it "works with searches" do
137
170
  data = fake_search(1000, 1).search
@@ -179,8 +212,8 @@ describe "Chatterbot::Config" do
179
212
  end
180
213
 
181
214
  it "doesn't update keys from the global config" do
182
- @bot.stub!(:global_config).and_return({:foo => :bar, :a => :b})
183
- @bot.stub!(:bot_config).and_return({:foo => :bar, :custom => :value})
215
+ @bot.stub(:global_config).and_return({:foo => :bar, :a => :b})
216
+ @bot.stub(:bot_config).and_return({:foo => :bar, :custom => :value})
184
217
 
185
218
  @bot.config = nil
186
219
 
@@ -188,8 +221,8 @@ describe "Chatterbot::Config" do
188
221
  end
189
222
 
190
223
  it "does update keys from the global config if they've been customized" do
191
- @bot.stub!(:global_config).and_return({:foo => :bar, :a => :b})
192
- @bot.stub!(:bot_config).and_return({:foo => :baz, :custom => :value})
224
+ @bot.stub(:global_config).and_return({:foo => :bar, :a => :b})
225
+ @bot.stub(:bot_config).and_return({:foo => :baz, :custom => :value})
193
226
 
194
227
  @bot.config = nil
195
228
 
@@ -200,6 +233,11 @@ describe "Chatterbot::Config" do
200
233
  @bot.config[:tmp_since_id] = 100
201
234
  @bot.config_to_save[:since_id].should == 100
202
235
  end
236
+
237
+ it "updates since_id_reply" do
238
+ @bot.config[:tmp_since_id_reply] = 100
239
+ @bot.config_to_save[:since_id_reply].should == 100
240
+ end
203
241
  end
204
242
 
205
243
 
@@ -283,8 +321,8 @@ describe "Chatterbot::Config" do
283
321
 
284
322
  @src = Tempfile.new("config")
285
323
 
286
- @bot.stub!(:config_file).and_return(@src.path)
287
- @bot.stub!(:config_to_save).and_return(tmp)
324
+ @bot.stub(:config_file).and_return(@src.path)
325
+ @bot.stub(:config_to_save).and_return(tmp)
288
326
  end
289
327
 
290
328
  it "should work" do
data/spec/db_spec.rb CHANGED
@@ -23,7 +23,7 @@ describe "Chatterbot::DB" do
23
23
  context "db interactions" do
24
24
  before(:each) do
25
25
  @bot = Chatterbot::Bot.new
26
- @bot.stub!(:update_config_at_exit)
26
+ @bot.stub(:update_config_at_exit)
27
27
  @bot.config[:db_uri] = @db_uri
28
28
  end
29
29
 
data/spec/dsl_spec.rb CHANGED
@@ -3,10 +3,16 @@ require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
3
3
  describe "Chatterbot::DSL" do
4
4
  describe "client routines" do
5
5
  before(:each) do
6
- @bot = mock(Chatterbot::Bot, :config => {})
6
+ @bot = double(Chatterbot::Bot, :config => {})
7
7
  @bot.send :require, 'chatterbot/dsl'
8
8
 
9
- Chatterbot::DSL.stub!(:bot).and_return(@bot)
9
+ Chatterbot::DSL.stub(:bot).and_return(@bot)
10
+ end
11
+
12
+ describe "client" do
13
+ it "returns the bot object" do
14
+ client.should eql(@bot.client)
15
+ end
10
16
  end
11
17
 
12
18
  describe "blacklist" do
@@ -120,11 +126,23 @@ describe "Chatterbot::DSL" do
120
126
  @bot.should_receive(:config).and_return({:since_id => 1234})
121
127
  since_id.should == 1234
122
128
  end
129
+
130
+ it "can be set" do
131
+ since_id(1234)
132
+ @bot.config[:since_id].should == 1234
133
+ end
134
+ end
135
+
136
+ describe "since_id_reply" do
137
+ it "should pass to bot object" do
138
+ @bot.should_receive(:config).and_return({:since_id_reply => 1234})
139
+ since_id_reply.should == 1234
140
+ end
123
141
  end
124
142
 
125
143
  describe "db" do
126
144
  it "should pass to bot object" do
127
- bot_db = mock(Object)
145
+ bot_db = double(Object)
128
146
  @bot.should_receive(:db).and_return(bot_db)
129
147
 
130
148
  db.should eql(bot_db)
@@ -10,7 +10,7 @@ describe "Chatterbot::Followers" do
10
10
  it "returns followers" do
11
11
  bot = test_bot
12
12
  bot.should_receive(:require_login).and_return(true)
13
- bot.stub!(:client).and_return(fake_followers(3))
13
+ bot.stub(:client).and_return(fake_followers(3))
14
14
 
15
15
  result = bot.followers
16
16
  result.size.should == 3
data/spec/logging_spec.rb CHANGED
@@ -4,8 +4,8 @@ describe "Chatterbot::Logging" do
4
4
  describe "debug logging" do
5
5
  before(:each) do
6
6
  @bot = Chatterbot::Bot.new
7
- @logger = mock(Logger)
8
- @bot.stub!(:logger).and_return(@logger)
7
+ @logger = double(Logger)
8
+ @bot.stub(:logger).and_return(@logger)
9
9
  end
10
10
 
11
11
  it "should call logger on debug" do
@@ -39,10 +39,10 @@ describe "Chatterbot::Logging" do
39
39
  @bot.should_receive(:log_tweets?).and_return(true)
40
40
 
41
41
  @bot.should_receive(:botname).and_return("logger")
42
- Time.stub!(:now).and_return(123)
42
+ Time.stub(:now).and_return(123)
43
43
 
44
- @tweets_table = mock(Object)
45
- @bot.stub!(:db).and_return({
44
+ @tweets_table = double(Object)
45
+ @bot.stub(:db).and_return({
46
46
  :tweets => @tweets_table
47
47
  })
48
48
  end
data/spec/reply_spec.rb CHANGED
@@ -7,26 +7,25 @@ describe "Chatterbot::Reply" do
7
7
  bot.replies
8
8
  end
9
9
 
10
- it "updates since_id when complete" do
10
+ it "updates since_id_reply when complete" do
11
11
  bot = test_bot
12
12
  bot.should_receive(:require_login).and_return(true)
13
- results = fake_replies(100, 1, 1000)
13
+ results = fake_replies(1, 1000)
14
14
 
15
- bot.stub!(:client).and_return(results)
15
+ bot.stub(:client).and_return(results)
16
16
 
17
- bot.replies do |x|
18
- ;
17
+ bot.replies do
19
18
  end
20
19
 
21
- bot.config[:tmp_since_id].should == 1000
20
+ bot.config[:tmp_since_id_reply].should == 1000
22
21
  end
23
22
 
24
23
  it "iterates results" do
25
24
  bot = test_bot
26
25
  bot.should_receive(:require_login).and_return(true)
27
- bot.stub!(:client).and_return(fake_replies(100, 3))
26
+ bot.stub(:client).and_return(fake_replies(3))
28
27
 
29
- bot.should_receive(:update_since_id).exactly(3).times
28
+ bot.should_receive(:update_since_id_reply).exactly(3).times
30
29
 
31
30
  indexes = []
32
31
  bot.replies do |x|
@@ -39,11 +38,9 @@ describe "Chatterbot::Reply" do
39
38
  it "checks blacklist" do
40
39
  bot = test_bot
41
40
  bot.should_receive(:require_login).and_return(true)
42
- bot.stub!(:client).and_return(fake_replies(100, 3))
41
+ bot.stub(:client).and_return(fake_replies(3))
43
42
 
44
- bot.should_receive(:update_since_id).exactly(2).times
45
-
46
- bot.stub!(:on_blacklist?).and_return(true, false)
43
+ bot.stub(:on_blacklist?).and_return(true, false, false)
47
44
 
48
45
 
49
46
  indexes = []
@@ -55,11 +52,11 @@ describe "Chatterbot::Reply" do
55
52
  end
56
53
 
57
54
 
58
- it "passes along since_id" do
55
+ it "passes along since_id_reply" do
59
56
  bot = test_bot
60
57
  bot.should_receive(:require_login).and_return(true)
61
- bot.stub!(:client).and_return(fake_replies(100, 3))
62
- bot.stub!(:since_id).and_return(123)
58
+ bot.stub(:client).and_return(fake_replies(100, 3))
59
+ bot.stub(:since_id_reply).and_return(123)
63
60
 
64
61
  bot.client.should_receive(:mentions).with({:since_id => 123, :count => 200})
65
62
 
@@ -67,14 +64,26 @@ describe "Chatterbot::Reply" do
67
64
  end
68
65
 
69
66
 
70
- it "doesn't pass along invalid since_id" do
67
+ it "doesn't pass along invalid since_id_reply" do
71
68
  bot = test_bot
72
69
  bot.should_receive(:require_login).and_return(true)
73
- bot.stub!(:client).and_return(fake_replies(100, 3))
74
- bot.stub!(:since_id).and_return(0)
70
+ bot.stub(:client).and_return(fake_replies(100, 3))
71
+ bot.stub(:since_id_reply).and_return(0)
75
72
 
76
73
  bot.client.should_receive(:mentions).with({:count => 200})
77
74
 
78
75
  bot.replies
79
76
  end
77
+
78
+ it "pass along since_id if since_id_reply is nil or zero" do
79
+ bot = test_bot
80
+ bot.should_receive(:require_login).and_return(true)
81
+ bot.stub(:client).and_return(fake_replies(100, 3))
82
+ bot.stub(:since_id).and_return(12345)
83
+
84
+ bot.client.should_receive(:mentions).with({:count => 200, :since_id => 12345})
85
+
86
+ bot.replies
87
+
88
+ end
80
89
  end
data/spec/retweet_spec.rb CHANGED
@@ -15,9 +15,9 @@ describe "Chatterbot::Retweet" do
15
15
  bot = test_bot
16
16
 
17
17
  bot.should_receive(:require_login).and_return(true)
18
- bot.stub!(:client).and_return(mock(Twitter::Client))
18
+ bot.stub(:client).and_return(mock(Twitter::Client))
19
19
 
20
- bot.stub!(:debug_mode?).and_return(false)
20
+ bot.stub(:debug_mode?).and_return(false)
21
21
 
22
22
  tweet_id = 12345
23
23
  bot.client.should_receive(:retweet).with(tweet_id)
data/spec/search_spec.rb CHANGED
@@ -30,7 +30,7 @@ describe "Chatterbot::Search" do
30
30
  bot = test_bot
31
31
 
32
32
  data = fake_search(100, 1)
33
- bot.stub!(:search_client).and_return(data)
33
+ bot.stub(:search_client).and_return(data)
34
34
  bot.should_receive(:update_since_id).with(100)
35
35
 
36
36
  bot.search("foo")
@@ -39,7 +39,7 @@ describe "Chatterbot::Search" do
39
39
  it "accepts multiple searches at once" do
40
40
  bot = test_bot
41
41
 
42
- bot.stub!(:search_client).and_return(fake_search(100, 1))
42
+ bot.stub(:search_client).and_return(fake_search(100, 1))
43
43
  bot.search_client.should_receive(:search).with("foo -include:retweets", {:result_type=>"recent"})
44
44
  bot.search_client.should_receive(:search).with("bar -include:retweets", {:result_type=>"recent"})
45
45
 
@@ -49,7 +49,7 @@ describe "Chatterbot::Search" do
49
49
  it "accepts extra params" do
50
50
  bot = test_bot
51
51
 
52
- bot.stub!(:search_client).and_return(fake_search(100, 1))
52
+ bot.stub(:search_client).and_return(fake_search(100, 1))
53
53
  bot.search_client.should_receive(:search).with("foo -include:retweets", {:lang => "en", :result_type=>"recent"})
54
54
 
55
55
  bot.search("foo", :lang => "en")
@@ -58,7 +58,7 @@ describe "Chatterbot::Search" do
58
58
  it "accepts a single search query" do
59
59
  bot = test_bot
60
60
 
61
- bot.stub!(:search_client).and_return(fake_search(100, 1))
61
+ bot.stub(:search_client).and_return(fake_search(100, 1))
62
62
  bot.search_client.should_receive(:search).with("foo -include:retweets", {:result_type=>"recent"})
63
63
 
64
64
  bot.search("foo")
@@ -66,10 +66,11 @@ describe "Chatterbot::Search" do
66
66
 
67
67
  it "passes along since_id" do
68
68
  bot = test_bot
69
- bot.stub!(:since_id).and_return(123)
69
+ bot.stub(:since_id).and_return(123)
70
+ bot.stub(:since_id_reply).and_return(456)
70
71
 
71
- bot.stub!(:search_client).and_return(fake_search(100, 1))
72
- bot.search_client.should_receive(:search).with("foo -include:retweets", {:since_id => 123, :result_type => "recent"})
72
+ bot.stub(:search_client).and_return(fake_search(100, 1))
73
+ bot.search_client.should_receive(:search).with("foo -include:retweets", {:since_id => 123, :result_type => "recent", :since_id_reply => 456})
73
74
 
74
75
  bot.search("foo")
75
76
  end
@@ -77,7 +78,7 @@ describe "Chatterbot::Search" do
77
78
  it "updates since_id when complete" do
78
79
  bot = test_bot
79
80
  results = fake_search(1000, 1)
80
- bot.stub!(:search_client).and_return(results)
81
+ bot.stub(:search_client).and_return(results)
81
82
 
82
83
  bot.should_receive(:update_since_id).with(1000)
83
84
  bot.search("foo")
@@ -85,7 +86,7 @@ describe "Chatterbot::Search" do
85
86
 
86
87
  it "iterates results" do
87
88
  bot = test_bot
88
- bot.stub!(:search_client).and_return(fake_search(100, 3))
89
+ bot.stub(:search_client).and_return(fake_search(100, 3))
89
90
  indexes = []
90
91
 
91
92
  bot.search("foo") do |x|
@@ -97,9 +98,9 @@ describe "Chatterbot::Search" do
97
98
 
98
99
  it "checks blacklist" do
99
100
  bot = test_bot
100
- bot.stub!(:search_client).and_return(fake_search(100, 3))
101
+ bot.stub(:search_client).and_return(fake_search(100, 3))
101
102
 
102
- bot.stub!(:on_blacklist?).and_return(true, false)
103
+ bot.stub(:on_blacklist?).and_return(true, false)
103
104
 
104
105
  indexes = []
105
106
  bot.search("foo") do |x|
@@ -11,7 +11,7 @@ describe "Chatterbot::Skeleton" do
11
11
  :secret => "secret",
12
12
  :token => "token"
13
13
  }
14
- @bot.stub!(:botname).and_return("Skelley_The_Skeleton")
14
+ @bot.stub(:botname).and_return("Skelley_The_Skeleton")
15
15
 
16
16
  @output = Chatterbot::Skeleton.generate(@bot)
17
17
  end
data/spec/spec_helper.rb CHANGED
@@ -21,21 +21,21 @@ Dir["#{File.dirname(__FILE__)}/support/**/*.rb"].each {|f| require f}
21
21
 
22
22
  def test_bot
23
23
  bot = Chatterbot::Bot.new
24
- bot.stub!(:load_config).and_return({})
25
- bot.stub!(:update_config_at_exit)
24
+ bot.stub(:load_config).and_return({})
25
+ bot.stub(:update_config_at_exit)
26
26
  bot
27
27
  end
28
28
 
29
29
  def fake_search(max_id = 100, result_count = 0, id_base=0)
30
- mock(Twitter::Client,
30
+ double(Twitter::Client,
31
31
  :credentials? => true,
32
32
  :search => Twitter::SearchResults.new(:search_metadata => {:max_id => max_id},
33
33
  :statuses => 1.upto(result_count).collect { |i| fake_tweet(i, id_base) } )
34
34
  )
35
35
  end
36
36
 
37
- def fake_replies(max_id = 100, result_count = 0, id_base = 0)
38
- mock(Twitter::Client,
37
+ def fake_replies(result_count = 0, id_base = 0)
38
+ double(Twitter::Client,
39
39
  {
40
40
  :credentials? => true,
41
41
  :mentions => 1.upto(result_count).collect { |i| fake_tweet(i, id_base, true) }
@@ -44,7 +44,7 @@ def fake_replies(max_id = 100, result_count = 0, id_base = 0)
44
44
  end
45
45
 
46
46
  def fake_followers(count)
47
- mock(Twitter::Client,
47
+ double(Twitter::Client,
48
48
  {
49
49
  :credentials? => true,
50
50
  :followers => 1.upto(count).collect { |i| fake_follower(i) }
@@ -69,3 +69,4 @@ end
69
69
  def fake_follower(index=0)
70
70
  Twitter::User.new(:id => index, :name => "Follower #{index}")
71
71
  end
72
+
data/spec/tweet_spec.rb CHANGED
@@ -15,9 +15,9 @@ describe "Chatterbot::Tweet" do
15
15
  bot = test_bot
16
16
 
17
17
  bot.should_receive(:require_login).and_return(true)
18
- bot.stub!(:client).and_return(mock(Twitter::Client))
18
+ bot.stub(:client).and_return(double(Twitter::Client))
19
19
 
20
- bot.stub!(:debug_mode?).and_return(false)
20
+ bot.stub(:debug_mode?).and_return(false)
21
21
 
22
22
  test_str = "test!"
23
23
  bot.client.should_receive(:update).with(test_str, {})
@@ -28,9 +28,9 @@ describe "Chatterbot::Tweet" do
28
28
  bot = test_bot
29
29
 
30
30
  bot.should_receive(:require_login).and_return(true)
31
- bot.stub!(:client).and_return(mock(Twitter::Client))
31
+ bot.stub(:client).and_return(double(Twitter::Client))
32
32
 
33
- bot.stub!(:debug_mode?).and_return(true)
33
+ bot.stub(:debug_mode?).and_return(true)
34
34
 
35
35
  bot.client.should_not_receive(:update)
36
36
  bot.tweet "no tweet!"
@@ -47,9 +47,9 @@ describe "Chatterbot::Tweet" do
47
47
  it "calls client.update with the right values" do
48
48
  bot = test_bot
49
49
  bot.should_receive(:require_login).and_return(true)
50
- bot.stub!(:client).and_return(mock(Twitter::Client))
50
+ bot.stub(:client).and_return(double(Twitter::Client))
51
51
 
52
- bot.stub!(:debug_mode?).and_return(false)
52
+ bot.stub(:debug_mode?).and_return(false)
53
53
 
54
54
  test_str = "test!"
55
55
 
@@ -64,9 +64,9 @@ describe "Chatterbot::Tweet" do
64
64
  it "doesn't reply when debug_mode? is set" do
65
65
  bot = test_bot
66
66
  bot.should_receive(:require_login).and_return(true)
67
- bot.stub!(:client).and_return(mock(Twitter::Client))
67
+ bot.stub(:client).and_return(double(Twitter::Client))
68
68
 
69
- bot.stub!(:debug_mode?).and_return(true)
69
+ bot.stub(:debug_mode?).and_return(true)
70
70
 
71
71
  bot.client.should_not_receive(:update)
72
72
  bot.reply "no reply test!", {:id => 100}
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: chatterbot
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.7.0
4
+ version: 0.7.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Colin Mitchell
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2013-10-30 00:00:00.000000000 Z
11
+ date: 2013-12-18 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: redcarpet
@@ -42,16 +42,16 @@ dependencies:
42
42
  name: twitter
43
43
  requirement: !ruby/object:Gem::Requirement
44
44
  requirements:
45
- - - '>='
45
+ - - '='
46
46
  - !ruby/object:Gem::Version
47
- version: 4.4.0
47
+ version: 4.8.1
48
48
  type: :runtime
49
49
  prerelease: false
50
50
  version_requirements: !ruby/object:Gem::Requirement
51
51
  requirements:
52
- - - '>='
52
+ - - '='
53
53
  - !ruby/object:Gem::Version
54
- version: 4.4.0
54
+ version: 4.8.1
55
55
  - !ruby/object:Gem::Dependency
56
56
  name: launchy
57
57
  requirement: !ruby/object:Gem::Requirement
@@ -122,6 +122,20 @@ dependencies:
122
122
  - - '>='
123
123
  - !ruby/object:Gem::Version
124
124
  version: 2.14.1
125
+ - !ruby/object:Gem::Dependency
126
+ name: rspec-mocks
127
+ requirement: !ruby/object:Gem::Requirement
128
+ requirements:
129
+ - - '>='
130
+ - !ruby/object:Gem::Version
131
+ version: 2.14.1
132
+ type: :development
133
+ prerelease: false
134
+ version_requirements: !ruby/object:Gem::Requirement
135
+ requirements:
136
+ - - '>='
137
+ - !ruby/object:Gem::Version
138
+ version: 2.14.1
125
139
  - !ruby/object:Gem::Dependency
126
140
  name: rdoc
127
141
  requirement: !ruby/object:Gem::Requirement
@@ -246,7 +260,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
246
260
  version: '0'
247
261
  requirements: []
248
262
  rubyforge_project: chatterbot
249
- rubygems_version: 2.0.3
263
+ rubygems_version: 2.1.11
250
264
  signing_key:
251
265
  specification_version: 4
252
266
  summary: A ruby framework for writing Twitter bots