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.
77 78 79 80 |
# File 'lib/assert/view/base.rb', line 77 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.
75 76 77 |
# File 'lib/assert/view/base.rb', line 75 def output_io @output_io end |
#runtime_result_callback ⇒ Object
Returns the value of attribute runtime_result_callback.
75 76 77 |
# File 'lib/assert/view/base.rb', line 75 def runtime_result_callback @runtime_result_callback end |
#suite ⇒ Object
Returns the value of attribute suite.
75 76 77 |
# File 'lib/assert/view/base.rb', line 75 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
67 68 69 70 71 72 73 |
# File 'lib/assert/view/base.rb', line 67 def self.template(&block) if block @template = block else @template end end |
Instance Method Details
#all_pass? ⇒ Boolean
117 118 119 |
# File 'lib/assert/view/base.rb', line 117 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
212 213 214 215 216 217 218 219 220 |
# File 'lib/assert/view/base.rb', line 212 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
158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 |
# File 'lib/assert/view/base.rb', line 158 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
191 192 193 |
# File 'lib/assert/view/base.rb', line 191 def capture_output_end_msg "--------------" end |
#capture_output_start_msg ⇒ Object
188 189 190 |
# File 'lib/assert/view/base.rb', line 188 def capture_output_start_msg "--- stdout ---" end |
#count(type) ⇒ Object
109 110 111 |
# File 'lib/assert/view/base.rb', line 109 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
146 147 148 149 150 151 152 153 154 155 |
# File 'lib/assert/view/base.rb', line 146 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.reverse. 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
96 97 98 |
# File 'lib/assert/view/base.rb', line 96 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
196 197 198 199 200 |
# File 'lib/assert/view/base.rb', line 196 def ocurring_result_types @result_types ||= [ :pass, :fail, :ignore, :skip, :error ].select { |result_sym| self.count(result_sym) > 0 } end |
#ordered_suite_contexts ⇒ Object
128 129 130 |
# File 'lib/assert/view/base.rb', line 128 def ordered_suite_contexts self.suite_contexts.sort{|a,b| a.to_s <=> b.to_s} end |
#ordered_suite_files ⇒ Object
139 140 141 |
# File 'lib/assert/view/base.rb', line 139 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
203 204 205 206 207 208 209 |
# File 'lib/assert/view/base.rb', line 203 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
89 90 91 92 |
# File 'lib/assert/view/base.rb', line 89 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
101 102 103 |
# File 'lib/assert/view/base.rb', line 101 def run_time(format='%.6f') format % self.suite.run_time end |
#runner_seed ⇒ Object
105 106 107 |
# File 'lib/assert/view/base.rb', line 105 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
183 184 185 186 |
# File 'lib/assert/view/base.rb', line 183 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
122 123 124 125 126 |
# File 'lib/assert/view/base.rb', line 122 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
133 134 135 136 137 |
# File 'lib/assert/view/base.rb', line 133 def suite_files @suite_files ||= self.suite.tests.inject([]) do |files, test| files << test.context_info.file end.uniq end |
#tests? ⇒ Boolean
113 114 115 |
# File 'lib/assert/view/base.rb', line 113 def tests? self.count(:tests) > 0 end |
#to_sentence(things) ⇒ Object
generate a comma-seperated sentence fragment given a list of things
223 224 225 226 227 228 229 |
# File 'lib/assert/view/base.rb', line 223 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
82 83 84 |
# File 'lib/assert/view/base.rb', line 82 def view self end |