thoughtbot / thoughtbot/factory_bot

"pending" feature to lint factories that are expected to be invalid

Open
#1,500 2 comments 1 reaction 1 assignee View on GitHub

@aledustet is already working on this.

Since Nov 19, 2021.

feature
Dominant language
Ruby
Stars
8.2k
Forks
2.6k
PR merge metrics
No merged PRs in 30d

Description

Problem this feature will solve

In a legacy codebase that has a large suite of factories, and a large chunk of them being invalid, it can be difficult to incrementally fix the factories. The factorybot linter is fantastic for discovering invalid factories. But, as known with other forms of automated tests, the linter is only useful when it can be kept green. That is, when adding the linter to an existing suite of factories with dozens or more invalid factories, the known-invalid factories must be initially ignored. (Similar to xit in rspec.) As the factories are incrementally addressed, they can be removed from the "ignore list" and subsequently included in the automated lint task. However, should a factory become "valid" while ignored, it must be removed from the ignore list in order to prevent it subsequently becoming invalid again!

Therefore, a more robust approach for validating the factories would be to have two lint invocations:

  1. linting the expected-valid factories; failing if any are invalid
  2. linting the expected-invalid factories; failing if any are valid

The latter represents the same behavior that RSpec's pending helper accomplishes. That is, the spec is run and is expected to fail. But if it succeeds (unexpectedly), it is recorded as a failure so that it can be removed from the pending list.

Desired solution

Ideally, the FactoryBot.lint would expect another option: pending: true or similar that would fail for any given factory that is valid.

Usage:

invalid_factories = [...]
FactoryBot.lint (FactoryBot.factories - invalid_factories)
FactoryBot.lint invalid_factories, pending: true

The ideal output would then adjust the messages to indicate that any factories that were not invalid, were in fact valid (unexpectedly); essentially negating the error messaging.

Alternatives considered

Additional context

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.