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,5 +1,17 @@
1
1
  require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
2
2
 
3
3
  describe "Chatterbot::Bot" do
4
+ after(:each) do
5
+ b = Chatterbot::Bot.new(:reset_since_id => false)
6
+ end
4
7
 
8
+ describe "reset_bot?" do
9
+ it "should call reset_since_id and update_config" do
10
+ expect_any_instance_of(Chatterbot::Bot).to receive(:reset_since_id)
11
+ expect_any_instance_of(Chatterbot::Bot).to receive(:update_config)
12
+ allow_any_instance_of(Chatterbot::Bot).to receive(:exit)
13
+ b = Chatterbot::Bot.new(:reset_since_id => true)
14
+ end
15
+
16
+ end
5
17
  end
@@ -3,78 +3,82 @@ 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 = double(Object)
7
6
  end
8
7
 
8
+ it "should initialize client" do
9
+ expect(@bot.client).to be_a(Twitter::REST::Client)
10
+ end
11
+ it "should initialize streaming client" do
12
+ expect(@bot.streaming_client).to be_a(Twitter::Streaming::Client)
13
+ end
14
+
9
15
  describe "reset_since_id_reply" do
10
16
  it "gets the id of the last reply" do
11
17
  bot = test_bot
12
- bot.stub(:client).and_return(fake_replies(1, 1000))
13
- bot.client.should_receive(:mentions)
18
+ allow(bot).to receive(:client).and_return(fake_replies(1, 1000))
19
+ expect(bot.client).to receive(:mentions_timeline)
14
20
 
15
21
  bot.reset_since_id_reply
16
22
 
17
- bot.config[:tmp_since_id_reply].should == 1000
23
+ expect(bot.config[:tmp_since_id_reply]).to eq(1000)
18
24
  end
19
-
20
25
  end
21
26
 
22
27
  describe "reset_since_id" do
23
28
  it "runs a search to get a new max_id" do
24
29
  bot = test_bot
25
30
 
26
- bot.stub(:client).and_return(fake_search(100, 1))
27
- bot.client.should_receive(:search).with("a")
28
- # bot.search("a")
31
+ allow(bot).to receive(:client).and_return(fake_search(100, 1))
32
+ expect(bot.client).to receive(:search).with("a")
29
33
  bot.reset_since_id
30
34
 
31
- bot.config[:tmp_since_id].should == 100
35
+ expect(bot.config[:tmp_since_id]).to eq(100)
32
36
  end
33
37
  end
34
38
 
35
39
  it "runs init_client and login on #require_login" do
36
- @bot.should_receive(:init_client).and_return(true)
37
- @bot.should_receive(:login).and_return(true)
40
+ expect(@bot).to receive(:init_client).and_return(true)
41
+ expect(@bot).to receive(:login).and_return(true)
38
42
  @bot.require_login
39
43
  end
40
44
 
41
45
  describe "init_client" do
42
46
  before(:each) do
43
47
  @client = double(Twitter::Client)
44
- @bot.should_receive(:client).and_return(@client)
48
+ expect(@bot).to receive(:client).and_return(@client)
45
49
  end
46
50
 
47
51
  it "returns true when client has credentials" do
48
- @client.should_receive(:credentials?).and_return(true)
49
- @bot.init_client.should == true
52
+ expect(@client).to receive(:credentials?).and_return(true)
53
+ expect(@bot.init_client).to eq(true)
50
54
  end
51
55
 
52
56
  it "returns false when client does not have credentials" do
53
- @client.should_receive(:credentials?).and_return(false)
54
- @bot.init_client.should == false
57
+ expect(@client).to receive(:credentials?).and_return(false)
58
+ expect(@bot.init_client).to eq(false)
55
59
  end
56
60
  end
57
61
 
58
62
 
59
63
  it "reset_client resets the client instance" do
60
- @bot.should_receive(:init_client).and_return(true)
64
+ expect(@bot).to receive(:init_client).and_return(true)
61
65
  @bot.reset_client
62
66
  end
63
67
 
64
68
  describe "api setup" do
65
69
  it "calls get_api_key" do
66
- @bot.should_receive(:needs_api_key?).and_return(true)
67
- @bot.should_receive(:needs_auth_token?).and_return(false)
68
- @bot.should_receive(:get_api_key)
70
+ expect(@bot).to receive(:needs_api_key?).and_return(true)
71
+ expect(@bot).to receive(:needs_auth_token?).and_return(false)
72
+ expect(@bot).to receive(:get_api_key)
69
73
  @bot.login
70
74
  end
71
75
  end
72
76
 
73
77
  describe "oauth validation" do
74
78
  before(:each) do
75
- @bot.should_receive(:needs_api_key?).and_return(false)
76
- @bot.should_receive(:needs_auth_token?).and_return(true)
77
- @bot.should_receive(:get_oauth_verifier).and_return("pin")
79
+ expect(@bot).to receive(:needs_api_key?).and_return(false)
80
+ expect(@bot).to receive(:needs_auth_token?).and_return(true)
81
+ expect(@bot).to receive(:get_oauth_verifier).and_return("pin")
78
82
  end
79
83
 
80
84
  it "handles getting an auth token" do
@@ -83,21 +87,21 @@ describe "Chatterbot::Client" do
83
87
  :secret => "secret"
84
88
  )
85
89
 
86
- @bot.should_receive(:request_token).and_return(token)
87
- token.should_receive(:get_access_token).with(:oauth_verifier => "pin").
90
+ expect(@bot).to receive(:request_token).and_return(token)
91
+ expect(token).to receive(:get_access_token).with(:oauth_verifier => "pin").
88
92
  and_return(double(:token => "access_token", :secret => "access_secret"))
89
93
 
90
- @bot.should_receive(:get_screen_name)
91
- @bot.should_receive(:update_config)
94
+ expect(@bot).to receive(:get_screen_name)
95
+ expect(@bot).to receive(:update_config)
92
96
 
93
97
  @bot.login
94
98
 
95
- @bot.config[:token].should == "access_token"
96
- @bot.config[:secret].should == "access_secret"
99
+ expect(@bot.config[:token]).to eq("access_token")
100
+ expect(@bot.config[:secret]).to eq("access_secret")
97
101
  end
98
102
 
99
103
  it "handles errors" do
100
- @bot.should_receive(:display_oauth_error)
104
+ expect(@bot).to receive(:display_oauth_error)
101
105
  @bot.login
102
106
  end
103
107
  end
@@ -108,12 +112,12 @@ describe "Chatterbot::Client" do
108
112
 
109
113
  @token = double(Object)
110
114
  response = double(Object, :body => @json)
111
- @token.should_receive(:get).with("/1.1/account/verify_credentials.json").and_return(response)
115
+ expect(@token).to receive(:get).with("/1.1/account/verify_credentials.json").and_return(response)
112
116
  end
113
117
 
114
118
  it "should work" do
115
119
  @bot.get_screen_name(@token)
116
- @bot.screen_name.should == "bot"
120
+ expect(@bot.screen_name).to eq("bot")
117
121
  end
118
122
  end
119
123
 
@@ -3,125 +3,157 @@ require 'tempfile'
3
3
 
4
4
  describe "Chatterbot::Config" do
5
5
  before(:each) do
6
- @bot = Chatterbot::Bot.new
6
+ @bot = Chatterbot::Bot.new
7
+ @tmp_config_dest = "/tmp/bot.yml"
8
+ allow(@bot).to receive(:config_file).and_return(@tmp_config_dest)
9
+ end
10
+ after(:each) do
11
+ if File.exist?(@tmp_config_dest)
12
+ File.unlink(@tmp_config_dest)
13
+ end
7
14
  end
8
15
 
9
16
  describe "loading" do
10
17
  it "overrides with incoming params" do
11
- @bot.should_receive(:global_config).and_return({:foo => :bar})
18
+ expect(@bot).to receive(:global_config).and_return({:foo => :bar})
12
19
  tmp = @bot.load_config({:foo => :baz})
13
- tmp[:foo].should == :baz
20
+ expect(tmp[:foo]).to eq(:baz)
14
21
  end
15
22
 
16
23
  it "loads config when we need a variable" do
17
- @bot.should_receive(:load_config).and_return({:foo => :bar})
24
+ expect(@bot).to receive(:load_config).and_return({:foo => :bar})
18
25
  @bot.config = nil
19
26
 
20
- @bot.config[:foo].should == :bar
27
+ expect(@bot.config[:foo]).to eq(:bar)
21
28
  end
22
29
 
23
30
  it "loads both global config and local config" do
24
- @bot.should_receive(:global_config).and_return({:foo => :bar, :a => :b})
25
- @bot.should_receive(:bot_config).and_return({:foo => :baz, :custom => :value})
31
+ expect(@bot).to receive(:global_config).and_return({:foo => :bar, :a => :b})
32
+ expect(@bot).to receive(:bot_config).and_return({:foo => :baz, :custom => :value})
26
33
 
27
- @bot.config = nil
34
+ @bot.config = nil
28
35
 
29
-
30
- @bot.config[:foo].should == :baz
31
- @bot.config[:a].should == :b
32
- @bot.config[:custom].should == :value
36
+ expect(@bot.config[:foo]).to eq(:baz)
37
+ expect(@bot.config[:a]).to eq(:b)
38
+ expect(@bot.config[:custom]).to eq(:value)
39
+ end
40
+
41
+ context "environment variables" do
42
+ before(:each) do
43
+ ENV["chatterbot_consumer_key"] = "env_chatterbot_consumer_key"
44
+ ENV["chatterbot_consumer_secret"] = "env_chatterbot_consumer_secret"
45
+ ENV["chatterbot_token"] = "env_chatterbot_token"
46
+ ENV["chatterbot_secret"] = "env_chatterbot_secret"
47
+ end
48
+
49
+ after(:each) do
50
+ ENV.delete "chatterbot_consumer_key"
51
+ ENV.delete "chatterbot_consumer_secret"
52
+ ENV.delete "chatterbot_token"
53
+ ENV.delete "chatterbot_secret"
54
+ end
55
+
56
+ it "checks for environment variables" do
57
+ @bot.config = nil
58
+ @bot.load_config
59
+
60
+ expect(@bot.config[:consumer_key]).to eq("env_chatterbot_consumer_key")
61
+ expect(@bot.config[:consumer_secret]).to eq("env_chatterbot_consumer_secret")
62
+ expect(@bot.config[:token]).to eq("env_chatterbot_token")
63
+ expect(@bot.config[:secret]).to eq("env_chatterbot_secret")
64
+ end
33
65
  end
34
66
 
35
67
  it "update_config? is true by default" do
36
- @bot.update_config?.should == true
68
+ expect(@bot.update_config?).to eq(true)
37
69
  end
38
70
 
39
71
  it "update_config? is false if this is a dry run" do
40
72
  @bot.config[:no_update] = true
41
- @bot.update_config?.should == false
73
+ expect(@bot.update_config?).to eq(false)
42
74
  end
43
75
 
44
76
 
45
77
  it "returns a log dest" do
46
- @bot.should_receive(:load_config).and_return({:log_dest => :bar})
78
+ expect(@bot).to receive(:load_config).and_return({:log_dest => :bar})
47
79
  @bot.config = nil
48
80
 
49
- @bot.log_dest.should == :bar
81
+ expect(@bot.log_dest).to eq(:bar)
50
82
  end
51
83
 
52
84
  it "checks for an auth_token" do
53
- @bot.should_receive(:load_config).and_return({:token => "123"})
85
+ expect(@bot).to receive(:load_config).and_return({:token => "123"})
54
86
  @bot.config = nil
55
87
 
56
- @bot.needs_auth_token?.should == false
88
+ expect(@bot.needs_auth_token?).to eq(false)
57
89
  end
58
90
 
59
91
  it "checks for an auth_token" do
60
- @bot.should_receive(:load_config).and_return({})
92
+ expect(@bot).to receive(:load_config).and_return({})
61
93
  @bot.config = nil
62
94
 
63
- @bot.needs_auth_token?.should == true
95
+ expect(@bot.needs_auth_token?).to eq(true)
64
96
  end
65
97
 
66
98
 
67
99
  it "checks for an API key" do
68
- @bot.should_receive(:load_config).and_return({})
100
+ expect(@bot).to receive(:load_config).and_return({})
69
101
  @bot.config = nil
70
102
 
71
- @bot.needs_api_key?.should == true
103
+ expect(@bot.needs_api_key?).to eq(true)
72
104
 
73
105
  @bot.config = {:consumer_key => "ck", :consumer_secret => "cs" }
74
- @bot.needs_api_key?.should == false
106
+ expect(@bot.needs_api_key?).to eq(false)
75
107
  end
76
108
  end
77
109
 
78
110
  describe "debug_mode=" do
79
111
  it "works" do
80
112
  @bot.debug_mode = true
81
- @bot.config[:debug_mode].should == true
113
+ expect(@bot.config[:debug_mode]).to eq(true)
82
114
  end
83
115
  end
84
116
 
85
117
  describe "no_update=" do
86
118
  it "works" do
87
119
  @bot.no_update = true
88
- @bot.config[:no_update].should == true
120
+ expect(@bot.config[:no_update]).to eq(true)
89
121
  end
90
122
  end
91
123
 
92
124
  describe "verbose=" do
93
125
  it "works" do
94
126
  @bot.verbose = true
95
- @bot.config[:verbose].should == true
127
+ expect(@bot.config[:verbose]).to eq(true)
96
128
  end
97
129
  end
98
130
 
99
131
  describe "reset_bot?" do
100
132
  it "works when reset_bot isn't set" do
101
- @bot.reset_bot?.should == false
133
+ expect(@bot.reset_bot?).to eq(false)
102
134
  end
103
135
 
104
136
  it "works when reset_bot is set" do
105
137
  @bot.config[:reset_since_id] = false
106
- @bot.reset_bot?.should == false
138
+ expect(@bot.reset_bot?).to eq(false)
107
139
 
108
140
  @bot.config[:reset_since_id] = true
109
- @bot.reset_bot?.should == true
141
+ expect(@bot.reset_bot?).to eq(true)
110
142
  end
111
143
  end
112
144
 
113
145
 
114
146
  describe "debug_mode?" do
115
147
  it "works when debug_mode isn't set" do
116
- @bot.debug_mode?.should == false
148
+ expect(@bot.debug_mode?).to eq(false)
117
149
  end
118
150
 
119
151
  it "works when debug_mode is set" do
120
152
  @bot.config[:debug_mode] = false
121
- @bot.debug_mode?.should == false
153
+ expect(@bot.debug_mode?).to eq(false)
122
154
 
123
155
  @bot.config[:debug_mode] = true
124
- @bot.debug_mode?.should == true
156
+ expect(@bot.debug_mode?).to eq(true)
125
157
  end
126
158
  end
127
159
 
@@ -129,7 +161,7 @@ describe "Chatterbot::Config" do
129
161
  it "works" do
130
162
 
131
163
  @bot.since_id_reply = 123
132
- @bot.config[:tmp_since_id_reply].should == 123
164
+ expect(@bot.config[:tmp_since_id_reply]).to eq(123)
133
165
  end
134
166
  end
135
167
 
@@ -137,9 +169,9 @@ describe "Chatterbot::Config" do
137
169
  it "works with tweets" do
138
170
  @bot.config[:tmp_since_id_reply] = 100
139
171
 
140
- data = fake_tweet(1000, 1000, true)
172
+ data = fake_tweet(1000, 1000)
141
173
  @bot.update_since_id_reply(data)
142
- @bot.config[:tmp_since_id_reply].should == 1000
174
+ expect(@bot.config[:tmp_since_id_reply]).to eq(1000)
143
175
  end
144
176
 
145
177
  it "doesn't work with searches" do
@@ -147,21 +179,21 @@ describe "Chatterbot::Config" do
147
179
 
148
180
  @bot.config[:tmp_since_id_reply] = 100
149
181
  @bot.update_since_id_reply(data)
150
- @bot.config[:tmp_since_id_reply].should == 100
182
+ expect(@bot.config[:tmp_since_id_reply]).to eq(100)
151
183
  end
152
184
 
153
185
  it "never rolls back" do
154
186
  @bot.config[:tmp_since_id_reply] = 100
155
- data = fake_tweet(50, 50, true)
187
+ data = fake_tweet(50, 50)
156
188
  @bot.update_since_id(data)
157
- @bot.config[:tmp_since_id_reply].should == 100
189
+ expect(@bot.config[:tmp_since_id_reply]).to eq(100)
158
190
  end
159
191
  end
160
192
 
161
193
  describe "since_id=" do
162
194
  it "works" do
163
195
  @bot.since_id = 123
164
- @bot.config[:tmp_since_id].should == 123
196
+ expect(@bot.config[:tmp_since_id]).to eq(123)
165
197
  end
166
198
  end
167
199
 
@@ -171,72 +203,90 @@ describe "Chatterbot::Config" do
171
203
 
172
204
  @bot.config[:tmp_since_id] = 100
173
205
  @bot.update_since_id(data)
174
- @bot.config[:tmp_since_id].should == 1000
206
+ expect(@bot.config[:tmp_since_id]).to eq(1000)
175
207
  end
176
208
 
209
+ it "works with SearchResults" do
210
+ s = Twitter::SearchResults.new(
211
+ {:search_metadata => {:max_id => 1000}},
212
+ double(Twitter::Request, :client => nil, :verb => nil, :path => nil, :options => nil)
213
+ )
214
+
215
+ @bot.config[:tmp_since_id] = 100
216
+ @bot.update_since_id(s)
217
+ expect(@bot.config[:tmp_since_id]).to eq(1000)
218
+ end
219
+
177
220
  it "works with tweets" do
178
221
  @bot.config[:tmp_since_id] = 100
179
222
 
180
- data = fake_tweet(1000, 1000, true)
223
+ data = fake_tweet(1000, 1000)
181
224
  @bot.update_since_id(data)
182
- @bot.config[:tmp_since_id].should == 1000
225
+ expect(@bot.config[:tmp_since_id]).to eq(1000)
183
226
  end
184
227
 
185
228
  it "works with arrays" do
186
229
  @bot.config[:tmp_since_id] = 100
187
230
 
188
231
  data = [
189
- fake_tweet(500, 1000, true),
190
- fake_tweet(1000, 1000, true),
191
- fake_tweet(400, 1000, true)
232
+ fake_tweet(500, 1000),
233
+ fake_tweet(1000, 1000),
234
+ fake_tweet(400, 1000)
192
235
  ]
193
236
 
194
237
  @bot.update_since_id(data)
195
- @bot.config[:tmp_since_id].should == 1000
238
+ expect(@bot.config[:tmp_since_id]).to eq(1000)
239
+ end
240
+
241
+ it "works with an id" do
242
+ @bot.config[:tmp_since_id] = 100
243
+
244
+ @bot.update_since_id(1000)
245
+ expect(@bot.config[:tmp_since_id]).to eq(1000)
196
246
  end
197
247
 
198
248
  it "never rolls back" do
199
249
  @bot.config[:tmp_since_id] = 100
200
- data = fake_tweet(50, 50, true)
250
+ data = fake_tweet(50, 50)
201
251
  @bot.update_since_id(data)
202
- @bot.config[:tmp_since_id].should == 100
252
+ expect(@bot.config[:tmp_since_id]).to eq(100)
203
253
  end
204
254
  end
205
255
 
206
256
 
207
257
  describe "update_config" do
208
258
  it "doesn't update the config if update_config? is false" do
209
- @bot.should_receive(:update_config?).and_return(false)
210
- @bot.should_not_receive(:has_db?)
259
+ expect(@bot).to receive(:update_config?).and_return(false)
260
+ expect(@bot).not_to receive(:has_db?)
211
261
  @bot.update_config
212
262
  end
213
263
 
214
264
  it "doesn't update keys from the global config" do
215
- @bot.stub(:global_config).and_return({:foo => :bar, :a => :b})
216
- @bot.stub(:bot_config).and_return({:foo => :bar, :custom => :value})
265
+ allow(@bot).to receive(:global_config).and_return({:foo => :bar, :a => :b})
266
+ allow(@bot).to receive(:bot_config).and_return({:foo => :bar, :custom => :value})
217
267
 
218
268
  @bot.config = nil
219
269
 
220
- @bot.config_to_save.should == { :custom => :value }
270
+ expect(@bot.config_to_save).to eq({ :custom => :value })
221
271
  end
222
272
 
223
273
  it "does update keys from the global config if they've been customized" do
224
- @bot.stub(:global_config).and_return({:foo => :bar, :a => :b})
225
- @bot.stub(:bot_config).and_return({:foo => :baz, :custom => :value})
274
+ allow(@bot).to receive(:global_config).and_return({:foo => :bar, :a => :b})
275
+ allow(@bot).to receive(:bot_config).and_return({:foo => :baz, :custom => :value})
226
276
 
227
277
  @bot.config = nil
228
278
 
229
- @bot.config_to_save.should == { :foo => :baz, :custom => :value }
279
+ expect(@bot.config_to_save).to eq({ :foo => :baz, :custom => :value })
230
280
  end
231
281
 
232
282
  it "updates since_id" do
233
283
  @bot.config[:tmp_since_id] = 100
234
- @bot.config_to_save[:since_id].should == 100
284
+ expect(@bot.config_to_save[:since_id]).to eq(100)
235
285
  end
236
286
 
237
287
  it "updates since_id_reply" do
238
288
  @bot.config[:tmp_since_id_reply] = 100
239
- @bot.config_to_save[:since_id_reply].should == 100
289
+ expect(@bot.config_to_save[:since_id_reply]).to eq(100)
240
290
  end
241
291
  end
242
292
 
@@ -244,39 +294,39 @@ describe "Chatterbot::Config" do
244
294
  describe "global config files" do
245
295
  it "has an array of global_config_files" do
246
296
  ENV["chatterbot_config"] = "/tmp/foo.yml"
247
- @bot.global_config_files.first.should == "/etc/chatterbot.yml"
248
- @bot.global_config_files[1].should == "/tmp/foo.yml"
249
- @bot.global_config_files.last.should include("/global.yml")
297
+ expect(@bot.global_config_files.first).to eq("/etc/chatterbot.yml")
298
+ expect(@bot.global_config_files[1]).to eq("/tmp/foo.yml")
299
+ expect(@bot.global_config_files.last).to include("/global.yml")
250
300
  end
251
301
 
252
302
  it "slurps in all the global_config_files" do
253
- @bot.stub(:global_config_files).and_return(["config.yml", "config2.yml", "config3.yml"])
254
- @bot.should_receive(:slurp_file).with("config.yml").and_return({:a => 1 })
255
- @bot.should_receive(:slurp_file).with("config2.yml").and_return({:b => 2 })
256
- @bot.should_receive(:slurp_file).with("config3.yml").and_return({:c => 3 })
303
+ allow(@bot).to receive(:global_config_files).and_return(["config.yml", "config2.yml", "config3.yml"])
304
+ expect(@bot).to receive(:slurp_file).with("config.yml").and_return({:a => 1 })
305
+ expect(@bot).to receive(:slurp_file).with("config2.yml").and_return({:b => 2 })
306
+ expect(@bot).to receive(:slurp_file).with("config3.yml").and_return({:c => 3 })
257
307
 
258
- @bot.global_config.should == { :a => 1, :b => 2, :c => 3}
308
+ expect(@bot.global_config).to eq({ :a => 1, :b => 2, :c => 3})
259
309
  end
260
310
 
261
311
  it "priorities last file in list" do
262
- @bot.stub(:global_config_files).and_return(["config.yml", "config2.yml", "config3.yml"])
263
- @bot.should_receive(:slurp_file).with("config.yml").and_return({:a => 1 })
264
- @bot.should_receive(:slurp_file).with("config2.yml").and_return({:b => 2 })
265
- @bot.should_receive(:slurp_file).with("config3.yml").and_return({:a => 100, :b => 50, :c => 3 })
266
- @bot.global_config.should == { :a => 100, :b => 50, :c => 3}
312
+ allow(@bot).to receive(:global_config_files).and_return(["config.yml", "config2.yml", "config3.yml"])
313
+ expect(@bot).to receive(:slurp_file).with("config.yml").and_return({:a => 1 })
314
+ expect(@bot).to receive(:slurp_file).with("config2.yml").and_return({:b => 2 })
315
+ expect(@bot).to receive(:slurp_file).with("config3.yml").and_return({:a => 100, :b => 50, :c => 3 })
316
+ expect(@bot.global_config).to eq({ :a => 100, :b => 50, :c => 3})
267
317
  end
268
318
  end
269
319
 
270
320
 
271
321
  describe "working_dir" do
272
322
  it "returns getwd for chatterbot scripts" do
273
- @bot.should_receive(:chatterbot_helper?).and_return(true)
274
- @bot.working_dir.should == Dir.getwd
323
+ expect(@bot).to receive(:chatterbot_helper?).and_return(true)
324
+ expect(@bot.working_dir).to eq(Dir.getwd)
275
325
  end
276
326
 
277
327
  it "returns calling dir for non-chatterbot scripts" do
278
- @bot.should_receive(:chatterbot_helper?).and_return(false)
279
- @bot.working_dir.should == File.dirname($0)
328
+ expect(@bot).to receive(:chatterbot_helper?).and_return(false)
329
+ expect(@bot.working_dir).to eq(File.dirname($0))
280
330
  end
281
331
  end
282
332
 
@@ -288,7 +338,7 @@ describe "Chatterbot::Config" do
288
338
  src << tmp.to_yaml
289
339
  src.flush
290
340
 
291
- @bot.slurp_file(src.path).should == tmp
341
+ expect(@bot.slurp_file(src.path)).to eq(tmp)
292
342
  end
293
343
 
294
344
  it "symbolizes keys" do
@@ -298,19 +348,19 @@ describe "Chatterbot::Config" do
298
348
  src << tmp.to_yaml
299
349
  src.flush
300
350
 
301
- @bot.slurp_file(src.path).should == { :since_id => 0 }
351
+ expect(@bot.slurp_file(src.path)).to eq({ :since_id => 0 })
302
352
  end
303
353
 
304
354
  it "doesn't store local file if we can store to db instead" do
305
- @bot.should_receive(:has_db?).and_return(true)
306
- @bot.should_receive(:store_database_config)
355
+ expect(@bot).to receive(:has_db?).and_return(true)
356
+ expect(@bot).to receive(:store_database_config)
307
357
  @bot.update_config
308
358
  end
309
359
 
310
360
  it "stores local file if no db" do
311
- @bot.should_receive(:has_db?).and_return(false)
312
- @bot.should_not_receive(:store_database_config)
313
- @bot.should_receive(:store_local_config)
361
+ expect(@bot).to receive(:has_db?).and_return(false)
362
+ expect(@bot).not_to receive(:store_database_config)
363
+ expect(@bot).to receive(:store_local_config)
314
364
  @bot.update_config
315
365
  end
316
366
  end
@@ -321,13 +371,13 @@ describe "Chatterbot::Config" do
321
371
 
322
372
  @src = Tempfile.new("config")
323
373
 
324
- @bot.stub(:config_file).and_return(@src.path)
325
- @bot.stub(:config_to_save).and_return(tmp)
374
+ allow(@bot).to receive(:config_file).and_return(@src.path)
375
+ allow(@bot).to receive(:config_to_save).and_return(tmp)
326
376
  end
327
377
 
328
378
  it "should work" do
329
379
  @bot.store_local_config
330
- @bot.slurp_file(@src.path).should == { :x => 123, :foo => :bar }
380
+ expect(@bot.slurp_file(@src.path)).to eq({ :x => 123, :foo => :bar })
331
381
  end
332
382
  end
333
383