0
0
Ruby on Railsframework~10 mins

Fixture and factory usage in Ruby on Rails - Interactive Code Practice

Choose your learning style9 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete the code to load fixtures in a Rails test.

Ruby on Rails
fixtures :[1]
Drag options to blanks, or click blank then click option'
Amodels
Busers
Ccontrollers
Dviews
Attempts:
3 left
💡 Hint
Common Mistakes
Using controller or view names instead of fixture names.
Trying to load fixtures that don't exist.
2fill in blank
medium

Complete 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'
Aname
Bpassword
Cusername
Demail
Attempts:
3 left
💡 Hint
Common Mistakes
Using name or username instead of email.
Forgetting to use curly braces for the block.
3fill in blank
hard

Fix 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'
Acreate
Bmakes
Cbuilds
Dgenerate
Attempts:
3 left
💡 Hint
Common Mistakes
Using non-existent methods like builds or makes.
Confusing build (which does not save) with create.
4fill in blank
hard

Fill 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'
Ausers
Bposts
Ccomments
Dprofiles
Attempts:
3 left
💡 Hint
Common Mistakes
Using different names for fixture and file path.
Misspelling the fixture file name.
5fill in blank
hard

Fill 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'
Asequence
Bn
Ccreate
Demail
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.