Skip to content
This repository
Tim Jarratt tjarratt
file 46 lines (38 sloc) 1.793 kb
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46
 require "spec_helper"

describe "Temperature example" do

  it "converts 30 degrees celsius to 86 degrees fahrenheit" do
    client = Savon.client do
      # The WSDL document provided by the service.
      wsdl "http://www.webservicex.net/ConvertTemperature.asmx?WSDL"

      # Needed because (up until now), Savon doesn't match XS types to Hash keys,
      # but defaults to convert Hash message Symbols (like :from_unit) to lowerCamelCase.
      # The service expects these to be CamelCase instead. Look at Savon's log output
      # and compare it with an example request generated by soapUI.
      convert_request_keys_to :camelcase

      # Lower timeouts so these specs don't take forever when the service is not available.
      open_timeout 10
      read_timeout 10

      # Disable logging for cleaner spec output.
      log false
    end

    response = call_and_fail_gracefully(client, :convert_temp) do
      # For the corrent values to pass for :from_unit and :to_unit, I searched the WSDL for
      # the "FromUnit" type which is a "TemperatureUnit" enumeration that looks like this:
      #
      # <s:simpleType name="TemperatureUnit">
      # <s:restriction base="s:string">
      # <s:enumeration value="degreeCelsius"/>
      # <s:enumeration value="degreeFahrenheit"/>
      # <s:enumeration value="degreeRankine"/>
      # <s:enumeration value="degreeReaumur"/>
      # <s:enumeration value="kelvin"/>
      # </s:restriction>
      # </s:simpleType>
      #
      # Support for XS schema types needs to be improved.
      message(:temperature => 30, :from_unit => "degreeCelsius", :to_unit => "degreeFahrenheit")
    end

    fahrenheit = response.body[:convert_temp_response][:convert_temp_result]
    expect(fahrenheit).to eq("86")
  end

end
Something went wrong with that request. Please try again.