2

I would like to test whenver the result of a step has a certain value, but this value is a multiline string that contains |, - and any special characters.

The string can look like:

{ ------- }|
{aaaaaaaaaa|
{aaaaaaaaaa|

I'm not sure how can I do it in a feature as this will throw me a syntax error:

Feature: asdada

  Scenario: test
    Given test
    When test
    Then the result is:
      { ------- }|
      {aaaaaaaaaa|
      {aaaaaaaaaa|
Kara
  • 6,115
  • 16
  • 50
  • 57
Totty.js
  • 15,563
  • 31
  • 103
  • 175
  • 1
    Surround the multiline text within """blah blah""" -- 3 double quotes. Refer to the second answer in this post --- https://stackoverflow.com/questions/35639150/is-it-possible-to-write-a-gherkin-step-on-multiple-lines – Grasshopper Oct 22 '18 at 14:20

2 Answers2

5

Example from Is it possible to write a gherkin step on multiple lines?

thanks to Grasshopper for answering this.

Given a blog post named "Random" with Markdown body
  """
  Some Title, Eh?
  ==============
  Here is the first paragraph of my blog post. Lorem ipsum dolor sit amet,
  consectetur adipiscing elit.
  """
Kara
  • 6,115
  • 16
  • 50
  • 57
Totty.js
  • 15,563
  • 31
  • 103
  • 175
-4

Don't do this, you are just making your scenario really fragile. Instead give the string a name and use that name in the scenario e.g. Then I should see the foo result. Now you can delegate the string comparison to the step definition, and define what the foo result is however you choose.

Scenarios are about documenting what you are doing and why its important. The format of results is all about how you are doing things. If you put the how in scenarios then every time you change how you do something you have to change scenarios. This makes small changes much more expensive.

diabolist
  • 3,990
  • 1
  • 11
  • 15
  • Thank you, but I think your approach is harder to change. I have different output based on the steps I do, is completely dynamic. Harder to read: So having a variable would require the reader of cucumber tests to check the result on another file. Harder to change: When I need to change something, I need to check the other file full of 2d maps. I think is better to do it inline like the comment. With your example would be: "Then I should see the resultA", resultB, resultC. There is no proper name you could give to these 2d maps. You could say, result is "2 roomst, 5 doors, 2 people, 1 is blue" – Totty.js Oct 23 '18 at 02:11
  • No my result would not be "Then I should see the resultA", resultB, resultC". And you can give a name to anything. Sometimes it can be really hard to find a good name, but that is part of understanding What you are doing and Why its important. Putting results in features makes them error prone (if the scenario breaks is it because the result has a typo or because it is wrong). And using scenarios to prove results is just wasteful. You could do that much more efficiently with a unit test. Anyhow good luck with your problem – diabolist Oct 24 '18 at 11:37
  • 1
    So how would you call a map of 5x5 with one line. Now another map 5x5 with one line offset and so on. Then again, reading the cucumber test alone should let you understand the test. In your example, reading the cucumber test won't help. you need to go to check what resultA means. Even with proper naming you won't get too far. That's my opinion, cucumber tests have to be readable directly, not by checking in some other place to understand. The result is core part of the software. But if you can give me a real scenario that works better, you can change my mind. – Totty.js Oct 25 '18 at 07:21
  • scenarios are not for explaining how things work. They are for driving the development of some behaviour. They are rubbish at showing complex results and structures, but this is by design, they are not meant to show complex results and structures. Scenarios are not for you the developer to see things are OK, they are for Brenda you manager to see that this bit of behaviour is working. She won't understand a text representation of your map of whatever anymore than I can. – diabolist Oct 25 '18 at 09:36
  • Imagine your thing is a 3 dimensional complex solid. You want your scenario to show that its valid. Good luck representing that structure in text, in a way that anyone can confirm its correct. Your argument states that for the scenario to be readable you have to be able to accurately represent the valid form of a result using text. My argument is that you don't have to do that, and goes further and states that representing any object in a scenario, a solid, an order, a blog post etc. is counter productive because it makes the scenario less readable for its target audience. – diabolist Oct 25 '18 at 09:44
  • One final thing, your scenario saying that xxx is valid, however you represent it, does not mean that xxx is valid. Any cucumber step can pass by having nothing in its body. They can pass by having the wrong code in its body. Scenarios ARE NOT tests. – diabolist Oct 25 '18 at 09:48
  • 1
    "Scenarios are not for you the developer to see things are OK, they are for Brenda you manager to see that this bit of behaviour is working." this is exactly what Brenda wants to see, the line is drawn when she draws a line. Is not a text representation, is the actual final product she will see. " have to be able to accurately represent the valid form of a result using text": this is where you got it wrong, the final output of the software is to output to console this text for the end user to see. "Scenarios ARE NOT tests": a scenario doesn't test? they are called e2e tests. – Totty.js Oct 26 '18 at 06:22