简体   繁体   English

如何使用Rspec测试wash_out控制器

[英]How to test wash_out controller with Rspec

I have implemented a Rails controller with the wash_out gem. 我已经使用wash_out gem实现了一个Rails控制器。

My controller look like this: 我的控制器看起来像这样:

class TestController < ApplicationController
  include WashOut::SOAP

  soap_action "int_to_string",
              :args   => :integer,
              :return => :string
  def int_to_string
    render :soap => params[:value].to_s
  end
end

routes.rb: routes.rb中:

MyApp::Application.routes.draw do
  wash_out :test
end

I am not sure how I can test this controller with Rspec. 我不知道如何用Rspec测试这个控制器。

Any ideas? 有任何想法吗?

In this link you can find a good aproach 在这个链接中你可以找到一个很好的方法

http://blog.johnsonch.com/2013/04/18/rails-3-soap-and-testing-oh-my/ http://blog.johnsonch.com/2013/04/18/rails-3-soap-and-testing-oh-my/

The aproach is: 方法是:

  • Create a client with savonrb gem 使用savonrb gem创建一个客户端
  • compare the result in your test 比较你的测试结果

you can spec the default wsdl route with something like: 您可以通过以下方式指定默认的wsdl路由:

 require "spec_helper"

describe MywsdlController do
  describe "routing" do

    it "mywsdl/wsdl route to mywsdl#_generate_wsdl" do 
      get("/mywsdl/wsdl").should route_to("mywsdl#_generate_wsdl")
    end

  end
end

then Id suggest to have a soap dir within spec one and a spec file per available service so you can init soap client before:each with testing params, that might give you a spec scenario. 然后我建议在规范1中有一个soap目录,每个可用服务都有一个spec文件,这样你就可以在之前启动soap客户端:每个都有测试参数,这可能会给你一个规范方案。

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

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