Skip to content

Instantly share code, notes, and snippets.

@kou029w
Created February 16, 2018 03:57
Show Gist options
  • Save kou029w/87aea45308ed8d8b5ec3559751b9181a to your computer and use it in GitHub Desktop.
Save kou029w/87aea45308ed8d8b5ec3559751b9181a to your computer and use it in GitHub Desktop.
RSpecの開始と終了をSlackに通知する
require 'slack-ruby-client'
Slack.configure do |config|
config.token = ENV.fetch('SLACK_API_TOKEN', '')
end
RSpec.configure do |config|
config.before(:suite) do
chat_post ':stopwatch: Running...'
end
config.after(:suite) do
chat_post ':checkered_flag: Goal!'
end
def chat_post(text)
channel = ENV.fetch('SLACK_CHANNEL', '')
username = ENV.fetch('SLACK_USERNAME', '')
text = "#{text} <@#{username}>" if !username.blank?
unless Slack::Config.token.blank? || channel.blank?
client = Slack::Web::Client.new
client.chat_postMessage(channel: channel, text: text, as_user: true)
end
end
end
@kou029w
Copy link
Author

kou029w commented Feb 16, 2018

実行時の様子

実行時の様子

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment