Class: Cornucopia::Util::ReportBuilder
- Inherits:
-
Object
- Object
- Cornucopia::Util::ReportBuilder
- Defined in:
- lib/cornucopia/util/report_builder.rb
Defined Under Namespace
Classes: TestDataHolder
Constant Summary collapse
- MAX_OLD_FOLDERS =
5
- @@current_report =
nil
- @@on_close_blocks =
[]
Class Method Summary collapse
- .build_index_section(section_name, section_items) ⇒ Object
- .build_index_section_item(path_name) ⇒ Object
- .current_report(folder_name = nil, parent_folder = nil) ⇒ Object
- .escape_string(value) ⇒ Object
- .folder_name_to_section_name(folder_name) ⇒ Object
- .format_code_refs(value) ⇒ Object
- .new_report(folder_name = nil, parent_folder = nil) ⇒ Object
- .on_close(&block) ⇒ Object
- .page_dump(page_html) ⇒ Object
- .pretty_array(array, format_sub_items = true) ⇒ Object
- .pretty_format(value, options = {}) ⇒ Object
-
.pretty_object(value, options = {}) ⇒ Object
I’ve seen some objects with pretty_inspect get stuck in an infinite loop (or close to it), so they take literally hours to print.
- .root_folder ⇒ Object
Instance Method Summary collapse
- #backup_log_files ⇒ Object
- #backup_report_folder ⇒ Object
- #body_list_item(name, path) ⇒ Object
-
#close ⇒ Object
This does nothing in a normal report because reports are built as you go.
- #delete_old_folders ⇒ Object
- #end_test(stack_object) ⇒ Object
- #image_link(image_file_name) ⇒ Object
- #index_base_page_name ⇒ Object
- #index_contents_page_name ⇒ Object
- #index_folder_name ⇒ Object
-
#initialize(folder_name = nil, parent_folder = nil) ⇒ ReportBuilder
constructor
A new instance of ReportBuilder.
- #initialize_basic_report_files ⇒ Object
- #initialize_report_files ⇒ Object
- #initialize_report_test_files ⇒ Object
- #open_report_contents_file(&block) ⇒ Object
- #open_report_test_contents_file(&block) ⇒ Object
- #padded_frame(padded_text) ⇒ Object
- #page_frame(page_html) ⇒ Object
- #page_text(page_html) ⇒ Object
- #rebuild_index_page ⇒ Object
- #rebuild_report_holder_page ⇒ Object
- #report_base_page_name ⇒ Object
- #report_contents_page_name ⇒ Object
- #report_folder_name ⇒ Object
- #report_test_base_page_name ⇒ Object
- #report_test_contents_page_name ⇒ Object
- #report_test_folder_name ⇒ Object
- #start_test(stack_object, test_name) ⇒ Object
- #test_list_item ⇒ Object
- #test_succeeded ⇒ Object
- #unique_file_name(file_base_name, base_folder = nil) ⇒ Object
- #unique_folder_name(folder_base_name, base_folder = nil) ⇒ Object
- #within_hidden_table(options = {}, &block) ⇒ Object
- #within_section(section_text, &block) ⇒ Object
- #within_table(options = {}, &block) ⇒ Object
- #within_test(test_name, &block) ⇒ Object
Constructor Details
#initialize(folder_name = nil, parent_folder = nil) ⇒ ReportBuilder
Returns a new instance of ReportBuilder.
204 205 206 207 208 209 210 211 212 213 214 215 216 |
# File 'lib/cornucopia/util/report_builder.rb', line 204 def initialize(folder_name = nil, parent_folder = nil) @parent_folder_name = parent_folder || Cornucopia::Util::Configuration.base_folder @base_folder_name = folder_name || Cornucopia::Util::Configuration.base_folder @report_title = folder_name || Cornucopia::Util::Configuration.base_folder @test_name = "unknown_test" @section_number = 0 @test_number = 0 @report_body = "".html_safe @report_folder_name = nil @index_folder_name = nil @report_test_folder_name = nil @test_list_item = nil end |
Class Method Details
.build_index_section(section_name, section_items) ⇒ Object
156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 |
# File 'lib/cornucopia/util/report_builder.rb', line 156 def build_index_section(section_name, section_items) section = "".html_safe section << "<div class=\"report-block\">".html_safe section << " <h4>".html_safe section << section_name section << "</h4>\n".html_safe section << " <ul class=\"index-list\">\n".html_safe section << Cornucopia::Util::ReportBuilder.build_index_section_item(section_items.shift) section_items.reverse.each do |section_item| section << Cornucopia::Util::ReportBuilder.build_index_section_item(section_item) end section << " </ul>\n".html_safe section << "</div>\n".html_safe section end |
.build_index_section_item(path_name) ⇒ Object
144 145 146 147 148 149 150 151 152 153 154 |
# File 'lib/cornucopia/util/report_builder.rb', line 144 def build_index_section_item(path_name) item_path = "".html_safe item_path << " <li>\n".html_safe item_path << " <a href=\"#{path_name}\" target=\"_blank\">".html_safe item_path << File.dirname(path_name) item_path << "</a>\n".html_safe item_path << " </li>\n".html_safe item_path end |
.current_report(folder_name = nil, parent_folder = nil) ⇒ Object
21 22 23 24 25 26 27 28 29 30 31 32 33 |
# File 'lib/cornucopia/util/report_builder.rb', line 21 def current_report(folder_name = nil, parent_folder = nil) if (@@current_report && ((parent_folder && @@current_report.instance_variable_get(:@parent_folder_name) != parent_folder) || (folder_name && @@current_report.instance_variable_get(:@base_folder_name) != folder_name))) @@current_report.close @@current_report = nil end folder_name ||= Cornucopia::Util::Configuration.base_folder parent_folder ||= Cornucopia::Util::Configuration.base_folder @@current_report ||= Cornucopia::Util::ReportBuilder.new(folder_name, parent_folder) end |
.escape_string(value) ⇒ Object
44 45 46 47 48 |
# File 'lib/cornucopia/util/report_builder.rb', line 44 def escape_string(value) value = value.to_s value = value + "" if value.frozen? "".html_safe + value.force_encoding("UTF-8") end |
.folder_name_to_section_name(folder_name) ⇒ Object
176 177 178 179 180 181 182 183 184 185 |
# File 'lib/cornucopia/util/report_builder.rb', line 176 def folder_name_to_section_name(folder_name) case File.basename(folder_name) when Cornucopia::Util::Configuration.base_folder "Feature Tests" when "diagnostics_rspec_report" "RSPEC Tests" else File.basename(folder_name) end end |
.format_code_refs(value) ⇒ Object
50 51 52 53 54 55 56 57 |
# File 'lib/cornucopia/util/report_builder.rb', line 50 def format_code_refs(value) safe_text = Cornucopia::Util::ReportBuilder.escape_string(value) safe_text = safe_text.gsub(/(#{Cornucopia::Util::ReportBuilder.root_folder}|\.\/|(?=(?:^features|^spec)\/))([^\:\r\n &]*(?: *\: *[0-9]+)?)/, "\\1 <span class=\"cornucopia-app-file\">\\2</span> ").html_safe safe_text end |
.new_report(folder_name = nil, parent_folder = nil) ⇒ Object
35 36 37 38 39 40 41 42 |
# File 'lib/cornucopia/util/report_builder.rb', line 35 def new_report(folder_name = nil, parent_folder = nil) if (@@current_report) @@current_report.close @@current_report = nil end @@current_report = Cornucopia::Util::ReportBuilder.new(folder_name, parent_folder) end |
.on_close(&block) ⇒ Object
199 200 201 |
# File 'lib/cornucopia/util/report_builder.rb', line 199 def on_close(&block) @@on_close_blocks << block end |
.page_dump(page_html) ⇒ Object
195 196 197 |
# File 'lib/cornucopia/util/report_builder.rb', line 195 def page_dump(page_html) "<textarea class=\"cornucopia-page-dump\">#{Cornucopia::Util::ReportBuilder.escape_string(page_html)}</textarea>\n".html_safe end |
.pretty_array(array, format_sub_items = true) ⇒ Object
59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 |
# File 'lib/cornucopia/util/report_builder.rb', line 59 def pretty_array(array, format_sub_items = true) if (array.is_a?(Array)) array.map do |value| # This is not expected to be called on an array of arrays, # block this and just convert sub-arrays to strings. format_value = value format_value = value.to_s if value.is_a?(Array) if format_sub_items Cornucopia::Util::ReportBuilder.pretty_format(format_value, in_pretty_print: true).rstrip else # "".html_safe + format_value format_value end end.join("\n").html_safe else Cornucopia::Util::ReportBuilder.pretty_format(array) end end |
.pretty_format(value, options = {}) ⇒ Object
133 134 135 136 137 138 139 140 141 142 |
# File 'lib/cornucopia/util/report_builder.rb', line 133 def pretty_format(value, = {}) pretty_text = value pretty_text = Cornucopia::Util::ReportBuilder.pretty_object(pretty_text, ) pretty_text = Cornucopia::Util::ReportBuilder.escape_string(pretty_text) pretty_text = Cornucopia::Util::PrettyFormatter.format_string(pretty_text) pretty_text = Cornucopia::Util::ReportBuilder.format_code_refs(pretty_text) pretty_text end |
.pretty_object(value, options = {}) ⇒ Object
I’ve seen some objects with pretty_inspect get stuck in an infinite loop (or close to it), so they take literally hours to print. This function uses Timeout to prevent this. either the class prints quickly, or we kill it and try something else.
If the something else doesn’t work, we just give up…
84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 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 |
# File 'lib/cornucopia/util/report_builder.rb', line 84 def pretty_object(value, = {}) timed_out = false return_value = nil begin begin timeout_length = Cornucopia::Util::Configuration.print_timeout_min if Object.const_defined?("Capybara") default_time = ::Capybara.respond_to?(:default_max_wait_time) ? ::Capybara.default_max_wait_time : ::Capybara.default_wait_time timeout_length = [timeout_length, default_time].max end if Object.const_defined?("Rails") timeout_length = [timeout_length, 30].max if Rails.env.development? end Timeout::timeout(timeout_length) do if value.is_a?(String) return_value = value elsif value.is_a?(Array) return_value = Cornucopia::Util::ReportBuilder.pretty_array(value, ![:in_pretty_print]) elsif value.respond_to?(:pretty_inspect) return_value = value.pretty_inspect else return_value = value.to_s end end rescue Timeout::Error timed_out = true end rescue Exception end # If it timed out or threw an exception, try .to_s # That may also timeout or throw an exception, and if it does, give up. if timed_out || !return_value begin Timeout::timeout(timeout_length) do return_value = value.to_s end rescue Timeout::Error return_value = "Timed out rendering" rescue => error return_value = "Rendering error => #{error.to_s}\n#{error.backtrace.join("\n")}" end end return_value end |
.root_folder ⇒ Object
187 188 189 190 191 192 193 |
# File 'lib/cornucopia/util/report_builder.rb', line 187 def root_folder if Object.const_defined?("Rails") Rails.root else FileUtils.pwd end end |
Instance Method Details
#backup_log_files ⇒ Object
682 683 684 685 686 687 688 689 690 691 692 693 |
# File 'lib/cornucopia/util/report_builder.rb', line 682 def backup_log_files log_folder = unique_folder_name "log_files", report_folder_name Cornucopia::Util::LogCapture.backup_log_files File.join(report_folder_name, log_folder) log_files = Dir[File.join(report_folder_name, log_folder, "**", "*")] log_files.each do |log_file| @report_body += body_list_item(File.basename(log_file), log_file[report_folder_name.length..-1]) end rebuild_report_holder_page end |
#backup_report_folder ⇒ Object
289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 |
# File 'lib/cornucopia/util/report_builder.rb', line 289 def backup_report_folder if Dir.exist?(@report_folder_name) if File.exist?(File.join(@report_folder_name, "index.html")) update_time = File.ctime(File.join(@report_folder_name, "index.html")) else update_time = File.ctime(@report_folder_name) end # ensure the name is unique... new_sub_dir = File.join(index_folder_name, "#{@base_folder_name}_#{update_time.strftime("%Y_%m_%d_%H_%M_%S")}").to_s index = 0 while Dir.exist?(new_sub_dir) if new_sub_dir[-1 * "_alt_#{index}".length..-1] == "_alt_#{index}" new_sub_dir = new_sub_dir[0..-1 * "_alt_#{index}".length - 1] end index += 1 new_sub_dir += "_alt_#{index}" end FileUtils.mv @report_folder_name, new_sub_dir end end |
#body_list_item(name, path) ⇒ Object
451 452 453 454 455 456 457 458 459 |
# File 'lib/cornucopia/util/report_builder.rb', line 451 def body_list_item(name, path) body_list_item = "<li>\n".html_safe body_list_item += "<a class=\"coruncopia-report-link\" href=\"#{path}\" target=\"_blank\">".html_safe body_list_item += name body_list_item += "</a>\n".html_safe body_list_item += "</li>\n".html_safe body_list_item end |
#close ⇒ Object
This does nothing in a normal report because reports are built as you go. If nothing has been reported though, this will create a report indicating that nothing happened.
221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 |
# File 'lib/cornucopia/util/report_builder.rb', line 221 def close exceptions = [] if @@on_close_blocks @@on_close_blocks.each do |on_close_block| begin on_close_block.yield rescue exceptions << $! end end end if File.exist?(report_base_page_name) if Cornucopia::Util::Configuration.backup_logs_on_failure backup_log_files end if Cornucopia::Util::Configuration.open_report_after_generation(@base_folder_name) # `open #{report_base_page_name}` rescue nil system("open #{report_base_page_name}") rescue nil end else open_report_contents_file do |write_file| write_file.write %Q[<p class=\"cornucopia-no-errors\">No Errors to report</p>] write_file.write "\n" end end if self == @@current_report @@current_report = nil end exceptions.each do |exception| raise exception end end |
#delete_old_folders ⇒ Object
314 315 316 317 318 319 320 321 322 323 324 325 |
# File 'lib/cornucopia/util/report_builder.rb', line 314 def delete_old_folders old_directories = Dir[File.join(index_folder_name, "#{@base_folder_name}_*")]. map { |dir| File.directory?(dir) ? dir : nil }.compact if Array.wrap(old_directories).length > MAX_OLD_FOLDERS old_directories.each_with_index do |dir, index| break if index >= old_directories.length - MAX_OLD_FOLDERS FileUtils.rm_rf dir end end end |
#end_test(stack_object) ⇒ Object
539 540 541 542 543 544 545 546 |
# File 'lib/cornucopia/util/report_builder.rb', line 539 def end_test(stack_object) test_data = stack_object.instance_variable_get(:@report_builder_test_start_data) @section_number = test_data[:orig_section_number] @test_name = test_data[:orig_test_name] @report_test_folder_name = test_data[:orig_test_folder] @test_list_item = test_data[:orig_test_list_item] end |
#image_link(image_file_name) ⇒ Object
621 622 623 624 625 626 627 |
# File 'lib/cornucopia/util/report_builder.rb', line 621 def image_link(image_file_name) dest_file_name = unique_file_name(File.basename(image_file_name)) FileUtils.mv image_file_name, File.join(report_test_folder_name, dest_file_name) "<img class=\"cornucopia-section-image\" src=\"./#{dest_file_name}\" />".html_safe end |
#index_base_page_name ⇒ Object
410 411 412 |
# File 'lib/cornucopia/util/report_builder.rb', line 410 def index_base_page_name File.join(index_folder_name, "index.html") end |
#index_contents_page_name ⇒ Object
414 415 416 |
# File 'lib/cornucopia/util/report_builder.rb', line 414 def index_contents_page_name File.join(index_folder_name, "report_contents.html") end |
#index_folder_name ⇒ Object
279 280 281 282 283 284 285 286 287 |
# File 'lib/cornucopia/util/report_builder.rb', line 279 def index_folder_name unless @index_folder_name @index_folder_name = File.join(Cornucopia::Util::ReportBuilder.root_folder, "#{@parent_folder_name}/") FileUtils.mkdir_p @index_folder_name end @index_folder_name end |
#initialize_basic_report_files ⇒ Object
433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 |
# File 'lib/cornucopia/util/report_builder.rb', line 433 def initialize_basic_report_files support_folder_name = report_folder_name FileUtils.mkdir_p @report_folder_name unless File.exist?(report_base_page_name) # use a different base index file. FileAsset.asset("report_base.html").add_file(File.join(support_folder_name, "index.html")) rebuild_index_page end FileAsset.asset("report_contents.html").add_file(File.join(support_folder_name, "report_contents.html")) FileAsset.asset("collapse.gif").add_file(File.join(support_folder_name, "collapse.gif")) FileAsset.asset("expand.gif").add_file(File.join(support_folder_name, "expand.gif")) FileAsset.asset("more_info.js").add_file(File.join(support_folder_name, "more_info.js")) FileAsset.asset("cornucopia.css").add_file(File.join(support_folder_name, "cornucopia.css")) end |
#initialize_report_files ⇒ Object
418 419 420 421 422 423 424 425 426 427 428 429 430 431 |
# File 'lib/cornucopia/util/report_builder.rb', line 418 def initialize_report_files support_folder_name = report_folder_name FileUtils.mkdir_p @report_folder_name unless File.exist?(report_base_page_name) # use a different base index file. FileAsset.asset("report_holder.html").add_file(File.join(support_folder_name, "index.html")) rebuild_index_page end FileAsset.asset("report.js").add_file(File.join(support_folder_name, "report.js")) FileAsset.asset("cornucopia.css").add_file(File.join(support_folder_name, "cornucopia.css")) end |
#initialize_report_test_files ⇒ Object
473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 |
# File 'lib/cornucopia/util/report_builder.rb', line 473 def initialize_report_test_files @report_body += test_list_item.to_s support_folder_name = report_test_folder_name FileUtils.mkdir_p @report_test_folder_name unless File.exist?(report_test_base_page_name) FileAsset.asset("report_base.html").add_file(File.join(support_folder_name, "index.html")) rebuild_report_holder_page end FileAsset.asset("report_contents.html").add_file(File.join(support_folder_name, "report_contents.html")) FileAsset.asset("collapse.gif").add_file(File.join(support_folder_name, "collapse.gif")) FileAsset.asset("expand.gif").add_file(File.join(support_folder_name, "expand.gif")) FileAsset.asset("more_info.js").add_file(File.join(support_folder_name, "more_info.js")) FileAsset.asset("cornucopia.css").add_file(File.join(support_folder_name, "cornucopia.css")) end |
#open_report_contents_file(&block) ⇒ Object
492 493 494 495 496 |
# File 'lib/cornucopia/util/report_builder.rb', line 492 def open_report_contents_file(&block) initialize_basic_report_files File.open(report_contents_page_name, "a:UTF-8", &block) end |
#open_report_test_contents_file(&block) ⇒ Object
498 499 500 501 502 |
# File 'lib/cornucopia/util/report_builder.rb', line 498 def open_report_test_contents_file(&block) initialize_report_test_files File.open(report_test_contents_page_name, "a:UTF-8", &block) end |
#padded_frame(padded_text) ⇒ Object
645 646 647 648 649 |
# File 'lib/cornucopia/util/report_builder.rb', line 645 def padded_frame(padded_text) padded_val = "<div class=\"padded-frame\">".html_safe padded_val << padded_text padded_val << "</div>".html_safe end |
#page_frame(page_html) ⇒ Object
633 634 635 636 637 638 639 640 641 642 643 |
# File 'lib/cornucopia/util/report_builder.rb', line 633 def page_frame(page_html) dump_file_name = unique_file_name("page_dump.html") File.open(File.join(report_test_folder_name, dump_file_name), "w:UTF-8") do |dump_file| page_text = page_html.to_s page_text = page_text + "" if page_text.frozen? dump_file.write page_text.force_encoding("UTF-8") end padded_frame("<iframe src=\"#{dump_file_name}\" class=\"cornucopia-sample-frame\" sandbox></iframe>\n".html_safe) end |
#page_text(page_html) ⇒ Object
629 630 631 |
# File 'lib/cornucopia/util/report_builder.rb', line 629 def page_text(page_html) padded_frame("<textarea class=\"cornucopia-page-dump\">#{Cornucopia::Util::ReportBuilder.escape_string(page_html)}</textarea>\n".html_safe) end |
#rebuild_index_page ⇒ Object
327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 |
# File 'lib/cornucopia/util/report_builder.rb', line 327 def rebuild_index_page index_folder = index_folder_name FileUtils.mkdir_p index_folder_name FileUtils.rm_rf index_contents_page_name FileAsset.asset("index_base.html").create_file(File.join(index_folder, "index.html")) FileAsset.asset("index_contents.html").add_file(File.join(index_folder, "report_contents.html")) FileAsset.asset("cornucopia.css").add_file(File.join(index_folder, "cornucopia.css")) index_file = "".html_safe if File.exist?(File.join(Cornucopia::Util::ReportBuilder.root_folder, "coverage/index.html")) index_file << Cornucopia::Util::ReportBuilder.build_index_section("Coverage", ["../coverage/index.html"]) end last_folder = nil group_items = [] Dir[File.join(@index_folder_name, "*")].sort.each do |directory_item| if File.directory?(directory_item) && File.exist?(File.join(directory_item, "index.html")) directory_item = directory_item[@index_folder_name.to_s.length..-1] if last_folder if directory_item =~ /^#{last_folder}_/ group_items << File.join(directory_item, "index.html") else unless group_items.empty? index_file << Cornucopia::Util::ReportBuilder.build_index_section( Cornucopia::Util::ReportBuilder.folder_name_to_section_name(last_folder), group_items) end last_folder = directory_item group_items = [File.join(last_folder, "index.html")] end else last_folder = directory_item group_items = [File.join(last_folder, "index.html")] end end end unless group_items.empty? index_file << Cornucopia::Util::ReportBuilder.build_index_section( Cornucopia::Util::ReportBuilder.folder_name_to_section_name(last_folder), group_items) end File.open(index_contents_page_name, "a:UTF-8") do |write_file| write_file << index_file end end |
#rebuild_report_holder_page ⇒ Object
377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 |
# File 'lib/cornucopia/util/report_builder.rb', line 377 def rebuild_report_holder_page initialize_report_files report_folder = report_folder_name FileUtils.mkdir_p report_folder_name FileUtils.rm_rf report_base_page_name report_holder_body = FileAsset.asset("report_holder.html").body FileAsset.asset("report.js").add_file(File.join(report_folder, "report.js")) FileAsset.asset("cornucopia.css").add_file(File.join(report_folder, "cornucopia.css")) File.open(File.join(report_folder, "index.html"), "w+") do |write_file| write_file << report_holder_body % { report_list: @report_body, report_title: @report_title } end end |
#report_base_page_name ⇒ Object
394 395 396 |
# File 'lib/cornucopia/util/report_builder.rb', line 394 def report_base_page_name File.join(report_folder_name, "index.html") end |
#report_contents_page_name ⇒ Object
398 399 400 |
# File 'lib/cornucopia/util/report_builder.rb', line 398 def report_contents_page_name File.join(report_folder_name, "report_contents.html") end |
#report_folder_name ⇒ Object
259 260 261 262 263 264 265 266 267 268 |
# File 'lib/cornucopia/util/report_builder.rb', line 259 def report_folder_name unless @report_folder_name @report_folder_name = File.join(index_folder_name, "#{@base_folder_name}/") backup_report_folder delete_old_folders end @report_folder_name end |
#report_test_base_page_name ⇒ Object
402 403 404 |
# File 'lib/cornucopia/util/report_builder.rb', line 402 def report_test_base_page_name File.join(report_test_folder_name, "index.html") end |
#report_test_contents_page_name ⇒ Object
406 407 408 |
# File 'lib/cornucopia/util/report_builder.rb', line 406 def report_test_contents_page_name File.join(report_test_folder_name, "report_contents.html") end |
#report_test_folder_name ⇒ Object
270 271 272 273 274 275 276 277 |
# File 'lib/cornucopia/util/report_builder.rb', line 270 def report_test_folder_name unless @report_test_folder_name @test_number += 1 @report_test_folder_name = File.join(report_folder_name, "test_#{@test_number}") end @report_test_folder_name end |
#start_test(stack_object, test_name) ⇒ Object
522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 |
# File 'lib/cornucopia/util/report_builder.rb', line 522 def start_test(stack_object, test_name) test_data = { orig_test_name: @test_name, orig_test_folder: @report_test_folder_name, orig_test_list_item: @test_list_item, orig_section_number: @section_number } stack_object.instance_variable_set(:@report_builder_test_start_data, test_data) @test_name = test_name @report_test_folder_name = nil @test_list_item = nil @section_number = 0 end |
#test_list_item ⇒ Object
461 462 463 464 465 466 467 468 469 470 471 |
# File 'lib/cornucopia/util/report_builder.rb', line 461 def test_list_item if @test_list_item nil else folder_name = File.basename(report_test_folder_name) @test_list_item = body_list_item(@test_name, File.join(folder_name, "index.html")) @test_list_item end end |
#test_succeeded ⇒ Object
504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 |
# File 'lib/cornucopia/util/report_builder.rb', line 504 def test_succeeded if @report_test_folder_name FileUtils.rm_rf report_test_folder_name @report_body.gsub!(@test_list_item, "") if @report_body.blank? FileUtils.rm_rf report_base_page_name FileUtils.rm_rf File.join(report_folder_name, "report.js") FileUtils.rm_rf File.join(report_folder_name, "cornucopia.css") @report_body = "".html_safe else rebuild_report_holder_page end @test_number -= 1 end end |
#unique_file_name(file_base_name, base_folder = nil) ⇒ Object
651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 |
# File 'lib/cornucopia/util/report_builder.rb', line 651 def unique_file_name(file_base_name, base_folder = nil) file_parts = file_base_name.split(".") base_name = file_parts[0..-2].join(".") extension = file_parts[-1] base_folder ||= report_test_folder_name unique_num = 1 num_string = "" while File.exist?(File.join(base_folder, "#{base_name}#{num_string}.#{extension}")) num_string = "_#{unique_num}" unique_num += 1 end "#{base_name}#{num_string}.#{extension}" end |
#unique_folder_name(folder_base_name, base_folder = nil) ⇒ Object
668 669 670 671 672 673 674 675 676 677 678 679 680 |
# File 'lib/cornucopia/util/report_builder.rb', line 668 def unique_folder_name(folder_base_name, base_folder = nil) unique_num = 1 num_string = "" base_folder ||= report_test_folder_name while File.exist?(File.join(base_folder, "#{folder_base_name}#{num_string}")) num_string = "_#{unique_num}" unique_num += 1 end "#{folder_base_name}#{num_string}" end |
#within_hidden_table(options = {}, &block) ⇒ Object
576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 |
# File 'lib/cornucopia/util/report_builder.rb', line 576 def within_hidden_table(={}, &block) table_pre = "<div class=\"cornucopia-show-hide-section\">\n".dup table_pre << " <div class=\"cornucopia-table\">\n" table_pre << " <div class=\"cornucopia-row\">\n" table_pre << " <div class=\"cornucopia-cell-data\">\n" table_pre << " <a class =\"cornucopia-additional-details\" href=\"#\">More Details...</a>\n" table_pre << " </div>\n" table_pre << " </div>\n" table_pre << " </div>\n" table_pre << " <div class=\"cornucopia-additional-details hidden\">\n" table_pre = table_pre.html_safe table_post = " </div>\n".dup table_post << "</div>\n" table_post = table_post.html_safe within_table(table_prefix: table_pre, table_postfix: table_post, report_table: nil, nested_table: .delete(:nested_table), nested_table_label: .delete(:nested_table_label), not_a_table: table_pre, suppress_blank_table: table_pre) do |outer_report_table| block.yield outer_report_table end end |
#within_section(section_text, &block) ⇒ Object
560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 |
# File 'lib/cornucopia/util/report_builder.rb', line 560 def within_section(section_text, &block) begin open_report_test_contents_file do |write_file| write_file.write "<div class=\"cornucopia-section #{((@section_number += 1) % 2) == 1 ? "cornucopia-even" : "cornucopia-odd"}\">\n" write_file.write "<p class=\"cornucopia-section-label\">#{Cornucopia::Util::ReportBuilder.escape_string(section_text)}</p>\n". dup.force_encoding("UTF-8") end block.yield self ensure open_report_test_contents_file do |write_file| write_file.write "</div>\n" write_file.write "<div class=\"cornucopia-end-section\" />\n" end end end |
#within_table(options = {}, &block) ⇒ Object
603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 |
# File 'lib/cornucopia/util/report_builder.rb', line 603 def within_table( = {}, &block) report_table = nil = [:report_table] begin Cornucopia::Util::ReportTable.new() do |table| report_table = table block.yield(report_table) end ensure if report_table && ! open_report_test_contents_file do |write_file| write_file.write report_table.full_table.force_encoding("UTF-8") end end end end |
#within_test(test_name, &block) ⇒ Object
548 549 550 551 552 553 554 555 556 557 558 |
# File 'lib/cornucopia/util/report_builder.rb', line 548 def within_test(test_name, &block) test_data_holder = TestDataHolder.new begin start_test(test_data_holder, test_name) block.yield ensure end_test(test_data_holder) end end |