Class: DTest::Test::Manager
- Inherits:
-
Object
- Object
- DTest::Test::Manager
- Defined in:
- lib/dtest/test.rb
Overview
class Case
Instance Attribute Summary collapse
-
#cases ⇒ Object
Returns the value of attribute cases.
Instance Method Summary collapse
- #add(name) ⇒ Object
-
#after(option = {}, &block) ⇒ Object
after test.
- #afterCase(option = {}, &block) ⇒ Object
-
#before(option = {}, &block) ⇒ Object
before test.
- #beforeCase(option = {}, &block) ⇒ Object
- #clear ⇒ Object
-
#combine(*args) ⇒ Object
return product or args for value-parameterized test.
- #flush ⇒ Object
- #include_context(name) ⇒ Object
-
#initialize ⇒ Manager
constructor
A new instance of Manager.
- #test(name, option = {}, &block) ⇒ Object
Methods included from Hook
Methods included from Singleton
Constructor Details
#initialize ⇒ Manager
Returns a new instance of Manager.
157 158 159 |
# File 'lib/dtest/test.rb', line 157 def initialize clear end |
Instance Attribute Details
#cases ⇒ Object
Returns the value of attribute cases.
155 156 157 |
# File 'lib/dtest/test.rb', line 155 def cases @cases end |
Instance Method Details
#add(name) ⇒ Object
232 233 234 235 236 237 238 |
# File 'lib/dtest/test.rb', line 232 def add(name) (@beforeCase + @afterCase + @before + @after + @test).each do |block| block.parent = name end @cases << Case.new(name, @beforeCase, @afterCase, @before, @after, @test, @contexts) flush end |
#after(option = {}, &block) ⇒ Object
after test
190 191 192 |
# File 'lib/dtest/test.rb', line 190 def after(option = {}, &block) @after << Block.new("after", option, &block) end |
#afterCase(option = {}, &block) ⇒ Object
180 181 182 |
# File 'lib/dtest/test.rb', line 180 def afterCase(option = {}, &block) @afterCase << Block.new("afterCase", option, &block) end |
#before(option = {}, &block) ⇒ Object
before test
185 186 187 |
# File 'lib/dtest/test.rb', line 185 def before(option = {}, &block) @before << Block.new("before", option, &block) end |
#beforeCase(option = {}, &block) ⇒ Object
176 177 178 |
# File 'lib/dtest/test.rb', line 176 def beforeCase(option = {}, &block) @beforeCase << Block.new("beforeCase", option, &block) end |
#clear ⇒ Object
161 162 163 164 165 |
# File 'lib/dtest/test.rb', line 161 def clear remove_instance_var flush @cases = [] end |
#combine(*args) ⇒ Object
return product or args for value-parameterized test
195 196 197 198 199 200 201 202 203 204 205 |
# File 'lib/dtest/test.rb', line 195 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 |
#flush ⇒ Object
167 168 169 170 171 172 173 174 |
# File 'lib/dtest/test.rb', line 167 def flush @beforeCase = [] @afterCase = [] @before = [] @after = [] @test = [] @contexts = [] end |
#include_context(name) ⇒ Object
207 208 209 210 211 212 213 |
# File 'lib/dtest/test.rb', line 207 def include_context(name) if DTest::SharedContext::Manager::instance.has_key?(name) @contexts << name unless @contexts.include?(name) else raise "#{name} context is not defined" end end |
#test(name, option = {}, &block) ⇒ Object
215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 |
# File 'lib/dtest/test.rb', line 215 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 |