Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

No easy way to override the scaffold controller spec generator #765

Closed
oveddan opened this issue Jun 13, 2013 · 5 comments
Closed

No easy way to override the scaffold controller spec generator #765

oveddan opened this issue Jun 13, 2013 · 5 comments

Comments

@oveddan
Copy link

oveddan commented Jun 13, 2013

I want to change the way the scaffold controller spec gets generated.

When creating a new generator in my rails app at:
lib/generators/rspec/scaffold/templates/controller_spec.rb

This never gets invoked, only the out of the box rspec-rails scaffold controller generator gets invoked.

It would be great if we could easily just change the way the specs for scaffold controllers are generated.

@alindeman
Copy link
Contributor

I don't really know how to make this work. It seems like work on Rails' generator mechanism would be required.

If you have any more information about this, or want to implement it, I'd be happy to look at some code :) But given this, I'm going to close as not an issue.

@oveddan
Copy link
Author

oveddan commented Aug 2, 2013

In the rails generator documentation, it says you can override the templates by putting a file with the same name in your app with the same relative path of the original generator:
http://guides.rubyonrails.org/generators.html#customizing-your-workflow-by-changing-generators-templates
So, based on that logic, it should be theoretically possible to do the same with the controller_spec.rb file
I'm going to look through the rails generator code to see where this is done (i.e. where it enables you to override helper.rb)

@abuiles
Copy link

abuiles commented Jan 3, 2014

@oveddan did you resolve this issue?

@oveddan
Copy link
Author

oveddan commented Jan 3, 2014

Not yet - I think it has do something with the way rails selects its generator template for scaffolds. Need to look into this more.

@oveddan
Copy link
Author

oveddan commented Jan 4, 2014

Looks like it actually does work, I just had the path to put the overriding template file wrong. The correct path is:
lib/templates/rspec/scaffold/controller_spec.rb
(prior I had lib/generators/rspec/scaffold/templates/controller_spec.rb)

When putting a file in that correct path, the template gets overriden by that file.
Should I update the readme to indicated where to put these files?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants