Clarification on culture info

305 views
Skip to first unread message

Matt Ellis

unread,
Feb 1, 2011, 11:43:10 AM2/1/11
to SpecFlow
Hi. Can someone clarify what's going on with the usage of CultureInfo
in SpecFlow, please?

It looks like there are 4 places to specify CultureInfo/language.

1. In the app.config file <language feature="..." />

This appears to be used as the language to parse the feature file
with, and is passed into the FeatureInfo constructor in the generated
code behind.

2. In the app.config file <language tool="..." />

I don't know what this is used for.

3. In the feature file: #language: en-US

Overrides the app.config's <language feature="..." /> on a per-feature
file basis. Affects the language used to parse the feature file, and
is also placed into the FeatureInfo constructor in the generated code
behind.

4. In the app.config <bindingCulture name="..." />

Not sure about this one.

I think it's the culture that's used to run each step. It appears to
come either from config or from the featureInfo set in the generated
code behind. But it looks like the bindingCulture config is never read
at runtime, only at generate time.

Can someone confirm if I've got this right, and/or explain what the
tool attribute in <language> is for?

Also, how can I get one scenario running in a different culture that
the default? I'd like to add a new scenario that shows my
implementation works fine in another culture, but because the
CultureInfo is reset across steps, I can't do this (without rolling my
own support with a BeforeStep hook...)

Thanks
Matt

Jonas Bandi

unread,
Feb 2, 2011, 5:08:33 AM2/2/11
to spec...@googlegroups.com
Hi, thanks for pointing out. We should definitely update our documentation...

***** App.config: *****
** <language feature="..." />
This defines the default language in which feature files are written
resp. in which SpecFlow will expect that the files are written. (ie.
this defines the Gherkin keywords that SpecFlow will use to parse the
feature files)

** <language tool="..." />
This is currently not used. This was thought to be the configuration
for localizing SpecFlow itself (i.e. Messages, Tracing etc). Currently
SpecFlow supports only English.

** <bindingCulture name="..." />
This defines the culture that is used when executing steps.
This is primarily relevant for the argument-transformations when
transforming arguments from the feature-file plain-text to a non-text
argument of a step-binding method (vie the regexp capture groups).
If this is not set, the same culture as set in <language feature="..."
/> is used.

Discussed in this thread:
http://groups.google.com/group/specflow/browse_thread/thread/fb424bb1c20e765/47f25440fccabbc3?lnk=gst&q=bindingCulture#47f25440fccabbc3

Here is an example:
https://github.com/techtalk/SpecFlow/blob/master/Tests/FeatureTests/App.config
https://github.com/techtalk/SpecFlow/blob/master/Tests/FeatureTests/StepArgumentTransfomation/StepArgumentTransformationGermanFeatureEnglishBinding.feature
https://github.com/techtalk/SpecFlow/blob/master/Tests/FeatureTests/StepArgumentTransfomation/StepArgumentTransformationSteps.cs

=> Here we have set 'de' as culture through the comment in the feature
file. But the binding culture is 'en-US'
=> You can use the german sentence "Dann ist 0.2 kleiner als 1" and
the 0.2 is converted into a double even though ',' is the decimal
separator in the 'de' culture.


***** Feature file: *****
#language: en-US
This overrides the default <language feature="..." /> from App.config
for specific feature files.


I hope this has shed some light on the different configurations?

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

Reply all
Reply to author
Forward
0 new messages