shoulda-addons 0.1.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/README.md +15 -0
- data/lib/shoulda_addons.rb +4 -0
- data/lib/shoulda_benchmark.rb +39 -0
- data/lib/shoulda_list_runner.rb +43 -0
- metadata +58 -0
data/README.md
ADDED
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
Like RSpec's profiling of the 10 slowest test cases? Like how it can print out the full test names in shiny and colorful terminal awesomeness instead of meaningless dots? Me too.
|
|
2
|
+
|
|
3
|
+
require 'shoulda_benchmark'
|
|
4
|
+
|
|
5
|
+
Patches Shoulda to track runtimes of all your tests, showing you the 10 slowest.
|
|
6
|
+
|
|
7
|
+
require 'shoulda_list_runner'
|
|
8
|
+
|
|
9
|
+
Patches Test::Unit to print out test names colored either red or green (you can guess which is which). Blatantly inspired by RedGreen and adapted for Shoulda awesomeness.
|
|
10
|
+
|
|
11
|
+
`require 'shoulda_addons'` if you want both, and why wouldn't you?
|
|
12
|
+
|
|
13
|
+
Install from gemcutter via: `gem install shoulda-addons`
|
|
14
|
+
|
|
15
|
+
Author: Mathias Meyer <meyer@paperplanes.de>
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
module Test
|
|
2
|
+
module Unit
|
|
3
|
+
class TestCase
|
|
4
|
+
def self.method_added(name)
|
|
5
|
+
return if @ignoring_added_methods
|
|
6
|
+
|
|
7
|
+
@__instrumented_methods ||= {}
|
|
8
|
+
return unless name.to_s.match(/^test:/) || @__instrumented_methods[name]
|
|
9
|
+
@ignoring_added_methods = true
|
|
10
|
+
alias_method " #{name}", "#{name}"
|
|
11
|
+
@__instrumented_methods[name] = true
|
|
12
|
+
define_method(name) do
|
|
13
|
+
runtime = Benchmark.realtime do
|
|
14
|
+
send(" #{name}")
|
|
15
|
+
end
|
|
16
|
+
Shoulda.runtimes[name] = runtime
|
|
17
|
+
end
|
|
18
|
+
@ignoring_added_methods = false
|
|
19
|
+
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
|
+
end
|
|
32
|
+
end
|
|
33
|
+
end
|
|
34
|
+
|
|
35
|
+
module Shoulda
|
|
36
|
+
def self.runtimes
|
|
37
|
+
@runtimes ||= {}
|
|
38
|
+
end
|
|
39
|
+
end
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
require 'test/unit'
|
|
2
|
+
require 'test/unit/ui/console/testrunner'
|
|
3
|
+
|
|
4
|
+
module Color
|
|
5
|
+
COLORS = { :clear => 0, :red => 31, :green => 32, :yellow => 33 }
|
|
6
|
+
def self.method_missing(color_name, *args)
|
|
7
|
+
color(color_name) + args.first + color(:clear)
|
|
8
|
+
end
|
|
9
|
+
def self.color(color)
|
|
10
|
+
"\e[#{COLORS[color.to_sym]}m"
|
|
11
|
+
end
|
|
12
|
+
end
|
|
13
|
+
|
|
14
|
+
module Test
|
|
15
|
+
module Unit
|
|
16
|
+
module UI
|
|
17
|
+
module Console
|
|
18
|
+
class TestRunner
|
|
19
|
+
def test_finished(name)
|
|
20
|
+
if is_fault?(name)
|
|
21
|
+
puts Color.red(name.gsub(/test: /, ""))
|
|
22
|
+
else
|
|
23
|
+
puts Color.green(name.to_s.gsub(/test: /, ""))
|
|
24
|
+
end
|
|
25
|
+
end
|
|
26
|
+
|
|
27
|
+
def is_fault?(name)
|
|
28
|
+
!_faults_by_name[name].nil?
|
|
29
|
+
end
|
|
30
|
+
|
|
31
|
+
def _faults_by_name
|
|
32
|
+
@_faults_by_name ||= {}
|
|
33
|
+
end
|
|
34
|
+
|
|
35
|
+
def add_fault(fault)
|
|
36
|
+
@faults << fault
|
|
37
|
+
_faults_by_name[fault.test_name] = fault
|
|
38
|
+
end
|
|
39
|
+
end
|
|
40
|
+
end
|
|
41
|
+
end
|
|
42
|
+
end
|
|
43
|
+
end
|
metadata
ADDED
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
|
2
|
+
name: shoulda-addons
|
|
3
|
+
version: !ruby/object:Gem::Version
|
|
4
|
+
version: 0.1.0
|
|
5
|
+
platform: ruby
|
|
6
|
+
authors:
|
|
7
|
+
- Mathias Meyer
|
|
8
|
+
autorequire:
|
|
9
|
+
bindir: bin
|
|
10
|
+
cert_chain: []
|
|
11
|
+
|
|
12
|
+
date: 2009-10-17 00:00:00 +02:00
|
|
13
|
+
default_executable:
|
|
14
|
+
dependencies: []
|
|
15
|
+
|
|
16
|
+
description: Some awesome addons for Shoulda to benchmark tests, or to get nicer output than just a dot, because what the dot?
|
|
17
|
+
email: meyer@paperplanes.de
|
|
18
|
+
executables: []
|
|
19
|
+
|
|
20
|
+
extensions: []
|
|
21
|
+
|
|
22
|
+
extra_rdoc_files:
|
|
23
|
+
- README.md
|
|
24
|
+
files:
|
|
25
|
+
- README.md
|
|
26
|
+
- lib/shoulda_addons.rb
|
|
27
|
+
- lib/shoulda_benchmark.rb
|
|
28
|
+
- lib/shoulda_list_runner.rb
|
|
29
|
+
has_rdoc: true
|
|
30
|
+
homepage: http://github.com/mattmatt/shoulda-addons
|
|
31
|
+
licenses: []
|
|
32
|
+
|
|
33
|
+
post_install_message:
|
|
34
|
+
rdoc_options:
|
|
35
|
+
- --charset=UTF-8
|
|
36
|
+
require_paths:
|
|
37
|
+
- lib
|
|
38
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
|
39
|
+
requirements:
|
|
40
|
+
- - ">="
|
|
41
|
+
- !ruby/object:Gem::Version
|
|
42
|
+
version: "0"
|
|
43
|
+
version:
|
|
44
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
|
45
|
+
requirements:
|
|
46
|
+
- - ">="
|
|
47
|
+
- !ruby/object:Gem::Version
|
|
48
|
+
version: "0"
|
|
49
|
+
version:
|
|
50
|
+
requirements: []
|
|
51
|
+
|
|
52
|
+
rubyforge_project:
|
|
53
|
+
rubygems_version: 1.3.5
|
|
54
|
+
signing_key:
|
|
55
|
+
specification_version: 3
|
|
56
|
+
summary: Neat addons for Shoulda, because Shoulda is neat.
|
|
57
|
+
test_files: []
|
|
58
|
+
|