spec/spec_helper.rb in chatterbot-1.0.2 vs spec/spec_helper.rb in chatterbot-2.0.0.pre

- old
+ new

@@ -17,18 +17,23 @@ # This option should be set when all dependencies are being loaded # before a spec run, as is the case in a typical spec helper. It will # cause any verifying double instantiation for a class that does not # exist to raise, protecting against incorrectly spelt names. mocks.verify_doubled_constant_names = true + end + config.after(:each) do + config_file = File.join(File.dirname($0), "#{File.basename($0, ".*")}.yml") + if File.exist?(config_file) + File.delete(config_file) rescue nil + end end end def test_bot bot = Chatterbot::Bot.new allow(bot).to receive(:load_config).and_return({}) - allow(bot).to receive(:update_config_at_exit) bot.reset! bot end def stubbable_client @@ -52,10 +57,16 @@ c = stubbable_client allow(c).to receive_messages(:mentions_timeline => 1.upto(result_count).collect { |i| fake_tweet(i, id_base)}) c end +def fake_direct_messages(result_count = 0, id_base = 0) + c = stubbable_client + allow(c).to receive_messages(:direct_messages_received => 1.upto(result_count).collect { |i| fake_dm(i, id_base)}) + c +end + def fake_home_timeline(result_count = 0, id_base = 0) c = stubbable_client allow(c).to receive_messages(:home_timeline => 1.upto(result_count).collect { |i| fake_tweet(i, id_base)}) c end @@ -75,9 +86,22 @@ :text => "I am a tweet", :user => { :id => 1, :screen_name => "chatterbot" } } Twitter::Tweet.new(x) +end + +def fake_dm(index, id=0) + id = index if id <= 0 + x = { + :from_user => "chatterbot", + :index => index, + :id => id, + :text => "I am a direct message", + :user => { :id => 1, :screen_name => "chatterbot" } + } + + Twitter::DirectMessage.new(x) end def fake_follower(index=0) Twitter::User.new(:id => index, :name => "Follower #{index}", :screen_name => "follower#{index}")