Skip to content

Run spec suite in macro finished hook instead of at_exit #14121

Open
@straight-shoota

Description

@straight-shoota

The execution of specs currently runs in an at_exit handler. It means the main program itself is basically empty, except for maybe some setup code. And I presume that's the reason why specs run in at_exit because it ensures it runs after any other top-level code, regardless of require order. Conceptually however, the spec runner is the actual main program, yet it only starts when the process is already exiting.
This seems to be a bit of a hack and can interfere with other at_exit handlers (#13763 (comment)).

Ideally, the spec runner should execute after any other top-level code but before any other at_exit handlers.

This seems like a good fit for macro finished, which essentially moves its code block to the end of the main program.

Running the spec suite directly from a macro finished hook should be largely equivalent to at_exit. It would be semantically cleaner and there would be no contention with other actual at_exit handlers.

Of course, in exchange, there will be contention with other macro finished hooks. But I figure that should not be as much hassle as with at_exit. Most uses of macro finished are for defining methods or constants based on other features defined previously and the purpose of the macro finished is to move the concluding code after the code it relates to. But there's usually no global aspect (in constrast to at_exit which affects the entire program). This should typically not interfere with the spec usage at all.

In order to be on the safe side, it would also be possible to nest macro finished, which moves the nested block at the very end even after all "single-level" macro finished.

macro finished
  macro finished
    puts "3"
  end
end

macro finished
  puts "1"
end

macro finished
  puts "2"
end

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions