File: 220_tag_parsing.t

package info (click to toggle)
libtest-bdd-cucumber-perl 0.26-1~bpo70%2B1
  • links: PTS, VCS
  • area: main
  • in suites: wheezy-backports
  • size: 528 kB
  • sloc: perl: 3,436; makefile: 8
file content (62 lines) | stat: -rw-r--r-- 1,505 bytes parent folder | download
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
57
58
59
60
61
62
#!perl

use strict;
use warnings;

use Test::More;
use Test::BDD::Cucumber::Parser;

my $feature_with_background = <<'HEREDOC'
@inherited1 @inherited2
Feature: Test Feature
	Conditions of satisfaction

	Background:
		Given a passing step called 'background-foo'
		Given a background step that sometimes passes

	@foo @bar
	Scenario: Two tags
		Given a passing step called 'bar'
		Given a passing step called 'baz'

	@baz
	Scenario: One tag
		Given a passing step called 'bar'
		Given a passing step called '<name>'
		Examples:
		  | name |
		  | bat  |
		  | ban  |
		  | fan  |
HEREDOC
;

my $feature_without_background = $feature_with_background;
$feature_without_background =~ s/\tBackground.+?\n\n//s;

for (
	[ "Feature with background section", $feature_with_background ],
	[ "Feature without background section", $feature_without_background ],
) {
	my ( $name, $feature_text ) = @$_;
	note( $name );

	my $feature = Test::BDD::Cucumber::Parser->parse_string( $feature_text );

	my @scenarios = @{ $feature->scenarios };
	is( @scenarios, 2, "Found two scenarios" );

	my $tags_match = sub {
		my ( $scenario, @expected_tags ) = @_;
		my @found_tags = sort @{$scenario->tags};
		is_deeply( \@found_tags, [sort @expected_tags],
			"Tags match for " . $scenario->name );
	};

	$tags_match->( $feature,      qw/inherited1 inherited2         / );
	$tags_match->( $scenarios[0], qw/inherited1 inherited2 foo bar / );
	$tags_match->( $scenarios[1], qw/inherited1 inherited2 baz     / );
}

done_testing();