首页 > 解决方案 > 是否可以在一个字段中接收从 Faker 生成的另一个字段的值?

问题描述

@@base_url  = 'https://api-de-tarefas.herokuapp.com/users'
    @@body = 
    {
    "user": {
    "email": Faker::Internet.email,
    "password": Faker::Number.number(6),
    "password_confirmation": 
     }    
}.to_json

我正在尝试将 gem faker 在密码字段中生成的值传递给密码验证字段。

标签: rubyhttparty

解决方案


只需预先确定值:

@@base_url = 'https://api-de-tarefas.herokuapp.com/users'
password = Faker::Number.number(6)
@@body = {
  "user": {
    "email": Faker::Internet.email,
    "password": password,
    "password_confirmation": password
  }    
}.to_json

顺便说一句,您真的需要类变量(以 开头@@)吗?我想不出类变量是一种好方法的许多情况。


推荐阅读