我想让我的每个功能测试自动测试各种格式。似乎实现这一点的方法是将“测试”方法包装在我自己的类方法中:
def self.test_all_formats(name)
[ "xml", "json" ].each do |fmt|
test "#{name} #{fmt}" do
yield(format)
end
end
end
test_all_formats "index" do |fmt|
get :index, { :format => fmt }
assert_response :ok
end
不幸的是,每个测试都会引发以下错误:
NoMethodError:AccountsControllerTest:Class 的未定义方法“get”。
尽管块的执行被推迟到测试的执行,但它试图在类的上下文中而不是实例的上下文中运行块。
有没有办法实现这种自动化测试?