spec/client_spec.rb in chatterbot-0.5.1 vs spec/client_spec.rb in chatterbot-0.6.1

- old
+ new

@@ -4,16 +4,46 @@ before(:each) do @bot = Chatterbot::Bot.new @bot.client = mock(Object) end + describe "reset_since_id" do + it "runs a search to get a new max_id" do + bot = test_bot + + bot.stub!(:search_client).and_return(fake_search(100, 1)) + bot.search_client.should_receive(:search).with("a") + bot.reset_since_id + + bot.config[:tmp_since_id].should == 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) @bot.require_login end + describe "init_client" do + before(:each) do + @client = mock(Twitter::Client) + @bot.should_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 + end + + it "returns false when client does not have credentials" do + @client.should_receive(:credentials?).and_return(false) + @bot.init_client.should == false + end + end + + it "reset_client resets the client instance" do @bot.should_receive(:init_client).and_return(true) @bot.reset_client end @@ -29,31 +59,31 @@ 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") - @bot.client.should_receive(:request_token).and_return( - mock(:token => "token", - :secret => "secret" - ) - ) - @bot.client.should_receive(:authorize). - with("token", "secret", { :oauth_verifier => "pin"}). - and_return(mock(:token => "access_token", :secret => "access_secret")) end it "handles getting an auth token" do - @bot.client.should_receive(:authorized?).and_return(true) + token = mock(Object, + :token => "token", + :secret => "secret" + ) + + @bot.should_receive(:request_token).and_return(token) + token.should_receive(:get_access_token).with(:oauth_verifier => "pin"). + and_return(mock(:token => "access_token", :secret => "access_secret")) + + @bot.should_receive(:get_screen_name) @bot.should_receive(:update_config) @bot.login @bot.config[:token].should == "access_token" @bot.config[:secret].should == "access_secret" end it "handles errors" do - @bot.client.should_receive(:authorized?).and_return(false) @bot.should_receive(:display_oauth_error) @bot.login end end end