test-unit-context 0.3.1 → 0.4.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/Gemfile +6 -2
- data/lib/test/unit/context.rb +3 -2
- data/lib/test/unit/context/context.rb +15 -15
- data/lib/test/unit/context/version.rb +1 -1
- data/lib/test/unit/patches.rb +23 -0
- data/test/test/unit/context_test.rb +27 -27
- data/test/test/unit/patches_test.rb +80 -0
- metadata +19 -23
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 8523381664878238015d48111fef51cdbbf845a2
|
4
|
+
data.tar.gz: e71b2ab94d3ab5aeb9e8b1548d77d9e52dcbcc4b
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: d3b254701151d71463055ed77409ec212f295109586260d650060dc31db4ab0e73d3bf30891c4fa3c57e5c70e011f191c2377314179f853dfe4820cc90a7f417
|
7
|
+
data.tar.gz: 415c8f1c4792dd7c605539ac2c7730f3c4bbce78aae396f988475cc000b2b8b2409b237e4111a6d881c78c04419d9fe1d1df57f957bd40b3bb1f6407ba1423bf
|
data/Gemfile
CHANGED
data/lib/test/unit/context.rb
CHANGED
@@ -1,11 +1,12 @@
|
|
1
1
|
require 'test/unit'
|
2
|
+
require 'test/unit/patches'
|
2
3
|
require 'test/unit/context/helpers'
|
3
4
|
require 'test/unit/context/version'
|
4
5
|
|
5
6
|
module Test
|
6
7
|
module Unit
|
7
8
|
module Context
|
8
|
-
|
9
|
+
|
9
10
|
def context_name
|
10
11
|
if superclass.respond_to?(:context_name)
|
11
12
|
"#{superclass.context_name} #{@context_name}".gsub(/^\s+/, "")
|
@@ -15,7 +16,7 @@ module Test
|
|
15
16
|
end
|
16
17
|
|
17
18
|
def context_name=(name); @context_name=name; end
|
18
|
-
|
19
|
+
|
19
20
|
end
|
20
21
|
end
|
21
22
|
end
|
@@ -3,23 +3,23 @@ module Test::Unit::Context
|
|
3
3
|
|
4
4
|
PREFIX = 'Context'.freeze # :nodoc:
|
5
5
|
SUFFIX = nil # :nodoc:
|
6
|
-
|
6
|
+
|
7
7
|
# Add a context to a set of tests.
|
8
|
-
#
|
8
|
+
#
|
9
9
|
# context "A new account" do
|
10
10
|
# test "does not have users" do
|
11
11
|
# assert Account.new.users.empty?
|
12
12
|
# end
|
13
13
|
# end
|
14
|
-
#
|
14
|
+
#
|
15
15
|
# The context name is prepended to the test name, so failures look like this:
|
16
|
-
#
|
16
|
+
#
|
17
17
|
# 1) Failure:
|
18
18
|
# test_a_new_account_does_not_have_users() [./test/test_accounts.rb:4]:
|
19
19
|
# <false> is not true.
|
20
|
-
#
|
20
|
+
#
|
21
21
|
# Contexts can also be nested like so:
|
22
|
-
#
|
22
|
+
#
|
23
23
|
# context "A new account" do
|
24
24
|
# context "created from the web application" do
|
25
25
|
# test "has web as its vendor" do
|
@@ -28,9 +28,9 @@ module Test::Unit::Context
|
|
28
28
|
# end
|
29
29
|
# end
|
30
30
|
#
|
31
|
-
# Context should have unique names within a given scope, otherwise they
|
32
|
-
# end-up being merged as if it where one single context declaration.
|
33
|
-
# Anonymous (un-named) contexts are supported as well - contrary they
|
31
|
+
# Context should have unique names within a given scope, otherwise they
|
32
|
+
# end-up being merged as if it where one single context declaration.
|
33
|
+
# Anonymous (un-named) contexts are supported as well - contrary they
|
34
34
|
# never get merged (a unique name is generated for each such context).
|
35
35
|
#
|
36
36
|
def context(name = nil, &block)
|
@@ -40,12 +40,12 @@ module Test::Unit::Context
|
|
40
40
|
if const_defined?(class_name)
|
41
41
|
klass = const_get(class_name)
|
42
42
|
if ( klass.superclass == self rescue nil )
|
43
|
-
warn "duplicate context definition with the name #{name.inspect} " <<
|
44
|
-
"found at #{caller.first} it is going to be merged with " <<
|
43
|
+
warn "duplicate context definition with the name #{name.inspect} " <<
|
44
|
+
"found at #{caller.first} it is going to be merged with " <<
|
45
45
|
"the previous context definition"
|
46
46
|
else
|
47
|
-
raise "could not create a context with the name #{name.inspect} " <<
|
48
|
-
"as a constant #{class_name} is already defined and is not " <<
|
47
|
+
raise "could not create a context with the name #{name.inspect} " <<
|
48
|
+
"as a constant #{class_name} is already defined and is not " <<
|
49
49
|
"another context definition"
|
50
50
|
end
|
51
51
|
else
|
@@ -53,7 +53,7 @@ module Test::Unit::Context
|
|
53
53
|
klass.extend Test::Unit::Context
|
54
54
|
klass.context_name = name
|
55
55
|
# NOTE: make sure by default we run "inherited" setup/teardown hooks
|
56
|
-
# unless context code does re-define the hook method e.g. `def setup`
|
56
|
+
# unless context code does re-define the hook method e.g. `def setup`
|
57
57
|
# instead of using the `setup do` or the setup method marker syntax :
|
58
58
|
klass.class_eval do
|
59
59
|
def setup; super; end
|
@@ -68,7 +68,7 @@ module Test::Unit::Context
|
|
68
68
|
end
|
69
69
|
|
70
70
|
%w( contexts group ).each { |m| alias_method m, :context }
|
71
|
-
|
71
|
+
|
72
72
|
def context_definitions(nested = false)
|
73
73
|
@_context_definitions ||= []
|
74
74
|
if nested
|
@@ -0,0 +1,23 @@
|
|
1
|
+
require 'test/unit'
|
2
|
+
require 'test/unit/testsuitecreator'
|
3
|
+
|
4
|
+
module Test::Unit
|
5
|
+
TestSuiteCreator.class_eval do
|
6
|
+
|
7
|
+
private
|
8
|
+
|
9
|
+
def collect_test_names
|
10
|
+
methods = @test_case.public_instance_methods(true)
|
11
|
+
test_case_super = @test_case.superclass
|
12
|
+
while test_case_super && test_case_super != TestCase
|
13
|
+
methods -= test_case_super.public_instance_methods(true)
|
14
|
+
test_case_super = test_case_super.superclass
|
15
|
+
end
|
16
|
+
test_names = methods.map(&:to_s).find_all do |method_name|
|
17
|
+
method_name =~ /^test./ or @test_case.attributes(method_name)[:test]
|
18
|
+
end
|
19
|
+
send("sort_test_names_in_#{@test_case.test_order}_order", test_names)
|
20
|
+
end
|
21
|
+
|
22
|
+
end
|
23
|
+
end
|
@@ -2,7 +2,7 @@ require File.expand_path('../../test_helper', File.dirname(__FILE__))
|
|
2
2
|
|
3
3
|
module Test::Unit
|
4
4
|
class TestContext < Test::Unit::TestCase
|
5
|
-
|
5
|
+
|
6
6
|
def test_test_without_context
|
7
7
|
assert true
|
8
8
|
end
|
@@ -10,7 +10,7 @@ module Test::Unit
|
|
10
10
|
test "another test without a context" do
|
11
11
|
assert true
|
12
12
|
end
|
13
|
-
|
13
|
+
|
14
14
|
def test_context_aliases
|
15
15
|
assert self.class.respond_to? :context
|
16
16
|
assert self.class.respond_to? :contexts
|
@@ -23,9 +23,9 @@ module Test::Unit
|
|
23
23
|
context("an '&\" name !?") {}
|
24
24
|
end
|
25
25
|
end
|
26
|
-
|
26
|
+
|
27
27
|
class Default < Test::Unit::TestCase
|
28
|
-
|
28
|
+
@_context_ = context "When testing" do
|
29
29
|
def test_this_thing
|
30
30
|
true
|
31
31
|
end
|
@@ -36,9 +36,9 @@ module Test::Unit
|
|
36
36
|
end
|
37
37
|
|
38
38
|
setup do
|
39
|
-
@default_context = Default
|
39
|
+
@default_context = Default.instance_variable_get :@_context_
|
40
40
|
end
|
41
|
-
|
41
|
+
|
42
42
|
test "[default context] sets the context name" do
|
43
43
|
assert_equal "When testing", @default_context.context_name
|
44
44
|
end
|
@@ -50,20 +50,20 @@ module Test::Unit
|
|
50
50
|
test "[default context] is defived from the test class" do
|
51
51
|
assert_equal Default, @default_context.superclass
|
52
52
|
end
|
53
|
-
|
53
|
+
|
54
54
|
test "[default context] reports among test case's context defs" do
|
55
55
|
assert Default.respond_to?(:context_definitions)
|
56
56
|
assert_include Default.context_definitions, @default_context
|
57
57
|
assert_equal 2, Default.context_definitions.size
|
58
58
|
end
|
59
|
-
|
59
|
+
|
60
60
|
test "has a (context name derived) class name" do
|
61
61
|
namespace = 'Test::Unit::TestContext::Default::'
|
62
62
|
assert_equal "#{namespace}ContextWhenTesting", @default_context.name
|
63
63
|
end
|
64
64
|
|
65
65
|
class Anonymous < Test::Unit::TestCase
|
66
|
-
|
66
|
+
@@_context_ = self.context do
|
67
67
|
def test_some_thing
|
68
68
|
true
|
69
69
|
end
|
@@ -76,34 +76,34 @@ module Test::Unit
|
|
76
76
|
#
|
77
77
|
end
|
78
78
|
end
|
79
|
-
|
79
|
+
|
80
80
|
setup do
|
81
|
-
@anonymous_context = Anonymous
|
81
|
+
@anonymous_context = Anonymous.send :class_variable_get, :@@_context_
|
82
82
|
end
|
83
83
|
|
84
84
|
test "[anonymous context] has a generated context name" do
|
85
85
|
assert_not_nil @anonymous_context.name
|
86
86
|
end
|
87
|
-
|
87
|
+
|
88
88
|
test "[anonymous context] is defived from the test class" do
|
89
89
|
assert_equal Anonymous, @anonymous_context.superclass
|
90
90
|
end
|
91
|
-
|
91
|
+
|
92
92
|
test "[anonymous context] reports among test case's context defs" do
|
93
93
|
assert Anonymous.respond_to?(:context_definitions)
|
94
94
|
assert_include Anonymous.context_definitions, @anonymous_context
|
95
95
|
assert_equal 3, Anonymous.context_definitions.size
|
96
96
|
assert_equal 3, Anonymous.context_definitions(true).size
|
97
97
|
end
|
98
|
-
|
98
|
+
|
99
99
|
test "[anonymous context] has a (context name derived) class name" do
|
100
100
|
namespace = 'Test::Unit::TestContext::Anonymous::'
|
101
101
|
context_name = @anonymous_context.context_name
|
102
102
|
assert_equal "#{namespace}Context#{context_name}", @anonymous_context.name
|
103
103
|
end
|
104
|
-
|
104
|
+
|
105
105
|
class Nested < Test::Unit::TestCase
|
106
|
-
|
106
|
+
@@_context_ = context "and we're testing" do
|
107
107
|
@nested = context "should be nested" do
|
108
108
|
def test_a_thing
|
109
109
|
true
|
@@ -114,10 +114,10 @@ module Test::Unit
|
|
114
114
|
end
|
115
115
|
|
116
116
|
setup do
|
117
|
-
@parent_context = Nested
|
118
|
-
@nested_context =
|
117
|
+
@parent_context = Nested.send :class_variable_get, :@@_context_
|
118
|
+
@nested_context = @parent_context.nested
|
119
119
|
end
|
120
|
-
|
120
|
+
|
121
121
|
test "[nested context] sets a nested context name" do
|
122
122
|
assert_equal "and we're testing should be nested", @nested_context.context_name
|
123
123
|
end
|
@@ -129,7 +129,7 @@ module Test::Unit
|
|
129
129
|
test "[nested context] is defived from the prev context class" do
|
130
130
|
assert_equal @parent_context, @nested_context.superclass
|
131
131
|
end
|
132
|
-
|
132
|
+
|
133
133
|
test "[nested context] reports context defs correctly" do
|
134
134
|
assert Nested.respond_to?(:context_definitions)
|
135
135
|
assert_equal 1, Nested.context_definitions.size
|
@@ -137,13 +137,13 @@ module Test::Unit
|
|
137
137
|
assert_equal 0, @nested_context.context_definitions.size
|
138
138
|
assert_equal 2, Nested.context_definitions(true).size
|
139
139
|
end
|
140
|
-
|
140
|
+
|
141
141
|
test "[nested context] has a (context name derived) class name" do
|
142
142
|
namespace = 'Test::Unit::TestContext::Nested::'
|
143
|
-
assert_equal "#{namespace}ContextAndWeReTesting::ContextShouldBeNested",
|
143
|
+
assert_equal "#{namespace}ContextAndWeReTesting::ContextShouldBeNested",
|
144
144
|
@nested_context.name
|
145
145
|
end
|
146
|
-
|
146
|
+
|
147
147
|
class Redefined < Test::Unit::TestCase
|
148
148
|
CONTEXT = context 42 do
|
149
149
|
def test_everything
|
@@ -161,7 +161,7 @@ module Test::Unit
|
|
161
161
|
setup do
|
162
162
|
@redefined_context = Redefined::CONTEXT
|
163
163
|
end
|
164
|
-
|
164
|
+
|
165
165
|
test "[redefined context] sets the context name" do
|
166
166
|
assert_equal 42, @redefined_context.context_name
|
167
167
|
end
|
@@ -177,9 +177,9 @@ module Test::Unit
|
|
177
177
|
end
|
178
178
|
assert_not_nil Redefined.warns
|
179
179
|
assert_equal 2, @redefined_context.instance_methods(false).grep(/test/).size
|
180
|
-
|
180
|
+
|
181
181
|
Redefined.reset_warns
|
182
|
-
|
182
|
+
|
183
183
|
assert_nil Redefined.warns
|
184
184
|
class Redefined
|
185
185
|
context '42' do # same class-name
|
@@ -190,6 +190,6 @@ module Test::Unit
|
|
190
190
|
assert_not_nil Redefined.warns
|
191
191
|
assert_equal 3, @redefined_context.instance_methods(false).grep(/test/).size
|
192
192
|
end
|
193
|
-
|
193
|
+
|
194
194
|
end
|
195
195
|
end
|
@@ -0,0 +1,80 @@
|
|
1
|
+
require File.expand_path('../../test_helper', File.dirname(__FILE__))
|
2
|
+
|
3
|
+
class PatchesTest < Test::Unit::TestCase
|
4
|
+
|
5
|
+
self.test_order = :alphabetic
|
6
|
+
|
7
|
+
@@tests_run = []
|
8
|
+
|
9
|
+
def self.add_test(test)
|
10
|
+
@@tests_run << test
|
11
|
+
end
|
12
|
+
|
13
|
+
module TestMethods
|
14
|
+
|
15
|
+
def test_1
|
16
|
+
PatchesTest.add_test :test_1
|
17
|
+
end
|
18
|
+
|
19
|
+
end
|
20
|
+
|
21
|
+
include TestMethods
|
22
|
+
|
23
|
+
def test_2
|
24
|
+
PatchesTest.add_test :test_2
|
25
|
+
end
|
26
|
+
|
27
|
+
context do
|
28
|
+
|
29
|
+
def test_3
|
30
|
+
PatchesTest.add_test :test_3
|
31
|
+
end
|
32
|
+
|
33
|
+
end
|
34
|
+
|
35
|
+
context 'empty' do
|
36
|
+
|
37
|
+
end
|
38
|
+
|
39
|
+
extend Test::Unit::Assertions
|
40
|
+
|
41
|
+
def self.shutdown
|
42
|
+
assert_equal [:test_1, :test_2, :test_3], @@tests_run
|
43
|
+
end
|
44
|
+
|
45
|
+
end
|
46
|
+
|
47
|
+
#module TestMethods
|
48
|
+
#
|
49
|
+
# def test_0
|
50
|
+
# puts 0
|
51
|
+
# end
|
52
|
+
#
|
53
|
+
#end
|
54
|
+
#
|
55
|
+
#class Test1 < Test::Unit::TestCase
|
56
|
+
# include TestMethods
|
57
|
+
#
|
58
|
+
# def test_1
|
59
|
+
# puts 1
|
60
|
+
# end
|
61
|
+
#
|
62
|
+
# test
|
63
|
+
# def a_test_1x
|
64
|
+
# puts '1x'
|
65
|
+
# end
|
66
|
+
#
|
67
|
+
#end
|
68
|
+
#
|
69
|
+
#class Test2 < Test1
|
70
|
+
#
|
71
|
+
# def test_2
|
72
|
+
# puts 2
|
73
|
+
# end
|
74
|
+
#
|
75
|
+
# test
|
76
|
+
# def a_test_2x
|
77
|
+
# puts '2x'
|
78
|
+
# end
|
79
|
+
#
|
80
|
+
#end
|
metadata
CHANGED
@@ -1,52 +1,47 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: test-unit-context
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
5
|
-
prerelease:
|
4
|
+
version: 0.4.0
|
6
5
|
platform: ruby
|
7
6
|
authors:
|
8
7
|
- kares
|
9
8
|
autorequire:
|
10
9
|
bindir: bin
|
11
10
|
cert_chain: []
|
12
|
-
date:
|
11
|
+
date: 2014-01-22 00:00:00.000000000 Z
|
13
12
|
dependencies:
|
14
13
|
- !ruby/object:Gem::Dependency
|
15
14
|
name: test-unit
|
16
15
|
requirement: !ruby/object:Gem::Requirement
|
17
|
-
none: false
|
18
16
|
requirements:
|
19
|
-
- -
|
17
|
+
- - ">="
|
20
18
|
- !ruby/object:Gem::Version
|
21
19
|
version: 2.4.0
|
22
20
|
type: :runtime
|
23
21
|
prerelease: false
|
24
22
|
version_requirements: !ruby/object:Gem::Requirement
|
25
|
-
none: false
|
26
23
|
requirements:
|
27
|
-
- -
|
24
|
+
- - ">="
|
28
25
|
- !ruby/object:Gem::Version
|
29
26
|
version: 2.4.0
|
30
27
|
- !ruby/object:Gem::Dependency
|
31
28
|
name: rake
|
32
29
|
requirement: !ruby/object:Gem::Requirement
|
33
|
-
none: false
|
34
30
|
requirements:
|
35
|
-
- -
|
31
|
+
- - ">="
|
36
32
|
- !ruby/object:Gem::Version
|
37
33
|
version: '0'
|
38
34
|
type: :development
|
39
35
|
prerelease: false
|
40
36
|
version_requirements: !ruby/object:Gem::Requirement
|
41
|
-
none: false
|
42
37
|
requirements:
|
43
|
-
- -
|
38
|
+
- - ">="
|
44
39
|
- !ruby/object:Gem::Version
|
45
40
|
version: '0'
|
46
|
-
description:
|
47
|
-
|
48
|
-
|
49
|
-
|
41
|
+
description: "Makes Test::Unit::TestCases 'contextable' and thus much\neasier to read
|
42
|
+
and write. If you've seen RSpec than it's the very same 'context \ndo ... end' re-invendet
|
43
|
+
for Test::Unit. Inspired by gem 'context' that does the\nsame for the 'old' Test::Unit
|
44
|
+
1.2.3 bundled with Ruby 1.8.x standard libraries."
|
50
45
|
email:
|
51
46
|
- self@kares.org
|
52
47
|
executables: []
|
@@ -55,8 +50,8 @@ extra_rdoc_files:
|
|
55
50
|
- README.md
|
56
51
|
- LICENSE
|
57
52
|
files:
|
58
|
-
- .gitignore
|
59
|
-
- .travis.yml
|
53
|
+
- ".gitignore"
|
54
|
+
- ".travis.yml"
|
60
55
|
- Gemfile
|
61
56
|
- LICENSE
|
62
57
|
- README.md
|
@@ -67,35 +62,36 @@ files:
|
|
67
62
|
- lib/test/unit/context/shared.rb
|
68
63
|
- lib/test/unit/context/spec.rb
|
69
64
|
- lib/test/unit/context/version.rb
|
65
|
+
- lib/test/unit/patches.rb
|
70
66
|
- test-unit-context.gemspec
|
71
67
|
- test/test/unit/context/hooks_test.rb
|
72
68
|
- test/test/unit/context/shared_test.rb
|
73
69
|
- test/test/unit/context/spec_spec.rb
|
74
70
|
- test/test/unit/context/spec_test.rb
|
75
71
|
- test/test/unit/context_test.rb
|
72
|
+
- test/test/unit/patches_test.rb
|
76
73
|
- test/test_helper.rb
|
77
74
|
homepage: http://github.com/kares/test-unit-context
|
78
75
|
licenses: []
|
76
|
+
metadata: {}
|
79
77
|
post_install_message:
|
80
78
|
rdoc_options: []
|
81
79
|
require_paths:
|
82
80
|
- lib
|
83
81
|
required_ruby_version: !ruby/object:Gem::Requirement
|
84
|
-
none: false
|
85
82
|
requirements:
|
86
|
-
- -
|
83
|
+
- - ">="
|
87
84
|
- !ruby/object:Gem::Version
|
88
85
|
version: '0'
|
89
86
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
90
|
-
none: false
|
91
87
|
requirements:
|
92
|
-
- -
|
88
|
+
- - ">="
|
93
89
|
- !ruby/object:Gem::Version
|
94
90
|
version: '0'
|
95
91
|
requirements: []
|
96
92
|
rubyforge_project:
|
97
|
-
rubygems_version:
|
93
|
+
rubygems_version: 2.2.1
|
98
94
|
signing_key:
|
99
|
-
specification_version:
|
95
|
+
specification_version: 4
|
100
96
|
summary: Context for Test::Unit (2.x)
|
101
97
|
test_files: []
|