Class: Assert::View::Base
- Inherits:
-
Object
- Object
- Assert::View::Base
- Includes:
- Options, Renderer
- Defined in:
- lib/assert/view/base.rb
Direct Known Subclasses
Instance Attribute Summary collapse
-
#output_io ⇒ Object
Returns the value of attribute output_io.
-
#runtime_result_callback ⇒ Object
Returns the value of attribute runtime_result_callback.
-
#suite ⇒ Object
Returns the value of attribute suite.
Class Method Summary collapse
-
.template(&block) ⇒ Object
set the view’s template by passing a block, get by calling w/ no args.
Instance Method Summary collapse
- #all_pass? ⇒ Boolean
-
#all_pass_result_summary_msg ⇒ Object
generate an appropriate result summary msg for all tests passing.
-
#all_results_for(what = nil) ⇒ Object
get all the results for a klass or other.
- #capture_output_end_msg ⇒ Object
- #capture_output_start_msg ⇒ Object
- #count(type) ⇒ Object
-
#detailed_results(test = nil) ⇒ Object
get all the results that have details to show in addition, if a block is given…
-
#handle_runtime_result(result) ⇒ Object
callback used by the runner to notify the view of any new results pipes the runtime result to any result callback block.
-
#initialize(output_io, suite = Assert.suite) ⇒ Base
constructor
A new instance of Base.
-
#ocurring_result_types ⇒ Object
return a list of result symbols that have actually occurred.
- #ordered_suite_contexts ⇒ Object
- #ordered_suite_files ⇒ Object
-
#result_summary_msg(result_type) ⇒ Object
print a result summary message for a given result type.
-
#run_tests(runner_callback, &result_callback) ⇒ Object
called by the view template store off any result_callback call the runner callback to actually run the tests.
-
#run_time(format = '%.6f') ⇒ Object
get the formatted suite run time.
- #runner_seed ⇒ Object
-
#show_result_details?(result) ⇒ Boolean
only show result details for failed or errored results show result details if a skip or passed result was issues w/ a message.
-
#suite_contexts ⇒ Object
get a uniq list of contexts for the test suite.
-
#suite_files ⇒ Object
get a uniq list of files containing contexts for the test suite.
- #tests? ⇒ Boolean
-
#to_sentence(things) ⇒ Object
generate a comma-seperated sentence fragment given a list of things.
- #view ⇒ Object
Methods included from Renderer
Constructor Details
#initialize(output_io, suite = Assert.suite) ⇒ Base
Returns a new instance of Base.
78 79 80 81 |
# File 'lib/assert/view/base.rb', line 78 def initialize(output_io, suite=Assert.suite) self.suite = suite self.output_io = output_io end |
Instance Attribute Details
#output_io ⇒ Object
Returns the value of attribute output_io.
76 77 78 |
# File 'lib/assert/view/base.rb', line 76 def output_io @output_io end |
#runtime_result_callback ⇒ Object
Returns the value of attribute runtime_result_callback.
76 77 78 |
# File 'lib/assert/view/base.rb', line 76 def runtime_result_callback @runtime_result_callback end |
#suite ⇒ Object
Returns the value of attribute suite.
76 77 78 |
# File 'lib/assert/view/base.rb', line 76 def suite @suite end |
Class Method Details
.template(&block) ⇒ Object
set the view’s template by passing a block, get by calling w/ no args
68 69 70 71 72 73 74 |
# File 'lib/assert/view/base.rb', line 68 def self.template(&block) if block @template = block else @template end end |
Instance Method Details
#all_pass? ⇒ Boolean
118 119 120 |
# File 'lib/assert/view/base.rb', line 118 def all_pass? self.count(:pass) == self.count(:results) end |
#all_pass_result_summary_msg ⇒ Object
generate an appropriate result summary msg for all tests passing
213 214 215 216 217 218 219 220 221 |
# File 'lib/assert/view/base.rb', line 213 def all_pass_result_summary_msg if self.count(:results) < 1 "uhh..." elsif self.count(:results) == 1 "pass" else "all pass" end end |
#all_results_for(what = nil) ⇒ Object
get all the results for a klass or other
159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 |
# File 'lib/assert/view/base.rb', line 159 def all_results_for(what=nil) tests = if what.kind_of?(Class) && what.ancestors.include?(Assert::Context) # test results for the given context self.suite.ordered_tests.select do |test| test.context_info.klass == what end elsif what.kind_of?(String) # test results for the given test file self.suite.ordered_tests.select do |test| test.context_info.file == what end else selt.suite.ordered_tests end result_index = 0 tests.collect do |test| result_index += 1 test.results. each {|r| yield r, result_index, test, test.output if block_given?} end.compact.flatten end |
#capture_output_end_msg ⇒ Object
192 193 194 |
# File 'lib/assert/view/base.rb', line 192 def capture_output_end_msg "--------------" end |
#capture_output_start_msg ⇒ Object
189 190 191 |
# File 'lib/assert/view/base.rb', line 189 def capture_output_start_msg "--- stdout ---" end |
#count(type) ⇒ Object
110 111 112 |
# File 'lib/assert/view/base.rb', line 110 def count(type) self.suite.count(type) end |
#detailed_results(test = nil) ⇒ Object
get all the results that have details to show in addition, if a block is given… yield each result with its index, test, and any captured output
147 148 149 150 151 152 153 154 155 156 |
# File 'lib/assert/view/base.rb', line 147 def detailed_results(test=nil) tests = test.nil? ? self.suite.ordered_tests.reverse : [test] result_index = 0 tests.collect do |test| result_index += 1 test.results. select { |result| self.show_result_details?(result) }. each {|r| yield r, result_index, test, test.output if block_given?} end.compact.flatten end |
#handle_runtime_result(result) ⇒ Object
callback used by the runner to notify the view of any new results pipes the runtime result to any result callback block
97 98 99 |
# File 'lib/assert/view/base.rb', line 97 def handle_runtime_result(result) self.runtime_result_callback.call(result) if self.runtime_result_callback end |
#ocurring_result_types ⇒ Object
return a list of result symbols that have actually occurred
197 198 199 200 201 |
# File 'lib/assert/view/base.rb', line 197 def ocurring_result_types @result_types ||= [ :pass, :fail, :ignore, :skip, :error ].select { |result_sym| self.count(result_sym) > 0 } end |
#ordered_suite_contexts ⇒ Object
129 130 131 |
# File 'lib/assert/view/base.rb', line 129 def ordered_suite_contexts self.suite_contexts.sort{|a,b| a.to_s <=> b.to_s} end |
#ordered_suite_files ⇒ Object
140 141 142 |
# File 'lib/assert/view/base.rb', line 140 def ordered_suite_files self.suite_files.sort{|a,b| a.to_s <=> b.to_s} end |
#result_summary_msg(result_type) ⇒ Object
print a result summary message for a given result type
204 205 206 207 208 209 210 |
# File 'lib/assert/view/base.rb', line 204 def result_summary_msg(result_type) if result_type == :pass && self.all_pass? self.all_pass_result_summary_msg else "#{self.count(result_type)} #{result_type.to_s}" end end |
#run_tests(runner_callback, &result_callback) ⇒ Object
called by the view template store off any result_callback call the runner callback to actually run the tests
90 91 92 93 |
# File 'lib/assert/view/base.rb', line 90 def run_tests(runner_callback, &result_callback) self.runtime_result_callback = result_callback runner_callback.call if runner_callback end |
#run_time(format = '%.6f') ⇒ Object
get the formatted suite run time
102 103 104 |
# File 'lib/assert/view/base.rb', line 102 def run_time(format='%.6f') format % self.suite.run_time end |
#runner_seed ⇒ Object
106 107 108 |
# File 'lib/assert/view/base.rb', line 106 def runner_seed self.suite.runner_seed end |
#show_result_details?(result) ⇒ Boolean
only show result details for failed or errored results show result details if a skip or passed result was issues w/ a message
184 185 186 187 |
# File 'lib/assert/view/base.rb', line 184 def show_result_details?(result) ([:fail, :error].include?(result.to_sym)) || ([:skip, :ignore].include?(result.to_sym) && result.) end |
#suite_contexts ⇒ Object
get a uniq list of contexts for the test suite
123 124 125 126 127 |
# File 'lib/assert/view/base.rb', line 123 def suite_contexts @suite_contexts ||= self.suite.tests.inject([]) do |contexts, test| contexts << test.context_info.klass end.uniq end |
#suite_files ⇒ Object
get a uniq list of files containing contexts for the test suite
134 135 136 137 138 |
# File 'lib/assert/view/base.rb', line 134 def suite_files @suite_files ||= self.suite.tests.inject([]) do |files, test| files << test.context_info.file end.uniq end |
#tests? ⇒ Boolean
114 115 116 |
# File 'lib/assert/view/base.rb', line 114 def tests? self.count(:tests) > 0 end |
#to_sentence(things) ⇒ Object
generate a comma-seperated sentence fragment given a list of things
224 225 226 227 228 229 230 |
# File 'lib/assert/view/base.rb', line 224 def to_sentence(things) if things.size <= 2 things.join(things.size == 2 ? ' and ' : '') else [things[0..-2].join(", "), things.last].join(", and ") end end |
#view ⇒ Object
83 84 85 |
# File 'lib/assert/view/base.rb', line 83 def view self end |