I am planning on using the Sanitize gem in a Rails project as a way of cl开发者_运维问答eaning user-submitted HTML snippets. The gem source on Github includes a robust set of tests, though they are not included in the final gem. In my model tests, I want to again verify that the gem does what it should be doing and that my model only stores clean HTML. It seems like overkill to have to recreate all of the gem tests in my model test, and I would prefer to have my test just make sure that the model's before_save filter (which calls on the Sanitize gem) works. What is the best way to handle this?
On a side note, while researching this I came across the GemTester area of RubyGems, which looks really promising, but requires gem authors to opt-in each gem.
I don't know if this will be the answer you're looking for, but my general principle is to not write tests for third party libraries. Rather, write tests for your integration points with those libraries, or the code that you're writing on top of those libraries. I would include a test to perhaps make sure that the before_save filter is being called correctly and leave it at that.
精彩评论