test_unit_extend 1.0.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.rdoc +43 -0
- data/lib/before_test.rb +38 -0
- data/lib/should_have_callbacks.rb +28 -0
- data/lib/test_unit_extend.rb +2 -0
- data/test/models/user.rb +11 -0
- data/test/test_before_test.rb +18 -0
- data/test/test_before_test_with_active_support.rb +17 -0
- data/test/test_helper.rb +6 -0
- data/test/test_should_have_callbacks.rb +5 -0
- data/test/test_should_have_callbacks_with_active_support.rb +7 -0
- metadata +81 -0
data/README.rdoc
ADDED
@@ -0,0 +1,43 @@
|
|
1
|
+
== Overview
|
2
|
+
Add extension to Test::Unit.
|
3
|
+
|
4
|
+
#before_test : do something before lauch a test
|
5
|
+
#should_have_callbacks : shoulda doesn't have macro to test presence of callbacks, here is one.
|
6
|
+
|
7
|
+
== before_test
|
8
|
+
|
9
|
+
class .... < Test::Unit::TestCase
|
10
|
+
|
11
|
+
before_test :test_me, :setup_for_test_me
|
12
|
+
|
13
|
+
def test_me
|
14
|
+
assert_equal "Cup of tea please", @var # OK
|
15
|
+
end
|
16
|
+
|
17
|
+
private
|
18
|
+
|
19
|
+
def setup_for_test_me
|
20
|
+
@var = "Cup of tea please"
|
21
|
+
end
|
22
|
+
|
23
|
+
end
|
24
|
+
|
25
|
+
== should_have_callbacks
|
26
|
+
|
27
|
+
If your model has callback :my_callback on before_create, just check it in your test by :
|
28
|
+
|
29
|
+
should_have_callbacks :before_create, :my_callback
|
30
|
+
|
31
|
+
You can also pass an array :
|
32
|
+
|
33
|
+
should_have_callbacks :before_create, [:my_callback_1, :my_callback_2]
|
34
|
+
|
35
|
+
|
36
|
+
== Install
|
37
|
+
|
38
|
+
gem install test_unit_extend
|
39
|
+
|
40
|
+
== Dependencies
|
41
|
+
|
42
|
+
before_test : if you use ActiveSupport::TestCase, it doesn't work with ActiveSupport 3 (In Development)
|
43
|
+
|
data/lib/before_test.rb
ADDED
@@ -0,0 +1,38 @@
|
|
1
|
+
module TestUnitExtend
|
2
|
+
def self.included(base)
|
3
|
+
|
4
|
+
def run(result,&block)
|
5
|
+
send(@@___before_tests[method_name]) if @@___before_tests[method_name]
|
6
|
+
original_run(result,&block)
|
7
|
+
end
|
8
|
+
|
9
|
+
class << base
|
10
|
+
@@___before_tests ||= {}
|
11
|
+
|
12
|
+
def before_test test, proc
|
13
|
+
@@___before_tests.merge!({test.to_s => proc})
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
class ActiveSupport::TestCase < ::Test::Unit::TestCase
|
21
|
+
alias_method :original_run, :run
|
22
|
+
include TestUnitExtend
|
23
|
+
end if defined?(ActiveSupport::TestCase)
|
24
|
+
|
25
|
+
class Test::Unit::TestCase
|
26
|
+
alias_method :original_run, :run
|
27
|
+
|
28
|
+
def run(result,&block)
|
29
|
+
send(@@___before_tests[method_name]) if @@___before_tests[method_name]
|
30
|
+
original_run(result,&block)
|
31
|
+
end
|
32
|
+
|
33
|
+
include TestUnitExtend
|
34
|
+
end
|
35
|
+
|
36
|
+
|
37
|
+
|
38
|
+
|
@@ -0,0 +1,28 @@
|
|
1
|
+
require 'active_support/inflector'
|
2
|
+
|
3
|
+
module TestUnitExtend
|
4
|
+
|
5
|
+
def should_have_callbacks callback, methods
|
6
|
+
klass = self.name.gsub('Test', '').constantize
|
7
|
+
chain = callback.to_s + '_callback_chain'
|
8
|
+
callbacks = klass.send(chain).map{|callback| callback.instance_variable_get(:@method)}
|
9
|
+
self.send(:define_method, :test_XXX_callbacks) do
|
10
|
+
assert ([*methods] - callbacks).empty?
|
11
|
+
end
|
12
|
+
end
|
13
|
+
|
14
|
+
end
|
15
|
+
|
16
|
+
class Test::Unit::TestCase
|
17
|
+
class << self
|
18
|
+
include TestUnitExtend
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
class ActiveSupport::TestCase < ::Test::Unit::TestCase
|
23
|
+
class << self
|
24
|
+
include TestUnitExtend
|
25
|
+
end
|
26
|
+
end if defined?(ActiveSupport::TestCase)
|
27
|
+
|
28
|
+
|
data/test/models/user.rb
ADDED
@@ -0,0 +1,18 @@
|
|
1
|
+
require 'test_helper'
|
2
|
+
|
3
|
+
class BeforeTestTest < Test::Unit::TestCase
|
4
|
+
|
5
|
+
before_test :test_me, :setup_for_test_me
|
6
|
+
|
7
|
+
def test_me
|
8
|
+
assert_equal "Cup of tea please", @var
|
9
|
+
end
|
10
|
+
|
11
|
+
|
12
|
+
private
|
13
|
+
|
14
|
+
def setup_for_test_me
|
15
|
+
@var = "Cup of tea please"
|
16
|
+
end
|
17
|
+
|
18
|
+
end
|
@@ -0,0 +1,17 @@
|
|
1
|
+
require 'test_helper'
|
2
|
+
|
3
|
+
class BeforeTestWithActiveSupportTest < ActiveSupport::TestCase
|
4
|
+
|
5
|
+
before_test :test_me, :setup_for_test_me
|
6
|
+
|
7
|
+
def test_me
|
8
|
+
assert_equal "Cup of tea please", @var
|
9
|
+
end
|
10
|
+
|
11
|
+
private
|
12
|
+
|
13
|
+
def setup_for_test_me
|
14
|
+
@var = "Cup of tea please"
|
15
|
+
end
|
16
|
+
|
17
|
+
end
|
data/test/test_helper.rb
ADDED
metadata
ADDED
@@ -0,0 +1,81 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: test_unit_extend
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
hash: 23
|
5
|
+
prerelease: false
|
6
|
+
segments:
|
7
|
+
- 1
|
8
|
+
- 0
|
9
|
+
- 0
|
10
|
+
version: 1.0.0
|
11
|
+
platform: ruby
|
12
|
+
authors:
|
13
|
+
- Philippe Cantin
|
14
|
+
autorequire:
|
15
|
+
bindir: bin
|
16
|
+
cert_chain: []
|
17
|
+
|
18
|
+
date: 2010-11-15 00:00:00 +01:00
|
19
|
+
default_executable:
|
20
|
+
dependencies: []
|
21
|
+
|
22
|
+
description: "Provide extensions to Test::Unit. #before_test, #should_have_callbcks ...."
|
23
|
+
email:
|
24
|
+
executables: []
|
25
|
+
|
26
|
+
extensions: []
|
27
|
+
|
28
|
+
extra_rdoc_files:
|
29
|
+
- README.rdoc
|
30
|
+
files:
|
31
|
+
- lib/before_test.rb
|
32
|
+
- lib/should_have_callbacks.rb
|
33
|
+
- lib/test_unit_extend.rb
|
34
|
+
- README.rdoc
|
35
|
+
- test/models/user.rb
|
36
|
+
- test/test_before_test.rb
|
37
|
+
- test/test_before_test_with_active_support.rb
|
38
|
+
- test/test_helper.rb
|
39
|
+
- test/test_should_have_callbacks.rb
|
40
|
+
- test/test_should_have_callbacks_with_active_support.rb
|
41
|
+
has_rdoc: true
|
42
|
+
homepage: http://github.com/anoiaque/test_unit_extend
|
43
|
+
licenses: []
|
44
|
+
|
45
|
+
post_install_message:
|
46
|
+
rdoc_options: []
|
47
|
+
|
48
|
+
require_paths:
|
49
|
+
- lib
|
50
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
51
|
+
none: false
|
52
|
+
requirements:
|
53
|
+
- - ">="
|
54
|
+
- !ruby/object:Gem::Version
|
55
|
+
hash: 3
|
56
|
+
segments:
|
57
|
+
- 0
|
58
|
+
version: "0"
|
59
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
60
|
+
none: false
|
61
|
+
requirements:
|
62
|
+
- - ">="
|
63
|
+
- !ruby/object:Gem::Version
|
64
|
+
hash: 3
|
65
|
+
segments:
|
66
|
+
- 0
|
67
|
+
version: "0"
|
68
|
+
requirements: []
|
69
|
+
|
70
|
+
rubyforge_project:
|
71
|
+
rubygems_version: 1.3.7
|
72
|
+
signing_key:
|
73
|
+
specification_version: 3
|
74
|
+
summary: "Provide extensions to Test::Unit. #before_test, #should_have_callbcks ...."
|
75
|
+
test_files:
|
76
|
+
- test/models/user.rb
|
77
|
+
- test/test_before_test.rb
|
78
|
+
- test/test_before_test_with_active_support.rb
|
79
|
+
- test/test_helper.rb
|
80
|
+
- test/test_should_have_callbacks.rb
|
81
|
+
- test/test_should_have_callbacks_with_active_support.rb
|