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.
92 93 94 95 |
# File 'lib/assert/view/base.rb', line 92 def initialize(output_io, suite=Assert.suite) self.output_io = output_io self.suite = suite end |
Instance Attribute Details
#output_io ⇒ Object
Returns the value of attribute output_io.
90 91 92 |
# File 'lib/assert/view/base.rb', line 90 def output_io @output_io end |
#runtime_result_callback ⇒ Object
Returns the value of attribute runtime_result_callback.
90 91 92 |
# File 'lib/assert/view/base.rb', line 90 def runtime_result_callback @runtime_result_callback end |
#suite ⇒ Object
Returns the value of attribute suite.
90 91 92 |
# File 'lib/assert/view/base.rb', line 90 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
82 83 84 85 86 87 88 |
# File 'lib/assert/view/base.rb', line 82 def self.template(&block) if block @template = block else @template end end |
Instance Method Details
#all_pass? ⇒ Boolean
132 133 134 |
# File 'lib/assert/view/base.rb', line 132 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
227 228 229 230 231 232 233 234 235 |
# File 'lib/assert/view/base.rb', line 227 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
173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 |
# File 'lib/assert/view/base.rb', line 173 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
206 207 208 |
# File 'lib/assert/view/base.rb', line 206 def capture_output_end_msg "--------------" end |
#capture_output_start_msg ⇒ Object
203 204 205 |
# File 'lib/assert/view/base.rb', line 203 def capture_output_start_msg "--- stdout ---" end |
#count(type) ⇒ Object
124 125 126 |
# File 'lib/assert/view/base.rb', line 124 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
161 162 163 164 165 166 167 168 169 170 |
# File 'lib/assert/view/base.rb', line 161 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
111 112 113 |
# File 'lib/assert/view/base.rb', line 111 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
211 212 213 214 215 |
# File 'lib/assert/view/base.rb', line 211 def ocurring_result_types @result_types ||= [ :pass, :fail, :ignore, :skip, :error ].select { |result_sym| self.count(result_sym) > 0 } end |
#ordered_suite_contexts ⇒ Object
143 144 145 |
# File 'lib/assert/view/base.rb', line 143 def ordered_suite_contexts self.suite_contexts.sort{|a,b| a.to_s <=> b.to_s} end |
#ordered_suite_files ⇒ Object
154 155 156 |
# File 'lib/assert/view/base.rb', line 154 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
218 219 220 221 222 223 224 |
# File 'lib/assert/view/base.rb', line 218 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
104 105 106 107 |
# File 'lib/assert/view/base.rb', line 104 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
116 117 118 |
# File 'lib/assert/view/base.rb', line 116 def run_time(format='%.6f') format % self.suite.run_time end |
#runner_seed ⇒ Object
120 121 122 |
# File 'lib/assert/view/base.rb', line 120 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
198 199 200 201 |
# File 'lib/assert/view/base.rb', line 198 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
137 138 139 140 141 |
# File 'lib/assert/view/base.rb', line 137 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
148 149 150 151 152 |
# File 'lib/assert/view/base.rb', line 148 def suite_files @suite_files ||= self.suite.tests.inject([]) do |files, test| files << test.context_info.file end.uniq end |
#tests? ⇒ Boolean
128 129 130 |
# File 'lib/assert/view/base.rb', line 128 def tests? self.count(:tests) > 0 end |
#to_sentence(things) ⇒ Object
generate a comma-seperated sentence fragment given a list of things
238 239 240 241 242 243 244 |
# File 'lib/assert/view/base.rb', line 238 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
97 98 99 |
# File 'lib/assert/view/base.rb', line 97 def view self end |