Reputation: 7998
I've got an interesting problem that's causing myself and my team a lot of headaches when it comes to running our spec suite.
Our spec suite is broken up into the following sub-folders, and next to them is their total execution time to completion:
rspec spec/acceptance 311.67s
rspec spec/controllers 18.97s
rspec spec/decorators 4.39s
rspec spec/helpers 9.45s
rspec spec/lib 16.88s
rspec spec/mailers 5.27s
rspec spec/models 121.05s
rspec spec/presenters 0.03s
rspec spec/workers 19.3s
Total run time: 8m 27s
Which certainly could be improved, but all in all is pretty managable.
However, if, I run rspec spec
and run the entire suite at once, the total time to complete is 27m 11s
!
So, obviously something we are doing is dramatically affecting the performance of the entire suite when run at once. I'm hoping that I can get some pointers as to where I can begin to try to troubleshoot this problem.
If it helps, I've posted my spec_helper.rb
file here
Thanks in advance,
Joe
Upvotes: 2
Views: 353
Reputation: 10195
At a guess, I'd say your integration specs are setting DatabaseCleaner
to :truncation
and it's not getting switched back to :transaction
for the other specs. I have a sample spec_helper
that navigates the situation here. There are also a couple methods provided that help you dig in and figure out which strategy is being used at any given time. Here it is for your convenience:
def cleaner_strategy
active_record_cleaner.instance_variable_get(:@strategy).class
end
def active_record_cleaner
DatabaseCleaner.instance_variable_get(:@cleaners)[[:active_record, {}]]
end
Side note: we use a filter for our integration specs since they are so slow. We disable them by default in our local env, and then let CI run them.
config.filter_run_excluding :slow unless ENV['SLOW']
Then you can run them individually with:
$ SLOW=true rspec spec/features/some_awesome_feature_spec.rb
Upvotes: 1
Reputation: 396
What does profiling tell you?
Run rspec spec --profile
or add --profile
to your ~/.rspec
file.
On completion of your tests, it will report the 10 slowest tests.
Upvotes: 0