Last active
November 13, 2021 03:07
-
-
Save Pistos/d2013bde9e482ee0396a3d5822ef0cbf to your computer and use it in GitHub Desktop.
Using Database Cleaner and FactoryBot with Hanami
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
# spec/factories/account.rb | |
FactoryBot.define do | |
factory :account, class: AccountRepository do | |
# ... | |
end | |
end |
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
require 'database_cleaner' | |
RSpec.configure do |config| | |
config.before(:suite) do | |
FactoryBot.find_definitions | |
DatabaseCleaner.strategy = :truncation | |
DatabaseCleaner.clean_with(:truncation) | |
end | |
config.around(:each) do |example| | |
DatabaseCleaner.cleaning do | |
example.run | |
end | |
end | |
end | |
FactoryBot.define do | |
initialize_with do | |
new.create(attributes) | |
end | |
to_create do |instance| | |
# Do nothing, because the instance should already have been saved at build | |
# time by the Hanami repository | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment