I have a Rails application with one model (following a tutorial) and I forgot to install the gem Rspec at inception. I have now done it but the Spec files and folders don't show up.
I have read the following : How do I generate specs for existing controllers? and tried a few command lines that have generated files (am so noob I cant find out what it has actually done)
But no new Spec files !
Would it be because I have a Model and not a Controller ? What would be the correct command line ? Alternatively may I create them directly and with what name?
Running tests by their file or directory names is the most familiar way to run tests with RSpec. RSpec can take a file name or directory name and run the file or the contents of the directory. So you can do: rspec spec/jobs to run the tests found in the jobs directory.
Installing RSpec Boot up your terminal and punch in gem install rspec to install RSpec. Once that's done, you can verify your version of RSpec with rspec --version , which will output the current version of each of the packaged gems. Take a minute also to hit rspec --help and look through the various options available.
Run the generators again:
rails generate rspec:model MyModel
rails generate rspec:controller MyController
It will ask if you want to override existing files. Answer as appropriate for your situation. You probably want to keep your existing model/controller files. The new controller specs should end up in (for example) spec/controllers/my_controller_spec.rb
.
Or you can simply add spec files manually. Consult the rspec-rails documentation for more details.
I also recommend reading the Guide to Testing Rails Applications.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With