File: Feature.pm

package info (click to toggle)
libtest-cukes-perl 0.11-2
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, forky, sid, trixie
  • size: 140 kB
  • sloc: perl: 311; makefile: 5
file content (56 lines) | stat: -rw-r--r-- 1,205 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
package Test::Cukes::Feature;
use Moose;

use Test::Cukes::Scenario;

has name => (
    is => "rw",
    required => 1,
    isa => "Str"
);

has body => (
    is => "rw",
    isa => "Str"
);

has scenarios => (
    is => "rw",
    isa => "ArrayRef[Test::Cukes::Scenario]"
);

sub BUILDARGS {
    my $class = shift;
    if (@_ == 1 && ! ref $_[0]) {
        my $text = shift;
        my $args = {
            name => "",
            body => "",
            scenarios => []
        };
        my @blocks = split /\n\n/, $text;
        my $meta = shift @blocks;

        unless ($meta =~ m/^Feature:\s([^\n]+x?)$(.+)\z/sm) {
            die "Cannot extra feature name and body from text:\n----\n$meta\n----\n\n";
        }

        $args->{name} = $1;
        $args->{body} = $2;

        for my $scenario_text (@blocks) {
            unless ($scenario_text =~ s/^  (.+?)$/$1/mg) {
                die "Scenario text is not properly indented:\n----\n${scenario_text}\n----\n\n";
            } 
            push @{$args->{scenarios}}, Test::Cukes::Scenario->new($scenario_text)
        }

        return $args;
    }

    return $class->SUPER::BUILDARGS(@_);
}

__PACKAGE__->meta->make_immutable;
no Moose;
1;