適格と呼ばれるメソッドの4つの構成メソッドについて、条件を合格から不合格に変更するためのかなり複雑な設定があります。
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
これらの2つと同じようにさらに2つの方法があります。私がしたいのは抽出することです
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コミュニティの計り知れないほどの膨大な専門知識を求めたいと思います。ありがとう。