Add config.around(:all) // current behaviour is confusing, and the same as around(:each)
Created by: rosenfeld
edited by @samphippen on 2018-10-22 Check this comment for the latest. We're trying to decide what this should do. edited by @samphippen on 2018-10-22
RSpec configurator currently allows us to have a config.around(:each) block, which is very useful. But it doesn't support a config.around(:all) which would also be a great addition.
The main reason is test suite performance. Let me explain.
My slowest specs, as usual, are those who touch the database. I've found that truncation is way more expensive in PostgreSQL than beginning a transaction and rolling it back. Also PostgreSQL also supports nested transactions (savepoints).
Sequel only supports the use of transaction through a block usage as
config.around(:each) do |example|
DB.transaction(savepoint: true, rollback: :always) { example.run }
end
But some example groups need an expensive setup where we need to create several records in the database. Let's say it takes 100ms just to set up all records. If I have 10 examples, the whole group will take 1s just setting up the database.
On the other hand, if RSpec supported config.around(:all) I could perform the group set up in a before(:all) block instead of a before(:each). This way, instead of the whole group taking over a second, it would take just a bit more than 100ms, which is a big improvement of 10x in the suite running time.
I can confirm that because I use a hack over Sequel using non-supported techniques to achieve the same effect and it does improve a lot our suite completion time. But I'm not comfortable in doing so in case this hack stops working with a new Sequel release.
Are there any reasons not to support around(:all) blocks?