shoulda-addons 0.2.2 → 0.2.3

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.
@@ -1,3 +1,5 @@
1
+ require 'benchmark'
2
+
1
3
  module ShouldaAddons
2
4
  module MiniTest
3
5
  module Benchmark
@@ -47,6 +49,11 @@ module Test
47
49
  def self.method_added(name)
48
50
  return if @ignoring_added_methods
49
51
 
52
+ test_name = if respond_to?(:name)
53
+ name
54
+ elsif respond_to?(:__name__)
55
+ __name__
56
+ end
50
57
  @__instrumented_methods ||= {}
51
58
  return unless name.to_s.match(/^test:/) || @__instrumented_methods[name]
52
59
  @ignoring_added_methods = true
@@ -56,7 +63,7 @@ module Test
56
63
  runtime = Benchmark.realtime do
57
64
  send(" #{name}")
58
65
  end
59
- Shoulda.runtimes[self.name] = runtime
66
+ Shoulda.runtimes[test_name] = runtime
60
67
  end
61
68
  @ignoring_added_methods = false
62
69
  end
@@ -1,10 +1,12 @@
1
- module Color
2
- COLORS = { :clear => 0, :red => 31, :green => 32, :yellow => 33 }
3
- def self.method_missing(color_name, *args)
4
- color(color_name) + args.first + color(:clear)
5
- end
6
- def self.color(color)
7
- "\e[#{COLORS[color.to_sym]}m"
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
8
10
  end
9
11
  end
10
12
 
@@ -15,11 +17,16 @@ if defined?(MiniTest::Unit)
15
17
  alias_method :run_before_shoulda_runner, :run
16
18
 
17
19
  def run runner
20
+ test_name = if respond_to?(:name)
21
+ name
22
+ elsif respond_to?(:__name__)
23
+ __name__
24
+ end
18
25
  result = run_before_shoulda_runner(runner)
19
26
  if result == '.'
20
- Color.green(name.gsub(/test: /, "")) + "\n"
27
+ ShouldaAddons::Color.green(test_name.gsub(/test: /, "")) + "\n"
21
28
  else
22
- Color.red(name.gsub(/test: /, "")) + "\n"
29
+ ShouldaAddons::Color.red(test_name.gsub(/test: /, "")) + "\n"
23
30
  end
24
31
  end
25
32
  end
@@ -42,9 +49,9 @@ else
42
49
  end
43
50
  else
44
51
  if is_fault?(name)
45
- output(Color.red(name.gsub(/test: /, "")))
52
+ output(ShouldaAddons::Color.red(name.gsub(/test: /, "")))
46
53
  else
47
- output(Color.green(name.to_s.gsub(/test: /, "")))
54
+ output(ShouldaAddons::Color.green(name.to_s.gsub(/test: /, "")))
48
55
  end
49
56
  end
50
57
  end
@@ -66,4 +73,4 @@ else
66
73
  end
67
74
  end
68
75
  end
69
- end
76
+ end
@@ -0,0 +1,27 @@
1
+ unless RUBY_VERSION >= '1.9'
2
+ puts 'Meant to run on Ruby 1.9'
3
+ exit
4
+ end
5
+
6
+ puts 'Running test for Minitest on Ruby 1.9'
7
+
8
+ require 'rubygems'
9
+ require 'test/unit'
10
+ require 'shoulda'
11
+ require File.dirname(__FILE__) + '/../lib/shoulda_benchmark'
12
+
13
+ class ShouldaBenchmarkMinitestTest < Test::Unit::TestCase
14
+ context 'Vrooom, vroom' do
15
+ should 'be slow' do
16
+ sleep 0.2
17
+ end
18
+
19
+ should 'be faster' do
20
+ sleep 0.1
21
+ end
22
+
23
+ should 'be wicked fast' do
24
+ # first!
25
+ end
26
+ end
27
+ end
@@ -0,0 +1,22 @@
1
+ puts 'Running test for Test::Unit 1.x'
2
+
3
+ require 'test/unit'
4
+ require 'rubygems'
5
+ require 'shoulda'
6
+ require File.dirname(__FILE__) + '/../lib/shoulda_benchmark'
7
+
8
+ class ShouldaBenchmarkTestUnit1xTest < Test::Unit::TestCase
9
+ context 'Vrooom, vroom' do
10
+ should 'be slow' do
11
+ sleep 0.2
12
+ end
13
+
14
+ should 'be faster' do
15
+ sleep 0.1
16
+ end
17
+
18
+ should 'be wicked fast' do
19
+ # first!
20
+ end
21
+ end
22
+ end
@@ -0,0 +1,22 @@
1
+ puts 'Running test for Test::Unit 2.x'
2
+
3
+ require 'rubygems'
4
+ gem 'test-unit'
5
+ require 'shoulda'
6
+ require File.dirname(__FILE__) + '/../lib/shoulda_benchmark'
7
+
8
+ class ShouldaBenchmarkTestUnit2xTest < Test::Unit::TestCase
9
+ context 'Vrooom, vroom' do
10
+ should 'be slow' do
11
+ sleep 0.2
12
+ end
13
+
14
+ should 'be faster' do
15
+ sleep 0.1
16
+ end
17
+
18
+ should 'be wicked fast' do
19
+ # first!
20
+ end
21
+ end
22
+ end
@@ -0,0 +1,23 @@
1
+ unless RUBY_VERSION >= '1.9'
2
+ puts 'Meant to run on Ruby 1.9'
3
+ exit
4
+ end
5
+
6
+ puts 'Running test for Minitest'
7
+
8
+ require 'test/unit'
9
+ require 'rubygems'
10
+ require File.dirname(__FILE__) + '/../lib/shoulda_list_runner'
11
+ require 'shoulda'
12
+
13
+ class ShouldaBenchmarkTestUnit1xTest < Test::Unit::TestCase
14
+ context 'I' do
15
+ should 'be green' do
16
+ assert true
17
+ end
18
+
19
+ should 'be red' do
20
+ assert false
21
+ end
22
+ end
23
+ end
@@ -0,0 +1,18 @@
1
+ puts 'Running test for Test::Unit 1.x'
2
+
3
+ require 'test/unit'
4
+ require 'rubygems'
5
+ require 'shoulda'
6
+ require File.dirname(__FILE__) + '/../lib/shoulda_list_runner'
7
+
8
+ class ShouldaBenchmarkTestUnit1xTest < Test::Unit::TestCase
9
+ context 'Vrooom, vroom' do
10
+ should 'be green' do
11
+ assert true
12
+ end
13
+
14
+ should 'be red' do
15
+ assert false
16
+ end
17
+ end
18
+ end
@@ -0,0 +1,18 @@
1
+ puts 'Running test for Test::Unit 2.x'
2
+
3
+ require 'rubygems'
4
+ gem 'test-unit'
5
+ require File.dirname(__FILE__) + '/../lib/shoulda_list_runner'
6
+ require 'shoulda'
7
+
8
+ class ShouldaBenchmarkTestUnit1xTest < Test::Unit::TestCase
9
+ context 'I' do
10
+ should 'be green' do
11
+ assert true
12
+ end
13
+
14
+ should 'be red' do
15
+ assert false
16
+ end
17
+ end
18
+ end
metadata CHANGED
@@ -1,7 +1,12 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: shoulda-addons
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.2
4
+ prerelease: false
5
+ segments:
6
+ - 0
7
+ - 2
8
+ - 3
9
+ version: 0.2.3
5
10
  platform: ruby
6
11
  authors:
7
12
  - Mathias Meyer
@@ -9,7 +14,7 @@ autorequire:
9
14
  bindir: bin
10
15
  cert_chain: []
11
16
 
12
- date: 2009-11-06 00:00:00 +01:00
17
+ date: 2010-11-28 00:00:00 +01:00
13
18
  default_executable:
14
19
  dependencies: []
15
20
 
@@ -26,33 +31,48 @@ files:
26
31
  - lib/shoulda_addons.rb
27
32
  - lib/shoulda_benchmark.rb
28
33
  - lib/shoulda_list_runner.rb
34
+ - test/shoulda_benchmark_minitest_test.rb
35
+ - test/shoulda_benchmark_test_unit_1x_test.rb
36
+ - test/shoulda_benchmark_test_unit_2x_test.rb
37
+ - test/shoulda_list_runner_minitest_test.rb
38
+ - test/shoulda_list_runner_test_unit_1x_test.rb
39
+ - test/shoulda_list_runner_test_unit_2x_test.rb
29
40
  has_rdoc: true
30
41
  homepage: http://github.com/mattmatt/shoulda-addons
31
42
  licenses: []
32
43
 
33
44
  post_install_message:
34
- rdoc_options:
35
- - --charset=UTF-8
45
+ rdoc_options: []
46
+
36
47
  require_paths:
37
48
  - lib
38
49
  required_ruby_version: !ruby/object:Gem::Requirement
50
+ none: false
39
51
  requirements:
40
52
  - - ">="
41
53
  - !ruby/object:Gem::Version
54
+ segments:
55
+ - 0
42
56
  version: "0"
43
- version:
44
57
  required_rubygems_version: !ruby/object:Gem::Requirement
58
+ none: false
45
59
  requirements:
46
60
  - - ">="
47
61
  - !ruby/object:Gem::Version
62
+ segments:
63
+ - 0
48
64
  version: "0"
49
- version:
50
65
  requirements: []
51
66
 
52
67
  rubyforge_project:
53
- rubygems_version: 1.3.5
68
+ rubygems_version: 1.3.7
54
69
  signing_key:
55
70
  specification_version: 3
56
71
  summary: Neat addons for Shoulda, because Shoulda is neat.
57
- test_files: []
58
-
72
+ test_files:
73
+ - test/shoulda_benchmark_minitest_test.rb
74
+ - test/shoulda_benchmark_test_unit_1x_test.rb
75
+ - test/shoulda_benchmark_test_unit_2x_test.rb
76
+ - test/shoulda_list_runner_minitest_test.rb
77
+ - test/shoulda_list_runner_test_unit_1x_test.rb
78
+ - test/shoulda_list_runner_test_unit_2x_test.rb