cabbage-ex / gherkin

A Gherkin file parser written in Elixir. Extracted from https://github.com/meadsteve/white-bread.
11 stars 8 forks source link

Scenarios descriptions should not start with "When" #17

Open HertzDevil opened 4 years ago

HertzDevil commented 4 years ago

Scenario descriptions are not allowed to start their lines with a keyword, including When, but this is currently not accounted for. Compare:

Gherkin.parse("""
Feature: feature
  Scenario: scenario
    Description
    Given step
""")
#=>
%Gherkin.Elements.Feature{
  background_steps: [],
  description: "",
  file: nil,
  line: 1,
  name: "feature",
  rules: [],
  scenarios: [
    %Gherkin.Elements.Scenario{
      description: "Description\n",
      line: 2,
      name: "scenario",
      steps: [
        %Gherkin.Elements.Step{
          doc_string: "",
          keyword: "Given",
          line: 4,
          table_data: [],
          text: "step"
        }
      ],
      tags: []
    }
  ],
  tags: []
}

to:

Gherkin.parse("""
Feature: feature
  Scenario: scenario
    Description
    When step
    Then step
""")
#=>
%Gherkin.Elements.Feature{
  background_steps: [],
  description: "",
  file: nil,
  line: 1,
  name: "feature",
  rules: [],
  scenarios: [
    %Gherkin.Elements.Scenario{
      description: "Description\nWhen step\n",
      line: 2,
      name: "scenario",
      steps: [
        %Gherkin.Elements.Step{
          doc_string: "",
          keyword: "Then",
          line: 5,
          table_data: [],
          text: "step"
        }
      ],
      tags: []
    }
  ],
  tags: []
}

This patch fixes this issue.

pzingg commented 1 year ago

It took me a while to figure out why the main branch was failing on just this situation, where I had a background, followed by a scenario whose first statement was a When. I arrived at the same solution. Please merge this!

Here was my example. The step When signing a GET request on "myhost.example" to "/path/to/resource" was being dropped.

Feature: Http Signatures

    Background: Private and Public Key
        Given the private key
            """
            -----BEGIN PRIVATE KEY-----
            MIIEvgIBADANBgkqhkiG9w0BAQEFAASCBKgwggSkAgEAAoIBAQDXm+EV0rbvZtsY
            PMu3Kmjg2fyY0VjdhIuesA5fjNkqQ2ZaaDKmAM/ypeM2JWwF/x/5iTe0cOznwsx/
            xANI/T0D7OuVYEc3WssQufQkGCpP3GPxZKhsMiM6MUEDLgUpSSjuT8ixjBOX9WfH
            W3KSE9HVTNto2o3XJBLLTMZshx79eGqXObq763DK4dUK1sY9w+Ht+ivmjRq8p0zC
            EBelYys2hz0vYv/2HdSCh4+AC8ITodM9cQE96xQGVNQtxHExchkns/p4yRvakZQI
            OVUXgQ29zFkAbw9vsdCn2fNXArg5dlyUqwfVgrQbygEZPGeugG2rtwlusm+o0w04
            7liDdy7pAgMBAAECggEAS9TtY4mLAcSBRpMLa06lOIAy0WTABpk5qgRt6blWIAE4
            nI+NUMl0WflyYnbi+XDzxAY462PUTuc6ma1NIny+2wSXDyCfq55pUWa1sYQ2TYRM
            OniWrAcuUKdGIGItOooatUamZZvIwGd1qq5FK4+A+65edRB5VrO/UHWeTElx4t+z
            0SUyfbpeCHvuEEK3OyY464V4ZW/D/zAAONaCF3n+FY9uBS0+9LEme0xvaBq24oF9
            zmbFJ5DjFSRpNVouGRmO03Uh9+uNrTYkcylDNgQaFCt7WcQO/3lCs+dqNf2psIht
            PCbLRqfXQSjQ6gQbnYPGmIFesVVwJpSyMXpFMcgISQKBgQDfBsmCBN0pFib4vaMf
            1KSLVxg7DFFiELf1D0ok4rSa7H5eo5flNND9xu+ESWQpcq9J0PVGZqfX7pen9EJV
            HmNPMYsAejTqHM/1bg3TdW3A4Xn0I2ShlZlNK0AzLYZRIBF0ZiCWunZBt8xjSLTm
            BGHZxvho1TZIffuudcxP5olY3wKBgQD3fFjQQt/bw/2JYUBFvjPiVOJ5j5MzaGLx
            gtpDMUFTuG/DPXUvTWp6xIkQj4xO5D9SfkTqBEPOGH/zc7CVoTMsh5vHDJ9fKE/l
            FynQaCzBOrU+zKeHvBscS91orF0nNrD3JYtb4GUe1oSZ/BlbwHjZMZQOAssaLDs1
            Bdq5SpLJNwKBgDXiU+k/95cnrP7IApN8Ms0fm9EYZslEtM1WhllnFK+hl96Rs+9C
            1YOa/t99Q9/nv4YcIEaEIuU+1hFUKHqcPu4xUB4raIFvuKbZkimW44+IaoibzIJl
            vIYyfu5ef2c2UkFHM3R3VH8IQy9xr5MrV+Df+8CIUvcsyRQbjeN4FZMNAoGBAOKB
            NxPcsN+FYC11CYsLSpcyE1koc5PQTQY3OaXXla+XFQr+25qgYvzblYrHpqWptt68
            XDxGDPy6ZZieYJaBw8FUl9k0j0RbM8w7R/TK83MiVTGVwxqyqalbMdgUMOmr34lD
            HmnHVSVFNnVsSpUz8ibufk/YdKSOqN2dbxK40uE/AoGBALGrR5FU2u1vcsUj1IvT
            epfA5+8kiQ5MdUWU+E7ORM+SRlnicsdS/IPT4KREBck/+GvXY/XZdMYT+T3a4o3P
            R4O3/2egqTchuPkwfSAy7L8jt2GNzFvxmcrvpKYAZzjh1KCrZ15OYr7ZhlEWs6MQ
            RbdDq36O45uplOe0heeOsPhj
            -----END PRIVATE KEY-----
            """
        And the public key
            """
            -----BEGIN PUBLIC KEY-----
            MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEA15vhFdK272bbGDzLtypo
            4Nn8mNFY3YSLnrAOX4zZKkNmWmgypgDP8qXjNiVsBf8f+Yk3tHDs58LMf8QDSP09
            A+zrlWBHN1rLELn0JBgqT9xj8WSobDIjOjFBAy4FKUko7k/IsYwTl/Vnx1tykhPR
            1UzbaNqN1yQSy0zGbIce/Xhqlzm6u+twyuHVCtbGPcPh7for5o0avKdMwhAXpWMr
            Noc9L2L/9h3UgoePgAvCE6HTPXEBPesUBlTULcRxMXIZJ7P6eMkb2pGUCDlVF4EN
            vcxZAG8Pb7HQp9nzVwK4OXZclKsH1YK0G8oBGTxnroBtq7cJbrJvqNMNOO5Yg3cu
            6QIDAQAB
            -----END PUBLIC KEY-----
            """

    Scenario: Signing GET request
        When signing a GET request on "myhost.example" to "/path/to/resource"
        And the date is "Wed, 15 Mar 2023 17:28:15 GMT"
        And the key_id is "https://remote.example/actor#key"
        Then the message to sign is
            """
            (request-target): get /path/to/resource
            host: myhost.example
            date: Wed, 15 Mar 2023 17:28:15 GMT
            """
        And the signature string is
            """
            keyId="https://remote.example/actor#key",algorithm="rsa-sha256",headers="(request-target) host date",signature="hUW2jMUkhiKTmAoqgq7CDz0l4nYiulbVNZflKu0Rxs34FyBs0zkBKLZLUnR35ptOvsZA7hyFOZbmK9VTw2VnoCvUYDPUb5VyO3MRpLv0pfXNExQEWuBMEcdvXTo30A0WIDSL95u7a6sQREjKKHD5+edW85WhhkqhPMtGpHe95cMItIBv6K5gACrsOYf8TyhtYqBxz8Et0iwoHnMzMCAHN4C+0nsGjqIfxlSqUSMrptjjov3EBEnVii9SEaWCH8AUE9kfh3FeZkT+v9eIDZdhj4+opnJlb9q2+7m/7YH0lxaXmqro0fhRFTd832wY/81LULix/pWTOmuJthpUF9w6jw=="
            """
jdewar commented 10 months ago

Also ran into this; had to add a superfluous Given line in the Scenario