Skip to content

Instantly share code, notes, and snippets.

@paulcsmith
Last active September 22, 2015 20:42
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save paulcsmith/b9207d0949cb7a53b859 to your computer and use it in GitHub Desktop.
Save paulcsmith/b9207d0949cb7a53b859 to your computer and use it in GitHub Desktop.
ExMachina Cheat Sheet - v0.3.0
  • factory(factory_name) to define a factory
factory(:user) do
  %User{name: "John"}
end
  • create(:user, name: "Jane")
  • build(:user, name: "Jane")
  • assoc(:author, factory: :user) (can only be used inside factory definition)
factory(:article) do
  %Article{author_id: assoc(:author, factory: :user)}
end
  • create_pair(:user, name: "Jane")
  • create_list(3, :user, name: "Jane")
  • build_pair(:user, name: "Jane")
  • build_list(3, :user, name: "Jane")
  • sequence(:email, &"myemail-#{&1}@example.com")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment