Bird
0
0

What will this RSpec mock test output?

medium📝 Predict Output Q5 of 15
Ruby - Testing with RSpec and Minitest
What will this RSpec mock test output?
class Order
  def total
    100
  end
end

order = Order.new
expect(order).to receive(:total).and_return(200)
puts order.total
A200
B100
Cnil
DError
Step-by-Step Solution
Solution:
  1. Step 1: Understand mock expectation

    The expect(order).to receive(:total).and_return(200) sets expectation and stubs total to return 200.
  2. Step 2: Check output of puts order.total

    The method call returns 200 due to the mock.
  3. Final Answer:

    200 -> Option A
  4. Quick Check:

    Mocked method output = 200 [OK]
Quick Trick: Mocks expect calls and return specified values [OK]
Common Mistakes:
  • Confusing mock with original method output
  • Expecting nil return
  • Assuming test raises error

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Ruby Quizzes