-
-
Notifications
You must be signed in to change notification settings - Fork 690
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
Rules + Examples #250
Comments
I really like this. I'd love to be able to: a) Generate and display an example map (in an example mapping tool) from existing Gherkin documents (that follow this new structure). If we change the Gherkin grammar, it's essential that old documents still work:
The AST would have to change so that every Gherkin Document has a list of For legacy documents (no rules), we'd have to build the AST with a "dummy" rule. Automatic rule validationWe've been wanting to add property based testing support to Gherkin and Cucumber for a while. Recently @ELetier introduced to a tool called Alloy, which can be used to validate rules using a different approach. The overall idea is that Cucumber users would be able write Gherkin documents with rules without examples. A property based testing tool or a tool like Alloy (which would have to be integrated with Cucumber somehow) would generate examples at runtime, based on the properties associated with the rules. I'm bringing this up because I want to make sure that a change to the Gherkin grammar to allow for rules also makes it possible to hook in property based testing tools and/or tools like Alloy. For example:
The text of the rules above would actually be interpreted (with a rule definition?), and there wouldn't (necessarily) be any explicit scenarios below. Let's discuss! |
Those |
The way @ryanwmarsh suggested it initially, the only effect of However, Cucumber (or a Cucumber plugin) could use the |
@enkessler I intended it to simply be present in the AST as @aslakhellesoy stated however, I recognize that some folks would like this to actually be a "Rule definition" as @aslakhellesoy also mentioned |
So are we thinking the step def side would look something like: // Given/When/Then
StepDef("An adult is traveling with an infant", function() {
// implement this step
});
Rule("An adult is 18 or older", function() {
// implement this rule
}); Or does the rule need some added context? |
Something like that. Not sure if the ruledef needs additional context, I'm not yet familiar enough with the other tools I mentioned. |
Didn't @sebrose suggest something similar, maybe in the Gherkin repo? On phone now so can't easily search. |
Hello @cucumber/committers - I've written up some thoughts about how we could add property based testing to Cucumber over at cucumber-examples/shouty.rb#2. Do you see any problems with this? |
I have no problem with the structure of the feature file, although I would like to see also what properties do you check of the rule in the Gherkin file itself. In Cukenhagen we discussed about this and based on that discussion I made this example: But of couse this can be an optional part. If there would be a "Rule" level in the feature file and some way to hook any kind of automation for it that's a good start... |
I would like to know the difference between "Rule" and "Scenario", aren't we conveying the same in both the keywords? According to my knowledge "Rule" is a condition that needs to verify through Gherkin Steps. Is Rule is a kind of Condition check for Scenario? |
@mgundala see @mattwynne's article about Example Mapping for an explanation of rules vs scenarios (aka examples). This is the technique we recommend for designing scenarios in three amigos sessions. |
@ryanwmarsh what's your motivation for suggesting to rename |
IMO we don't need So ideally for me we'd have:
i.e. you can use |
@lunivore I'd love to know what you think about this |
I was thinking the last days about this, but I am still not sure about this suggestion. |
As there are several suggestions in this issue I suggest we focus on adding
Feel free to create separate issues for those. This issue is exclusively about adding a |
Maybe it's just because I'm not familiar either rules and property based testing, but every time I see
But it looks like a rule definition is no different from a step definition so I suppose that different people could use it in different ways. |
@enkessler Apart from the Example Mapping article, I think the @lunivore blog post Acceptance Criteria vs. Scenarios is a good description of the meaning of "Rule" (defined by the Acceptance Criteria) and "Example" (defined by the Scenarios) as used in the discussion. |
Hey Matt,
Scenario and Example are pretty much synonyms, with the first being easier
to imagine than the second. Historically we've used Example at a unit /
class level, and Scenario at a system level. I'm happy for that to
continue. "Give me an example" and "Give me a scenario where that happens"
are both good questions to get the conversation started.
If you want a really good word it's "Exemplar" but hardly anyone knows what
that means. I prefer to stick with plain English where possible. Please
don't remove "Scenario"; if you want to support "Example" as well, that
would be good.
I would really love to avoid "Specification" just because it makes it sound
as if things are concrete. I find those words tend to make people skip the
"exploration by example" bit of BDD, from which the specs and rules should
be derived. I prefer "Rule" to "Specification" or "Acceptance Criteria"
(which makes people think of software instead of behaviour). At least we
know rules are made to be broken.
(Also "Acceptance Criteria" is plural; it's "Criterion" if you've only got
one.)
With respect to "Shouts have a range of {int}", that's a rule / criterion.
If I then ask, "Can you give me an example?" you have to think of "The one
where...", hence, "The one where the queen shouts for Charles for dinner
and he's in Trafalgar Square" (we actually did this in one of the courses
that Aslak and I took jointly). That's an example. Or a scenario.
This becomes a lot clearer when there are different contexts in play, so if
in doubt, look for examples that have those. I really like Shouty as an
exercise though because it's new enough that people can actually practice
the exploration bit. It's really hard to explore things that aren't new.
Re Feature: meh, I don't really mind. I use capabilities, but sometimes we
need to subdivide capabilities by context or even by outcome when they
become extensive. Features are implementations of capabilities in contexts.
Consider using "Theme" if you want something non-software-related. That
works for everything, including elephants.
Also please ping me on Twitter or something if you want my thoughts; really
happy to give it but I only saw this by chance!
Cheers,
Liz.
…On Thu, Oct 5, 2017 at 9:57 PM, Matt Wynne ***@***.***> wrote:
@lunivore <https://github.com/lunivore> I'd love to know what you think
about this
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
<#250 (comment)>,
or mute the thread
<https://github.com/notifications/unsubscribe-auth/AA_ZkNhjsiKnscwieN46RsIzEGdCBTJHks5spULLgaJpZM4O80LW>
.
|
@mattwynne I do not think a Scenario Outline is a Rule, but a Scenario Outline can be used to define the set of Examples illustrating a Rule. I think a statement like "the Steps of a Rule" is nonsense, therefore I think it would be a mistake to place the Outline Steps directly below the Rule line, there need to be something in between to mark the line between the Rule itself and the Examples illustrating the Rule. |
I'm still a little confused over the addition. Is the idea to provide an intermediate level of description for the feature? That is I find feature is at a level down from what I might want, in so far as an Epic would describe a larger piece of functionality and the features would break that down, with the scenarios being more concrete user interactions. This 'seems' to be similar in that a rule is a level down or a way to group a set of scenarios. In our Features we often put as part of the description a bullet point list of Rules which are trying to give a high level description of the scenarios below. So if we have the additional Rule keyword it would wrap the scenarios/examples for that rule. I can see value in that. I'm still not clear why you'd add validation to the rule however, if the scenarios/examples are filling that role. If you want to make it more terse then having separate keywords for Specification that then have multiple When, Then, When thens etc. would seem clearer. |
A 'Rule' would specify a particular business rule (i.e. the range in Shouty, or the age at which Fluffy bunny can be sold); traditionally called 'acceptance criterion' in software development. Imho it would be helpful to explicitly specify these rules, as they would be tested by the scenarios/examples but might not be explicitly mentioned here. I do not understand if/how a Rule would then also be implemented to actually 'do' something (as in the example PR by @aslakhellesoy ); to me it would be additional background info to state which Rule (or Rules?) are being tested in certain Scenarios/Examples. The Scenarios/Examples would specify how the 'Rule" is applied in different situations and test that the 'Rule' is correctly implemented in the system. However, it could also be used as a 'setting' (as the range in the Shouty example), so you could test for different versions of a Rule? (i.e. different ranges). If that is the case, then I would wonder how this is different from a Given or a Background? |
Criteri on, not criteri um (it's Latinized Greek -> κριτήριον ), plural criteria. Rules might be about context (Given / Background), but they might also be triggered by actions or only affect outcome. So for instance:
|
Now I'm possibly more confused about the use of the 'Rule' keyword. Rule: Trade contract should be audited within 2 days. So, there's a 'Rule'; it is exemplified(?; I mean that an example is provided) / tested by the Scenario, the specific rule may come into play at any step in the scenario though? Second example: what does 'over Christmas' mean? |
Some rules require n+1 examples to illustrate. So in this case, you'd have two: the one where it took more than one day to audit, and the one where it didn't. I only illustrated one because that wasn't a facet I was focused on, but there it is. If you have a lot of different rules, you often have the "happy path" (your +1) and then all the edge cases ("n"). If you're just adding a new outcome, you're introducing a new rule without introducing any new examples, but you'll be extending an existing one. I'm sure there's some kind of mathematical construct, but my main point is that rules can have multiple examples. Remember though that the main purpose of BDD is to capture conversations, which explore the space and only produce specifications and tests as a nice by-product. We just had an exercise today for which we had a post-it on our forehead and could only ask yes/no questions in the room, then had to find our matching post-it pair. My question was, "Can you see my pair from here? Is my pair in that direction?" Perfectly within the rules, but I'm pretty sure it wasn't what they intended. That's the kind of thing that examples help to clarify. |
Do we have a conclusion here? Considering the idea of adding an additional, but optional "Rule" grouping around scenarios and scenario outlines...
I think the introduction of a Rule level grouping is quite an safe change. Even if the change will not be backward compatible it is easy to make an extension that provides the "flat" scenario structure for a feature file by visiting the rule/scenario tree. I run into this problem (lack of structure to express rules) more and more often and I would really like to have better support for it. |
This issue has been automatically marked as stale because it has not had recent activity. It will be closed in a week if no further activity occurs. |
Wow great discussion here. Somehow I didn't get the notifications. So many great points. I apologize for letting this go stale. 🙏
Now allow me to get crazy for a moment. I'm boiling the 🐸 slowly here. What if rules and examples didn't have to be in the same file?
Here's why. In some organizations rules are a meaningful artifact. In some organizations rules must be given an identifier so they may be referenced in various forms of documentation and discussion. Alternatively rules must correlate with an industry regulation. What I have proposed is an incomplete solution for organizing and referring to rules. How do we reason about the rules in our system when we have hundreds? My suggestion:
Boiling the 🐸 further. We still have the problem of terms. In many regulated businesses the terms used in rules matter greatly. Where are these terms to be defined? My gut says terms need to be first class citizens as well. I feel I might be considered disruptive with this but that is not my intention. I care that we say Cucumber is how we connect tests to rules and examples to produce "living documentation".
|
I agree about being able to relate Rules and Examples across Gherkin docs. I don’t see the need for a rule-ref, or the additional syntax to go with it. I think it would be in the spirit of Gherkin’s simplicity to just use the name of the Rule as it’s unique ID. So by duplicating the name of the rule in several places you could associate more scenarios to the Rule. I think it’s time for someone here to make a concrete proposal and we can go ahead and implement something. |
@ryanwmarsh I'm very much in favour of incorporating the Rules keyword, I almost always include it anyway. I'd be wary of separating them into two files though. Without capability to manage the relationship between them (would Cucumber do this?) we would quickly end up with unrelated rules and examples or rules without examples, etc. |
This has been done on master and will be released in Gherkin 6. Then we need to wait for Cucumbers to upgrade to Gherkin 6, which is quite a bit of work. But it's happening at least! |
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. |
Summary
There is no useful mapping between Gherkin and "rules and examples".
Expected Behavior
I can express Rules and Examples naturally (aside from the fact that Gherkin is context free grammar and will never be as fully expressive as English).
Current Behavior
Features, Scenarios and Steps are the high level concepts. Rules and Examples must be shoe-horned in by the user.
Possible Solution
Feature:
is replaced withSpec:
Rule:
is a new section in-between what is currentlyScenario:
andFeature:
Scenario:
is replaced withExample:
Scenario Outline:
is replaced withExample Outline:
Context & Motivation
We teach that:
The three most important concepts in Gherkin + Cucumber are features, scenarios, and steps.
There is no useful mapping between Gherkin and "rules and examples".
The text was updated successfully, but these errors were encountered: