Class: Growl::RSpec::Formatter

Inherits:
RSpec::Core::Formatters::BaseTextFormatter
  • Object
show all
Defined in:
lib/growl/rspec/formatter.rb

Overview

The Growl::RSpec::Formatter depens on the growl gem (and therefore, growlnotify bin must be installed)

Use it by putting this in your spec_helper.rb

RSpec.configure do |config|
   config.formatter = 'Growl::RSpec::Formatter'
end

You can switch off granular growls about each spec failure via:

Growl::RSpec::Formatter.config = {
  :growl_failures => false
}

You can configure additional growlnotify options like:

Growl::RSpec::Formatter.growlnotify_config = {
  :host => 'your.growl.host'
}

Constant Summary collapse

DEFAULT_CONFIG =

the formatters default config hash

{
  :growl_failures => true
}.freeze

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.configObject

read the formatters config hash



30
31
32
# File 'lib/growl/rspec/formatter.rb', line 30

def self.config
  @@config ||= DEFAULT_CONFIG
end

.config=(c) ⇒ Object

set the formatters config hash



35
36
37
# File 'lib/growl/rspec/formatter.rb', line 35

def self.config=(c)
  @@config = DEFAULT_CONFIG.dup.merge(c)
end

.growlnotify_configObject

get the config hash that is passed to growlnotify gem



45
46
47
# File 'lib/growl/rspec/formatter.rb', line 45

def self.growlnotify_config
  @@_growlnotify_config ||= {}
end

.growlnotify_config=(o) ⇒ Object

set the config hash that is passed to growlnotify gem



40
41
42
# File 'lib/growl/rspec/formatter.rb', line 40

def self.growlnotify_config=(o)
  @@_growlnotify_config = o
end

Instance Method Details

#dump_failuresObject

hook when spec failed



50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
# File 'lib/growl/rspec/formatter.rb', line 50

def dump_failures
  super
  return if failed_examples.empty?
  if self.class.config[:growl_failures]

    msg = failed_examples.each_with_index.map do |example, idx|
      ["#{idx+1}. it #{example.description}",
       example.[:execution_result][:exception]]
    end.flatten.join("\n\n")

    ::Growl.notify_warning msg, {
      :title => "#{failed_examples.size} specs failed"
    }.merge(self.class.growlnotify_config)
  end
end

#dump_summary(duration, example_count, failure_count, pending_count) ⇒ Object

hook when all specs ran



67
68
69
70
71
72
73
74
75
# File 'lib/growl/rspec/formatter.rb', line 67

def dump_summary(duration, example_count, failure_count, pending_count)
  super(duration, example_count, failure_count, pending_count)

  msg = "#{example_count} specs in total (#{pending_count} pending). "\
        "Consumed #{duration.round(1)}s"
  ::Growl.notify_info msg, {
    :title => "#{failure_count} specs failed!"
  }.merge(self.class.growlnotify_config)
end