Is there a plugin/extension similar to shared_examples in RSpec for Test::Unit tests?
相关问题
- How to specify memcache server to Rack::Session::M
- Why am I getting a “C compiler cannot create execu
- reference to a method?
- ruby 1.9 wrong file encoding on windows
- gem cleanup shows error: Unable to uninstall bundl
相关文章
- Ruby using wrong version of openssl
- Difference between Thread#run and Thread#wakeup?
- how to call a active record named scope with a str
- “No explicit conversion of Symbol into String” for
- Rspec controller error expecting <“index”> but
- Segmentation fault with ruby 2.0.0p247 leading to
- How to detect if an element exists in Watir
- uninitialized constant Mysql2::Client::SECURE_CONN
Test::Unit
tests are just Ruby classes, so you can use the same methods of code reuse as any other Ruby class.To write shared examples, you could use a module.
I was able to implement shared tests (similar to RSpec shared examples) using the following code:
To define and use shared tests in a Test::Unit test:
If you are using rails (or just active_support), use a
Concern
.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:
but because it enables the use of
ActiveSupport::Testing::Declarative#test
it has the advantage of not wearing out your underscore key :)Look at this gist I wrote a couple of years ago. It still works great: https://gist.github.com/jodosha/1560208
Used like this: