test_notifier 0.3.0 → 0.3.1
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/test_notifier.rb +5 -3
- data/lib/test_notifier/notifier/osd_cat.rb +2 -1
- data/lib/test_notifier/runner/autotest.rb +8 -1
- data/lib/test_notifier/runner/rspec.rb +12 -9
- data/lib/test_notifier/runner/spec.rb +12 -9
- data/lib/test_notifier/runner/test_unit.rb +3 -4
- data/lib/test_notifier/stats.rb +89 -0
- data/lib/test_notifier/version.rb +1 -1
- data/resources/error.png +0 -0
- data/test/stats_test.rb +84 -0
- metadata +7 -3
data/lib/test_notifier.rb
CHANGED
@@ -16,7 +16,8 @@ module TestNotifier
|
|
16
16
|
|
17
17
|
TITLES = {
|
18
18
|
:fail => "Failed!",
|
19
|
-
:success => "Passed!"
|
19
|
+
:success => "Passed!",
|
20
|
+
:error => "Error!"
|
20
21
|
}
|
21
22
|
|
22
23
|
def notify(options)
|
@@ -39,6 +40,7 @@ module TestNotifier
|
|
39
40
|
end
|
40
41
|
end
|
41
42
|
|
42
|
-
autoload :Notifier,
|
43
|
-
autoload :Runner,
|
43
|
+
autoload :Notifier, "test_notifier/notifier"
|
44
|
+
autoload :Runner, "test_notifier/runner"
|
45
|
+
autoload :Stats, "test_notifier/stats"
|
44
46
|
end
|
@@ -16,7 +16,14 @@ Autotest.add_hook :ran_command do |at|
|
|
16
16
|
elsif test_unit_matches
|
17
17
|
_, tests, assertions, failures, errors = *test_unit_matches
|
18
18
|
|
19
|
-
|
19
|
+
if errors.to_i.nonzero?
|
20
|
+
status = :error
|
21
|
+
elsif failures.to_i.nonzero?
|
22
|
+
status = :fail
|
23
|
+
else
|
24
|
+
status = :success
|
25
|
+
end
|
26
|
+
|
20
27
|
message = "#{tests} tests, #{assertions} assertions, #{failures} failures, #{errors} errors"
|
21
28
|
TestNotifier.notify(:status => status, :message => message) unless tests.to_i.zero?
|
22
29
|
end
|
@@ -4,15 +4,18 @@ require "rspec/core/formatters/base_text_formatter"
|
|
4
4
|
class RSpec::Core::Formatters::BaseTextFormatter
|
5
5
|
alias dump_summary_original dump_summary
|
6
6
|
|
7
|
-
def dump_summary(duration,
|
8
|
-
dump_summary_original(duration,
|
7
|
+
def dump_summary(duration, example_count, failure_count, pending_count)
|
8
|
+
dump_summary_original(duration, example_count, failure_count, pending_count)
|
9
9
|
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
10
|
+
return if example_count.zero?
|
11
|
+
|
12
|
+
stats = TestNotifier::Stats.new(:rspec, {
|
13
|
+
:total => example_count,
|
14
|
+
:fail => failure_count,
|
15
|
+
:pending => pending_count,
|
16
|
+
:error => examples.reject {|e| e.instance_variable_get("@exception").nil?}.count
|
17
|
+
})
|
18
|
+
|
19
|
+
TestNotifier.notify(:status => stats.status, :message => stats.message)
|
17
20
|
end
|
18
21
|
end
|
@@ -4,15 +4,18 @@ require "spec/runner/formatter/base_text_formatter"
|
|
4
4
|
class Spec::Runner::Formatter::BaseTextFormatter
|
5
5
|
alias dump_summary_original dump_summary
|
6
6
|
|
7
|
-
def dump_summary(duration,
|
8
|
-
dump_summary_original(duration,
|
7
|
+
def dump_summary(duration, example_count, failure_count, pending_count)
|
8
|
+
dump_summary_original(duration, example_count, failure_count, pending_count)
|
9
9
|
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
10
|
+
return if example_count.zero?
|
11
|
+
|
12
|
+
stats = TestNotifier::Stats.new(:spec, {
|
13
|
+
:total => example_count,
|
14
|
+
:fail => failure_count,
|
15
|
+
:pending => pending_count,
|
16
|
+
:error => nil
|
17
|
+
})
|
18
|
+
|
19
|
+
TestNotifier.notify(:status => stats.status, :message => stats.message) if example_count > 0
|
17
20
|
end
|
18
21
|
end
|
@@ -10,12 +10,11 @@ class Test::Unit::UI::Console::TestRunner
|
|
10
10
|
begin
|
11
11
|
re = /(\d+) tests, (\d+) assertions, (\d+) failures, (\d+) errors/
|
12
12
|
_, tests, assertions, failures, errors = *@result.to_s.match(re)
|
13
|
+
return if tests.to_i.zero?
|
13
14
|
|
14
|
-
return if tests.to_i == 0
|
15
15
|
|
16
|
-
|
17
|
-
|
18
|
-
TestNotifier.notify(:status => status, :message => message)
|
16
|
+
stats = TestNotifier::Stats.new(:test_unit, :total => tests, :assertions => assertions, :fail => failures, :error => errors)
|
17
|
+
TestNotifier.notify(:status => stats.status, :message => stats.message)
|
19
18
|
rescue
|
20
19
|
end
|
21
20
|
end
|
@@ -0,0 +1,89 @@
|
|
1
|
+
module TestNotifier
|
2
|
+
class Stats
|
3
|
+
attr_accessor :adapter, :options
|
4
|
+
|
5
|
+
def initialize(adapter, options = {})
|
6
|
+
@adapter = adapter
|
7
|
+
@options = normalize(options)
|
8
|
+
end
|
9
|
+
|
10
|
+
def status
|
11
|
+
@options = normalize(options)
|
12
|
+
send("status_for_#{adapter}")
|
13
|
+
end
|
14
|
+
|
15
|
+
def message
|
16
|
+
@options = normalize(options)
|
17
|
+
send("message_for_#{adapter}")
|
18
|
+
end
|
19
|
+
|
20
|
+
private
|
21
|
+
def normalize(options)
|
22
|
+
[:total, :success, :fail, :pending, :error, :assertions].inject({}) do |buffer, key|
|
23
|
+
buffer[key] = options[key].to_i
|
24
|
+
buffer
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
def status_for_test_unit
|
29
|
+
if options[:error].nonzero?
|
30
|
+
:error
|
31
|
+
elsif options[:fail].nonzero?
|
32
|
+
:fail
|
33
|
+
else
|
34
|
+
:success
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
38
|
+
def status_for_rspec
|
39
|
+
if options[:error].nonzero?
|
40
|
+
:error
|
41
|
+
elsif options[:fail].nonzero?
|
42
|
+
:fail
|
43
|
+
else
|
44
|
+
:success
|
45
|
+
end
|
46
|
+
end
|
47
|
+
|
48
|
+
def status_for_spec
|
49
|
+
if options[:fail].nonzero?
|
50
|
+
:fail
|
51
|
+
else
|
52
|
+
:success
|
53
|
+
end
|
54
|
+
end
|
55
|
+
|
56
|
+
def message_for_rspec
|
57
|
+
options[:success] = options[:total] - options[:fail]
|
58
|
+
options[:fail] = options[:fail] - options[:error]
|
59
|
+
|
60
|
+
text = []
|
61
|
+
text << "#{options[:total]} " + pluralize(options[:total], "example")
|
62
|
+
text << "#{options[:fail]} failed" unless options[:fail].zero?
|
63
|
+
text << "#{options[:pending]} pending" unless options[:pending].zero?
|
64
|
+
text << "#{options[:error]} " + pluralize(options[:error], "error") unless options[:error].zero?
|
65
|
+
text.join(", ")
|
66
|
+
end
|
67
|
+
|
68
|
+
def message_for_spec
|
69
|
+
text = []
|
70
|
+
text << "#{options[:total]} " + pluralize(options[:total], "example")
|
71
|
+
text << "#{options[:fail]} failed" unless options[:fail].zero?
|
72
|
+
text << "#{options[:pending]} pending" unless options[:pending].zero?
|
73
|
+
text.join(", ")
|
74
|
+
end
|
75
|
+
|
76
|
+
def message_for_test_unit
|
77
|
+
text = []
|
78
|
+
text << "#{options[:total]} " + pluralize(options[:total], "test")
|
79
|
+
text << "#{options[:assertions]} " + pluralize(options[:assertions], "assertion")
|
80
|
+
text << "#{options[:fail]} failed" unless options[:fail].zero?
|
81
|
+
text << "#{options[:error]} " + pluralize(options[:error], "error") unless options[:error].zero?
|
82
|
+
text.join(", ")
|
83
|
+
end
|
84
|
+
|
85
|
+
def pluralize(count, text)
|
86
|
+
count > 1 ? "#{text}s" : text
|
87
|
+
end
|
88
|
+
end
|
89
|
+
end
|
data/resources/error.png
ADDED
Binary file
|
data/test/stats_test.rb
ADDED
@@ -0,0 +1,84 @@
|
|
1
|
+
require "test_helper"
|
2
|
+
|
3
|
+
class TestNotifier::Stats::RSpecTest < Test::Unit::TestCase
|
4
|
+
def setup
|
5
|
+
@stats = TestNotifier::Stats.new(:rspec)
|
6
|
+
end
|
7
|
+
|
8
|
+
test "success message" do
|
9
|
+
@stats.options = { :total => 10 }
|
10
|
+
assert_equal "10 examples", @stats.message
|
11
|
+
end
|
12
|
+
|
13
|
+
test "message with failing examples" do
|
14
|
+
@stats.options = { :total => 10, :fail => 5 }
|
15
|
+
assert_equal "10 examples, 5 failed", @stats.message
|
16
|
+
end
|
17
|
+
|
18
|
+
test "message with pending examples" do
|
19
|
+
@stats.options = { :total => 10, :pending => 5 }
|
20
|
+
assert_equal "10 examples, 5 pending", @stats.message
|
21
|
+
end
|
22
|
+
|
23
|
+
test "message with error examples" do
|
24
|
+
@stats.options = { :total => 10, :fail => 5, :error => 5 }
|
25
|
+
assert_equal "10 examples, 5 errors", @stats.message
|
26
|
+
end
|
27
|
+
|
28
|
+
test "message with all types" do
|
29
|
+
@stats.options = { :total => 6, :fail => 3, :error => 2, :pending => 3 }
|
30
|
+
assert_equal "6 examples, 1 failed, 3 pending, 2 errors", @stats.message
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
class TestNotifier::Stats::SpecTest < Test::Unit::TestCase
|
35
|
+
def setup
|
36
|
+
@stats = TestNotifier::Stats.new(:spec)
|
37
|
+
end
|
38
|
+
|
39
|
+
test "success message" do
|
40
|
+
@stats.options = { :total => 10 }
|
41
|
+
assert_equal "10 examples", @stats.message
|
42
|
+
end
|
43
|
+
|
44
|
+
test "message with failing examples" do
|
45
|
+
@stats.options = { :total => 10, :fail => 5 }
|
46
|
+
assert_equal "10 examples, 5 failed", @stats.message
|
47
|
+
end
|
48
|
+
|
49
|
+
test "message with pending examples" do
|
50
|
+
@stats.options = { :total => 10, :pending => 5 }
|
51
|
+
assert_equal "10 examples, 5 pending", @stats.message
|
52
|
+
end
|
53
|
+
|
54
|
+
test "message with all types" do
|
55
|
+
@stats.options = { :total => 6, :fail => 2, :pending => 3 }
|
56
|
+
assert_equal "6 examples, 2 failed, 3 pending", @stats.message
|
57
|
+
end
|
58
|
+
end
|
59
|
+
|
60
|
+
class TestNotifier::Stats::TestUnitTest < Test::Unit::TestCase
|
61
|
+
def setup
|
62
|
+
@stats = TestNotifier::Stats.new(:test_unit)
|
63
|
+
end
|
64
|
+
|
65
|
+
test "success message" do
|
66
|
+
@stats.options = { :total => 10, :assertions => 20 }
|
67
|
+
assert_equal "10 tests, 20 assertions", @stats.message
|
68
|
+
end
|
69
|
+
|
70
|
+
test "message with failing examples" do
|
71
|
+
@stats.options = { :total => 10, :assertions => 20, :fail => 5 }
|
72
|
+
assert_equal "10 tests, 20 assertions, 5 failed", @stats.message
|
73
|
+
end
|
74
|
+
|
75
|
+
test "message with error examples" do
|
76
|
+
@stats.options = { :total => 10, :assertions => 20, :error => 5 }
|
77
|
+
assert_equal "10 tests, 20 assertions, 5 errors", @stats.message
|
78
|
+
end
|
79
|
+
|
80
|
+
test "message with all types" do
|
81
|
+
@stats.options = { :total => 6, :fail => 2, :error => 3, :assertions => 20 }
|
82
|
+
assert_equal "6 tests, 20 assertions, 2 failed, 3 errors", @stats.message
|
83
|
+
end
|
84
|
+
end
|
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: test_notifier
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 17
|
5
5
|
prerelease: false
|
6
6
|
segments:
|
7
7
|
- 0
|
8
8
|
- 3
|
9
|
-
-
|
10
|
-
version: 0.3.
|
9
|
+
- 1
|
10
|
+
version: 0.3.1
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- Nando Vieira
|
@@ -48,12 +48,15 @@ files:
|
|
48
48
|
- lib/test_notifier/runner/rspec.rb
|
49
49
|
- lib/test_notifier/runner/spec.rb
|
50
50
|
- lib/test_notifier/runner/test_unit.rb
|
51
|
+
- lib/test_notifier/stats.rb
|
51
52
|
- lib/test_notifier/test_unit.rb
|
52
53
|
- lib/test_notifier/version.rb
|
54
|
+
- resources/error.png
|
53
55
|
- resources/fail.png
|
54
56
|
- resources/register-growl.scpt
|
55
57
|
- resources/success.png
|
56
58
|
- test/notifier_test.rb
|
59
|
+
- test/stats_test.rb
|
57
60
|
- test/test_helper.rb
|
58
61
|
- test/test_notifier_test.rb
|
59
62
|
has_rdoc: true
|
@@ -92,5 +95,6 @@ specification_version: 3
|
|
92
95
|
summary: Display system notifications (dbus, growl and snarl) after running tests.
|
93
96
|
test_files:
|
94
97
|
- test/notifier_test.rb
|
98
|
+
- test/stats_test.rb
|
95
99
|
- test/test_helper.rb
|
96
100
|
- test/test_notifier_test.rb
|