djsun-context 0.5.5

Sign up to get free protection for your applications and to get access to all the features.
@@ -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,21 @@
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 :this_is_fun, "this is fun".to_method_name
7
+ end
8
+
9
+ it "should be downcased when converted" do
10
+ assert :this_is_a_blast, "THIS is A BlASt".to_method_name
11
+ end
12
+
13
+ it "should change spaces to _" do
14
+ assert :this_has_been_great, "This has been great".to_method_name
15
+ end
16
+
17
+ it "should change dangerous punctuation to _" do
18
+ assert :no__really__this_was__good_, "No, really; this was #good!".to_method_name
19
+ end
20
+ end
21
+ end
@@ -0,0 +1,2 @@
1
+ require 'test/unit'
2
+ require File.dirname(__FILE__) + '/../lib/context'
@@ -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,79 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: djsun-context
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.5.5
5
+ platform: ruby
6
+ authors:
7
+ - Jeremy McAnally
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+
12
+ date: 2008-10-03 00:00:00 -07:00
13
+ default_executable:
14
+ dependencies: []
15
+
16
+ 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!
17
+ email: jeremy@entp.com
18
+ executables: []
19
+
20
+ extensions: []
21
+
22
+ extra_rdoc_files:
23
+ - History.txt
24
+ - Manifest.txt
25
+ - README.rdoc
26
+ files:
27
+ - README.rdoc
28
+ - Rakefile
29
+ - context.gemspec
30
+ - History.txt
31
+ - License.txt
32
+ - Manifest.txt
33
+ - PostInstall.txt
34
+ - config/hoe.rb
35
+ - config/requirements.rb
36
+ - lib/context.rb
37
+ - lib/context/version.rb
38
+ - lib/context/lifecycle.rb
39
+ - lib/context/suite.rb
40
+ - lib/context/context.rb
41
+ - lib/context/shared_behavior.rb
42
+ - lib/context/test.rb
43
+ - lib/context/core_ext/string.rb
44
+ - lib/context/core_ext/rails_hacks.rb
45
+ - setup.rb
46
+ has_rdoc: true
47
+ homepage: http://github.com/jeremymcanally/context
48
+ licenses:
49
+ post_install_message:
50
+ rdoc_options:
51
+ - --main
52
+ - README.rdoc
53
+ require_paths:
54
+ - lib
55
+ required_ruby_version: !ruby/object:Gem::Requirement
56
+ requirements:
57
+ - - ">="
58
+ - !ruby/object:Gem::Version
59
+ version: "0"
60
+ version:
61
+ required_rubygems_version: !ruby/object:Gem::Requirement
62
+ requirements:
63
+ - - ">="
64
+ - !ruby/object:Gem::Version
65
+ version: "0"
66
+ version:
67
+ requirements: []
68
+
69
+ rubyforge_project:
70
+ rubygems_version: 1.3.5
71
+ signing_key:
72
+ specification_version: 2
73
+ summary: Contexts and DSL sugar for your tests
74
+ test_files:
75
+ - test/test_context.rb
76
+ - test/test_core_ext.rb
77
+ - test/test_lifecycle.rb
78
+ - test/test_test.rb
79
+ - test/test_helper.rb