What have you found for these years?

2008-10-13

沒有 mocha 該如何是好

早就寫好的 api, 終於要寫測試了。遲遲沒做一來是因為有其他事情介入,
二來是寫 test case 真的是又煩又悶的事情... 應該要有些人專門寫 test case 或
spec, 不然這些東西真的嚴重影響寫程式的節奏。有些東西真的要一氣呵成,
中間斷掉的話那個氣勢就虛掉了。其實很多事情都是這樣,當技術差異不大時,
比的就是氣勢了...

這個 api 要測試真的是麻煩到不行了 :(
一方面我沒辦法把真正的 model 拿出來用,都是在寫 fake,
model 寫一次,fake 又寫一次,東西寫太像太費工夫,寫得不像又怕測不好。
再加上 facebook api 前後不一致性非常高,有的地方用 empty element,
有的地方又用 xsi:nil="true", 有的地方又需要 list="true",
而且又不見得真的是 list! photos.upload 居然還需要修改 http header...
害我為了測試正確性,得開一個 mongrel 來跑修改過的 rails, 工程有夠浩大。

目前才約 200 個 assertions, 在我電腦上就要跑到快 6 秒。
這部份想引入 minitest 來縮短測試時間,不過又擔心跟 rails/mocha 不相容...

anyway, 這時候有 mocha 真的是感動到痛哭流涕 XD

albums = [stub(:readable_for? => true,
:id => 5,
:icon => nil,
:user_id => 123,
:title => 'zzz',
:created_at => 456,
:updated_at => 789,
:description => 'facebook sucks',
:photos => [])]

Album.expects(:find).with(['5']).returns(albums)
test[:aids => '5']

User.any_instance.expects(:albums_for_visitor).returns(albums)
test[:uid => '123']

0 retries:

Post a Comment

Note: Only a member of this blog may post a comment.



All texts are licensed under CC Attribution 3.0