Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/sorting/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何在cucumber功能文件中表示嵌套的json对象_Json_Cucumber_Cucumber Jvm - Fatal编程技术网

如何在cucumber功能文件中表示嵌套的json对象

如何在cucumber功能文件中表示嵌套的json对象,json,cucumber,cucumber-jvm,Json,Cucumber,Cucumber Jvm,我需要在功能文件中表示JSON对象。我可以使用一个json文件来获取代码。但这意味着我无法从要素文件传递值 Scenario: Test Given a condition is met Then the following json response is sent | json | | {"dddd":"dddd","ggggg":"ggggg"}| 以上内容适用于普通json。但是,如果存在嵌套对象等,那么在上面这样的一行中编写json将使该功能非常难以读取和修复 请让我知道。您

我需要在功能文件中表示JSON对象。我可以使用一个json文件来获取代码。但这意味着我无法从要素文件传递值

Scenario: Test

Given a condition is met

Then the following json response is sent
 | json |
 | {"dddd":"dddd","ggggg":"ggggg"}|
以上内容适用于普通json。但是,如果存在嵌套对象等,那么在上面这样的一行中编写json将使该功能非常难以读取和修复


请让我知道。

您可以使用字符串来实现这一点,它使json更加易读

Then the following json response is sent
  """
   {
      'dddd': 'dddd',
      'ggggg': 'ggggg',
      'somethingelse': {
        'thing': 'thingvalue',
        'thing2': 'thing2value'
      }
    }
  """
在代码中,您可以直接使用它:

Then(/^the following json response is sent$/) do |message|
  expect(rest_stub.body).to eq(message)
end

或者类似的东西。

很好,谢谢!看起来这将解决我的问题。但是如果我想与其他参数一起验证json,例如:然后将以下响应发送给| user | json | user1 |{“user1”:{“dddddd”:“dddddd”:“ggdd”,“ggggg”:“ggggggg”}}}| user2{“user2”:{“ddddddddd”:“ddddddd”,“ggggggg”:“ggggggg”}}这是另一个问题。这些问题很简单,可以通过搜索轻松找到。当我搜索google“Cumber json”时,我在顶部看到了3个很好的答案这是什么
expect(rest\u stub.body)。到eq(message)
和rest\u stub.body将是对调用的预期响应