Stop stubbing a private generator method to silence Thor command noise - #1821
Merged
nbulaj merged 1 commit intoMay 19, 2026
Merged
Conversation
Stubbing the private PreviousRefreshTokenGenerator#no_previous_refresh_token_column?
method via allow_any_instance_of transiently (re)defines it on the Thor
generator class. That triggers Thor's method_added hook, which registers
it as a runnable command; when Thor::Group#invoke_all later runs every
command, Thor::Command#run finds the method private and emits
Could not find command "no_previous_refresh_token_column?".
to stdout during the test suite.
Stub the underlying ActiveRecord column check
(ActiveRecord::Base.connection.column_exists?) instead, so no method is
(re)defined on the generator class. The noise is gone, the test intent is
preserved, and the 'column already exists' case is now deterministic
rather than depending on the test schema state.
55728
force-pushed
the
55728/fix/generator-spec-thor-command-noise
branch
from
May 19, 2026 14:14
b7db7df to
d988a01
Compare
Member
|
🙇 |
Contributor
Author
|
Thanks a lot 😊 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Running the test suite prints this line twice:
It comes from
spec/generators/previous_refresh_token_generator_spec.rb, which stubs the private methodPreviousRefreshTokenGenerator#no_previous_refresh_token_column?viaallow_any_instance_of(...).to receive(:no_previous_refresh_token_column?).Root cause
It is not a bug in Doorkeeper's generator code, and it never happens when a real user runs
rails generate doorkeeper:previous_refresh_token. It is an interaction between RSpec and Thor that only occurs in the spec:allow_any_instance_of(...).to receive(:no_previous_refresh_token_column?)(re)defines that method on the generator class.Thor::Base.method_added, which registers the (transiently public) method as a runnable command.run_generator→Thor::Group#invoke_alliterates over every registered command and callsThor::Command#run.Thor::Command#runhits theprivate_method?(instance)branch and callshandle_no_command_error, which printsCould not find command "no_previous_refresh_token_column?".So the trigger is "stub a private method on a Thor generator via
allow_any_instance_of". Neither Thor nor RSpec is strictly misbehaving; the test just shouldn't stub the method under test on a Thor class.Fix
Stub the underlying database dependency that
no_previous_refresh_token_column?wraps (ActiveRecord::Base.connection.column_exists?) instead of the private method itself. No method is (re)defined on the generator class, so Thor never registers a spurious command and the noise disappears.Bonus: the "column already exists" example now stubs
column_exists? => trueexplicitly instead of relying onand_call_originalagainst the test schema, making it deterministic.Behavior change
None for the generator. Test-only change; the same scenarios are covered:
Testing
bundle exec rspec spec/generators/previous_refresh_token_generator_spec.rb→ 2 examples, 0 failures.
bundle exec rspec→ 1295 examples, 0 failures, and theCould not find command "..."line no longer appears anywhere in the output.bundle exec rubocop spec/generators/previous_refresh_token_generator_spec.rb→ no offenses.