riot_notifier 0.0.6 → 0.0.7
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +1 -0
- data/README.rdoc +34 -25
- data/Rakefile +26 -22
- data/VERSION +1 -0
- data/lib/riot_notifier/base.rb +59 -0
- data/lib/riot_notifier/libnotify.rb +34 -0
- data/lib/riot_notifier/module.rb +45 -0
- data/lib/riot_notifier/none.rb +14 -0
- data/lib/riot_notifier/redgreen_binary.rb +28 -0
- data/lib/riot_notifier.rb +9 -77
- data/test/helper.rb +14 -1
- data/test/test_riot_notifier.rb +13 -8
- metadata +20 -5
- data/VERSION.yml +0 -5
data/.gitignore
CHANGED
data/README.rdoc
CHANGED
@@ -1,6 +1,7 @@
|
|
1
1
|
= Notifier for testing framework riot.
|
2
2
|
|
3
|
-
Notifies you about passes, errors, failures via
|
3
|
+
Notifies you about passes, errors, failures via custom notify libraries
|
4
|
+
like libnotify.
|
4
5
|
|
5
6
|
== Usage
|
6
7
|
|
@@ -9,42 +10,50 @@ Notifies you about passes, errors, failures via $HOME/bin/notify_redgreen
|
|
9
10
|
require 'riot'
|
10
11
|
require 'riot_notifier'
|
11
12
|
|
12
|
-
#
|
13
|
-
Riot.reporter = RiotNotifier
|
13
|
+
# Auto-detect in load order
|
14
|
+
Riot.reporter = RiotNotifier
|
14
15
|
|
15
|
-
|
16
|
-
|
17
|
-
|
16
|
+
=== Advanced usage
|
17
|
+
|
18
|
+
require 'riot'
|
19
|
+
require 'riot_notifier'
|
20
|
+
|
21
|
+
# Auto-detect in specified order notifier defined in RiotNotifier
|
22
|
+
Riot.reporter = RiotNotifier.try(:Libnotify, :RedgreenBinary)
|
23
|
+
Riot.reporter = RiotNotifier[:Libnotify, :RedgreenBinary] # sugar
|
18
24
|
|
19
|
-
|
25
|
+
# Use specific notifier class (libnotify)
|
26
|
+
Riot.reporter = RiotNotifier::Libnotify
|
20
27
|
|
21
|
-
|
28
|
+
# Use my own notifier
|
29
|
+
class MyOwn < ::RiotNotifier::Base
|
30
|
+
# override .notify and #usable?
|
31
|
+
end
|
22
32
|
|
23
|
-
|
33
|
+
Riot.reporter = RiotNotifier[MyOwn] # try only this
|
34
|
+
Riot.reporter = RiotNotifier # try MyOwn first (auto-detection)
|
24
35
|
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
OPTIONS="-t 2000 -u normal -i /usr/share/icons/gnome/scalable/emblems/emblem-default.svg :-)"
|
31
|
-
;;
|
32
|
-
esac
|
33
|
-
shift
|
36
|
+
# Use my own inline
|
37
|
+
Riot.reporter = Class.new(RiotNotifier::Base) do
|
38
|
+
def notify(color, msg)
|
39
|
+
MyFancyNotifierGem.notify(:color => color, :message => msg)
|
40
|
+
end
|
34
41
|
|
35
|
-
|
42
|
+
def self.usable?
|
43
|
+
require 'my_fancy_notifier_gem'
|
44
|
+
true
|
45
|
+
rescue LoadError
|
46
|
+
false
|
47
|
+
end
|
48
|
+
end
|
36
49
|
|
37
|
-
==
|
50
|
+
== Installation
|
38
51
|
|
39
|
-
gem install gemcutter
|
40
|
-
gem tumble
|
41
52
|
gem install riot_notifier
|
42
53
|
|
43
54
|
== Authors
|
44
55
|
* Peter Suschlik
|
45
56
|
|
46
57
|
== TODO
|
47
|
-
* talk to DBUS directly (ruby-dbus?) instead of `notify-send` binary
|
48
58
|
* riot's assertions support blocks! (like asserts_topic.equals { topic }). Use it!
|
49
|
-
* Test Libnotify
|
50
|
-
* Autodetect notify class
|
59
|
+
* Test auto-detection and Libnotify
|
data/Rakefile
CHANGED
@@ -1,31 +1,34 @@
|
|
1
1
|
require 'rake'
|
2
|
-
require 'rake/testtask'
|
3
|
-
require 'rake/rdoctask'
|
4
|
-
|
5
|
-
desc 'Default: run unit tests.'
|
6
|
-
task :default => :test
|
7
|
-
|
8
|
-
require 'jeweler'
|
9
|
-
Jeweler::Tasks.new do |gem|
|
10
|
-
gem.name = "riot_notifier"
|
11
|
-
gem.summary = 'Simple notifier for riot'
|
12
|
-
gem.email = "peter-riot_notifier@suschlik.de"
|
13
|
-
gem.homepage = "http://github.com/splattael/riot_notifier"
|
14
|
-
gem.authors = ["Peter Suschlik"]
|
15
|
-
|
16
|
-
gem.has_rdoc = true
|
17
|
-
gem.extra_rdoc_files = [ "README.rdoc" ]
|
18
2
|
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
3
|
+
begin
|
4
|
+
require 'jeweler'
|
5
|
+
Jeweler::Tasks.new do |gem|
|
6
|
+
gem.name = "riot_notifier"
|
7
|
+
gem.summary = 'Simple notifier for riot'
|
8
|
+
gem.email = "peter-riot_notifier@suschlik.de"
|
9
|
+
gem.homepage = "http://github.com/splattael/riot_notifier"
|
10
|
+
gem.authors = ["Peter Suschlik"]
|
11
|
+
|
12
|
+
gem.has_rdoc = true
|
13
|
+
gem.extra_rdoc_files = [ "README.rdoc" ]
|
14
|
+
|
15
|
+
gem.add_dependency "riot", ">= 0.10.9"
|
16
|
+
gem.add_development_dependency "riot_notifier"
|
17
|
+
gem.add_development_dependency "libnotify"
|
18
|
+
|
19
|
+
gem.test_files = Dir.glob('test/test_*.rb')
|
20
|
+
end
|
21
|
+
Jeweler::GemcutterTasks.new
|
22
|
+
rescue LoadError
|
23
|
+
puts "Jeweler (or a dependency) not available. Install it with: gem install jeweler"
|
23
24
|
end
|
24
25
|
|
25
|
-
Jeweler::GemcutterTasks.new
|
26
|
-
|
27
26
|
# Test
|
28
27
|
require 'rake/testtask'
|
28
|
+
desc 'Default: run unit tests.'
|
29
|
+
task :default => :test
|
30
|
+
task :test => :check_dependencies
|
31
|
+
|
29
32
|
Rake::TestTask.new(:test) do |test|
|
30
33
|
test.test_files = FileList.new('test/test_*.rb')
|
31
34
|
test.libs << 'test'
|
@@ -33,6 +36,7 @@ Rake::TestTask.new(:test) do |test|
|
|
33
36
|
end
|
34
37
|
|
35
38
|
# RDoc
|
39
|
+
require 'rake/rdoctask'
|
36
40
|
Rake::RDocTask.new do |rd|
|
37
41
|
rd.title = "Riot Notifier"
|
38
42
|
rd.main = "README.rdoc"
|
data/VERSION
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
0.0.7
|
@@ -0,0 +1,59 @@
|
|
1
|
+
# Base class for all specific notifiers.
|
2
|
+
#
|
3
|
+
# Each notifier should implement +notify+ and +usable?+.
|
4
|
+
#
|
5
|
+
# Note: Base is NOT usable.
|
6
|
+
module RiotNotifier
|
7
|
+
|
8
|
+
class Base < ::Riot::DotMatrixReporter
|
9
|
+
|
10
|
+
def initialize(*args, &block)
|
11
|
+
raise "#{self.class} is NOT usable" unless self.class.usable?
|
12
|
+
super
|
13
|
+
end
|
14
|
+
|
15
|
+
# Notifies you about failures and errors.
|
16
|
+
# This methods should be overridden in order to define specific notifications libraries.
|
17
|
+
def notify(color, msg)
|
18
|
+
# override me
|
19
|
+
end
|
20
|
+
|
21
|
+
# Tests if this notifier is usable.
|
22
|
+
# Should contain some initialization code e.g. require 'libnotify'.
|
23
|
+
def self.usable?
|
24
|
+
# override
|
25
|
+
false
|
26
|
+
end
|
27
|
+
|
28
|
+
def self.inherited(notifier)
|
29
|
+
::RiotNotifier.order.unshift notifier
|
30
|
+
end
|
31
|
+
|
32
|
+
# Override
|
33
|
+
|
34
|
+
def fail(desc, message)
|
35
|
+
super
|
36
|
+
notify(:red, "FAILURE: #{message}")
|
37
|
+
end
|
38
|
+
|
39
|
+
def error(desc, error)
|
40
|
+
super
|
41
|
+
notify(:red, "ERROR: #{error}")
|
42
|
+
end
|
43
|
+
|
44
|
+
def results(time_taken)
|
45
|
+
super
|
46
|
+
unless bad_results?
|
47
|
+
notify(:green, "%d passes, %d failures, %d errors in %s seconds" % [passes, failures, errors, ("%0.6f" % time_taken)])
|
48
|
+
end
|
49
|
+
end
|
50
|
+
|
51
|
+
private
|
52
|
+
|
53
|
+
def bad_results?
|
54
|
+
failures + errors > 0
|
55
|
+
end
|
56
|
+
|
57
|
+
end
|
58
|
+
|
59
|
+
end
|
@@ -0,0 +1,34 @@
|
|
1
|
+
# Notifies via libnotify.
|
2
|
+
module RiotNotifier
|
3
|
+
|
4
|
+
class Libnotify < Base
|
5
|
+
OPTIONS = {
|
6
|
+
:green => {
|
7
|
+
:icon_path => "/usr/share/icons/gnome/scalable/emblems/emblem-default.svg",
|
8
|
+
:timeout => 2.5,
|
9
|
+
:urgency => :normal,
|
10
|
+
:summary => ":-)"
|
11
|
+
},
|
12
|
+
:red => {
|
13
|
+
:icon_path => "/usr/share/icons/gnome/scalable/emotes/face-angry.svg",
|
14
|
+
:timeout => 2.5,
|
15
|
+
:urgency => :critical,
|
16
|
+
:summary => ":-("
|
17
|
+
}
|
18
|
+
}
|
19
|
+
|
20
|
+
def notify(color, msg)
|
21
|
+
options = OPTIONS[color] or raise "unknown color #{color}"
|
22
|
+
|
23
|
+
::Libnotify.show(options.merge(:body => msg))
|
24
|
+
end
|
25
|
+
|
26
|
+
def self.usable?
|
27
|
+
require 'libnotify'
|
28
|
+
true
|
29
|
+
rescue LoadError
|
30
|
+
false
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
end
|
@@ -0,0 +1,45 @@
|
|
1
|
+
# Notifies you about failures and errors in your riot tests!
|
2
|
+
#
|
3
|
+
# Usage:
|
4
|
+
# require 'riot'
|
5
|
+
# require 'riot_notifier'
|
6
|
+
#
|
7
|
+
# # auto-detection
|
8
|
+
# Riot.reporter = RiotNotifier
|
9
|
+
# # try these first
|
10
|
+
# Riot.reporter = RiotNotifier[:RedgreenBinary, :Libnotify]
|
11
|
+
#
|
12
|
+
module RiotNotifier
|
13
|
+
|
14
|
+
def self.new(*args, &block)
|
15
|
+
notifier_class = notifier_classes.detect(&:usable?) || None
|
16
|
+
notifier_class.new(*args, &block)
|
17
|
+
end
|
18
|
+
|
19
|
+
def self.order
|
20
|
+
@order ||= []
|
21
|
+
end
|
22
|
+
|
23
|
+
def self.try(*order)
|
24
|
+
@order = order
|
25
|
+
self
|
26
|
+
end
|
27
|
+
|
28
|
+
class << self
|
29
|
+
alias [] try
|
30
|
+
end
|
31
|
+
|
32
|
+
def self.notifier_classes
|
33
|
+
order.map { |o| resolve_notifier_class(o) }.compact - [None]
|
34
|
+
end
|
35
|
+
|
36
|
+
def self.resolve_notifier_class(o)
|
37
|
+
case o
|
38
|
+
when Class; o
|
39
|
+
when Symbol, String; const_get(o)
|
40
|
+
else
|
41
|
+
nil
|
42
|
+
end
|
43
|
+
end
|
44
|
+
|
45
|
+
end
|
@@ -0,0 +1,28 @@
|
|
1
|
+
# Notifies via $HOME/bin/notify_redgreen (with notify-send)
|
2
|
+
module RiotNotifier
|
3
|
+
|
4
|
+
class RedgreenBinary < Base
|
5
|
+
attr_reader :path
|
6
|
+
PATH = ENV['HOME'] + "/bin/notify_redgreen"
|
7
|
+
|
8
|
+
def initialize(path = PATH)
|
9
|
+
super()
|
10
|
+
@path = path
|
11
|
+
end
|
12
|
+
|
13
|
+
def notify(color, msg)
|
14
|
+
msg.gsub!(/</, '<')
|
15
|
+
msg.gsub!(/"/, "\\\"")
|
16
|
+
exec "#{@path} #{color} \"#{msg}\""
|
17
|
+
end
|
18
|
+
|
19
|
+
def exec(*args)
|
20
|
+
Kernel.system(*args)
|
21
|
+
end
|
22
|
+
|
23
|
+
def self.usable?
|
24
|
+
File.exist?(PATH)
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
end
|
data/lib/riot_notifier.rb
CHANGED
@@ -1,82 +1,14 @@
|
|
1
1
|
require 'riot'
|
2
2
|
|
3
|
-
module
|
4
|
-
|
5
|
-
def notify(color, msg)
|
6
|
-
# overwrite me
|
7
|
-
end
|
3
|
+
require 'riot_notifier/module'
|
4
|
+
require 'riot_notifier/base'
|
8
5
|
|
9
|
-
|
10
|
-
super
|
11
|
-
say yellow("#{desc}: #{message}")
|
12
|
-
notify(:red, "FAILURE: #{message}")
|
13
|
-
end
|
6
|
+
# Reverse load order!
|
14
7
|
|
15
|
-
|
16
|
-
|
17
|
-
say red("#{desc}: #{error}")
|
18
|
-
notify(:red, "ERROR: #{error}")
|
19
|
-
end
|
8
|
+
# Fallback
|
9
|
+
require 'riot_notifier/none'
|
20
10
|
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
end
|
26
|
-
end
|
27
|
-
|
28
|
-
private
|
29
|
-
|
30
|
-
def bad_results?
|
31
|
-
failures + errors > 0
|
32
|
-
end
|
33
|
-
end
|
34
|
-
|
35
|
-
class Libnotify < Base
|
36
|
-
OPTIONS = {
|
37
|
-
:green => {
|
38
|
-
:icon_path => "/usr/share/icons/gnome/scalable/emblems/emblem-default.svg",
|
39
|
-
:timeout => 2.5,
|
40
|
-
:urgency => :normal,
|
41
|
-
:summary => ":-)"
|
42
|
-
},
|
43
|
-
:red => {
|
44
|
-
:icon_path => "/usr/share/icons/gnome/scalable/emotes/face-angry.svg",
|
45
|
-
:timeout => 2.5,
|
46
|
-
:urgency => :critical,
|
47
|
-
:summary => ":-("
|
48
|
-
}
|
49
|
-
}
|
50
|
-
|
51
|
-
def initialize
|
52
|
-
require 'libnotify'
|
53
|
-
super()
|
54
|
-
end
|
55
|
-
|
56
|
-
def notify(color, msg)
|
57
|
-
options = OPTIONS[color] or raise "unknown color #{color}"
|
58
|
-
|
59
|
-
::Libnotify.show(options.merge(:body => msg))
|
60
|
-
end
|
61
|
-
end
|
62
|
-
|
63
|
-
class RedgreenNotifier < Base
|
64
|
-
attr_reader :path
|
65
|
-
PATH = ENV['HOME'] + "/bin/notify_redgreen"
|
66
|
-
|
67
|
-
def initialize(path = PATH)
|
68
|
-
super()
|
69
|
-
@path = path
|
70
|
-
end
|
71
|
-
|
72
|
-
def notify(color, msg)
|
73
|
-
msg.gsub!(/</, '<')
|
74
|
-
msg.gsub!(/"/, "\\\"")
|
75
|
-
exec "#{@path} #{color} \"#{msg}\""
|
76
|
-
end
|
77
|
-
|
78
|
-
def exec(*args)
|
79
|
-
Kernel.system(*args)
|
80
|
-
end
|
81
|
-
end
|
82
|
-
end
|
11
|
+
# Custom notifiers - loading is important for auto-detection
|
12
|
+
# LIFO!
|
13
|
+
require 'riot_notifier/redgreen_binary'
|
14
|
+
require 'riot_notifier/libnotify'
|
data/test/helper.rb
CHANGED
@@ -1,5 +1,18 @@
|
|
1
|
+
require 'rubygems'
|
1
2
|
require 'riot'
|
2
3
|
|
3
4
|
require 'riot_notifier'
|
4
5
|
|
5
|
-
Riot.reporter = RiotNotifier
|
6
|
+
Riot.reporter = RiotNotifier
|
7
|
+
|
8
|
+
module Riot
|
9
|
+
class Situation
|
10
|
+
# Create backtrace for this exception.
|
11
|
+
def bt!(error)
|
12
|
+
return error if error.backtrace
|
13
|
+
raise error
|
14
|
+
rescue error.class => e
|
15
|
+
e
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
data/test/test_riot_notifier.rb
CHANGED
@@ -1,9 +1,8 @@
|
|
1
|
-
require 'rubygems'
|
2
1
|
|
3
2
|
require 'helper'
|
4
3
|
require 'stringio'
|
5
4
|
|
6
|
-
class MockNotifier < ::RiotNotifier::
|
5
|
+
class MockNotifier < ::RiotNotifier::None
|
7
6
|
def initialize
|
8
7
|
super(StringIO.new)
|
9
8
|
end
|
@@ -11,17 +10,23 @@ class MockNotifier < ::RiotNotifier::Base
|
|
11
10
|
def notify(color, msg)
|
12
11
|
[ color, msg ]
|
13
12
|
end
|
13
|
+
|
14
|
+
::RiotNotifier.order.delete(self)
|
14
15
|
end
|
15
16
|
|
16
17
|
context "RiotNotifier" do
|
17
18
|
context "with MockNotifier" do
|
18
|
-
setup
|
19
|
+
setup do
|
20
|
+
reporter = MockNotifier.new
|
21
|
+
reporter.describe_context(Riot::Context.new("test") {})
|
22
|
+
reporter
|
23
|
+
end
|
19
24
|
|
20
|
-
asserts("
|
21
|
-
asserts("
|
25
|
+
asserts("notifies failure in red") { topic.fail("desc", "failed") }.equals([:red, "FAILURE: failed"])
|
26
|
+
asserts("notifies error in red") { topic.error("desc", bt!(ArgumentError.new("errored"))) }.equals([:red, "ERROR: errored"])
|
22
27
|
asserts("doesn't display results with bad results") do
|
23
28
|
topic.report("desc", [:fail, "failure"])
|
24
|
-
topic.report("desc", [:error, "error"])
|
29
|
+
topic.report("desc", [:error, bt!(ArgumentError.new("error"))])
|
25
30
|
topic.results(23.0)
|
26
31
|
end.nil
|
27
32
|
|
@@ -35,9 +40,9 @@ context "RiotNotifier" do
|
|
35
40
|
end
|
36
41
|
end # with MockNotifier
|
37
42
|
|
38
|
-
context "with
|
43
|
+
context "with RedgreenBinary" do
|
39
44
|
setup do
|
40
|
-
Class.new(RiotNotifier::
|
45
|
+
Class.new(RiotNotifier::RedgreenBinary) do
|
41
46
|
def exec(string)
|
42
47
|
string
|
43
48
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: riot_notifier
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.7
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Peter Suschlik
|
@@ -9,7 +9,7 @@ autorequire:
|
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
11
|
|
12
|
-
date: 2009-12-
|
12
|
+
date: 2009-12-17 00:00:00 +01:00
|
13
13
|
default_executable:
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
@@ -20,11 +20,21 @@ dependencies:
|
|
20
20
|
requirements:
|
21
21
|
- - ">="
|
22
22
|
- !ruby/object:Gem::Version
|
23
|
-
version: 0.10.
|
23
|
+
version: 0.10.9
|
24
|
+
version:
|
25
|
+
- !ruby/object:Gem::Dependency
|
26
|
+
name: riot_notifier
|
27
|
+
type: :development
|
28
|
+
version_requirement:
|
29
|
+
version_requirements: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ">="
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: "0"
|
24
34
|
version:
|
25
35
|
- !ruby/object:Gem::Dependency
|
26
36
|
name: libnotify
|
27
|
-
type: :
|
37
|
+
type: :development
|
28
38
|
version_requirement:
|
29
39
|
version_requirements: !ruby/object:Gem::Requirement
|
30
40
|
requirements:
|
@@ -45,8 +55,13 @@ files:
|
|
45
55
|
- .watchr
|
46
56
|
- README.rdoc
|
47
57
|
- Rakefile
|
48
|
-
- VERSION
|
58
|
+
- VERSION
|
49
59
|
- lib/riot_notifier.rb
|
60
|
+
- lib/riot_notifier/base.rb
|
61
|
+
- lib/riot_notifier/libnotify.rb
|
62
|
+
- lib/riot_notifier/module.rb
|
63
|
+
- lib/riot_notifier/none.rb
|
64
|
+
- lib/riot_notifier/redgreen_binary.rb
|
50
65
|
- test/helper.rb
|
51
66
|
- test/test_riot_notifier.rb
|
52
67
|
has_rdoc: true
|