be9-context 0.5.5
Sign up to get free protection for your applications and to get access to all the features.
- data/History.txt +10 -0
- data/License.txt +20 -0
- data/Manifest.txt +26 -0
- data/PostInstall.txt +0 -0
- data/README.rdoc +158 -0
- data/Rakefile +4 -0
- data/config/hoe.rb +73 -0
- data/config/requirements.rb +15 -0
- data/context.gemspec +44 -0
- data/lib/context.rb +6 -0
- data/lib/context/core.rb +102 -0
- data/lib/context/core_ext/rails_hacks.rb +8 -0
- data/lib/context/core_ext/string.rb +29 -0
- data/lib/context/lifecycle.rb +115 -0
- data/lib/context/shared_behavior.rb +96 -0
- data/lib/context/suite.rb +35 -0
- data/lib/context/test.rb +34 -0
- data/lib/context/version.rb +9 -0
- data/setup.rb +1585 -0
- data/test/test_context.rb +62 -0
- data/test/test_core_ext.rb +25 -0
- data/test/test_helper.rb +2 -0
- data/test/test_lifecycle.rb +224 -0
- data/test/test_test.rb +23 -0
- metadata +97 -0
@@ -0,0 +1,62 @@
|
|
1
|
+
require File.dirname(__FILE__) + '/test_helper.rb'
|
2
|
+
|
3
|
+
class CustomTest < Test::Unit::TestCase
|
4
|
+
def setup
|
5
|
+
end
|
6
|
+
end
|
7
|
+
|
8
|
+
class TestContext < CustomTest
|
9
|
+
def test_can_write_tests_without_context
|
10
|
+
assert true
|
11
|
+
end
|
12
|
+
|
13
|
+
def test_context_aliases
|
14
|
+
[:context, :contexts, :describe, :describes, :group, :specify, :specifies].each do |method_alias|
|
15
|
+
assert self.class.respond_to?(method_alias)
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
context "A new context" do
|
20
|
+
context "when not nested" do
|
21
|
+
before do
|
22
|
+
@context = Class.new(Test::Unit::TestCase).context("When testing") do
|
23
|
+
def test_this_thing
|
24
|
+
true
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
it "should set the context name" do
|
30
|
+
assert_equal "When testing", @context.context_name
|
31
|
+
end
|
32
|
+
|
33
|
+
it "should be a Test::Unit::TestCase" do
|
34
|
+
assert @context.ancestors.include?(Test::Unit::TestCase)
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
38
|
+
context "when nested" do
|
39
|
+
before do
|
40
|
+
@context = self.class.context("and we're testing") do
|
41
|
+
def self.nested
|
42
|
+
@nested
|
43
|
+
end
|
44
|
+
|
45
|
+
@nested = context "should be nested" do
|
46
|
+
def test_this_thing
|
47
|
+
true
|
48
|
+
end
|
49
|
+
end
|
50
|
+
end
|
51
|
+
end
|
52
|
+
|
53
|
+
it "should set a nested context's name" do
|
54
|
+
assert_equal "A new context when nested and we're testing should be nested", @context.nested.context_name
|
55
|
+
end
|
56
|
+
|
57
|
+
it "should also be a Test::Unit::TestCase" do
|
58
|
+
assert @context.nested.ancestors.include?(Test::Unit::TestCase)
|
59
|
+
end
|
60
|
+
end
|
61
|
+
end
|
62
|
+
end
|
@@ -0,0 +1,25 @@
|
|
1
|
+
require File.dirname(__FILE__) + '/test_helper.rb'
|
2
|
+
|
3
|
+
class TestCoreExt < Test::Unit::TestCase
|
4
|
+
context "A string" do
|
5
|
+
it "should be converted to method name" do
|
6
|
+
assert_equal 'this_is_fun', "this is fun".to_method_name
|
7
|
+
end
|
8
|
+
|
9
|
+
it "should be converted to class name" do
|
10
|
+
assert_equal 'ThisIsFunYes_', "this is fun... - (yes)??!".to_class_name
|
11
|
+
end
|
12
|
+
|
13
|
+
it "should be downcased when converted" do
|
14
|
+
assert_equal 'this_is_a_blast', "THIS is A BlASt".to_method_name
|
15
|
+
end
|
16
|
+
|
17
|
+
it "should change spaces to _" do
|
18
|
+
assert_equal 'this_has_been_great', "This has been great".to_method_name
|
19
|
+
end
|
20
|
+
|
21
|
+
it "should change dangerous punctuation to _" do
|
22
|
+
assert_equal 'no_really_this_was_good_', "No, really; this was #good!".to_method_name
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
data/test/test_helper.rb
ADDED
@@ -0,0 +1,224 @@
|
|
1
|
+
require File.dirname(__FILE__) + '/test_helper.rb'
|
2
|
+
|
3
|
+
class TestLifecycle < Test::Unit::TestCase
|
4
|
+
before do
|
5
|
+
@inherited_before_each_var ||= 0
|
6
|
+
@inherited_before_each_var += 1
|
7
|
+
end
|
8
|
+
|
9
|
+
before do
|
10
|
+
@inherited_before_each_var ||= 0
|
11
|
+
@inherited_before_each_var_2 ||= 0
|
12
|
+
@inherited_before_each_var += 2
|
13
|
+
@inherited_before_each_var_2 += 1
|
14
|
+
end
|
15
|
+
|
16
|
+
after do
|
17
|
+
@inherited_after_each_var ||= 0
|
18
|
+
@inherited_after_each_var += 1
|
19
|
+
end
|
20
|
+
|
21
|
+
before :all do
|
22
|
+
@inherited_before_all_var ||= 0
|
23
|
+
@inherited_before_all_var += 1
|
24
|
+
end
|
25
|
+
|
26
|
+
after :all do
|
27
|
+
@inherited_after_all_var ||= 0
|
28
|
+
@inherited_after_all_var += 1
|
29
|
+
end
|
30
|
+
|
31
|
+
sample_test = context "lifecycle" do
|
32
|
+
attr_reader :inherited_before_each_var, :inherited_before_each_var_2, :inherited_after_each_var,
|
33
|
+
:after_each_var, :inherited_before_all_var, :inherited_after_all_var, :before_all_var, :after_all_var, :ivar,
|
34
|
+
:superclass_before_each_var, :superclass_after_each_var, :superclass_before_all_var, :superclass_after_all_var, :one, :two
|
35
|
+
|
36
|
+
before do
|
37
|
+
@inherited_before_each_var ||= 0
|
38
|
+
@inherited_before_each_var += 4
|
39
|
+
end
|
40
|
+
|
41
|
+
after do
|
42
|
+
@after_each_var ||= 0
|
43
|
+
@after_each_var += 1
|
44
|
+
end
|
45
|
+
|
46
|
+
before :all do
|
47
|
+
@before_all_var ||= 0
|
48
|
+
@before_all_var += 1
|
49
|
+
end
|
50
|
+
|
51
|
+
after :all do
|
52
|
+
@after_all_var ||= 0
|
53
|
+
@after_all_var += 1
|
54
|
+
end
|
55
|
+
|
56
|
+
after :a_method
|
57
|
+
|
58
|
+
test "foo" do
|
59
|
+
end
|
60
|
+
end
|
61
|
+
|
62
|
+
before do
|
63
|
+
@superclass_before_each_var ||= 0
|
64
|
+
@superclass_before_each_var += 1
|
65
|
+
end
|
66
|
+
|
67
|
+
after do
|
68
|
+
@superclass_after_each_var ||= 0
|
69
|
+
@superclass_after_each_var += 1
|
70
|
+
end
|
71
|
+
|
72
|
+
before :all do
|
73
|
+
@superclass_before_all_var ||= 0
|
74
|
+
@superclass_before_all_var += 1
|
75
|
+
end
|
76
|
+
|
77
|
+
after :all do
|
78
|
+
@superclass_after_all_var ||= 0
|
79
|
+
@superclass_after_all_var += 1
|
80
|
+
end
|
81
|
+
|
82
|
+
context "With before/after :each blocks" do
|
83
|
+
before do
|
84
|
+
@result = Test::Unit::TestResult.new
|
85
|
+
@test = sample_test.new("test: lifecycle foo")
|
86
|
+
@test.run(@result) { |inherited_after_each_var, v| }
|
87
|
+
end
|
88
|
+
|
89
|
+
it "it runs superclass before callbacks in order" do
|
90
|
+
assert_equal 1, @test.superclass_before_each_var
|
91
|
+
end
|
92
|
+
|
93
|
+
it "it runs inherited before callbacks in order" do
|
94
|
+
assert_equal 7, @test.inherited_before_each_var
|
95
|
+
end
|
96
|
+
|
97
|
+
it "it runs before callbacks in order" do
|
98
|
+
assert_equal 1, @test.inherited_before_each_var_2
|
99
|
+
end
|
100
|
+
|
101
|
+
it "it runs superclass after callbacks" do
|
102
|
+
assert_equal 1, @test.superclass_after_each_var
|
103
|
+
end
|
104
|
+
|
105
|
+
it "it runs inherited after callbacks" do
|
106
|
+
assert_equal 1, @test.inherited_after_each_var
|
107
|
+
end
|
108
|
+
|
109
|
+
it "it runs after callbacks" do
|
110
|
+
assert_equal 1, @test.after_each_var
|
111
|
+
end
|
112
|
+
|
113
|
+
it "it runs after callbacks specified with method names, instead of blocks" do
|
114
|
+
assert_equal "a method ran", @test.ivar
|
115
|
+
end
|
116
|
+
end
|
117
|
+
|
118
|
+
context "With before/after :all blocks" do
|
119
|
+
before do
|
120
|
+
@result = Test::Unit::TestResult.new
|
121
|
+
@suite = sample_test.suite
|
122
|
+
@suite.run(@result) { |inherited_after_each_var, v| }
|
123
|
+
@test = @suite.tests.first
|
124
|
+
end
|
125
|
+
|
126
|
+
it "it runs superclass before callbacks in order" do
|
127
|
+
assert_equal 1, @test.superclass_before_all_var
|
128
|
+
end
|
129
|
+
|
130
|
+
it "it runs inherited before callbacks in order" do
|
131
|
+
assert_equal 1, @test.inherited_before_all_var
|
132
|
+
end
|
133
|
+
|
134
|
+
it "it runs before callbacks in order" do
|
135
|
+
assert_equal 1, @test.before_all_var
|
136
|
+
end
|
137
|
+
|
138
|
+
it "it runs superclass after callbacks" do
|
139
|
+
assert_equal 1, @test.superclass_after_all_var
|
140
|
+
end
|
141
|
+
|
142
|
+
it "it runs inherited after callbacks" do
|
143
|
+
assert_equal 1, @test.inherited_after_all_var
|
144
|
+
end
|
145
|
+
|
146
|
+
it "it runs after callbacks" do
|
147
|
+
assert_equal 1, @test.after_all_var
|
148
|
+
end
|
149
|
+
end
|
150
|
+
|
151
|
+
# Test that we aren't stomping on defined seutp method
|
152
|
+
context "With setup/teardown methods" do
|
153
|
+
before do
|
154
|
+
@result = Test::Unit::TestResult.new
|
155
|
+
@test = sample_test.new("test: lifecycle foo")
|
156
|
+
|
157
|
+
@test.class.setup do
|
158
|
+
@one = 1
|
159
|
+
end
|
160
|
+
|
161
|
+
@test.class.teardown do
|
162
|
+
@two = 10
|
163
|
+
end
|
164
|
+
|
165
|
+
@test.run(@result) { |inherited_after_each_var, v| }
|
166
|
+
end
|
167
|
+
|
168
|
+
it "runs setup method block a la Shoulda" do
|
169
|
+
assert_equal 1, @test.one
|
170
|
+
end
|
171
|
+
|
172
|
+
it "runs setup method block and regular callbacks" do
|
173
|
+
assert_equal 7, @test.inherited_before_each_var
|
174
|
+
end
|
175
|
+
|
176
|
+
it "runs teardown method block a la Shoulda" do
|
177
|
+
assert_equal 10, @test.two
|
178
|
+
end
|
179
|
+
|
180
|
+
it "runs teardown method block and regular callbacks" do
|
181
|
+
assert_equal 1, @test.after_each_var
|
182
|
+
end
|
183
|
+
end
|
184
|
+
|
185
|
+
context "With the before option" do
|
186
|
+
setup do
|
187
|
+
@jvar = "override success!"
|
188
|
+
end
|
189
|
+
|
190
|
+
l = lambda { @ivar = "awesome" }
|
191
|
+
should "run the lambda", :before => l do
|
192
|
+
assert_equal "awesome", @ivar
|
193
|
+
end
|
194
|
+
|
195
|
+
l = lambda { @jvar = "should be overridden" }
|
196
|
+
should "run the lambda before the setup", :before => l do
|
197
|
+
assert_equal "override success!", @jvar
|
198
|
+
end
|
199
|
+
end
|
200
|
+
|
201
|
+
context "Before tests" do
|
202
|
+
# omg this is odd
|
203
|
+
setup do
|
204
|
+
assert_equal "yup, it's set", @ivar
|
205
|
+
end
|
206
|
+
|
207
|
+
before_test "run before the setup block" do
|
208
|
+
@ivar = "yup, it's set"
|
209
|
+
end
|
210
|
+
end
|
211
|
+
|
212
|
+
context "To be compatible with rails' expectations" do
|
213
|
+
setup :a_method
|
214
|
+
|
215
|
+
it "should accept a symbol for an argument to setup and run that method at setup time" do
|
216
|
+
assert_equal "a method ran", @ivar
|
217
|
+
end
|
218
|
+
end
|
219
|
+
|
220
|
+
protected
|
221
|
+
def a_method
|
222
|
+
@ivar = "a method ran"
|
223
|
+
end
|
224
|
+
end
|
data/test/test_test.rb
ADDED
@@ -0,0 +1,23 @@
|
|
1
|
+
require File.dirname(__FILE__) + '/test_helper.rb'
|
2
|
+
|
3
|
+
class TestTest < Test::Unit::TestCase
|
4
|
+
def test_test_aliases
|
5
|
+
[:test, :it, :should, :tests].each do |method_alias|
|
6
|
+
assert self.class.respond_to?(method_alias)
|
7
|
+
end
|
8
|
+
end
|
9
|
+
|
10
|
+
def test_before_test_aliases
|
11
|
+
[:before_test, :before_it, :before_should, :before_tests].each do |method_alias|
|
12
|
+
assert self.class.respond_to?(method_alias), method_alias.inspect
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
context "A test block" do
|
17
|
+
it "should create a test_xxx method" do
|
18
|
+
self.class.test("should create a test method") { true }
|
19
|
+
|
20
|
+
assert self.respond_to?("test: A test block should create a test method")
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
metadata
ADDED
@@ -0,0 +1,97 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: be9-context
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
hash: 1
|
5
|
+
prerelease: false
|
6
|
+
segments:
|
7
|
+
- 0
|
8
|
+
- 5
|
9
|
+
- 5
|
10
|
+
version: 0.5.5
|
11
|
+
platform: ruby
|
12
|
+
authors:
|
13
|
+
- Jeremy McAnally
|
14
|
+
autorequire:
|
15
|
+
bindir: bin
|
16
|
+
cert_chain: []
|
17
|
+
|
18
|
+
date: 2010-11-02 00:00:00 +06:00
|
19
|
+
default_executable:
|
20
|
+
dependencies: []
|
21
|
+
|
22
|
+
description: If you've ever wanted contexts in your Test::Unit tests, then context is for you. Your tests will be easier to read and write without all the magic and extra code smell!
|
23
|
+
email: jeremy@entp.com
|
24
|
+
executables: []
|
25
|
+
|
26
|
+
extensions: []
|
27
|
+
|
28
|
+
extra_rdoc_files:
|
29
|
+
- History.txt
|
30
|
+
- Manifest.txt
|
31
|
+
- README.rdoc
|
32
|
+
files:
|
33
|
+
- README.rdoc
|
34
|
+
- Rakefile
|
35
|
+
- context.gemspec
|
36
|
+
- History.txt
|
37
|
+
- License.txt
|
38
|
+
- Manifest.txt
|
39
|
+
- PostInstall.txt
|
40
|
+
- config/hoe.rb
|
41
|
+
- config/requirements.rb
|
42
|
+
- lib/context.rb
|
43
|
+
- lib/context/version.rb
|
44
|
+
- lib/context/lifecycle.rb
|
45
|
+
- lib/context/suite.rb
|
46
|
+
- lib/context/core.rb
|
47
|
+
- lib/context/shared_behavior.rb
|
48
|
+
- lib/context/test.rb
|
49
|
+
- lib/context/core_ext/string.rb
|
50
|
+
- lib/context/core_ext/rails_hacks.rb
|
51
|
+
- setup.rb
|
52
|
+
- test/test_context.rb
|
53
|
+
- test/test_core_ext.rb
|
54
|
+
- test/test_lifecycle.rb
|
55
|
+
- test/test_test.rb
|
56
|
+
- test/test_helper.rb
|
57
|
+
has_rdoc: true
|
58
|
+
homepage: http://github.com/be9/context
|
59
|
+
licenses: []
|
60
|
+
|
61
|
+
post_install_message:
|
62
|
+
rdoc_options:
|
63
|
+
- --main
|
64
|
+
- README.rdoc
|
65
|
+
require_paths:
|
66
|
+
- lib
|
67
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
68
|
+
none: false
|
69
|
+
requirements:
|
70
|
+
- - ">="
|
71
|
+
- !ruby/object:Gem::Version
|
72
|
+
hash: 3
|
73
|
+
segments:
|
74
|
+
- 0
|
75
|
+
version: "0"
|
76
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
77
|
+
none: false
|
78
|
+
requirements:
|
79
|
+
- - ">="
|
80
|
+
- !ruby/object:Gem::Version
|
81
|
+
hash: 3
|
82
|
+
segments:
|
83
|
+
- 0
|
84
|
+
version: "0"
|
85
|
+
requirements: []
|
86
|
+
|
87
|
+
rubyforge_project:
|
88
|
+
rubygems_version: 1.3.7
|
89
|
+
signing_key:
|
90
|
+
specification_version: 3
|
91
|
+
summary: Contexts and DSL sugar for your tests
|
92
|
+
test_files:
|
93
|
+
- test/test_context.rb
|
94
|
+
- test/test_core_ext.rb
|
95
|
+
- test/test_lifecycle.rb
|
96
|
+
- test/test_test.rb
|
97
|
+
- test/test_helper.rb
|