-
Notifications
You must be signed in to change notification settings - Fork 21.5k
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 railties' tests #30595
Improve railties' tests #30595
Conversation
r? @eileencodes (@rails-bot has picked a reviewer for you, use r? to override) |
b14bea6
to
dfbdd2a
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There are several very different changes going on in a single commit here, and instead of describing any of them, the title of the commit is just copied from the other PR.
135782d
to
97c9ebe
Compare
97c9ebe
to
1bbc858
Compare
@matthewd Thanks for the correcting, I just split up changes to commits with explanations. |
@@ -40,7 +40,7 @@ def test_not_protected_when_previous_migration_was_not_production | |||
with_rails_env "test" do | |||
rails "generate", "model", "product", "name:string" | |||
rails "db:create", "db:migrate" | |||
output = Dir.chdir(app_path) { rails("db:test:prepare", "test") } | |||
output = rails("db:test:prepare", allow_failure: true) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this currently raising? What failure do we need to allow? 😕
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If for some reason db:test:prepare
fails, the code below
refute_match(/ActiveRecord::ProtectedEnvironmentError/, output)
won't be executed
instead we will see error
RuntimeError: rails command failed (1): bin/rails db:test:prepare 2>&1
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why would that be a bad thing?
If the command fails, I want the test to fail, not pass just because the failure doesn't contain that string.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Because if leave it as it is and db:test:prepare
fails for some reason(for example: adding bad changes in a PR)
this line will never be executed
refute_match(/ActiveRecord::ProtectedEnvironmentError/, output)
so if db:test:prepare
raise ActiveRecord::ProtectedEnvironmentError
or any antother error, test status will be as error
but not as failure
or passed
.
In this way, this test doesn't check what we expect.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If there is an error in that command, then an error has occurred, and so 'error' would be the correct result for the test.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@matthewd I just removed the changes
1bbc858
to
6ff99e4
Compare
@@ -40,7 +40,7 @@ def test_not_protected_when_previous_migration_was_not_production | |||
with_rails_env "test" do | |||
rails "generate", "model", "product", "name:string" | |||
rails "db:create", "db:migrate" | |||
output = Dir.chdir(app_path) { rails("db:test:prepare", "test") } | |||
output = rails("db:test:prepare") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Again, I think this is important to ensure test
actually works, because our only assertion is a loose non-match.
It's really not good to make changes to tests just because you don't think something needs to be there.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@matthewd do we have to return back execution of bin/rails test
that was removed by https://github.com/rails/rails/pull/30520/files#diff-e1c35224a4df7f73d90a9a90e45aab2bL32?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No. That one is never reached, because the prepare fails. And the following assertion is positive ("this must be there"), not negative ("this specific string should not be").
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I deleted the changes
1f1098f
to
6ff99e4
Compare
@matthewd This PR is ready for review. |
assert system("bin/rails do_nothing RAILS_ENV=production"), | ||
"should not be pre-required for rake even eager_load=true" | ||
end | ||
assert rails("do_nothing" "RAILS_ENV=production"), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Asserting on a value that's always true isn't very useful.
.. and this is missing a comma, so it's also not running the command it intends to.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@matthewd Should I just leave rails("do_nothing", "RAILS_ENV=production")
without assert
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hmm.. maybe we should make do_nothing
do a puts, then assert on that. That way it would've caught the missing comma.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hmm.. maybe we should make do_nothing do a puts, then assert on that. That way it would've caught the missing comma.
Good idea! Done.
…Generation#rails See rails#30520
- Remove redundant setting `RAILS_ENV` for `db:test:prepare`. `db:test:prepare` doesn't require it.
6ff99e4
to
2329207
Compare
Dir.chdir(app_path) { }
in railties' testsImprove RakeTest#test_not_protected_when_previous_migration_was_not_productionAllow failure for
db:test:prepare
to ensure the test woun't raise error:RuntimeError: rails command failed (1): bin/rails db:test:prepare 2>&1
Prevent redundant execution ofbin/rails test
inside the testSee Run in-app rails commands via fork+load where possible #30520
RAILS_ENV
fordb:test:prepare
.db:test:prepare
doesn't require it./cc @matthewd