Sha256: febc3b3f705bc0001d1cb2d78ea275f500445cca63a25a1753ccef31e62b8fb4

Contents?: true

Size: 1.13 KB

Versions: 2

Compression:

Stored size: 1.13 KB

Contents

module Boty
  module RSpec
    module Bot
      require File.expand_path "../../../spec/support/slack_support", __FILE__

      def self.included(base)
        base.instance_eval do
          include SlackSupport::Users

          before do
            @_bot = Boty::Bot.new(
              {"id" => "1234", "name" => "bot"},
              Boty::Session.new
            )

            class << Boty::Slack.chat
              attr_accessor :messages

              def post_message(message, options)
                @messages ||= []
                @messages << { message: message, options: options }
              end
            end
          end

          let(:bot) {
            Boty::ScriptDSL.new @_bot
          }
        end
      end

      def event(options)
        @_bot.event({ "type" => "message" }.merge options)
      end

      def message(text)
        event "text" => text
      end
    end

    ::RSpec::Matchers.define :have_responded do |expected|
      # TODO: add proper messages for failures.
      match do |dsl|
        last_message = Slack.chat.messages.last
        expected == last_message[:message]
      end
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
boty-0.0.17.1 lib/boty/rspec.rb
boty-0.0.17 lib/boty/rspec.rb