spec/helpers_spec.rb in chatterbot-0.2.8 vs spec/helpers_spec.rb in chatterbot-0.2.9
- old
+ new
@@ -16,25 +16,73 @@
it "#tweet_user works with string" do
bot = Chatterbot::Bot.new
bot.tweet_user("foo").should == "@foo"
bot.tweet_user("@foo").should == "@foo"
end
-
+
+ describe "#from_user" do
+ before(:each) do
+ @bot = Chatterbot::Bot.new
+ end
+
+ it "should accept strings" do
+ @bot.from_user("x").should == "x"
+ end
+
+ it "should accept :from_user" do
+ @bot.from_user(:from_user => "x").should == "x"
+ end
+
+ it "should accept :screen_name" do
+ @bot.from_user(:user => {:screen_name => "x"}).should == "x"
+ end
+ end
+
describe "#botname" do
before(:each) do
+ class TestBot < Chatterbot::Bot; end
@bot = Chatterbot::Bot.new
@bot.client = mock(Object)
end
+ it "can set botname" do
+ @bot = TestBot.new
+ @bot.botname = "foo"
+ @bot.botname.should == "foo"
+ end
+
it "calls botname smartly for inherited classes" do
- class TestBot < Chatterbot::Bot; end
@bot2 = TestBot.new
@bot2.botname.should == "testbot"
end
it "calls botname for non-inherited bots" do
File.should_receive(:basename).and_return("bot")
@bot.botname.should == "bot"
end
+
+ it "uses specified name" do
+ @bot = Chatterbot::Bot.new(:name => 'xyzzy')
+ @bot.botname.should == "xyzzy"
+ end
end
-
+
+ describe "#replace_variables" do
+ before(:each) do
+ @bot = Chatterbot::Bot.new(:name => 'xyzzy')
+ @tweet = {}
+ end
+
+ it "should replace username by calling tweet_user" do
+ @bot.should_receive(:tweet_user).and_return("@foobar")
+ @bot.replace_variables("#USER#", @tweet).should == "@foobar"
+ end
+
+ it "should be fine with not replacing anything" do
+ @bot.replace_variables("foobar", @tweet).should == "foobar"
+ end
+
+ it "should be fine without a tweet" do
+ @bot.replace_variables("foobar").should == "foobar"
+ end
+ end
end