[我使用类httparty时parsed_response有问题

问题描述 投票:0回答:1

<< img src =“ https://image.soinside.com/eyJ1cmwiOiAiaHR0cHM6Ly9pLnN0YWNrLmltZ3VyLmNvbS9GODRDbS5qcGcifQ==” alt =“在此处输入图像描述”>我对班级httparty有问题

 class CRUD

       include HTTParty

       def self.create   

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

    @headers = {
                 "Accept": 'application/vnd.tasksmanager.v2',
                          'Content-Type': 'application/json'
    }   

      @request = HTTParty.post(@base_url, body: @body, headers: @headers)
          end 
      end 

我的step_definitions

When("é enviada uma requisição para a criação do usuário") do
   CRUD.create
    puts "Requisição com exito: #{CRUD.create.message} para código #{CRUD.create.code}" 
 end

then("são retornadas as informações da inclusão") do
   puts CRUD.create.body
   puts CRUD(@request.parsed_response['data']['attributes']['email'])
 end

我对类httparty有问题,类CRUD包含HTTParty def self.create @base_url ='https://api-de-tarefas.herokuapp.com/users'@body = {... ...>]

ruby cucumber bdd
1个回答
0
投票
[OK, I made the adjustments and the test ran, but I have a problem now !. Why is the query email (get)is different from the inclusion email (post)?

see my class

require 'HTTParty'
require 'httparty/request'
require 'httparty/response/headers'

#require_relative '..features/pages/hooks/hook.rb'

class CRUD

   include HTTParty

   def create  

  @base_url  = 'https://api-de-tarefas.herokuapp.com/users'
    @body = 
    {
    "user": {
    "email": Faker::Internet.email,
    "password":  :@password,
    "password_confirmation": :@password

     }    
}.to_json

@headers = {
             "Accept": 'application/vnd.tasksmanager.v2',
                      'Content-Type': 'application/json'
}   

  @request = CRUD.post(@base_url, body: @body, headers: @headers)
 end

  def retrieve
    @response  = CRUD.get('https://api-de-tarefas.herokuapp.com/contacts') 
 end 
end


See my step_definitions

Dado("que eu tenha um payload padrão") do
  @manter_user = CRUD.new
 end

Quando("é enviada uma requisição para a criação do usuário") do
   @manter_user.create
    puts "Requisição com exito: #{@manter_user.create.message} para código #{@manter_user.create.code}" 
 end

Então("são retornadas as informações da inclusão") do
   puts @manter_user.create.body
   puts @manter_user.create.parsed_response\['data'\]\['attributes'\]\['email'\] 
 end

  Dado("que eu tenha o usuário cadastrado") do 
    @manter_user = CRUD.new                                       
    @manter_user.create
    puts @manter_user.create.body

  end                                                                                 

  Quando("é enviada uma requisição de consulta") do                                   
    @manter_user.retrieve
    puts "Consulta processada com sucesso #{@manter_user.retrieve.code}"
  end                                                                                

  Então("a API me retorna a informação do usuário") do                                
    puts @manter_user.create.parsed_response\['data'\]\['attributes'\]\['email'\] 
  end][1]  

enter code here
© www.soinside.com 2019 - 2024. All rights reserved.