Please provide patterns for testing rails generators, plugins and engines
08 Jul 2010, 23:00
Kristian Riiber Mandrup (10 posts)
With Rails 3, the Plugin and Generator architecture has been vastly improved, and I like many others I am sure want develop my own generators and plugins.
I have seen there is a Rails::Generator::TestCase you can inherit your unit test class from to facilitate testin generators (for examples of use see ‘rails3-generators’ project on github). It is pretty easy and intuitive to use and makes generator development so much better! But what about generators that cause the shell to ask the users questions to guide the process? I did find a gem called ‘session’ which enables you to operate on the shell session as it is executing… and theres is also a ‘fakefs’ gem, to fake the file system. What is the testing pattern to integrate these gems in the process?
I am however not sure how to go about testing Rails 3 plugin development or Rails Engines (such as Devise). Please shed some light on this! Would be awesome with some chapters covering these issues of Rails Testing :) Maybe an Advanced Rails Testing in the last part of the book? Thanks!
12 Jul 2010, 02:22
Noel Rappin (20 posts)
Thanks for the feedback. The basic answer for all these features is that they weren’t in the original schedule because no Rails 3 features were, since Rails 3 was barely a glint when the outline was written. But I’ll definitely take it under advisement, because they are good features to cover. I can’t promise anything yet, because there are practical constraints of time and space, but I’ll definitely look into it.
Some specific notes:
If I was trying to test a generator that talked via the shell, I might try the Aruba gem that extends Cucumber for command-line stuff, but I’m not completely sure if that would work.
This is just me talking out of school, because I haven’t tried it yet, but I think you’d test a Rails Engine just as though it was it’s own mini-app. I might be missing something, though.
As far as plugins go, the main issue is simulating the application that surrounds the plugin. I haven’t tried it in Rails 3 yet, but my previous book “Professional Ruby on Rails” does talk about testing Rails plugins in a Rails 2 environment, and I think that some of the techniques would still hold.
|You must be logged in to comment|