Created
February 16, 2018 03:57
-
-
Save kou029w/87aea45308ed8d8b5ec3559751b9181a to your computer and use it in GitHub Desktop.
RSpecの開始と終了をSlackに通知する
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
実行時の様子