Class: Test4requirements::Requirement
- Inherits:
-
Object
- Object
- Test4requirements::Requirement
- Defined in:
- lib/test4requirements/requirement.rb
Constant Summary collapse
- OPTIONS =
Valid options for Requirement#new
[ :description, :reference, :key, #optional, but must be identic with first parameter ]
Instance Attribute Summary collapse
-
#description ⇒ Object
readonly
Description of the requirement.
-
#key ⇒ Object
readonly
Key of the requirement.
-
#log ⇒ Object
Logger.
-
#reference ⇒ Object
readonly
Reference, e.g.
-
#tests ⇒ Object
readonly
Testcases of the requirement.
Instance Method Summary collapse
-
#[](key) ⇒ Object
Returns the result of a TestCase.
-
#initialize(key, options = {}) ⇒ Requirement
constructor
Each requirement must include a key.
-
#result(key, val) ⇒ Object
Set a result for a test case.
-
#successfull? ⇒ Boolean
Test, if the requirement was successfull.
-
#test=(loc) ⇒ Object
Assign a TestCase.
-
#test_defined? ⇒ Boolean
Return false, if no test is defined.
-
#testresults ⇒ Object
Return a list of tests with test result.
- #to_s ⇒ Object
Constructor Details
#initialize(key, options = {}) ⇒ Requirement
Each requirement must include a key.
Optional values:
-
description
-
reference, e.g. ‘Customer Requirement, Version 2011-08-02, page 12’
20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 |
# File 'lib/test4requirements/requirement.rb', line 20 def initialize( key, = {} ) @key = key .keys.each{|key| raise ArgumentError, "#{self.class}.new: Option #{key} undefined" unless OPTIONS.include?(key) } raise ArgumentError, "#{self.class}.new: Key not explicit: #{key}" if [:key] and [:key] != key @description = [:description] @reference = [:reference] #TestCases. Key is TestCase name. @tests = {} end |
Instance Attribute Details
#description ⇒ Object (readonly)
Description of the requirement
38 39 40 |
# File 'lib/test4requirements/requirement.rb', line 38 def description @description end |
#key ⇒ Object (readonly)
Key of the requirement
36 37 38 |
# File 'lib/test4requirements/requirement.rb', line 36 def key @key end |
#log ⇒ Object
Logger. Defined by RequirementList#<<
42 43 44 |
# File 'lib/test4requirements/requirement.rb', line 42 def log @log end |
#reference ⇒ Object (readonly)
Reference, e.g. ‘Page 47, Requirement document 2’
40 41 42 |
# File 'lib/test4requirements/requirement.rb', line 40 def reference @reference end |
#tests ⇒ Object (readonly)
Testcases of the requirement
44 45 46 |
# File 'lib/test4requirements/requirement.rb', line 44 def tests @tests end |
Instance Method Details
#[](key) ⇒ Object
Returns the result of a TestCase.
-
nil: no test found
-
false: Not successfull
-
true: Succesfull tested
60 61 62 63 |
# File 'lib/test4requirements/requirement.rb', line 60 def [](key) return nil unless @tests[key] return @tests[key].uniq == [:ok] end |
#result(key, val) ⇒ Object
Set a result for a test case.
67 68 69 70 |
# File 'lib/test4requirements/requirement.rb', line 67 def result(key, val) @tests[key] ||= [] @tests[key] << val end |
#successfull? ⇒ Boolean
Test, if the requirement was successfull.
If there is one test without success, the requirement is not successfull solved.
-
nil: no test found or one test not executed
-
false: At least one test not successfull
-
true: Succesfull tested
87 88 89 90 91 92 93 94 95 |
# File 'lib/test4requirements/requirement.rb', line 87 def successfull?() return nil unless test_defined? success = true @tests.each{|key,result| return nil if result.empty? success = (success and (result - [:ok]).empty?) } return success end |
#test=(loc) ⇒ Object
Assign a TestCase.
49 50 51 52 |
# File 'lib/test4requirements/requirement.rb', line 49 def test=(loc) @log.info("Test #{loc} assigned to requirement #{@key}") if @log and @log.info? @tests[loc] = [] #Collects problems end |
#test_defined? ⇒ Boolean
Return false, if no test is defined. Else you get the number of tests.
76 77 78 |
# File 'lib/test4requirements/requirement.rb', line 76 def test_defined?() return @tests.empty? ? false : @tests.size end |
#testresults ⇒ Object
Return a list of tests with test result.
99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 |
# File 'lib/test4requirements/requirement.rb', line 99 def testresults() #single tests: Only key returned #~ return @tests.keys if @tests.size == 1 res_ok = [] res_fail = [] res_pend = [] res_omit = [] res_error = [] #enclear erros status @tests.each{|key, result| #Convert key (for shoulda) case key when /^test: (.*) should (.*)\. \((.*)\)/ #old: test: _Shoulda should request_2. (Test_ShouldaTest) #new: request_2 (_Shoulda/Test_ShouldaTest) key = "#{$2} (#{$1}/#{$3})" end if result.include?(:failure) res_fail << key elsif result.include?(:pend) res_pend << key elsif result.include?(:omit) res_omit << key elsif result.include?(:ok) res_ok << key else res_error << key end } res = [] res << "OK: #{res_ok.join(', ')}" unless res_ok.empty? res << "Failure: #{res_fail.join(', ')}" unless res_fail.empty? res << "Pending: #{res_pend.join(', ')}" unless res_pend.empty? res << "Omission: #{res_omit.join(', ')}" unless res_omit.empty? res << "Error: #{res_omit.join(', ')}" unless res_error.empty? res end |
#to_s ⇒ Object
139 140 141 |
# File 'lib/test4requirements/requirement.rb', line 139 def to_s() "<Requirement #{key}>" end |