我想在我的控制器中测试这个方法。
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}
该方法期望参数,但结果为零。
我有两个问题。
该方法是否应该在帮助程序中而不是在控制器本身中(根据 Rails 约定)?
如何提交获取请求并通过
params
测试?