Skip to content

Instantly share code, notes, and snippets.

View FCO's full-sized avatar

Fernando Correa de Oliveira FCO

View GitHub Profile
@FCO
FCO / test.raku
Last active December 11, 2022 15:05
use Factories; # your factories module
factory-run {
my $child = .create: "child";
}
use Factories; # your factories module
my $*RED-DB = factory-db;
my $child = factory-create "child";
use Factories; # your factories module
my $*RED-DB = database "Pg", :host<some_host>;
my $child = factory-create "child";
use Child;
use Gift;
factory "child", :model(Child), {
.name = "Aline";
.country = "Brazil";
}
factory "gift", :model(Gift), {
.name = "a gift";
@FCO
FCO / 2nd try.md
Last active December 11, 2022 14:40

RedFactory

Since the elves started using Red (https://raku-advent.blog/2019/12/21/searching-for-a-red-gift/) they thought it was missing a better way of testing code that uses it. They tested it using several SQL files that would be used before each test to populate the database with test data. That works ok, but that's too hard to understand what's expected from the test not looking at those SQL files. It also added a big chunk of boilerplate at the beginning of each test file for

factory-run {
.create: "post", "archived"
}
factory "post", :model(Post), {
.title = {
"Post title { .counter-by-model }"
}
.body = -> $_, :$title-repetition = 3 {
(.title ~ "\n") x $title-repetition
}
trait "archived", {
.archived = now
factory "post", :model(Post), {
.title = {
"Post title { .counter-by-model }"
}
.body = -> $_, :$title-repetition = 3 {
(.title ~ "\n") x $title-repetition
}
factory-run {
.create: "post";
# Post.new: :title("Post title 1"), :body("Post title 1\nPost title 1\nPost title 1\n")
.create: "post";
# Post.new: :title("Post title 2"), :body("Post title 2\nPost title 2\nPost title 2\n")
.create: "post", :title<aaa>;
# Post.new: :title("aaa"), :body("aaa\naaa\naaa")
factory "post", :model(Post), {
.title = {
"Post title { .counter-by-model }"
}
.body = -> $_, :$title-repetition = 3 {
(.title ~ "\n") x $title-repetition
}
}