Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Include DatabaseCleaner usage when demoing FactoryGirl.lint
Because built factories create associated records, the database may not be empty when the suite is run. This encourages developers to start DatabaseCleaner and clean after linting is complete to ensure a clean database. Closes #619, #611, #620
- Loading branch information
7f31ba9
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.
Can confirm this is still happening.
7f31ba9
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.
Based on @joshuaclayton's patch, this is a workaround, that can be placed in the spec_helper.rb:
config.before(:suite) do
begin
DatabaseCleaner.start
FactoryGirl.lint
ensure
DatabaseCleaner.clean
end
end
7f31ba9
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.
Hi
I would say it is better to create separate spec file
spec/lint_spec.rb
with:In this case the references to
DatabaseCleaner
not needed, because the default cleaning strategy will be applied (for exampleconfig.use_transactional_fixtures = true
will work as well).And you can run it only on purpose, ( but not before any test run which may don't use factories at all)
7f31ba9
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.
@mshytikov I dig this idea - especially when there are other mechanisms for stubbing external requests and other similarly tricky issues. Thanks for sharing!
7f31ba9
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.
Thanks a lot @mshytikov! Perfect solution. I also want to point out that it took me a bit of time to track down FactoryGirl.lint as the source of this problem, and even then it was on a hunch. @joshuaclayton maybe you could consider adding a warning to the lint section in the FactoryGirl Getting Started doc?
7f31ba9
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.
@AWaselnuk did you have some text in mind that would've been helpful for you? If so, could you put together a PR and we can discuss there? I'm completely onboard with improving the experience!
7f31ba9
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.
@joshuaclayton I just saw this on GETTING_STARTED.md master branch:
That's perfect. It mentions the expected side effect of linting and provides a possible solution. Thanks!
7f31ba9
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.
@joshuaclayton, @mshytikov - that rspec example would be perfect as a default generated test in factory_girl_rails