Skip to content

Integration: Test::Unit

Mike Burns edited this page Apr 14, 2023 · 1 revision
class Test::Unit::TestCase
  include FactoryBot::Syntax::Methods
end

FactoryBot::Syntax::Methods

Including FactoryBot::Syntax::Methods gives you access to build, build_list, create, create_list, and attributes_for directly in your tests, such as:

def test_renders_itself
  user = create(:user, articles: build_list(:article, 2)) # not FactoryBot.create or FactoryBot.build_list
  writer = build(:writer) # not FactoryBot.build
  
  user.render(writer)

  assert writer.to_s == "User with two articles"
end