dtest 0.0.4 → 0.0.5

Sign up to get free protection for your applications and to get access to all the features.
@@ -16,10 +16,9 @@ DTest is a testing tool to describe integrating test for distributed systems.
16
16
 
17
17
  * support Ctrl-C interruption
18
18
  * TestCase value-parameterized
19
- * desigining instance variable valid scope
20
19
 
21
20
  == Copyright
22
21
 
23
- Copyright (c) 2011 Shuzo Kashihara. See LICENSE.txt for
22
+ Copyright (c) 2012 Shuzo Kashihara. See LICENSE.txt for
24
23
  further details.
25
24
 
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.0.4
1
+ 0.0.5
@@ -0,0 +1,36 @@
1
+ SharedContext 'context1' do
2
+ @test = 'hoge'
3
+ set :var, 'variable1'
4
+ def context_method
5
+ 'hello'
6
+ end
7
+ end
8
+
9
+ SharedContext 'context2' do
10
+ set :var, 'variable2'
11
+ def context_method
12
+ 'world'
13
+ end
14
+ end
15
+
16
+ GlobalHarness do
17
+ include_context 'context1'
18
+ before do
19
+ assert_equal('hello', context_method)
20
+ assert_equal('variable1', var)
21
+ assert_equal('hoge', @test)
22
+ end
23
+ end
24
+
25
+ TestCase 'test' do
26
+ include_context 'context2'
27
+ before do
28
+ assert_equal('hoge', @test)
29
+ @test = 'fuga'
30
+ end
31
+ test 'test' do
32
+ assert_equal('world', context_method)
33
+ assert_equal('variable2', var)
34
+ assert_equal('fuga', @test)
35
+ end
36
+ end
@@ -4,22 +4,38 @@ require 'dtest/runner'
4
4
  require 'dtest/dsl'
5
5
 
6
6
  def usage
7
- puts "dtest [files...]"
7
+ puts 'dtest [options] [files...]'
8
+ puts 'dtest [options] [files...] -- [arguments for testcode]'
9
+ puts ''
10
+ puts ' --xml output_path Specify path to write junit style xml.'
11
+ puts ' --color Enables to print color on the terminal.'
8
12
  end
9
13
 
10
- if ARGV.empty?
11
- usage
12
- else
14
+ begin
13
15
  # Command line parser
14
- option = DTest::Runner.parse!(ARGV)
16
+ argv = ARGV
17
+ first = ARGV.index('--')
18
+ unless first.nil?
19
+ argv = ARGV[0..first-1]
20
+ ARGV.slice!(0..first)
21
+ end
22
+ option = DTest::Runner.parse!(argv)
15
23
 
16
- # execute test
17
- res = DTest::Runner.run(ARGV)
18
- DTest::Runner.report(res)
24
+ if argv.empty?
25
+ usage
26
+ else
27
+ # execute test
28
+ res = DTest::Runner.run(argv)
29
+ DTest::Runner.report(res)
19
30
 
20
- # output xml
21
- if option[:xml_path]
22
- res.outputxml(option[:xml_path])
31
+ # output xml
32
+ if option[:xml_path]
33
+ res.outputxml(option[:xml_path])
34
+ end
23
35
  end
36
+ rescue OptionParser::InvalidOption => e
37
+ puts "#{e.message}\n\n"
38
+ usage
24
39
  end
25
40
 
41
+
@@ -1,6 +1,5 @@
1
1
  # -*- coding: utf-8 -*-
2
2
 
3
- require 'singleton'
4
3
  require 'time'
5
4
 
6
5
  require 'dtest/failure'
@@ -73,7 +72,10 @@ module DTest
73
72
  # getter value
74
73
  @__state[:let].send(name)
75
74
  else
76
- super
75
+ file, line, error_line = DTest::failure_line(caller(1).first)
76
+ e = NameError.new("undefined local variable or method `#{name}'")
77
+ e.set_backtrace(["#{file}:#{line}", error_line])
78
+ raise e
77
79
  end
78
80
  end
79
81
 
@@ -147,7 +149,7 @@ module DTest
147
149
  end
148
150
 
149
151
  unless raised_expected_error
150
- str = "exception expected #{errors.to_s} but #{actual_error.inspect}\n"
152
+ str = "exception expected #{errors.join(', ')} but #{actual_error.inspect}\n"
151
153
  failed(str)
152
154
  end
153
155
  end
@@ -255,7 +257,7 @@ END
255
257
  }, @block)
256
258
  end
257
259
 
258
- end # class Context
260
+ end # class Block
259
261
 
260
262
  end # module DTest
261
263
 
@@ -1,6 +1,7 @@
1
-
2
- require 'dtest/core'
1
+ require 'dtest/test'
2
+ require 'dtest/global'
3
3
  require 'dtest/failure'
4
+ require 'dtest/shared_context'
4
5
 
5
6
  module DTest
6
7
  module DSL
@@ -22,6 +23,11 @@ module DTest
22
23
  manager.defined = true
23
24
  end
24
25
  end
26
+
27
+ def SharedContext(name, option = {}, &block)
28
+ manager = SharedContext::Manager::instance
29
+ manager.add(name, option, &block)
30
+ end
25
31
  end # module DSL
26
32
  end # module DTest
27
33
 
@@ -1,3 +1,6 @@
1
+ require 'singleton'
2
+ require 'dtest/util'
3
+ require 'dtest/progress'
1
4
 
2
5
  module DTest
3
6
  module Global
@@ -6,10 +9,12 @@ module DTest
6
9
 
7
10
  attr_accessor :global
8
11
  attr_accessor :before, :after
12
+ attr_accessor :shared_contexts
9
13
 
10
14
  def initialize
11
15
  @before = []
12
16
  @after = []
17
+ @shared_contexts = []
13
18
  end
14
19
 
15
20
  def execute_after(list, context)
@@ -24,6 +29,15 @@ module DTest
24
29
  # Progress
25
30
  global_values = Object.new
26
31
  context = Context.new(global_values)
32
+
33
+ unless @shared_contexts.empty?
34
+ i = DTest::SharedContext::Manager::instance
35
+ @shared_contexts.each { |name|
36
+ context.instance_eval(&i.contexts[name])
37
+ }
38
+ context
39
+ end
40
+
27
41
  Progress.setUpGlobal(testcases)
28
42
 
29
43
  global_result = Test::GlobalResult.new(testcases)
@@ -38,6 +52,7 @@ module DTest
38
52
 
39
53
  # execute cases
40
54
  testcases.each do |testcase|
55
+ testcase.shared_contexts = shared_contexts
41
56
  testcase.defined_values = global_values.clone
42
57
  execute_testcase(global_result, testcase)
43
58
  end
@@ -79,6 +94,14 @@ module DTest
79
94
  @defined = false
80
95
  end
81
96
 
97
+ def include_context(name)
98
+ if DTest::SharedContext::Manager::instance.has_key?(name)
99
+ @harness.shared_contexts << name unless @harness.shared_contexts.include?(name)
100
+ else
101
+ raise "#{name} context is not defined"
102
+ end
103
+ end
104
+
82
105
  def before(option = {}, &block)
83
106
  b = Block.new("before", option, &block)
84
107
  b.parent = 'Global'
@@ -17,7 +17,7 @@ module DTest
17
17
  opt.on('--xml PATH') do |path|
18
18
  res[:xml_path] = path
19
19
  end
20
- opt.parse!(ARGV)
20
+ opt.parse!(argv)
21
21
 
22
22
  res
23
23
  end
@@ -0,0 +1,40 @@
1
+ require 'singleton'
2
+ require 'dtest/util'
3
+ require 'dtest/failure'
4
+ require 'dtest/progress'
5
+
6
+ module DTest
7
+ module SharedContext
8
+ class Manager
9
+ include Singleton
10
+ include Hook
11
+
12
+ attr_reader :contexts
13
+
14
+ def initialize
15
+ clear
16
+ end
17
+
18
+ def clear
19
+ remove_instance_var
20
+ @contexts = {}
21
+ end
22
+
23
+ def has_key?(name)
24
+ @contexts.has_key?(name)
25
+ end
26
+
27
+ def add(name, option, &block)
28
+ file, line, = DTest::failure_line(caller(2).first)
29
+ str = ["#{name} context already defined"]
30
+ str << " in #{file}:#{line}" if file && line
31
+ raise str.join("\n") if @contexts.has_key?(name)
32
+
33
+ @contexts[name] = block
34
+ end
35
+ end # class Manager
36
+
37
+ module SharedHolder
38
+ end
39
+ end # module SharedContext
40
+ end # module DTest
@@ -1,4 +1,5 @@
1
-
1
+ require 'singleton'
2
+ require 'dtest/util'
2
3
  require 'dtest/progress'
3
4
 
4
5
  module DTest
@@ -11,8 +12,9 @@ module DTest
11
12
  attr_accessor :before, :after
12
13
  attr_accessor :test
13
14
  attr_accessor :defined_values
15
+ attr_accessor :shared_contexts
14
16
 
15
- def initialize(name, beforeCase, afterCase, before, after, test)
17
+ def initialize(name, beforeCase, afterCase, before, after, test, local_contexts)
16
18
  @name = name
17
19
  @beforeCase = beforeCase
18
20
  @afterCase = afterCase
@@ -20,9 +22,25 @@ module DTest
20
22
  @after = after
21
23
  @test = test
22
24
  @defined_values = Object.new
25
+ @shared_contexts = []
26
+ @local_contexts = local_contexts
23
27
  end
24
28
 
25
29
  private
30
+ def create_context
31
+ context = Context.new(@defined_values)
32
+
33
+ contexts = @shared_contexts + @local_contexts
34
+ unless contexts.empty?
35
+ i = DTest::SharedContext::Manager::instance
36
+ contexts.each { |name|
37
+ context.instance_eval(&i.contexts[name])
38
+ }
39
+ end
40
+
41
+ context
42
+ end
43
+
26
44
  def execute_after_case(list, context)
27
45
  begin
28
46
  exec(list, context)
@@ -40,6 +58,46 @@ module DTest
40
58
  end
41
59
  end
42
60
 
61
+ def execute_test(result, test)
62
+ Progress.test(@name, test.name)
63
+
64
+ context = create_context
65
+
66
+ # set result
67
+ @before.each {|b| b.result = result.before_failure }
68
+ @after.each {|b| b.result = result.after_failure }
69
+
70
+ begin
71
+ # execute before blocks
72
+ exec(@before, context)
73
+
74
+ # exeucte test
75
+ result.timer {
76
+ test.result = result
77
+ test.call(context, name)
78
+ }
79
+ rescue AbortTest
80
+ # にぎりつぶす
81
+ # 次のテストを実行する
82
+ rescue AbortTestCase, AbortGlobal => e
83
+ # スルー
84
+ raise e
85
+ rescue StandardError, Exception => e
86
+ # にぎりつぶす
87
+ ensure
88
+ begin
89
+ execute_after(@after, context)
90
+ ensure
91
+ if result.failure.empty? && result.ba_empty?
92
+ result.result = Result::PASS
93
+ Progress.test_success(@name, test.name)
94
+ else
95
+ Progress.test_fail(@name, test.name)
96
+ end
97
+ end
98
+ end
99
+ end
100
+
43
101
  public
44
102
  def execute(global_result)
45
103
  # TestCase result
@@ -53,7 +111,7 @@ module DTest
53
111
  Progress.setUpTestCase(name, @test.size)
54
112
  executed = 0
55
113
  passed = 0
56
- context = Context.new(@defined_values)
114
+ context = create_context
57
115
 
58
116
  begin
59
117
  caseresult.timer {
@@ -88,45 +146,6 @@ module DTest
88
146
  end
89
147
  end
90
148
 
91
- def execute_test(result, test)
92
- Progress.test(@name, test.name)
93
-
94
- context = Context.new(@defined_values)
95
-
96
- # set result
97
- @before.each {|b| b.result = result.before_failure }
98
- @after.each {|b| b.result = result.after_failure }
99
-
100
- begin
101
- # execute before blocks
102
- exec(@before, context)
103
-
104
- # exeucte test
105
- result.timer {
106
- test.result = result
107
- test.call(context, name)
108
- }
109
- rescue AbortTest
110
- # にぎりつぶす
111
- # 次のテストを実行する
112
- rescue AbortTestCase, AbortGlobal => e
113
- # スルー
114
- raise e
115
- rescue StandardError, Exception => e
116
- # にぎりつぶす
117
- ensure
118
- begin
119
- execute_after(@after, context)
120
- ensure
121
- if result.failure.empty? && result.ba_empty?
122
- result.result = Result::PASS
123
- Progress.test_success(@name, test.name)
124
- else
125
- Progress.test_fail(@name, test.name)
126
- end
127
- end
128
- end
129
- end
130
149
  end # class Case
131
150
 
132
151
  class Manager
@@ -151,6 +170,7 @@ module DTest
151
170
  @before = []
152
171
  @after = []
153
172
  @test = []
173
+ @contexts = []
154
174
  end
155
175
 
156
176
  def beforeCase(option = {}, &block)
@@ -184,6 +204,14 @@ module DTest
184
204
  end
185
205
  end
186
206
 
207
+ def include_context(name)
208
+ if DTest::SharedContext::Manager::instance.has_key?(name)
209
+ @contexts << name unless @contexts.include?(name)
210
+ else
211
+ raise "#{name} context is not defined"
212
+ end
213
+ end
214
+
187
215
  def test(name, option = {}, &block)
188
216
  if option && option[:params]
189
217
  # value-parameterized test
@@ -205,7 +233,7 @@ module DTest
205
233
  (@beforeCase + @afterCase + @before + @after + @test).each do |block|
206
234
  block.parent = name
207
235
  end
208
- @cases << Case.new(name, @beforeCase, @afterCase, @before, @after, @test)
236
+ @cases << Case.new(name, @beforeCase, @afterCase, @before, @after, @test, @contexts)
209
237
  flush
210
238
  end
211
239
  end # class Manager
@@ -1,5 +1,5 @@
1
1
  module DTest
2
2
 
3
- VERSION = '0.0.4'
3
+ VERSION = '0.0.5'
4
4
 
5
5
  end
@@ -5,3 +5,15 @@ end
5
5
  $LOAD_PATH << File.expand_path(File.join('..', 'lib'), File.dirname(__FILE__))
6
6
  require 'dtest/dsl'
7
7
  require 'dtest/runner'
8
+
9
+ def dtest_clear_instance
10
+ Global::Manager.instance.clear
11
+ Test::Manager.instance.clear
12
+ SharedContext::Manager.instance.clear
13
+ end
14
+
15
+ shared_context 'dtest' do
16
+ after do
17
+ dtest_clear_instance
18
+ end
19
+ end
@@ -9,15 +9,12 @@ include DTest
9
9
 
10
10
 
11
11
  describe Global::Manager, 'global abort' do
12
+ include_context 'dtest'
13
+
12
14
  before do
13
15
  $call = []
14
16
  end
15
17
 
16
- after do
17
- Global::Manager.instance.clear
18
- Test::Manager.instance.clear
19
- end
20
-
21
18
  it "global before abort_if" do
22
19
  GlobalHarness do
23
20
  before do
@@ -99,6 +96,8 @@ describe Global::Manager, 'global abort' do
99
96
  end
100
97
 
101
98
  describe Global::Manager, 'testcase abort' do
99
+ include_context 'dtest'
100
+
102
101
  before do
103
102
  $call = []
104
103
  GlobalHarness do
@@ -111,11 +110,6 @@ describe Global::Manager, 'testcase abort' do
111
110
  end
112
111
  end
113
112
 
114
- after do
115
- Global::Manager.instance.clear
116
- Test::Manager.instance.clear
117
- end
118
-
119
113
  # before: abort_if, abort_case_if, abort_global_if
120
114
  it "beforeCase abort_if" do
121
115
  TestCase "testcase1" do
@@ -423,6 +417,8 @@ end
423
417
 
424
418
 
425
419
  describe Global::Manager, 'test abort' do
420
+ include_context 'dtest'
421
+
426
422
  before do
427
423
  $call = []
428
424
  GlobalHarness do
@@ -435,12 +431,6 @@ describe Global::Manager, 'test abort' do
435
431
  end
436
432
  end
437
433
 
438
- after do
439
- Global::Manager.instance.clear
440
- Test::Manager.instance.clear
441
- end
442
-
443
-
444
434
  it "test:after abort_if" do
445
435
  TestCase "abortcase1" do
446
436
  beforeCase do
@@ -588,6 +578,8 @@ end
588
578
 
589
579
 
590
580
  describe Global::Manager, 'test abort' do
581
+ include_context 'dtest'
582
+
591
583
  before do
592
584
  $call = []
593
585
  GlobalHarness do
@@ -601,11 +593,6 @@ describe Global::Manager, 'test abort' do
601
593
  end
602
594
  end
603
595
 
604
- after do
605
- Global::Manager.instance.clear
606
- Test::Manager.instance.clear
607
- end
608
-
609
596
  it "test abort_if" do
610
597
  TestCase "testcase1" do
611
598
 
@@ -2,16 +2,12 @@ require File.expand_path(File.join('.', 'spec_helper'), File.dirname(__FILE__))
2
2
  include DTest
3
3
 
4
4
  describe Global::Manager, 'test assert' do
5
+ include_context 'dtest'
5
6
 
6
7
  before do
7
8
  $call = []
8
9
  end
9
10
 
10
- after do
11
- Global::Manager.instance.clear
12
- Test::Manager.instance.clear
13
- end
14
-
15
11
  it "assert global before" do
16
12
  GlobalHarness do
17
13
  before do
@@ -1,6 +1,6 @@
1
1
  require File.expand_path(File.join('.', 'spec_helper'), File.dirname(__FILE__))
2
2
 
3
- ARGV = []
3
+ ARGV.slice!(0..-1)
4
4
 
5
5
  Dir::glob(File.dirname(__FILE__) + "/dtest/*.rb").each {|f|
6
6
  ARGV << f
@@ -1,11 +1,8 @@
1
1
  require File.expand_path(File.join('.', 'spec_helper'), File.dirname(__FILE__))
2
2
 
3
- ARGV = []
3
+ ARGV.slice!(0..-1)
4
4
  begin
5
5
  load 'dtest/command.rb'
6
6
  ensure
7
- DTest::Global::Manager.instance.clear
8
- DTest::Test::Manager.instance.clear
7
+ dtest_clear_instance
9
8
  end
10
-
11
-
@@ -0,0 +1,220 @@
1
+ require File.expand_path(File.join('.', 'spec_helper'), File.dirname(__FILE__))
2
+ include DTest
3
+
4
+ describe SharedContext::Manager, 'dtest define shared_context' do
5
+ include_context 'dtest'
6
+
7
+ it "define context" do
8
+ SharedContext 'hello' do
9
+ end
10
+ end
11
+
12
+ it "missing to define same name context" do
13
+ SharedContext 'hello' do
14
+ end
15
+
16
+ lambda {
17
+ SharedContext 'hello' do
18
+ end
19
+ }.should raise_error(RuntimeError)
20
+ end
21
+ end
22
+
23
+ describe Global::Manager, 'dtest include_context' do
24
+ include_context 'dtest'
25
+
26
+ before do
27
+ SharedContext 'hello' do
28
+ def hello
29
+ 'hello'
30
+ end
31
+ end
32
+
33
+ SharedContext 'world' do
34
+ def world
35
+ 'world'
36
+ end
37
+ end
38
+
39
+ SharedContext 'hello_overwrite' do
40
+ def hello
41
+ 'hello_overwrite'
42
+ end
43
+ end
44
+ end
45
+
46
+ it "missing to include undefined context" do
47
+ lambda {
48
+ GlobalHarness do
49
+ include_context 'undefined_context'
50
+ end
51
+ }.should raise_error(RuntimeError)
52
+ end
53
+
54
+ it "missing to include undefined context" do
55
+ lambda {
56
+ TestCase 'testcase' do
57
+ include_context 'undefined'
58
+ end
59
+ }.should raise_error(RuntimeError)
60
+ end
61
+
62
+ it "global context" do
63
+ GlobalHarness do
64
+ include_context 'hello'
65
+ before do
66
+ assert_equal('hello', hello)
67
+ end
68
+ after do
69
+ assert_equal('hello', hello)
70
+ end
71
+ end
72
+
73
+ TestCase "testcase" do
74
+ test 'context' do
75
+ assert_equal('hello', hello)
76
+ end
77
+ end
78
+
79
+ global_report = Runner.run
80
+ global_report.after_failure.failure.size.should == 0
81
+
82
+ global_report.result.size.should == 1
83
+ cresult = global_report.result.first
84
+ cresult.before_failure.failure.size.should == 0
85
+ cresult.after_failure.failure.size.should == 0
86
+
87
+ result = cresult.result
88
+ result[0].before_failure.failure.size.should == 0
89
+ result[0].after_failure.failure.size.should == 0
90
+ result[0].failure.size.should == 0
91
+ end
92
+
93
+ it "testcase context" do
94
+ TestCase "testcase" do
95
+ include_context 'hello'
96
+ before do
97
+ assert_equal('hello', hello)
98
+ end
99
+
100
+ test 'context' do
101
+ assert_equal('hello', hello)
102
+ end
103
+
104
+ after do
105
+ assert_equal('hello', hello)
106
+ end
107
+ end
108
+
109
+ global_report = Runner.run
110
+ global_report.after_failure.failure.size.should == 0
111
+
112
+ global_report.result.size.should == 1
113
+ cresult = global_report.result.first
114
+ cresult.before_failure.failure.size.should == 0
115
+ cresult.after_failure.failure.size.should == 0
116
+
117
+ result = cresult.result
118
+ result[0].before_failure.failure.size.should == 0
119
+ result[0].after_failure.failure.size.should == 0
120
+ result[0].failure.size.should == 0
121
+ end
122
+
123
+
124
+ it "multi include context" do
125
+ TestCase "testcase" do
126
+ include_context 'hello'
127
+ include_context 'world'
128
+
129
+ test 'context' do
130
+ assert_equal('hello', hello)
131
+ assert_equal('world', world)
132
+ end
133
+ end
134
+
135
+ global_report = Runner.run
136
+ global_report.after_failure.failure.size.should == 0
137
+
138
+ global_report.result.size.should == 1
139
+ cresult = global_report.result.first
140
+ cresult.before_failure.failure.size.should == 0
141
+ cresult.after_failure.failure.size.should == 0
142
+
143
+ result = cresult.result
144
+ result[0].before_failure.failure.size.should == 0
145
+ result[0].after_failure.failure.size.should == 0
146
+ result[0].failure.size.should == 0
147
+ end
148
+
149
+
150
+ it "multi include and overwrite context" do
151
+ GlobalHarness do
152
+ include_context 'hello'
153
+ before do
154
+ assert_equal('hello', hello)
155
+ end
156
+ end
157
+ TestCase "testcase" do
158
+ include_context 'hello_overwrite'
159
+ test 'context' do
160
+ assert_equal('hello_overwrite', hello)
161
+ end
162
+ end
163
+
164
+ global_report = Runner.run
165
+ global_report.after_failure.failure.size.should == 0
166
+
167
+ global_report.result.size.should == 1
168
+ cresult = global_report.result.first
169
+ cresult.before_failure.failure.size.should == 0
170
+ cresult.after_failure.failure.size.should == 0
171
+
172
+ result = cresult.result
173
+ result[0].before_failure.failure.size.should == 0
174
+ result[0].after_failure.failure.size.should == 0
175
+ result[0].failure.size.should == 0
176
+ end
177
+
178
+ it "context can use dtest methods" do
179
+ SharedContext 'set' do
180
+ set :value, 'world'
181
+
182
+ def call_set(name, param)
183
+ set name, param # dtest
184
+ end
185
+
186
+ def my_assert_equal(a, b)
187
+ assert_equal(a, b)
188
+ end
189
+ end
190
+
191
+ GlobalHarness do
192
+ include_context 'set'
193
+ end
194
+
195
+ TestCase "context method" do
196
+ before do
197
+ call_set(:variable, 'hogehoge')
198
+ end
199
+
200
+ test 'context' do
201
+ assert_equal('world', value)
202
+ assert_equal('hogehoge', variable)
203
+ my_assert_equal(1234, 1234)
204
+ end
205
+ end
206
+
207
+ global_report = Runner.run
208
+ global_report.after_failure.failure.size.should == 0
209
+
210
+ global_report.result.size.should == 1
211
+ cresult = global_report.result.first
212
+ cresult.before_failure.failure.size.should == 0
213
+ cresult.after_failure.failure.size.should == 0
214
+
215
+ result = cresult.result
216
+ result[0].before_failure.failure.size.should == 0
217
+ result[0].after_failure.failure.size.should == 0
218
+ result[0].failure.size.should == 0
219
+ end
220
+ end
@@ -2,6 +2,7 @@ require File.expand_path(File.join('.', 'spec_helper'), File.dirname(__FILE__))
2
2
  include DTest
3
3
 
4
4
  describe Global::Manager, 'GlobalHarness can only be defined once' do
5
+ include_context 'dtest'
5
6
  after do
6
7
  Global::Manager.instance.clear
7
8
  Test::Manager.instance.clear
@@ -20,15 +21,11 @@ describe Global::Manager, 'GlobalHarness can only be defined once' do
20
21
  end
21
22
 
22
23
  describe Global::Manager, 'global before/after exception' do
24
+ include_context 'dtest'
23
25
  before do
24
26
  $call = []
25
27
  end
26
28
 
27
- after do
28
- Global::Manager.instance.clear
29
- Test::Manager.instance.clear
30
- end
31
-
32
29
  it "global_before" do
33
30
 
34
31
  GlobalHarness do
@@ -65,6 +62,7 @@ end
65
62
 
66
63
 
67
64
  describe Global::Manager, 'test before/after exception' do
65
+ include_context 'dtest'
68
66
  before do
69
67
  $call = []
70
68
  GlobalHarness do
@@ -77,11 +75,6 @@ describe Global::Manager, 'test before/after exception' do
77
75
  end
78
76
  end
79
77
 
80
- after do
81
- Global::Manager.instance.clear
82
- Test::Manager.instance.clear
83
- end
84
-
85
78
  it "testcase:beforeCase" do
86
79
  TestCase "testcase1" do
87
80
  beforeCase do
@@ -193,6 +186,7 @@ end
193
186
 
194
187
 
195
188
  describe Global::Manager, 'exception catch' do
189
+ include_context 'dtest'
196
190
  before do
197
191
  $call = []
198
192
 
@@ -3,15 +3,11 @@ include DTest
3
3
 
4
4
 
5
5
  describe Global::Manager, 'execpted' do
6
+ include_context 'dtest'
6
7
  before do
7
8
  $call = []
8
9
  end
9
10
 
10
- after do
11
- Global::Manager.instance.clear
12
- Test::Manager.instance.clear
13
- end
14
-
15
11
  it "test expect_true" do
16
12
  GlobalHarness do
17
13
  before do
@@ -204,6 +200,7 @@ end
204
200
 
205
201
 
206
202
  describe Global::Manager, 'expect failure count' do
203
+ include_context 'dtest'
207
204
  before do
208
205
  GlobalHarness do
209
206
  before do
@@ -214,11 +211,6 @@ describe Global::Manager, 'expect failure count' do
214
211
  end
215
212
  end
216
213
 
217
- after do
218
- Global::Manager.instance.clear
219
- Test::Manager.instance.clear
220
- end
221
-
222
214
  it "fail_before" do
223
215
  TestCase "before" do
224
216
  before do
@@ -2,12 +2,7 @@ require File.expand_path(File.join('.', 'spec_helper'), File.dirname(__FILE__))
2
2
  include DTest
3
3
 
4
4
  describe Global::Manager, 'dtest instance' do
5
- before do
6
- end
7
- after do
8
- Global::Manager.instance.clear
9
- Test::Manager.instance.clear
10
- end
5
+ include_context 'dtest'
11
6
 
12
7
  it "global context" do
13
8
  GlobalHarness do
@@ -37,7 +32,7 @@ describe Global::Manager, 'dtest instance' do
37
32
  global_report = Runner.run([])
38
33
  global_report.after_failure.failure.size.should == 1
39
34
 
40
- global_report.result.size == 1
35
+ global_report.result.size.should == 1
41
36
  cresult = global_report.result.first
42
37
 
43
38
  cresult.before_failure.failure.size.should == 0
@@ -76,12 +71,12 @@ describe Global::Manager, 'dtest instance' do
76
71
 
77
72
  global_report = Runner.run([])
78
73
 
79
- global_report.result.size == 1
74
+ global_report.result.size.should == 1
80
75
  cresult = global_report.result[0]
81
76
  cresult.before_failure.failure.size.should == 0
82
77
  cresult.after_failure.failure.size.should == 0
83
78
 
84
- cresult.result.size == 1
79
+ cresult.result.size.should == 1
85
80
  cresult.passed.should == 1
86
81
  cresult.failed.should == 0
87
82
  end
@@ -112,20 +107,22 @@ describe Global::Manager, 'dtest instance' do
112
107
 
113
108
  global_report = Runner.run([])
114
109
 
115
- global_report.result.size == 1
110
+ global_report.result.size.should == 1
116
111
  cresult = global_report.result.first
117
- cresult.result.size == 2
112
+ cresult.result.size.should == 2
118
113
  result = cresult.result
119
- result[0].before_failure.failure.size == 1
120
- result[0].after_failure.failure.size == 1
121
- result[0].failure.size == 0
122
- result[1].before_failure.failure.size == 1
123
- result[1].after_failure.failure.size == 1
124
- result[1].failure.size == 1
114
+ result[0].before_failure.failure.size.should == 0
115
+ result[0].after_failure.failure.size.should == 1
116
+ result[0].failure.size.should == 0
117
+ result[1].before_failure.failure.size.should == 0
118
+ result[1].after_failure.failure.size.should == 1
119
+ result[1].failure.size.should == 1
125
120
  end
126
121
  end
127
122
 
128
123
  describe Global::Manager, 'dtest setter/getter' do
124
+ include_context 'dtest'
125
+
129
126
  before do
130
127
  GlobalHarness do
131
128
  before do
@@ -138,11 +135,6 @@ describe Global::Manager, 'dtest setter/getter' do
138
135
  end
139
136
  end
140
137
 
141
- after do
142
- Global::Manager.instance.clear
143
- Test::Manager.instance.clear
144
- end
145
-
146
138
  it "testcase_to_test" do
147
139
 
148
140
  TestCase "testcase" do
@@ -174,7 +166,7 @@ describe Global::Manager, 'dtest setter/getter' do
174
166
  global_report = Runner.run([])
175
167
  global_report.after_failure.failure.size.should == 0
176
168
 
177
- global_report.result.size == 1
169
+ global_report.result.size.should == 1
178
170
  cresult = global_report.result.first
179
171
  cresult.before_failure.failure.size.should == 0
180
172
  cresult.result.size.should == 2
@@ -185,6 +177,8 @@ end
185
177
 
186
178
 
187
179
  describe Global::Manager, 'test global' do
180
+ include_context 'dtest'
181
+
188
182
  before do
189
183
  $call = []
190
184
  GlobalHarness do
@@ -198,11 +192,6 @@ describe Global::Manager, 'test global' do
198
192
  end
199
193
  end
200
194
 
201
- after do
202
- Global::Manager.instance.clear
203
- Test::Manager.instance.clear
204
- end
205
-
206
195
  it "global before/after should be executed" do
207
196
  Runner.run([])
208
197
  $call.should == [:beforeGlobal, :afterGlobal]
metadata CHANGED
@@ -1,59 +1,46 @@
1
- --- !ruby/object:Gem::Specification
1
+ --- !ruby/object:Gem::Specification
2
2
  name: dtest
3
- version: !ruby/object:Gem::Version
4
- prerelease: false
5
- segments:
6
- - 0
7
- - 0
8
- - 4
9
- version: 0.0.4
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.5
5
+ prerelease:
10
6
  platform: ruby
11
- authors:
7
+ authors:
12
8
  - Shuzo Kashihara
13
9
  autorequire:
14
10
  bindir: bin
15
11
  cert_chain: []
16
-
17
- date: 2012-02-13 00:00:00 +09:00
18
- default_executable:
19
- dependencies:
20
- - !ruby/object:Gem::Dependency
12
+ date: 2012-02-22 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
21
15
  name: rake
22
- prerelease: false
23
- requirement: &id001 !ruby/object:Gem::Requirement
24
- requirements:
25
- - - ">="
26
- - !ruby/object:Gem::Version
27
- segments:
28
- - 0
29
- - 9
30
- - 2
16
+ requirement: &70197109479700 !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ! '>='
20
+ - !ruby/object:Gem::Version
31
21
  version: 0.9.2
32
22
  type: :development
33
- version_requirements: *id001
34
- - !ruby/object:Gem::Dependency
35
- name: rspec
36
23
  prerelease: false
37
- requirement: &id002 !ruby/object:Gem::Requirement
38
- requirements:
39
- - - ">="
40
- - !ruby/object:Gem::Version
41
- segments:
42
- - 1
43
- - 2
44
- - 3
24
+ version_requirements: *70197109479700
25
+ - !ruby/object:Gem::Dependency
26
+ name: rspec
27
+ requirement: &70197109479200 !ruby/object:Gem::Requirement
28
+ none: false
29
+ requirements:
30
+ - - ! '>='
31
+ - !ruby/object:Gem::Version
45
32
  version: 1.2.3
46
33
  type: :development
47
- version_requirements: *id002
48
- description: DTest is a testing tool to describe integrating test for distributed systems.
34
+ prerelease: false
35
+ version_requirements: *70197109479200
36
+ description: DTest is a testing tool to describe integrating test for distributed
37
+ systems.
49
38
  email: suma@sourceforge.jp
50
- executables:
39
+ executables:
51
40
  - dtest
52
41
  extensions: []
53
-
54
42
  extra_rdoc_files: []
55
-
56
- files:
43
+ files:
57
44
  - Gemfile
58
45
  - LICENSE.txt
59
46
  - README.rdoc
@@ -63,6 +50,7 @@ files:
63
50
  - dtest.gemspec
64
51
  - examples/sample.rb
65
52
  - examples/sample2.rb
53
+ - examples/shared_context_example.rb
66
54
  - lib/dtest.rb
67
55
  - lib/dtest/command.rb
68
56
  - lib/dtest/core.rb
@@ -73,6 +61,7 @@ files:
73
61
  - lib/dtest/report.rb
74
62
  - lib/dtest/result.rb
75
63
  - lib/dtest/runner.rb
64
+ - lib/dtest/shared_context.rb
76
65
  - lib/dtest/test.rb
77
66
  - lib/dtest/util.rb
78
67
  - lib/dtest/version.rb
@@ -81,48 +70,42 @@ files:
81
70
  - spec/test_assert_spec.rb
82
71
  - spec/test_command1_spec.rb
83
72
  - spec/test_command2_spec.rb
73
+ - spec/test_context_spec.rb
84
74
  - spec/test_exception_spec.rb
85
75
  - spec/test_expect_spec.rb
86
76
  - spec/test_spec.rb
87
77
  - spec/test_value_parameterized_spec.rb
88
- has_rdoc: false
89
78
  homepage: https://github.com/suma/dtest
90
79
  licenses: []
91
-
92
80
  post_install_message:
93
81
  rdoc_options: []
94
-
95
- require_paths:
82
+ require_paths:
96
83
  - lib
97
- required_ruby_version: !ruby/object:Gem::Requirement
98
- requirements:
99
- - - ">="
100
- - !ruby/object:Gem::Version
101
- segments:
102
- - 1
103
- - 8
104
- - 7
84
+ required_ruby_version: !ruby/object:Gem::Requirement
85
+ none: false
86
+ requirements:
87
+ - - ! '>='
88
+ - !ruby/object:Gem::Version
105
89
  version: 1.8.7
106
- required_rubygems_version: !ruby/object:Gem::Requirement
107
- requirements:
108
- - - ">="
109
- - !ruby/object:Gem::Version
110
- segments:
111
- - 0
112
- version: "0"
90
+ required_rubygems_version: !ruby/object:Gem::Requirement
91
+ none: false
92
+ requirements:
93
+ - - ! '>='
94
+ - !ruby/object:Gem::Version
95
+ version: '0'
113
96
  requirements: []
114
-
115
97
  rubyforge_project:
116
- rubygems_version: 1.3.6
98
+ rubygems_version: 1.8.10
117
99
  signing_key:
118
100
  specification_version: 3
119
101
  summary: DTest is a testing tool to describe integrating test for distributed systems.
120
- test_files:
102
+ test_files:
121
103
  - spec/spec_helper.rb
122
104
  - spec/test_abort_spec.rb
123
105
  - spec/test_assert_spec.rb
124
106
  - spec/test_command1_spec.rb
125
107
  - spec/test_command2_spec.rb
108
+ - spec/test_context_spec.rb
126
109
  - spec/test_exception_spec.rb
127
110
  - spec/test_expect_spec.rb
128
111
  - spec/test_spec.rb