A simple PORO
Imagine you wrote this simple PORO in your Ruby on Rails app:
class CreditCard::AgeValidator
def initialize(age)
@age = age
end
def valid?
return true if @age >= 18
false
end
end
Questions:
- What tests would you write for it?
- What cases would you cover with your tests? How many tests would you write?
What about this update_required?
method
class Account < ApplicationRecord
# t.date "expires_at"
# t.string "website"
def update_required?
website.blank? || expired?
end
def eternal? = expires_at.nil?
def expired?
return false if eternal?
expires_at < Date.current
end
end
Questions:
- What cases would you cover when testing Account#update_required?
- What cases would you cover with your tests? How many tests would you write?
Top comments (0)