I''m trying to have most of the important stuff tested and in order to do that I run in front of some stuff I''m not quite sure which is the best way to test them. At this time I am having question around how to test modules and the custom validators (the typical email format validator for example). To test a module the best I saw up to now was finded here: http://stackoverflow.com/questions/512466/how-to-implement-an-abstract-class-in-ruby In the before he creates a new class and import the module to test, Then, using the class created, he test the module methods. Is this the recommended way to go? About testing validators I guess something like what was done with the models could also work but again not sure if its the way to go or if its totally wrong. Some advices on this matters will be really appreciated, Thanks in advance. -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://rubyforge.org/pipermail/rspec-users/attachments/20110803/91225731/attachment.html>
David Chelimsky
2011-Aug-05 02:01 UTC
[rspec-users] How to test modules and custom validators
On Aug 3, 2011, at 11:08 AM, Piter Fcbk wrote:> I''m trying to have most of the important stuff tested and in order to do that I run in front of some stuff I''m not quite sure which is the best way to test them. > At this time I am having question around how to test modules and the custom validators (the typical email format validator for example). > > To test a module the best I saw up to now was finded here: http://stackoverflow.com/questions/512466/how-to-implement-an-abstract-class-in-ruby > In the before he creates a new class and import the module to test, Then, using the class created, he test the module methods. > Is this the recommended way to go? > > About testing validators I guess something like what was done with the models could also work but again not sure if its the way to go or if its totally wrong. > > Some advices on this matters will be really appreciated, > > Thanks in advance.I usually like to do something like: describe MyModule do let(:object) { Class.new { include MyModule } } it "does something" do object.method_from_my_module.should do_something end end HTH, David -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://rubyforge.org/pipermail/rspec-users/attachments/20110804/ac8e88e2/attachment.html>
Craig Demyanovich
2011-Aug-05 03:13 UTC
[rspec-users] How to test modules and custom validators
I recently wrote this spec <https://gist.github.com/1126847> for a custom validator. I hope you find it useful. Feedback welcome. Craig -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://rubyforge.org/pipermail/rspec-users/attachments/20110804/ba3cc8d2/attachment.html>