cabbage icon indicating copy to clipboard operation
cabbage copied to clipboard

Support setup, setup_all callbacks

Open revati opened this issue 5 years ago • 5 comments

setup_all -> should initialize test file scope setup -> should be able to setup scenario, alternative to background.

How they should be behaving together?

revati avatar Feb 27 '19 17:02 revati

Background should be translated to setup and that is it.

hauleth avatar Feb 27 '19 18:02 hauleth

@hauleth Yeah, they should do the same thing. Where

  • setup is more technical setup functionality
  • the background is more domain setup functionality

From this it seems that workflow should be as follows:

  • setup_all
  • setup
  • background
  • feature steps
  • all exits

revati avatar Feb 27 '19 18:02 revati

The issue with background === setup is that this might break developer expectations. My first implementation did exactly that, but the thing is that ExUnit maintains the order that setup callbacks are defined.

Given the code replacement that is happening behind the scenes, if a developer writes an explicit setup block anywhere underneath the 'using' line, their setup block will run after tags and after background steps.

This is fine for tags, as they are a before/after thing which follows the Gherkin spec. But I think it would break expectations to have user defined 'setup' blocks run after the background steps.

Now I would argue if you're using Cabbage you shouldn't be writing explicit (ExUnit) 'setup' blocks when you should be using background steps, but there is still something to be said for making the experience as smooth as possible and minimising surprises.

mononym avatar Mar 04 '19 13:03 mononym

Perhaps a good documentation with recommendations like beware if you use setup and background would fit most of the use cases (?)

hisapy avatar Mar 04 '19 14:03 hisapy

I think calling it out explicitly would definitely be a good thing, and like you said would cover most use cases.

mononym avatar Mar 05 '19 07:03 mononym