Search code examples
rubyhttparty

Is it possible to receive in one field the value of another field generated from a 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

I'm trying to pass in the body the value generated by gem faker in the password field to the password_verification field.


Solution

  • Just determine the value upfront:

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

    Btw do you really need class variables (starting with @@)? I cannot think of many situations in which a class variable is a good approach.