tu-context 0.5.7
Sign up to get free protection for your applications and to get access to all the features.
- data/.document +5 -0
- data/.gitignore +21 -0
- data/History.txt +10 -0
- data/License.txt +20 -0
- data/Manifest.txt +30 -0
- data/PostInstall.txt +0 -0
- data/README.rdoc +159 -0
- data/Rakefile +52 -0
- data/VERSION +1 -0
- data/config/hoe.rb +73 -0
- data/config/requirements.rb +15 -0
- data/context.gemspec +44 -0
- data/countloc.rb +65 -0
- data/lib/context.rb +19 -0
- data/lib/context/context.rb +64 -0
- data/lib/context/core_ext/rails_hacks.rb +10 -0
- data/lib/context/core_ext/string.rb +17 -0
- data/lib/context/lifecycle.rb +103 -0
- data/lib/context/shared_behavior.rb +97 -0
- data/lib/context/suite.rb +39 -0
- data/lib/context/test.rb +37 -0
- data/lib/context/version.rb +9 -0
- data/setup.rb +1585 -0
- data/tasks/deployment.rake +34 -0
- data/tasks/environment.rake +7 -0
- data/test/test_context.rb +57 -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_nested_lifecycle.rb +44 -0
- data/test/test_shared.rb +116 -0
- data/test/test_shared_lifecycle.rb +24 -0
- data/test/test_test.rb +23 -0
- metadata +108 -0
@@ -0,0 +1,34 @@
|
|
1
|
+
desc 'Release the website and new gem version'
|
2
|
+
task :deploy => [:check_version, :website, :release] do
|
3
|
+
puts "Remember to create SVN tag:"
|
4
|
+
puts "svn copy svn+ssh://#{rubyforge_username}@rubyforge.org/var/svn/#{PATH}/trunk " +
|
5
|
+
"svn+ssh://#{rubyforge_username}@rubyforge.org/var/svn/#{PATH}/tags/REL-#{VERS} "
|
6
|
+
puts "Suggested comment:"
|
7
|
+
puts "Tagging release #{CHANGES}"
|
8
|
+
end
|
9
|
+
|
10
|
+
desc 'Runs tasks website_generate and install_gem as a local deployment of the gem'
|
11
|
+
task :local_deploy => [:website_generate, :install_gem]
|
12
|
+
|
13
|
+
task :check_version do
|
14
|
+
unless ENV['VERSION']
|
15
|
+
puts 'Must pass a VERSION=x.y.z release version'
|
16
|
+
exit
|
17
|
+
end
|
18
|
+
unless ENV['VERSION'] == VERS
|
19
|
+
puts "Please update your version.rb to match the release version, currently #{VERS}"
|
20
|
+
exit
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
desc 'Install the package as a gem, without generating documentation(ri/rdoc)'
|
25
|
+
task :install_gem_no_doc => [:clean, :package] do
|
26
|
+
sh "#{'sudo ' unless Hoe::WINDOZE }gem install pkg/*.gem --no-rdoc --no-ri"
|
27
|
+
end
|
28
|
+
|
29
|
+
namespace :manifest do
|
30
|
+
desc 'Recreate Manifest.txt to include ALL files'
|
31
|
+
task :refresh do
|
32
|
+
`rake check_manifest | patch -p0 > Manifest.txt`
|
33
|
+
end
|
34
|
+
end
|
@@ -0,0 +1,57 @@
|
|
1
|
+
require File.dirname(__FILE__) + '/test_helper.rb'
|
2
|
+
|
3
|
+
class TestContext < Test::Unit::TestCase
|
4
|
+
def test_can_write_tests_without_context
|
5
|
+
assert true
|
6
|
+
end
|
7
|
+
|
8
|
+
def test_context_aliases
|
9
|
+
[:context, :contexts, :describe, :describes, :group, :specify, :specifies].each do |method_alias|
|
10
|
+
assert self.class.respond_to?(method_alias)
|
11
|
+
end
|
12
|
+
end
|
13
|
+
|
14
|
+
context "A new context" do
|
15
|
+
context "when not nested" do
|
16
|
+
before do
|
17
|
+
@context = Class.new(Test::Unit::TestCase).context("When testing") do
|
18
|
+
def test_this_thing
|
19
|
+
true
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
it "should set the context name" do
|
25
|
+
assert_equal "When testing", @context.context_name
|
26
|
+
end
|
27
|
+
|
28
|
+
it "should be a Test::Unit::TestCase" do
|
29
|
+
assert @context.ancestors.include?(Test::Unit::TestCase)
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
context "when nested" do
|
34
|
+
before do
|
35
|
+
@context = self.class.context("and we're testing") do
|
36
|
+
def self.nested
|
37
|
+
@nested
|
38
|
+
end
|
39
|
+
|
40
|
+
@nested = context "should be nested" do
|
41
|
+
def test_this_thing
|
42
|
+
true
|
43
|
+
end
|
44
|
+
end
|
45
|
+
end
|
46
|
+
end
|
47
|
+
|
48
|
+
it "should set a nested context's name" do
|
49
|
+
assert_equal "A new context when nested and we're testing should be nested", @context.nested.context_name
|
50
|
+
end
|
51
|
+
|
52
|
+
it "should also be a Test::Unit::TestCase" do
|
53
|
+
assert @context.nested.ancestors.include?(Test::Unit::TestCase)
|
54
|
+
end
|
55
|
+
end
|
56
|
+
end
|
57
|
+
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 downcased when converted" do
|
10
|
+
assert_equal "this_is_a_blast", "THIS is A BlASt".to_method_name
|
11
|
+
end
|
12
|
+
|
13
|
+
it "should change spaces to _" do
|
14
|
+
assert_equal "this_has_been_great", "This has been great".to_method_name
|
15
|
+
end
|
16
|
+
|
17
|
+
it "should change dangerous punctuation to _" do
|
18
|
+
assert_equal "no_really_this_was_good_", "No, really; this was #good!".to_method_name
|
19
|
+
end
|
20
|
+
|
21
|
+
it "should change ? to _" do
|
22
|
+
assert_equal "are_you_sure_yes_", "Are you sure? Yes.".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
|
@@ -0,0 +1,44 @@
|
|
1
|
+
require File.dirname(__FILE__) + '/test_helper.rb'
|
2
|
+
|
3
|
+
class TestNestedLifecycle < Test::Unit::TestCase
|
4
|
+
before :all do
|
5
|
+
@var = 0
|
6
|
+
end
|
7
|
+
|
8
|
+
before do
|
9
|
+
@var += 1
|
10
|
+
end
|
11
|
+
context "A new context" do
|
12
|
+
before do
|
13
|
+
@var += 1
|
14
|
+
end
|
15
|
+
|
16
|
+
before :all do
|
17
|
+
@var = 0
|
18
|
+
end
|
19
|
+
|
20
|
+
context "A nested context" do
|
21
|
+
before do
|
22
|
+
@var += 1
|
23
|
+
end
|
24
|
+
|
25
|
+
before :all do
|
26
|
+
@var += 1
|
27
|
+
end
|
28
|
+
|
29
|
+
context "A second, nested context" do
|
30
|
+
before do
|
31
|
+
@var += 1
|
32
|
+
end
|
33
|
+
|
34
|
+
before :all do
|
35
|
+
@var += 1
|
36
|
+
end
|
37
|
+
|
38
|
+
it "should set var" do
|
39
|
+
assert_equal 6, @var
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end
|
data/test/test_shared.rb
ADDED
@@ -0,0 +1,116 @@
|
|
1
|
+
require File.dirname(__FILE__) + '/test_helper.rb'
|
2
|
+
|
3
|
+
class TestTest < Test::Unit::TestCase
|
4
|
+
def test_shared_aliases
|
5
|
+
%w(shared_behavior share_as share_behavior_as shared_examples_for).each do |method_alias|
|
6
|
+
assert self.class.respond_to?(method_alias.to_sym)
|
7
|
+
end
|
8
|
+
end
|
9
|
+
|
10
|
+
def test_use_aliases
|
11
|
+
%w(uses it_should_behave_like behaves_like uses_examples_from).each do |method_alias|
|
12
|
+
assert self.class.respond_to?(method_alias.to_sym)
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
context "A shared group" do
|
17
|
+
context "creates a module" do
|
18
|
+
test "based on a string name" do
|
19
|
+
self.class.shared "things and fun" do
|
20
|
+
end
|
21
|
+
|
22
|
+
assert Object.const_get(:ThingsAndFun)
|
23
|
+
assert_equal Context::SharedBehavior, Object.const_get(:ThingsAndFun).class
|
24
|
+
end
|
25
|
+
|
26
|
+
it "based on a symbol name" do
|
27
|
+
self.class.shared :fun_and_games do
|
28
|
+
end
|
29
|
+
|
30
|
+
assert Object.const_get(:FunAndGames)
|
31
|
+
assert_equal Context::SharedBehavior, Object.const_get(:FunAndGames).class
|
32
|
+
end
|
33
|
+
|
34
|
+
it "unless the name is not a String or Symbol" do
|
35
|
+
assert_raise ArgumentError do
|
36
|
+
self.class.shared StandardError do
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
42
|
+
context "should be locatable" do
|
43
|
+
shared "hello sir" do
|
44
|
+
def amazing!
|
45
|
+
puts "back off!"
|
46
|
+
end
|
47
|
+
end
|
48
|
+
|
49
|
+
it "by a symbol" do
|
50
|
+
assert_nothing_raised do
|
51
|
+
self.class.use :hello_sir
|
52
|
+
end
|
53
|
+
end
|
54
|
+
|
55
|
+
shared "hello madam" do
|
56
|
+
def fantastic!
|
57
|
+
puts "you know me!"
|
58
|
+
end
|
59
|
+
end
|
60
|
+
|
61
|
+
it "by a string" do
|
62
|
+
assert_nothing_raised do
|
63
|
+
self.class.use "hello madam"
|
64
|
+
end
|
65
|
+
end
|
66
|
+
|
67
|
+
shared "hi dog" do
|
68
|
+
def stupendous!
|
69
|
+
puts "hoo hah!"
|
70
|
+
end
|
71
|
+
end
|
72
|
+
|
73
|
+
it "by direct reference" do
|
74
|
+
assert_nothing_raised do
|
75
|
+
self.class.use HiDog
|
76
|
+
end
|
77
|
+
end
|
78
|
+
end
|
79
|
+
|
80
|
+
context "should include its shared behavior" do
|
81
|
+
shared "Athos" do
|
82
|
+
it "en_garde" do
|
83
|
+
true
|
84
|
+
end
|
85
|
+
end
|
86
|
+
|
87
|
+
it "by a symbol" do
|
88
|
+
self.class.use :athos
|
89
|
+
|
90
|
+
assert send("test: A shared group should include its shared behavior en_garde")
|
91
|
+
end
|
92
|
+
|
93
|
+
shared "Porthos" do
|
94
|
+
def parry!
|
95
|
+
true
|
96
|
+
end
|
97
|
+
end
|
98
|
+
|
99
|
+
it "by a string" do
|
100
|
+
self.class.use "Porthos"
|
101
|
+
assert parry!
|
102
|
+
end
|
103
|
+
|
104
|
+
shared "Aramis" do
|
105
|
+
def lunge!
|
106
|
+
true
|
107
|
+
end
|
108
|
+
end
|
109
|
+
|
110
|
+
it "by direct reference" do
|
111
|
+
self.class.use Aramis
|
112
|
+
assert lunge!
|
113
|
+
end
|
114
|
+
end
|
115
|
+
end
|
116
|
+
end
|