scarpe 0.2.1 → 0.3.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.rubocop.yml +4 -0
- data/.yardopts +12 -0
- data/CHANGELOG.md +16 -2
- data/Gemfile +3 -0
- data/Gemfile.lock +116 -0
- data/README.md +53 -30
- data/Rakefile +13 -1
- data/docs/yard/catscradle.md +44 -0
- data/docs/yard/template/default/fulldoc/html/setup.rb +13 -0
- data/docs/yard/template/default/layout/html/setup.rb +9 -0
- data/examples/animate.rb +20 -0
- data/examples/arrow.rb +10 -0
- data/examples/background_with_image.rb +16 -0
- data/examples/bloopsaphone/working/bronx_army_knife.rb +66 -0
- data/examples/bloopsaphone/working/morning_serenity.rb +21 -0
- data/examples/bloopsaphone/working/simpsons_theme_song_by_why.rb +6 -4
- data/examples/btn_tooltip.rb +7 -0
- data/examples/button_go_away.rb +1 -1
- data/examples/button_style_changed.rb +7 -0
- data/examples/button_styles_default.rb +6 -0
- data/examples/check.rb +18 -0
- data/examples/clear_and_append.rb +24 -0
- data/examples/download_and_show_image.rb +28 -0
- data/examples/edit_box.rb +3 -5
- data/examples/fonts.rb +2 -2
- data/examples/gen.rb +8 -8
- data/examples/get_headers.rb +10 -0
- data/examples/highlander.rb +4 -2
- data/examples/legacy/README.md +6 -0
- data/examples/legacy/not_checked/shoes-contrib/basic/shoes-notes.rb +1 -1
- data/examples/legacy/not_checked/simple/anim-shapes.rb +1 -1
- data/examples/legacy/not_checked/speedometer_app.rb +55 -0
- data/examples/legacy/working/simple/image-icon.rb +3 -0
- data/examples/legacy/{not_checked → working}/simple/image.rb +1 -1
- data/examples/link.rb +2 -2
- data/examples/list_box_choose.rb +17 -0
- data/examples/local_assets/local_file_server.rb +82 -0
- data/examples/local_assets/sample.gif +0 -0
- data/examples/local_assets/sample.mp4 +0 -0
- data/examples/local_fonts.rb +4 -0
- data/examples/local_images.rb +3 -0
- data/examples/motion_events.rb +20 -0
- data/examples/para/para_text.rb +14 -0
- data/examples/parse_xl_funnies.rb +58 -0
- data/examples/progress.rb +31 -0
- data/examples/radio/radio.rb +16 -0
- data/examples/radio/radio_groups.rb +18 -0
- data/examples/radio/radio_same_slot.rb +6 -0
- data/examples/rect.rb +4 -0
- data/examples/rotate_shapes.rb +17 -0
- data/examples/ruby_racer.rb +13 -15
- data/examples/selfitude.rb +18 -0
- data/examples/shapes/shapes_fill.rb +4 -3
- data/examples/shoes_school.rb +2 -4
- data/examples/show_hide.rb +6 -0
- data/examples/simpler-menu.rb +21 -0
- data/examples/skip_ci/change_my_audio_source.rb +21 -0
- data/examples/skip_ci/guitar_fretboard.rb +137 -0
- data/examples/video.rb +10 -0
- data/exe/scarpe +43 -66
- data/fonts/Pacifico.ttf +0 -0
- data/lacci/Gemfile +24 -0
- data/lacci/Gemfile.lock +79 -0
- data/lacci/Rakefile +12 -0
- data/lacci/lacci.gemspec +37 -0
- data/lacci/lib/lacci/scarpe_cli.rb +71 -0
- data/lacci/lib/lacci/scarpe_core.rb +22 -0
- data/lacci/lib/lacci/version.rb +13 -0
- data/lacci/lib/scarpe/niente/app.rb +23 -0
- data/lacci/lib/scarpe/niente/display_service.rb +62 -0
- data/lacci/lib/scarpe/niente/drawable.rb +57 -0
- data/lacci/lib/scarpe/niente/logger.rb +29 -0
- data/lacci/lib/scarpe/niente/shoes_spec.rb +87 -0
- data/lacci/lib/scarpe/niente.rb +20 -0
- data/lacci/lib/shoes/app.rb +309 -0
- data/{lib/scarpe → lacci/lib/shoes}/background.rb +2 -2
- data/{lib/scarpe → lacci/lib/shoes}/border.rb +2 -2
- data/lacci/lib/shoes/builtins.rb +63 -0
- data/lacci/lib/shoes/changelog.rb +52 -0
- data/{lib/scarpe → lacci/lib/shoes}/colors.rb +3 -1
- data/lacci/lib/shoes/constants.rb +47 -0
- data/{lib/scarpe → lacci/lib/shoes}/display_service.rb +71 -53
- data/lacci/lib/shoes/download.rb +123 -0
- data/lacci/lib/shoes/drawable.rb +380 -0
- data/lacci/lib/shoes/drawables/arc.rb +49 -0
- data/lacci/lib/shoes/drawables/arrow.rb +41 -0
- data/lacci/lib/shoes/drawables/button.rb +73 -0
- data/lacci/lib/shoes/drawables/check.rb +29 -0
- data/lacci/lib/shoes/drawables/document_root.rb +20 -0
- data/lacci/lib/shoes/drawables/edit_box.rb +29 -0
- data/{lib/scarpe → lacci/lib/shoes/drawables}/edit_line.rb +6 -6
- data/lacci/lib/shoes/drawables/flow.rb +22 -0
- data/{lib/scarpe → lacci/lib/shoes/drawables}/image.rb +7 -11
- data/lacci/lib/shoes/drawables/line.rb +20 -0
- data/lacci/lib/shoes/drawables/link.rb +34 -0
- data/lacci/lib/shoes/drawables/list_box.rb +56 -0
- data/lacci/lib/shoes/drawables/para.rb +118 -0
- data/lacci/lib/shoes/drawables/progress.rb +14 -0
- data/lacci/lib/shoes/drawables/radio.rb +33 -0
- data/lacci/lib/shoes/drawables/rect.rb +17 -0
- data/lacci/lib/shoes/drawables/shape.rb +36 -0
- data/lacci/lib/shoes/drawables/slot.rb +87 -0
- data/{lib/scarpe → lacci/lib/shoes/drawables}/span.rb +8 -7
- data/lacci/lib/shoes/drawables/stack.rb +26 -0
- data/lacci/lib/shoes/drawables/star.rb +50 -0
- data/lacci/lib/shoes/drawables/subscription_item.rb +93 -0
- data/lacci/lib/shoes/drawables/text_drawable.rb +63 -0
- data/lacci/lib/shoes/drawables/video.rb +16 -0
- data/lacci/lib/shoes/drawables/widget.rb +69 -0
- data/lacci/lib/shoes/drawables.rb +31 -0
- data/lacci/lib/shoes/errors.rb +28 -0
- data/lacci/lib/shoes/log.rb +71 -0
- data/lacci/lib/shoes/ruby_extensions.rb +15 -0
- data/lacci/lib/shoes/spacing.rb +9 -0
- data/lacci/lib/shoes-spec.rb +93 -0
- data/lacci/lib/shoes.rb +147 -0
- data/lacci/test/test_colors.rb +39 -0
- data/lacci/test/test_helper.rb +63 -0
- data/lacci/test/test_lacci.rb +18 -0
- data/lacci/test/test_shoes_errors.rb +49 -0
- data/lib/scarpe/cats_cradle.rb +271 -0
- data/lib/scarpe/errors.rb +77 -0
- data/lib/scarpe/evented_assertions.rb +121 -0
- data/lib/scarpe/shoes_spec.rb +181 -0
- data/lib/scarpe/version.rb +2 -2
- data/lib/scarpe/wv/app.rb +45 -23
- data/lib/scarpe/wv/arc.rb +4 -48
- data/lib/scarpe/wv/arrow.rb +9 -0
- data/lib/scarpe/wv/button.rb +7 -33
- data/lib/scarpe/wv/check.rb +27 -0
- data/lib/scarpe/wv/control_interface.rb +32 -40
- data/lib/scarpe/wv/document_root.rb +66 -31
- data/lib/scarpe/wv/drawable.rb +273 -0
- data/lib/scarpe/wv/edit_box.rb +4 -19
- data/lib/scarpe/wv/edit_line.rb +4 -18
- data/lib/scarpe/wv/flow.rb +2 -28
- data/lib/scarpe/wv/image.rb +10 -25
- data/lib/scarpe/wv/line.rb +3 -28
- data/lib/scarpe/wv/link.rb +3 -15
- data/lib/scarpe/wv/list_box.rb +6 -29
- data/lib/scarpe/wv/para.rb +11 -28
- data/lib/scarpe/wv/progress.rb +19 -0
- data/lib/scarpe/wv/radio.rb +33 -0
- data/lib/scarpe/wv/rect.rb +13 -0
- data/lib/scarpe/wv/shape.rb +41 -10
- data/lib/scarpe/wv/slot.rb +64 -0
- data/lib/scarpe/wv/span.rb +3 -25
- data/lib/scarpe/wv/stack.rb +2 -38
- data/lib/scarpe/wv/star.rb +3 -54
- data/lib/scarpe/wv/subscription_item.rb +84 -0
- data/lib/scarpe/wv/text_drawable.rb +32 -0
- data/lib/scarpe/wv/video.rb +34 -0
- data/lib/scarpe/wv/web_wrangler.rb +449 -299
- data/lib/scarpe/wv/webview_local_display.rb +63 -26
- data/lib/scarpe/wv/webview_relay_display.rb +24 -125
- data/lib/scarpe/wv/webview_relay_util.rb +140 -0
- data/lib/scarpe/wv/wv_display_worker.rb +19 -6
- data/lib/scarpe/wv.rb +76 -14
- data/lib/scarpe/wv_local.rb +1 -1
- data/lib/scarpe/wv_relay.rb +1 -1
- data/lib/scarpe.rb +4 -32
- data/logger/debug_web_wrangler.json +1 -1
- data/logger/scarpe_wv_test.json +1 -1
- data/scarpe-components/.gitignore +1 -0
- data/scarpe-components/Gemfile +22 -0
- data/scarpe-components/Gemfile.lock +86 -0
- data/scarpe-components/README.md +35 -0
- data/scarpe-components/Rakefile +12 -0
- data/scarpe-components/lib/scarpe/components/base64.rb +25 -0
- data/scarpe-components/lib/scarpe/components/calzini/alert.rb +49 -0
- data/scarpe-components/lib/scarpe/components/calzini/art_widgets.rb +203 -0
- data/scarpe-components/lib/scarpe/components/calzini/button.rb +39 -0
- data/scarpe-components/lib/scarpe/components/calzini/misc.rb +146 -0
- data/scarpe-components/lib/scarpe/components/calzini/para.rb +35 -0
- data/scarpe-components/lib/scarpe/components/calzini/slots.rb +155 -0
- data/scarpe-components/lib/scarpe/components/calzini/text_widgets.rb +65 -0
- data/scarpe-components/lib/scarpe/components/calzini.rb +149 -0
- data/scarpe-components/lib/scarpe/components/errors.rb +20 -0
- data/scarpe-components/lib/scarpe/components/file_helpers.rb +66 -0
- data/scarpe-components/lib/scarpe/components/html.rb +131 -0
- data/scarpe-components/lib/scarpe/components/minitest_export_reporter.rb +75 -0
- data/scarpe-components/lib/scarpe/components/minitest_import_runnable.rb +98 -0
- data/scarpe-components/lib/scarpe/components/minitest_result.rb +86 -0
- data/scarpe-components/lib/scarpe/components/modular_logger.rb +113 -0
- data/scarpe-components/lib/scarpe/components/print_logger.rb +47 -0
- data/{lib/scarpe → scarpe-components/lib/scarpe/components}/promises.rb +115 -48
- data/scarpe-components/lib/scarpe/components/segmented_file_loader.rb +189 -0
- data/scarpe-components/lib/scarpe/components/string_helpers.rb +10 -0
- data/scarpe-components/lib/scarpe/components/tiranti.rb +225 -0
- data/scarpe-components/lib/scarpe/components/unit_test_helpers.rb +257 -0
- data/scarpe-components/lib/scarpe/components/version.rb +7 -0
- data/scarpe-components/scarpe-components.gemspec +38 -0
- data/scarpe-components/test/calzini/test_calzini_alert.rb +30 -0
- data/scarpe-components/test/calzini/test_calzini_art_drawables.rb +105 -0
- data/scarpe-components/test/calzini/test_calzini_button.rb +52 -0
- data/scarpe-components/test/calzini/test_calzini_misc.rb +115 -0
- data/scarpe-components/test/calzini/test_calzini_para.rb +37 -0
- data/scarpe-components/test/calzini/test_calzini_slots.rb +130 -0
- data/scarpe-components/test/calzini/test_calzini_text_drawables.rb +41 -0
- data/scarpe-components/test/mtr_data/exception.json +1 -0
- data/scarpe-components/test/mtr_data/fail_with_message.json +1 -0
- data/scarpe-components/test/mtr_data/skipped_no_message.json +1 -0
- data/scarpe-components/test/mtr_data/skipped_w_msg.json +1 -0
- data/scarpe-components/test/mtr_data/succeed_2_asserts.json +1 -0
- data/scarpe-components/test/test_components.rb +9 -0
- data/scarpe-components/test/test_dimensions.rb +26 -0
- data/scarpe-components/test/test_helper.rb +43 -0
- data/scarpe-components/test/test_html.rb +65 -0
- data/scarpe-components/test/test_minitest_result.rb +61 -0
- data/scarpe-components/test/test_promises.rb +261 -0
- data/scarpe-components/test/test_segmented_app_files.rb +184 -0
- data/scarpegen.rb +14 -14
- data/sig/scarpe.rbs +1 -1
- data/{lib/scarpe → spikes}/glibui/widget.rb +2 -2
- data/{lib/scarpe → spikes}/glibui.rb +1 -1
- data/templates/basic_class_template.erb +13 -14
- data/templates/class_template_with_event_bind.erb +4 -4
- data/templates/class_template_with_shapes.erb +8 -17
- data/templates/example_template.erb +1 -1
- data/templates/module_template.erb +4 -4
- data/templates/webview_template.erb +3 -5
- metadata +236 -145
- data/examples/fill.rb +0 -25
- data/examples/legacy/not_checked/shoes-contrib/basic/class-book.yaml +0 -387
- data/examples/legacy/not_checked/shoes-contrib/elements/image-icon.rb +0 -3
- data/examples/legacy/not_checked/shoes-contrib/good/good-clock.rb +0 -51
- data/examples/legacy/not_checked/shoes-contrib/good/good-follow.rb +0 -26
- data/examples/legacy/not_checked/shoes-contrib/good/good-reminder.rb +0 -174
- data/examples/legacy/not_checked/shoes-contrib/good/good-vjot.rb +0 -56
- data/examples/legacy/not_checked/shoes-contrib/simple/simple-timer.rb +0 -13
- data/examples/legacy/not_checked/shoes-dep-samples/good-clock.rb +0 -51
- data/examples/legacy/not_checked/shoes-dep-samples/good-follow.rb +0 -26
- data/examples/legacy/not_checked/shoes-dep-samples/good-reminder.rb +0 -174
- data/examples/legacy/not_checked/shoes-dep-samples/good-vjot.rb +0 -56
- data/examples/legacy/not_checked/shoes-dep-samples/simple-accordion.rb +0 -75
- data/examples/legacy/not_checked/shoes-dep-samples/simple-anim-shapes.rb +0 -17
- data/examples/legacy/not_checked/shoes-dep-samples/simple-anim-text.rb +0 -13
- data/examples/legacy/not_checked/shoes-dep-samples/simple-arc.rb +0 -23
- data/examples/legacy/not_checked/shoes-dep-samples/simple-bounce.rb +0 -24
- data/examples/legacy/not_checked/shoes-dep-samples/simple-calc.rb +0 -70
- data/examples/legacy/not_checked/shoes-dep-samples/simple-chipmunk.rb +0 -26
- data/examples/legacy/not_checked/shoes-dep-samples/simple-control-sizes.rb +0 -24
- data/examples/legacy/not_checked/shoes-dep-samples/simple-curve.rb +0 -26
- data/examples/legacy/not_checked/shoes-dep-samples/simple-dialogs.rb +0 -29
- data/examples/legacy/not_checked/shoes-dep-samples/simple-draw.rb +0 -13
- data/examples/legacy/not_checked/shoes-dep-samples/simple-editor.rb +0 -28
- data/examples/legacy/not_checked/shoes-dep-samples/simple-form.rb +0 -28
- data/examples/legacy/not_checked/shoes-dep-samples/simple-form.shy +0 -0
- data/examples/legacy/not_checked/shoes-dep-samples/simple-mask.rb +0 -21
- data/examples/legacy/not_checked/shoes-dep-samples/simple-menu.rb +0 -31
- data/examples/legacy/not_checked/shoes-dep-samples/simple-menu1.rb +0 -35
- data/examples/legacy/not_checked/shoes-dep-samples/simple-rubygems.rb +0 -29
- data/examples/legacy/not_checked/shoes-dep-samples/simple-slide.rb +0 -45
- data/examples/legacy/not_checked/shoes-dep-samples/simple-sphere.rb +0 -28
- data/examples/legacy/not_checked/shoes-dep-samples/simple-sqlite3.rb +0 -13
- data/examples/legacy/not_checked/shoes-dep-samples/simple-timer.rb +0 -13
- data/examples/legacy/not_checked/shoes-dep-samples/simple-video.rb +0 -13
- data/examples/legacy/not_checked/simple/anim-text.rb +0 -13
- data/examples/legacy/not_checked/simple/arc.rb +0 -23
- data/examples/legacy/not_checked/simple/bounce.rb +0 -24
- data/examples/legacy/not_checked/simple/chipmunk.rb +0 -26
- data/examples/legacy/not_checked/simple/curve.rb +0 -26
- data/examples/legacy/not_checked/simple/dialogs.rb +0 -29
- data/examples/legacy/not_checked/simple/downloader.rb +0 -40
- data/examples/legacy/not_checked/simple/draw.rb +0 -13
- data/examples/legacy/not_checked/simple/mask.rb +0 -21
- data/examples/legacy/not_checked/simple/slide.rb +0 -45
- data/examples/legacy/not_checked/simple/sphere.rb +0 -28
- data/lib/constants.rb +0 -5
- data/lib/scarpe/alert.rb +0 -19
- data/lib/scarpe/app.rb +0 -78
- data/lib/scarpe/arc.rb +0 -49
- data/lib/scarpe/button.rb +0 -35
- data/lib/scarpe/document_root.rb +0 -20
- data/lib/scarpe/edit_box.rb +0 -24
- data/lib/scarpe/fill.rb +0 -23
- data/lib/scarpe/flow.rb +0 -19
- data/lib/scarpe/line.rb +0 -25
- data/lib/scarpe/link.rb +0 -25
- data/lib/scarpe/list_box.rb +0 -25
- data/lib/scarpe/logger.rb +0 -155
- data/lib/scarpe/para.rb +0 -90
- data/lib/scarpe/shape.rb +0 -19
- data/lib/scarpe/spacing.rb +0 -9
- data/lib/scarpe/stack.rb +0 -70
- data/lib/scarpe/star.rb +0 -47
- data/lib/scarpe/text_widget.rb +0 -42
- data/lib/scarpe/unit_test_helpers.rb +0 -163
- data/lib/scarpe/widget.rb +0 -198
- data/lib/scarpe/widgets.rb +0 -30
- data/lib/scarpe/wv/alert.rb +0 -65
- data/lib/scarpe/wv/background.rb +0 -18
- data/lib/scarpe/wv/border.rb +0 -22
- data/lib/scarpe/wv/control_interface_test.rb +0 -253
- data/lib/scarpe/wv/dimensions.rb +0 -22
- data/lib/scarpe/wv/fill.rb +0 -30
- data/lib/scarpe/wv/html.rb +0 -107
- data/lib/scarpe/wv/shape_helper.rb +0 -44
- data/lib/scarpe/wv/spacing.rb +0 -41
- data/lib/scarpe/wv/text_widget.rb +0 -30
- data/lib/scarpe/wv/widget.rb +0 -181
- data/scarpe-0.2.0.gem +0 -0
- /data/examples/legacy/not_checked/{expert → shoes-contrib/basic}/definr.rb +0 -0
- /data/examples/legacy/not_checked/{expert → shoes-contrib/basic}/funnies.rb +0 -0
- /data/examples/legacy/not_checked/shoes-contrib/{elements → basic}/list_box-select-class.rb +0 -0
- /data/examples/legacy/{not_checked/shoes-contrib/basic → working/simple}/basic-edit-box.rb +0 -0
- /data/examples/legacy/{not_checked/shoes-contrib/elements → working/simple}/basic-fps.rb +0 -0
- /data/examples/legacy/{not_checked/shoes-contrib/elements → working/simple}/border-cat.rb +0 -0
- /data/examples/legacy/{not_checked/shoes-contrib/elements → working/simple}/check-mate.rb +0 -0
- /data/examples/legacy/{not_checked/shoes-contrib/manipulation → working/simple}/clear-slot.rb +0 -0
- /data/examples/legacy/{not_checked/shoes-contrib/basic → working/simple}/clock.rb +0 -0
- /data/examples/legacy/{not_checked/shoes-contrib/basic → working/simple}/gradient-shoes.rb +0 -0
- /data/examples/legacy/{not_checked/shoes-contrib/basic → working/simple}/list_box-shape-report.rb +0 -0
- /data/examples/legacy/{not_checked/shoes-contrib/elements → working/simple}/list_box.rb +0 -0
- /data/examples/legacy/{not_checked/shoes-contrib/elements → working/simple}/phat-button.rb +0 -0
- /data/examples/legacy/{not_checked/shoes-contrib → working}/simple/simple-calc.rb +0 -0
- /data/examples/legacy/{not_checked/shoes-contrib/position → working/simple}/stack-width.rb +0 -0
- /data/examples/legacy/{not_checked/shoes-contrib/elements → working/simple}/width-introspec.rb +0 -0
- /data/{lib/scarpe → spikes}/glibui/README.md +0 -0
- /data/{lib/scarpe → spikes}/glibui/alert.rb +0 -0
- /data/{lib/scarpe → spikes}/glibui/app.rb +0 -0
- /data/{lib/scarpe → spikes}/glibui/background.rb +0 -0
- /data/{lib/scarpe → spikes}/glibui/border.rb +0 -0
- /data/{lib/scarpe → spikes}/glibui/button.rb +0 -0
- /data/{lib/scarpe → spikes}/glibui/dimensions.rb +0 -0
- /data/{lib/scarpe → spikes}/glibui/document_root.rb +0 -0
- /data/{lib/scarpe → spikes}/glibui/edit_box.rb +0 -0
- /data/{lib/scarpe → spikes}/glibui/edit_line.rb +0 -0
- /data/{lib/scarpe → spikes}/glibui/flow.rb +0 -0
- /data/{lib/scarpe → spikes}/glibui/html.rb +0 -0
- /data/{lib/scarpe → spikes}/glibui/image.rb +0 -0
- /data/{lib/scarpe → spikes}/glibui/link.rb +0 -0
- /data/{lib/scarpe → spikes}/glibui/local_display.rb +0 -0
- /data/{lib/scarpe → spikes}/glibui/para.rb +0 -0
- /data/{lib/scarpe → spikes}/glibui/spacing.rb +0 -0
- /data/{lib/scarpe → spikes}/glibui/stack.rb +0 -0
- /data/{lib/scarpe → spikes}/glibui/text_widget.rb +0 -0
- /data/{lib/scarpe → spikes}/libui/alert.rb +0 -0
- /data/{lib/scarpe → spikes}/libui/button.rb +0 -0
- /data/{lib/scarpe → spikes}/libui/colors.rb +0 -0
- /data/{lib/scarpe → spikes}/libui/core.rb +0 -0
- /data/{lib/scarpe → spikes}/libui/flow.rb +0 -0
- /data/{lib/scarpe → spikes}/libui/libui.rb +0 -0
- /data/{lib/scarpe → spikes}/libui/notepad.md +0 -0
- /data/{lib/scarpe → spikes}/libui/para.rb +0 -0
- /data/{lib/scarpe → spikes}/libui/stack.rb +0 -0
@@ -0,0 +1,189 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require "scarpe/components/file_helpers"
|
4
|
+
|
5
|
+
module Scarpe::Components
|
6
|
+
class SegmentedFileLoader
|
7
|
+
include Scarpe::Components::FileHelpers
|
8
|
+
|
9
|
+
# Add a new segment type (e.g. "catscradle") with a different
|
10
|
+
# file handler.
|
11
|
+
#
|
12
|
+
# @param type [String] the new name for this segment type
|
13
|
+
# @param handler [Object] an object that will be called as obj.call(filename) - often a proc
|
14
|
+
# @return <void>
|
15
|
+
def add_segment_type(type, handler)
|
16
|
+
if segment_type_hash.key?(type)
|
17
|
+
raise Shoes::Errors::InvalidAttributeValueError, "Segment type #{type.inspect} already exists!"
|
18
|
+
end
|
19
|
+
|
20
|
+
segment_type_hash[type] = handler
|
21
|
+
end
|
22
|
+
|
23
|
+
# Return an Array of segment type labels, such as "code" and "app_test".
|
24
|
+
#
|
25
|
+
# @return [Array<String>] the segment type labels
|
26
|
+
def segment_types
|
27
|
+
segment_type_hash.keys
|
28
|
+
end
|
29
|
+
|
30
|
+
# Normally a Shoes application will want to keep the default segment types,
|
31
|
+
# which allow loading a Shoes app and running a test inside. But sometimes
|
32
|
+
# the default handler will be wrong and a library will want to register
|
33
|
+
# its own "shoes" and "app_test" segment handlers, or not have any at all.
|
34
|
+
# For those applications, it makes sense to clear all segment types before
|
35
|
+
# registering its own.
|
36
|
+
#
|
37
|
+
# @return <void>
|
38
|
+
def remove_all_segment_types!
|
39
|
+
@segment_type_hash = {}
|
40
|
+
end
|
41
|
+
|
42
|
+
# Load a .sca file with an optional YAML frontmatter prefix and
|
43
|
+
# multiple file sections which can be treated differently.
|
44
|
+
#
|
45
|
+
# The file loader acts like a proc, being called with .call()
|
46
|
+
# and returning true or false for whether it has handled the
|
47
|
+
# file load. This allows chaining loaders in order and the
|
48
|
+
# first loader to recognise a file will run it.
|
49
|
+
#
|
50
|
+
# @param path [String] the file or directory to treat as a Scarpe app
|
51
|
+
# @return [Boolean] return true if the file is loaded as a segmented Scarpe app file
|
52
|
+
def call(path)
|
53
|
+
return false unless path.end_with?(".scas") || path.end_with?(".sspec")
|
54
|
+
|
55
|
+
file_load(path)
|
56
|
+
true
|
57
|
+
end
|
58
|
+
|
59
|
+
# Segment type handlers can call this to perform an operation after the load
|
60
|
+
# has completed. This is important for ordering, and because loading a Shoes
|
61
|
+
# app often doesn't return. So to have a later section (e.g. tests, additional
|
62
|
+
# data) do something that affects Shoes app loading (e.g. set an env var,
|
63
|
+
# affect the display service) it's important that app loading take place later
|
64
|
+
# in the sequence.
|
65
|
+
def after_load(&block)
|
66
|
+
@after_load ||= []
|
67
|
+
@after_load << block
|
68
|
+
end
|
69
|
+
|
70
|
+
def self.gen_name(segmap)
|
71
|
+
ctr = (1..10_000).detect { |i| !segmap.key?("%5d" % i) }
|
72
|
+
"%5d" % ctr
|
73
|
+
end
|
74
|
+
|
75
|
+
def self.front_matter_and_segments_from_file(contents)
|
76
|
+
require "yaml" # Only load when needed
|
77
|
+
require "English"
|
78
|
+
|
79
|
+
segments = contents.split(/\n-{5,}/)
|
80
|
+
front_matter = {}
|
81
|
+
|
82
|
+
# The very first segment can start with front matter, or with a divider, or with no divider.
|
83
|
+
if segments[0].start_with?("---\n") || segments[0] == "---"
|
84
|
+
# We have YAML front matter at the start. All later segments will have a divider.
|
85
|
+
front_matter = YAML.load segments[0]
|
86
|
+
front_matter ||= {} # If the front matter is just the three dashes it returns nil
|
87
|
+
segments = segments[1..-1]
|
88
|
+
elsif segments[0].start_with?("-----")
|
89
|
+
# We have a divider at the start. Great! We're already well set up for this case.
|
90
|
+
elsif segments.size == 1
|
91
|
+
# No front matter, no divider, a single unnamed segment. No more parsing needed.
|
92
|
+
return [{}, { "" => segments[0] }]
|
93
|
+
else
|
94
|
+
# No front matter, no divider before the first segment, multiple segments.
|
95
|
+
# We'll add an artificial divider to the first segment for uniformity.
|
96
|
+
segments = ["-----\n" + segments[0]] + segments[1..-1]
|
97
|
+
end
|
98
|
+
|
99
|
+
segmap = {}
|
100
|
+
segments.each do |segment|
|
101
|
+
if segment =~ /\A-* +(.*?)\n/
|
102
|
+
# named segment with separator
|
103
|
+
name = ::Regexp.last_match(1)
|
104
|
+
|
105
|
+
raise("Duplicate segment name: #{name.inspect}!") if segmap.key?(name)
|
106
|
+
|
107
|
+
segmap[name] = ::Regexp.last_match.post_match
|
108
|
+
elsif segment =~ /\A-* *\n/
|
109
|
+
# unnamed segment with separator
|
110
|
+
segmap[gen_name(segmap)] = ::Regexp.last_match.post_match
|
111
|
+
else
|
112
|
+
raise Scarpe::InternalError, "Internal error when parsing segments in segmented app file! seg: #{segment.inspect}"
|
113
|
+
end
|
114
|
+
end
|
115
|
+
|
116
|
+
[front_matter, segmap]
|
117
|
+
end
|
118
|
+
|
119
|
+
def file_load(path)
|
120
|
+
contents = File.read(path)
|
121
|
+
|
122
|
+
front_matter, segmap = self.class.front_matter_and_segments_from_file(contents)
|
123
|
+
|
124
|
+
if segmap.empty?
|
125
|
+
raise Scarpe::FileContentError, "Illegal segmented Scarpe file: must have at least one code segment, not just front matter!"
|
126
|
+
end
|
127
|
+
|
128
|
+
if front_matter[:segments]
|
129
|
+
if front_matter[:segments].size != segmap.size
|
130
|
+
raise Scarpe::FileContentError, "Number of front matter :segments must equal number of file segments!"
|
131
|
+
end
|
132
|
+
else
|
133
|
+
if segmap.size > 2
|
134
|
+
raise Scarpe::FileContentError, "Segmented files with more than two segments have to specify what they're for!"
|
135
|
+
end
|
136
|
+
|
137
|
+
# Set to default of shoes code only or shoes code and app test code.
|
138
|
+
front_matter[:segments] = segmap.size == 2 ? ["shoes", "app_test"] : ["shoes"]
|
139
|
+
end
|
140
|
+
|
141
|
+
# Match up front_matter[:segments] with the segments, or use the default of shoes and app_test.
|
142
|
+
|
143
|
+
sth = segment_type_hash
|
144
|
+
sv = segmap.values
|
145
|
+
|
146
|
+
tf_specs = []
|
147
|
+
front_matter[:segments].each.with_index do |seg_type, idx|
|
148
|
+
unless sth.key?(seg_type)
|
149
|
+
raise Scarpe::FileContentError, "Unrecognized segment type #{seg_type.inspect}! No matching segment type available!"
|
150
|
+
end
|
151
|
+
|
152
|
+
tf_specs << ["scarpe_#{seg_type}_segment_contents", sv[idx]]
|
153
|
+
end
|
154
|
+
|
155
|
+
with_tempfiles(tf_specs) do |filenames|
|
156
|
+
filenames.each.with_index do |filename, idx|
|
157
|
+
seg_name = front_matter[:segments][idx]
|
158
|
+
sth[seg_name].call(filename)
|
159
|
+
end
|
160
|
+
|
161
|
+
# Need to call @after_load hooks while tempfiles still exist
|
162
|
+
if @after_load && !@after_load.empty?
|
163
|
+
@after_load.each(&:call)
|
164
|
+
@after_load = []
|
165
|
+
end
|
166
|
+
end
|
167
|
+
end
|
168
|
+
|
169
|
+
# The hash of segment type labels mapped to handlers which will be called.
|
170
|
+
# This could be called by a display service, a test framework or similar
|
171
|
+
# code that wants to define a non-Scarpe-standard file format.
|
172
|
+
#
|
173
|
+
# @return [Hash<String, Object>] the name/handler pairs
|
174
|
+
def segment_type_hash
|
175
|
+
@segment_handlers ||= {
|
176
|
+
"shoes" => proc { |seg_file| after_load { load seg_file } },
|
177
|
+
"app_test" => proc do |seg_file|
|
178
|
+
ENV["SHOES_SPEC_TEST"] = seg_file
|
179
|
+
ENV["SHOES_MINITEST_EXPORT_FILE"] = "sspec.json"
|
180
|
+
end,
|
181
|
+
}
|
182
|
+
end
|
183
|
+
end
|
184
|
+
end
|
185
|
+
|
186
|
+
# You can add additional segment types to the segmented file loader
|
187
|
+
# loader = Scarpe::Components::SegmentedFileLoader.new
|
188
|
+
# loader.add_segment_type "capybara", proc { |seg_file| load_file_as_capybara(seg_file) }
|
189
|
+
# Shoes.add_file_loader loader
|
@@ -0,0 +1,10 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Scarpe; module Components; end; end
|
4
|
+
module Scarpe::Components::StringHelpers
|
5
|
+
# Cut down from Rails camelize
|
6
|
+
def self.camelize(string)
|
7
|
+
string = string.sub(/^[a-z\d]*/, &:capitalize)
|
8
|
+
string.gsub(/(?:_|(\/))([a-z\d]*)/) { "#{::Regexp.last_match(1)}#{::Regexp.last_match(2).capitalize}" }
|
9
|
+
end
|
10
|
+
end
|
@@ -0,0 +1,225 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
# In Italian, tiranti are bootstraps -- the literal pull-on-a-boot kind, not a step to something better.
|
4
|
+
# Tiranti.rb builds on calzini.rb, but renders a Bootstrap-decorated version of the HTML output.
|
5
|
+
# You would ordinarily set either Calzini or Tiranti as the top-level HTML renderer, not both.
|
6
|
+
# You'll include both if you use Tiranti, because it falls back to Calzini for a lot of its rendering.
|
7
|
+
|
8
|
+
require "scarpe/components/calzini"
|
9
|
+
|
10
|
+
# The Tiranti module expects to be included by a class defining
|
11
|
+
# the following methods:
|
12
|
+
#
|
13
|
+
# * html_id - the HTML ID for the specific rendered DOM object
|
14
|
+
# * handler_js_code(event_name) - the JS handler code for this DOM object and event name
|
15
|
+
# * (optional) display_properties - the display properties for this object, unless overridden in render()
|
16
|
+
module Scarpe::Components::Tiranti
|
17
|
+
include Scarpe::Components::Calzini
|
18
|
+
extend self
|
19
|
+
|
20
|
+
# Currently we're using Bootswatch 5
|
21
|
+
BOOTSWATCH_THEMES = [
|
22
|
+
"cerulean",
|
23
|
+
"cosmo",
|
24
|
+
"cyborg",
|
25
|
+
"darkly",
|
26
|
+
"flatly",
|
27
|
+
"journal",
|
28
|
+
"litera",
|
29
|
+
"lumen",
|
30
|
+
"lux",
|
31
|
+
"materia",
|
32
|
+
"minty",
|
33
|
+
"morph",
|
34
|
+
"pulse",
|
35
|
+
"quartz",
|
36
|
+
"sandstone",
|
37
|
+
"simplex",
|
38
|
+
"sketchy",
|
39
|
+
"slate",
|
40
|
+
"solar",
|
41
|
+
"spacelab",
|
42
|
+
"superhero",
|
43
|
+
"united",
|
44
|
+
"vapor",
|
45
|
+
"yeti",
|
46
|
+
"zephyr",
|
47
|
+
]
|
48
|
+
|
49
|
+
BOOTSWATCH_THEME = ENV["SCARPE_BOOTSTRAP_THEME"] || "sketchy"
|
50
|
+
|
51
|
+
def empty_page_element
|
52
|
+
<<~HTML
|
53
|
+
<html>
|
54
|
+
<head id='head-wvroot'>
|
55
|
+
<meta charset="utf-8">
|
56
|
+
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
|
57
|
+
<link rel="stylesheet" href="https://bootswatch.com/5/#{BOOTSWATCH_THEME}/bootstrap.css">
|
58
|
+
<link rel="stylesheet" href="https://bootswatch.com/_vendor/bootstrap-icons/font/bootstrap-icons.min.css">
|
59
|
+
<style id='style-wvroot'>
|
60
|
+
/** Style resets **/
|
61
|
+
body {
|
62
|
+
height: 100%;
|
63
|
+
overflow: hidden;
|
64
|
+
}
|
65
|
+
</style>
|
66
|
+
</head>
|
67
|
+
<body id='body-wvroot'>
|
68
|
+
<div id='wrapper-wvroot'></div>
|
69
|
+
|
70
|
+
<script src="https://bootswatch.com/_vendor/bootstrap/dist/js/bootstrap.bundle.min.js"></script>
|
71
|
+
</body>
|
72
|
+
</html>
|
73
|
+
HTML
|
74
|
+
end
|
75
|
+
|
76
|
+
# def render_stack
|
77
|
+
# end
|
78
|
+
# def render_flow
|
79
|
+
# end
|
80
|
+
|
81
|
+
# How do we want to handle theme-specific colours and primary/secondary buttons in Bootstrap?
|
82
|
+
# "Disabled" could be checked in properties. Is there any way we can/should use "outline" buttons?
|
83
|
+
def button_element(props)
|
84
|
+
HTML.render do |h|
|
85
|
+
h.button(id: html_id, type: "button", class: "btn btn-primary", onclick: handler_js_code("click"), style: button_style(props)) do
|
86
|
+
props["text"]
|
87
|
+
end
|
88
|
+
end
|
89
|
+
end
|
90
|
+
|
91
|
+
private
|
92
|
+
|
93
|
+
def button_style(props)
|
94
|
+
styles = drawable_style(props)
|
95
|
+
|
96
|
+
styles[:"background-color"] = props["color"] if props["color"]
|
97
|
+
styles[:"padding-top"] = props["padding_top"] if props["padding_top"]
|
98
|
+
styles[:"padding-bottom"] = props["padding_bottom"] if props["padding_bottom"]
|
99
|
+
styles[:color] = props["text_color"] if props["text_color"]
|
100
|
+
styles[:width] = dimensions_length(props["width"]) if props["width"]
|
101
|
+
styles[:height] = dimensions_length(props["height"]) if props["height"]
|
102
|
+
styles[:"font-size"] = props["font_size"] if props["font_size"]
|
103
|
+
|
104
|
+
styles[:top] = dimensions_length(props["top"]) if props["top"]
|
105
|
+
styles[:left] = dimensions_length(props["left"]) if props["left"]
|
106
|
+
styles[:position] = "absolute" if props["top"] || props["left"]
|
107
|
+
styles[:"font-size"] = dimensions_length(text_size(props["size"])) if props["size"]
|
108
|
+
styles[:"font-family"] = props["font"] if props["font"]
|
109
|
+
|
110
|
+
styles
|
111
|
+
end
|
112
|
+
|
113
|
+
public
|
114
|
+
|
115
|
+
def alert_element(props)
|
116
|
+
onclick = handler_js_code(props["event_name"] || "click")
|
117
|
+
|
118
|
+
HTML.render do |h|
|
119
|
+
h.div(id: html_id, class: "modal", tabindex: -1, role: "dialog", style: alert_overlay_style(props)) do
|
120
|
+
h.div(class: "modal-dialog", role: "document") do
|
121
|
+
h.div(class: "modal-content", style: alert_modal_style) do
|
122
|
+
h.div(class: "modal-header") do
|
123
|
+
h.h5(class: "modal-title") { "Alert" }
|
124
|
+
h.button(type: "button", class: "close", data_dismiss: "modal", aria_label: "Close") do
|
125
|
+
h.span(aria_hidden: "true") { "×" }
|
126
|
+
end
|
127
|
+
end
|
128
|
+
h.div(class: "modal-body") do
|
129
|
+
h.p { props["text"] }
|
130
|
+
end
|
131
|
+
h.div(class: "modal-footer") do
|
132
|
+
h.button(type: "button", onclick:, class: "btn btn-primary") { "OK" }
|
133
|
+
#h.button(type: "button", class: "btn btn-secondary") { "Close" }
|
134
|
+
end
|
135
|
+
end
|
136
|
+
end
|
137
|
+
end
|
138
|
+
end
|
139
|
+
end
|
140
|
+
|
141
|
+
def check_element(props)
|
142
|
+
HTML.render do |h|
|
143
|
+
h.div class: "form-check" do
|
144
|
+
h.input type: :checkbox,
|
145
|
+
id: html_id,
|
146
|
+
class: "form-check-input",
|
147
|
+
onclick: handler_js_code("click"),
|
148
|
+
value: props["text"],
|
149
|
+
checked: props["checked"],
|
150
|
+
style: drawable_style(props)
|
151
|
+
end
|
152
|
+
end
|
153
|
+
end
|
154
|
+
|
155
|
+
def progress_element(props)
|
156
|
+
HTML.render do |h|
|
157
|
+
h.div(class: "progress", style: "width: 90%") do
|
158
|
+
pct = "%.1f" % ((props["fraction"] || 0.0) * 100.0)
|
159
|
+
h.div(
|
160
|
+
class: "progress-bar progress-bar-striped progress-bar-animated",
|
161
|
+
role: "progressbar",
|
162
|
+
"aria-valuenow": pct,
|
163
|
+
"aria-valuemin": 0,
|
164
|
+
"aria-valuemax": 100,
|
165
|
+
style: "width: #{pct}%",
|
166
|
+
)
|
167
|
+
end
|
168
|
+
end
|
169
|
+
end
|
170
|
+
|
171
|
+
# para_element is a bit of a hard one, since it does not-entirely-trivial
|
172
|
+
# mapping between display objects and IDs. But we don't want Calzini
|
173
|
+
# messing with the display service or display objects.
|
174
|
+
def para_element(props, &block)
|
175
|
+
tag, opts = para_elt_and_opts(props)
|
176
|
+
|
177
|
+
HTML.render do |h|
|
178
|
+
h.send(tag, **opts, &block)
|
179
|
+
end
|
180
|
+
end
|
181
|
+
|
182
|
+
private
|
183
|
+
|
184
|
+
ELT_AND_SIZE = {
|
185
|
+
inscription: [:p, 10],
|
186
|
+
ins: [:p, 10],
|
187
|
+
para: [:p, 12],
|
188
|
+
caption: [:p, 14],
|
189
|
+
tagline: [:p, 18],
|
190
|
+
subtitle: [:h3, 26],
|
191
|
+
title: [:h2, 34],
|
192
|
+
banner: [:h1, 48],
|
193
|
+
}.freeze
|
194
|
+
|
195
|
+
def para_elt_and_opts(props)
|
196
|
+
elt, size = para_elt_and_size(props)
|
197
|
+
size = dimensions_length(size)
|
198
|
+
|
199
|
+
para_style = drawable_style(props).merge({
|
200
|
+
color: rgb_to_hex(props["stroke"]),
|
201
|
+
"font-size": para_font_size(props),
|
202
|
+
"font-family": props["font"],
|
203
|
+
}.compact)
|
204
|
+
|
205
|
+
opts = (props["html_attributes"] || {}).merge(id: html_id, style: para_style)
|
206
|
+
|
207
|
+
[elt, opts]
|
208
|
+
end
|
209
|
+
|
210
|
+
def para_elt_and_size(props)
|
211
|
+
return [:p, nil] unless props["size"]
|
212
|
+
|
213
|
+
ps = props["size"].to_s.to_sym
|
214
|
+
if ELT_AND_SIZE.key?(ps)
|
215
|
+
ELT_AND_SIZE[ps]
|
216
|
+
else
|
217
|
+
sz = props["size"].to_i
|
218
|
+
if sz > 18
|
219
|
+
[:h2, sz]
|
220
|
+
else
|
221
|
+
[:p, sz]
|
222
|
+
end
|
223
|
+
end
|
224
|
+
end
|
225
|
+
end
|
@@ -0,0 +1,257 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require "tempfile"
|
4
|
+
require "json"
|
5
|
+
require "fileutils"
|
6
|
+
|
7
|
+
require "scarpe/components/file_helpers"
|
8
|
+
|
9
|
+
module Scarpe::Test; end
|
10
|
+
|
11
|
+
# We want test failures set up once *total*, not per Minitest::Test. So an instance var
|
12
|
+
# doesn't do it.
|
13
|
+
ALREADY_SET_UP_LOGGED_TEST_FAILURES = { setup: false }
|
14
|
+
|
15
|
+
# General helpers for general usage.
|
16
|
+
# Helpers here should *not* use Webview-specific functionality.
|
17
|
+
# The intention is that these are helpers for various Scarpe display
|
18
|
+
# services that do *not* necessarily use Webview.
|
19
|
+
|
20
|
+
module Scarpe::Test::Helpers
|
21
|
+
# Very useful for tests
|
22
|
+
include Scarpe::Components::FileHelpers
|
23
|
+
|
24
|
+
# Temporarily set env vars for the block of code inside. The old environment
|
25
|
+
# variable values will be restored after the block finishes.
|
26
|
+
#
|
27
|
+
# @param envs [Hash<String,String>] A hash of environment variable names and values
|
28
|
+
def with_env_vars(envs)
|
29
|
+
old_env = {}
|
30
|
+
envs.each do |k, v|
|
31
|
+
old_env[k] = ENV[k]
|
32
|
+
ENV[k] = v
|
33
|
+
end
|
34
|
+
yield
|
35
|
+
ensure
|
36
|
+
old_env.each { |k, v| ENV[k] = v }
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
40
|
+
# This test will save extensive logs in case of test failure.
|
41
|
+
# Note that it defines setup/teardown methods. If you want
|
42
|
+
# multiple setup/teardowns from multiple places to happen you
|
43
|
+
# may need to explictly call (e.g. with logged_test_setup/teardown)
|
44
|
+
# to ensure everything you want happens.
|
45
|
+
module Scarpe::Test::LoggedTest
|
46
|
+
def self.included(includer)
|
47
|
+
class << includer
|
48
|
+
attr_accessor :logger_dir
|
49
|
+
end
|
50
|
+
end
|
51
|
+
|
52
|
+
def file_id
|
53
|
+
"#{self.class.name}_#{self.name}"
|
54
|
+
end
|
55
|
+
|
56
|
+
# This should be called by the test during setup to make sure that
|
57
|
+
# failure logs will be saved if this test fails. It makes sure the
|
58
|
+
# log config will save all logs from all sources, but keeps a copy
|
59
|
+
# of the old log config to restore after the test is finished.
|
60
|
+
#
|
61
|
+
# @return [void]
|
62
|
+
def logged_test_setup
|
63
|
+
# Make sure test failures will be saved at the end of the run.
|
64
|
+
# Delete stale test failures and logging only the *first* time this is called.
|
65
|
+
set_up_test_failures
|
66
|
+
|
67
|
+
@normal_log_config = Shoes::Log.current_log_config
|
68
|
+
Shoes::Log.configure_logger(log_config_for_test)
|
69
|
+
|
70
|
+
Shoes::Log.logger("LoggedScarpeTest").info("Test: #{self.class.name}##{self.name}")
|
71
|
+
end
|
72
|
+
|
73
|
+
# If you include this module and don't override setup/teardown, everything will
|
74
|
+
# work fine. But if you need more setup/teardown steps, you can do that too.
|
75
|
+
#
|
76
|
+
# The setup method guarantees that just including this module will do setup
|
77
|
+
# automatically. If you override it, be sure to call `super` or `logged_test_setup`.
|
78
|
+
#
|
79
|
+
# @return [void]
|
80
|
+
def setup
|
81
|
+
logged_test_setup
|
82
|
+
end
|
83
|
+
|
84
|
+
# After the test has finished, this will restore the old log configuration.
|
85
|
+
# It will also save the logfiles, but only if the test failed, not if it
|
86
|
+
# succeeded or was skipped.
|
87
|
+
#
|
88
|
+
# @return [void]
|
89
|
+
def logged_test_teardown
|
90
|
+
# Restore previous log config
|
91
|
+
Shoes::Log.configure_logger(@normal_log_config)
|
92
|
+
|
93
|
+
if self.failure
|
94
|
+
save_failure_logs
|
95
|
+
else
|
96
|
+
remove_unsaved_logs
|
97
|
+
end
|
98
|
+
end
|
99
|
+
|
100
|
+
# Make sure that, by default, #logged_test_teardown will be called for teardown.
|
101
|
+
# If a class overrides teardown, it should also call `super` or `logged_test_teardown`
|
102
|
+
# to make sure this still happens.
|
103
|
+
#
|
104
|
+
# @return [void]
|
105
|
+
def teardown
|
106
|
+
logged_test_teardown
|
107
|
+
end
|
108
|
+
|
109
|
+
# Set additional LoggedTest configuration for specific logs to separate or save.
|
110
|
+
# This is normally going to be display-service-specific log components.
|
111
|
+
# Note that this only really works with the modular logger or another logger
|
112
|
+
# that does something useful with the log config. The simple print logger
|
113
|
+
# doesn't do a lot with it.
|
114
|
+
def extra_log_config=(additional_log_config)
|
115
|
+
@additional_log_config = additional_log_config
|
116
|
+
end
|
117
|
+
|
118
|
+
# This is the log config that LoggedTests use. It makes sure all components keep all
|
119
|
+
# logs, but also splits the logs into several different files for later ease of scanning.
|
120
|
+
#
|
121
|
+
# TODO: this shouldn't directly include any Webview entries like WebviewAPI or
|
122
|
+
# CatsCradle. Those should be overridden in Webview.
|
123
|
+
#
|
124
|
+
# @return [Hash] the log config
|
125
|
+
def log_config_for_test
|
126
|
+
{
|
127
|
+
"default" => ["debug", "logger/test_failure_#{file_id}.log"],
|
128
|
+
"DisplayService" => ["debug", "logger/test_failure_display_service_#{file_id}.log"],
|
129
|
+
}.merge(@additional_log_config || {})
|
130
|
+
end
|
131
|
+
|
132
|
+
# The list of logfiles that should be saved. Normally this is called internally by the
|
133
|
+
# class, not externally from elsewhere.
|
134
|
+
#
|
135
|
+
# This could be a lot simpler except I want to only update the file list in one place,
|
136
|
+
# log_config_for_test(). Having a single spot should (I hope) make it a lot friendlier to
|
137
|
+
# add more logfiles for different components, logged API objects, etc.
|
138
|
+
def saved_log_files
|
139
|
+
lc = log_config_for_test
|
140
|
+
log_outfiles = lc.values.map { |_level, loc| loc }
|
141
|
+
log_outfiles.select { |s| s.start_with?("logger/") }.map { |s| s.delete_prefix("logger/") }
|
142
|
+
end
|
143
|
+
|
144
|
+
# Make sure that test failure logs will be noticed, and a message will be printed,
|
145
|
+
# if any logged tests fail. This needs to be called at least once in any Minitest-enabled
|
146
|
+
# process using logged tests.
|
147
|
+
#
|
148
|
+
# @return [void]
|
149
|
+
def set_up_test_failures
|
150
|
+
return if ALREADY_SET_UP_LOGGED_TEST_FAILURES[:setup]
|
151
|
+
|
152
|
+
log_dir = self.class.logger_dir
|
153
|
+
raise(Scarpe::MustOverrideMethod, "Must set logger directory!") unless log_dir
|
154
|
+
raise(Scarpe::NoSuchFile, "Can't find logger directory!") unless File.directory?(log_dir)
|
155
|
+
|
156
|
+
ALREADY_SET_UP_LOGGED_TEST_FAILURES[:setup] = true
|
157
|
+
# Delete stale test failures, if any, before starting the first failure-logged test
|
158
|
+
Dir["#{log_dir}/test_failure*.log"].each { |fn| File.unlink(fn) }
|
159
|
+
|
160
|
+
Minitest.after_run do
|
161
|
+
# Print test failure notice to console
|
162
|
+
unless Dir["#{log_dir}/test_failure*.out.log"].empty?
|
163
|
+
puts "Some tests have failed! See #{log_dir}/test_failure*.out.log for test logs!"
|
164
|
+
end
|
165
|
+
|
166
|
+
# Remove un-saved test logs
|
167
|
+
Dir["#{log_dir}/test_failure*.log"].each do |f|
|
168
|
+
next if f.include?(".out.log")
|
169
|
+
|
170
|
+
File.unlink(f) if File.exist?(f)
|
171
|
+
end
|
172
|
+
end
|
173
|
+
end
|
174
|
+
|
175
|
+
# Failure log output location for a given file path. This is normally used internally to this
|
176
|
+
# class, not externally.
|
177
|
+
#
|
178
|
+
# @return [String] the output path
|
179
|
+
def logfail_out_loc(filepath)
|
180
|
+
# Add a .out prefix before final .log
|
181
|
+
out_loc = filepath.gsub(%r{.log\Z}, ".out.log")
|
182
|
+
|
183
|
+
if out_loc == filepath
|
184
|
+
raise Shoes::Errors::InvalidAttributeValueError, "Something is wrong! Could not figure out failure-log output path for #{filepath.inspect}!"
|
185
|
+
end
|
186
|
+
|
187
|
+
if File.exist?(out_loc)
|
188
|
+
raise Scarpe::DuplicateFileError, "Duplicate test file #{out_loc.inspect}? This file should *not* already exist!"
|
189
|
+
end
|
190
|
+
|
191
|
+
out_loc
|
192
|
+
end
|
193
|
+
|
194
|
+
# Save the failure logs in the appropriate place(s). This is normally used internally, not externally.
|
195
|
+
#
|
196
|
+
# @return [void]
|
197
|
+
def save_failure_logs
|
198
|
+
saved_log_files.each do |log_file|
|
199
|
+
full_loc = File.expand_path("#{self.class.logger_dir}/#{log_file}")
|
200
|
+
# TODO: we'd like to skip 0-length logfiles. But also Logging doesn't flush. For now, ignore.
|
201
|
+
next unless File.exist?(full_loc)
|
202
|
+
|
203
|
+
FileUtils.mv full_loc, logfail_out_loc(full_loc)
|
204
|
+
end
|
205
|
+
end
|
206
|
+
|
207
|
+
# Remove unsaved failure logs. This is normally used internally, not externally.
|
208
|
+
#
|
209
|
+
# @return [void]
|
210
|
+
def remove_unsaved_logs
|
211
|
+
Dir["#{self.class.logger_dir}/test_failure*.log"].each do |f|
|
212
|
+
next if f.include?(".out.log") # Don't delete saved logs
|
213
|
+
|
214
|
+
File.unlink(f)
|
215
|
+
end
|
216
|
+
end
|
217
|
+
end
|
218
|
+
|
219
|
+
module Scarpe::Test::HTMLAssertions
|
220
|
+
# Assert that `actual_html` is the same as `expected_tag` with `opts`.
|
221
|
+
# This uses Scarpe's HTML tag-based renderer to render the tag and options
|
222
|
+
# into text, and valides that the text is the same.
|
223
|
+
#
|
224
|
+
# @see Scarpe::Components::HTML.render
|
225
|
+
#
|
226
|
+
# @param actual_html [String] the html to compare to
|
227
|
+
# @param expected_tag [String,Symbol] the HTML tag, used to send a method call
|
228
|
+
# @param opts keyword options passed to the tag method call
|
229
|
+
# @yield block passed to the tag method call.
|
230
|
+
# @return [void]
|
231
|
+
def assert_html(actual_html, expected_tag, **opts, &block)
|
232
|
+
expected_html = Scarpe::Components::HTML.render do |h|
|
233
|
+
h.public_send(expected_tag, opts, &block)
|
234
|
+
end
|
235
|
+
|
236
|
+
assert_equal expected_html, actual_html
|
237
|
+
end
|
238
|
+
|
239
|
+
# Assert that `actual_html` includes `expected_tag` with `opts`.
|
240
|
+
# This uses Scarpe's HTML tag-based renderer to render the tag and options
|
241
|
+
# into text, and valides that the full HTML contains that tag.
|
242
|
+
#
|
243
|
+
# @see Scarpe::Components::HTML.render
|
244
|
+
#
|
245
|
+
# @param actual_html [String] the html to compare to
|
246
|
+
# @param expected_tag [String,Symbol] the HTML tag, used to send a method call
|
247
|
+
# @param opts keyword options passed to the tag method call
|
248
|
+
# @yield block passed to the tag method call.
|
249
|
+
# @return [void]
|
250
|
+
def assert_contains_html(actual_html, expected_tag, **opts, &block)
|
251
|
+
expected_html = Scarpe::Components::HTML.render do |h|
|
252
|
+
h.public_send(expected_tag, opts, &block)
|
253
|
+
end
|
254
|
+
|
255
|
+
assert actual_html.include?(expected_html), "Expected #{actual_html.inspect} to include #{expected_html.inspect}!"
|
256
|
+
end
|
257
|
+
end
|