ae_page_objects icon indicating copy to clipboard operation
ae_page_objects copied to clipboard

AePageObjects::Document blows up with unclear error message when load ensuring

Open leoskyrocker opened this issue 9 years ago • 5 comments

Demo: https://github.com/appfolio/ae_page_objects/commit/033919974ce9c7972d5dcbf04c3d9a6db88398dd

STR

  1. Create a page object document like this that has 2 paths: 1st path is a valid path, 2nd path does not exist in the app.
  2. In the test, go visit a url that does not match the first path of the above page object.
  3. Instantiate the page object you created above, e.g. DummyShowPageWithUnresolvablePath.new

O

NoMethodError: undefined method `requirements' for nil:NilClass
    /Users/leolei/src/ae_page_objects/lib/ae_page_objects/core/application_router.rb:48:in `resolve_named_route'
    /Users/leolei/src/ae_page_objects/lib/ae_page_objects/core/application_router.rb:18:in `recognizes?'
    /Users/leolei/src/ae_page_objects/lib/ae_page_objects/core/application_router.rb:117:in `path_recognizes_url?'
    /Users/leolei/src/ae_page_objects/lib/ae_page_objects/core/site.rb:47:in `path_recognizes_url?'
    /Users/leolei/src/ae_page_objects/lib/ae_page_objects/document.rb:10:in `block in can_load_from_current_url?'
    /Users/leolei/src/ae_page_objects/lib/ae_page_objects/document.rb:9:in `any?'
    /Users/leolei/src/ae_page_objects/lib/ae_page_objects/document.rb:9:in `can_load_from_current_url?'
    /Users/leolei/src/ae_page_objects/lib/ae_page_objects/document.rb:66:in `block in ensure_loaded!'
    /Users/leolei/src/ae_page_objects/lib/ae_page_objects.rb:67:in `wait_until'
    /Users/leolei/src/ae_page_objects/lib/ae_page_objects/document.rb:66:in `ensure_loaded!'
    /Users/leolei/src/ae_page_objects/lib/ae_page_objects/node.rb:19:in `initialize'
    /Users/leolei/src/ae_page_objects/lib/ae_page_objects/document.rb:48:in `initialize'
    test/selenium/page_object_integration_test.rb:28:in `new'
    test/selenium/page_object_integration_test.rb:28:in `test_load_ensuring'
    minitest (5.8.4) lib/minitest/test.rb:108:in `block (3 levels) in run'
    minitest (5.8.4) lib/minitest/test.rb:205:in `capture_exceptions'
    minitest (5.8.4) lib/minitest/test.rb:105:in `block (2 levels) in run'
    minitest (5.8.4) lib/minitest/test.rb:256:in `time_it'
    minitest (5.8.4) lib/minitest/test.rb:104:in `block in run'
    minitest (5.8.4) lib/minitest.rb:331:in `on_signal'
    minitest (5.8.4) lib/minitest/test.rb:276:in `with_info_handler'
    minitest (5.8.4) lib/minitest/test.rb:103:in `run'
    minitest (5.8.4) lib/minitest.rb:778:in `run_one_method'
    minitest (5.8.4) lib/minitest.rb:305:in `run_one_method'
    minitest (5.8.4) lib/minitest.rb:293:in `block (2 levels) in run'
    minitest (5.8.4) lib/minitest.rb:292:in `each'
    minitest (5.8.4) lib/minitest.rb:292:in `block in run'
    minitest (5.8.4) lib/minitest.rb:331:in `on_signal'
    minitest (5.8.4) lib/minitest.rb:318:in `with_info_handler'
    minitest (5.8.4) lib/minitest.rb:291:in `run'
    minitest (5.8.4) lib/minitest.rb:152:in `block in __run'
    minitest (5.8.4) lib/minitest.rb:152:in `map'
    minitest (5.8.4) lib/minitest.rb:152:in `__run'
    minitest (5.8.4) lib/minitest.rb:129:in `run'
    minitest (5.8.4) lib/minitest.rb:56:in `block in autorun'

D A better error message, telling the user they actually put in a path that's not found. (It's really hard to debug if someone run into this, and it was a typo).

leoskyrocker avatar May 07 '16 00:05 leoskyrocker

On another thought, is there any reasons that we allow invalid paths at all rather than failing fast? (I could only reproduce this when it fails to hit the first path, whereas it would be nice if it failed fast no matter what, so that people don't leave in unexpected paths that actually are not valid anymore.)

leoskyrocker avatar May 07 '16 00:05 leoskyrocker

On another thought, is there any reasons that we allow invalid paths at all rather than failing fast? (I could only reproduce this when it fails to hit the first path, whereas it would be nice if it failed fast no matter what, so that people don't leave in unexpected paths that actually are not valid anymore.)

What do you have in mind for "failing fast"? Paths are specified during class definition, which may be before the router is hooked up.

dtognazzini avatar May 10 '16 16:05 dtognazzini

I see. Could we iterate the paths and check when the Document is initialized? If we did this we can ensure the Document contains valid paths on instantiation, and so that we don't have a partially corrupted Document object throughout the usage.

leoskyrocker avatar May 10 '16 18:05 leoskyrocker

We could do this, but it would incur overhead every time a Document was created. We could optimize that with caching. On the spectrum of discovering paths from earliest to latest, this would be somewhere in the middle. I'm not sure if it's worth it.

dtognazzini avatar May 11 '16 19:05 dtognazzini

That is true, given that we are going to have a clearer message, this might not be a big issue.

leoskyrocker avatar May 17 '16 06:05 leoskyrocker