I’m using RSpec 1 and rspec-rails to test my Rails 2.3.14 application. In this same application, I’m using Draper to provide decorators for my models. I want to be able to test my decorators.
I’ve got specs in spec/decorators, but as best as I can tell, because rspec-rails doesn’t recognize the decorators/ path, and therefore doesn’t wire up any of the extra Rails stuff into the specs.
How do I set up RSpec to recognize my spec/decorators path, and cause it to include the functionality I need (which is going to be route/helper functionality)?
I notice that RSpec has things like HelperExampleGroup, ControllerExampleGroup, etc, and I suspect that these implicitly map to spec/helpers and spec/controllers and such, but I’m unclear as to how to leverage this to set up my own DecoratorHelperGroup.
I feel like I’m 90% of the way there, but can’t quite make that final connection. Examples would be most valuable, but I’ll take an abstract, as well.
Solved it. The magic sauce is
Spec::Example::ExampleGroupFactory.registerFor the record, here’s my complete
spec/support/decorators.rbAll this effectively does is register specs under
spec/decoratorsto operate as view specs (which gets me all the pieces I need). Before each decorator spec, calling#set_current_view_contexton the controller invokes the Draper bits necessary to wire helpers up into my decorators. I also added adecoratemethod to use the current described decorator class to decorate an arbitrary object, allowing easy decoration of objects for testing. Mission accomplished!