Skip to content

Make UnexpectedNilError un-rescueable from tests #20

Description

@amomchilov

It currently inherits from Exception, so that a bare rescue => e doesn't unintentionally rescue it. We've already run into a real-world case where that proved useful, where a fork of the not_nil! implementation made it derive from StandardError, which indeed hid a test failure (only detected because we switched that copy of the code to use Type Toolkit).

To make it truly uncatchable, we can do something like throw Object.new. In a production app, this would crash your Rails app with UncaughtThrowError, so we'd have to limit it to tests. But we also don't want to crash minitest/RSpec, so we'd need to wrap the test runner in a catch call. We would need some kind of secret-ish tag to throw, that only the test runner can catch.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions