[libtest-bdd-cucumber-perl] 16/52: The language of a feature is now stated in the feature itself (as in cucumber)

Intrigeri intrigeri at moszumanska.debian.org
Thu Jun 19 10:18:33 UTC 2014


This is an automated email from the git hooks/post-receive script.

intrigeri pushed a commit to annotated tag 0.19
in repository libtest-bdd-cucumber-perl.

commit 86bb79ef8aa07b04cdb21fedb19cdfd9fae55488
Author: glauschwuffel <glauschwuffel at nomaden.org>
Date:   Sun May 18 15:44:27 2014 +0200

    The language of a feature is now stated in the feature itself (as in cucumber)
---
 examples/calculator/features/basic.feature.es |  1 +
 lib/Test/BDD/Cucumber/Model/Feature.pm        | 11 ++++++++++-
 lib/Test/BDD/Cucumber/Parser.pm               | 23 +++++++++++++++++++----
 t/240-localized-features.t                    | 21 +++++++++++++++++++++
 4 files changed, 51 insertions(+), 5 deletions(-)

diff --git a/examples/calculator/features/basic.feature.es b/examples/calculator/features/basic.feature.es
index 4e7adda..fec9f9f 100644
--- a/examples/calculator/features/basic.feature.es
+++ b/examples/calculator/features/basic.feature.es
@@ -1,3 +1,4 @@
+# language: es
 Característica: Funciones Básicas de Calculadora
   In order to check I've written the Calculator class correctly
   As a developer I want to check some basic operations
diff --git a/lib/Test/BDD/Cucumber/Model/Feature.pm b/lib/Test/BDD/Cucumber/Model/Feature.pm
index 7687b4b..5867177 100644
--- a/lib/Test/BDD/Cucumber/Model/Feature.pm
+++ b/lib/Test/BDD/Cucumber/Model/Feature.pm
@@ -74,6 +74,15 @@ Scenarios.
 
 has 'tags' => ( is => 'rw', isa => 'ArrayRef[Str]', default => sub {[]} );
 
+=head2 language
+
+Language the feature is written in. Defaults to 'en'.
+
+=cut
+
+has 'language' => ( is => 'rw', isa => 'Str',
+	default => sub { 'en' });
+
 =head1 AUTHOR
 
 Peter Sergeant C<pete at clueball.com>
@@ -84,4 +93,4 @@ Copyright 2011, Peter Sergeant; Licensed under the same terms as Perl
 
 =cut
 
-1;
\ No newline at end of file
+1;
diff --git a/lib/Test/BDD/Cucumber/Parser.pm b/lib/Test/BDD/Cucumber/Parser.pm
index 8b1da15..80bd05b 100644
--- a/lib/Test/BDD/Cucumber/Parser.pm
+++ b/lib/Test/BDD/Cucumber/Parser.pm
@@ -63,11 +63,13 @@ sub parse_file   {
 sub _construct {
 	my ( $class, $document, $tag_scheme, $language ) = @_;
 	
-	my $self = { keywords => $LANGUAGES->{$language} };
-        bless $self, $class;
-
 	my $feature = Test::BDD::Cucumber::Model::Feature->new({ document => $document });
-        my @lines = $self->_remove_next_blanks( @{ $document->lines } );
+        my @lines = $class->_remove_next_blanks( @{ $document->lines } );
+
+	$feature->language($class->_extract_language(\@lines));
+
+	my $self = { keywords => $LANGUAGES->{$feature->language} };
+        bless $self, $class;
 
 	$self->_extract_scenarios(
 	$self->_extract_conditions_of_satisfaction(
@@ -78,6 +80,19 @@ sub _construct {
 	return $feature;
 }
 
+sub _extract_language {
+    my ($self, $lines)=@_;
+
+    # return default language if we don't see the language directive on the first line
+    return 'en' unless $lines->[0]->raw_content =~ m{^\s*#\s*language:\s+(.+)$};
+
+    # remove the language directive if we saw it ...
+    shift @$lines;
+
+    # ... and return the language it declared
+    return $1;
+}
+
 sub _remove_next_blanks {
     my ( $self, @lines ) = @_;
     while ($lines[0] && $lines[0]->is_blank) {
diff --git a/t/240-localized-features.t b/t/240-localized-features.t
new file mode 100644
index 0000000..864faa2
--- /dev/null
+++ b/t/240-localized-features.t
@@ -0,0 +1,21 @@
+#!perl
+
+use strict;
+use warnings;
+
+use Test::More;
+use Test::BDD::Cucumber::Parser;
+
+my $files = {
+   en => 'examples/calculator/features/basic.feature',
+   es => 'examples/calculator/features/basic.feature.es'
+};
+
+for my $language (keys %$files) {
+    my $feature = Test::BDD::Cucumber::Parser->parse_file( $files->{$language} );
+
+    isa_ok $feature, 'Test::BDD::Cucumber::Model::Feature';
+    is $feature->language, $language, 'feature language';
+}
+
+done_testing;
\ No newline at end of file

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-perl/packages/libtest-bdd-cucumber-perl.git



More information about the Pkg-perl-cvs-commits mailing list