Saya ingin menguji metode ini di pengontrol saya.
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
Ini adalah tes yang saya tulis sejauh ini.
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
Masalah saya sepertinya terletak pada baris ini get :fetch_match_displayed_count, {params:params}
Metode ini mengharapkan params, tetapi hasilnya nihil.
Saya punya dua pertanyaan.
Haruskah metode ini ada di helper dan bukan di controller itu sendiri (sesuai konvensi Rails)?
Bagaimana cara mengirimkan permintaan dapatkan dan lulus
params
dalam ujian saya?
create
. Kalau begitu, saya hanya bisa mengharapkan hal berikut:controller.should_receive(:fetch_match_displayed_count).with(params).and_return(5)
- person Huy   schedule 01.02.2013