How do I integrate RSpec with Rake, Rails, and my existing tests?

I would like to start using RSpec to write tests for my Rails application, but I have many existing tests written using Test :: Unit. I would like to continue the execution of all tests (or all unit tests, functional tests, etc.) just from the command line with something like

rake test:units

or something else, and run all unit tests, regardless of whether they are written using Test :: Unit or RSpec. And I definitely don't want to spend a ton of time converting my existing tests to RSpec; that is not a starter.

Now I think that I would like my RSpec tests to exist next to my existing tests, in a test / module, testing / functional, etc. What is the best way to do this? Or is it even a good idea? That is, I'm pretty new to RSpec (and Ruby and Rails, for that matter), so maybe it's better to use RSpecs separately. No matter where they are stored in the file system, I still need to run all the tests with one rake task, and I will need to collect code coverage numbers for the entire test case using rcov, which I already do with my existing tests.

+3
source share
1 answer

edit: Rspec rails.


Rspec spec/, :

spec/
├── controllers
│   ├── pages_controller_spec.rb
│   └── users_controller_spec.rb
├── helpers
│   ├── pages_helper_spec.rb
│   └── users_helper_spec.rb
├── models
│   └── user_spec.rb
├── spec_helper.rb
└── views
    ├── pages
    │   └── home.html.haml_spec.rb
    └── users
        ├── index.html.haml_spec.rb
        └── show.html.haml_spec.rb

, . , Test:: Unit , Rspec. spec_helper.rb. Rspec, .

, rspec spec , , rspec. - :

task :run_tests do
  system("rspec spec/")
  system("rake test:units")
end

rspec, Test:: Unit .

+6

Source: https://habr.com/ru/post/1776528/


All Articles