jeremymcanally-context 0.0.5 → 0.0.6
Sign up to get free protection for your applications and to get access to all the features.
- data/context.gemspec +1 -1
- data/lib/context/context.rb +1 -2
- data/lib/context/lifecycle.rb +5 -5
- data/lib/context/shared_behavior.rb +62 -17
- data/lib/context/suite.rb +1 -1
- data/lib/context/version.rb +1 -1
- metadata +1 -1
data/context.gemspec
CHANGED
data/lib/context/context.rb
CHANGED
@@ -50,8 +50,7 @@ class Test::Unit::TestCase
|
|
50
50
|
cls.class_eval(&block)
|
51
51
|
(self.context_list ||= []) << cls
|
52
52
|
|
53
|
-
#
|
54
|
-
const_set("Test#{name.to_class_name}#{cls.object_id}", cls)
|
53
|
+
const_set("Test#{name.to_class_name}#{cls.object_id.abs}", cls)
|
55
54
|
cls
|
56
55
|
end
|
57
56
|
|
data/lib/context/lifecycle.rb
CHANGED
@@ -22,7 +22,7 @@ class Test::Unit::TestCase
|
|
22
22
|
send("after_#{period}_callbacks") << block
|
23
23
|
end
|
24
24
|
|
25
|
-
def gather_callbacks(callback_type, period)
|
25
|
+
def gather_callbacks(callback_type, period) # :nodoc:
|
26
26
|
callbacks = superclass.respond_to?(:gather_callbacks) ? superclass.gather_callbacks(callback_type, period) : []
|
27
27
|
callbacks.push(*send("#{callback_type}_#{period}_callbacks"))
|
28
28
|
end
|
@@ -33,7 +33,7 @@ class Test::Unit::TestCase
|
|
33
33
|
self.after_each_callbacks = []
|
34
34
|
self.after_all_callbacks = []
|
35
35
|
|
36
|
-
def self.inherited(child)
|
36
|
+
def self.inherited(child) # :nodoc:
|
37
37
|
super
|
38
38
|
child.before_all_callbacks = []
|
39
39
|
child.before_each_callbacks = []
|
@@ -51,11 +51,11 @@ class Test::Unit::TestCase
|
|
51
51
|
end
|
52
52
|
end
|
53
53
|
|
54
|
-
def run_each_callbacks(callback_type)
|
54
|
+
def run_each_callbacks(callback_type) # :nodoc:
|
55
55
|
self.class.gather_callbacks(callback_type, :each).each { |c| instance_eval(&c) }
|
56
56
|
end
|
57
57
|
|
58
|
-
def run_all_callbacks(callback_type)
|
58
|
+
def run_all_callbacks(callback_type) # :nodoc:
|
59
59
|
previous_ivars = instance_variables
|
60
60
|
self.class.gather_callbacks(callback_type, :all).each { |c| instance_eval(&c) }
|
61
61
|
(instance_variables - previous_ivars).inject({}) do |hash, ivar|
|
@@ -63,7 +63,7 @@ class Test::Unit::TestCase
|
|
63
63
|
end
|
64
64
|
end
|
65
65
|
|
66
|
-
def set_values_from_callbacks(values)
|
66
|
+
def set_values_from_callbacks(values) # :nodoc:
|
67
67
|
values.each do |name, value|
|
68
68
|
instance_variable_set name, value
|
69
69
|
end
|
@@ -1,25 +1,51 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
@behavior = beh
|
10
|
-
end
|
1
|
+
module Context
|
2
|
+
class SharedBehavior < Module
|
3
|
+
def self.create_from_behavior(beh) # :nodoc:
|
4
|
+
mod = self.new
|
5
|
+
mod._behavior = beh
|
6
|
+
|
7
|
+
mod
|
8
|
+
end
|
11
9
|
|
12
|
-
|
13
|
-
|
14
|
-
|
10
|
+
def _behavior=(beh) # :nodoc:
|
11
|
+
@_behavior = beh
|
12
|
+
end
|
15
13
|
|
16
|
-
|
17
|
-
|
14
|
+
def included(arg) # :nodoc:
|
15
|
+
@_behavior.call
|
16
|
+
end
|
18
17
|
end
|
19
18
|
end
|
20
19
|
|
21
20
|
class Test::Unit::TestCase
|
22
21
|
class << self
|
22
|
+
# Share behavior among different contexts. This creates a module (actually, a Module subclass)
|
23
|
+
# that is included using the +use+ method (or one of its aliases) provided by context or +include+
|
24
|
+
# if you know the module's constant name.
|
25
|
+
#
|
26
|
+
# ==== Examples
|
27
|
+
#
|
28
|
+
# shared "other things" do
|
29
|
+
# it "should do things but not some things" do
|
30
|
+
# # behavior is fun
|
31
|
+
# end
|
32
|
+
# end
|
33
|
+
#
|
34
|
+
# use "other things"
|
35
|
+
# # or...
|
36
|
+
# it_should_behave_like "other things"
|
37
|
+
#
|
38
|
+
# shared :client do
|
39
|
+
# it "should be a client to our server" do
|
40
|
+
# # TODO: client behavior here
|
41
|
+
# end
|
42
|
+
# end
|
43
|
+
#
|
44
|
+
# use :client
|
45
|
+
# # or...
|
46
|
+
# uses "client"
|
47
|
+
# behaves_like "client"
|
48
|
+
#
|
23
49
|
def shared(name, &block)
|
24
50
|
case name.class.name
|
25
51
|
when "String"
|
@@ -30,14 +56,33 @@ class Test::Unit::TestCase
|
|
30
56
|
raise ArgumentError, "Provide a String or Symbol as the name of the shared behavior group"
|
31
57
|
end
|
32
58
|
|
33
|
-
Object.const_set(name,
|
59
|
+
Object.const_set(name, Context::SharedBehavior.create_from_behavior(block))
|
34
60
|
end
|
35
61
|
|
36
62
|
%w(shared_behavior share_as share_behavior_as shared_examples_for).each {|m| alias_method m, :shared}
|
37
63
|
|
64
|
+
# Pull in behavior shared by +shared+ or a module.
|
65
|
+
#
|
66
|
+
# ==== Examples
|
67
|
+
#
|
68
|
+
# shared "other things" do
|
69
|
+
# it "should do things but not some things" do
|
70
|
+
# # behavior is fun
|
71
|
+
# end
|
72
|
+
# end
|
73
|
+
#
|
74
|
+
# use "other things"
|
75
|
+
# # or...
|
76
|
+
# it_should_behave_like "other things"
|
77
|
+
#
|
78
|
+
# module Things
|
79
|
+
# end
|
80
|
+
#
|
81
|
+
# uses Things
|
82
|
+
#
|
38
83
|
def use(shared_name)
|
39
84
|
case shared_name.class.name
|
40
|
-
when "
|
85
|
+
when "Context::SharedBehavior", "Module"
|
41
86
|
include shared_name
|
42
87
|
when "String"
|
43
88
|
include Object.const_get(shared_name.to_module_name)
|
data/lib/context/suite.rb
CHANGED
@@ -24,7 +24,7 @@ module Test
|
|
24
24
|
class TestSuite
|
25
25
|
# Runs the tests and/or suites contained in this
|
26
26
|
# TestSuite.
|
27
|
-
def run(result, &progress_block)
|
27
|
+
def run(result, &progress_block) # :nodoc:
|
28
28
|
yield(STARTED, name)
|
29
29
|
ivars_from_callback = @tests.first.run_all_callbacks(:before) if @tests.first.is_a?(Test::Unit::TestCase)
|
30
30
|
@tests.each do |test|
|
data/lib/context/version.rb
CHANGED