bddkickstarter / Gherkin.TypeProvider

A Gherkin TypeProvider
The Unlicense
17 stars 2 forks source link

Better way to check if tag is present or not? #2

Closed deyanp closed 4 years ago

deyanp commented 4 years ago

I need to get a boolean flag true/false representing the present/absence of a scenario tag.

Is this the best way to do it, as it seems a bit redundant, and in case I remove the tag the line will not compile anyway:

let shouldMock = scenario.TagList.AllTags |> Array.contains scenario.Tags.mocked

(the tag is @mocked and is set at the scenario level)

bddkickstarter commented 4 years ago

Hi Deyan - the tags can be searched by their name:

scenario.TagList.AllTags |> Seq.tryPick(fun t -> t.Name = "@mocked)

I'm marking tags as visited, however I'm not sure about that now (as this wouldn't visit that tag as its getting it from the array....I might ad a way to exclude them from the report a bit easier)

deyanp commented 4 years ago

Yes, yours is the "untyped" approach with string comparison, above I have used the "strongly-typed" approach with scenario.Tags.mocked ... but somehow the strongly-typed approach is strange because if @mocked is not there it will not even compile ;)

bddkickstarter commented 4 years ago

yes that's right....there is a class called TagContainer on the scenario that will always have an array of the untyped tags. Typed tags are added as properties to the container using their name just like scenarios. If you remove that tag from your scenario then it will "disappear" from the container (the magic of type providers lol).

I'm still not 100% sure about that functionality cos as you know tags are a bit different as they're more about implementation than behaviour and i think that they would be used more like you are i.e. do they exist based on their name

bddkickstarter commented 4 years ago

I've fixed the fact that Features without tags were missing the underlying array and added a HasTag method which makes it easier to check for the existance of tags

let shouldMock = scenario.HasTag("@mocked")

....hope this helps