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,49 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require_relative "test_helper"
|
4
|
+
|
5
|
+
class TestShoesErrors < NienteTest
|
6
|
+
def test_drawable_attr_error
|
7
|
+
run_test_niente_code(<<~SHOES_APP, app_test_code: <<~SHOES_SPEC)
|
8
|
+
Shoes.app do
|
9
|
+
button "OK" do
|
10
|
+
star 10, 25, "sammy"
|
11
|
+
end
|
12
|
+
end
|
13
|
+
SHOES_APP
|
14
|
+
assert_raises Shoes::Errors::InvalidAttributeValueError do
|
15
|
+
button().trigger_click
|
16
|
+
end
|
17
|
+
SHOES_SPEC
|
18
|
+
end
|
19
|
+
|
20
|
+
def test_too_many_instances_error
|
21
|
+
run_test_niente_code(<<~SHOES_APP, app_test_code: <<~SHOES_SPEC)
|
22
|
+
$ruby_main = self
|
23
|
+
Shoes.app do
|
24
|
+
end
|
25
|
+
SHOES_APP
|
26
|
+
assert_raises Shoes::Errors::TooManyInstancesError do
|
27
|
+
$ruby_main.instance_eval do
|
28
|
+
Shoes.app {}
|
29
|
+
end
|
30
|
+
end
|
31
|
+
SHOES_SPEC
|
32
|
+
end
|
33
|
+
|
34
|
+
def test_drawables_found_errors
|
35
|
+
run_test_niente_code(<<~SHOES_APP, app_test_code: <<~SHOES_SPEC)
|
36
|
+
Shoes.app do
|
37
|
+
button "OK"
|
38
|
+
button "Not OK"
|
39
|
+
end
|
40
|
+
SHOES_APP
|
41
|
+
assert_raises Shoes::Errors::MultipleDrawablesFoundError do
|
42
|
+
button()
|
43
|
+
end
|
44
|
+
assert_raises Shoes::Errors::NoDrawablesFoundError do
|
45
|
+
edit_line()
|
46
|
+
end
|
47
|
+
SHOES_SPEC
|
48
|
+
end
|
49
|
+
end
|
@@ -0,0 +1,271 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require "scarpe/components/unit_test_helpers"
|
4
|
+
require "scarpe/evented_assertions"
|
5
|
+
|
6
|
+
require "fiber"
|
7
|
+
|
8
|
+
module Scarpe::Test
|
9
|
+
# We'd like something we can call Shoes drawable methods on, such as para.replace.
|
10
|
+
# But we'd also like to be able to grab the corresponding display drawable and
|
11
|
+
# call some of *those* methods.
|
12
|
+
class CCProxy
|
13
|
+
attr_reader :display
|
14
|
+
attr_reader :obj
|
15
|
+
|
16
|
+
def initialize(obj)
|
17
|
+
@obj = obj
|
18
|
+
# TODO: how to do this with Webview relay? Proxy object to send a message, maybe?
|
19
|
+
@display = ::Shoes::DisplayService.display_service.query_display_drawable_for(obj.linkable_id)
|
20
|
+
end
|
21
|
+
|
22
|
+
def method_missing(method, ...)
|
23
|
+
if @obj.respond_to?(method)
|
24
|
+
self.singleton_class.define_method(method) do |*args, **kwargs, &block|
|
25
|
+
@obj.send(method, *args, **kwargs, &block)
|
26
|
+
end
|
27
|
+
send(method, ...)
|
28
|
+
else
|
29
|
+
super # raise an exception
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
def respond_to_missing?(method_name, include_private = false)
|
34
|
+
@obj.respond_to_missing?(method_name, include_private)
|
35
|
+
end
|
36
|
+
|
37
|
+
def trigger(event_name, *args)
|
38
|
+
name = "#{@obj.linkable_id}-#{event_name}"
|
39
|
+
Scarpe::Webview::DisplayService.instance.app.handle_callback(name, *args)
|
40
|
+
end
|
41
|
+
|
42
|
+
[:click, :hover, :leave, :change].each do |ev|
|
43
|
+
define_method "trigger_#{ev}" do |*args|
|
44
|
+
trigger(ev, *args)
|
45
|
+
end
|
46
|
+
end
|
47
|
+
end
|
48
|
+
|
49
|
+
module DrawableFinders
|
50
|
+
# What to do about TextDrawables? Link, code, em, strong?
|
51
|
+
# Also, wait, what's up with span? What *is* that?
|
52
|
+
Shoes::Drawable.drawable_classes.each do |drawable_class|
|
53
|
+
finder_name = drawable_class.dsl_name
|
54
|
+
|
55
|
+
define_method(finder_name) do |*args|
|
56
|
+
app = Shoes::App.instance
|
57
|
+
|
58
|
+
drawables = app.find_drawables_by(drawable_class, *args)
|
59
|
+
raise Shoes::Errors::MultipleDrawablesFoundError, "Found more than one #{finder_name} matching #{args.inspect}!" if drawables.size > 1
|
60
|
+
raise Shoes::Errors::NoDrawablesFoundError, "Found no #{finder_name} matching #{args.inspect}!" if drawables.empty?
|
61
|
+
|
62
|
+
CCProxy.new(drawables[0])
|
63
|
+
end
|
64
|
+
end
|
65
|
+
end
|
66
|
+
|
67
|
+
# This class defines the CatsCradle DSL. It also holds a "bag of fibers"
|
68
|
+
# with promises for when they should next resume.
|
69
|
+
class CCInstance
|
70
|
+
include Shoes::Log
|
71
|
+
include Scarpe::Test::EventedAssertions
|
72
|
+
include Scarpe::Test::Helpers
|
73
|
+
include Scarpe::Test::DrawableFinders
|
74
|
+
|
75
|
+
def self.instance
|
76
|
+
@instance ||= CCInstance.new
|
77
|
+
end
|
78
|
+
|
79
|
+
def initialize
|
80
|
+
log_init("CatsCradle")
|
81
|
+
|
82
|
+
evented_assertions_initialize
|
83
|
+
|
84
|
+
@waiting_fibers = []
|
85
|
+
@event_promises = {}
|
86
|
+
|
87
|
+
@manager_fiber = Fiber.new do
|
88
|
+
loop do
|
89
|
+
# A fiber can run briefly and then exit. It can run and then block on an API call.
|
90
|
+
# These fibers return promises to indicate to CatsCradle when they can run again.
|
91
|
+
# A fiber that is no longer #alive? is assumed to be successfully finished.
|
92
|
+
@waiting_fibers.each do |fiber_data|
|
93
|
+
next unless fiber_data[:promise].fulfilled?
|
94
|
+
|
95
|
+
@log.debug("Resuming fiber with value #{fiber_data[:promise].returned_value.inspect}")
|
96
|
+
result = fiber_data[:fiber].transfer fiber_data[:promise].returned_value
|
97
|
+
|
98
|
+
# Dead fibers will be removed later, just leave it
|
99
|
+
next unless fiber_data[:fiber].alive?
|
100
|
+
|
101
|
+
case result
|
102
|
+
when ::Scarpe::Promise
|
103
|
+
fiber_data[:promise] = result
|
104
|
+
else
|
105
|
+
raise Scarpe::UnexpectedFiberTransferError, "Unexpected object returned from Fiber#transfer for still-living Fiber! #{result.inspect}"
|
106
|
+
end
|
107
|
+
end
|
108
|
+
|
109
|
+
# Throw out dead fibers or those that will never wake
|
110
|
+
@waiting_fibers.select! do |fiber_data|
|
111
|
+
fiber_data[:fiber].alive? && !fiber_data[:promise].rejected?
|
112
|
+
end
|
113
|
+
|
114
|
+
# Done with this iteration
|
115
|
+
Fiber.yield
|
116
|
+
end
|
117
|
+
end
|
118
|
+
end
|
119
|
+
|
120
|
+
# If we add "every" events, that's likely to complicate timing and event_promise handling.
|
121
|
+
EVENT_TYPES = [:init, :next_heartbeat, :next_redraw, :every_heartbeat, :every_redraw]
|
122
|
+
|
123
|
+
# This needs to be called after the basic display service objects exist
|
124
|
+
# and we can find the control interface.
|
125
|
+
def event_init
|
126
|
+
return if @cc_init_done
|
127
|
+
|
128
|
+
@cc_init_done = true
|
129
|
+
|
130
|
+
@control_interface = ::Shoes::DisplayService.display_service.control_interface
|
131
|
+
@wrangler = @control_interface.wrangler
|
132
|
+
|
133
|
+
cc_instance = self # ControlInterface#on_event does an instance eval. We'll reset self with another.
|
134
|
+
|
135
|
+
@control_interface.on_event(:every_heartbeat) do
|
136
|
+
cc_instance.instance_eval do
|
137
|
+
p = @event_promises.delete(:next_heartbeat)
|
138
|
+
p&.fulfilled!
|
139
|
+
|
140
|
+
p = @event_promises.delete(:every_heartbeat)
|
141
|
+
p&.fulfilled!
|
142
|
+
|
143
|
+
# Give every ready fiber a chance to run once.
|
144
|
+
@manager_fiber.resume
|
145
|
+
end
|
146
|
+
end
|
147
|
+
|
148
|
+
@control_interface.on_event(:every_redraw) do
|
149
|
+
cc_instance.instance_eval do
|
150
|
+
p = @event_promises.delete(:next_redraw)
|
151
|
+
p&.fulfilled!
|
152
|
+
|
153
|
+
p = @event_promises.delete(:every_redraw)
|
154
|
+
p&.fulfilled!
|
155
|
+
|
156
|
+
# Give every ready fiber a chance to run once.
|
157
|
+
@manager_fiber.resume
|
158
|
+
end
|
159
|
+
end
|
160
|
+
end
|
161
|
+
|
162
|
+
def event_promise(event)
|
163
|
+
@event_promises[event] ||= ::Scarpe::Promise.new
|
164
|
+
end
|
165
|
+
|
166
|
+
def on_event(event, &block)
|
167
|
+
raise Scarpe::UnknownEventTypeError, "Unknown event type: #{event.inspect}!" unless EVENT_TYPES.include?(event)
|
168
|
+
|
169
|
+
f = Fiber.new do
|
170
|
+
CCInstance.instance.instance_eval(&block)
|
171
|
+
end
|
172
|
+
@waiting_fibers << { promise: event_promise(event), fiber: f }
|
173
|
+
end
|
174
|
+
|
175
|
+
def proxy_for(shoes_drawable)
|
176
|
+
CCProxy.new(shoes_drawable)
|
177
|
+
end
|
178
|
+
|
179
|
+
def die_after(time)
|
180
|
+
t_start = Time.now
|
181
|
+
@die_after = [t_start, time]
|
182
|
+
|
183
|
+
@wrangler.periodic_code("scarpeTestTimeout") do |*_args|
|
184
|
+
t_delta = (Time.now - t_start).to_f
|
185
|
+
if t_delta > time
|
186
|
+
@did_time_out = true
|
187
|
+
@log.warn("die_after - timed out after #{t_delta.inspect} (threshold: #{time.inspect})")
|
188
|
+
return_results(false, "Timed out!")
|
189
|
+
::Shoes::DisplayService.dispatch_event("destroy", nil)
|
190
|
+
end
|
191
|
+
end
|
192
|
+
end
|
193
|
+
|
194
|
+
def wait(promise)
|
195
|
+
raise(Scarpe::InvalidPromiseError, "Must supply a promise to wait!") unless promise.is_a?(::Scarpe::Promise)
|
196
|
+
|
197
|
+
# Wait until this promise is complete before running again
|
198
|
+
@manager_fiber.transfer(promise)
|
199
|
+
end
|
200
|
+
|
201
|
+
# This returns a promise, which can be waited on using wait()
|
202
|
+
def fully_updated
|
203
|
+
@wrangler.promise_dom_fully_updated
|
204
|
+
end
|
205
|
+
|
206
|
+
def dom_html(timeout: 1.0)
|
207
|
+
query_js_value("document.getElementById('wrapper-wvroot').innerHTML", timeout:)
|
208
|
+
end
|
209
|
+
|
210
|
+
def query_js_value(js_code, timeout: 1.0)
|
211
|
+
js_promise = @wrangler.eval_js_async(js_code, timeout:)
|
212
|
+
|
213
|
+
# This promise will return the string, so we can just pass it to #transfer
|
214
|
+
@manager_fiber.transfer(js_promise)
|
215
|
+
end
|
216
|
+
|
217
|
+
def query_js_promise(js_code, timeout: 1.0)
|
218
|
+
@wrangler.eval_js_async(js_code, timeout:)
|
219
|
+
end
|
220
|
+
|
221
|
+
def test_finished(return_results: true)
|
222
|
+
return_assertion_data if return_results
|
223
|
+
|
224
|
+
::Shoes::DisplayService.dispatch_event("destroy", nil)
|
225
|
+
end
|
226
|
+
|
227
|
+
def test_finished_no_results
|
228
|
+
::Shoes::DisplayService.dispatch_event("destroy", nil)
|
229
|
+
end
|
230
|
+
end
|
231
|
+
|
232
|
+
# "Cat's Cradle" is a children's game where they interlace string between
|
233
|
+
# their fingers to make beautiful complicated shapes. The interlacing
|
234
|
+
# of fibers made it a good name for a prototype.
|
235
|
+
|
236
|
+
# An attempt at an experimental Fiber-based testing system to deal with
|
237
|
+
# Shoes, Display and JS all at the same time.
|
238
|
+
#
|
239
|
+
# In general, we'll use Fiber.transfer to bounce control back and forth
|
240
|
+
# between the evented implementations (e.g. waiting for redraw) that
|
241
|
+
# need to return control to Webview, and the procedural test flows
|
242
|
+
# that look far better if we don't do that explicitly.
|
243
|
+
#
|
244
|
+
# Ruby Fiber basic docs: https://ruby-doc.org/core-3.0.0/Fiber.html
|
245
|
+
#
|
246
|
+
# This module is mixed into a test object if we're running CatsCradle-based tests
|
247
|
+
module CatsCradle
|
248
|
+
attr_reader :cc_instance
|
249
|
+
|
250
|
+
def event_init
|
251
|
+
@cc_instance ||= CCInstance.instance
|
252
|
+
@cc_instance.event_init
|
253
|
+
end
|
254
|
+
|
255
|
+
def on_heartbeat(&block)
|
256
|
+
@cc_instance.on_event(:next_heartbeat, &block)
|
257
|
+
end
|
258
|
+
|
259
|
+
def on_every_heartbeat(&block)
|
260
|
+
@cc_instance.on_event(:every_heartbeat, &block)
|
261
|
+
end
|
262
|
+
|
263
|
+
def on_init(&block)
|
264
|
+
@cc_instance.on_event(:init, &block)
|
265
|
+
end
|
266
|
+
|
267
|
+
def on_next_redraw(&block)
|
268
|
+
@cc_instance.on_event(:next_redraw, &block)
|
269
|
+
end
|
270
|
+
end
|
271
|
+
end
|
@@ -0,0 +1,77 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Scarpe
|
4
|
+
class UnknownShoesEventAPIError < Scarpe::Error; end
|
5
|
+
|
6
|
+
class UnknownShapeCommandError < Scarpe::Error; end
|
7
|
+
|
8
|
+
class UnknownBuiltinCommandError < Scarpe::Error; end
|
9
|
+
|
10
|
+
class UnknownEventTypeError < Scarpe::Error; end
|
11
|
+
|
12
|
+
class UnexpectedFiberTransferError < Scarpe::Error; end
|
13
|
+
|
14
|
+
class InvalidPromiseError < Scarpe::Error; end
|
15
|
+
|
16
|
+
class MissingAppError < Scarpe::Error; end
|
17
|
+
|
18
|
+
class MissingDocRootError < Scarpe::Error; end
|
19
|
+
|
20
|
+
class MissingWranglerError < Scarpe::Error; end
|
21
|
+
|
22
|
+
class IllegalSubscribeEventError < Scarpe::Error; end
|
23
|
+
|
24
|
+
class IllegalDispatchEventError < Scarpe::Error; end
|
25
|
+
|
26
|
+
class MissingBlockError < Scarpe::Error; end
|
27
|
+
|
28
|
+
class DuplicateCallbackError < Scarpe::Error; end
|
29
|
+
|
30
|
+
class JSBindingError < Scarpe::Error; end
|
31
|
+
|
32
|
+
class JSInitError < Scarpe::Error; end
|
33
|
+
|
34
|
+
class PeriodicHandlerSetupError < Scarpe::Error; end
|
35
|
+
|
36
|
+
class WebWranglerNotRunningError < Scarpe::Error; end
|
37
|
+
|
38
|
+
class NonexistentEvalResultError < Scarpe::Error; end
|
39
|
+
|
40
|
+
class JSRedrawError < Scarpe::Error; end
|
41
|
+
|
42
|
+
class ConnectionError < Scarpe::Error; end
|
43
|
+
|
44
|
+
class DatagramSendError < Scarpe::Error; end
|
45
|
+
|
46
|
+
class InvalidOperationError < Scarpe::Error; end
|
47
|
+
|
48
|
+
class MissingAttributeError < Scarpe::Error; end
|
49
|
+
|
50
|
+
# This error indicates a problem when running ConfirmedEval
|
51
|
+
class JSEvalError < Scarpe::Error
|
52
|
+
def initialize(data)
|
53
|
+
@data = data
|
54
|
+
super(data[:msg] || (self.class.name + "!"))
|
55
|
+
end
|
56
|
+
end
|
57
|
+
|
58
|
+
# An error running the supplied JS code string in confirmed_eval
|
59
|
+
class JSRuntimeError < JSEvalError; end
|
60
|
+
|
61
|
+
# The code timed out for some reason
|
62
|
+
class JSTimeoutError < JSEvalError; end
|
63
|
+
|
64
|
+
# We got weird or nonsensical results that seem like an error on WebWrangler's part
|
65
|
+
class JSInternalError < JSEvalError; end
|
66
|
+
|
67
|
+
# An error occurred which would normally be handled by shutting down the app
|
68
|
+
class AppShutdownError < Scarpe::Error; end
|
69
|
+
|
70
|
+
class InvalidClassError < Scarpe::Error; end
|
71
|
+
|
72
|
+
class MissingClassError < Scarpe::Error; end
|
73
|
+
|
74
|
+
class EmptyPageNotSetError < Scarpe::Error; end
|
75
|
+
|
76
|
+
class BadDisplayClassType < Scarpe::Error; end
|
77
|
+
end
|
@@ -0,0 +1,121 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require "tempfile"
|
4
|
+
require "json"
|
5
|
+
require "fileutils"
|
6
|
+
|
7
|
+
require "scarpe/components/unit_test_helpers"
|
8
|
+
|
9
|
+
module Scarpe::Test; end
|
10
|
+
|
11
|
+
# We need a separate assertion system for the kind of Scarpe
|
12
|
+
# testing where we start a subprocess, perform the assertion
|
13
|
+
# logic in the subprocess, and then run Minitest in the parent.
|
14
|
+
# It's an unusual setup.
|
15
|
+
module Scarpe::Test::EventedAssertions
|
16
|
+
include Scarpe::Test::HTMLAssertions
|
17
|
+
|
18
|
+
private
|
19
|
+
|
20
|
+
def evented_assertions_initialize
|
21
|
+
@assertion_data = []
|
22
|
+
@assertions_passed = 0
|
23
|
+
@assertions_failed = []
|
24
|
+
end
|
25
|
+
|
26
|
+
public
|
27
|
+
|
28
|
+
def assert(value, msg = nil)
|
29
|
+
msg ||= "Assertion #{value ? "succeeded" : "failed"}"
|
30
|
+
@assertion_data << [(value ? true : false), msg]
|
31
|
+
if value
|
32
|
+
@assertions_passed += 1
|
33
|
+
else
|
34
|
+
@assertions_failed << msg
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
38
|
+
def assert_equal(expected, actual, msg = nil)
|
39
|
+
msg ||= "Expected #{actual.inspect} to equal #{expected.inspect}!"
|
40
|
+
assert actual == expected, msg
|
41
|
+
end
|
42
|
+
|
43
|
+
def assertion_data_as_a_struct
|
44
|
+
{
|
45
|
+
still_pending: 0,
|
46
|
+
succeeded: @assertions_passed,
|
47
|
+
failed: @assertions_failed.size,
|
48
|
+
failures: @assertions_failed,
|
49
|
+
}
|
50
|
+
end
|
51
|
+
|
52
|
+
def test_metadata
|
53
|
+
{}
|
54
|
+
end
|
55
|
+
|
56
|
+
# Assert that `text` includes `subtext`.
|
57
|
+
#
|
58
|
+
# @param text [String] the longer text
|
59
|
+
# @param subtext [String] the text that is asserted to be included
|
60
|
+
# @param msg [String,nil] if supplied, the failure message for the assertion
|
61
|
+
# @return [void]
|
62
|
+
def assert_include(text, subtext, msg = nil)
|
63
|
+
msg ||= "Expected #{text.inspect} to include #{subtext.inspect}"
|
64
|
+
assert text.include?(subtext), msg
|
65
|
+
end
|
66
|
+
|
67
|
+
# Assert that `text` does not include `subtext`.
|
68
|
+
#
|
69
|
+
# @param text [String] the longer text
|
70
|
+
# @param subtext [String] the text that is asserted to not be included
|
71
|
+
# @param msg [String,nil] if supplied, the failure message for the assertion
|
72
|
+
# @return [void]
|
73
|
+
def assert_not_include(text, subtext, msg = nil)
|
74
|
+
msg ||= "Expected #{text.inspect} not to include #{subtext.inspect}"
|
75
|
+
assert !text.include?(subtext), msg
|
76
|
+
end
|
77
|
+
|
78
|
+
def return_assertion_data
|
79
|
+
if !@assertions_failed.empty?
|
80
|
+
return_results(false, "Assertions failed", assertion_data_as_a_struct)
|
81
|
+
elsif @assertions_passed > 0
|
82
|
+
return_results(true, "All assertions passed", assertion_data_as_a_struct)
|
83
|
+
else
|
84
|
+
return_results(true, "Test finished successfully")
|
85
|
+
end
|
86
|
+
end
|
87
|
+
|
88
|
+
# This does a final return of results. If it gets called
|
89
|
+
# multiple times with different results, the test fails because that's not allowed.
|
90
|
+
#
|
91
|
+
# @param result_bool [Boolean] true if the results are success, false if failure
|
92
|
+
# @param msg [String] the message included with the results
|
93
|
+
# @param data [Hash] any additional data to pass with the results
|
94
|
+
# @return void
|
95
|
+
def return_results(result_bool, msg, data = {})
|
96
|
+
result_file = ENV["SCARPE_TEST_RESULTS"] || "./scarpe_results.txt"
|
97
|
+
|
98
|
+
result_structs = [result_bool, msg, data.merge(test_metadata)]
|
99
|
+
if File.exist?(result_file)
|
100
|
+
results_returned = JSON.parse File.read(result_file)
|
101
|
+
end
|
102
|
+
|
103
|
+
# Multiple different sets of results is bad, even if both are passing.
|
104
|
+
if results_returned && results_returned[0..1] != result_structs[0..1]
|
105
|
+
# Just raising here doesn't reliably fail the test.
|
106
|
+
# See: https://github.com/scarpe-team/scarpe/issues/212
|
107
|
+
Shoes::Log.logger("Test Results").error("Writing multi-result failure file to #{result_file.inspect}!")
|
108
|
+
|
109
|
+
new_res_data = { first_result: results_returned, second_result: result_structs }.merge(test_metadata)
|
110
|
+
bad_result = [false, "Returned two sets of results!", new_res_data]
|
111
|
+
File.write(result_file, JSON.pretty_generate(bad_result))
|
112
|
+
|
113
|
+
return
|
114
|
+
elsif results_returned
|
115
|
+
Shoes::Log.logger("Test Results").warn "Returning identical results twice: #{results_returned.inspect}"
|
116
|
+
end
|
117
|
+
|
118
|
+
Shoes::Log.logger("Test Results").debug("Writing results file #{result_file.inspect} to disk!")
|
119
|
+
File.write(result_file, JSON.pretty_generate(result_structs))
|
120
|
+
end
|
121
|
+
end
|
@@ -0,0 +1,181 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require "minitest"
|
4
|
+
require "scarpe/cats_cradle"
|
5
|
+
require "scarpe/components/string_helpers"
|
6
|
+
|
7
|
+
require "scarpe/components/unit_test_helpers"
|
8
|
+
|
9
|
+
# Test framework code to allow Scarpe to execute Shoes-Spec test code.
|
10
|
+
# This will run inside the exe/scarpe child process, then send
|
11
|
+
# results back to the parent Minitest process.
|
12
|
+
|
13
|
+
module Scarpe::Test
|
14
|
+
# Is it at all reasonable to define more than one test to run in the same Shoes run? Probably not.
|
15
|
+
# They'll leave in-memory residue.
|
16
|
+
def self.run_shoes_spec_test_code(code, class_name: nil, test_name: nil)
|
17
|
+
if @shoes_spec_init
|
18
|
+
raise Shoes::Errors::MultipleShoesSpecRunsError, "Scarpe-Webview can only run a single Shoes spec per process!"
|
19
|
+
end
|
20
|
+
|
21
|
+
@shoes_spec_init = true
|
22
|
+
|
23
|
+
require "scarpe/components/minitest_export_reporter"
|
24
|
+
Minitest::Reporters::ShoesExportReporter.activate!
|
25
|
+
|
26
|
+
class_name ||= ENV["SHOES_MINITEST_CLASS_NAME"] || "TestShoesSpecCode"
|
27
|
+
test_name ||= ENV["SHOES_MINITEST_METHOD_NAME"] || "test_shoes_spec"
|
28
|
+
|
29
|
+
require_relative "cats_cradle"
|
30
|
+
|
31
|
+
# We want Minitest assertions available in the test code.
|
32
|
+
# But this will normally run in a subprocess. So we need
|
33
|
+
# to run Minitest tests and then export the results.
|
34
|
+
|
35
|
+
# We create a test object based on CatsCradle, which will
|
36
|
+
# run the test as straight-line code, wait for appropriate
|
37
|
+
# events and generally make things well-behaved. But the
|
38
|
+
# test DSL isn't CatsCradle. It's based on Minitest and
|
39
|
+
# ShoesSpecTest (see below).
|
40
|
+
#
|
41
|
+
# Note that that means that using CatsCradle to "bounce"
|
42
|
+
# control back and forth for evented tricks isn't really
|
43
|
+
# an option. We may need to revisit all of this later...
|
44
|
+
test_obj = Object.new
|
45
|
+
class << test_obj
|
46
|
+
include Scarpe::Test::CatsCradle
|
47
|
+
end
|
48
|
+
Scarpe::ShoesSpecTest.test_obj = test_obj
|
49
|
+
test_obj.instance_eval do
|
50
|
+
event_init
|
51
|
+
|
52
|
+
on_heartbeat do
|
53
|
+
Minitest.run ARGV
|
54
|
+
|
55
|
+
test_finished_no_results
|
56
|
+
Scarpe::ShoesSpecTest.test_obj = nil
|
57
|
+
end
|
58
|
+
end
|
59
|
+
|
60
|
+
test_class = Class.new(Scarpe::ShoesSpecTest)
|
61
|
+
Object.const_set(Scarpe::Components::StringHelpers.camelize(class_name), test_class)
|
62
|
+
test_name = "test_" + test_name unless test_name.start_with?("test_")
|
63
|
+
test_class.define_method(test_name) do
|
64
|
+
eval(code)
|
65
|
+
end
|
66
|
+
end
|
67
|
+
end
|
68
|
+
|
69
|
+
# This is based on the CatsCradle proxies initially, but will diverge over time
|
70
|
+
class Scarpe::ShoesSpecProxy
|
71
|
+
attr_reader :obj
|
72
|
+
attr_reader :linkable_id
|
73
|
+
attr_reader :display
|
74
|
+
|
75
|
+
JS_EVENTS = [:click, :hover, :leave, :change]
|
76
|
+
|
77
|
+
def initialize(obj)
|
78
|
+
@obj = obj
|
79
|
+
@linkable_id = obj.linkable_id
|
80
|
+
@display = ::Shoes::DisplayService.display_service.query_display_drawable_for(obj.linkable_id)
|
81
|
+
|
82
|
+
unless @display
|
83
|
+
raise "Can't find display widget for #{obj.inspect}!"
|
84
|
+
end
|
85
|
+
end
|
86
|
+
|
87
|
+
def method_missing(method, ...)
|
88
|
+
if @obj.respond_to?(method)
|
89
|
+
self.singleton_class.define_method(method) do |*args, **kwargs, &block|
|
90
|
+
@obj.send(method, *args, **kwargs, &block)
|
91
|
+
end
|
92
|
+
send(method, ...)
|
93
|
+
else
|
94
|
+
super # raise an exception
|
95
|
+
end
|
96
|
+
end
|
97
|
+
|
98
|
+
def trigger(event_name, *args)
|
99
|
+
name = "#{@linkable_id}-#{event_name}"
|
100
|
+
Scarpe::Webview::DisplayService.instance.app.handle_callback(name, *args)
|
101
|
+
end
|
102
|
+
|
103
|
+
JS_EVENTS.each do |ev|
|
104
|
+
define_method "trigger_#{ev}" do |*args|
|
105
|
+
trigger(ev, *args)
|
106
|
+
end
|
107
|
+
end
|
108
|
+
|
109
|
+
def respond_to_missing?(method_name, include_private = false)
|
110
|
+
@obj.respond_to_missing?(method_name, include_private)
|
111
|
+
end
|
112
|
+
end
|
113
|
+
|
114
|
+
# When running ShoesSpec tests, we create a parent class for all of them
|
115
|
+
# with the appropriate convenience methods and accessors.
|
116
|
+
class Scarpe::ShoesSpecTest < Minitest::Test
|
117
|
+
include Scarpe::Test::HTMLAssertions
|
118
|
+
|
119
|
+
class << self
|
120
|
+
attr_accessor :test_obj
|
121
|
+
end
|
122
|
+
Shoes::Drawable.drawable_classes.each do |drawable_class|
|
123
|
+
finder_name = drawable_class.dsl_name
|
124
|
+
|
125
|
+
define_method(finder_name) do |*args|
|
126
|
+
app = Shoes::App.instance
|
127
|
+
|
128
|
+
drawables = app.find_drawables_by(drawable_class, *args)
|
129
|
+
raise Shoes::Errors::MultipleDrawablesFoundError, "Found more than one #{finder_name} matching #{args.inspect}!" if drawables.size > 1
|
130
|
+
raise Shoes::Errors::NoDrawablesFoundError, "Found no #{finder_name} matching #{args.inspect}!" if drawables.empty?
|
131
|
+
|
132
|
+
Scarpe::ShoesSpecProxy.new(drawables[0])
|
133
|
+
end
|
134
|
+
end
|
135
|
+
def drawable(*specs)
|
136
|
+
drawables = app.find_drawables_by(*specs)
|
137
|
+
raise Scarpe::MultipleDrawablesFoundError, "Found more than one #{finder_name} matching #{args.inspect}!" if drawables.size > 1
|
138
|
+
raise Scarpe::NoDrawablesFoundError, "Found no #{finder_name} matching #{args.inspect}!" if drawables.empty?
|
139
|
+
|
140
|
+
Scarpe::ShoesSpecProxy.new(drawables[0])
|
141
|
+
end
|
142
|
+
|
143
|
+
def catscradle_dsl(&block)
|
144
|
+
Scarpe::Test::CCInstance.instance.instance_eval(&block)
|
145
|
+
end
|
146
|
+
|
147
|
+
def dom_html
|
148
|
+
catscradle_dsl do
|
149
|
+
wait fully_updated
|
150
|
+
dom_html
|
151
|
+
end
|
152
|
+
end
|
153
|
+
|
154
|
+
# This isn't working. Neither is calling die_after. Are the other fibers not
|
155
|
+
# running or something like that? Should run a test from the command line
|
156
|
+
# and see what's happening... Or check logfiles?
|
157
|
+
def timeout(t_timeout = 5.0, exit_code: -1)
|
158
|
+
catscradle_dsl do
|
159
|
+
t0 = Time.now
|
160
|
+
on_event(:every_heartbeat) do
|
161
|
+
if Time.now - t0 >= t_timeout
|
162
|
+
if exit_code == 0
|
163
|
+
@log.info "Timed out after #{t_timeout} seconds!"
|
164
|
+
else
|
165
|
+
@log.error "Timed out after #{t_timeout} seconds!"
|
166
|
+
end
|
167
|
+
exit exit_code
|
168
|
+
end
|
169
|
+
end
|
170
|
+
end
|
171
|
+
end
|
172
|
+
|
173
|
+
def exit_on_first_heartbeat(exit_code: 0)
|
174
|
+
catscradle_dsl do
|
175
|
+
on_event(:next_heartbeat) do
|
176
|
+
@log.info "Exiting on first heartbeat (exit code #{exit_code})"
|
177
|
+
exit exit_code
|
178
|
+
end
|
179
|
+
end
|
180
|
+
end
|
181
|
+
end
|
data/lib/scarpe/version.rb
CHANGED