0
我有模式:Rails在模型中测试小方法是好的还是不好的做法?
class Answer < ActiveRecord::Base
def pending_edits
self.edits.where(:is_approved => nil)
end
def update_body (new_body)
update_attributes :old_body => self.body, :body => new_body
end
def current_accepted_edit
edits.find_by(:is_current => true)
end
1)它是矫枉过正和坏的做法,因为有这么简单的测试方法这?
但我写了他们anyway.So测试,以防万一
2)如果我需要对其进行测试 - 这是一个好的it block description
:在我的RSpec的测试?
it 'answer.pending edits_method' do
some testing code
end
它真的取决于,你认为这真的很小的规格增加了东西有用你的测试套件?如果答案是肯定的,那就做吧,如果答案是否定的:不要这样做,如果你不能决定的话:无论如何,如果你不确定是否有更好的答案 – arieljuod