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

Interface changes for support code #770

Closed
nicojs opened this issue Feb 21, 2017 · 3 comments
Closed

Interface changes for support code #770

nicojs opened this issue Feb 21, 2017 · 3 comments

Comments

@nicojs
Copy link
Contributor

nicojs commented Feb 21, 2017

I'm very happy with the interface changes done using issue #679 However, i still think its a little verbose and there is some room for improvement. I want to improve on that further.

Right now, a step definition file looks like this:

const {defineSupportCode} = require('cucumber');
defineSupportCode(({ Given, When, Then }) => {
    
    Given('something', function () {
         this.page = new SomethingPageObject();
    });

    Than('something should exit', function () {
         if(!this.page) {
              throw new Error('Something isn\'t there');
         }
    });
});

The way i see it, there are 2 things that could be better.

  1. First there is some very specific boilerplate code needed with the defineSupportCode. This is illustrated best with the ({ Given, When, Then }) part. Its an eye sore. I understand you're using parameter context matching here, but it's not that well known as an ES feature.

  2. Second, there is the this redirection for the world object. If i write my code examples with arrow functions instead of using the function keyword, bad things could happen because I'm leaking state. But this particular test will still succeed. This can be very confusing.

The first issue could be solved by requiring Given, When and Then directly form 'cucumber'. Is there a reason for the defineSupportCode construct?

The second issue is a little bit harder to solve without much clutter. But i still would like to improve the api. Any thoughts on this?

Background: I give automated testing courses to testers and i see they have a some trouble understanding concepts like this redirection and functional programming. I would like to improve their lives with the 2.0 api.

@charlierudolph
Copy link
Member

@nicojs sorry for the delayed response

Is there a reason for the defineSupportCode construct?

This was an easy transition from the original 1.0 interface as it dealt with functions and just moved the functions from this to the first argument. I cared most about stopping the library from calling all exported functions.

The first issue could be solved by requiring Given, When and Then directly form 'cucumber'

I'm okay with this if you'd like to take a stab. I believe the easiest way this could be implemented while retaining the current interface as well is

const {Given} = require('cucumber');

Given(...)

// is basically syntactic sugar for

defineSupportCode(({Given}) => {
  Given(...)
})

The second issue is a little bit harder to solve without much clutter. But i still would like to improve the api. Any thoughts on this?

See #745

@nicojs
Copy link
Contributor Author

nicojs commented May 10, 2017

I've created a WIP PR, lets talk about it there #828

See #745

Thanks! Lets talk about it there.

@lock
Copy link

lock bot commented Oct 25, 2018

This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.

@lock lock bot locked as resolved and limited conversation to collaborators Oct 25, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants