shoulda-addons 0.1.1 → 0.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/lib/shoulda_benchmark.rb +41 -11
- data/lib/shoulda_list_runner.rb +41 -23
- metadata +2 -2
data/lib/shoulda_benchmark.rb
CHANGED
@@ -1,3 +1,44 @@
|
|
1
|
+
module ShouldaAddons
|
2
|
+
module MiniTest
|
3
|
+
module Benchmark
|
4
|
+
def self.included(base)
|
5
|
+
base.class_eval do
|
6
|
+
alias :run_before_benchmark :run
|
7
|
+
|
8
|
+
def run args = []
|
9
|
+
result = run_before_benchmark
|
10
|
+
puts Shoulda.runtimes.collect{|name, total| [name, total]}.
|
11
|
+
sort{|runtime1, runtime2| runtime2[1] <=> runtime1[1]}[0...10].
|
12
|
+
collect{|name, total| "#{"%0.2f" % total} s: #{name.to_s.gsub(/test: /, "")}"}.<<("").join("\n")
|
13
|
+
result
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
if defined?(MiniTest::Unit)
|
22
|
+
module ::MiniTest
|
23
|
+
class Unit
|
24
|
+
include ShouldaAddons::MiniTest::Benchmark
|
25
|
+
end
|
26
|
+
end
|
27
|
+
else
|
28
|
+
module Test
|
29
|
+
module Unit
|
30
|
+
class TestResult
|
31
|
+
alias :to_old_s :to_s
|
32
|
+
def to_s
|
33
|
+
Shoulda.runtimes.collect{|name, total| [name, total]}.
|
34
|
+
sort{|runtime1, runtime2| runtime2[1] <=> runtime1[1]}[0...10].
|
35
|
+
collect{|name, total| "#{"%0.2f" % total} s: #{name.to_s.gsub(/test: /, "")}"}.<<("").<<(to_old_s).join("\n")
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
1
42
|
module Test
|
2
43
|
module Unit
|
3
44
|
class TestCase
|
@@ -17,17 +58,6 @@ module Test
|
|
17
58
|
end
|
18
59
|
@ignoring_added_methods = false
|
19
60
|
end
|
20
|
-
|
21
|
-
end
|
22
|
-
|
23
|
-
class TestResult
|
24
|
-
alias :to_old_s :to_s
|
25
|
-
def to_s
|
26
|
-
puts Shoulda.runtimes.collect {|name, total| total}.inject(0) {|num, sum| num + sum}
|
27
|
-
Shoulda.runtimes.collect{|name, total| [name, total]}.
|
28
|
-
sort{|runtime1, runtime2| runtime2[1] <=> runtime1[1]}[0...10].
|
29
|
-
collect{|name, total| "#{"%0.2f" % total} s: #{name.to_s.gsub(/test: /, "")}"}.<<("").<<(to_old_s).join("\n")
|
30
|
-
end
|
31
61
|
end
|
32
62
|
end
|
33
63
|
end
|
data/lib/shoulda_list_runner.rb
CHANGED
@@ -1,6 +1,3 @@
|
|
1
|
-
require 'test/unit'
|
2
|
-
require 'test/unit/ui/console/testrunner'
|
3
|
-
|
4
1
|
module Color
|
5
2
|
COLORS = { :clear => 0, :red => 31, :green => 32, :yellow => 33 }
|
6
3
|
def self.method_missing(color_name, *args)
|
@@ -11,30 +8,51 @@ module Color
|
|
11
8
|
end
|
12
9
|
end
|
13
10
|
|
14
|
-
|
15
|
-
module
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
11
|
+
if defined?(MiniTest::Unit)
|
12
|
+
module MiniTest
|
13
|
+
class Unit
|
14
|
+
class TestCase
|
15
|
+
alias_method :run_before_shoulda_runner, :run
|
16
|
+
|
17
|
+
def run runner
|
18
|
+
result = run_before_shoulda_runner(runner)
|
19
|
+
if result == '.'
|
20
|
+
Color.green(name.gsub(/test: /, "")) + "\n"
|
21
|
+
else
|
22
|
+
Color.red(name.gsub(/test: /, "")) + "\n"
|
25
23
|
end
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
28
|
+
else
|
29
|
+
require 'test/unit/ui/console/testrunner'
|
30
|
+
|
31
|
+
module Test
|
32
|
+
module Unit
|
33
|
+
module UI
|
34
|
+
module Console
|
35
|
+
class TestRunner
|
36
|
+
def test_finished(name)
|
37
|
+
if is_fault?(name)
|
38
|
+
puts Color.red(name.gsub(/test: /, ""))
|
39
|
+
else
|
40
|
+
puts Color.green(name.to_s.gsub(/test: /, ""))
|
41
|
+
end
|
42
|
+
end
|
26
43
|
|
27
|
-
|
28
|
-
|
29
|
-
|
44
|
+
def is_fault?(name)
|
45
|
+
!_faults_by_name[name].nil?
|
46
|
+
end
|
30
47
|
|
31
|
-
|
32
|
-
|
33
|
-
|
48
|
+
def _faults_by_name
|
49
|
+
@_faults_by_name ||= {}
|
50
|
+
end
|
34
51
|
|
35
|
-
|
36
|
-
|
37
|
-
|
52
|
+
def add_fault(fault)
|
53
|
+
@faults << fault
|
54
|
+
_faults_by_name[fault.test_name] = fault
|
55
|
+
end
|
38
56
|
end
|
39
57
|
end
|
40
58
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: shoulda-addons
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Mathias Meyer
|
@@ -9,7 +9,7 @@ autorequire:
|
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
11
|
|
12
|
-
date: 2009-10-
|
12
|
+
date: 2009-10-18 00:00:00 +02:00
|
13
13
|
default_executable:
|
14
14
|
dependencies: []
|
15
15
|
|