Recall & Review
beginner
What is the main purpose of model tests in Rails?
Model tests check that the data and business logic in your Rails models work correctly. They ensure validations, associations, and methods behave as expected.
Click to reveal answer
beginner
How do you test a validation in a Rails model?
You create a test that tries to save a model with invalid data and check that it does not save and adds the correct error messages.
Click to reveal answer
intermediate
What is a fixture in Rails testing?
A fixture is a sample data file used to set up known data in the test database before running tests. It helps tests run with consistent data.
Click to reveal answer
intermediate
Why should model tests be fast and isolated?
Fast and isolated tests help you quickly find problems and run tests often. They focus only on the model without depending on other parts like the UI or controllers.
Click to reveal answer
beginner
How do you test a custom method in a Rails model?
You write a test that calls the method on a model instance and checks that it returns the expected result or changes the model state correctly.
Click to reveal answer
Which Rails testing framework is commonly used for model tests?
✗ Incorrect
RSpec and Minitest are popular testing frameworks in Rails for writing readable and expressive model tests.
What does a validation test usually check in a Rails model?
✗ Incorrect
Validation tests check that invalid data prevents saving and adds errors.
Which method is used to create a test instance of a model in Rails tests?
✗ Incorrect
Model.new creates a new instance without saving, useful for testing validations before saving.
What is the role of fixtures in Rails model tests?
✗ Incorrect
Fixtures provide sample data loaded into the test database before tests run.
Why should model tests avoid relying on the UI or controllers?
✗ Incorrect
Model tests should be fast and isolated to quickly find issues in model logic.
Explain how to write a test for a validation in a Rails model.
Think about what happens when you try to save wrong data.
You got /3 concepts.
Describe the benefits of using fixtures in Rails model tests.
Fixtures help set up the test environment.
You got /3 concepts.