Created
March 9, 2018 15:04
-
-
Save benoittgt/a13ad810f9fd21963fb8be9751ff7956 to your computer and use it in GitHub Desktop.
find where data are leaking with rspec and active record
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
RSpec.configure do |config| | |
config.before(:suite) do | |
FactoryBot.find_definitions if FactoryBot.factories.count == 0 | |
DatabaseCleaner[:active_record].clean_with(:transaction) | |
end | |
config.around(:each) do |example| | |
unless User.count.zero? | |
# we will output to current terminal but also into a file in tmp | |
open('tmp/leaky.txt', 'a') { |f| | |
f << "Location is: #{example.location} with #{User.count} and ids: #{User.ids}\n" | |
} | |
p example.location | |
puts "Leak with #{User.count} and ids: #{User.ids}" | |
end | |
DatabaseCleaner.cleaning do | |
example.run | |
end | |
DataStore.clear | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
wip