このメソッドをコントローラーでテストしたいと思います。
def fetch_match_displayed_count(params)
match_count = 0
params.each do |param|
match_count += 1 if param[1]["result"] && param[1]["result"] != "result"
end
match_count
end
これは私がこれまでに書いたテストです。
describe "fetch_match_displayed_count" do
it "should assign match_count with correct number of matches" do
params = {"result_1"=>{"match_id"=>"975", "result"=>"not_match"}, "result_2"=>{"match_id"=>"976", "result"=>"match"}, "result_3"=>{"match_id"=>"977", "result"=>"not_sure"}, "result_4"=>{"match_id"=>"978", "result"=>"match"}, "result_5"=>{"match_id"=>"979", "result"=>"not_match"}, "workerId"=>"123", "hitId"=>"", "assignmentId"=>"", "controller"=>"mt_results", "action"=>"create"}
controller.should_receive(:fetch_match_displayed_count).with(params)
get :fetch_match_displayed_count, {params:params}
assigns(:match_count).should == 5
end
end
私の問題はこの行にあるようですget :fetch_match_displayed_count, {params:params}
メソッドはパラメーターを期待していますが、nilになっています。
2 つの質問があります。
このメソッドはコントローラー自体ではなく、ヘルパーに配置する必要がありますか (Rails の規則に従って)?
params
get リクエストを送信してテストに合格するにはどうすればよいですか?