Practice - 5 Tasks
Answer the questions below
1fill in blank
easyComplete the code to define a simple test case in Minitest.
Ruby on Rails
class CalculatorTest < [1] def test_addition assert_equal 4, 2 + 2 end end
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using RSpec class names in Minitest tests.
Confusing ActiveSupport::TestCase with Minitest::Test.
✗ Incorrect
In Minitest, test classes inherit from Minitest::Test to define test cases.
2fill in blank
mediumComplete the code to write an example group in RSpec.
Ruby on Rails
RSpec.describe Calculator do it '[1]' do expect(2 + 2).to eq(4) end end
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using imperative phrases like 'test addition' instead of descriptive behavior.
Not using a string inside the it block.
✗ Incorrect
RSpec uses descriptive strings inside it blocks to explain the behavior being tested.
3fill in blank
hardFix the error in the Minitest assertion syntax.
Ruby on Rails
def test_subtraction [1] 2, 5 - 3 end
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using RSpec syntax like 'expect' in Minitest.
Using 'assert' without '_equal' for equality checks.
✗ Incorrect
Minitest uses assert_equal(expected, actual) for equality checks.
4fill in blank
hardFill both blanks to complete the RSpec expectation syntax.
Ruby on Rails
expect([1]).to [2](5)
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'be' matcher incorrectly for equality.
Putting the expected value inside expect().
✗ Incorrect
In RSpec, expect(value).to eq(expected) checks if value equals expected.
5fill in blank
hardFill all three blanks to write a Minitest setup method and test.
Ruby on Rails
class UserTest < Minitest::Test def [1] @user = User.new(name: 'Alice') end def [2] assert_equal '[3]', @user.name end end
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'initialize' instead of 'setup' for test preparation.
Not prefixing test methods with 'test_'.
Using wrong expected value in assertion.
✗ Incorrect
The setup method runs before each test. Test methods start with test_. The assertion checks the user's name.