Why is RSpec so slow under Rails?

前端 未结 11 573
无人共我
无人共我 2020-12-24 05:00

Whenever I run rspec tests for my Rails application it takes forever and a day of overhead before it actually starts running tests. Why is rspec so slow? Is there a way to

11条回答
  •  孤独总比滥情好
    2020-12-24 05:39

    because it loads all the environement, loads fixtures and all that jazz.

    The real culprit is if you run it using rake spec, it runs the db:test:prepare task.

    This task drops your entire test database and re-creates it from scratch. This seems ridiculous to me, but that's what it does (the same thing happens when you run rake:test:units etc).

    You can easily work around this using the spec application which rspec installs as part of the rspec gem.

    Like this:

    cd railsapp
    spec spec # run all specs without rebuilding the whole damn database
    spec spec/models # run model specs only
    
    cd spec
    spec controllers/user* # run specs for controllers that start with user
    

提交回复
热议问题