methods-syntax

Methods syntax

use ORM::Factory exports plain-sub wrappers around every public factory method, so specs can stay terse:

use ORM::Factory;

define {
  .factory: 'user', { .fname: 'Greg' };
  .sequence: 'counter', -> $n { $n };
};

build('user');              # → ORM::Factory.build('user')
create('user', :role<admin>);
attributes-for('user');
build-stubbed('user');
build-list('user', 5);
create-pair('user');
generate('counter');

Available helpers

subdelegates to
buildORM::Factory.build
createORM::Factory.create
build-stubbedORM::Factory.build-stubbed
attributes-forORM::Factory.attributes-for
build-listORM::Factory.build-list
create-listORM::Factory.create-list
build-stubbed-listORM::Factory.build-stubbed-list
attributes-for-listORM::Factory.attributes-for-list
build-pairORM::Factory.build-pair
create-pairORM::Factory.create-pair
generateORM::Factory.generate
generate-listORM::Factory.generate-list

Qualified vs. bare-name syntax

The qualified form (ORM::Factory.build('user')) and the bare-name form (build('user')) are both available after use ORM::Factory. Pick one style per spec rather than mixing them.

behave / Test integration

Both behave and the core Test module are plain Raku, so the helpers work in either harness without extra glue:

use BDD::Behave;
use ORM::Factory;

describe 'user factory', {
  it 'creates a user', { expect(create('user').saved).to.be-truthy };
};
use Test;
use ORM::Factory;

is build('user').fname, 'Greg', 'static attribute';
done-testing;

The Camelia image is copyright 2009 by Larry Wall. "Raku" is trademark of the Yet Another Society. All rights reserved.