Module: Testowl::Growl

Defined in:
lib/testowl/growl.rb

Constant Summary collapse

Growlnotify =
"growlnotify"
TerminalNotifier =
"terminal-notifier"

Class Method Summary collapse

Class Method Details

.grr(title, message, seconds, status, files, suffix, identifier) ⇒ Object



7
8
9
10
# File 'lib/testowl/growl.rb', line 7

def self.grr(title, message, seconds, status, files, suffix, identifier)
  with_terminal_notifier(title, message, seconds, status, files, suffix, identifier) ||
    with_growl(title, message, seconds, status, files, suffix, identifier)
end

.image_path(name) ⇒ Object



66
67
68
# File 'lib/testowl/growl.rb', line 66

def self.image_path(name)
  File.dirname(__FILE__) + "/../../images/#{name}.png"
end

.with_growl(title, message, seconds, status, files, suffix, identifier) ⇒ Object



38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
# File 'lib/testowl/growl.rb', line 38

def self.with_growl(title, message, seconds, status, files, suffix, identifier)
  project = File.expand_path(".").split("/").last
  growlnotify = `which #{Growlnotify}`.chomp
  if growlnotify == ''
    if @g_warning_done
      puts "Skipping growl"
    else
      puts "If you install #{Growlnotify} you'll get growl notifications. See the README."
      @g_warning_done = true
    end
    false
  else
    message_lines = [message.gsub("'", "`")]
    message_lines << sprintf("(%0.1f seconds)", seconds) if seconds
    message_lines << "#{files.map{|file| file.sub(/^spec\/[^\/]*\//, '').sub(/_test.rb$/, '')}.join("\n")}\n#{suffix}"
    message_lines << identifier
    options = []
    options << "-n Watchr"
    options << "--message '#{message_lines.join("\n\n")}'"
    options << "--image '#{image_path(status)}'"
    options << "--identifier #{identifier}" # (used for coalescing)
    title = "TestOwl #{title} (#{project})"
    system %(#{growlnotify} #{options.join(' ')} '#{title}' &)
    puts message
    true
  end
end

.with_terminal_notifier(title, message, seconds, status, files, suffix, identifier) ⇒ Object



12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
# File 'lib/testowl/growl.rb', line 12

def self.with_terminal_notifier(title, message, seconds, status, files, suffix, identifier)
  project = File.expand_path(".").split("/").last
  terminal_notifier = `which #{TerminalNotifier}`.chomp
  if terminal_notifier == ''
    if @tn_warning_done
      puts "Skipping terminal notifier"
    else
      puts "If you install #{TerminalNotifier} you'll get notifications. Trying growl next. See the README."
      @tn_warning_done = true
    end
    false
  else
    message_lines = [message.gsub("'", "`")]
    message_lines << sprintf("(%0.1f seconds)", seconds) if seconds
    message_lines << "#{files.map{|file| file.sub(/^spec\/[^\/]*\//, '').sub(/_test.rb$/, '')}.join("\n")}\n#{suffix}"
    message_lines << identifier
    options = []
    options << "-message '#{message_lines.join("\n\n")}'"
    options << "-group #{identifier}" # (used for coalescing)
    options << "-title 'TestOwl #{title} (#{project})'"
    system %(#{terminal_notifier} #{options.join(' ')} &)
    puts message
    true
  end
end