Is there a recommended way of testing Rails generators with RSpec? The only solution I've found is the Generator Spec gem, that hasn't been updated in over two years.
I would write a file by hand that acts as a test fixture. I would then as part of my test generate the file with the generator. At that point I would diff the two files. Looks like the diffy gem could help you there. If there is no diff then pass the test. Fail if otherwise.
https://github.com/samg/diffy
Don't forget to clean up your temp files after the tests. You don't want them hanging around in your repos.
There's the gem https://github.com/petergoldstein/generator_spec, which does a decent job, although it is not very actively maintained
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With