Why is RSpec so slow under Rails?

前端 未结 11 523
无人共我
无人共我 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:42

    If you are on a Windows environment then there is probably little you can do as Rails seems to startup really slowly under Windows. I had the same experience on Windows and had to move my setup to a Linux VM to make it really zippy (I was also using autotest).

    0 讨论(0)
  • 2020-12-24 05:44

    Running tests can be really slow because the whole rails environment has to load (try script/console) and only then can all tests run. You should use autotest which keeps the environment loaded and will check which files you edit. When you edit and save a file, only the tests that depend on these will run automatically and quickly.

    0 讨论(0)
  • 2020-12-24 05:49

    The main reason is that require takes forever on windows, for some reason.

    Tips for speedup: spork now works with windows, I believe.

    You can try "faster_require" which caches locations:

    http://github.com/rdp/faster_require

    GL. -rp

    0 讨论(0)
  • 2020-12-24 05:50

    As of rspec-rails-1.2.7, spec_server is deprecated in favor of the spork gem.

    0 讨论(0)
  • 2020-12-24 06:02

    I definitely suggest checking out spork.

    http://spork.rubyforge.org/

    The railstutorial specifically addresses this, and gives a workaround to get spork running nicely in rails 3.0 (as of this moment, spork is not rails 3 ready out of the box). Of course, if you're not on rails 3.0, then you should be good to go.

    The part of the tutorial showing how to get spork running in rails 3.0

    http://railstutorial.org/chapters/static-pages#sec:spork

    Checking when spork is rails 3.0 ready

    http://www.railsplugins.org/plugins/440-spork

    0 讨论(0)
提交回复
热议问题