lib/boty/rspec.rb in boty-0.0.16 vs lib/boty/rspec.rb in boty-0.0.17
- old
+ new
@@ -1,41 +1,49 @@
module Boty
module RSpec
module Bot
+ require File.expand_path "../../../spec/support/slack_support", __FILE__
+
def self.included(base)
base.instance_eval do
- let(:bot) {
- bot = Boty::Bot.new({"id" => "1234", "name" => "bot"},
- Boty::Session.new)
+ include SlackSupport::Users
- class << bot
- attr_accessor :_response
+ before do
+ @_bot = Boty::Bot.new(
+ {"id" => "1234", "name" => "bot"},
+ Boty::Session.new
+ )
- def say(message)
- @_response = message
+ class << Boty::Slack.chat
+ attr_accessor :messages
+
+ def post_message(message, options)
+ @messages ||= []
+ @messages << { message: message, options: options }
end
end
+ end
- bot
+ let(:bot) {
+ Boty::ScriptDSL.new @_bot
}
end
end
def event(options)
- bot.event({ "type" => "message" }.merge options)
+ @_bot.event({ "type" => "message" }.merge options)
end
- def message_event(text)
+ def message(text)
event "text" => text
end
end
::RSpec::Matchers.define :have_responded do |expected|
# TODO: add proper messages for failures.
- match do |bot|
- response = bot._response
- bot._response = nil
- response == expected
+ match do |dsl|
+ last_message = Slack.chat.messages.last
+ expected == last_message[:message]
end
end
end
end