0
0
Rubyprogramming~10 mins

Let and before hooks in Ruby - Interactive Code Practice

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

Complete the code to define a lazy variable using let.

Ruby
let(:user) { [1] }
Drag options to blanks, or click blank then click option'
Ait
BUser.new
Cdescribe
Dbefore(:each)
Attempts:
3 left
💡 Hint
Common Mistakes
Using before(:each) inside let block.
Trying to call describe or it inside let.
2fill in blank
medium

Complete the code to run setup code before each test.

Ruby
before(:each) do
  [1]
end
Drag options to blanks, or click blank then click option'
A@user = User.new
Blet(:user)
Cdescribe 'user'
Dit 'creates user'
Attempts:
3 left
💡 Hint
Common Mistakes
Trying to call let(:user) inside before.
Writing describe or it inside before.
3fill in blank
hard

Fix the error in the before hook to properly initialize @count.

Ruby
before(:each) do
  @count = [1]
end
Drag options to blanks, or click blank then click option'
Acount + 1
Blet(:count)
Ccount = 0
D0
Attempts:
3 left
💡 Hint
Common Mistakes
Using count + 1 without defining count.
Trying to call let(:count) inside before.
4fill in blank
hard

Fill both blanks to create a let variable and use it in a before hook.

Ruby
let(:number) { [1] }
before(:each) do
  @result = number [2] 5
end
Drag options to blanks, or click blank then click option'
A10
B+
C*
D20
Attempts:
3 left
💡 Hint
Common Mistakes
Using multiplication instead of addition.
Using a string instead of a number in let.
5fill in blank
hard

Fill all three blanks to define a let variable, a before hook, and a test using them.

Ruby
let(:text) { [1] }
before(:each) do
  @shouted = text.[2]
end
it 'shouts the text' do
  expect(@shouted).to eq([3])
end
Drag options to blanks, or click blank then click option'
A"hello"
Bupcase
C"HELLO"
Ddowncase
Attempts:
3 left
💡 Hint
Common Mistakes
Using downcase instead of upcase.
Mismatching expected string case in the test.