Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve Rails::Generators::Actions logging and debugging #49490

Merged
merged 1 commit into from
Oct 16, 2023

Conversation

stevepolitodesign
Copy link
Contributor

Motivation / Background

This commit is a follow-up to #49448, with regards to this comment.

Prior to this commit, logging and debugging for
Rails::Generators::Actions was limited even when enabling RAILS_LOG_TO_STDOUT. This was because the private action method in the corresponding test was capturing $stdout.

Before

CleanShot.2023-10-04.at.19.49.42.mp4

After

CleanShot.2023-10-04.at.19.50.14.mp4

Detail

We simply conditionally capture the stdout like we did in #49448.

4220d82e93 Improve generator logging and debugging
diff --git a/railties/test/generators/actions_test.rb b/railties/test/generators/actions_test.rb
index 6b5cdcf781..51a006ca87 100644
--- a/railties/test/generators/actions_test.rb
+++ b/railties/test/generators/actions_test.rb
@@ -720,7 +720,11 @@ def test_log_with_status_with_quiet
 
   private
     def action(...)
-      capture(:stdout) { generator.send(...) }
+      if ENV["RAILS_LOG_TO_STDOUT"] == "true"
+        generator.send(...)
+      else
+        capture(:stdout) { generator.send(...) }
+      end
     end
 
     def revoke(...)

Additional information

It's possible other call sites in the test suite need to be updated, but I wanted to keep this commit focused.

Checklist

Before submitting the PR make sure the following are checked:

  • This Pull Request is related to one change. Changes that are unrelated should be opened in separate PRs.
  • Commit message has a detailed description of what changed and why. If this PR fixes a related issue include it in the commit message. Ex: [Fix #issue-number]
  • Tests are added or updated if you fix a bug or add a feature.
  • CHANGELOG files are updated for the changed libraries if there is a behavior change or additional feature. Minor bug fixes and documentation changes should not be included.

@rails-bot rails-bot bot added the railties label Oct 4, 2023
This commit is a follow-up to rails#49448, with regards to [this comment][].

Prior to this commit, logging and debugging for
[Rails::Generators::Actions][] was limited even when enabling
`RAILS_LOG_TO_STDOUT`. This was because the private `action` method in
the corresponding test was capturing `$stdout`.

[this comment]: rails#49448 (comment)
[Rails::Generators::Actions]: https://api.rubyonrails.org/v7.0.8/classes/Rails/Generators/Actions.html
@@ -720,7 +720,11 @@ def test_log_with_status_with_quiet

private
def action(...)
capture(:stdout) { generator.send(...) }
if ENV["RAILS_LOG_TO_STDOUT"] == "true"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we usually use == "true" or do we want to just assert this is not nil? I've seen people using env vars like RAILS_LOG_TO_STDOUT=1 some_command

Suggested change
if ENV["RAILS_LOG_TO_STDOUT"] == "true"
if !ENV["RAILS_LOG_TO_STDOUT"].nil?

Or, if we wanna go the Active Support route:

Suggested change
if ENV["RAILS_LOG_TO_STDOUT"] == "true"
if ENV["RAILS_LOG_TO_STDOUT"].present?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In #49448 we look for "true", so this commit is consistent with that one.

My original thinking was I didn't want something like RAILS_LOG_TO_STDOUT=FALSE ./bin/test test/generators/actions_test.rb to work.

@kamipo kamipo merged commit 2e40616 into rails:main Oct 16, 2023
4 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants