我有 3 个包含相同模块的控制器。
如何使用 Test:Unit 将模块集中在一个地方进行测试?
我应该为每个控制器(不是 DRY)编写 3 个相同的功能测试吗?
测试控制器/测试控制器1/测试控制器2:
class TestController < ApplicationController
include TestModule
test_module :test, :only => [:index]
...
end
测试模块:
module TestModule
extend ActiveSupport::Concern
module ClassMethods
private
def test_module(resource, options = {})
self.before_filter(options.slice(:only, :except)) do
puts 'test_module'
end
end
end
end
提前致谢 !