stevehodgkiss/generator_spec

No such file or directory @ rb_sysopen ... tmp/config/routes.rb.

fwl opened this issue · 1 comments

fwl commented

Hello and thank you for the useful gem!

When using the route method in a generator the following error gets thrown:

Failure/Error: run_generator
     Errno::ENOENT:
       No such file or directory @ rb_sysopen - /path/to/tmp/config/routes.rb

This is in an "install" generator that legitimately performs various installation tasks like placing an initializer and adding some routes. How should one test generators that touch the config/routes.rb file when using generator_spec if the above error is thrown?

fwl commented

Adding the following in the before block solves the problem:

routes = Rails.root + 'config/routes.rb'
destination = File.join(destination_root, "config")
FileUtils.mkdir_p(destination)
FileUtils.cp routes, destination

Taken from alexrothenberg/ammeter#10 (comment).

I guess it's also worth mentioning that ammeter also solves similar problems to this gem.