简体   繁体   中英

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. From the json_spec readme it shows that you can store a variable as follows; I keep the JSON response as "USER_1". Is there any way to access this "USER_1" variable for use in my step defintions?

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. If i needed to do something with the response (eg to issue additional requests) i would parse last_json myself.

The code for the JsonSpec memory can be found here . And the usage of it during the step-definition can be seen here .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM