Search code examples
rubycucumbercapybarahttparty

How to add the value of another field to an HTTParty field using Ruby


Is possible to use this: Add password-generated faker content to "passoword_confirmation". If so, what is the syntax, try various ways and failed !. Thank's

"email": Faker::Internet.email, "password": Faker::number(6), "password_confirmation":

@@base_url  = 'https://api-de-tarefas.herokuapp.com/users'
    @@body = 
    {
    "user": {
    "email": Faker::Internet.email,
    "password": Faker::number(6),
    "password_confirmation":      here I want to receive the password generated from Faker.

     }    
}.to_json

Solution

  • You could persist the password by saving it to a variable before entering the @@body block.

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