Class: Lemon::TestCase
- Inherits:
-
Object
- Object
- Lemon::TestCase
- Defined in:
- lib/lemon/test_case.rb
Overview
Test Case serves as the base class for Lemon’s specialized test case classes.
Direct Known Subclasses
Defined Under Namespace
Classes: DSL
Instance Attribute Summary collapse
-
#advice ⇒ Object
readonly
Advice are labeled procedures, such as before and after advice.
-
#context ⇒ Object
readonly
The parent context in which this case resides.
-
#label ⇒ Object
readonly
Brief description of the test case.
-
#setup ⇒ Object
readonly
The setup and teardown advice.
-
#skip ⇒ Object
readonly
Skip execution of test case?.
-
#target ⇒ Object
readonly
Target component.
-
#tests ⇒ Object
readonly
List of tests and sub-contexts.
Instance Method Summary collapse
- #domain ⇒ Object
-
#domain_class ⇒ Object
Get the domain class dynamically so that each subclass of TestCase will retrieve it’s own.
-
#each(&block) ⇒ Object
Iterate over each test and subcase.
- #evaluate(&block) ⇒ Object
-
#initialize(settings = {}, &block) ⇒ TestCase
constructor
A test case
target
is a class or module. -
#run(test, &block) ⇒ Object
Run test in the context of this case.
-
#scope ⇒ Scope
Module for evaluating test case script.
-
#size ⇒ Object
Number of tests and subcases.
- #skip!(reason = true) ⇒ Object
- #skip? ⇒ Boolean
- #tags ⇒ Object
- #to_s ⇒ Object
-
#type ⇒ Object
Subclasses of TestCase can override this to describe the type of test case they define.
-
#validate_settings ⇒ Object
Subclasses can override this methof to validate settings.
Constructor Details
#initialize(settings = {}, &block) ⇒ TestCase
A test case target
is a class or module.
58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 |
# File 'lib/lemon/test_case.rb', line 58 def initialize(settings={}, &block) @context = settings[:context] @target = settings[:target] @label = settings[:label] @setup = settings[:setup] @skip = settings[:skip] @tags = settings[:tags] @advice = @context ? @context.advice.dup : TestAdvice.new @tests = [] @domain = domain_class.new(self) validate_settings evaluate(&block) end |
Instance Attribute Details
#advice ⇒ Object (readonly)
Advice are labeled procedures, such as before and after advice.
28 29 30 |
# File 'lib/lemon/test_case.rb', line 28 def advice @advice end |
#context ⇒ Object (readonly)
The parent context in which this case resides.
15 16 17 |
# File 'lib/lemon/test_case.rb', line 15 def context @context end |
#label ⇒ Object (readonly)
Brief description of the test case.
18 19 20 |
# File 'lib/lemon/test_case.rb', line 18 def label @label end |
#setup ⇒ Object (readonly)
The setup and teardown advice.
24 25 26 |
# File 'lib/lemon/test_case.rb', line 24 def setup @setup end |
#skip ⇒ Object (readonly)
Skip execution of test case?
34 35 36 |
# File 'lib/lemon/test_case.rb', line 34 def skip @skip end |
#target ⇒ Object (readonly)
Target component.
21 22 23 |
# File 'lib/lemon/test_case.rb', line 21 def target @target end |
#tests ⇒ Object (readonly)
List of tests and sub-contexts.
31 32 33 |
# File 'lib/lemon/test_case.rb', line 31 def tests @tests end |
Instance Method Details
#domain ⇒ Object
84 85 86 |
# File 'lib/lemon/test_case.rb', line 84 def domain @domain end |
#domain_class ⇒ Object
Get the domain class dynamically so that each subclass of TestCase will retrieve it’s own.
180 181 182 |
# File 'lib/lemon/test_case.rb', line 180 def domain_class self.class.const_get(:DSL) end |
#each(&block) ⇒ Object
Iterate over each test and subcase.
98 99 100 |
# File 'lib/lemon/test_case.rb', line 98 def each(&block) tests.each(&block) end |
#evaluate(&block) ⇒ Object
91 92 93 |
# File 'lib/lemon/test_case.rb', line 91 def evaluate(&block) @domain.module_eval(&block) end |
#run(test, &block) ⇒ Object
Run test in the context of this case.
151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 |
# File 'lib/lemon/test_case.rb', line 151 def run(test, &block) advice[:before].each do |matches, block| if matches.all?{ |match| test.match?(match) } scope.instance_exec(test, &block) #block.call(unit) end end block.call advice[:after].each do |matches, block| if matches.all?{ |match| test.match?(match) } scope.instance_exec(test, &block) #block.call(unit) end end end |
#scope ⇒ Scope
Module for evaluating test case script.
172 173 174 |
# File 'lib/lemon/test_case.rb', line 172 def scope @scope ||= TestScope.new(self) end |
#size ⇒ Object
Number of tests and subcases.
105 106 107 |
# File 'lib/lemon/test_case.rb', line 105 def size tests.size end |
#skip!(reason = true) ⇒ Object
134 135 136 |
# File 'lib/lemon/test_case.rb', line 134 def skip!(reason=true) @skip = reason end |
#skip? ⇒ Boolean
127 128 129 |
# File 'lib/lemon/test_case.rb', line 127 def skip? @skip end |
#tags ⇒ Object
141 142 143 |
# File 'lib/lemon/test_case.rb', line 141 def @tags end |
#to_s ⇒ Object
120 121 122 |
# File 'lib/lemon/test_case.rb', line 120 def to_s @label.to_s end |
#type ⇒ Object
Subclasses of TestCase can override this to describe the type of test case they define.
113 114 115 |
# File 'lib/lemon/test_case.rb', line 113 def type 'Test Case' end |
#validate_settings ⇒ Object
Subclasses can override this methof to validate settings. It is run just before evaluation of scope block.
80 81 |
# File 'lib/lemon/test_case.rb', line 80 def validate_settings end |