class AnswerValidatable include ActiveModel::Validations attr_accessor :answer attr_accessor :question attr_accessor :question_id validates :answer, answer_format: true MockQuestion = Struct.new(:input_type) def initialize input_type, qid = nil @input_type = input_type @question_id = qid end def question MockQuestion.new(@input_type) end end