简体   繁体   中英

Should you test the gems your Rails app uses? If so, how do you?

I am planning on using the Sanitize gem in a Rails project as a way of cleaning 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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM