Class: DTest::Test::Manager

Inherits:
Object
  • Object
show all
Includes:
Hook, Singleton
Defined in:
lib/dtest/test.rb

Overview

class Case

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Hook

#exec

Methods included from Singleton

#remove_instance_var

Constructor Details

#initializeManager

Returns a new instance of Manager.



137
138
139
# File 'lib/dtest/test.rb', line 137

def initialize
  clear
end

Instance Attribute Details

#casesObject

Returns the value of attribute cases.



135
136
137
# File 'lib/dtest/test.rb', line 135

def cases
  @cases
end

Instance Method Details

#add(name) ⇒ Object



203
204
205
206
207
208
209
# File 'lib/dtest/test.rb', line 203

def add(name)
  (@beforeCase + @afterCase + @before + @after + @test).each do |block|
    block.parent = name
  end
  @cases << Case.new(name, @beforeCase, @afterCase, @before, @after, @test)
  flush
end

#after(option = {}, &block) ⇒ Object

after test



169
170
171
# File 'lib/dtest/test.rb', line 169

def after(option = {}, &block)
  @after << Block.new("after", option, &block)
end

#afterCase(option = {}, &block) ⇒ Object



159
160
161
# File 'lib/dtest/test.rb', line 159

def afterCase(option = {}, &block)
  @afterCase << Block.new("afterCase", option, &block)
end

#before(option = {}, &block) ⇒ Object

before test



164
165
166
# File 'lib/dtest/test.rb', line 164

def before(option = {}, &block)
  @before << Block.new("before", option, &block)
end

#beforeCase(option = {}, &block) ⇒ Object



155
156
157
# File 'lib/dtest/test.rb', line 155

def beforeCase(option = {}, &block)
  @beforeCase << Block.new("beforeCase", option, &block)
end

#clearObject



141
142
143
144
145
# File 'lib/dtest/test.rb', line 141

def clear
  remove_instance_var
  flush
  @cases = []
end

#combine(*args) ⇒ Object

return product or args for value-parameterized test



174
175
176
177
178
179
180
181
182
183
184
# File 'lib/dtest/test.rb', line 174

def combine(*args)
  if args.all? {|x| x.is_a? Array}
    para = args.shift
    args.each do |x|
      para = para.product(x)
    end
    para.map {|x| x.flatten(1)}
  else
    raise ArgumentError, 'All arguments must be Array'
  end
end

#flushObject



147
148
149
150
151
152
153
# File 'lib/dtest/test.rb', line 147

def flush
  @beforeCase = []
  @afterCase = []
  @before = []
  @after = []
  @test = []
end

#test(name, option = {}, &block) ⇒ Object



186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
# File 'lib/dtest/test.rb', line 186

def test(name, option = {}, &block)
  if option && option[:params]
    # value-parameterized test
    params = option[:params]
    count = 0
    params.each do |param|
      test = Block.new("#{name}/#{count}", option, &block)
      test.parameter = param
      @test << test
      count += 1
    end
  else
    # normal test
    @test << Block.new(name, option, &block)
  end
end