cdmwebs-shoulda-addons 0.2.2

Sign up to get free protection for your applications and to get access to all the features.
data/README.md ADDED
@@ -0,0 +1,22 @@
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
+ Is it safe for Ruby 1.9? Yes! Support for the new MiniTest framework is built-in.
16
+
17
+ Author: Mathias Meyer <meyer@paperplanes.de>
18
+
19
+ #### Contributions
20
+
21
+ * Test::Unit 2.0 compatibility (github.com/ffmike)
22
+ * Include the test class name in the benchmark output for Test::Unit (github.com/tobias)
@@ -0,0 +1,4 @@
1
+ $:.<<(File.expand_path(File.dirname(__FILE__)))
2
+
3
+ require 'shoulda_benchmark'
4
+ require 'shoulda_list_runner'
@@ -0,0 +1,73 @@
1
+ require 'benchmark'
2
+
3
+ module ShouldaAddons
4
+ module MiniTest
5
+ module Benchmark
6
+ def self.included(base)
7
+ base.class_eval do
8
+ alias :run_before_benchmark :run
9
+
10
+ def run args = []
11
+ result = run_before_benchmark
12
+ puts Shoulda.runtimes.collect{|name, total| [name, total]}.
13
+ sort{|runtime1, runtime2| runtime2[1] <=> runtime1[1]}[0...10].
14
+ collect{|name, total| "#{"%0.2f" % total} s: #{name.to_s.gsub(/test: /, "")}"}.<<("").join("\n")
15
+ result
16
+ end
17
+ end
18
+ end
19
+ end
20
+ end
21
+ end
22
+
23
+ if defined?(MiniTest::Unit)
24
+ module ::MiniTest
25
+ class Unit
26
+ include ShouldaAddons::MiniTest::Benchmark
27
+ end
28
+ end
29
+ else
30
+ require 'test/unit/testresult'
31
+ module Test
32
+ module Unit
33
+ class TestResult
34
+ alias :to_old_s :to_s
35
+ def to_s
36
+ Shoulda.runtimes.collect{|name, total| [name, total]}.
37
+ sort{|runtime1, runtime2| runtime2[1] <=> runtime1[1]}[0...10].
38
+ collect{|name, total| "#{"%0.2f" % total} s: #{name.to_s.gsub(/test: /, "")}"}.<<("").<<(to_old_s).join("\n")
39
+ end
40
+ end
41
+ end
42
+ end
43
+ end
44
+
45
+ require 'test/unit/testcase'
46
+ module Test
47
+ module Unit
48
+ class TestCase
49
+ def self.method_added(name)
50
+ return if @ignoring_added_methods
51
+
52
+ @__instrumented_methods ||= {}
53
+ return unless name.to_s.match(/^test:/) || @__instrumented_methods[name]
54
+ @ignoring_added_methods = true
55
+ alias_method " #{name}", "#{name}"
56
+ @__instrumented_methods[name] = true
57
+ define_method(name) do
58
+ runtime = Benchmark.realtime do
59
+ send(" #{name}")
60
+ end
61
+ Shoulda.runtimes[self.name] = runtime
62
+ end
63
+ @ignoring_added_methods = false
64
+ end
65
+ end
66
+ end
67
+ end
68
+
69
+ module Shoulda
70
+ def self.runtimes
71
+ @runtimes ||= {}
72
+ end
73
+ end
@@ -0,0 +1,71 @@
1
+ module ShouldaAddons
2
+ module Color
3
+ @@colors = { :clear => 0, :red => 31, :green => 32, :yellow => 33 }
4
+ def self.method_missing(color_name, *args)
5
+ color(color_name) + args.first + color(:clear)
6
+ end
7
+ def self.color(color)
8
+ "\e[#{@@colors[color.to_sym]}m"
9
+ end
10
+ end
11
+ end
12
+
13
+ if defined?(MiniTest::Unit)
14
+ module MiniTest
15
+ class Unit
16
+ class TestCase
17
+ alias_method :run_before_shoulda_runner, :run
18
+
19
+ def run runner
20
+ result = run_before_shoulda_runner(runner)
21
+ if result == '.'
22
+ ShouldaAddons::Color.green(name.gsub(/test: /, "")) + "\n"
23
+ else
24
+ ShouldaAddons::Color.red(name.gsub(/test: /, "")) + "\n"
25
+ end
26
+ end
27
+ end
28
+ end
29
+ end
30
+ else
31
+ require 'test/unit/ui/console/testrunner'
32
+
33
+ module Test
34
+ module Unit
35
+ module UI
36
+ module Console
37
+ class TestRunner
38
+ def test_finished(name)
39
+ if defined?(Test::Unit::Color)
40
+ if is_fault?(name)
41
+ output(name.gsub(/test: /, ""), Test::Unit::Color.new("red"))
42
+ else
43
+ output(name.gsub(/test: /, ""), Test::Unit::Color.new("green"))
44
+ end
45
+ else
46
+ if is_fault?(name)
47
+ output(ShouldaAddons::Color.red(name.gsub(/test: /, "")))
48
+ else
49
+ output(ShouldaAddons::Color.green(name.to_s.gsub(/test: /, "")))
50
+ end
51
+ end
52
+ end
53
+
54
+ def is_fault?(name)
55
+ !_faults_by_name[name].nil?
56
+ end
57
+
58
+ def _faults_by_name
59
+ @_faults_by_name ||= {}
60
+ end
61
+
62
+ def add_fault(fault)
63
+ @faults << fault
64
+ _faults_by_name[fault.test_name] = fault
65
+ end
66
+ end
67
+ end
68
+ end
69
+ end
70
+ end
71
+ end
metadata ADDED
@@ -0,0 +1,70 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: cdmwebs-shoulda-addons
3
+ version: !ruby/object:Gem::Version
4
+ hash: 19
5
+ prerelease: false
6
+ segments:
7
+ - 0
8
+ - 2
9
+ - 2
10
+ version: 0.2.2
11
+ platform: ruby
12
+ authors:
13
+ - Mathias Meyer
14
+ autorequire:
15
+ bindir: bin
16
+ cert_chain: []
17
+
18
+ date: 2009-11-06 00:00:00 -05:00
19
+ default_executable:
20
+ dependencies: []
21
+
22
+ description: Some awesome addons for Shoulda to benchmark tests, or to get nicer output than just a dot, because what the dot?
23
+ email: meyer@paperplanes.de
24
+ executables: []
25
+
26
+ extensions: []
27
+
28
+ extra_rdoc_files:
29
+ - README.md
30
+ files:
31
+ - README.md
32
+ - lib/shoulda_addons.rb
33
+ - lib/shoulda_benchmark.rb
34
+ - lib/shoulda_list_runner.rb
35
+ has_rdoc: true
36
+ homepage: http://github.com/mattmatt/shoulda-addons
37
+ licenses: []
38
+
39
+ post_install_message:
40
+ rdoc_options:
41
+ - --charset=UTF-8
42
+ require_paths:
43
+ - lib
44
+ required_ruby_version: !ruby/object:Gem::Requirement
45
+ none: false
46
+ requirements:
47
+ - - ">="
48
+ - !ruby/object:Gem::Version
49
+ hash: 3
50
+ segments:
51
+ - 0
52
+ version: "0"
53
+ required_rubygems_version: !ruby/object:Gem::Requirement
54
+ none: false
55
+ requirements:
56
+ - - ">="
57
+ - !ruby/object:Gem::Version
58
+ hash: 3
59
+ segments:
60
+ - 0
61
+ version: "0"
62
+ requirements: []
63
+
64
+ rubyforge_project:
65
+ rubygems_version: 1.3.7
66
+ signing_key:
67
+ specification_version: 3
68
+ summary: Neat addons for Shoulda, because Shoulda is neat.
69
+ test_files: []
70
+