28 / 28 lines covered (100.0%)
1unit module BDD::Behave::SpecTree::ExampleGroup;23need BDD::Behave::SpecTree::Core;4need BDD::Behave::SpecTree::Example;56constant SpecNode = BDD::Behave::SpecTree::Core::SpecNode;7constant Container = BDD::Behave::SpecTree::Core::Container;8constant HookPhase = BDD::Behave::SpecTree::Core::HookPhase;9constant Hook = BDD::Behave::SpecTree::Core::Hook;10constant Example = BDD::Behave::SpecTree::Example::Example;1112our class ExampleGroup is SpecNode does Container {13 has Hook @.before-all-hooks;14 has Hook @.after-all-hooks;15 has Hook @.before-each-hooks;16 has Hook @.after-each-hooks;17 has Hook @.around-all-hooks;18 has Hook @.around-each-hooks;19 has @.lets;2021 method groups {22 @!children.grep(::?CLASS);23 }2425 method examples {26 @!children.grep(Example);27 }2829 method add-group(::?CLASS:D $group --> ::?CLASS) {30 self.add-child($group);31 }3233 method add-example(Example $example --> Example) {34 self.add-child($example);35 }3637 method add-let($let) {38 @!lets.push($let);39 $let;40 }4142 method let-definitions {43 @!lets // [];44 }4546 method add-hook(HookPhase:D $phase, Callable:D $callback,47 :@include-tags = [], :@exclude-tags = [], :%meta = %()48 --> Hook) {49 my $hook = Hook.new(50 :$callback,51 :include-tags(@include-tags.list),52 :exclude-tags(@exclude-tags.list),53 :%meta,54 );55 given $phase {56 when 'before-all' { @!before-all-hooks.push($hook) }57 when 'after-all' { @!after-all-hooks.push($hook) }58 when 'before-each' { @!before-each-hooks.push($hook) }59 when 'after-each' { @!after-each-hooks.push($hook) }60 when 'around-all' { @!around-all-hooks.push($hook) }61 when 'around-each' { @!around-each-hooks.push($hook) }62 }63 $hook;64 }6566 method hooks(HookPhase:D $phase --> List) {67 given $phase {68 when 'before-all' { @!before-all-hooks.List }69 when 'after-all' { @!after-all-hooks.List }70 when 'before-each' { @!before-each-hooks.List }71 when 'after-each' { @!after-each-hooks.List }72 when 'around-all' { @!around-all-hooks.List }73 when 'around-each' { @!around-each-hooks.List }74 }75 }76}