Sha256: 6435f1e8995b33bdf8c9e8329572ada80259b65e09129ecc00111b80f9baaab6

Contents?: true

Size: 1.55 KB

Versions: 2

Compression:

Stored size: 1.55 KB

Contents

require 'rspec/core/formatters/base_text_formatter'
require 'terminal-notifier'

class Nc < RSpec::Core::Formatters::BaseTextFormatter
  if RSpec::Core::Formatters.respond_to? :register
    RSpec::Core::Formatters.register self.class, :example_failed
  end

  def dump_summary(duration, example_count, failure_count, pending_count)
    body = []
    body << "Finished in #{_format_duration duration}"
    body << _summary_line(example_count, failure_count, pending_count)

    name = File.basename(File.expand_path '.')

    title = if failure_count > 0
      "\u26D4 #{name}: #{failure_count} failed example#{failure_count == 1 ? nil : 's'}"
    else
      "\u2705 #{name}: Success"
    end

    say title, body.join("\n")
  end

  def dump_pending; end
  def dump_failures; end
  def message(message); end

  private

  def say(title, body)
    TerminalNotifier.notify body, :title => title
  end

  def _format_duration(duration)
    if respond_to? :format_duration
      format_duration duration
    else
      require 'rspec/core/formatters/helpers'
      RSpec::Core::Formatters::Helpers.format_duration duration
    end
  end

  def _summary_line(example_count, failure_count, pending_count)
    if respond_to? :summary_line
      summary_line(example_count, failure_count, pending_count)
    else
      RSpec::Core::Notifications::SummaryNotification.new(
        nil,
        SizeResponder.new(example_count),
        SizeResponder.new(failure_count),
        SizeResponder.new(pending_count),
        nil
      ).totals_line
    end
  end

  SizeResponder = Struct.new(:size)
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
rspec-nc-0.1.1 lib/nc.rb
rspec-nc-0.1.0 lib/nc.rb