我有一个非常精细的设置来将条件从通过更改为失败的四个组合方法称为合格?。
describe "#participant_age_eligible?" do
it "returns whether participant is age-eligible" do
@part.participant_age_eligible?(@pers).should == true
end
it "returns false if participant is not age eligible" do
q = @survey_section.questions.select { |q| q.data_export_identifier ==
"#{OperationalDataExtractor::PbsEligibilityScreener::
INTERVIEW_PREFIX}.AGE_ELIG" }.first
answer = q.answers.select { |a| a.response_class == "answer" && a.reference_identifier == "2" }.first
Factory(:response, :survey_section_id => @survey_section.id, :question_id => q.id, :answer_id => answer.id, :response_set_id => @response_set.id)
@part.participant_age_eligible?(@pers).should == false
end
end
describe "#participant_psu_county_eligible?" do
it "returns whether participant lives in eligible PSU" do
@part.participant_psu_county_eligible?(@pers).should == true
end
it "returns false if participant coes not live in an eligible PSU" do
q = @survey_section.questions.select { |q| q.data_export_identifier ==
"#{OperationalDataExtractor::PbsEligibilityScreener::
INTERVIEW_PREFIX}.PSU_ELIG_CONFIRM" }.first
answer = q.answers.select { |a| a.response_class == "answer" && a.reference_identifier == "2" }.first
Factory(:response, :survey_section_id => @survey_section.id, :question_id => q.id, :answer_id => answer.id, :response_set_id => @response_set.id)
@part.participant_psu_county_eligible?(@pers).should == false
end
end
还有另外两种方法,就像这两种方法一样。我想做的是提取
q = @survey_section.questions.select { |q| q.data_export_identifier ==
"#{OperationalDataExtractor::PbsEligibilityScreener::
INTERVIEW_PREFIX}.AGE_ELIG" }.first
answer = q.answers.select { |a| a.response_class == "answer" && a.reference_identifier == "2" }.first
Factory(:response, :survey_section_id => @survey_section.id, :question_id => q.id, :answer_id => answer.id, :response_set_id => @response_set.id)
部分到 before 块中的方法,然后传递相关参数,但我犹豫,因为我从未见过有人在 before 块中定义方法,甚至不确定你能做到,进一步,我不确定你是否甚至即使可以,也应该这样做,也许它指出了我没有看到的问题。所以我想问问 SO 社区深不可测的巨大专业知识。谢谢。