Skip to content

Instantly share code, notes, and snippets.

@aquaflamingo
Created May 15, 2021 03:56
Show Gist options
  • Save aquaflamingo/32e163bb85bf9520fe6cbe8b9fa089f8 to your computer and use it in GitHub Desktop.
Save aquaflamingo/32e163bb85bf9520fe6cbe8b9fa089f8 to your computer and use it in GitHub Desktop.
# post.cr
class Post
YAML.mapping({
name: String,
description: String,
})
end
# factory.cr
module Factory
def make(klass : Class, name : Symbol) : Class
yaml = File.open("spec/fixtures/#{name}.yml") do |file|
YAML.parse(file)
end
klass.from_yaml(
yaml
)
end
end
# spec_helper
include Factory
# Test
post = make(Post, :post)
post.save
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment