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

Update docs to require full namespace #1669

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 20 additions & 0 deletions GETTING_STARTED.md
Original file line number Diff line number Diff line change
Expand Up @@ -219,6 +219,26 @@ It is also possible to explicitly specify the class:
factory :admin, class: "User"
```

Explicit specification of the class, _with the full namespace_, is necessary when defining factories for classes within modules in non-Rails applications:

```
# foo/bar.rb
module Foo
class Bar
...
end
end

# factories.rb
FactoryBot.define do
factory :bar, class: 'Foo::Bar' do
...
end
end
```

If the full namespace is not provided in the `factory` statement, you will receive a `NameError: uninitialized constant Bar` error.

You can pass a constant as well, if the constant is available (note that this
can cause test performance problems in large Rails applications, since
referring to the constant will cause it to be eagerly loaded).
Expand Down
Loading