ruby - Step definitions for cucumber data tables for storing correct answers -
i trying find way test multiple choice questions. structure lesson has 8 stages , each stage contains multiple choice questions 1 correct answer. loading of questions random each time have been looking best way test whether correct answer clicked. reason have created data table 2 columns more extensive along these lines:
| opposite of true | false | | comes after tuesday | wednesday | in feature test have written testing correct answer match. later hoping find way test if question , answer match not in data table incorrect. able explain how go doing test definitions this?
i have tried use rows_hash method getting following error
undefined method `rows_hash' -3634850196505698949:fixnum (nomethoderror) given(/^a list of answer\-value pairs$/) |table| @question_answer_table = hash end when(/^i choose match$/) hash = @question_answer_table @question_answer_table.rows_hash return false if hash[question].nil? return hash[question] == answer end
i think rows_hash method you.
def question_correct?(cucumber_table, question, answer) hash = cucumber_table.rows_hash return false if hash[question].nil? return hash[question] == answer end the code works converting 2 column data table hash, first column key , second value.
keep in mind method requires data table limited 2 columns.
Comments
Post a Comment