spec/integration/hipbot_spec.rb in hipbot-0.1.0 vs spec/integration/hipbot_spec.rb in hipbot-0.2.0

- old
+ new

@@ -8,36 +8,58 @@ def sender_first_name "you are #{message.sender.split[0]}" end end +class AwesomePlugin < Hipbot::Plugin + on /respond awesome/ do + reply("awesome responded") + end +end + +class CoolPlugin < Hipbot::Plugin + on /respond cool/ do + reply("cool responded") + end +end + class MyHipbot < Hipbot::Bot configure do |config| config.name = 'robbot' config.jid = 'robbot@chat.hipchat.com' config.helpers = HipbotHelpers + config.plugins = [ AwesomePlugin, CoolPlugin.new ] end on /^hello hipbot!$/ do reply("hello!") end + on /you're (.*), robot/ do |adj| reply("I know I'm #{adj}") end + on /hi everyone!/, global: true do reply('hello!') end + on /tell me the project name/ do reply(project_name) end + on /tell me my name/ do reply("you are #{sender.first_name}") end + + default do + reply("I didn't understand you") + end end describe MyHipbot do - # TODO: replace with actual objects + subject { described_class.instance } + let(:room) { Hipbot::Room.create('1', 'private', topic: 'topic') } let(:sender) { Hipbot::User.create('1', 'John Doe') } describe "configuration" do it "should set robot name" do @@ -62,10 +84,15 @@ it "should reply to global message" do subject.expects(:send_to_room).with(room, "hello!") subject.react(sender, room, "hi everyone!") end + + it "should respond with default reply" do + subject.expects(:send_to_room).with(room, "I didn't understand you") + subject.react(sender, room, "@robbot blahlblah") + end end describe "custom helpers" do it "should have access to room variable" do subject.expects(:send_to_room).with(room, 'private project') @@ -73,8 +100,20 @@ end it "should have access to message variable" do subject.expects(:send_to_room).with(room, 'you are John') subject.react(sender, room, '@robbot tell me my name') + end + end + + describe "plugins" do + it "should reply to reaction defined in plugin" do + subject.expects(:send_to_room).with(room, 'awesome responded') + subject.react(sender, room, '@robbot respond awesome') + end + + it "should reply to reaction defined in second plugin" do + subject.expects(:send_to_room).with(room, 'cool responded') + subject.react(sender, room, '@robbot respond cool') end end end