【发布时间】:2014-07-30 19:54:41
【问题描述】:
我在控制器中有一个受保护的方法,需要为它编写测试用例。方法是
def source
@source.present? ? @source.class : Association.reflect_on_association(source.to_sym).klass
end
@source 是一个对象,source 是一个字符串。
我不知道如何为这个方法编写测试用例。
edit
这是我正在尝试的
subject { @controller }
describe '#source' do
let(:source_object) { create :program_type}
describe "Object is not present" do
it 'should reflect on association and return the reflection class' do
subject.stubs(:source_identifier).returns("program_type")
subject.send(:source).must_equal ProgramType
end
end
describe "Object is present" do
it 'should return the class of the object' do
subject.send(:source).must_equal source_object.class
end
end
end
提前致谢。
【问题讨论】:
标签: ruby ruby-on-rails-3 minitest