0
0
Rubyprogramming~10 mins

RSpec expectations and matchers 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 check if the variable result equals 10 using RSpec.

Ruby
expect(result).to [1] 10
Drag options to blanks, or click blank then click option'
Abe
Beq
Chave
Dinclude
Attempts:
3 left
💡 Hint
Common Mistakes
Using be which checks object identity, not value equality.
Using have or include which are for collections.
2fill in blank
medium

Complete the code to check if the array numbers includes the number 5.

Ruby
expect(numbers).to [1] 5
Drag options to blanks, or click blank then click option'
Ainclude
Bcontain
Cmatch
Deq
Attempts:
3 left
💡 Hint
Common Mistakes
Using eq which checks for exact equality, not inclusion.
Using contain which is not a valid RSpec matcher.
3fill in blank
hard

Fix the error in the code to check if the string message starts with 'Hello'.

Ruby
expect(message).to [1]('Hello')
Drag options to blanks, or click blank then click option'
Aeq
Binclude
Cmatch
Dstart_with
Attempts:
3 left
💡 Hint
Common Mistakes
Using eq which checks full equality.
Using include which checks for substring anywhere.
Using match which expects a regex.
4fill in blank
hard

Fill both blanks to check if the variable value is greater than 5 and less than 10.

Ruby
expect(value).to be [1] 5.and be [2] 10
Drag options to blanks, or click blank then click option'
A>
B<
C==
D>=
Attempts:
3 left
💡 Hint
Common Mistakes
Using equality operators instead of comparison.
Reversing the comparison signs.
5fill in blank
hard

Fill all three blanks to check if the hash user has a key :name with value 'Alice' and the key :age is greater than 20.

Ruby
expect(user). [1] include([2] => 'Alice'}) and expect(user[:age]).to be [3] 20
Drag options to blanks, or click blank then click option'
Ato
B:name
C>
Dhave_key
Attempts:
3 left
💡 Hint
Common Mistakes
Using have_key instead of include for key-value pairs.
Using wrong comparison operators for age.