How to Test Web Service on Ruby on Rails

Asked

Viewed 556 times

0

I’m having the following doubt, I’m making a server with my application , I’m using the gem wash-out, I understood how it works and I was able to put my web-service to run, but I would like to know how to test my server, I’ve searched several tutorials and none helped me.

For example:

 soap_action "novo_cadastro",
      :args   => {:titulo => :string, :descricao => :string },
      :return => :xml

  def novo_cadastro
    cad = Cadastro.new(titulo: params[:titulo], descricao: params[:descricao])
    if cad.save
      render xml: cad
    else
      render :soap => nil
    end
  end

How to test this?

Grateful.

  • what kind of test you are in doubt of how to do unit test or integration test?

  • I have my controller working, I created a client and it only connects, makes requests and gets a response, but this was just a test, on my real server, I need to use the TDD technique to make sure that it is working, I can’t test the actions of the controller, I don’t really know how, the client is easy to test, but and the server?

  • start by running unit tests on your server, the secret to a good test is to cover as much of the code as possible and test your program’s boundary cases well, start by breaking your program into small tests in a simple way. Test has no miracle, have q stop studying and do. I suggest if you are in a hurry the codeschool test courses.

  • @Felipebergamo I know how to do tests, the model is with 100% test coverage, my question is how to test this function above, which is only accessed by a client.

  • like the wash-out is based on Gem Savon, take a look at Gem: savon_spec

1 answer

1


An example of the WashOut:

require 'test_helper'
require 'savon'

class NovoCadastroTeste < ActiveSupport::TestCase

    test "cadastro com sucesso" do

        cliente = Savon::Client.new(wsdl: "http://localhost:3000/novo_cadastro/wsdl")

        cliente.operations # Retorna operações possíveis.

        resultado = client.call(:novo_cadastro, message: { :titulo => "titulo", :descricao => "descricao" })

        # Verifique se a resposta está correta.

        resultado = resultado.to_hash

        assert resultado[:sucesso]
    end
end

You should import the Gem from Savon in your Gemfile, like this:

gem 'savon'

Browser other questions tagged

You are not signed in. Login or sign up in order to post.