Browse Source

Use slack-ruby-bot.

master
dB 9 years ago
parent
commit
365a751abd
42 changed files with 68 additions and 548 deletions
  1. +3
    -6
      Gemfile
  2. +13
    -11
      Gemfile.lock
  3. +0
    -18
      app/slack-mathbot.rb
  4. +0
    -83
      app/slack-mathbot/app.rb
  5. +0
    -27
      app/slack-mathbot/commands/base.rb
  6. +0
    -9
      app/slack-mathbot/commands/hi.rb
  7. +0
    -9
      app/slack-mathbot/commands/unknown.rb
  8. +0
    -13
      app/slack-mathbot/config.rb
  9. +0
    -3
      app/slack-mathbot/hooks.rb
  10. +0
    -10
      app/slack-mathbot/hooks/base.rb
  11. +0
    -11
      app/slack-mathbot/hooks/hello.rb
  12. +0
    -33
      app/slack-mathbot/hooks/message.rb
  13. +0
    -1
      app/slack_mathbot.rb
  14. +4
    -1
      config.ru
  15. +0
    -14
      config/application.rb
  16. +0
    -5
      config/boot.rb
  17. +0
    -3
      config/environment.rb
  18. +0
    -3
      config/initializers/giphy.rb
  19. +0
    -13
      config/initializers/slack/request.rb
  20. +5
    -0
      slack-mathbot.rb
  21. +0
    -0
      slack-mathbot/about.rb
  22. +4
    -0
      slack-mathbot/app.rb
  23. +0
    -3
      slack-mathbot/commands.rb
  24. +1
    -1
      slack-mathbot/commands/about.rb
  25. +1
    -1
      slack-mathbot/commands/calculate.rb
  26. +1
    -1
      slack-mathbot/commands/help.rb
  27. +0
    -0
      slack-mathbot/version.rb
  28. +0
    -103
      spec/fixtures/slack/auth_test.yml
  29. +0
    -59
      spec/fixtures/slack/user_info.yml
  30. +2
    -26
      spec/slack-mathbot/app_spec.rb
  31. +6
    -0
      spec/slack-mathbot/commands/about_spec.rb
  32. +6
    -0
      spec/slack-mathbot/commands/calculate_spec.rb
  33. +6
    -0
      spec/slack-mathbot/commands/help_spec.rb
  34. +7
    -1
      spec/slack-mathbot/commands/hi_spec.rb
  35. +8
    -2
      spec/slack-mathbot/commands/unknown_spec.rb
  36. +1
    -8
      spec/spec_helper.rb
  37. +0
    -31
      spec/support/slack-mathbot/respond_with_error.rb
  38. +0
    -20
      spec/support/slack-mathbot/respond_with_slack_message.rb
  39. +0
    -5
      spec/support/slack_api_key.rb
  40. +0
    -4
      spec/support/slack_calculator.rb
  41. +0
    -8
      spec/support/vcr.rb
  42. +0
    -2
      web.rb

+ 3
- 6
Gemfile View File

@ -2,13 +2,10 @@ source 'http://rubygems.org'
ruby '2.1.6'
gem 'hashie'
gem 'slack-api', '~> 1.1.6', require: 'slack'
gem 'slack-ruby-bot'
gem 'puma'
gem 'sinatra'
gem 'activesupport'
gem 'dentaku'
gem 'giphy', '~> 2.0.2'
group :development, :test do
gem 'rake', '~> 10.4'
@ -17,8 +14,8 @@ group :development, :test do
end
group :test do
gem 'rspec', '~> 3.2'
gem 'rack-test', '~> 0.6.2'
gem 'rspec'
gem 'rack-test'
gem 'vcr'
gem 'webmock'
end

+ 13
- 11
Gemfile.lock View File

@ -1,7 +1,7 @@
GEM
remote: http://rubygems.org/
specs:
activesupport (4.2.1)
activesupport (4.2.3)
i18n (~> 0.7)
json (~> 1.7, >= 1.7.7)
minitest (~> 5.1)
@ -34,13 +34,13 @@ GEM
faraday_middleware (~> 0.9)
faraday_middleware-parse_oj (~> 0.3)
launchy (~> 2.4)
hashie (3.4.1)
hashie (3.4.2)
i18n (0.7.0)
json (1.8.2)
json (1.8.3)
launchy (2.4.3)
addressable (~> 2.3)
minitest (5.6.1)
multi_json (1.11.0)
minitest (5.7.0)
multi_json (1.11.1)
multipart-post (2.0.0)
oj (2.12.9)
parser (2.3.0.pre.2)
@ -85,6 +85,11 @@ GEM
faraday_middleware (~> 0.8)
faye-websocket (~> 0.9.2)
multi_json (~> 1.0, >= 1.0.3)
slack-ruby-bot (0.1.0)
activesupport
giphy (~> 2.0.2)
hashie
slack-api (~> 1.1.6)
thor (0.19.1)
thread_safe (0.3.5)
tilt (1.4.1)
@ -102,17 +107,14 @@ PLATFORMS
ruby
DEPENDENCIES
activesupport
dentaku
foreman
giphy (~> 2.0.2)
hashie
puma
rack-test (~> 0.6.2)
rack-test
rake (~> 10.4)
rspec (~> 3.2)
rspec
rubocop (= 0.31.0)
sinatra
slack-api (~> 1.1.6)
slack-ruby-bot
vcr
webmock

+ 0
- 18
app/slack-mathbot.rb View File

@ -1,18 +0,0 @@
require 'slack-mathbot/version'
require 'slack-mathbot/about'
require 'slack-mathbot/config'
require 'slack-mathbot/hooks'
require 'slack-mathbot/commands'
require 'slack-mathbot/app'
module SlackMathbot
class << self
def configure
block_given? ? yield(Config) : Config
end
def config
Config
end
end
end

+ 0
- 83
app/slack-mathbot/app.rb View File

@ -1,83 +0,0 @@
module SlackMathbot
class App
cattr_accessor :hooks
include SlackMathbot::Hooks::Hello
include SlackMathbot::Hooks::Message
def initialize
SlackMathbot.configure do |config|
config.token = ENV['SLACK_API_TOKEN'] || fail("Missing ENV['SLACK_API_TOKEN'].")
end
Slack.configure do |config|
config.token = SlackMathbot.config.token
end
end
def config
SlackMathbot.config
end
def self.instance
@instance ||= SlackMathbot::App.new
end
def run
auth!
start!
end
def stop!
client.stop
end
private
def logger
@logger ||= begin
$stdout.sync = true
Logger.new(STDOUT)
end
end
def start!
loop do
client.start
@client = nil
end
end
def client
@client ||= begin
client = Slack.realtime
hooks.each do |hook|
client.on hook do |data|
begin
send hook, data
rescue StandardError => e
logger.error e
begin
Slack.chat_postMessage(channel: data['channel'], text: e.message) if data.key?('channel')
rescue
# ignore
end
end
end
end
client
end
end
def auth!
auth = Slack.auth_test
SlackMathbot.configure do |config|
config.url = auth['url']
config.team = auth['team']
config.user = auth['user']
config.team_id = auth['team_id']
config.user_id = auth['user_id']
end
logger.info "Welcome '#{SlackMathbot.config.user}' to the '#{SlackMathbot.config.team}' team at #{SlackMathbot.config.url}."
end
end
end

+ 0
- 27
app/slack-mathbot/commands/base.rb View File

@ -1,27 +0,0 @@
module SlackMathbot
module Commands
class Base
def self.send_message(channel, text)
Slack.chat_postMessage(channel: channel, text: text)
end
def self.send_message_with_gif(channel, text, keywords)
gif = begin
Giphy.random(keywords)
rescue StandardError => e
logger.warn "Giphy.random: #{e.message}"
nil
end
text = text + "\n" + gif.image_url.to_s if gif
send_message channel, text
end
def self.logger
@logger ||= begin
$stdout.sync = true
Logger.new(STDOUT)
end
end
end
end
end

+ 0
- 9
app/slack-mathbot/commands/hi.rb View File

@ -1,9 +0,0 @@
module SlackMathbot
module Commands
class Hi < Base
def self.call(data, _command, _arguments)
send_message_with_gif data.channel, "Hi <@#{data.user}>!", 'hi'
end
end
end
end

+ 0
- 9
app/slack-mathbot/commands/unknown.rb View File

@ -1,9 +0,0 @@
module SlackMathbot
module Commands
class Unknown < Base
def self.call(data, _command, _arguments)
send_message_with_gif data.channel, "Sorry <@#{data.user}>, I don't understand that command!", 'idiot'
end
end
end
end

+ 0
- 13
app/slack-mathbot/config.rb View File

@ -1,13 +0,0 @@
module SlackMathbot
module Config
extend self
attr_accessor :token
attr_accessor :url
attr_accessor :user
attr_accessor :user_id
attr_accessor :team
attr_accessor :team_id
attr_accessor :secret
end
end

+ 0
- 3
app/slack-mathbot/hooks.rb View File

@ -1,3 +0,0 @@
require 'slack-mathbot/hooks/base'
require 'slack-mathbot/hooks/hello'
require 'slack-mathbot/hooks/message'

+ 0
- 10
app/slack-mathbot/hooks/base.rb View File

@ -1,10 +0,0 @@
module SlackMathbot
module Hooks
module Base
def included(caller)
caller.hooks ||= []
caller.hooks << name.demodulize.underscore.to_sym
end
end
end
end

+ 0
- 11
app/slack-mathbot/hooks/hello.rb View File

@ -1,11 +0,0 @@
module SlackMathbot
module Hooks
module Hello
extend Base
def hello(_data)
logger.info "Successfully connected to #{SlackMathbot.config.url}."
end
end
end
end

+ 0
- 33
app/slack-mathbot/hooks/message.rb View File

@ -1,33 +0,0 @@
module SlackMathbot
module Hooks
module Message
extend Base
def message(data)
data = Hashie::Mash.new(data)
bot_name, command, arguments = parse_command(data.text)
return unless bot_name == SlackMathbot.config.user
klass = command_to_class(command || 'Default')
klass.call data, command, arguments
end
private
def parse_command(text)
return unless text
text = '= ' + text[1..text.length] if text[0] == '='
parts = text.split.reject(&:blank?)
if parts && parts[0] == '='
parts[0] = SlackMathbot.config.user
parts.insert 1, 'calculate'
end
[parts.first.downcase, parts[1].try(:downcase), parts[2..parts.length]] if parts && parts.any?
end
def command_to_class(command)
klass = "SlackMathbot::Commands::#{command.titleize}".constantize rescue nil
klass || SlackMathbot::Commands::Unknown
end
end
end
end

+ 0
- 1
app/slack_mathbot.rb View File

@ -1 +0,0 @@
require 'slack-mathbot'

+ 4
- 1
config.ru View File

@ -1,4 +1,7 @@
require File.expand_path('../app', __FILE__)
$LOAD_PATH.unshift(File.dirname(__FILE__))
require 'slack-mathbot'
require 'web'
Thread.new do
SlackMathbot::App.instance.run

+ 0
- 14
config/application.rb View File

@ -1,14 +0,0 @@
$LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'app'))
$LOAD_PATH.unshift(File.dirname(__FILE__))
require 'boot'
Bundler.require :default, ENV['RACK_ENV']
Dir[File.expand_path('../initializers', __FILE__) + '/**/*.rb'].each do |file|
require file
end
require File.expand_path('../application', __FILE__)
require 'slack_mathbot'

+ 0
- 5
config/boot.rb View File

@ -1,5 +0,0 @@
require 'rubygems'
require 'bundler/setup'
require 'logger'
require 'active_support'
require 'active_support/core_ext'

+ 0
- 3
config/environment.rb View File

@ -1,3 +0,0 @@
ENV['RACK_ENV'] ||= 'development'
require File.expand_path('../application', __FILE__)

+ 0
- 3
config/initializers/giphy.rb View File

@ -1,3 +0,0 @@
Giphy::Configuration.configure do |config|
config.api_key = ENV['GIPHY_API_KEY'] || 'dc6zaTOxFJmzC' # from https://github.com/Giphy/GiphyAPI
end

+ 0
- 13
config/initializers/slack/request.rb View File

@ -1,13 +0,0 @@
module Slack
module Request
private
alias_method :_request, :request
def request(method, path, options)
response = _request(method, path, options)
fail response['error'] unless response['ok'] if response.is_a?(Hash)
response
end
end
end

+ 5
- 0
slack-mathbot.rb View File

@ -0,0 +1,5 @@
require 'slack-ruby-bot'
require 'slack-mathbot/version'
require 'slack-mathbot/about'
require 'slack-mathbot/commands'
require 'slack-mathbot/app'

app/slack-mathbot/about.rb → slack-mathbot/about.rb View File


+ 4
- 0
slack-mathbot/app.rb View File

@ -0,0 +1,4 @@
module SlackMathbot
class App < SlackRubyBot::App
end
end

app/slack-mathbot/commands.rb → slack-mathbot/commands.rb View File

@ -1,6 +1,3 @@
require 'slack-mathbot/commands/base'
require 'slack-mathbot/commands/calculate'
require 'slack-mathbot/commands/about'
require 'slack-mathbot/commands/help'
require 'slack-mathbot/commands/hi'
require 'slack-mathbot/commands/unknown'

app/slack-mathbot/commands/about.rb → slack-mathbot/commands/about.rb View File

@ -1,6 +1,6 @@
module SlackMathbot
module Commands
class Default < Base
class Default < SlackRubyBot::Commands::Base
def self.call(data, _command, _arguments)
send_message_with_gif data.channel, SlackMathbot::ABOUT, 'math'
end

app/slack-mathbot/commands/calculate.rb → slack-mathbot/commands/calculate.rb View File

@ -1,6 +1,6 @@
module SlackMathbot
module Commands
class Calculate < Base
class Calculate < SlackRubyBot::Commands::Base
def self.call(data, _command, arguments)
result = Dentaku::Calculator.new.evaluate(arguments.join)
result = result.to_s if result

app/slack-mathbot/commands/help.rb → slack-mathbot/commands/help.rb View File

@ -1,6 +1,6 @@
module SlackMathbot
module Commands
class Help < Base
class Help < SlackRubyBot::Commands::Base
def self.call(data, _command, _arguments)
send_message_with_gif data.channel, 'See https://github.com/dblock/slack-mathbot, please.', 'help'
end

app/slack-mathbot/version.rb → slack-mathbot/version.rb View File


+ 0
- 103
spec/fixtures/slack/auth_test.yml View File

@ -1,103 +0,0 @@
---
http_interactions:
- request:
method: post
uri: https://slack.com/api/auth.test
body:
encoding: UTF-8
string: token=token
headers:
Accept:
- application/json; charset=utf-8
User-Agent:
- Slack Ruby Gem 1.1.1
Content-Type:
- application/x-www-form-urlencoded
Accept-Encoding:
- gzip;q=1.0,deflate;q=0.6,identity;q=0.3
response:
status:
code: 200
message: OK
headers:
Access-Control-Allow-Origin:
- '*'
Cache-Control:
- private, no-cache, no-store, must-revalidate
Content-Type:
- application/json; charset=utf-8
Date:
- Tue, 28 Apr 2015 12:55:23 GMT
Expires:
- Mon, 26 Jul 1997 05:00:00 GMT
Pragma:
- no-cache
Server:
- Apache
Strict-Transport-Security:
- max-age=31536000; includeSubDomains; preload
Vary:
- Accept-Encoding
X-Accepted-Oauth-Scopes:
- identify
X-Content-Type-Options:
- nosniff
X-Oauth-Scopes:
- identify,read,post,client
X-Xss-Protection:
- '0'
Content-Length:
- '128'
Connection:
- keep-alive
body:
encoding: UTF-8
string: '{"ok":true,"url":"https:\/\/math.slack.com\/","team":"calcteam","user":"calcuser","team_id":"TDEADBEEF","user_id":"UBAADFOOD"}'
http_version:
recorded_at: Tue, 28 Apr 2015 12:55:22 GMT
- request:
method: post
uri: https://slack.com/api/rtm.start
body:
encoding: UTF-8
string: token=token
headers:
Accept:
- application/json; charset=utf-8
User-Agent:
- Slack Ruby Gem 1.1.1
Content-Type:
- application/x-www-form-urlencoded
Accept-Encoding:
- gzip;q=1.0,deflate;q=0.6,identity;q=0.3
response:
status:
code: 200
message: OK
headers:
Access-Control-Allow-Origin:
- '*'
Content-Type:
- application/json; charset=utf-8
Date:
- Tue, 28 Apr 2015 21:41:33 GMT
Server:
- Apache
Strict-Transport-Security:
- max-age=31536000; includeSubDomains; preload
Vary:
- Accept-Encoding
X-Content-Type-Options:
- nosniff
X-Xss-Protection:
- '0'
Content-Length:
- '55'
Connection:
- keep-alive
body:
encoding: UTF-8
string: '{"ok":false,"error":"invalid_auth"}'
http_version:
recorded_at: Tue, 28 Apr 2015 21:41:33 GMT
recorded_with: VCR 2.9.3

+ 0
- 59
spec/fixtures/slack/user_info.yml View File

@ -1,59 +0,0 @@
---
http_interactions:
- request:
method: post
uri: https://slack.com/api/users.info
body:
encoding: UTF-8
string: token=token&user=user
headers:
Accept:
- application/json; charset=utf-8
User-Agent:
- Slack Ruby Gem 1.1.1
Content-Type:
- application/x-www-form-urlencoded
Accept-Encoding:
- gzip;q=1.0,deflate;q=0.6,identity;q=0.3
response:
status:
code: 200
message: OK
headers:
Access-Control-Allow-Origin:
- '*'
Cache-Control:
- private, no-cache, no-store, must-revalidate
Content-Type:
- application/json; charset=utf-8
Date:
- Wed, 29 Apr 2015 16:10:34 GMT
Expires:
- Mon, 26 Jul 1997 05:00:00 GMT
Pragma:
- no-cache
Server:
- Apache
Strict-Transport-Security:
- max-age=31536000; includeSubDomains; preload
Vary:
- Accept-Encoding
X-Accepted-Oauth-Scopes:
- read
X-Content-Type-Options:
- nosniff
X-Oauth-Scopes:
- identify,read,post,client
X-Xss-Protection:
- '0'
Content-Length:
- '448'
Connection:
- keep-alive
body:
encoding: UTF-8
string: '{"ok":true,"user":{"id":"U007","name":"username","deleted":false,"status":null,"color":"9f69e7","real_name":"","tz":"America\/Indiana\/Indianapolis","tz_label":"Eastern
Daylight Time","tz_offset":-14400,"profile":{"real_name":"","real_name_normalized":"","email":"dblock@dblock.org","image_24":"https:\/\/secure.gravatar.com\/avatar\/3d925b45ac07ec0ae5bd04888f6c5b61.jpg?s=24&d=https%3A%2F%2Fslack.global.ssl.fastly.net%2F3654%2Fimg%2Favatars%2Fava_0015-24.png","image_32":"https:\/\/secure.gravatar.com\/avatar\/3d925b45ac07ec0ae5bd04888f6c5b61.jpg?s=32&d=https%3A%2F%2Fslack.global.ssl.fastly.net%2F3654%2Fimg%2Favatars%2Fava_0015-32.png","image_48":"https:\/\/secure.gravatar.com\/avatar\/3d925b45ac07ec0ae5bd04888f6c5b61.jpg?s=48&d=https%3A%2F%2Fslack.global.ssl.fastly.net%2F3654%2Fimg%2Favatars%2Fava_0015-48.png","image_72":"https:\/\/secure.gravatar.com\/avatar\/3d925b45ac07ec0ae5bd04888f6c5b61.jpg?s=72&d=https%3A%2F%2Fslack.global.ssl.fastly.net%2F3654%2Fimg%2Favatars%2Fava_0015-72.png","image_192":"https:\/\/secure.gravatar.com\/avatar\/3d925b45ac07ec0ae5bd04888f6c5b61.jpg?s=192&d=https%3A%2F%2Fslack.global.ssl.fastly.net%2F272a%2Fimg%2Favatars%2Fava_0015.png"},"is_admin":true,"is_owner":true,"is_primary_owner":true,"is_restricted":false,"is_ultra_restricted":false,"is_bot":false,"has_files":false}}'
http_version:
recorded_at: Wed, 29 Apr 2015 16:10:34 GMT

+ 2
- 26
spec/slack-mathbot/app_spec.rb View File

@ -1,32 +1,8 @@
require 'spec_helper'
describe SlackMathbot::App do
subject do
def app
SlackMathbot::App.new
end
context 'not configured' do
before do
@slack_api_token = ENV.delete('SLACK_API_TOKEN')
end
after do
ENV['SLACK_API_TOKEN'] = @slack_api_token
end
it 'requires SLACK_API_TOKEN' do
expect { subject }.to raise_error RuntimeError, "Missing ENV['SLACK_API_TOKEN']."
end
end
context 'configured', vcr: { cassette_name: 'auth_test' } do
context 'run' do
before do
subject.send(:auth!)
end
it 'succeeds auth' do
expect(subject.config.url).to eq 'https://math.slack.com/'
expect(subject.config.team).to eq 'calcteam'
expect(subject.config.user).to eq 'calcuser'
expect(subject.config.team_id).to eq 'TDEADBEEF'
expect(subject.config.user_id).to eq 'UBAADFOOD'
end
end
end
it_behaves_like 'a slack ruby bot'
end

+ 6
- 0
spec/slack-mathbot/commands/about_spec.rb View File

@ -1,6 +1,12 @@
require 'spec_helper'
describe SlackMathbot::Commands::Default do
def app
SlackMathbot::App.new
end
before do
app.config.user = 'mathbot'
end
it 'mathbot' do
expect(message: 'mathbot').to respond_with_slack_message(SlackMathbot::ABOUT)
end

+ 6
- 0
spec/slack-mathbot/commands/calculate_spec.rb View File

@ -1,6 +1,12 @@
require 'spec_helper'
describe SlackMathbot::Commands::Calculate, vcr: { cassette_name: 'user_info' } do
def app
SlackMathbot::App.new
end
before do
app.config.user = 'mathbot'
end
it 'adds two numbers' do
expect(message: 'mathbot calculate 2+2', channel: 'channel').to respond_with_slack_message('4')
end

+ 6
- 0
spec/slack-mathbot/commands/help_spec.rb View File

@ -1,6 +1,12 @@
require 'spec_helper'
describe SlackMathbot::Commands::Help do
def app
SlackMathbot::App.new
end
before do
app.config.user = 'mathbot'
end
it 'help' do
expect(message: 'mathbot help').to respond_with_slack_message('See https://github.com/dblock/slack-mathbot, please.')
end

+ 7
- 1
spec/slack-mathbot/commands/hi_spec.rb View File

@ -1,6 +1,12 @@
require 'spec_helper'
describe SlackMathbot::Commands::Hi do
describe SlackRubyBot::Commands::Hi do
def app
SlackMathbot::App.new
end
before do
app.config.user = 'mathbot'
end
it 'says hi' do
expect(message: 'mathbot hi').to respond_with_slack_message('Hi <@user>!')
end

+ 8
- 2
spec/slack-mathbot/commands/unknown_spec.rb View File

@ -1,11 +1,17 @@
require 'spec_helper'
describe SlackMathbot::Commands::Unknown, vcr: { cassette_name: 'user_info' } do
describe SlackRubyBot::Commands::Unknown, vcr: { cassette_name: 'user_info' } do
def app
SlackMathbot::App.new
end
before do
app.config.user = 'mathbot'
end
it 'invalid command' do
expect(message: 'mathbot foobar').to respond_with_slack_message("Sorry <@user>, I don't understand that command!")
end
it 'does not respond to sad face' do
expect(SlackMathbot::Commands::Base).to_not receive(:send_message)
expect(SlackRubyBot::Commands::Base).to_not receive(:send_message)
SlackMathbot::App.new.send(:message, text: ':((')
end
end

+ 1
- 8
spec/spec_helper.rb View File

@ -1,12 +1,5 @@
$LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..'))
require 'rubygems'
require 'rspec'
require 'rack/test'
require 'slack-ruby-bot/rspec'
require 'config/environment'
require 'slack-mathbot'
Dir[File.join(File.dirname(__FILE__), 'support', '**/*.rb')].each do |file|
require file
end

+ 0
- 31
spec/support/slack-mathbot/respond_with_error.rb View File

@ -1,31 +0,0 @@
require 'rspec/expectations'
RSpec::Matchers.define :respond_with_error do |expected|
match do |actual|
channel, user, message = parse(actual)
app = SlackMathbot::App.new
SlackMathbot.config.user = 'mathbot'
allow(Giphy).to receive(:random)
begin
expect do
app.send(:message, text: message, channel: channel, user: user)
end.to raise_error ArgumentError, expected
rescue RSpec::Expectations::ExpectationNotMetError => e
@error_message = e.message
raise e
end
true
end
failure_message do |actual|
_, _, message = parse(actual)
@error_message || "expected for '#{message}' to fail with '#{expected}'"
end
private
def parse(actual)
actual = { message: actual } unless actual.is_a?(Hash)
[actual[:channel] || 'channel', actual[:user] || 'user', actual[:message]]
end
end

+ 0
- 20
spec/support/slack-mathbot/respond_with_slack_message.rb View File

@ -1,20 +0,0 @@
require 'rspec/expectations'
RSpec::Matchers.define :respond_with_slack_message do |expected|
match do |actual|
channel, user, message = parse(actual)
app = SlackMathbot::App.new
SlackMathbot.config.user = 'mathbot'
allow(Giphy).to receive(:random)
expect(SlackMathbot::Commands::Base).to receive(:send_message).with(channel, expected)
app.send(:message, text: message, channel: channel, user: user)
true
end
private
def parse(actual)
actual = { message: actual } unless actual.is_a?(Hash)
[actual[:channel] || 'channel', actual[:user] || 'user', actual[:message]]
end
end

+ 0
- 5
spec/support/slack_api_key.rb View File

@ -1,5 +0,0 @@
RSpec.configure do |config|
config.before :all do
ENV['SLACK_API_TOKEN'] ||= 'test'
end
end

+ 0
- 4
spec/support/slack_calculator.rb View File

@ -1,4 +0,0 @@
SlackMathbot.configure do |config|
config.token = 'testtoken'
config.user = 'mathbot'
end

+ 0
- 8
spec/support/vcr.rb View File

@ -1,8 +0,0 @@
require 'vcr'
VCR.configure do |config|
config.cassette_library_dir = 'spec/fixtures/slack'
config.hook_into :webmock
# config.default_cassette_options = { record: :new_episodes }
config.configure_rspec_metadata!
end

app.rb → web.rb View File

@ -1,5 +1,3 @@
require File.expand_path('../config/environment', __FILE__)
require 'sinatra/base'
module SlackMathbot

Loading…
Cancel
Save