【问题标题】:Is it possible to receive in one field the value of another field generated from a Faker?是否可以在一个字段中接收从 Faker 生成的另一个字段的值?
【发布时间】:2019-10-17 18:00:12
【问题描述】:
@@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 在密码字段中生成的值传递给密码验证字段。

【问题讨论】:

  • 这会大量使用类变量,这通常是一个不好的迹象。您是否考虑过改用常量?

标签: ruby httparty


【解决方案1】:

只需预先确定值:

@@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

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

【讨论】:

  • spickermann 对不起,我的朋友,我在变量方面犯了一个小错误!。非常感谢您的帮助!
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2015-07-24
  • 1970-01-01
  • 2020-01-19
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多