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
| sub | delegates to |
|---|---|
build | ORM::Factory.build |
create | ORM::Factory.create |
build-stubbed | ORM::Factory.build-stubbed |
attributes-for | ORM::Factory.attributes-for |
build-list | ORM::Factory.build-list |
create-list | ORM::Factory.create-list |
build-stubbed-list | ORM::Factory.build-stubbed-list |
attributes-for-list | ORM::Factory.attributes-for-list |
build-pair | ORM::Factory.build-pair |
create-pair | ORM::Factory.create-pair |
generate | ORM::Factory.generate |
generate-list | ORM::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;