How to test akismet in a Rails app?
I'm using the rakismet
gem to submit user cont开发者_JAVA百科ent to Akismet for spam testing.
So far every test I have done has classified the content as spam.
I'm starting to think I'm doing something wrong.
Does anyone know why I might be getting all false positives on my test data?
... Because they're test data ?
You can't rely on real rakismet data in your test. Because any test can be detected as spam one day or an other.
Or just because using rakismet requires that you have an internet connection, which can sometimes not be the case.
You should mock the rakismet methods and force them to return what you expect them to.
For example you can use mocha. And do something like the following :
Object.stubs(:spam?).returns(false)
So your objects will never be spams.
精彩评论