Skip to content
Fernando Correa de Oliveira edited this page Oct 20, 2018 · 7 revisions
use Test;
use Red;

plan 2;

my $*RED-DB = database "Mock";
$*RED-DB.die-on-unexpected;

model ExampleModel { has Int $.col is column }

$*RED-DB.when: "CREATE TABLE example_model(col INTEGER NULL)", :once, :return[];

ExampleModel.^create-table;

$*RED-DB.when: rx:i/SELECT \s+ col/, :once, :return[{:10data}, {:20data}, {:30data}];

is (10, 20, 30), ExampleModel.^all.map({ .col }), "map is working";

$*RED-DB.verify;

Output:

1..2
ok 1 - map is working
    1..2
    ok 1 - Query 'create table example_model ( col integer null )' should be called 1 times and was called 1 time(s)
    ok 2 - Query that matches 'rx/select \s+ col/' should be called 1 times and was called 1 time(s)
ok 2 - Red Mock verify
Clone this wiki locally