Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Expecting that only the annotation of defined language in feature work #1543

Closed
kaygisiz opened this issue Jan 23, 2019 · 12 comments
Closed
Labels
⚡ enhancement Request for new functionality

Comments

@kaygisiz
Copy link

kaygisiz commented Jan 23, 2019

Summary

When I define the language of feature using “# language:”, i am expecting that only the annotation of that language work, and others don’t. Just like how The localized keywords work and Given/When/Then does not.

My stepdef class:

public class StepDefinitions {
    @Eğerki("^sadece bi cümle$")
    @Given("^just a sentence$")
    public void deneme() {
        System.out.println("worked");
    }
}

My feature file:

# language: tr
 
Özellik: Dil
  Senaryo:
    Eğer ki just a sentence

in above example, i can't write 'Given' but i can write a 'Given' step after 'Eğerki'. I think this is a syntax error.

Expected Behavior

Test should fail either with a no step definition found or with kind of a wrong language message when defined language in feature file and language of called method's stepdef annotation doesn't match.

Current Behavior

Cucumber allows you write steps from any language defined in step definitions.

Possible Solution

Cucumber core/expressions doesn’t store language of the expression. The lang of annotation should be stored along with the regexp and shoudl be check during pickle matching.

Context & Motivation

I am trying to support selectable multiple languages in my project that using cucumber. I am planning to write multiple annotations for different languages on each method annotation and the user will just see step definitions of the selected language in the IDE.

There is also the rare case that step definitions from different languages may cause duplicate step definition errors.

Environment

  • cucumber-java: 1.2.5
  • cucumber-jvm-deps: 1.0.5
  • cucumber-testng: 1.2.5
  • testng: 6.9.8
@furkanozbay
Copy link

furkanozbay commented Jan 24, 2019

Same here

@ugurkekec
Copy link

Hi bro, same issue

@ooktay
Copy link

ooktay commented Jan 24, 2019

👍 this will be great for our test library i18n. I don't like it when regexps are separate from source.

@mpkorstanje mpkorstanje added Core ⚡ enhancement Request for new functionality labels Jan 25, 2019
@mpkorstanje
Copy link
Contributor

This is an interesting feature request. Without going into its merits, to achieve it a significant amount of re-engineering of cucumbers core is needed. Briefly:

  1. Step annotations and lambda's do not contain information about the language used to generate them
  2. Consequently step definitions can not contain any information about the language used in a step
  3. As a result it is not possible to match steps by language.

So before we discuss this features merit; would any of you be able to volunteer your time?

@kaygisiz
Copy link
Author

okay, i will be able to

@ooktay
Copy link

ooktay commented Jan 29, 2019

I'll work with @kaygisiz and try to make it into 4.3.0

@mpkorstanje
Copy link
Contributor

mpkorstanje commented Jan 29, 2019

Excellent. This will be a breaking change so we can't introduce it until v5. There is a develop-v5 that would be a good place to start researching.

It would perhaps also be good to look at #1426 and #1458. The TypeRegistry uses localized number converters. These should match the language used by the step definition. So steps of different languages should use a type registry for the same language.

By making parameter types part of the glue this localization become easier. For example with the code below the steps Donnée une 42,0 and Given a 42.0 should both yield 42 but depending on the locale set in the ParameterType either french or English will receive the right number.

@Donnée("une {chose}")
public void a_thing(Thing thing){
    ....
}

@Given("a {thing}")
public void a_thing(Thing thing){
  ....
}

By defining the parameter types in the glue however it becomes possible to make a distinction here.The french and English parameter could be transformed using a different locale (recognizable by the language of the annotation).

@Paramètre(name="chose", pattern=".*")
public Thing parseThing(double d)(
   return new Thing(d);
}

@Parameter(name="thing", pattern=".*")
public Thing parseThing(double d)(
   return new Thing(d);
}

@mpkorstanje
Copy link
Contributor

I also do have some questions about the merit of this feature. On it's face I can see that this the proper way to do things when developing features in multiple languages at the same time. However I have never encountered this in practice. Could you give me a concrete real world example of this?

@ooktay
Copy link

ooktay commented Feb 1, 2019

Actually, I do have some common step defs that I use for many clients and I package them in jars. Some clients want these functions in local language, so I need to package them separately.
I need to do this for each common module.

@mpkorstanje
Copy link
Contributor

Fair enough.

@mpkorstanje
Copy link
Contributor

I haven't seen any activity on this since. Feel free to reopen if/when some progress is made.

@eitzenbe
Copy link

Is there any update on this? I would think that adding a language to the anotation would allow at least IDE plugins to deal with it maybe even the cucumber parser?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
⚡ enhancement Request for new functionality
Projects
None yet
Development

No branches or pull requests

6 participants