scarpe 0.2.2 → 0.4.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (378) hide show
  1. checksums.yaml +4 -4
  2. data/.rubocop.yml +7 -1
  3. data/.yardopts +1 -0
  4. data/CHANGELOG.md +52 -6
  5. data/Gemfile +2 -1
  6. data/Gemfile.lock +20 -6
  7. data/LICENSE.txt +7 -1
  8. data/README.md +100 -21
  9. data/Rakefile +68 -1
  10. data/examples/Edit_box_Styles.rb +8 -0
  11. data/examples/Kerning.rb +7 -0
  12. data/examples/animate.rb +20 -0
  13. data/examples/arrow.rb +10 -0
  14. data/examples/border.rb +11 -0
  15. data/examples/btn_tooltip.rb +7 -0
  16. data/examples/button_style_changed.rb +7 -0
  17. data/examples/button_styles_default.rb +6 -0
  18. data/examples/check.rb +2 -0
  19. data/examples/download_and_show_image.rb +3 -0
  20. data/examples/flags/finland.rb +15 -0
  21. data/examples/flags/italy.rb +11 -0
  22. data/examples/flags/mauritius.rb +14 -0
  23. data/examples/font_family.rb +17 -0
  24. data/examples/font_shorthand.rb +9 -0
  25. data/examples/gen.rb +12 -8
  26. data/examples/highlander.rb +3 -3
  27. data/examples/legacy/README.md +6 -0
  28. data/examples/legacy/not_checked/shoes-contrib/basic/shoes-notes.rb +1 -1
  29. data/examples/legacy/not_checked/shoes-manual/append.rb +10 -0
  30. data/examples/legacy/not_checked/shoes-manual/background_change.rb +12 -0
  31. data/examples/legacy/not_checked/shoes-manual/background_pattern.rb +5 -0
  32. data/examples/legacy/not_checked/shoes-manual/basic_app.rb +8 -0
  33. data/examples/legacy/not_checked/shoes-manual/border.rb +9 -0
  34. data/examples/legacy/not_checked/shoes-manual/builtins/FONTS.rb +5 -0
  35. data/examples/legacy/not_checked/shoes-manual/builtins/ask.rb +2 -0
  36. data/examples/legacy/not_checked/shoes-manual/builtins/ask_color.rb +5 -0
  37. data/examples/legacy/not_checked/shoes-manual/builtins/ask_open_file.rb +5 -0
  38. data/examples/legacy/not_checked/shoes-manual/builtins/ask_save_folder.rb +2 -0
  39. data/examples/legacy/not_checked/shoes-manual/builtins/confirm.rb +4 -0
  40. data/examples/legacy/not_checked/shoes-manual/builtins/debug.rb +2 -0
  41. data/examples/legacy/not_checked/shoes-manual/builtins/info.rb +3 -0
  42. data/examples/legacy/not_checked/shoes-manual/button.rb +9 -0
  43. data/examples/legacy/not_checked/shoes-manual/clear.rb +7 -0
  44. data/examples/legacy/not_checked/shoes-manual/custom_header.rb +13 -0
  45. data/examples/legacy/not_checked/shoes-manual/displace.rb +14 -0
  46. data/examples/legacy/not_checked/shoes-manual/edit_box.rb +8 -0
  47. data/examples/legacy/not_checked/shoes-manual/fill_pattern.rb +5 -0
  48. data/examples/legacy/not_checked/shoes-manual/fonts.rb +7 -0
  49. data/examples/legacy/not_checked/shoes-manual/gutter.rb +6 -0
  50. data/examples/legacy/not_checked/shoes-manual/image_web.rb +4 -0
  51. data/examples/legacy/not_checked/shoes-manual/keypress.rb +7 -0
  52. data/examples/legacy/not_checked/shoes-manual/list_box.rb +10 -0
  53. data/examples/legacy/not_checked/shoes-manual/motion.rb +10 -0
  54. data/examples/legacy/not_checked/shoes-manual/mouse.rb +8 -0
  55. data/examples/legacy/not_checked/shoes-manual/move.rb +14 -0
  56. data/examples/legacy/not_checked/shoes-manual/nested_ovals.rb +8 -0
  57. data/examples/legacy/not_checked/shoes-manual/oval.rb +7 -0
  58. data/examples/legacy/not_checked/shoes-manual/ovals.rb +6 -0
  59. data/examples/legacy/not_checked/shoes-manual/ovals_image.rb +8 -0
  60. data/examples/legacy/not_checked/shoes-manual/prepend.rb +7 -0
  61. data/examples/legacy/not_checked/shoes-manual/progress_bar.rb +10 -0
  62. data/examples/legacy/not_checked/shoes-manual/radio.rb +18 -0
  63. data/examples/legacy/not_checked/shoes-manual/radio_alternative_1.rb +7 -0
  64. data/examples/legacy/not_checked/shoes-manual/radio_alternative_2.rb +9 -0
  65. data/examples/legacy/not_checked/shoes-manual/rotate_rectangle.rb +6 -0
  66. data/examples/legacy/not_checked/shoes-manual/shape.rb +11 -0
  67. data/examples/legacy/not_checked/shoes-manual/static/avatar.png +0 -0
  68. data/examples/legacy/not_checked/shoes-manual/stroke.rb +5 -0
  69. data/examples/legacy/not_checked/shoes-manual/style.rb +3 -0
  70. data/examples/legacy/not_checked/shoes-manual/style_alternative_1.rb +4 -0
  71. data/examples/legacy/not_checked/shoes-manual/style_alternative_2.rb +5 -0
  72. data/examples/legacy/not_checked/shoes-manual/style_length.rb +5 -0
  73. data/examples/legacy/not_checked/shoes-manual/timer.rb +6 -0
  74. data/examples/legacy/not_checked/shoes-manual/trigger_window.rb +8 -0
  75. data/examples/legacy/not_checked/shoes-manual/window_owner.rb +8 -0
  76. data/examples/legacy/not_checked/simple/anim-shapes.rb +1 -1
  77. data/examples/legacy/not_checked/speedometer_app.rb +55 -0
  78. data/examples/legacy/working/shoes_manual/alert_button.rb +2 -0
  79. data/examples/legacy/working/shoes_manual/animate.rb +7 -0
  80. data/examples/legacy/working/shoes_manual/background_para.rb +4 -0
  81. data/examples/legacy/working/shoes_manual/button_alternative.rb +7 -0
  82. data/examples/legacy/working/shoes_manual/checkbox.rb +17 -0
  83. data/examples/legacy/working/shoes_manual/download.rb +12 -0
  84. data/examples/legacy/working/shoes_manual/edit_box.rb +6 -0
  85. data/examples/legacy/working/shoes_manual/editline.rb +7 -0
  86. data/examples/legacy/working/shoes_manual/fixed_height.rb +8 -0
  87. data/examples/legacy/working/shoes_manual/fixed_width.rb +12 -0
  88. data/examples/legacy/working/shoes_manual/image.rb +5 -0
  89. data/examples/legacy/working/shoes_manual/instance_variable_check.rb +10 -0
  90. data/examples/legacy/working/shoes_manual/message.rb +18 -0
  91. data/examples/legacy/working/shoes_manual/rectangle.rb +6 -0
  92. data/examples/legacy/working/shoes_manual/save_download.rb +12 -0
  93. data/examples/legacy/working/shoes_manual/self_check.rb +10 -0
  94. data/examples/legacy/working/shoes_manual/stack.rb +7 -0
  95. data/examples/legacy/working/shoes_manual/style_info.rb +8 -0
  96. data/examples/legacy/working/shoes_manual/utf8_support.rb +8 -0
  97. data/examples/legacy/working/shoes_manual/width.rb +4 -0
  98. data/examples/legacy/working/simple/image-icon.rb +3 -0
  99. data/examples/legacy/{not_checked → working}/simple/image.rb +1 -1
  100. data/examples/list_box_choose.rb +17 -0
  101. data/examples/local_assets/local_file_server.rb +82 -0
  102. data/examples/local_assets/multi_image.rb +5 -0
  103. data/examples/local_assets/sample.gif +0 -0
  104. data/examples/local_assets/sample.mp4 +0 -0
  105. data/examples/local_assets/small.png +0 -0
  106. data/examples/local_fonts.rb +5 -2
  107. data/examples/local_images.rb +2 -3
  108. data/examples/margin.rb +13 -0
  109. data/examples/margin_check.rb +27 -0
  110. data/examples/oval-with-kwargs.rb +3 -0
  111. data/examples/oval.rb +26 -0
  112. data/examples/para/para_text.rb +14 -0
  113. data/examples/para_font_styles.rb +17 -0
  114. data/examples/para_font_variant.rb +6 -0
  115. data/examples/para_fontweight.rb +13 -0
  116. data/examples/parse_xl_funnies.rb +3 -0
  117. data/examples/progress.rb +31 -0
  118. data/examples/radio/radio_groups.rb +2 -2
  119. data/examples/rect.rb +4 -0
  120. data/examples/rotate_shapes.rb +17 -0
  121. data/examples/scarpe_ext.rb +3 -0
  122. data/examples/shapes/star.rb +1 -3
  123. data/examples/simpler-menu.rb +21 -0
  124. data/examples/spacing.rb +1 -1
  125. data/examples/span.rb +4 -2
  126. data/exe/scarpe +2 -1
  127. data/lacci/Gemfile +2 -0
  128. data/lacci/Gemfile.lock +8 -1
  129. data/lacci/lacci.gemspec +2 -2
  130. data/lacci/lib/lacci/scarpe_cli.rb +2 -2
  131. data/lacci/lib/lacci/scarpe_core.rb +2 -1
  132. data/lacci/lib/lacci/version.rb +1 -1
  133. data/lacci/lib/scarpe/niente/app.rb +23 -0
  134. data/lacci/lib/scarpe/niente/display_service.rb +66 -0
  135. data/lacci/lib/scarpe/niente/drawable.rb +59 -0
  136. data/lacci/lib/scarpe/niente/shoes_spec.rb +93 -0
  137. data/lacci/lib/scarpe/niente.rb +32 -0
  138. data/lacci/lib/shoes/app.rb +111 -72
  139. data/lacci/lib/shoes/background.rb +2 -2
  140. data/lacci/lib/shoes/border.rb +2 -2
  141. data/lacci/lib/shoes/builtins.rb +63 -0
  142. data/lacci/lib/shoes/changelog.rb +52 -0
  143. data/lacci/lib/shoes/colors.rb +3 -1
  144. data/lacci/lib/shoes/constants.rb +41 -2
  145. data/lacci/lib/shoes/display_service.rb +80 -18
  146. data/lacci/lib/shoes/download.rb +2 -2
  147. data/lacci/lib/shoes/drawable.rb +654 -0
  148. data/lacci/lib/shoes/drawables/arc.rb +27 -0
  149. data/lacci/lib/shoes/drawables/arrow.rb +21 -0
  150. data/lacci/lib/shoes/drawables/border.rb +28 -0
  151. data/lacci/lib/shoes/drawables/button.rb +57 -0
  152. data/lacci/lib/shoes/drawables/check.rb +33 -0
  153. data/lacci/lib/shoes/drawables/document_root.rb +20 -0
  154. data/lacci/lib/shoes/{widgets → drawables}/edit_box.rb +9 -8
  155. data/lacci/lib/shoes/{widgets → drawables}/edit_line.rb +8 -7
  156. data/lacci/lib/shoes/drawables/flow.rb +20 -0
  157. data/lacci/lib/shoes/drawables/font_helper.rb +62 -0
  158. data/lacci/lib/shoes/{widgets → drawables}/image.rb +7 -7
  159. data/lacci/lib/shoes/drawables/line.rb +17 -0
  160. data/lacci/lib/shoes/drawables/link.rb +31 -0
  161. data/lacci/lib/shoes/drawables/list_box.rb +59 -0
  162. data/lacci/lib/shoes/drawables/oval.rb +48 -0
  163. data/lacci/lib/shoes/drawables/para.rb +206 -0
  164. data/lacci/lib/shoes/drawables/progress.rb +15 -0
  165. data/lacci/lib/shoes/drawables/radio.rb +35 -0
  166. data/lacci/lib/shoes/drawables/rect.rb +18 -0
  167. data/lacci/lib/shoes/{widgets → drawables}/shape.rb +8 -8
  168. data/lacci/lib/shoes/drawables/slot.rb +178 -0
  169. data/lacci/lib/shoes/drawables/stack.rb +21 -0
  170. data/lacci/lib/shoes/drawables/star.rb +28 -0
  171. data/lacci/lib/shoes/drawables/subscription_item.rb +93 -0
  172. data/lacci/lib/shoes/drawables/text_drawable.rb +122 -0
  173. data/lacci/lib/shoes/drawables/video.rb +17 -0
  174. data/lacci/lib/shoes/drawables/widget.rb +74 -0
  175. data/lacci/lib/shoes/drawables.rb +32 -0
  176. data/lacci/lib/shoes/errors.rb +38 -0
  177. data/lacci/lib/shoes/log.rb +2 -2
  178. data/lacci/lib/shoes/margin_helper.rb +79 -0
  179. data/lacci/lib/shoes/ruby_extensions.rb +15 -0
  180. data/lacci/lib/shoes-spec.rb +93 -0
  181. data/lacci/lib/shoes.rb +31 -10
  182. data/lacci/test/.gitignore +1 -0
  183. data/lacci/test/test_draw_context.rb +167 -0
  184. data/lacci/test/test_font_helper.rb +57 -0
  185. data/lacci/test/test_helper.rb +81 -0
  186. data/lacci/test/test_lacci.rb +99 -3
  187. data/lacci/test/test_margin_helper.rb +82 -0
  188. data/lacci/test/test_niente_test_infra.rb +26 -0
  189. data/lacci/test/test_oval.rb +82 -0
  190. data/lacci/test/test_parenting.rb +140 -0
  191. data/lacci/test/test_shoes_errors.rb +49 -0
  192. data/lacci/test/test_text_drawables.rb +23 -0
  193. data/lib/scarpe/assets.rb +18 -0
  194. data/lib/scarpe/cats_cradle.rb +84 -103
  195. data/lib/scarpe/errors.rb +77 -0
  196. data/lib/scarpe/shoes_spec.rb +160 -0
  197. data/lib/scarpe/version.rb +2 -2
  198. data/lib/scarpe/wv/app.rb +21 -20
  199. data/lib/scarpe/wv/arc.rb +4 -51
  200. data/lib/scarpe/wv/arrow.rb +9 -0
  201. data/lib/scarpe/wv/border.rb +9 -18
  202. data/lib/scarpe/wv/button.rb +7 -35
  203. data/lib/scarpe/wv/check.rb +3 -5
  204. data/lib/scarpe/wv/control_interface.rb +20 -30
  205. data/lib/scarpe/wv/document_root.rb +81 -4
  206. data/lib/scarpe/wv/{widget.rb → drawable.rb} +71 -82
  207. data/lib/scarpe/wv/edit_box.rb +8 -18
  208. data/lib/scarpe/wv/edit_line.rb +9 -20
  209. data/lib/scarpe/wv/flow.rb +2 -18
  210. data/lib/scarpe/wv/image.rb +7 -30
  211. data/lib/scarpe/wv/line.rb +3 -25
  212. data/lib/scarpe/wv/link.rb +6 -17
  213. data/lib/scarpe/wv/list_box.rb +6 -29
  214. data/lib/scarpe/wv/oval.rb +13 -0
  215. data/lib/scarpe/wv/para.rb +12 -30
  216. data/lib/scarpe/wv/progress.rb +19 -0
  217. data/lib/scarpe/wv/radio.rb +9 -10
  218. data/lib/scarpe/wv/rect.rb +13 -0
  219. data/lib/scarpe/wv/scarpe_extensions.rb +8 -0
  220. data/lib/scarpe/wv/shape.rb +13 -13
  221. data/lib/scarpe/wv/slot.rb +8 -25
  222. data/lib/scarpe/wv/stack.rb +2 -18
  223. data/lib/scarpe/wv/star.rb +3 -53
  224. data/lib/scarpe/wv/subscription_item.rb +38 -4
  225. data/lib/scarpe/wv/text_drawable.rb +90 -0
  226. data/lib/scarpe/wv/video.rb +15 -15
  227. data/lib/scarpe/wv/web_wrangler.rb +320 -328
  228. data/lib/scarpe/wv/webview_local_display.rb +52 -33
  229. data/lib/scarpe/wv/webview_relay_display.rb +12 -12
  230. data/lib/scarpe/wv/webview_relay_util.rb +7 -10
  231. data/lib/scarpe/wv/wv_display_worker.rb +2 -2
  232. data/lib/scarpe/wv.rb +52 -12
  233. data/lib/scarpe/wv_local.rb +1 -1
  234. data/lib/scarpe/wv_relay.rb +1 -1
  235. data/lib/scarpe.rb +1 -0
  236. data/logger/debug_web_wrangler.json +1 -1
  237. data/logger/scarpe_wv_test.json +1 -1
  238. data/scarpe-components/Gemfile +4 -1
  239. data/scarpe-components/Gemfile.lock +85 -0
  240. data/scarpe-components/README.md +2 -2
  241. data/scarpe-components/assets/bootstrap-themes/bootstrap-cerulean.css +12229 -0
  242. data/scarpe-components/assets/bootstrap-themes/bootstrap-cosmo.css +11810 -0
  243. data/scarpe-components/assets/bootstrap-themes/bootstrap-cyborg.css +12210 -0
  244. data/scarpe-components/assets/bootstrap-themes/bootstrap-darkly.css +12153 -0
  245. data/scarpe-components/assets/bootstrap-themes/bootstrap-flatly.css +12126 -0
  246. data/scarpe-components/assets/bootstrap-themes/bootstrap-icons.min.css +5 -0
  247. data/scarpe-components/assets/bootstrap-themes/bootstrap-journal.css +12099 -0
  248. data/scarpe-components/assets/bootstrap-themes/bootstrap-litera.css +12211 -0
  249. data/scarpe-components/assets/bootstrap-themes/bootstrap-lumen.css +12369 -0
  250. data/scarpe-components/assets/bootstrap-themes/bootstrap-lux.css +11928 -0
  251. data/scarpe-components/assets/bootstrap-themes/bootstrap-materia.css +13184 -0
  252. data/scarpe-components/assets/bootstrap-themes/bootstrap-minty.css +12177 -0
  253. data/scarpe-components/assets/bootstrap-themes/bootstrap-morph.css +12750 -0
  254. data/scarpe-components/assets/bootstrap-themes/bootstrap-pulse.css +11890 -0
  255. data/scarpe-components/assets/bootstrap-themes/bootstrap-quartz.css +12622 -0
  256. data/scarpe-components/assets/bootstrap-themes/bootstrap-sandstone.css +12201 -0
  257. data/scarpe-components/assets/bootstrap-themes/bootstrap-simplex.css +12186 -0
  258. data/scarpe-components/assets/bootstrap-themes/bootstrap-sketchy.css +12451 -0
  259. data/scarpe-components/assets/bootstrap-themes/bootstrap-slate.css +12492 -0
  260. data/scarpe-components/assets/bootstrap-themes/bootstrap-solar.css +12149 -0
  261. data/scarpe-components/assets/bootstrap-themes/bootstrap-spacelab.css +12266 -0
  262. data/scarpe-components/assets/bootstrap-themes/bootstrap-superhero.css +12216 -0
  263. data/scarpe-components/assets/bootstrap-themes/bootstrap-united.css +12077 -0
  264. data/scarpe-components/assets/bootstrap-themes/bootstrap-vapor.css +12549 -0
  265. data/scarpe-components/assets/bootstrap-themes/bootstrap-yeti.css +12325 -0
  266. data/scarpe-components/assets/bootstrap-themes/bootstrap-zephyr.css +12283 -0
  267. data/scarpe-components/assets/bootstrap-themes/bootstrap.bundle.min.js +7 -0
  268. data/scarpe-components/lib/scarpe/components/asset_server.rb +219 -0
  269. data/scarpe-components/lib/scarpe/components/base64.rb +23 -5
  270. data/scarpe-components/lib/scarpe/components/calzini/alert.rb +49 -0
  271. data/scarpe-components/lib/scarpe/components/calzini/art_drawables.rb +227 -0
  272. data/scarpe-components/lib/scarpe/components/calzini/border.rb +38 -0
  273. data/scarpe-components/lib/scarpe/components/calzini/button.rb +37 -0
  274. data/scarpe-components/lib/scarpe/components/calzini/misc.rb +136 -0
  275. data/scarpe-components/lib/scarpe/components/calzini/para.rb +237 -0
  276. data/scarpe-components/lib/scarpe/components/calzini/slots.rb +109 -0
  277. data/scarpe-components/lib/scarpe/components/calzini.rb +236 -0
  278. data/scarpe-components/lib/scarpe/components/errors.rb +24 -0
  279. data/scarpe-components/lib/scarpe/components/file_helpers.rb +1 -0
  280. data/scarpe-components/lib/scarpe/components/html.rb +134 -0
  281. data/scarpe-components/lib/scarpe/components/minitest_export_reporter.rb +83 -0
  282. data/scarpe-components/lib/scarpe/components/minitest_import_runnable.rb +98 -0
  283. data/scarpe-components/lib/scarpe/components/minitest_result.rb +127 -0
  284. data/scarpe-components/lib/scarpe/components/modular_logger.rb +5 -5
  285. data/scarpe-components/lib/scarpe/components/print_logger.rb +22 -3
  286. data/scarpe-components/lib/scarpe/components/process_helpers.rb +37 -0
  287. data/scarpe-components/lib/scarpe/components/promises.rb +14 -14
  288. data/scarpe-components/lib/scarpe/components/segmented_file_loader.rb +36 -17
  289. data/scarpe-components/lib/scarpe/components/string_helpers.rb +10 -0
  290. data/scarpe-components/lib/scarpe/components/tiranti.rb +167 -0
  291. data/scarpe-components/lib/scarpe/components/unit_test_helpers.rb +48 -6
  292. data/scarpe-components/lib/scarpe/components/version.rb +2 -2
  293. data/scarpe-components/test/assets/big-image.png +0 -0
  294. data/scarpe-components/test/assets/big-stylesheet.css +497 -0
  295. data/scarpe-components/test/assets/little-image.png +0 -0
  296. data/scarpe-components/test/assets/little-stylesheet.css +1 -0
  297. data/scarpe-components/test/calzini/test_calzini_alert.rb +30 -0
  298. data/scarpe-components/test/calzini/test_calzini_art_drawables.rb +105 -0
  299. data/scarpe-components/test/calzini/test_calzini_button.rb +54 -0
  300. data/scarpe-components/test/calzini/test_calzini_misc.rb +115 -0
  301. data/scarpe-components/test/calzini/test_calzini_para.rb +34 -0
  302. data/scarpe-components/test/calzini/test_calzini_slots.rb +85 -0
  303. data/scarpe-components/test/calzini/test_calzini_text_drawables.rb +106 -0
  304. data/scarpe-components/test/calzini/test_various.rb +133 -0
  305. data/scarpe-components/test/mtr_data/exception.json +1 -0
  306. data/scarpe-components/test/mtr_data/fail_with_message.json +1 -0
  307. data/scarpe-components/test/mtr_data/skipped_no_message.json +1 -0
  308. data/scarpe-components/test/mtr_data/skipped_w_msg.json +1 -0
  309. data/scarpe-components/test/mtr_data/succeed_2_asserts.json +1 -0
  310. data/scarpe-components/test/test_asset_server.rb +72 -0
  311. data/scarpe-components/test/test_components.rb +31 -2
  312. data/scarpe-components/test/test_dimensions.rb +26 -0
  313. data/scarpe-components/test/test_helper.rb +20 -1
  314. data/scarpe-components/test/test_html.rb +65 -0
  315. data/scarpe-components/test/test_minitest_result.rb +68 -0
  316. data/scarpe-components/test/test_promises.rb +5 -4
  317. data/scarpe-components/test/test_segmented_app_files.rb +10 -6
  318. data/scarpegen.rb +14 -14
  319. data/sig/scarpe.rbs +1 -1
  320. data/tasks/check_html_fixtures.rb +140 -0
  321. data/tasks/regenerate_html_fixtures.rb +104 -0
  322. data/templates/basic_class_template.erb +13 -14
  323. data/templates/class_template_with_event_bind.erb +4 -4
  324. data/templates/class_template_with_shapes.erb +8 -28
  325. data/templates/example_template.erb +1 -1
  326. data/templates/module_template.erb +4 -4
  327. data/templates/webview_template.erb +3 -2
  328. metadata +286 -80
  329. data/examples/legacy/not_checked/shoes-contrib/elements/image-icon.rb +0 -3
  330. data/lacci/lib/shoes/spacing.rb +0 -9
  331. data/lacci/lib/shoes/widget.rb +0 -218
  332. data/lacci/lib/shoes/widgets/alert.rb +0 -19
  333. data/lacci/lib/shoes/widgets/arc.rb +0 -51
  334. data/lacci/lib/shoes/widgets/button.rb +0 -35
  335. data/lacci/lib/shoes/widgets/check.rb +0 -28
  336. data/lacci/lib/shoes/widgets/document_root.rb +0 -20
  337. data/lacci/lib/shoes/widgets/flow.rb +0 -22
  338. data/lacci/lib/shoes/widgets/font.rb +0 -14
  339. data/lacci/lib/shoes/widgets/line.rb +0 -18
  340. data/lacci/lib/shoes/widgets/link.rb +0 -25
  341. data/lacci/lib/shoes/widgets/list_box.rb +0 -25
  342. data/lacci/lib/shoes/widgets/para.rb +0 -68
  343. data/lacci/lib/shoes/widgets/radio.rb +0 -35
  344. data/lacci/lib/shoes/widgets/slot.rb +0 -75
  345. data/lacci/lib/shoes/widgets/span.rb +0 -26
  346. data/lacci/lib/shoes/widgets/stack.rb +0 -24
  347. data/lacci/lib/shoes/widgets/star.rb +0 -44
  348. data/lacci/lib/shoes/widgets/subscription_item.rb +0 -60
  349. data/lacci/lib/shoes/widgets/text_widget.rb +0 -51
  350. data/lacci/lib/shoes/widgets/video.rb +0 -15
  351. data/lacci/lib/shoes/widgets.rb +0 -29
  352. data/lib/scarpe/evented_assertions.rb +0 -88
  353. data/lib/scarpe/wv/alert.rb +0 -66
  354. data/lib/scarpe/wv/background.rb +0 -27
  355. data/lib/scarpe/wv/control_interface_test.rb +0 -238
  356. data/lib/scarpe/wv/dimensions.rb +0 -22
  357. data/lib/scarpe/wv/font.rb +0 -36
  358. data/lib/scarpe/wv/html.rb +0 -108
  359. data/lib/scarpe/wv/spacing.rb +0 -41
  360. data/lib/scarpe/wv/span.rb +0 -68
  361. data/lib/scarpe/wv/text_widget.rb +0 -30
  362. /data/examples/legacy/not_checked/{expert → shoes-contrib/basic}/definr.rb +0 -0
  363. /data/examples/legacy/not_checked/{expert → shoes-contrib/basic}/funnies.rb +0 -0
  364. /data/examples/legacy/not_checked/shoes-contrib/{elements → basic}/list_box-select-class.rb +0 -0
  365. /data/examples/legacy/{not_checked → working}/shoes3-tests/editline/editline.rb +0 -0
  366. /data/examples/legacy/{not_checked/shoes-contrib/basic → working/simple}/basic-edit-box.rb +0 -0
  367. /data/examples/legacy/{not_checked/shoes-contrib/elements → working/simple}/basic-fps.rb +0 -0
  368. /data/examples/legacy/{not_checked/shoes-contrib/elements → working/simple}/border-cat.rb +0 -0
  369. /data/examples/legacy/{not_checked/shoes-contrib/elements → working/simple}/check-mate.rb +0 -0
  370. /data/examples/legacy/{not_checked/shoes-contrib/manipulation → working/simple}/clear-slot.rb +0 -0
  371. /data/examples/legacy/{not_checked/shoes-contrib/basic → working/simple}/clock.rb +0 -0
  372. /data/examples/legacy/{not_checked/shoes-contrib/basic → working/simple}/gradient-shoes.rb +0 -0
  373. /data/examples/legacy/{not_checked/shoes-contrib/basic → working/simple}/list_box-shape-report.rb +0 -0
  374. /data/examples/legacy/{not_checked/shoes-contrib/elements → working/simple}/list_box.rb +0 -0
  375. /data/examples/legacy/{not_checked/shoes-contrib/elements → working/simple}/phat-button.rb +0 -0
  376. /data/examples/legacy/{not_checked/shoes-contrib → working}/simple/simple-calc.rb +0 -0
  377. /data/examples/legacy/{not_checked/shoes-contrib/position → working/simple}/stack-width.rb +0 -0
  378. /data/examples/legacy/{not_checked/shoes-contrib/elements → working/simple}/width-introspec.rb +0 -0
@@ -0,0 +1,109 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Scarpe::Components::Calzini
4
+ def slot_element(props, &block)
5
+ HTML.render do |h|
6
+ h.div((props["html_attributes"] || {}).merge(id: html_id, style: slot_style(props))) do
7
+ h.div(style: { height: "100%", width: "100%" }, &block)
8
+ end
9
+ end
10
+ end
11
+
12
+ def flow_element(props, &block)
13
+ HTML.render do |h|
14
+ h.div((props["html_attributes"] || {}).merge(id: html_id, style: flow_style(props))) do
15
+ h.div(style: { height: "100%", width: "100%", position: "relative" }, &block)
16
+ end
17
+ end
18
+ end
19
+
20
+ def stack_element(props, &block)
21
+ HTML.render do |h|
22
+ h.div((props["html_attributes"] || {}).merge(id: html_id, style: stack_style(props))) do
23
+ h.div(style: { height: "100%", width: "100%", position: "relative" }, &block)
24
+ end
25
+ end
26
+ end
27
+
28
+ def documentroot_element(props, &block)
29
+ flow_element(props, &block)
30
+ end
31
+
32
+ private
33
+
34
+ def slot_style(props)
35
+ styles = drawable_style(props)
36
+ styles = background_style(props, styles)
37
+ styles = border_style(props, styles)
38
+
39
+ styles[:width] = dimensions_length(props["width"]) if props["width"]
40
+ styles[:height] = dimensions_length(props["height"]) if props["height"]
41
+
42
+ ## A new slot defines a new coordinate system, so absolutely-positioned children
43
+ ## are relative to it. But that's going to need a lot of testing and Shoes3 comparison.
44
+ #styles[:position] = "relative"
45
+
46
+ styles
47
+ end
48
+
49
+ def flow_style(props)
50
+ {
51
+ display: "flex",
52
+ "flex-direction": "row",
53
+ "flex-wrap": "wrap",
54
+ "align-content": "flex-start",
55
+ "justify-content": "flex-start",
56
+ "align-items": "flex-start",
57
+ }.merge(slot_style(props))
58
+ end
59
+
60
+ def stack_style(props)
61
+ {
62
+ display: "flex",
63
+ "flex-direction": "column",
64
+ "align-content": "flex-start",
65
+ "justify-content": "flex-start",
66
+ "align-items": "flex-start",
67
+ overflow: props["scroll"] ? "auto" : nil,
68
+ }.compact.merge(slot_style(props))
69
+ end
70
+
71
+ def border_style(props, styles)
72
+ bc = props["border_color"]
73
+ return styles unless bc
74
+
75
+ opts = props["options"] || {}
76
+
77
+ border_style_hash = case bc
78
+ when Range
79
+ { "border-image": "linear-gradient(45deg, #{bc.first}, #{bc.last})" }
80
+ when Array
81
+ { "border-color": "rgba(#{bc.join(", ")})" }
82
+ else
83
+ { "border-color": bc }
84
+ end
85
+ styles.merge(
86
+ "border-style": "solid",
87
+ "border-width": "#{opts["strokewidth"] || 1}px",
88
+ "border-radius": "#{opts["curve"] || 0}px",
89
+ ).merge(border_style_hash)
90
+ end
91
+
92
+ def background_style(props, styles)
93
+ bc = props["background_color"]
94
+ return styles unless bc
95
+
96
+ color = case bc
97
+ when Array
98
+ "rgba(#{bc.join(", ")})"
99
+ when Range
100
+ "linear-gradient(45deg, #{bc.first}, #{bc.last})"
101
+ when ->(value) { File.exist?(value) }
102
+ "url(data:image/png;base64,#{encode_file_to_base64(bc)})"
103
+ else
104
+ bc
105
+ end
106
+
107
+ styles.merge(background: color)
108
+ end
109
+ end
@@ -0,0 +1,236 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative "html"
4
+ require_relative "base64"
5
+ require_relative "errors"
6
+
7
+ # Require all drawable rendering code under calzini directory
8
+ Dir.glob("calzini/*.rb", base: __dir__) do |drawable|
9
+ require_relative drawable
10
+ end
11
+
12
+ # The Calzini module expects to be included by a class defining
13
+ # the following methods:
14
+ #
15
+ # * html_id - the HTML ID for the specific rendered DOM object
16
+ # * handler_js_code(event_name) - the JS handler code for this DOM object and event name
17
+ # * (optional) shoes_styles - the Shoes styles for this object, unless overridden in render()
18
+ module Scarpe::Components::Calzini
19
+ extend self
20
+
21
+ HTML = Scarpe::Components::HTML
22
+ include Scarpe::Components::Base64
23
+
24
+ SIZES = {
25
+ inscription: 10,
26
+ ins: 10,
27
+ para: 12,
28
+ caption: 14,
29
+ tagline: 18,
30
+ subtitle: 26,
31
+ title: 34,
32
+ banner: 48,
33
+ }.freeze
34
+ private_constant :SIZES
35
+
36
+ # Render the Shoes drawable of type `drawable_name` with
37
+ # the given properties to HTML and return it. If the
38
+ # drawable type takes a block (e.g. Stack or Flow) then
39
+ # the block will be properly rendered.
40
+ #
41
+ # @param drawable_name [String] the drawable name like "alert", "button" or "rect"
42
+ # @param properties [Hash] a drawable-specific hash of property names to values
43
+ # @block the block which, when called, will return the contents for drawable types with contents
44
+ # @return [String] the rendered HTML
45
+ def render(drawable_name, properties = shoes_styles, &block)
46
+ send("#{drawable_name}_element", properties, &block)
47
+ end
48
+
49
+ # Return HTML for an empty page element, to be filled with HTML
50
+ # renderings of the DOM tree.
51
+ #
52
+ # The wrapper-wvroot element is where Scarpe will fill in the
53
+ # DOM element.
54
+ #
55
+ # @return [String] the rendered HTML for the empty page object.
56
+ def empty_page_element
57
+ <<~HTML
58
+ <html>
59
+ <head id='head-wvroot'>
60
+ <style id='style-wvroot'>
61
+ /** Style resets **/
62
+ body {
63
+ font-family: arial, Helvetica, sans-serif;
64
+ margin: 0;
65
+ height: 100%;
66
+ overflow: hidden;
67
+ }
68
+ p {
69
+ margin: 0;
70
+ }
71
+ #wrapper-wvroot {
72
+ height: 100%;
73
+ width: 100%;
74
+ }
75
+ </style>
76
+ </head>
77
+ <body id='body-wvroot'>
78
+ <div id='wrapper-wvroot'></div>
79
+ </body>
80
+ </html>
81
+ HTML
82
+ end
83
+
84
+ def text_size(sz)
85
+ case sz
86
+ when Numeric
87
+ sz
88
+ when Symbol
89
+ SIZES[sz]
90
+ when String
91
+ SIZES[sz.to_sym] || sz.to_i
92
+ else
93
+ raise "Unexpected text size object: #{sz.inspect}"
94
+ end
95
+ end
96
+
97
+ def dimensions_length(value)
98
+ case value
99
+ when Integer
100
+ if value < 0
101
+ "calc(100% - #{value.abs}px)"
102
+ else
103
+ "#{value}px"
104
+ end
105
+ when Float
106
+ "#{value * 100}%"
107
+ else
108
+ value
109
+ end
110
+ end
111
+
112
+ def drawable_style(props)
113
+ styles = {}
114
+ if props["hidden"]
115
+ styles[:display] = "none"
116
+ end
117
+
118
+ # Do we need to set CSS positioning here, especially if displace is set? Position: relative maybe?
119
+ # We need some Shoes3 screenshots and HTML-based tests here...
120
+
121
+ if props["top"] || props["left"]
122
+ styles[:position] = "absolute"
123
+ end
124
+
125
+ styles[:top] = dimensions_length(props["top"]) if props["top"]
126
+ styles[:left] = dimensions_length(props["left"]) if props["left"]
127
+ styles[:width] = dimensions_length(props["width"]) if props["width"]
128
+ styles[:height] = dimensions_length(props["height"]) if props["height"]
129
+ styles[:"margin-left"] = dimensions_length(props["margin_left"]) if props["margin_left"]
130
+ styles[:"margin-right"] = dimensions_length(props["margin_right"]) if props["margin_right"]
131
+ styles[:"margin-top"] = dimensions_length(props["margin_top"]) if props["margin_top"]
132
+ styles[:"margin-bottom"] = dimensions_length(props["margin_bottom"]) if props["margin_bottom"]
133
+
134
+
135
+
136
+ styles = spacing_styles_for_attr("padding", props, styles)
137
+
138
+ styles
139
+ end
140
+
141
+ SPACING_DIRECTIONS = [:left, :right, :top, :bottom]
142
+
143
+ # We extract the appropriate margin and padding from the margin and
144
+ # padding properties. If there are no margin or padding properties,
145
+ # we fall back to props["options"] margin or padding, if it exists.
146
+ #
147
+ # Margin or padding (in either props or props["options"]) can be
148
+ # a Hash with directions as keys, or an Array of left/right/top/bottom,
149
+ # or a constant, which means all four are that constant. You can
150
+ # also specify a "margin" plus "margin-top" which is constant but
151
+ # margin-top is overridden, or similar.
152
+ #
153
+ # If any margin or padding property exists in props then we don't
154
+ # check props["options"].
155
+ def spacing_styles_for_attr(attr, props, styles, with_options: true)
156
+ spacing_styles = {}
157
+
158
+ case props[attr]
159
+ when Hash
160
+ props[attr].each do |dir, value|
161
+ spacing_styles[:"#{attr}-#{dir}"] = dimensions_length value
162
+ end
163
+ when Array
164
+ SPACING_DIRECTIONS.zip(props[attr]).to_h.compact.each do |dir, value|
165
+ spacing_styles[:"#{attr}-#{dir}"] = dimensions_length(value)
166
+ end
167
+ when String, Numeric
168
+ spacing_styles[attr.to_sym] = dimensions_length(props[attr])
169
+ end
170
+
171
+ SPACING_DIRECTIONS.each do |dir|
172
+ if props["#{attr}_#{dir}"]
173
+ spacing_styles[:"#{attr}-#{dir}"] = dimensions_length props["#{attr}_#{dir}"]
174
+ end
175
+ end
176
+
177
+ unless spacing_styles.empty?
178
+ return styles.merge(spacing_styles)
179
+ end
180
+
181
+ # We should see if there are spacing properties in props["options"],
182
+ # unless we're currently doing that.
183
+ if with_options && props["options"]
184
+ spacing_styles = spacing_styles_for_attr(attr, props["options"], {}, with_options: false)
185
+ styles.merge spacing_styles
186
+ else
187
+ # No "options" or we already checked it? Return the styles we were given.
188
+ styles
189
+ end
190
+ end
191
+
192
+ def first_color_of(*colors)
193
+ colors.compact!
194
+ colors.select! { |c| c != "" }
195
+ rgb_to_hex(colors[0])
196
+ end
197
+
198
+ # Convert an [r, g, b, a] array to an HTML hex color code
199
+ # Arrays support alpha. HTML hex does not. So premultiply.
200
+ def rgb_to_hex(color)
201
+ return nil if color.nil?
202
+ return "#000000" if color == ""
203
+
204
+ # TODO: need to figure out if it's a color name like "aquamarine"
205
+ # or a hex code or an image file to use as a pattern or what.
206
+ return color if color.is_a?(String)
207
+
208
+ r, g, b, a = *color
209
+ if r.is_a?(Float)
210
+ a ||= 1.0
211
+ r_float = r * a
212
+ g_float = g * a
213
+ b_float = b * a
214
+ else
215
+ a ||= 255
216
+ a_float = (a / 255.0)
217
+ r_float = (r.to_f / 255.0) * a_float
218
+ g_float = (g.to_f / 255.0) * a_float
219
+ b_float = (b.to_f / 255.0) * a_float
220
+ end
221
+
222
+ r_int = (r_float * 255.0).to_i.clamp(0, 255)
223
+ g_int = (g_float * 255.0).to_i.clamp(0, 255)
224
+ b_int = (b_float * 255.0).to_i.clamp(0, 255)
225
+
226
+ "#%0.2X%0.2X%0.2X" % [r_int, g_int, b_int]
227
+ end
228
+
229
+ def degrees_to_radians(degrees)
230
+ degrees * Math::PI / 180
231
+ end
232
+
233
+ def radians_to_degrees(radians)
234
+ radians * (180.0 / Math::PI)
235
+ end
236
+ end
@@ -0,0 +1,24 @@
1
+ # frozen_string_literal: true
2
+
3
+ # Also defined in scarpe_core
4
+ class Scarpe::Error < StandardError; end
5
+
6
+ # TODO: this should be under Scarpe::Errors, and also probably merged into the normal
7
+ # Scarpe errors file.
8
+ module Scarpe
9
+ class InternalError < Scarpe::Error; end
10
+
11
+ class OperationNotAllowedError < Scarpe::Error; end
12
+
13
+ class FileContentError < Scarpe::Error; end
14
+
15
+ class NoOperationError < Scarpe::Error; end
16
+
17
+ class DuplicateFileError < Scarpe::Error; end
18
+
19
+ class NoSuchFile < Scarpe::Error; end
20
+
21
+ class MustOverrideMethod < Scarpe::Error; end
22
+
23
+ class InvalidHTMLTag < Scarpe::Error; end
24
+ end
@@ -4,6 +4,7 @@ require "tempfile"
4
4
 
5
5
  # These can be used for unit tests, but also more generally.
6
6
 
7
+ module Scarpe; module Components; end; end
7
8
  module Scarpe::Components::FileHelpers
8
9
  # Create a temporary file with the given prefix and contents.
9
10
  # Execute the block of code with it in place. Make sure
@@ -0,0 +1,134 @@
1
+ # frozen_string_literal: true
2
+
3
+ class Scarpe::Components::HTML
4
+ CONTENT_TAGS = [
5
+ :div,
6
+ :p,
7
+ :button,
8
+ :ul,
9
+ :li,
10
+ :textarea,
11
+ :a,
12
+ :video,
13
+ :strong,
14
+ :style,
15
+ :progress,
16
+ :em,
17
+ :code,
18
+ :defs,
19
+ :marker,
20
+ :u,
21
+ :line,
22
+ :span,
23
+ :sub,
24
+ :sup,
25
+ :del,
26
+ :svg,
27
+ :h1,
28
+ :h2,
29
+ :h3,
30
+ :h4,
31
+ :h5,
32
+ ].freeze
33
+ VOID_TAGS = [:input, :img, :polygon, :source, :link, :path, :rect, :ellipse].freeze
34
+
35
+ TAGS = (CONTENT_TAGS + VOID_TAGS).freeze
36
+
37
+ class << self
38
+ def render(&block)
39
+ new(&block).value
40
+ end
41
+ end
42
+
43
+ def initialize(&block)
44
+ @buffer = ""
45
+ block.call(self)
46
+ end
47
+
48
+ def value
49
+ @buffer
50
+ end
51
+
52
+ def respond_to_missing?(name, include_all = false)
53
+ TAGS.include?(name) || super(name, include_all)
54
+ end
55
+
56
+ def p(*args, &block)
57
+ method_missing(:p, *args, &block)
58
+ end
59
+
60
+ def option(**attrs, &block)
61
+ tag(:option, **attrs, &block)
62
+ end
63
+
64
+ def tag(name, **attrs, &block)
65
+ if VOID_TAGS.include?(name)
66
+ raise Shoes::Errors::InvalidAttributeValueError, "void tag #{name} cannot have content" if block_given?
67
+
68
+ @buffer += "<#{name}#{render_attributes(attrs)} />"
69
+ else
70
+ @buffer += "<#{name}#{render_attributes(attrs)}>"
71
+
72
+ if block_given?
73
+ result = block.call(self)
74
+ else
75
+ result = attrs[:content]
76
+ @buffer += result if result.is_a?(String)
77
+ end
78
+ @buffer += result if result.is_a?(String)
79
+
80
+ @buffer += "</#{name}>"
81
+ end
82
+
83
+ nil
84
+ end
85
+
86
+ def select(**attrs, &block)
87
+ tag(:select, **attrs, &block)
88
+ end
89
+
90
+ def method_missing(name, *args, &block)
91
+ raise Scarpe::InvalidHTMLTag, "no method #{name} for #{self.class.name}" unless TAGS.include?(name)
92
+
93
+ if VOID_TAGS.include?(name)
94
+ raise Shoes::Errors::InvalidAttributeValueError, "void tag #{name} cannot have content" if block_given?
95
+
96
+ @buffer += "<#{name}#{render_attributes(*args)} />"
97
+ else
98
+ @buffer += "<#{name}#{render_attributes(*args)}>"
99
+
100
+ if block_given?
101
+ result = block.call(self)
102
+ else
103
+ result = args.first
104
+ @buffer += result if result.is_a?(String)
105
+ end
106
+ @buffer += result if result.is_a?(String)
107
+
108
+ @buffer += "</#{name}>"
109
+ end
110
+
111
+ nil
112
+ end
113
+
114
+ private
115
+
116
+ def render_attributes(attributes = {})
117
+ return "" if attributes.empty?
118
+
119
+ attributes[:style] = render_style(attributes[:style]) if attributes[:style]
120
+ attributes.compact!
121
+
122
+ return if attributes.empty?
123
+
124
+ result = attributes.map { |k, v| "#{k}=\"#{v}\"" }.join(" ")
125
+ " #{result}"
126
+ end
127
+
128
+ def render_style(style)
129
+ return style unless style.is_a?(Hash)
130
+ return if style.empty?
131
+
132
+ style.map { |k, v| "#{k}:#{v}" }.join(";")
133
+ end
134
+ end
@@ -0,0 +1,83 @@
1
+ # frozen_string_literal: true
2
+
3
+ # Have to require this to get DefaultReporter and the Minitest::Reporters namespace.
4
+ ENV["MINITEST_REPORTER"] = "ShoesExportReporter"
5
+ require "minitest/reporters"
6
+ require "json"
7
+ require "json/add/exception"
8
+
9
+ module Minitest
10
+ module Reporters
11
+ # To use this Scarpe component, you'll need minitest-reporters in your Gemfile,
12
+ # probably in the "test" group. You'll need to require and activate ShoesExportReporter
13
+ # to register it as Minitest's reporter:
14
+ #
15
+ # require "scarpe/components/minitest_export_reporter"
16
+ # Minitest::Reporters::ShoesExportReporter.activate!
17
+ #
18
+ # Select a destination to export JSON test results to:
19
+ #
20
+ # export SHOES_MINITEST_EXPORT_FILE=/tmp/shoes_test_export.json
21
+ #
22
+ # This class overrides the MINITEST_REPORTER environment variable when you call activate.
23
+ # If MINITEST_REPORTER isn't set then when you run via Vim, TextMate, RubyMine, etc,
24
+ # the reporter will be automatically overridden and print to console instead.
25
+ #
26
+ # Based on https://gist.github.com/davidwessman/09a13840a8a80080e3842ac3051714c7
27
+ class ShoesExportReporter < BaseReporter
28
+ class << self
29
+ attr_accessor :metadata
30
+ attr_accessor :export_file
31
+ end
32
+
33
+ def self.activate!
34
+ unless ENV["SHOES_MINITEST_EXPORT_FILE"]
35
+ raise "ShoesExportReporter is available, but no export file was specified! Set SHOES_MINITEST_EXPORT_FILE!"
36
+ end
37
+ ShoesExportReporter.export_file = File.expand_path(ENV["SHOES_MINITEST_EXPORT_FILE"])
38
+ ShoesExportReporter.metadata ||= {}
39
+
40
+ Minitest::Reporters.use!
41
+ end
42
+
43
+ def serialize_failures(failures)
44
+ failures.map do |fail|
45
+ case fail
46
+ when Minitest::UnexpectedError
47
+ ["unexpected", fail.to_json, fail.error.to_json]
48
+ when Exception
49
+ ["exception", fail.to_json]
50
+ else
51
+ raise "Not sure how to serialize failure object! #{fail.inspect}"
52
+ end
53
+ end
54
+ end
55
+
56
+ def report
57
+ super
58
+
59
+ results = tests.map do |result|
60
+ failures = serialize_failures result.failures
61
+ {
62
+ name: result.name,
63
+ klass: test_class(result),
64
+ assertions: result.assertions,
65
+ failures: failures,
66
+ time: result.time,
67
+ metadata: result.respond_to?(:metadata) ? result.metadata : {},
68
+ exporter_metadata: ShoesExportReporter.metadata,
69
+ source_location: begin
70
+ result.source_location
71
+ rescue
72
+ ["unknown", -1]
73
+ end,
74
+ }
75
+ end
76
+
77
+ out_file = ShoesExportReporter.export_file
78
+ #puts "Writing Minitest results to #{out_file.inspect}."
79
+ File.write(out_file, JSON.dump(results))
80
+ end
81
+ end
82
+ end
83
+ end
@@ -0,0 +1,98 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "minitest"
4
+ require "json"
5
+ require "json/add/exception"
6
+
7
+ module Scarpe; module Components; end; end
8
+ module Scarpe::Components::ImportRunnables
9
+ # Minitest Runnables are unusual - we expect to declare a class (like a Test) with
10
+ # a lot of methods to run. The ImportRunnable is a single Runnable. But whenever
11
+ # you tell it to import a JSON file, it will add all of the described tests to
12
+ # its runnable methods.
13
+ #
14
+ # Normally that means that your subclass tests will run up front and produce
15
+ # JSON files, then Minitest will autorun at the end and report all their
16
+ # results.
17
+ #
18
+ # It wouldn't really make sense to create these runnables during the testing
19
+ # phase, because Minitest has already decided what to run at that point.
20
+ class ImportRunnable #< Minitest::Runnable
21
+ # Import JSON from an exported Minitest run. Note that running this multiple
22
+ # times with overlapping class names may be really bad.
23
+ def self.import_json_data(data)
24
+ @imported_classes ||= {}
25
+ @imported_tests ||= {}
26
+
27
+ JSON.parse(data).each do |item|
28
+ klass = item["klass"]
29
+ meth = item["name"]
30
+ @imported_tests[klass] ||= {}
31
+ @imported_tests[klass][meth] = item
32
+ end
33
+
34
+ @imported_tests.each do |klass_name, test_method_hash|
35
+ klass = @imported_classes[klass_name]
36
+ unless klass
37
+ new_klass = Class.new(Minitest::Runnable)
38
+ @imported_classes[klass_name] = new_klass
39
+ ImportRunnable.const_set(klass_name, new_klass)
40
+ klass = new_klass
41
+
42
+ klass.define_singleton_method(:run_one_method) do |klass, method_name, reporter|
43
+ reporter.prerecord klass, method_name
44
+ imp = test_method_hash[method_name]
45
+
46
+ res = Minitest::Result.new imp["name"]
47
+ res.klass = imp["klass"]
48
+ res.assertions = imp["assertions"]
49
+ res.time = imp["time"]
50
+ res.failures = ImportRunnable.deserialize_failures imp["failures"]
51
+ res.metadata = imp["metadata"] if imp["metadata"]
52
+
53
+ # Record the synthetic result built from imported data
54
+ reporter.record res
55
+ end
56
+ end
57
+
58
+ # Update "runnables" method to reflect all current known runnable tests
59
+ klass_methods = test_method_hash.keys
60
+ klass.define_singleton_method(:runnable_methods) do
61
+ klass_methods
62
+ end
63
+ end
64
+ end
65
+
66
+ def self.json_to_err(err_json)
67
+ klass = begin
68
+ Object.const_get(err_json["json_class"])
69
+ rescue
70
+ nil
71
+ end
72
+ if klass && klass <= Minitest::Assertion
73
+ klass.json_create(err_json)
74
+ else
75
+ err = Exception.json_create(err_json)
76
+ Minitest::UnexpectedError.new(err)
77
+ end
78
+ end
79
+
80
+ def self.deserialize_failures(failures)
81
+ failures.map do |fail|
82
+ # Instantiate the Minitest::Assertion or Minitest::UnexpectedError
83
+ if fail[0] == "exception"
84
+ exc_json = JSON.parse(fail[1])
85
+ json_to_err exc_json
86
+ elsif fail[0] == "unexpected"
87
+ unexpected_json = JSON.parse(fail[1])
88
+ inner_json = JSON.parse(fail[2])
89
+ outer_err = json_to_err unexpected_json
90
+ inner_err = json_to_err inner_json
91
+ outer_err.error = inner_err
92
+ else
93
+ raise "Unknown exception data when trying to deserialize! #{fail.inspect}"
94
+ end
95
+ end
96
+ end
97
+ end
98
+ end