2

これは私のコントローラーです:

class SignerController < ApplicationController

  soap_service

  soap_action 'xmlSign', args: {
    xml:         :string,
    certificate: :string
  },
  return: {
    signed_xml: :string,
    error:      :string
  },
  to: :xml_sign

  def xml_sign
    render soap: {
      signed_xml: "TODO"
    }
  rescue
    render soap: {
      error: $!.message
    }
  end

end

http://blog.johnsonch.com/2013/04/18/rails-3-soap-and-testing-oh-my/に従って、このテストを作成しました。

require 'rails_helper'
require 'savon'

RSpec.describe SignerController, type: :controller do

  HTTPI.adapter = :rack
  HTTPI::Adapter::Rack.mount 'app', Signer::Application

  it 'signs an xml' do
    application_base = "http://app"
    client = Savon::Client.new({:wsdl => application_base + signer_wsdl_path })
    result = client.call(:xmlSign, xml: 'xml', certificate: 'cert')
    result.body[:xml_sign][:value].should_not be_nil
  end

end

ただし、rspec は常に次のエラーをスローします。

NoMethodError:
  undefined method `element_children' for nil:NilClass
# ./spec/controllers/signer_controller_spec.rb:12:in `block (2 levels) in <top (required)>'

Rails 5.1.5、wash_out 0.12、httpi 2.4.2、savon 2.11.2 を使用しています。

どうすればこれを修正できますか?

4

1 に答える 1

0

私にとってうまくいったのは、コントローラーの仕様に「render_views」を追加することでした。例えば

RSpec.describe SoapController, type: controller do
  render_views # added render_views

  HTTPI.adapter = :rack
  HTTPI::Adapter::Rack.mount 'application', PhoneDialogue::Application

  it 'signs an xml' do
    application_base = "http://app"
    client = Savon::Client.new({:wsdl => application_base + soap_wsdl_path })
    result = client.call(:xmlSign, xml: 'xml', certificate: 'cert')
    result.body[:xml_sign][:value].should_not be_nil
  end
end
于 2018-07-11T19:37:46.950 に答える