ENV['RACK_ENV'] = 'test'
require File.join(File.join(File.expand_path(File.dirname(__FILE__))), '..', 'lib', 'sinatra', 'soap')
require 'rspec'
require 'rack/test'
class SoapApp < Sinatra::Base
register Sinatra::Soap
soap :test do |params|
params
end
end
module RSpecMixin
include Rack::Test::Methods
end
RSpec.configure { |c| c.include RSpecMixin }
describe 'A default soap sinatra application' do
def app
SoapApp
end
it "should parse soap request and send response" do
headers = {"HTTP_SOAPACTION" => 'test'}
message = 'onebarwat'
post '/action', message, headers
response =<<-XML
one
bar
wat
XML
last_response.body.should == response
end
it "should raise soap fault on unknown action" do
headers = {"HTTP_SOAPACTION" => 'test2'}
message = 'onebarwat'
post '/action', message, headers
response =<<-XML
Client
Undefined Soap Action
XML
last_response.body.should == response
end
it "should have endpoint for soap actions" do
endpoint = app.routes["POST"].select {|k| k[0].to_s.match('action')}.count
endpoint.should eq 1
end
it "should have route for wsdl" do
wsdl = app.routes["GET"].select {|k| k[0].to_s.match('wsdl')}.count
wsdl.should == 1
end
end