Каратэ: есть ли способ применить функции против примеров: переменные? - PullRequest
1 голос
/ 04 апреля 2019

У меня есть тест каратэ, который проходит:

Feature:  Armstrong numbers

  Background:
    * url baseUrl
    * configure lowerCaseResponseHeaders = true

  Scenario Outline: Find Armstrong numbers in the range from <start> to <end> are <result>
    Given path '/armstrongs'
    And param start = <start>
    And param end = <end>
    When method get
    Then status 200
    And match header content-type contains 'application/json'
    And match header content-type contains 'charset=utf-8'
    And match response == {numbers:<result>, start:<start>, end:<end>, count: <count>, type:Armstrong}
    Examples:
      | start | end    | result                | count
      | 1     | 10     | [1,2,3,4,5,6,7,8,9]   | 9
      | 100   | 1000   | [153, 370, 371, 407]  | 4
      | 90000 | 100000 | [92727, 93084]        | 2

Однако я хотел бы, чтобы переменная count не была указана в разделе «Примеры:

Feature:  Armstrong numbers

  Background:
    * url baseUrl
    * configure lowerCaseResponseHeaders = true

  Scenario Outline: Find Armstrong numbers in the range from <start> to <end> are <result>
    Given path '/armstrongs'
    And param start = <start>
    And param end = <end>
    When method get
    Then status 200
    And match header content-type contains 'application/json'
    And match header content-type contains 'charset=utf-8'
    And match response == {numbers:<result>, start:<start>, end:<end>, count: <result>.length, type:Armstrong}
    Examples:
      | start | end    | result
      | 1     | 10     | [1,2,3,4,5,6,7,8,9]
      | 100   | 1000   | [153, 370, 371, 407]
      | 90000 | 100000 | [92727, 93084]

Когда я пытаюсь это сделать, я получаю сообщение об ошибке:

Armstrong.feature:15 - net.minidev.json.parser.ParseException: Unexpected token . at position 72.

и тест не пройден.

Есть ли способ применить функции к примерам: переменным, таким как .length, чтобы получить ожидаемые результаты и пройти тест?

1 Ответ

0 голосов
/ 04 апреля 2019

Сделайте это изменение:

And def result = <result>
And match response == {numbers: '#(result)', start: <start>, end: <end>, count: '#(result.length)', type: 'Armstrong' }
...