Skip to content

Commit

Permalink
Force generators to abort if they fail.
Browse files Browse the repository at this point in the history
Rails does not seem to provide a clean way to abort something if a
generator fails. Under most circumstances this is probably the proper
solution.

However, for us, these generators calls also function as smoke tests for
our actual generator code. If one of them fails, we need to fail the
build. Thankfully, if the generator had a problem the status is captured
in `$?`. We can verify that the last process was successful and abort
when it is not; thus failing the build and notifying the team.
  • Loading branch information
cupakromer committed Dec 28, 2014
1 parent a13ed43 commit 2fd7b70
Showing 1 changed file with 5 additions and 0 deletions.
5 changes: 5 additions & 0 deletions example_app_generator/generate_stuff.rb
Expand Up @@ -49,6 +49,11 @@ def self.environment_hooks
end
end

def generate(*)
super
$?.success? || abort
end

# Generally polluting `main` is bad as it monkey patches all objects. In this
# context, `self` is an _instance_ of a `Rails::Generators::AppGenerator`. So
# this won't pollute anything.
Expand Down

0 comments on commit 2fd7b70

Please sign in to comment.