Module: Roap::TestHelper
- Defined in:
- lib/roap_test_helper/env.rb,
lib/roap_test_helper/extension.rb,
lib/roap_test_helper/roap_test_helper.rb
Defined Under Namespace
Modules: Extension
Classes: Env, EnvManager
Constant Summary
collapse
- @@tests =
[]
Class Method Summary
collapse
Class Method Details
.on(klass, &block) ⇒ Object
11
12
13
14
15
16
17
18
19
20
21
22
23
24
|
# File 'lib/roap_test_helper/roap_test_helper.rb', line 11
def self.on klass, &block
@env = Env.new
def self.setup &block
@env.setup = block
end
def self.teardown &block
@env.teardown = block
end
EnvManager::register_env klass, @env
instance_eval &block
end
|
.setup(&block) ⇒ Object
14
15
16
|
# File 'lib/roap_test_helper/roap_test_helper.rb', line 14
def self.setup &block
@env.setup = block
end
|
.teardown(&block) ⇒ Object
17
18
19
|
# File 'lib/roap_test_helper/roap_test_helper.rb', line 17
def self.teardown &block
@env.teardown = block
end
|
.test_all(*options) ⇒ Object
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
|
# File 'lib/roap_test_helper/roap_test_helper.rb', line 26
def self.test_all *options
puts "Roap::TestHelper::test_all"
if options.include? :suppress_stdout
original_stdout = $stdout
$stdout = File.open File::NULL, "w"
end
@@tests.each do |test|
EnvManager::setup :global
EnvManager::setup test[:klass]
if test[:type] == :singleton_method
method = test[:klass].singleton_method test[:method_name]
begin
result = method.call *test[:args]
rescue Exception => e
exception = e
end
elsif test[:type] == :code
begin
result = eval test[:code]
rescue Exception => e
exception = e
end
end
EnvManager::teardown test[:klass]
EnvManager::teardown :global
if exception or result != test[:should] and
exception.class != test[:should]
STDERR.puts "test faild / #{test[:klass]}::#{test[:method_name]}"
STDERR.puts " => #{result} / should #{test[:should]}"
if exception
STDERR.puts " => #{exception}"
end
if options.include? :stop_on_failure
STDERR.puts "test_all stopped by stop_on_failure option"
break
end
end
end
$stdout = original_stdout if options.include? :suppress_stdout
end
|
.tests ⇒ Object
7
8
9
|
# File 'lib/roap_test_helper/roap_test_helper.rb', line 7
def self.tests
@@tests
end
|