Shoulda can automatically load custom macros
I wrote about creating your own shoulda macros awhile back. At that point, I was suggesting to place these in your test/test_helper.rb
.
Now it’s even easier, thanks to a semi recent change.
You can now create put .rb
files in test/shoulda_macros
, and Shoulda will automatically pick them up. Let’s try making a will_paginate macro, and stick it out in test/shoulda_macros/will_paginate_macros.rb
:
In the test of an imaginary Post
model, which I’m sure you can picture, we can do:
For plugin and gem authors, vendor/gems/*/shoulda_macros/*.rb
and vendor/plugins/*.rb
will also be automatically picked up.