citron 0.3.0 → 0.4.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/.ruby CHANGED
@@ -1,6 +1,7 @@
1
1
  ---
2
2
  source:
3
3
  - PROFILE
4
+ - Profile
4
5
  authors:
5
6
  - name: Thomas Sawyer
6
7
  email: transfire@gmail.com
@@ -33,15 +34,18 @@ repositories:
33
34
  resources:
34
35
  home: http://rubyworks.github.com/citron
35
36
  code: http://github.com/rubyworks/citron
37
+ bugs: http://github.com/rubyworks/citron/issues
38
+ chat: irc://chat.us.freenode.net/rubyworks
39
+ mail: http://groups.google.com/groups/rubyworks-mailinglist
36
40
  extra: {}
37
41
  load_path:
38
42
  - lib
39
43
  revision: 0
40
44
  name: citron
41
45
  title: Citron
42
- version: 0.3.0
43
- summary: Classic Unit-style Test Framework
44
- description: Citron is a unit testing framework with a classic test-case/test-unit
45
- style.
46
+ version: 0.4.0
47
+ summary: Classic Unit Testing
48
+ description: Citron is a classical unit testing framework with a developer freindly
49
+ DSL, runs on top of RubyTest and is BRASS compliant.
46
50
  organization: RubyWorks
47
51
  date: '2012-02-25'
data/COPYING.md CHANGED
@@ -1,14 +1,13 @@
1
1
  # COPYRIGHT
2
2
 
3
-
4
3
  ## NOTICES
5
4
 
6
5
  ### Citron
7
6
 
8
- http://rubyworks.github.com/citron
9
-
10
- * Copyright (c) 2011 Rubyworks (BSD-2-Clause)
11
-
7
+ Citron - Classic Unit Testing
8
+ 2011 (c) Rubyworks (BSD-2-Clause license)
9
+ All rights expressly reserved.
10
+ http://rubyworks.github.com/citron
12
11
 
13
12
  ## LICENSES
14
13
 
@@ -1,5 +1,15 @@
1
1
  # Release History
2
2
 
3
+ ## 0.4.0 / 2012-02-28
4
+
5
+ Reimplmented with a class-based model. This design is the traditional XUnit
6
+ OOP design, so it is more fitting Citron's design goals.
7
+
8
+ Changes:
9
+
10
+ * Reimplement with class-based model.
11
+
12
+
3
13
  ## 0.3.0 / 2012-02-25
4
14
 
5
15
  This release cleans up the code, deprecates the complex Before and After
@@ -1,6 +1,7 @@
1
- BSD 2 Clause License
2
-
3
- Copyright 2011 Thomas Sawyer. All rights reserved.
1
+ Citron - Classic Unit Testing
2
+ Copyright (c) 2011 Rubyworks (BSD-2-Clause license)
3
+ All rights are expressly reserved.
4
+ http://rubyworks.github.com/citron
4
5
 
5
6
  Redistribution and use in source and binary forms, with or without
6
7
  modification, are permitted provided that the following conditions are met:
data/README.md CHANGED
@@ -1,20 +1,36 @@
1
1
  # Citron
2
2
 
3
3
  [Website](http://rubyworks.github.com/citron) /
4
- [Development](http://github.com/rubyworks/citron) /
5
4
  [Report Issue](http://github.com/rubyworks/citron/issues) /
5
+ [IRC Channel](irc://chat.us.freenode.net/rubyworks) /
6
+ [Mailing List](http://groups.google.com/groups/rubyworks-mailinglist) /
7
+ [Development](http://github.com/rubyworks/citron)
8
+
9
+ [![Build Status](https://secure.travis-ci.org/rubyworks/citron.png)](http://travis-ci.org/rubyworks/citron)
6
10
 
7
11
 
8
12
  ## Description
9
13
 
10
- Citron is a traditional unit test framework. It defines a simple
11
- domain language for creating classically styled unit tests.
14
+ Citron is a classical unit testing framework. It defines a simple
15
+ domain language for creating traditionally modeled unit tests.
16
+
17
+
18
+ ## Installation
19
+
20
+ Using Rubygems simply install `citron`:
21
+
22
+ $ gem install citron
12
23
 
24
+ Citron depends on `ansi` for terminal colorization and `rubytest`,
25
+ so those will be installed as well if they are not already.
13
26
 
14
- ## Example
15
27
 
16
- Here's a fun example.
28
+ ## Instruction
17
29
 
30
+ Citon tests are written as a collection of testcase and test blocks.
31
+ Here is a fun example. We'll call the test file `test/test_beatit.rb`:
32
+
33
+ ```ruby
18
34
  TestCase "Show them how to Beat It" do
19
35
 
20
36
  setup do
@@ -42,14 +58,15 @@ Here's a fun example.
42
58
  raise NotImplementedError
43
59
  end
44
60
 
45
- # omit
46
- test "just beat it" do
47
- e = NotImplementedError.new
48
- e.set_assertion(true)
49
- raise e
50
- end
51
-
52
61
  end
62
+ ```
63
+
64
+ Citron doesn't dictate the assertions system you use. In the above example, we are using
65
+ the [A.E.](http://rubyworks.github.com/ae) assertion framework. You can use any [BRASS](http://rubyworks.github.com)
66
+ compliant system you prefer.
67
+
68
+ Citron is built on top of [RubyTest](http://rubyworks.github.com/rubytest).
69
+ Jump over to its website to learn how to run tests and setup test run profiles.
53
70
 
54
71
 
55
72
  ## Copyrights
@@ -2,8 +2,6 @@ $TEST_SUITE ||= []
2
2
 
3
3
  module Citron
4
4
  require 'citron/world'
5
- require 'citron/test_setup'
6
- require 'citron/test_teardown'
7
5
  require 'citron/test_proc'
8
6
  require 'citron/test_case'
9
7
 
@@ -11,8 +9,9 @@ module Citron
11
9
  #
12
10
  # Define a general test case.
13
11
  #
14
- def test_case(label, &block)
15
- $TEST_SUITE << Citron::TestCase.new(:label=>label, &block)
12
+ def test_case(label, *tags, &block)
13
+ testcase = Citron::TestCase.context(label, *tags, &block)
14
+ $TEST_SUITE << testcase.new
16
15
  end
17
16
 
18
17
  alias :TestCase :test_case
@@ -3,202 +3,99 @@ module Citron
3
3
  # Test Case encapsulates a collection of
4
4
  # unit tests organized into groups of contexts.
5
5
  #
6
- class TestCase
6
+ class TestCase < World
7
7
 
8
- # The parent context in which this case resides.
9
- attr :context
8
+ class << self
10
9
 
11
- # Brief description of the test case.
12
- attr :label
10
+ # Brief description of the test case.
11
+ attr :label
13
12
 
14
- # Symbol list of tags. Trailing element may be Hash
15
- # of `symbol => object`.
16
- attr :tags
13
+ # Symbol list of tags. Trailing element may be Hash
14
+ # of `symbol => object`.
15
+ attr :tags
17
16
 
18
- # List of tests and sub-cases.
19
- attr :tests
17
+ # List of tests and sub-cases.
18
+ attr :tests
20
19
 
21
- # The setup advice.
22
- attr :setup
20
+ # Code unit that is subject of test case.
21
+ attr :unit
23
22
 
24
- # The teardown advice.
25
- attr :teardown
26
-
27
- # Code unit that is subject of test case.
28
- attr :unit
23
+ # Initialize new TestCase.
24
+ #
25
+ def __set__(settings={}, &block)
26
+ @label = settings[:label]
27
+ @tags = settings[:tags]
28
+ @skip = settings[:skip]
29
29
 
30
- # Module for evaluating tests.
31
- attr :scope
30
+ @unit = calc_unit(@label)
32
31
 
33
- private
32
+ @tests = []
34
33
 
35
- # Initialize new TestCase.
36
- #
37
- def initialize(settings={}, &block)
38
- @context = settings[:context]
39
- @label = settings[:label]
40
- @tags = settings[:tags]
41
- #@setup = settings[:setup]
42
- @skip = settings[:skip]
43
-
44
- @unit = calc_unit
45
-
46
- if context
47
- @setup = context.setup.copy(self) if context.setup
48
- @teardown = context.teardown.copy(self) if context.teardown
34
+ class_eval(&block)
49
35
  end
50
36
 
51
- @tests = []
52
-
53
- @scope = Scope.new(self)
54
-
55
- @scope.module_eval(&block) if block
56
- end
57
-
58
- #
59
- def calc_unit
60
- case @label
61
- when Module, Class
62
- @label
63
- when /^(\.|\#|\:\:)\w+/
64
- if @context && Module === @context.unit
65
- [@context.unit, @label].join('')
66
- else
37
+ #
38
+ #
39
+ #
40
+ def calc_unit(label)
41
+ case label
42
+ when Module, Class
67
43
  @label
44
+ when /^(\.|\#|\:\:)\w+/
45
+ if Module === superclass.unit
46
+ [superclass.unit, @label].join('')
47
+ else
48
+ @label
49
+ end
68
50
  end
69
51
  end
70
- end
71
-
72
- public
73
-
74
- #
75
- # Assign the setup procedure
76
- #
77
- # @param [TestSetup] test_setup
78
- #
79
- def setup=(test_setup)
80
- @setup = test_setup
81
- end
82
-
83
- #
84
- # Assign the teardown procedure.
85
- #
86
- # @param [TestTeardown] test_teardown
87
- #
88
- def teardown=(test_teardown)
89
- @teardown = test_teardown
90
- end
91
-
92
- #
93
- # Add new test or sub-case.
94
- #
95
- # @param [TestCase,TestProc] test_obejct
96
- # Test sub-case or procedure to add to this case.
97
- #
98
- def <<(test_object)
99
- @tests << test_object
100
- end
101
-
102
- #
103
- # Iterate over each test and sub-case.
104
- #
105
- # @param [Proc] block
106
- # Iteration procedure.
107
- #
108
- def each(&block)
109
- tests.each(&block)
110
- end
111
52
 
112
- #
113
- #def call
114
- # yield
115
- #end
116
-
117
- #
118
- # Number of tests and sub-cases.
119
- #
120
- # @return [Fixnum] size
121
- #
122
- def size
123
- tests.size
124
- end
125
-
126
- #
127
- # Subclasses of TestCase can override this to describe
128
- # the type of test case they define.
129
- #
130
- # @return [String]
131
- #
132
- #def type
133
- # 'TestCase'
134
- #end
135
-
136
- #
137
- # Test case label.
138
- #
139
- # @return [String]
140
- #
141
- def to_s
142
- label.to_s
143
- end
144
-
145
- #
146
- # Is test case to be skipped?
147
- #
148
- # @return [Boolean,String]
149
- # If +false+ or +nil+ if not skipped, otherwise
150
- # +true+ or a string explain why to skip.
151
- #
152
- def skip?
153
- @skip
154
- end
155
-
156
- #
157
- # Set test case to be skipped.
158
- #
159
- # @param [Boolean,String] reason
160
- # Set to +false+ or +nil+ if not skipped, otherwise
161
- # +true+ or a string explain why to skip.
162
- #
163
- def skip=(reason)
164
- @skip = reason
165
- end
166
-
167
- def test_scope
168
- @test_scope ||= TestProc::Scope.new(scope)
169
- end
53
+ #
54
+ # Subclasses of TestCase can override this to describe
55
+ # the type of test case they define.
56
+ #
57
+ # @return [String]
58
+ #
59
+ #def type
60
+ # 'TestCase'
61
+ #end
170
62
 
171
- #
172
- # Run +test+ in the context of this case.
173
- #
174
- # @param [TestProc] test
175
- # The test unit to run.
176
- #
177
- def run(test)
178
- setup.call(test_scope) if setup
179
- #scope.instance_exec(*arguments, &procedure)
180
- test_scope.instance_eval(&test.procedure)
181
- teardown.call(test_scope) if teardown
182
- end
63
+ #
64
+ # Add new test or sub-case.
65
+ #
66
+ # @param [Class<TestCase>,TestProc] test_obejct
67
+ # Test sub-case or procedure to add to this case.
68
+ #
69
+ def <<(test_object)
70
+ @tests ||= []
71
+ @tests << test_object
72
+ end
183
73
 
184
- # The evaluation scope for a test case.
185
- #
186
- class Scope < World
74
+ #
75
+ #def call
76
+ # yield
77
+ #end
187
78
 
188
79
  #
189
- # Initialize new evaluation scope.
80
+ # Is test case to be skipped?
190
81
  #
191
- # @param [TestCase] testcase
192
- # The test case this scope belongs.
82
+ # @return [Boolean,String]
83
+ # If +false+ or +nil+ if not skipped, otherwise
84
+ # +true+ or a string explain why to skip.
193
85
  #
194
- def initialize(testcase) #, &code)
195
- @_case = testcase
196
- @_setup = testcase.setup
197
- @_skip = false
86
+ def skip?
87
+ @skip
88
+ end
198
89
 
199
- if testcase.context
200
- include(testcase.context.scope)
201
- end
90
+ #
91
+ # Set test case to be skipped.
92
+ #
93
+ # @param [Boolean,String] reason
94
+ # Set to +false+ or +nil+ if not skipped, otherwise
95
+ # +true+ or a string explain why to skip.
96
+ #
97
+ def skip=(reason)
98
+ @skip = reason
202
99
  end
203
100
 
204
101
  #
@@ -212,19 +109,17 @@ module Citron
212
109
  # These can be used as a means of filtering tests.
213
110
  #
214
111
  def Context(label, *tags, &block)
215
- settings = {
216
- :context => @_case,
217
- #:setup => @_setup,
112
+ context = Class.new(self)
113
+ context.__set__(
218
114
  :skip => @_skip,
219
115
  :label => label,
220
- :tags => tags
221
- }
222
-
223
- testcase = TestCase.new(settings, &block)
116
+ :tags => tags,
117
+ &block
118
+ )
224
119
 
225
- @_case.tests << testcase
120
+ self << context
226
121
 
227
- testcase
122
+ context
228
123
  end
229
124
 
230
125
  alias :context :Context
@@ -243,8 +138,7 @@ module Citron
243
138
  file, line, _ = *caller[0].split(':')
244
139
 
245
140
  settings = {
246
- :context => @_case,
247
- #:setup => @_setup,
141
+ :context => self,
248
142
  :skip => @_skip,
249
143
  :label => label,
250
144
  :tags => tags,
@@ -254,9 +148,12 @@ module Citron
254
148
 
255
149
  if procedure.arity == 0 || (RUBY_VERSION < '1.9' && procedure.arity == -1)
256
150
  test = TestProc.new(settings, &procedure)
257
- @_case.tests << test
151
+
152
+ self << test
153
+
258
154
  @_test = nil
259
- test
155
+
156
+ return test
260
157
  else
261
158
  @_test = [settings, procedure]
262
159
  end
@@ -276,7 +173,7 @@ module Citron
276
173
  procedure.call(*args)
277
174
  end
278
175
 
279
- @_case << test
176
+ self << test
280
177
 
281
178
  return test
282
179
  end
@@ -291,12 +188,9 @@ module Citron
291
188
  # A brief description of what the setup procedure sets-up.
292
189
  #
293
190
  def Setup(label=nil, &proc)
294
- if proc
295
- @_case.setup = TestSetup.new(@_case, label, &proc)
296
- @_case.teardown = nil # if the setup is reset, then so it the teardown
297
- else
298
- @_case.setup
299
- end
191
+ define_method(:setup, &proc)
192
+ # if the setup is reset, then so should the teardown
193
+ define_method(:teardown){}
300
194
  end
301
195
 
302
196
  alias :setup :Setup
@@ -305,11 +199,7 @@ module Citron
305
199
  # Teardown procedure is used to clean-up after each unit test.
306
200
  #
307
201
  def Teardown(&proc)
308
- if proc
309
- @_case.teardown = TestTeardown.new(@_case, &proc)
310
- else
311
- @_case.teardown
312
- end
202
+ define_method(:teardown, &proc)
313
203
  end
314
204
 
315
205
  alias :teardown :Teardown
@@ -348,6 +238,61 @@ module Citron
348
238
 
349
239
  alias :skip :Skip
350
240
 
241
+ alias :inspect :to_s
242
+
243
+ #
244
+ # Test case label.
245
+ #
246
+ # @return [String]
247
+ #
248
+ def to_s
249
+ label.to_s
250
+ end
251
+
252
+ end
253
+
254
+ #
255
+ # Iterate over each test and sub-case.
256
+ #
257
+ def each
258
+ self.class.tests.each do |test_object|
259
+ case test_object
260
+ when Class #TestCase
261
+ yield(test_object.new)
262
+ when TestProc
263
+ yield(test_object.for(self))
264
+ end
265
+ end
266
+ end
267
+
268
+ #
269
+ # Number of tests and sub-cases.
270
+ #
271
+ # @return [Fixnum] size
272
+ #
273
+ def size
274
+ self.class.tests.size
275
+ end
276
+
277
+ #
278
+ # Test case label.
279
+ #
280
+ # @return [String]
281
+ #
282
+ def to_s
283
+ self.class.label.to_s
284
+ end
285
+
286
+ #
287
+ # Dummy method for setup.
288
+ #
289
+ def setup
290
+ end
291
+
292
+ #
293
+ # Dummy method for teardown.
294
+ #
295
+ def teardown
351
296
  end
352
297
 
353
298
  end
@@ -8,7 +8,6 @@ module Citron
8
8
  #
9
9
  def initialize(options={}, &procedure)
10
10
  @context = options[:context]
11
- #@setup = options[:setup]
12
11
  @label = options[:label]
13
12
  @tags = options[:tags]
14
13
  @skip = options[:skip]
@@ -97,18 +96,20 @@ module Citron
97
96
  #
98
97
  # @return [TestSetup] setup
99
98
  #
100
- def setup
101
- @context.setup
102
- end
99
+ #def setup
100
+ # @context.setup
101
+ #end
103
102
 
104
- #
105
- # Ruby Test looks for `#topic` as the desciption of a test's setup.
106
- #
107
- # @return [String] Description of the setup.
108
- #
109
- def topic
110
- setup.to_s
111
- end
103
+ # TODO: possible to support topic?
104
+
105
+ ##
106
+ ## Ruby Test looks for `#topic` as the desciption of a test's setup.
107
+ ##
108
+ ## @return [String] Description of the setup.
109
+ ##
110
+ #def topic
111
+ # setup.to_s
112
+ #end
112
113
 
113
114
  #
114
115
  # Location of test definition.
@@ -142,33 +143,32 @@ module Citron
142
143
  # Run this test in context.
143
144
  #
144
145
  def call
145
- context.run(self)
146
+ @scope.setup
147
+ @scope.instance_eval(&procedure)
148
+ @scope.teardown
146
149
  end
147
150
 
148
151
  #
149
- # Convert `#call` to Proc.
150
- #
151
- # @return [Proc]
152
+ # Return copy with `@scope` set.
152
153
  #
153
- def to_proc
154
- lambda{ call }
154
+ def for(scope)
155
+ @scope = scope
156
+ self.dup
155
157
  end
156
158
 
159
+ ##
160
+ ## Convert `#call` to Proc.
161
+ ##
162
+ ## @return [Proc]
163
+ ##
164
+ #def to_proc
165
+ # lambda{ call } # procedure ?
166
+ #end
167
+
157
168
  #
158
169
  #def set_proc(&proc)
159
170
  # @procedure = proc
160
171
  #end
161
-
162
- class Scope < World
163
-
164
- def initialize(parent)
165
- #include context
166
- @_parent = parent
167
- extend parent
168
- end
169
-
170
- end
171
-
172
172
  end
173
173
 
174
174
  end
@@ -3,7 +3,7 @@ module Citron
3
3
  # To add global helpers to test case context, you can
4
4
  # add that functionality to the Citron::World module.
5
5
  #
6
- class World < Module
6
+ class World #< Module
7
7
  end
8
8
 
9
9
  end
@@ -7,7 +7,7 @@ testcase Array do
7
7
  end
8
8
 
9
9
  test "unit should be class and method" do
10
- @_parent.instance_variable_get(:@_case).unit.assert == "Array#join"
10
+ self.class.unit.assert == "Array#join"
11
11
  end
12
12
 
13
13
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: citron
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.0
4
+ version: 0.4.0
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,11 +9,11 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-02-26 00:00:00.000000000 Z
12
+ date: 2012-02-28 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rubytest
16
- requirement: &22941000 !ruby/object:Gem::Requirement
16
+ requirement: &18271840 !ruby/object:Gem::Requirement
17
17
  none: false
18
18
  requirements:
19
19
  - - ! '>='
@@ -21,10 +21,10 @@ dependencies:
21
21
  version: '0'
22
22
  type: :runtime
23
23
  prerelease: false
24
- version_requirements: *22941000
24
+ version_requirements: *18271840
25
25
  - !ruby/object:Gem::Dependency
26
26
  name: ae
27
- requirement: &22940460 !ruby/object:Gem::Requirement
27
+ requirement: &18271300 !ruby/object:Gem::Requirement
28
28
  none: false
29
29
  requirements:
30
30
  - - ! '>='
@@ -32,10 +32,10 @@ dependencies:
32
32
  version: '0'
33
33
  type: :runtime
34
34
  prerelease: false
35
- version_requirements: *22940460
35
+ version_requirements: *18271300
36
36
  - !ruby/object:Gem::Dependency
37
37
  name: detroit
38
- requirement: &22939960 !ruby/object:Gem::Requirement
38
+ requirement: &18270800 !ruby/object:Gem::Requirement
39
39
  none: false
40
40
  requirements:
41
41
  - - ! '>='
@@ -43,10 +43,10 @@ dependencies:
43
43
  version: '0'
44
44
  type: :development
45
45
  prerelease: false
46
- version_requirements: *22939960
46
+ version_requirements: *18270800
47
47
  - !ruby/object:Gem::Dependency
48
48
  name: reap
49
- requirement: &22939440 !ruby/object:Gem::Requirement
49
+ requirement: &18270280 !ruby/object:Gem::Requirement
50
50
  none: false
51
51
  requirements:
52
52
  - - ! '>='
@@ -54,10 +54,10 @@ dependencies:
54
54
  version: '0'
55
55
  type: :development
56
56
  prerelease: false
57
- version_requirements: *22939440
57
+ version_requirements: *18270280
58
58
  - !ruby/object:Gem::Dependency
59
59
  name: qed
60
- requirement: &22938940 !ruby/object:Gem::Requirement
60
+ requirement: &18269780 !ruby/object:Gem::Requirement
61
61
  none: false
62
62
  requirements:
63
63
  - - ! '>='
@@ -65,24 +65,22 @@ dependencies:
65
65
  version: '0'
66
66
  type: :development
67
67
  prerelease: false
68
- version_requirements: *22938940
69
- description: Citron is a unit testing framework with a classic test-case/test-unit
70
- style.
68
+ version_requirements: *18269780
69
+ description: Citron is a classical unit testing framework with a developer freindly
70
+ DSL, runs on top of RubyTest and is BRASS compliant.
71
71
  email:
72
72
  - transfire@gmail.com
73
73
  executables: []
74
74
  extensions: []
75
75
  extra_rdoc_files:
76
- - LICENSE.txt
76
+ - License.txt
77
77
  - COPYING.md
78
- - HISTORY.md
79
78
  - README.md
79
+ - History.md
80
80
  files:
81
81
  - .ruby
82
82
  - lib/citron/test_case.rb
83
83
  - lib/citron/test_proc.rb
84
- - lib/citron/test_setup.rb
85
- - lib/citron/test_teardown.rb
86
84
  - lib/citron/world.rb
87
85
  - lib/citron.rb
88
86
  - test/case_basic.rb
@@ -91,9 +89,9 @@ files:
91
89
  - test/case_setup.rb
92
90
  - test/case_unit.rb
93
91
  - COPYING.md
94
- - LICENSE.txt
95
- - HISTORY.md
96
92
  - README.md
93
+ - History.md
94
+ - License.txt
97
95
  homepage: http://rubyworks.github.com/citron
98
96
  licenses:
99
97
  - BSD-2-Clause
@@ -118,5 +116,5 @@ rubyforge_project:
118
116
  rubygems_version: 1.8.11
119
117
  signing_key:
120
118
  specification_version: 3
121
- summary: Classic Unit-style Test Framework
119
+ summary: Classic Unit Testing
122
120
  test_files: []
@@ -1,73 +0,0 @@
1
- module Citron
2
-
3
- # Ecapsulate a test case's setup code.
4
- #
5
- class TestSetup
6
-
7
- #
8
- # The test case to which this advice belong.
9
- #
10
- attr :context
11
-
12
- #
13
- # The setup procedures.
14
- #
15
- attr :procedures
16
-
17
- #
18
- # A brief description of the setup.
19
- #
20
- attr :label
21
-
22
- #
23
- # Initialize new Setup instance.
24
- #
25
- def initialize(context, label, &proc)
26
- @context = context
27
- @label = label.to_s
28
- @procedures = []
29
-
30
- @procedures << proc if proc
31
- end
32
-
33
- #
34
- # Copy the setup for a new context.
35
- #
36
- def copy(context)
37
- c = self.class.new(context, label)
38
- c.procedures = procedures
39
- c
40
- end
41
-
42
- #
43
- # Run setup procedure in test scope.
44
- #
45
- def call(scope)
46
- procedures.each do |proc|
47
- scope.instance_eval(&proc)
48
- end
49
- end
50
-
51
- #
52
- # Returns the description with newlines removed.
53
- #
54
- def to_s
55
- label.gsub(/\n/, ' ')
56
- end
57
-
58
- #
59
- # Add a setup procedure.
60
- #
61
- def add(&proc)
62
- @procedures << proc
63
- end
64
-
65
- protected
66
-
67
- def procedures=(procedures)
68
- @procedures = procedures
69
- end
70
-
71
- end
72
-
73
- end
@@ -1,60 +0,0 @@
1
- module Citron
2
-
3
- # Ecapsulate a test case's teardown code.
4
- #
5
- class TestTeardown
6
-
7
- #
8
- # The test case to which this advice belong.
9
- #
10
- attr :context
11
-
12
- #
13
- # The setup procedures.
14
- #
15
- attr :procedures
16
-
17
- #
18
- # Initialize new Setup instance.
19
- #
20
- def initialize(context, &proc)
21
- @context = context
22
- @procedures = []
23
-
24
- @procedures << proc if proc
25
- end
26
-
27
- #
28
- # Copy the teardown for a new context.
29
- #
30
- def copy(context)
31
- c = self.class.new(context)
32
- c.procedures = procedures
33
- c
34
- end
35
-
36
- #
37
- # Run teardown procedure in test scope.
38
- #
39
- def call(scope)
40
- procedures.each do |proc|
41
- scope.instance_eval(&proc)
42
- end
43
- end
44
-
45
- #
46
- # Add a teardown procedure.
47
- #
48
- def add(&proc)
49
- procedures << proc
50
- end
51
-
52
- protected
53
-
54
- def procedures=(procedures)
55
- @procedures = procedures
56
- end
57
-
58
- end
59
-
60
- end