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

[ModelInferrer] Make Features use methods to share step implementations instead of copying the AST #4

Open
riederm opened this issue Apr 29, 2017 · 3 comments
Assignees
Projects

Comments

@riederm
Copy link
Owner

riederm commented Apr 29, 2017

A stepReference is implement in a way so the AST from the referenced step is copied.

Feature: Testing stuff
    Scenario: Scenario 1
        Then "0" should equal "0"
            args.first => args.second
        And "1" should equal "0"

Copying the AST introduces some problems (e.g. these elements have no Node-Model applied).

instead of generating two basically identical methods:

 @Test
  @Order(0)
  @Named("Given foo \\\"0\\\"")
  public void _givenFoo0() {
    final StepArguments args = new StepArguments("0");
    InputOutput.<String>println(JnarioIterableExtensions.<String>first(args));
  }
  
  @Test
  @Order(1)
  @Named("Then foo \\\"2\\\"")
  public void _thenFoo2() {
    final StepArguments args = new StepArguments("2");
    InputOutput.<String>println(JnarioIterableExtensions.<String>first(args));
  }

it should generate the the implementation into its own method, and only call from the single steps:

  public void fooImpl(StepArguments args){
	  InputOutput.<String>println(JnarioIterableExtensions.<String>first(args));
  }
	
	@Test
  @Order(0)
  @Named("Given foo \\\"0\\\"")
  public void _givenFoo0() {
    final StepArguments args = new StepArguments("0");
    fooImpl(args);
  }
  
  @Test
  @Order(1)
  @Named("Then foo \\\"2\\\"")
  public void _thenFoo2() {
    final StepArguments args = new StepArguments("2");
    fooImpl(args);
  }

since steps can be used across different Scenario/Features, probably an implementation needs to be generated per Scenario.

@riederm riederm changed the title [ModelInferer] Make Features use methods to share step implementations instead of copying the AST [ModelInferrer] Make Features use methods to share step implementations instead of copying the AST Apr 29, 2017
@riederm
Copy link
Owner Author

riederm commented Apr 29, 2017

related issue: sebastianbenz#161

@riederm riederm added this to ToDo in Jnario 1.2 Apr 30, 2017
@ghaith
Copy link
Collaborator

ghaith commented Apr 30, 2017

Problem is that Steps can be shared across multiple Scenarios, if we want to extract the step into a common method it has to happen in the XXFeature.java class and not in the Scenario classes
Example :

 Feature: SomeClassFeature
	val a = 10
	Scenario: Testing a feature reference
		Given step 
			new SomeClass
	Scenario: Referencing it
		Given step

Another problem is a step can also be declared in a Background, however it is currently unusable from a scenario as it leads to generating the same method twice

@riederm
Copy link
Owner Author

riederm commented Apr 30, 2017

I just realized that steps can even be shared across different features. Interesting is, that it not only pulls the implementation into the other feature, but it also pulls the fields (that may be used, or may not be used) into the new feature.

This produces some interesting situations. You can reference two steps from two different features that both use a member variable with the same name, but with different types.

Maybe we need some conceptual work first.
A more cleaner approach would be to have some well defined scopes of the member-fields pulled in by spec-references. I could think of things like:

  1. pull in the variables and the implemention per feature, rename the variables to fully qualifying names.
  2. dont declare fields as simple fields but generate a member-Class that holds all fields as public members. Each feature that uses these variables instantiates its own object. So withing the implementation you would refer this variables using "someClassFeatureMembers.a" instead of "a". Basically the same idea like 1 - just differently executed

@riederm riederm moved this from ToDo to In Progress in Jnario 1.2 May 1, 2017
@riederm riederm moved this from In Progress to ToDo in Jnario 1.2 May 1, 2017
@riederm riederm removed this from ToDo in Jnario 1.2 May 1, 2017
@riederm riederm added this to ToDo in Jnario 1.2 May 1, 2017
@riederm riederm moved this from ToDo to In Progress in Jnario 1.2 May 14, 2017
@riederm riederm self-assigned this May 14, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Jnario 1.2
In Progress
Development

No branches or pull requests

2 participants