Sha256: d651be1c86de9d8f69533b6115a96993e07a4ae5afbe6497657c68e8ddb33e56
Contents?: true
Size: 1.85 KB
Versions: 5
Compression:
Stored size: 1.85 KB
Contents
# frozen_string_literal: true describe SlackRubyBot::Commands do let! :command do Class.new(SlackRubyBot::Commands::Base) do command 'sayhi' command 'saybye' def self.call(client, data, match) client.say(channel: data.channel, text: "#{match[:command]}: #{match[:expression]}") end end end def app SlackRubyBot::App.new end it 'supports multiple commands' do expect(message: "#{SlackRubyBot.config.user} sayhi arg1 arg2").to respond_with_slack_message('sayhi: arg1 arg2') expect(message: "#{SlackRubyBot.config.user} saybye arg1 arg2").to respond_with_slack_message('saybye: arg1 arg2') end it 'checks for direct message' do expect(command.send(:direct_message?, Hashie::Mash.new(channel: 'D0K79RKJ7'))).to be true expect(command.send(:direct_message?, Hashie::Mash.new(channel: 'S0K79RKJ7'))).to be false end it 'checks that message from another user' do SlackRubyBot.config.user_id = 'UDEADBEEF' expect(command.send(:message_from_another_user?, Hashie::Mash.new(user: 'U0CPHNZ2N'))).to be true expect(command.send(:message_from_another_user?, Hashie::Mash.new(user: 'UDEADBEEF'))).to be false end it 'checks that bot mentioned in message' do bot_names = ['rubybot', '<@deadbeef>', '<@deadbeef>:', 'rubybot:'] expect(command.send(:message_begins_with_bot_mention?, 'rubybot', bot_names)).to be true expect(command.send(:message_begins_with_bot_mention?, 'rubybot ', bot_names)).to be true expect(command.send(:message_begins_with_bot_mention?, 'rubybotbot', bot_names)).to be false expect(command.send(:message_begins_with_bot_mention?, 'rubybot:', bot_names)).to be true expect(command.send(:message_begins_with_bot_mention?, 'rubybot: ', bot_names)).to be true expect(command.send(:message_begins_with_bot_mention?, 'rubybot:bot', bot_names)).to be false end end
Version data entries
5 entries across 5 versions & 1 rubygems