Is there a plugin/extension similar to shared_examples in RSpec for Test::Unit tests?
If you are using rails (or just active_support), use a Concern
.
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
If you're not using active_support, just use Module#class_eval
.
This technique builds on Andy H.'s answer, where he points out that:
Test::Unit tests are just Ruby classes, so you can use [normal techniques] of code reuse
but because it enables the use of ActiveSupport::Testing::Declarative#test
it has the advantage of not wearing out your underscore key :)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With