简体   繁体   English

如何在Rails 5中使用Rspec测试Wash_out控制器

[英]How to test wash_out controller with Rspec in Rails 5

I am using wash_out to create a soap webservice, this is my controller: 我正在使用wash_out创建soap Webservice,这是我的控制器:

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

following http://blog.johnsonch.com/2013/04/18/rails-3-soap-and-testing-oh-my/ I wrote this test: 以下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

but rspec always throws this error: 但是rspec总是抛出此错误:

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

I am using rails 5.1.5, wash_out 0.12, httpi 2.4.2 and savon 2.11.2 我正在使用Rails 5.1.5,wash_out 0.12,httpi 2.4.2和savon 2.11.2

how can I fix this? 我怎样才能解决这个问题?

What worked for me was adding "render_views" to the controller spec. 对我有用的是在控制器规范中添加“ render_views”。 For example 例如

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM