Using generator_spec outside rails app.
Closed this issue · 3 comments
Using generator_spec when developing a gem doesn't seem to be so trivial. It seems that the resort gem uses some workarounds to get it working (https://github.com/codegram/resort/blob/master/spec/generators/migration_spec.rb). But after several tries I finally gave up. Could you provide instructions to use generator_spec outside of a rails app?
What error are you getting? What version of ruby are you using?
I'm using it to test a gem (engine_builder) if you want another example - https://github.com/stevehodgkiss/engine_builder/blob/master/spec/engine_builder_spec.rb
Resort doesn't use any hacks to get it working, other than making sure some part of rails is loaded before requiring generator_spec. The minimum I could get it working with is action_controller.
If you are running from the rspec command, make sure you run with bundle exec because if you don't rspec will try and load capybara and it will find it in the global gemset. That shouldn't matter if you have require 'bundler/setup'
in spec_helper though.
Thanks for the example and help Steve. I got it finally working. I wondered a bit about that ActionView::Template::Handlers::ERB::ENCODING_FLAG = ActionView::ENCODING_FLAG
line in the resort spec (that is what I meant with hack), but it seems that it doesn't have to do anything with generator_spec.
To have another working example: The generator and the belonging to spec.
So, thanks again for your help and I will mention your very nice library in my Rails extension from scratch blog series.
Cool, thanks! I just wrote the rails generator test class wrapper, the credit for the rspec matcher should go to Yahuda Katz. I found it in beard.