[英]Access Cucumber feature variable in a step defintion with json_spec
I downloaded the json_spec
gem and I'm trying to access a variable that was stored in my Cucumber feature file. 我下载了
json_spec
gem,并尝试访问存储在Cucumber功能文件中的变量。 From the json_spec readme it shows that you can store a variable as follows; 从json_spec 自述文件中可以看出,您可以按以下方式存储变量; I keep the JSON response as "USER_1".
我将JSON响应保留为“ USER_1”。 Is there any way to access this "USER_1" variable for use in my step defintions?
有什么方法可以访问此“ USER_1”变量以在我的步骤定义中使用?
Yes there is. 就在这里。
JsonSpec.memory[:USER_1]
Will allow you to access the specific stored value. 将允许您访问特定的存储值。 However this is not really documented as supported behaviour and as such constitutes an implementation detail that is subject to change.
但是,这并未真正记录为受支持的行为,因此构成了可能更改的实现细节。 So i wouldn't rely on it.
所以我不会依靠它。
And additionally you should always be able to access the actual JSON as last_json
, which is the method you need to provide for json_spec to work. 另外,您应该始终能够以
last_json
身份访问实际的JSON,这是为使json_spec工作而需要提供的方法。 If i needed to do something with the response (eg to issue additional requests) i would parse last_json
myself. 如果我需要对响应做一些事情(例如发出其他请求),我将自己解析
last_json
。
The code for the JsonSpec memory can be found here . JsonSpec存储器的代码可以在这里找到。 And the usage of it during the step-definition can be seen here .
可以在这里看到它在步进定义中的用法。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.