-
Notifications
You must be signed in to change notification settings - Fork 14
Test Factories
Mike Nelson edited this page Jan 29, 2020
·
1 revision
There is a separate gem subroutine-factory which enables you to easily utilize factories and operations to produce test data. It's a great replacement to FactoryGirl, as it ensures the data entering your DB is getting there via a real world operation.
# support/factories/signups.rb
Subroutine::Factory.define :signup do
op ::SignupOp
inputs :email, random{|r| "foo-{r}@example.com" }
inputs :password, "password123"
# by default, the op will be returned when the factory is used.
# this `output` returns the value of the `user` output on the resulting op
output :user
end
# signup_test.rb
user = Subroutine::Factory.create :signup
user = Subroutine::Factory.create :signup, email: "foo@bar.com"