RSPEC으로 모델 테스트하기
상황
class WarRequest < ApplicationRecord
belongs_to :rule
has_one :war, dependent: :destroy
has_many :war_statuses, dependent: :destroy
has_many :guilds, through: :war_statuses
validates :status, inclusion: { in: ["pending", "accepted", "canceled"], message: "상태를 잘못 입력하셨습니다." }
validates :rule_id, inclusion: { in: 1..7, message: "요청하신 룰이 존재하지 않습니다." }
validates :target_match_score, inclusion: { in: [3, 5, 7, 10], message: "목표 점수를 잘못 입력하셨습니다." }
validates :max_no_reply_count, inclusion: { in: 3..10, message: "최대 미응답 개수를 잘못 입력하셨습니다." }
validates :bet_point, inclusion: { in: (1000..10000).step(500), message: "배팅 포인트를 잘못 입력하셨습니다."}
validates :start_date, presence: { message: "시작일을 입력해주세요."}
validate :start_date_after_now
validate :start_date_after_max_end_date
validate :end_date_after_start_date
....
end해결 - RSPEC 를 사용하
throw 가 던져지는 상황을 어떻게 테스트 할까?
RSPEC 를 이용한 Exception 테스트
1. 폴더와 파일을 만든다.
2. 테스트 코드 작성
Last updated