RSpec for Test::Unit 测试中是否有类似于共享示例的插件/扩展?
如果您使用的是rails(或只是active_support),请使用Concern https://github.com/rails/rails/blob/f37ad331089f64ab0386e8ac94b6626b45c38a1e/activesupport/lib/active_support/concern.rb.
require 'active_support/concern'
module SharedTests
extend ActiveSupport::Concern
included do
# This way, test name can be a string :)
test 'banana banana banana' do
assert true
end
end
end
如果您不使用 active_support,只需使用Module#class_eval
.
该技术建立在Andy H. https://stackoverflow.com/users/725792/andy-h的回答,他指出:
Test::单元测试只是 Ruby 类,因此您可以使用代码重用的[常规技术]
但因为它允许使用ActiveSupport::Testing::Declarative#test https://github.com/rails/rails/blob/a5ab38c7bb99e135e29f5727e3e75a1e562d8216/activesupport/lib/active_support/testing/declarative.rb它的优点是不会耗尽你的下划线键:)
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)