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
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
| use Factories; # your factories module | |
| factory-run { | |
| my $child = .create: "child"; | |
| } |
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
| use Factories; # your factories module | |
| my $*RED-DB = factory-db; | |
| my $child = factory-create "child"; |
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
| use Factories; # your factories module | |
| my $*RED-DB = database "Pg", :host<some_host>; | |
| my $child = factory-create "child"; |
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
| use Child; | |
| use Gift; | |
| factory "child", :model(Child), { | |
| .name = "Aline"; | |
| .country = "Brazil"; | |
| } | |
| factory "gift", :model(Gift), { | |
| .name = "a gift"; |
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
| factory-run { | |
| .create: "post", "archived" | |
| } |
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
| factory "post", :model(Post), { | |
| .title = { | |
| "Post title { .counter-by-model }" | |
| } | |
| .body = -> $_, :$title-repetition = 3 { | |
| (.title ~ "\n") x $title-repetition | |
| } | |
| trait "archived", { | |
| .archived = now |
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
| factory "post", :model(Post), { | |
| .title = { | |
| "Post title { .counter-by-model }" | |
| } | |
| .body = -> $_, :$title-repetition = 3 { | |
| (.title ~ "\n") x $title-repetition | |
| } |
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
| 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") |
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
| factory "post", :model(Post), { | |
| .title = { | |
| "Post title { .counter-by-model }" | |
| } | |
| .body = -> $_, :$title-repetition = 3 { | |
| (.title ~ "\n") x $title-repetition | |
| } | |
| } |