spec/client_spec.rb in chatterbot-0.7.1 vs spec/client_spec.rb in chatterbot-0.9.0

- old
+ new

@@ -1,120 +1,124 @@ require File.expand_path(File.dirname(__FILE__) + '/spec_helper') describe "Chatterbot::Client" do before(:each) do @bot = Chatterbot::Bot.new - @bot.client = double(Object) end + it "should initialize client" do + expect(@bot.client).to be_a(Twitter::REST::Client) + end + it "should initialize streaming client" do + expect(@bot.streaming_client).to be_a(Twitter::Streaming::Client) + end + describe "reset_since_id_reply" do it "gets the id of the last reply" do bot = test_bot - bot.stub(:client).and_return(fake_replies(1, 1000)) - bot.client.should_receive(:mentions) + allow(bot).to receive(:client).and_return(fake_replies(1, 1000)) + expect(bot.client).to receive(:mentions_timeline) bot.reset_since_id_reply - bot.config[:tmp_since_id_reply].should == 1000 + expect(bot.config[:tmp_since_id_reply]).to eq(1000) end - end describe "reset_since_id" do it "runs a search to get a new max_id" do bot = test_bot - bot.stub(:client).and_return(fake_search(100, 1)) - bot.client.should_receive(:search).with("a") -# bot.search("a") + allow(bot).to receive(:client).and_return(fake_search(100, 1)) + expect(bot.client).to receive(:search).with("a") bot.reset_since_id - bot.config[:tmp_since_id].should == 100 + expect(bot.config[:tmp_since_id]).to eq(100) end end it "runs init_client and login on #require_login" do - @bot.should_receive(:init_client).and_return(true) - @bot.should_receive(:login).and_return(true) + expect(@bot).to receive(:init_client).and_return(true) + expect(@bot).to receive(:login).and_return(true) @bot.require_login end describe "init_client" do before(:each) do @client = double(Twitter::Client) - @bot.should_receive(:client).and_return(@client) + expect(@bot).to receive(:client).and_return(@client) end it "returns true when client has credentials" do - @client.should_receive(:credentials?).and_return(true) - @bot.init_client.should == true + expect(@client).to receive(:credentials?).and_return(true) + expect(@bot.init_client).to eq(true) end it "returns false when client does not have credentials" do - @client.should_receive(:credentials?).and_return(false) - @bot.init_client.should == false + expect(@client).to receive(:credentials?).and_return(false) + expect(@bot.init_client).to eq(false) end end it "reset_client resets the client instance" do - @bot.should_receive(:init_client).and_return(true) + expect(@bot).to receive(:init_client).and_return(true) @bot.reset_client end describe "api setup" do it "calls get_api_key" do - @bot.should_receive(:needs_api_key?).and_return(true) - @bot.should_receive(:needs_auth_token?).and_return(false) - @bot.should_receive(:get_api_key) + expect(@bot).to receive(:needs_api_key?).and_return(true) + expect(@bot).to receive(:needs_auth_token?).and_return(false) + expect(@bot).to receive(:get_api_key) @bot.login end end describe "oauth validation" do before(:each) do - @bot.should_receive(:needs_api_key?).and_return(false) - @bot.should_receive(:needs_auth_token?).and_return(true) - @bot.should_receive(:get_oauth_verifier).and_return("pin") + expect(@bot).to receive(:needs_api_key?).and_return(false) + expect(@bot).to receive(:needs_auth_token?).and_return(true) + expect(@bot).to receive(:get_oauth_verifier).and_return("pin") end it "handles getting an auth token" do token = double(Object, :token => "token", :secret => "secret" ) - @bot.should_receive(:request_token).and_return(token) - token.should_receive(:get_access_token).with(:oauth_verifier => "pin"). + expect(@bot).to receive(:request_token).and_return(token) + expect(token).to receive(:get_access_token).with(:oauth_verifier => "pin"). and_return(double(:token => "access_token", :secret => "access_secret")) - @bot.should_receive(:get_screen_name) - @bot.should_receive(:update_config) + expect(@bot).to receive(:get_screen_name) + expect(@bot).to receive(:update_config) @bot.login - @bot.config[:token].should == "access_token" - @bot.config[:secret].should == "access_secret" + expect(@bot.config[:token]).to eq("access_token") + expect(@bot.config[:secret]).to eq("access_secret") end it "handles errors" do - @bot.should_receive(:display_oauth_error) + expect(@bot).to receive(:display_oauth_error) @bot.login end end describe "get_screen_name" do before(:each) do @json = '{"id":12345,"screen_name":"bot"}' @token = double(Object) response = double(Object, :body => @json) - @token.should_receive(:get).with("/1.1/account/verify_credentials.json").and_return(response) + expect(@token).to receive(:get).with("/1.1/account/verify_credentials.json").and_return(response) end it "should work" do @bot.get_screen_name(@token) - @bot.screen_name.should == "bot" + expect(@bot.screen_name).to eq("bot") end end