Challenge - 5 Problems
Fixture and Factory Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ component_behavior
intermediate2:00remaining
What will be the user email after loading this fixture?
Given this YAML fixture for a User model, what will be the email of the user loaded in the test?
Ruby on Rails
users:
one:
id: 1
name: "Alice"
email: "alice@example.com"
two:
id: 2
name: "Bob"
email: "bob@example.com"Attempts:
2 left
💡 Hint
Look at the fixture key used to load the user.
✗ Incorrect
The fixture key 'one' corresponds to the user with email 'alice@example.com'.
📝 Syntax
intermediate2:00remaining
Which factory definition is correct for a User with a dynamic email?
Choose the correct FactoryBot factory definition that creates a User with a unique email each time.
Attempts:
2 left
💡 Hint
Look for the FactoryBot sequence syntax.
✗ Incorrect
Option B uses FactoryBot's sequence to generate unique emails, which is the correct pattern.
🔧 Debug
advanced3:00remaining
Why does this test fail when using fixtures with associations?
Given these fixtures, why does the test fail with a 'nil' association error?
users.yml:
alice:
id: 1
name: "Alice"
posts.yml:
first_post:
id: 1
title: "Hello"
user_id: 2
Attempts:
2 left
💡 Hint
Check the user_id value in posts.yml against users.yml ids.
✗ Incorrect
The post references user_id 2, but users.yml only defines user with id 1, so the association is nil.
❓ state_output
advanced2:00remaining
What is the count of users after running this FactoryBot create sequence?
If you run this code in a test:
5.times { FactoryBot.create(:user) }
What will User.count be?
Attempts:
2 left
💡 Hint
Assuming the factory uses sequences for unique emails.
✗ Incorrect
Each create call adds one user, so after 5 calls, User.count is 5.
🧠 Conceptual
expert3:00remaining
Why prefer factories over fixtures in modern Rails testing?
Which reason best explains why many Rails developers prefer FactoryBot factories over fixtures?
Attempts:
2 left
💡 Hint
Think about flexibility and test maintenance.
✗ Incorrect
Factories provide dynamic data generation and traits, making tests easier to maintain and less fragile.