Я хочу проверить этот метод в моем контроллере.
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
в моем тесте?
create
. Тогда я могу ожидать следующее:controller.should_receive(:fetch_match_displayed_count).with(params).and_return(5)
- person Huy   schedule 01.02.2013