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

Fix class level loading #70

Merged
merged 7 commits into from
Jan 6, 2024
Merged

Fix class level loading #70

merged 7 commits into from
Jan 6, 2024

Conversation

kaspth
Copy link
Owner

@kaspth kaspth commented Jan 1, 2024

When doing a self.class.seed from within a test, we'd be within the Test Class scope, so the @loader variable would assign there and and not on Oaken::Seeds.loader.

The old structure was a little muddy anyway, so this attempts a rewrite that's hopefully clearer.

Now we'll always be within Oaken::Seeds' singleton_class.

Note: originally the point about injecting load_onto Oaken::Seeds was so you could potentially have other seeds modules, so you could have your app seeds split up ala Packwerk. But it doesn't really work and it's kinda unclear how I'd make it work, so it's probably better to yank it in a bit.

cc @tcannonfodder

delegate :entry, to: :loader
class << self
# Expose a class `seed` method for individual test classes to use.
# TODO: support parallelization somehow.
Copy link
Collaborator

Choose a reason for hiding this comment

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

So I think this approach actually is the best way forward for supporting parallelization. My reason being that it's called on a per-test basis. Tests are already broken up into individual units of work from a parallelization perspective. Having the seed method be called on a per-test basis (or in a setup/before block, which is also called on an individual unit of work) helps reinforce test isolation. That:

  • Reduces the amount of junk data that's generated for unrelated tests
  • Makes it easier to debug a particular test
  • Reduces test flakiness
  • Encourages writing seed files for specific edge-case scenarios

Copy link
Owner Author

Choose a reason for hiding this comment

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

@tcannonfodder I added this as a recommendation and explanation in 6ed2503

Copy link
Owner Author

@kaspth kaspth Jan 11, 2024

Choose a reason for hiding this comment

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

I think the README needs a general rinse but I liked the list you had and wanted that in there now. Though the writing I ended up with reads a bit like people should always have per-test seed files, which is not always the case.

When doing a `self.class.seed` from within a test, we'd be within the Test Class scope, so the `@loader` variable would assign there and
and not on `Oaken::Seeds.loader`.

The old structure was a little muddy anyway, so this attempts a rewrite that's hopefully clearer.

Now we'll always be within `Oaken::Seeds`' `singleton_class`.

Note: originally the point about injecting `load_onto Oaken::Seeds` was so you could potentially have other seeds modules, so you could have your app seeds split up ala Packwerk.
But it doesn't really work and it's kinda unclear how I'd make it work, so it's probably better to yank it in a bit.
@kaspth kaspth merged commit 1f8d335 into main Jan 6, 2024
2 checks passed
@kaspth kaspth deleted the fix-class-level-loading branch January 6, 2024 18:27
kaspth added a commit that referenced this pull request Jan 11, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants