Seralto
Seralto

Reputation: 1076

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?

Upvotes: 2

Views: 3285

Answers (2)

sealocal
sealocal

Reputation: 12467

Generate a controller with simple spec examples for the specified actions:

rails g rspec:controller Posts index show create

Upvotes: 2

Seralto
Seralto

Reputation: 1076

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.

Upvotes: 3

Related Questions