Practice - 5 Tasks
Answer the questions below
1fill in blank
easyComplete the code to load fixtures in a Rails test.
Ruby on Rails
fixtures :[1] Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using controller or view names instead of fixture names.
Trying to load fixtures that don't exist.
✗ Incorrect
In Rails tests, you load fixtures by specifying the fixture name, such as users for user data.
2fill in blank
mediumComplete the factory definition to create a user with FactoryBot.
Ruby on Rails
factory :user do [1] { "test@example.com" } end
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using
name or username instead of email.Forgetting to use curly braces for the block.
✗ Incorrect
The email attribute is commonly set in a user factory to provide a unique email address.
3fill in blank
hardFix the error in the factory usage to create a user instance.
Ruby on Rails
user = FactoryBot.[1](:user) Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using non-existent methods like
builds or makes.Confusing
build (which does not save) with create.✗ Incorrect
The correct method to create and save a factory object is create.
4fill in blank
hardFill both blanks to define a fixture file path and load it in a test.
Ruby on Rails
fixtures :[1] file_path = Rails.root.join('test', 'fixtures', '[2].yml')
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using different names for fixture and file path.
Misspelling the fixture file name.
✗ Incorrect
The fixture name and file path must match. Here, users is used for both.
5fill in blank
hardFill all three blanks to create a factory with a sequence and use it in a test.
Ruby on Rails
factory :user do [1] :email do |[2]| "user[2]@example.com" end end user = FactoryBot.[3](:user)
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using
email instead of sequence.Forgetting to use the block variable
n.Using
build instead of create when saving is needed.✗ Incorrect
Use sequence to generate unique emails with a number n. Then use create to make the user.