How to change current culture without changing the keyword language?

303 views
Skip to first unread message

mgilden

unread,
Jun 30, 2010, 11:02:38 AM6/30/10
to SpecFlow
I'm trying to upgrade to SpecFlow 1.3.2 but I have run in to a problem
with the way languages are handled.

All our feature files are written in the english language, since this
is the language of our domain, but all values such as decimals, dates
and so on are all formatted according to danish culture info. With the
new release of SpecFlow we seem to be bound to either translate the
feature files to danish or explicitly tell all formatting methods to
use danish culture. Is there any other way to have english Gherkin
keywords while stille having the current culture info be danish?

Thanks,
Martin

Jonas Bandi

unread,
Jul 1, 2010, 4:55:01 AM7/1/10
to spec...@googlegroups.com
Since SpecFlow 1.3 we are using the culture of the feature files to do
the conversions (numbers, dates ...).

To use a different culture for your formatting than for the feature
language you can use the [StepArgumentTransformation] feature.
It is a bit of work: you have to define a StepArgumentTransformation
method for each type you want to convert.
But you only have to do that once and you can even put those steps
into its own library to reuse it across projects.

I have put an example onto SpecFlow-Examples to demonstrate what I
just described:

http://github.com/techtalk/SpecFlow-Examples/tree/master/features/SpecFlow.Examples.StepArgumentTransformation/

Please tell us if this works for you.

-jonas

--
mail: jonas...@gmail.com
web: www.jonasbandi.net
blog: blog.jonasbandi.net
twitter: twitter.com/jbandi

mgilden

unread,
Jul 1, 2010, 7:57:39 AM7/1/10
to SpecFlow
Hi Jonas,

Thanks for your reply, I wasn't aware of the
StepArgumentTransformation feature. While this is a great feature it
doesn't solve the problem entirely for us.

It solves the problem with step arguments of primitive types. But
since the CurrentCulture remains english we still experience problems:
- When using tables as step arguments, where we do custom parsing of
values.
- With formatting done in the system under test

We have currently solved the problem by introducing parsing- and
formatting helper classes that apply a specific culture to all
operations of that kind and use these in both steps and system under
test. Combined with the feature you mentioned everything is good
again.

I do think it is a great feature of SpecFlow to actually use a
specific culture when executing the tests since the feature files are
obviously written in a specifc format. But I would probably prefer to
have the option to configure culture and Gherkin language
independently. Maybe as an optional configuration value that would
explicitly state the culture to be set as CurrentCulture.

Thanks again,
Martin

On 1 Jul., 10:55, Jonas Bandi <jonas.ba...@gmail.com> wrote:
> Since SpecFlow 1.3 we are using the culture of the feature files to do
> the conversions (numbers, dates ...).
>
> To use a different culture for your formatting than for the feature
> language you can use the [StepArgumentTransformation] feature.
> It is a bit of work: you have to define a StepArgumentTransformation
> method for each type you want to convert.
> But you only have to do that once and you can even put those steps
> into its own library to reuse it across projects.
>
> I have put an example onto SpecFlow-Examples to demonstrate what I
> just described:
>
> http://github.com/techtalk/SpecFlow-Examples/tree/master/features/Spe...
>
> Please tell us if this works for you.
>
> -jonas
>
> On Wed, Jun 30, 2010 at 5:02 PM, mgilden <mar...@gildenpfennig.dk> wrote:
> > I'm trying to upgrade to SpecFlow 1.3.2 but I have run in to a problem
> > with the way languages are handled.
>
> > All our feature files are written in the english language, since this
> > is the language of our domain, but all values such as decimals, dates
> > and so on are all formatted according to danish culture info. With the
> > new release of SpecFlow we seem to be bound to either translate the
> > feature files to danish or explicitly tell all formatting methods to
> > use danish culture. Is there any other way to have english Gherkin
> > keywords while stille having the current culture info be danish?
>
> > Thanks,
> > Martin
>
> --
> mail: jonas.ba...@gmail.com

jbandi

unread,
Aug 22, 2010, 5:47:05 PM8/22/10
to SpecFlow
Hi,
SpecFlow supports now setting the „bindingCulture“, which defines the
culture that is used when executing steps.
The feature is in master on github now and will be part of the next
release (> 1.3.5)

An example how to set the bindingCulture is here:
http://github.com/techtalk/SpecFlow/blob/master/Tests/FeatureTests/App.config
http://github.com/techtalk/SpecFlow/blob/master/Tests/FeatureTests/StepArgumentTransfomation/StepArgumentTransformationGermanFeatureEnglishBinding.feature
http://github.com/techtalk/SpecFlow/blob/master/Tests/FeatureTests/StepArgumentTransfomation/StepArgumentTransformationSteps.cs

Any feedback is appreciated.
Regards
jonas
Reply all
Reply to author
Forward
0 new messages