RSpec describe and it blocks
📖 Scenario: You are writing tests for a simple Ruby method that adds two numbers. Testing helps you check if your code works as expected before using it in real projects.
🎯 Goal: You will create an RSpec test file using describe and it blocks to organize and run tests for the addition method.
📋 What You'll Learn
Create a
describe block for the add methodInside
describe, write an it block describing the expected behaviorUse
expect with eq matcher to check the result of add(2, 3)Print the test result by running the RSpec test file
💡 Why This Matters
🌍 Real World
Writing tests helps catch bugs early and ensures your code works as expected before sharing or deploying it.
💼 Career
RSpec is widely used in Ruby development jobs to write automated tests, improving code quality and reliability.
Progress0 / 4 steps