How to catch a fail that does not stop the run
A step reads fail(:deck_full) if deck.full?, and the line below it runs regardless. Plain verbs only record an outcome and carry on, and the bang forms are the ones that stop. The cop spots the slip without executing anything.
RuboCop is not in the site’s bundle, so everything on this page is plain code.
1. Enable the cop
Section titled “1. Enable the cop”On RuboCop 1.72 or newer, load the plugin from .rubocop.yml:
plugins: - actionable-rb: require_path: actionable/rubocopOlder RuboCop versions take require: [actionable/rubocop] instead. Once loaded, the cop is on.
2. Tell it about your base classes
Section titled “2. Tell it about your base classes”Out of the box it treats subclasses of Actionable::Action and ApplicationAction as actions. Setting the option replaces that list, so repeat any default you still rely on.
Actionable/VerbNotLast: ActionBaseClasses: - Actionable::Action - ApplicationAction - Harbour::BaseActionA class in the same file counts as well, when its superclass chain reaches one of these.
3. Fix what it reports
Section titled “3. Fix what it reports”The offense lands on the call node and carries this message:
`fail` records the outcome and keeps running, and more code runs after it: use `fail!` to stop here, or make it the method's last expression.Most of the time the fix is the bang form.
# beforedef assign_berth fail(:deck_full) if deck.full? record_boardingend
# afterdef assign_berth fail!(:deck_full) if deck.full? record_boardingendA plain verb is fine as the last statement of a method or a branch, after return, and on a different receiver. Bang verbs are never flagged.
4. Know the runtime check
Section titled “4. Know the runtime check”The same rule also runs without RuboCop. On the first .run, the action class reads its step and hook methods and raises Actionable::DefinitionError that names every offense, so any spec that runs the action will catch it. The cop’s job is to catch it sooner, in the editor and on each pull request.
See also
Section titled “See also”FieldStruct, Actionable and their adapters are open source under the MIT license.