How to discover why RSpec is taking so long to start?
Asked Answered
T

2

9

I know there is a way to know which specs are taking the most time, but my doubt is about the loading of the RSpec. The specs itself are not taking too much time, but the load is.
There is a way to discover that?
I am working on a Rails' legacy code and I don't know which gems could be affecting it.

Tatiania answered 20/4, 2019 at 13:3 Comment(1)
#33300312Lassie
T
2

For anyone who comes here, the problem was that the RSpec was truncating every time I ran the tests.
I discovered it by checking the log while it was starting (tail -f log/test.log).
To solve that, I used the database_cleaner gem and configured it with :transaction as the clean strategy.

config.before(:each) do
    DatabaseCleaner.strategy = :transaction
end
Tatiania answered 18/11, 2019 at 11:33 Comment(1)
I did that, adding your snippet to spec_helper.rb, but the tables keeps truncating as for log/test.log file. Am I missing something?Avrilavrit
C
0

Could be app-specific (amount of Gems to load for instance). To speed up Rspec load time significantly you can use spring-commands-rspec which implement the rspec command for Spring (Rails application preloader), as such:

In your gemfile, add:

gem 'spring-commands-rspec', group: :development

then run: bundle install, and finally:

bundle exec spring binstub rspec

Run Rspec before and after this procedure, you should see a huge improvement.

More info here:

https://github.com/jonleighton/spring-commands-rspec https://schwad.github.io/ruby/rails/testing/2017/08/14/50-times-faster-rspec-loading.html https://www.netguru.com/blog/9-ways-to-speed-up-your-rspec-tests

Curcuma answered 20/4, 2019 at 14:58 Comment(1)
running spring stop at the end could be helpful to restart Spring!Wittgenstein

© 2022 - 2024 — McMap. All rights reserved.