Sérgio Toledo Sérgio Toledo - 27 days ago 6
Ruby Question

Rails 4 and Rspec - generate controller test

I have an API that has many controllers and models.

I installed Rspec and every new resource I create, the corresponding test files are created automatically.

Is there a way to generate these files for all others old resources including REST tests?

For instance, I have a file costumers_controller.rb created before I install Rspec, is there a way to generate the default file costumers_controller_spec.rb?

Answer Source

I found the answer:

rails g rspec:scaffold controller_name

This generate also the request and routing file.

In order to generate the model just use:

rails g rspec:model model_name

And all test files will be ready to use.

Thanks.