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: Scope
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
-
#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.
-
#scope_class ⇒ Object
Get the scope class dynamically so that each subclass of TestCase will retrieve it’s own.
-
#size ⇒ Object
Number of tests and subcases.
- #skip!(reason = true) ⇒ Object
- #skip? ⇒ Boolean
- #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.
56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 |
# File 'lib/lemon/test_case.rb', line 56 def initialize(settings={}, &block) @context = settings[:context] @target = settings[:target] @label = settings[:label] @setup = settings[:setup] @skip = settings[:skip] @advice = @context ? @context.advice.dup : TestAdvice.new @tests = [] @scope = scope_class.new(self) validate_settings evaluate(&block) end |
Instance Attribute Details
#advice ⇒ Object (readonly)
Advice are labeled procedures, such as before and after advice.
27 28 29 |
# File 'lib/lemon/test_case.rb', line 27 def advice @advice end |
#context ⇒ Object (readonly)
The parent context in which this case resides.
14 15 16 |
# File 'lib/lemon/test_case.rb', line 14 def context @context end |
#label ⇒ Object (readonly)
Brief description of the test case.
17 18 19 |
# File 'lib/lemon/test_case.rb', line 17 def label @label end |
#setup ⇒ Object (readonly)
The setup and teardown advice.
23 24 25 |
# File 'lib/lemon/test_case.rb', line 23 def setup @setup end |
#skip ⇒ Object (readonly)
Skip execution of test case?
33 34 35 |
# File 'lib/lemon/test_case.rb', line 33 def skip @skip end |
#target ⇒ Object (readonly)
Target component.
20 21 22 |
# File 'lib/lemon/test_case.rb', line 20 def target @target end |
#tests ⇒ Object (readonly)
List of tests and sub-contexts.
30 31 32 |
# File 'lib/lemon/test_case.rb', line 30 def tests @tests end |
Instance Method Details
#each(&block) ⇒ Object
Iterate over each test and subcase.
84 85 86 |
# File 'lib/lemon/test_case.rb', line 84 def each(&block) tests.each(&block) end |
#evaluate(&block) ⇒ Object
79 80 81 |
# File 'lib/lemon/test_case.rb', line 79 def evaluate(&block) @scope.module_eval(&block) end |
#run(test, &block) ⇒ Object
Run test in the context of this case.
119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 |
# File 'lib/lemon/test_case.rb', line 119 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.
138 139 140 |
# File 'lib/lemon/test_case.rb', line 138 def scope @scope end |
#scope_class ⇒ Object
Get the scope class dynamically so that each subclass of TestCase will retrieve it’s own.
144 145 146 |
# File 'lib/lemon/test_case.rb', line 144 def scope_class self.class.const_get(:Scope) end |
#size ⇒ Object
Number of tests and subcases.
89 90 91 |
# File 'lib/lemon/test_case.rb', line 89 def size tests.size end |
#skip!(reason = true) ⇒ Object
110 111 112 |
# File 'lib/lemon/test_case.rb', line 110 def skip!(reason=true) @skip = reason end |
#skip? ⇒ Boolean
105 106 107 |
# File 'lib/lemon/test_case.rb', line 105 def skip? @skip end |
#to_s ⇒ Object
100 101 102 |
# File 'lib/lemon/test_case.rb', line 100 def to_s @label.to_s end |
#type ⇒ Object
Subclasses of TestCase can override this to describe the type of test case they define.
95 96 97 |
# File 'lib/lemon/test_case.rb', line 95 def type 'Case' end |
#validate_settings ⇒ Object
Subclasses can override this methof to validate settings. It is run just before evaluation of scope block.
75 76 |
# File 'lib/lemon/test_case.rb', line 75 def validate_settings end |