Created
May 15, 2021 03:56
-
-
Save aquaflamingo/32e163bb85bf9520fe6cbe8b9fa089f8 to your computer and use it in GitHub Desktop.
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
# 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