chatterbot 0.7.1 → 0.9.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 (54) hide show
  1. checksums.yaml +4 -4
  2. data/.travis.yml +1 -1
  3. data/Gemfile +7 -5
  4. data/README.markdown +1 -1
  5. data/Rakefile +8 -0
  6. data/bin/chatterbot-blacklist +2 -0
  7. data/bin/chatterbot-register +2 -0
  8. data/bin/chatterbot-status +2 -0
  9. data/chatterbot.gemspec +6 -6
  10. data/examples/streaming_bot.rb +42 -0
  11. data/lib/chatterbot.rb +16 -1
  12. data/lib/chatterbot/blacklist.rb +3 -1
  13. data/lib/chatterbot/bot.rb +4 -0
  14. data/lib/chatterbot/client.rb +21 -26
  15. data/lib/chatterbot/config.rb +26 -30
  16. data/lib/chatterbot/db.rb +2 -0
  17. data/lib/chatterbot/dsl.rb +117 -3
  18. data/lib/chatterbot/favorite.rb +23 -0
  19. data/lib/chatterbot/followers.rb +9 -0
  20. data/lib/chatterbot/helpers.rb +3 -1
  21. data/lib/chatterbot/logging.rb +4 -3
  22. data/lib/chatterbot/profile.rb +40 -0
  23. data/lib/chatterbot/reply.rb +10 -2
  24. data/lib/chatterbot/retweet.rb +10 -4
  25. data/lib/chatterbot/search.rb +12 -6
  26. data/lib/chatterbot/skeleton.rb +6 -0
  27. data/lib/chatterbot/streaming.rb +67 -0
  28. data/lib/chatterbot/streaming_handler.rb +96 -0
  29. data/lib/chatterbot/tweet.rb +2 -0
  30. data/lib/chatterbot/ui.rb +2 -1
  31. data/lib/chatterbot/utils.rb +11 -0
  32. data/lib/chatterbot/version.rb +1 -1
  33. data/spec/blacklist_spec.rb +24 -23
  34. data/spec/bot_spec.rb +12 -0
  35. data/spec/client_spec.rb +36 -32
  36. data/spec/config_spec.rb +135 -85
  37. data/spec/db_spec.rb +5 -5
  38. data/spec/dsl_spec.rb +74 -27
  39. data/spec/favorite_spec.rb +34 -0
  40. data/spec/followers_spec.rb +32 -11
  41. data/spec/helpers_spec.rb +25 -20
  42. data/spec/logging_spec.rb +16 -15
  43. data/spec/profile_spec.rb +65 -0
  44. data/spec/reply_spec.rb +24 -24
  45. data/spec/retweet_spec.rb +17 -9
  46. data/spec/search_spec.rb +26 -26
  47. data/spec/skeleton_spec.rb +6 -6
  48. data/spec/spec_helper.rb +44 -32
  49. data/spec/streaming_handler_spec.rb +78 -0
  50. data/spec/streaming_spec.rb +172 -0
  51. data/spec/tweet_spec.rb +18 -18
  52. data/spec/utils_spec.rb +29 -0
  53. data/specs.watchr +1 -13
  54. metadata +27 -16
@@ -1,29 +1,30 @@
1
1
  require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
2
+ require 'tempfile'
2
3
 
3
4
  describe "Chatterbot::Logging" do
4
5
  describe "debug logging" do
5
6
  before(:each) do
6
7
  @bot = Chatterbot::Bot.new
7
8
  @logger = double(Logger)
8
- @bot.stub(:logger).and_return(@logger)
9
+ allow(@bot).to receive(:logger).and_return(@logger)
9
10
  end
10
11
 
11
12
  it "should call logger on debug" do
12
- @bot.should_receive(:logging?).and_return(true)
13
- @logger.should_receive(:debug).with("rspec hi!")
13
+ expect(@bot).to receive(:logging?).and_return(true)
14
+ expect(@logger).to receive(:debug).with("rspec hi!")
14
15
  @bot.debug "hi!"
15
16
  end
16
17
 
17
18
  it "should not call logger when not logging desired" do
18
- @bot.should_receive(:logging?).and_return(false)
19
- @logger.should_not_receive(:debug)
19
+ expect(@bot).to receive(:logging?).and_return(false)
20
+ expect(@logger).not_to receive(:debug)
20
21
  @bot.debug "hi!"
21
22
  end
22
23
 
23
24
  it "should call logger and also print output when critical" do
24
- @bot.should_receive(:logging?).and_return(true)
25
- @logger.should_receive(:debug).with("rspec hi!")
26
- @bot.should_receive(:puts).with("hi!")
25
+ expect(@bot).to receive(:logging?).and_return(true)
26
+ expect(@logger).to receive(:debug).with("rspec hi!")
27
+ expect(@bot).to receive(:puts).with("hi!")
27
28
  @bot.critical "hi!"
28
29
  end
29
30
  end
@@ -36,28 +37,28 @@ describe "Chatterbot::Logging" do
36
37
  @bot = Chatterbot::Bot.new
37
38
  @bot.config[:db_uri] = @db_uri
38
39
 
39
- @bot.should_receive(:log_tweets?).and_return(true)
40
+ expect(@bot).to receive(:log_tweets?).and_return(true)
40
41
 
41
- @bot.should_receive(:botname).and_return("logger")
42
- Time.stub(:now).and_return(123)
42
+ expect(@bot).to receive(:botname).and_return("logger")
43
+ allow(Time).to receive(:now).and_return(123)
43
44
 
44
45
  @tweets_table = double(Object)
45
- @bot.stub(:db).and_return({
46
+ allow(@bot).to receive(:db).and_return({
46
47
  :tweets => @tweets_table
47
48
  })
48
49
  end
49
50
 
50
51
  it "logs tweets to the db" do
51
- @tweets_table.should_receive(:insert).with({ :txt => "TEST", :bot => "logger", :created_at => 123})
52
+ expect(@tweets_table).to receive(:insert).with({ :txt => "TEST", :bot => "logger", :created_at => 123})
52
53
  @bot.log "TEST"
53
54
  end
54
55
 
55
56
  it "logs tweets with some source info to the db" do
56
- source_tweet = {:from_user => "replytome", :id => 12345, :text => "i should trigger a bot" }
57
+ source_tweet = Twitter::Tweet.new({:id => 12345, :text => "i should trigger a bot", :user => {:screen_name => "replytome", :id => 456}})
57
58
 
58
59
  params = {:txt=>"TEST", :bot=>"logger", :created_at=>123, :user=>"replytome", :source_id=>12345, :source_tweet=>"i should trigger a bot"}
59
60
 
60
- @tweets_table.should_receive(:insert).with(params)
61
+ expect(@tweets_table).to receive(:insert).with(params)
61
62
 
62
63
  @bot.log "TEST", source_tweet
63
64
  end
@@ -0,0 +1,65 @@
1
+ require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
2
+
3
+ describe "Chatterbot::Profile" do
4
+ describe "#profile_text" do
5
+ let(:user) { fake_user('user', 100) }
6
+ let(:bot) { test_bot }
7
+
8
+
9
+ it "calls require_login" do
10
+ expect(bot).to receive(:require_login).and_return(false)
11
+ bot.profile_text "set my profile!"
12
+ end
13
+
14
+ context "data" do
15
+ before(:each) do
16
+ expect(bot).to receive(:require_login).and_return(true)
17
+ allow(bot).to receive(:client).and_return(double(Twitter::Client))
18
+
19
+ allow(bot).to receive(:debug_mode?).and_return(false)
20
+ end
21
+
22
+ it "calls client.user to get" do
23
+ expect(bot.client).to receive(:user).and_return(user)
24
+ bot.profile_text
25
+ end
26
+
27
+ it "calls client.update_profile to set" do
28
+ expect(bot.client).to receive(:update_profile).with(description:"hello")
29
+ bot.profile_text "hello"
30
+ end
31
+ end
32
+ end
33
+
34
+
35
+ describe "#profile_website" do
36
+ let(:user) { fake_user('user', 100) }
37
+ let(:bot) { test_bot }
38
+
39
+
40
+ it "calls require_login" do
41
+ expect(bot).to receive(:require_login).and_return(false)
42
+ bot.profile_website "set my profile!"
43
+ end
44
+
45
+ context "data" do
46
+ before(:each) do
47
+ expect(bot).to receive(:require_login).and_return(true)
48
+ allow(bot).to receive(:client).and_return(double(Twitter::Client))
49
+
50
+ allow(bot).to receive(:debug_mode?).and_return(false)
51
+ end
52
+
53
+ it "calls client.user to get" do
54
+ expect(bot.client).to receive(:user).and_return(user)
55
+ bot.profile_website
56
+ end
57
+
58
+ it "calls client.update_profile to set" do
59
+ expect(bot.client).to receive(:update_profile).with(url:"http://hello.com")
60
+ bot.profile_website "http://hello.com"
61
+ end
62
+ end
63
+ end
64
+
65
+ end
@@ -3,44 +3,44 @@ require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
3
3
  describe "Chatterbot::Reply" do
4
4
  it "calls require_login" do
5
5
  bot = test_bot
6
- bot.should_receive(:require_login).and_return(false)
6
+ expect(bot).to receive(:require_login).and_return(false)
7
7
  bot.replies
8
8
  end
9
9
 
10
10
  it "updates since_id_reply when complete" do
11
11
  bot = test_bot
12
- bot.should_receive(:require_login).and_return(true)
12
+ expect(bot).to receive(:require_login).and_return(true)
13
13
  results = fake_replies(1, 1000)
14
14
 
15
- bot.stub(:client).and_return(results)
15
+ allow(bot).to receive(:client).and_return(results)
16
16
 
17
17
  bot.replies do
18
18
  end
19
19
 
20
- bot.config[:tmp_since_id_reply].should == 1000
20
+ expect(bot.config[:tmp_since_id_reply]).to eq(1000)
21
21
  end
22
22
 
23
23
  it "iterates results" do
24
24
  bot = test_bot
25
- bot.should_receive(:require_login).and_return(true)
26
- bot.stub(:client).and_return(fake_replies(3))
25
+ expect(bot).to receive(:require_login).and_return(true)
26
+ allow(bot).to receive(:client).and_return(fake_replies(3))
27
27
 
28
- bot.should_receive(:update_since_id_reply).exactly(3).times
28
+ expect(bot).to receive(:update_since_id_reply).exactly(3).times
29
29
 
30
30
  indexes = []
31
31
  bot.replies do |x|
32
32
  indexes << x[:id]
33
33
  end
34
34
 
35
- indexes.should == [1,2,3]
35
+ expect(indexes).to eq([1,2,3])
36
36
  end
37
37
 
38
38
  it "checks blacklist" do
39
39
  bot = test_bot
40
- bot.should_receive(:require_login).and_return(true)
41
- bot.stub(:client).and_return(fake_replies(3))
40
+ expect(bot).to receive(:require_login).and_return(true)
41
+ allow(bot).to receive(:client).and_return(fake_replies(3))
42
42
 
43
- bot.stub(:on_blacklist?).and_return(true, false, false)
43
+ allow(bot).to receive(:on_blacklist?).and_return(true, false, false)
44
44
 
45
45
 
46
46
  indexes = []
@@ -48,17 +48,17 @@ describe "Chatterbot::Reply" do
48
48
  indexes << x[:id]
49
49
  end
50
50
 
51
- indexes.should == [2,3]
51
+ expect(indexes).to eq([2,3])
52
52
  end
53
53
 
54
54
 
55
55
  it "passes along since_id_reply" do
56
56
  bot = test_bot
57
- bot.should_receive(:require_login).and_return(true)
58
- bot.stub(:client).and_return(fake_replies(100, 3))
59
- bot.stub(:since_id_reply).and_return(123)
57
+ expect(bot).to receive(:require_login).and_return(true)
58
+ allow(bot).to receive(:client).and_return(fake_replies(100, 3))
59
+ allow(bot).to receive(:since_id_reply).and_return(123)
60
60
 
61
- bot.client.should_receive(:mentions).with({:since_id => 123, :count => 200})
61
+ expect(bot.client).to receive(:mentions_timeline).with({:since_id => 123, :count => 200})
62
62
 
63
63
  bot.replies
64
64
  end
@@ -66,22 +66,22 @@ describe "Chatterbot::Reply" do
66
66
 
67
67
  it "doesn't pass along invalid since_id_reply" do
68
68
  bot = test_bot
69
- bot.should_receive(:require_login).and_return(true)
70
- bot.stub(:client).and_return(fake_replies(100, 3))
71
- bot.stub(:since_id_reply).and_return(0)
69
+ expect(bot).to receive(:require_login).and_return(true)
70
+ allow(bot).to receive(:client).and_return(fake_replies(100, 3))
71
+ allow(bot).to receive(:since_id_reply).and_return(0)
72
72
 
73
- bot.client.should_receive(:mentions).with({:count => 200})
73
+ expect(bot.client).to receive(:mentions_timeline).with({:count => 200})
74
74
 
75
75
  bot.replies
76
76
  end
77
77
 
78
78
  it "pass along since_id if since_id_reply is nil or zero" do
79
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)
80
+ expect(bot).to receive(:require_login).and_return(true)
81
+ allow(bot).to receive(:client).and_return(fake_replies(100, 3))
82
+ allow(bot).to receive(:since_id).and_return(12345)
83
83
 
84
- bot.client.should_receive(:mentions).with({:count => 200, :since_id => 12345})
84
+ expect(bot.client).to receive(:mentions_timeline).with({:count => 200, :since_id => 12345})
85
85
 
86
86
  bot.replies
87
87
 
@@ -7,21 +7,29 @@ describe "Chatterbot::Retweet" do
7
7
  end
8
8
 
9
9
  it "calls require_login when tweeting" do
10
- @bot.should_receive(:require_login).and_return(false)
10
+ expect(@bot).to receive(:require_login).and_return(false)
11
11
  @bot.retweet "tweet test!"
12
12
  end
13
13
 
14
- it "calls client.retweet with the right values" do
15
- bot = test_bot
14
+ context "data" do
15
+ before(:each) do
16
+ expect(@bot).to receive(:require_login).and_return(true)
17
+ allow(@bot).to receive(:client).and_return(double(Twitter::Client))
16
18
 
17
- bot.should_receive(:require_login).and_return(true)
18
- bot.stub(:client).and_return(mock(Twitter::Client))
19
+ allow(@bot).to receive(:debug_mode?).and_return(false)
20
+ end
19
21
 
20
- bot.stub(:debug_mode?).and_return(false)
22
+ it "calls client.retweet with an id" do
23
+ tweet_id = 12345
24
+ expect(@bot.client).to receive(:retweet).with(tweet_id)
25
+ @bot.retweet(tweet_id)
26
+ end
21
27
 
22
- tweet_id = 12345
23
- bot.client.should_receive(:retweet).with(tweet_id)
24
- bot.retweet(tweet_id)
28
+ it "calls client.retweet with a tweet" do
29
+ t = Twitter::Tweet.new(:id => 7890, :text => "did you know that i hate bots?")
30
+ expect(@bot.client).to receive(:retweet).with(7890)
31
+ @bot.retweet(t)
32
+ end
25
33
  end
26
34
  end
27
35
  end
@@ -7,41 +7,41 @@ describe "Chatterbot::Search" do
7
7
  end
8
8
 
9
9
  it "should tack onto query" do
10
- @bot.exclude_retweets("foo").should == ("foo -include:retweets")
10
+ expect(@bot.exclude_retweets("foo")).to eq("foo -include:retweets")
11
11
  end
12
12
 
13
13
  it "shouldn't tack onto query" do
14
- @bot.exclude_retweets("foo -include:retweets").should == ("foo -include:retweets")
14
+ expect(@bot.exclude_retweets("foo -include:retweets")).to eq("foo -include:retweets")
15
15
  end
16
16
 
17
17
  it "shouldn't tack onto query" do
18
- @bot.exclude_retweets("foo include:retweets").should == ("foo include:retweets")
18
+ expect(@bot.exclude_retweets("foo include:retweets")).to eq("foo include:retweets")
19
19
  end
20
20
  end
21
21
 
22
22
  it "calls search" do
23
23
  bot = Chatterbot::Bot.new
24
- bot.should_receive(:search)
24
+ expect(bot).to receive(:search)
25
25
  bot.search("foo")
26
26
  end
27
27
 
28
28
 
29
29
  it "calls update_since_id" do
30
30
  bot = test_bot
31
-
31
+
32
32
  data = fake_search(100, 1)
33
- bot.stub(:search_client).and_return(data)
34
- bot.should_receive(:update_since_id).with(100)
33
+ allow(bot).to receive(:client).and_return(data)
34
+ expect(bot).to receive(:update_since_id).with(data.search)
35
35
 
36
36
  bot.search("foo")
37
37
  end
38
38
 
39
39
  it "accepts multiple searches at once" do
40
40
  bot = test_bot
41
-
42
- bot.stub(:search_client).and_return(fake_search(100, 1))
43
- bot.search_client.should_receive(:search).with("foo -include:retweets", {:result_type=>"recent"})
44
- bot.search_client.should_receive(:search).with("bar -include:retweets", {:result_type=>"recent"})
41
+
42
+ allow(bot).to receive(:client).and_return(fake_search(100, 1))
43
+ expect(bot.client).to receive(:search).once.ordered.with("foo -include:retweets", {:result_type=>"recent"})
44
+ expect(bot.client).to receive(:search).once.ordered.with("bar -include:retweets", {:result_type=>"recent"})
45
45
 
46
46
  bot.search(["foo", "bar"])
47
47
  end
@@ -49,8 +49,8 @@ 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))
53
- bot.search_client.should_receive(:search).with("foo -include:retweets", {:lang => "en", :result_type=>"recent"})
52
+ allow(bot).to receive(:client).and_return(fake_search(100, 1))
53
+ expect(bot.client).to receive(:search).with("foo -include:retweets", {:lang => "en", :result_type=>"recent"})
54
54
 
55
55
  bot.search("foo", :lang => "en")
56
56
  end
@@ -58,19 +58,19 @@ 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))
62
- bot.search_client.should_receive(:search).with("foo -include:retweets", {:result_type=>"recent"})
61
+ allow(bot).to receive(:client).and_return(fake_search(100, 1))
62
+ expect(bot.client).to receive(:search).with("foo -include:retweets", {:result_type=>"recent"})
63
63
 
64
64
  bot.search("foo")
65
65
  end
66
66
 
67
67
  it "passes along since_id" do
68
68
  bot = test_bot
69
- bot.stub(:since_id).and_return(123)
70
- bot.stub(:since_id_reply).and_return(456)
69
+ allow(bot).to receive(:since_id).and_return(123)
70
+ allow(bot).to receive(:since_id_reply).and_return(456)
71
71
 
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})
72
+ allow(bot).to receive(:client).and_return(fake_search(100, 1))
73
+ expect(bot.client).to receive(:search).with("foo -include:retweets", {:since_id => 123, :result_type => "recent", :since_id_reply => 456})
74
74
 
75
75
  bot.search("foo")
76
76
  end
@@ -78,36 +78,36 @@ describe "Chatterbot::Search" do
78
78
  it "updates since_id when complete" do
79
79
  bot = test_bot
80
80
  results = fake_search(1000, 1)
81
- bot.stub(:search_client).and_return(results)
81
+ allow(bot).to receive(:client).and_return(results)
82
82
 
83
- bot.should_receive(:update_since_id).with(1000)
83
+ expect(bot).to receive(:update_since_id).with(results.search)
84
84
  bot.search("foo")
85
85
  end
86
86
 
87
87
  it "iterates results" do
88
88
  bot = test_bot
89
- bot.stub(:search_client).and_return(fake_search(100, 3))
89
+ allow(bot).to receive(:client).and_return(fake_search(100, 3))
90
90
  indexes = []
91
91
 
92
92
  bot.search("foo") do |x|
93
93
  indexes << x.attrs[:index]
94
94
  end
95
95
 
96
- indexes.should == [1,2,3]
96
+ expect(indexes).to eq([100, 99, 98])
97
97
  end
98
98
 
99
99
  it "checks blacklist" do
100
100
  bot = test_bot
101
- bot.stub(:search_client).and_return(fake_search(100, 3))
101
+ allow(bot).to receive(:client).and_return(fake_search(100, 3))
102
102
 
103
- bot.stub(:on_blacklist?).and_return(true, false)
103
+ allow(bot).to receive(:on_blacklist?).and_return(true, false)
104
104
 
105
105
  indexes = []
106
106
  bot.search("foo") do |x|
107
107
  indexes << x.attrs[:index]
108
108
  end
109
109
 
110
- indexes.should == [2,3]
110
+ expect(indexes).to eq([99, 98])
111
111
  end
112
112
 
113
113
  end
@@ -11,19 +11,19 @@ describe "Chatterbot::Skeleton" do
11
11
  :secret => "secret",
12
12
  :token => "token"
13
13
  }
14
- @bot.stub(:botname).and_return("Skelley_The_Skeleton")
14
+ allow(@bot).to receive(:botname).and_return("Skelley_The_Skeleton")
15
15
 
16
16
  @output = Chatterbot::Skeleton.generate(@bot)
17
17
  end
18
18
 
19
19
  it "should have name" do
20
- @output.should include("Skelley_The_Skeleton")
20
+ expect(@output).to include("Skelley_The_Skeleton")
21
21
  end
22
22
 
23
23
  it "should have auth info" do
24
- @output.should include("'consumer_key'")
25
- @output.should include("'consumer_secret'")
26
- @output.should include("'secret'")
27
- @output.should include("'token'")
24
+ expect(@output).to include("'consumer_key'")
25
+ expect(@output).to include("'consumer_secret'")
26
+ expect(@output).to include("'secret'")
27
+ expect(@output).to include("'token'")
28
28
  end
29
29
  end
@@ -1,72 +1,84 @@
1
1
  # -*- coding: utf-8 -*-
2
2
  require 'simplecov'
3
3
  SimpleCov.start
4
- #$LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
5
- #$LOAD_PATH.unshift(File.dirname(__FILE__))
6
4
 
7
5
  require 'bundler/setup'
8
6
  Bundler.require
9
7
 
10
- #require "twitter_oauth"
11
8
  require "twitter"
12
9
 
13
- #require 'tempfile'
14
- #require 'sqlite3'
15
-
16
-
17
10
  # Requires supporting files with custom matchers and macros, etc,
18
11
  # in ./support/ and its subdirectories.
19
12
  Dir["#{File.dirname(__FILE__)}/support/**/*.rb"].each {|f| require f}
20
13
 
14
+ RSpec.configure do |config|
15
+ config.mock_with :rspec do |mocks|
16
+
17
+ # This option should be set when all dependencies are being loaded
18
+ # before a spec run, as is the case in a typical spec helper. It will
19
+ # cause any verifying double instantiation for a class that does not
20
+ # exist to raise, protecting against incorrectly spelt names.
21
+ mocks.verify_doubled_constant_names = true
22
+
23
+ end
24
+ end
21
25
 
22
26
  def test_bot
23
27
  bot = Chatterbot::Bot.new
24
- bot.stub(:load_config).and_return({})
25
- bot.stub(:update_config_at_exit)
28
+ allow(bot).to receive(:load_config).and_return({})
29
+ allow(bot).to receive(:update_config_at_exit)
30
+ bot.reset!
26
31
  bot
27
32
  end
28
33
 
34
+ def stubbable_client
35
+ c = Twitter::Client.new
36
+ allow(c).to receive_messages(:credentials? => true)
37
+ c
38
+ end
39
+
29
40
  def fake_search(max_id = 100, result_count = 0, id_base=0)
30
- double(Twitter::Client,
31
- :credentials? => true,
32
- :search => Twitter::SearchResults.new(:search_metadata => {:max_id => max_id},
33
- :statuses => 1.upto(result_count).collect { |i| fake_tweet(i, id_base) } )
34
- )
41
+ result = 1.upto(result_count).each_with_index.map { |x, i|
42
+ fake_tweet(max_id - i, id_base)
43
+ }
44
+ allow(result).to receive(:max_id).and_return(max_id)
45
+
46
+ c = stubbable_client
47
+ allow(c).to receive_messages(:search => result)
48
+ c
35
49
  end
36
50
 
37
51
  def fake_replies(result_count = 0, id_base = 0)
38
- double(Twitter::Client,
39
- {
40
- :credentials? => true,
41
- :mentions => 1.upto(result_count).collect { |i| fake_tweet(i, id_base, true) }
42
- }
43
- )
52
+ c = stubbable_client
53
+ allow(c).to receive_messages(:mentions_timeline => 1.upto(result_count).collect { |i| fake_tweet(i, id_base)})
54
+ c
44
55
  end
45
56
 
46
57
  def fake_followers(count)
47
- double(Twitter::Client,
48
- {
49
- :credentials? => true,
50
- :followers => 1.upto(count).collect { |i| fake_follower(i) }
51
- }
52
- )
58
+ c = stubbable_client
59
+ allow(c).to receive_messages(:followers => 1.upto(count).collect { |i| fake_follower(i) })
60
+ c
53
61
  end
54
62
 
55
- def fake_tweet(index, id=0, as_object = false)
63
+ def fake_tweet(index, id=0)
56
64
  id = index if id <= 0
57
65
  x = {
58
66
  :from_user => "chatterbot",
59
67
  :index => index,
60
68
  :id => id,
61
- :user => {
62
- 'screen_name' => "chatterbot"
63
- }
69
+ :text => "I am a tweet",
70
+ :user => { :id => 1, :screen_name => "chatterbot" }
64
71
  }
65
72
 
66
- as_object == true ? Twitter::Tweet.new(x) : x
73
+ Twitter::Tweet.new(x)
67
74
  end
68
75
 
69
76
  def fake_follower(index=0)
70
- Twitter::User.new(:id => index, :name => "Follower #{index}")
77
+ Twitter::User.new(:id => index, :name => "Follower #{index}",
78
+ :screen_name => "follower#{index}")
79
+ end
80
+
81
+ def fake_user(name, id = 1)
82
+ Twitter::User.new(:id => id, :name => name, :screen_name => name)
71
83
  end
72
84