module Spinach::Reporter::SpinachSlackReportable

Attributes

notifier[R]

Public Class Methods

new(*args) click to toggle source
Calls superclass method
# File lib/spinach/reporter/spinach_slack_reportable.rb, line 7
def initialize(*args)
  super
  @notifier = Slack::Notifier.new(
    ENV['SPINACH_SLACK_WEBHOOK_URL'],
    channel: ENV['SPINACH_SLACK_CHANNEL'],
    username: ENV['SPINACH_SLACK_USERNAME']
  )
end

Public Instance Methods

after_run(*args) click to toggle source
Calls superclass method
# File lib/spinach/reporter/spinach_slack_reportable.rb, line 27
def after_run(*args)
  super
  message = 'Test Run Complete!'
  msg = {
    fallback: message,
    text: message,
    color: 'good'
  }
  notifier.ping '', attachments: [msg]
end
before_run(*args) click to toggle source
Calls superclass method
# File lib/spinach/reporter/spinach_slack_reportable.rb, line 16
def before_run(*args)
  super
  message = 'Starting Test Run'
  msg = {
    fallback: message,
    text: message,
    color: 'good'
  }
  notifier.ping '', attachments: [msg]
end
on_error_step(*args) click to toggle source
Calls superclass method
# File lib/spinach/reporter/spinach_slack_reportable.rb, line 56
def on_error_step(*args)
  super
  step_error(*args, 'Step Error')
end
on_failed_step(*args) click to toggle source
Calls superclass method
# File lib/spinach/reporter/spinach_slack_reportable.rb, line 51
def on_failed_step(*args)
  super
  step_error(*args, 'Step Failed')
end
on_undefined_step(*args) click to toggle source
Calls superclass method
# File lib/spinach/reporter/spinach_slack_reportable.rb, line 38
def on_undefined_step(*args)
  super
  step = args[0]
  msg = {
    fallback: "#{step_string(step)}\nis not defined.",
    title: 'Step Not Defined',
    text: step_string(step),
    color: 'warning',
    mrkdwn_in: ['text']
  }
  notifier.ping '', attachments: [msg]
end

Private Instance Methods

step_error(*args, title) click to toggle source
# File lib/spinach/reporter/spinach_slack_reportable.rb, line 67
def step_error(*args, title)
  step, error = args
  msg = {
    fallback: "#{step_string(step)}\nfailed.\n```\n#{error.message}\n\n#{error.backtrace[0]}```",
    title: title,
    text: "#{step_string(step)}\n```\n#{error.message}\n\n#{error.backtrace.join("\n")}\n```",
    color: 'danger',
    mrkdwn_in: ['text']
  }
  notifier.ping '', attachments: [msg]
end
step_string(step) click to toggle source
# File lib/spinach/reporter/spinach_slack_reportable.rb, line 63
def step_string(step)
  "`#{current_feature.name} :: #{current_scenario.name} :: #{step.name}`"
end