diff --git a/lib/wasabi.rb b/lib/wasabi.rb index bfdffed..6d458b3 100644 --- a/lib/wasabi.rb +++ b/lib/wasabi.rb @@ -1,6 +1,7 @@ require 'wasabi/version' require 'wasabi/document' require 'wasabi/resolver' +require 'wasabi/importer' class Wasabi @@ -12,38 +13,32 @@ class Wasabi def initialize(wsdl, request = nil) resolver = Resolver.new(request) + importer = Importer.new(resolver, self) - xml = resolver.resolve(wsdl) - document = Nokogiri.XML(xml) - - @parser = Parser.new(document) + @documents, @schemas = importer.import(wsdl) end - attr_reader :parser + attr_reader :documents, :schemas def service_name - @parser.service_name + @documents.service_name end - # TODO: move this to an operation. + # TODO: move this up to the operation. def endpoint - @parser.endpoint + @documents.endpoint end def target_namespace - @parser.target_namespace + @documents.target_namespace end def namespaces - @parser.namespaces - end - - def schemas - @parser.schemas + @documents.namespaces end def operation(operation_name) - @parser.operations[operation_name] + @documents.operations[operation_name] end end diff --git a/lib/wasabi/document.rb b/lib/wasabi/document.rb index ff05e08..ce6cef1 100644 --- a/lib/wasabi/document.rb +++ b/lib/wasabi/document.rb @@ -1,115 +1,70 @@ -require "nokogiri" -require "wasabi/resolver" -require "wasabi/parser" +require 'wasabi/schema' +require 'wasabi/legacy_operation_parser' class Wasabi - - # = Wasabi::Document - # - # Represents a WSDL document. class Document - # Accepts a WSDL +document+ to parse. - def initialize(document = nil) - self.document = document + def initialize(document, wsdl) + @document = document + @wsdl = wsdl end - attr_accessor :document, :request, :xml - - alias_method :document?, :document - - # Returns the SOAP endpoint. - def endpoint - @endpoint ||= parser.endpoint + def service_name + @document.root['name'] end - # Sets the SOAP endpoint. - attr_writer :endpoint - - # Returns the target namespace. def target_namespace - @target_namespace ||= parser.target_namespace + @document.root['targetNamespace'] end - # Sets the target namespace. - attr_writer :target_namespace - - # Returns a list of available SOAP actions. - def soap_actions - @soap_actions ||= parser.operations.keys - end - - # Returns a map of SOAP operations. - def operations - @operations ||= parser.operations + def namespaces + @namespaces ||= collect_namespaces(@document, *schema_nodes) end - # Returns the service name. - def service_name - @service_name ||= parser.service_name + def schemas + @schemas ||= schema_nodes.map { |node| Schema.new(node, @wsdl) } end - attr_writer :service_name + def imports + imports = [] - def namespaces - parser.namespaces - end - - # XXX: legacy interface. change savon to use the new types interface. - def type_namespaces - @type_namespaces ||= begin - namespaces = [] - parser.schemas.types.each do |name, type| - namespaces << [[name], type.namespace] - type.children.each { |child| namespaces << [[name, child[:name]], type.namespace] } - end if document - namespaces + @document.xpath('/wsdl:definitions/wsdl:import', 'wsdl' => Wasabi::WSDL).each do |node| + location = node['location'] + imports << location if location end - end - # XXX: legacy interface. change savon to use the new types interface. - def type_definitions - @type_definitions ||= begin - result = [] - parser.schemas.types.each do |name, type| - type.children.each do |child| - # how can we properly handle anyType elements here? - # see Type#parse_element - next unless child[:type] - - tag, nsid = child[:type].split(":").reverse - result << [[name, child[:name]], tag] if user_defined(nsid) - end - end if document - result - end + imports end - # Returns whether the given +namespace+ was defined manually. - def user_defined(namespace) - uri = parser.namespaces[namespace] - !(uri =~ %r{^http://schemas.xmlsoap.org} || uri =~ %r{^http://www.w3.org}) + def operations + @operations ||= LegacyOperationParser.new(@document).operations end - # Returns the raw WSDL document. - # Can be used as a hook to extend the library. - def xml - @xml ||= Resolver.new(request).resolve(document) + def service_node + @document.at_xpath('/wsdl:definitions/wsdl:service', 'wsdl' => Wasabi::WSDL) end - def parser - @parser ||= guard_parse && parse + private + + def schema_nodes + @schema_nodes ||= begin + types = @document.at_xpath('/wsdl:definitions/wsdl:types', 'wsdl' => Wasabi::WSDL) + types ? types.element_children : [] + end end - private + def collect_namespaces(*nodes) + namespaces = {} - def guard_parse - return true if document - raise ArgumentError, "Wasabi needs a WSDL document" - end + nodes.each do |node| + node.namespaces.each do |k, v| + key = k.sub(/^xmlns:/, '') + namespaces[key] = v + end + end - def parse - Parser.new Nokogiri::XML(xml) + namespaces.delete('xmlns') + namespaces end end diff --git a/lib/wasabi/document_collection.rb b/lib/wasabi/document_collection.rb new file mode 100644 index 0000000..d5a56fd --- /dev/null +++ b/lib/wasabi/document_collection.rb @@ -0,0 +1,57 @@ +require 'uri' + +class Wasabi + class DocumentCollection + include Enumerable + + def initialize + @documents = [] + end + + def <<(document) + @documents << document + end + + def each(&block) + @documents.each(&block) + end + + def service_name + @service_name ||= first.service_name + end + + def target_namespace + @target_namespace ||= first.target_namespace + end + + def target_namespace + @target_namespace ||= first.target_namespace + end + + def namespaces + @namespaces ||= inject({}) { |memo, document| memo.merge(document.namespaces) } + end + + def operations + @operations ||= inject({}) { |memo, document| memo.merge(document.operations) } + end + + # TODO: this works for now, but it should be moved into the Operation, + # because there can be different endpoints for different operations. + def endpoint + return @endpoint if @endpoint + + if service = first.service_node + endpoint = service.at_xpath(".//soap11:address/@location", 'soap11' => Wasabi::SOAP_1_1) + endpoint ||= service.at_xpath(service_node, ".//soap12:address/@location", 'soap12' => Wasabi::SOAP_1_2) + end + + begin + @endpoint = URI(URI.escape(endpoint.to_s)) if endpoint + rescue URI::InvalidURIError + @endpoint = nil + end + end + + end +end diff --git a/lib/wasabi/importer.rb b/lib/wasabi/importer.rb new file mode 100644 index 0000000..9201b1d --- /dev/null +++ b/lib/wasabi/importer.rb @@ -0,0 +1,40 @@ +require 'nokogiri' +require 'wasabi/document' +require 'wasabi/document_collection' +require 'wasabi/schema_collection' + +class Wasabi + class Importer + + def initialize(resolver, wsdl) + @resolver = resolver + @wsdl = wsdl + end + + def import(location) + documents = DocumentCollection.new + schemas = SchemaCollection.new + + import! [location] do |document| + documents << document + schemas.push(document.schemas) + end + + [documents, schemas] + end + + private + + def import!(locations, &block) + locations.each do |location| + xml = @resolver.resolve(location) + document = Document.new Nokogiri.XML(xml), @wsdl + + block.call(document) + + import! document.imports, &block + end + end + + end +end diff --git a/lib/wasabi/operations.rb b/lib/wasabi/legacy_operation_parser.rb similarity index 89% rename from lib/wasabi/operations.rb rename to lib/wasabi/legacy_operation_parser.rb index 6b27daf..c5af52a 100644 --- a/lib/wasabi/operations.rb +++ b/lib/wasabi/legacy_operation_parser.rb @@ -2,10 +2,10 @@ require 'wasabi/operation' class Wasabi - class Operations + class LegacyOperationParser - def initialize(parser) - @parser = parser + def initialize(document) + @document = document @operations = {} parse @@ -21,12 +21,12 @@ def parse end def parse_messages - messages = @parser.document.root.element_children.select { |node| node.name == 'message' } + messages = @document.root.element_children.select { |node| node.name == 'message' } @messages = Hash[messages.map { |node| [node['name'], node] }] end def parse_port_types - port_types = @parser.document.root.element_children.select { |node| node.name == 'portType' } + port_types = @document.root.element_children.select { |node| node.name == 'portType' } @port_types = Hash[port_types.map { |node| [node['name'], node] }] end @@ -40,7 +40,7 @@ def parse_port_type_operations end def parse_operations - operations = @parser.document.xpath("wsdl:definitions/wsdl:binding/wsdl:operation", 'wsdl' => Wasabi::WSDL) + operations = @document.xpath("wsdl:definitions/wsdl:binding/wsdl:operation", 'wsdl' => Wasabi::WSDL) operations.each do |operation| name = operation.attribute("name").to_s diff --git a/lib/wasabi/parser.rb b/lib/wasabi/parser.rb deleted file mode 100644 index e1dbafc..0000000 --- a/lib/wasabi/parser.rb +++ /dev/null @@ -1,83 +0,0 @@ -require 'uri' -require "wasabi/schema_collection" -require 'wasabi/schema' -require "wasabi/operations" - -class Wasabi - class Parser - - def initialize(document) - @document = document - end - - attr_reader :document - - def service_name - @document.root['name'] - end - - def target_namespace - @document.root['targetNamespace'] - end - - def namespaces - @namespaces ||= collect_namespaces(@document, *schema_nodes) - end - - def schemas - @schemas ||= begin - schemas = schema_nodes.map { |node| Schema.new(node, self) } - SchemaCollection.new(schemas) - end - end - - def operations - @operations ||= Operations.new(self).operations - end - - # TODO: this works for now, but it should be moved into the Operation, - # because there can be different endpoints for different operations. - def endpoint - return @endpoint if @endpoint - - if service = service_node - endpoint = service.at_xpath(".//soap11:address/@location", 'soap11' => Wasabi::SOAP_1_1) - endpoint ||= service.at_xpath(service_node, ".//soap12:address/@location", 'soap12' => Wasabi::SOAP_1_2) - end - - begin - @endpoint = URI(URI.escape(endpoint.to_s)) if endpoint - rescue URI::InvalidURIError - @endpoint = nil - end - end - - private - - def collect_namespaces(*nodes) - namespaces = {} - - nodes.each do |node| - node.namespaces.each do |k, v| - key = k.sub(/^xmlns:/, '') - namespaces[key] = v - end - end - - namespaces.delete('xmlns') - namespaces - end - - def schema_nodes - @schema_nodes ||= begin - types = @document.at_xpath('/wsdl:definitions/wsdl:types', 'wsdl' => Wasabi::WSDL) - types ? types.element_children : [] - end - end - - def service_node - @document.at_xpath('/wsdl:definitions/wsdl:service', 'wsdl' => Wasabi::WSDL) - end - - end -end diff --git a/lib/wasabi/schema.rb b/lib/wasabi/schema.rb index f9f9ecd..250efdf 100644 --- a/lib/wasabi/schema.rb +++ b/lib/wasabi/schema.rb @@ -5,15 +5,13 @@ class Schema CHILD_TYPES = %w[element complexType simpleType] - def initialize(schema, parser) + def initialize(schema, wsdl) @schema = schema + @wsdl = wsdl @target_namespace = @schema['targetNamespace'] @element_form_default = @schema['elementFormDefault'] - # TODO: get rid of this dependency. - @parser = parser - @elements = {} @complex_types = {} @simple_types = {} @@ -40,13 +38,13 @@ def parse_types case node.name when 'element' - type = Type.new(node, @parser) + type = Type.new(node, @wsdl) @elements[type_name] = type when 'complexType' - type = Type.new(node, @parser) + type = Type.new(node, @wsdl) @complex_types[type_name] = type when 'simpleType' - simple_type = SimpleType.new(node, @parser) + simple_type = SimpleType.new(node, @wsdl) @simple_types[type_name] = simple_type end end diff --git a/lib/wasabi/schema_collection.rb b/lib/wasabi/schema_collection.rb index 78343da..d20afe4 100644 --- a/lib/wasabi/schema_collection.rb +++ b/lib/wasabi/schema_collection.rb @@ -2,8 +2,16 @@ class Wasabi class SchemaCollection include Enumerable - def initialize(schemas) - @schemas = schemas + def initialize + @schemas = [] + end + + def <<(schema) + @schemas << schema + end + + def push(schemas) + @schemas += schemas end def each(&block) diff --git a/lib/wasabi/type.rb b/lib/wasabi/type.rb index d13d52f..dffa1a0 100644 --- a/lib/wasabi/type.rb +++ b/lib/wasabi/type.rb @@ -2,9 +2,9 @@ class Wasabi class SimpleType - def initialize(node, parser) + def initialize(node, wsdl) @node = node - @parser = parser + @wsdl = wsdl end def type @@ -18,9 +18,9 @@ def type class Type - def initialize(node, parser) + def initialize(node, wsdl) @node = node - @parser = parser + @wsdl = wsdl @name = node['name'] end @@ -65,7 +65,7 @@ def parse_complex_type(complex_type, name) complex_type.xpath('./xs:complexContent/xs:extension[@base]', 'xs' => Wasabi::XSD).each do |extension| base = extension.attribute('base').value.match(/\w+$/).to_s - base_type = @parser.schemas.types.fetch(base) { raise "expected to find extension base #{base} in types" } + base_type = @wsdl.schemas.types.fetch(base) { raise "expected to find extension base #{base} in types" } children += base_type.children end @@ -82,7 +82,7 @@ def parse_element(element) _, nsid = type && type.split(':').reverse if nsid - namespace = @parser.namespaces.fetch(nsid) + namespace = @wsdl.namespaces.fetch(nsid) simple_type = namespace == Wasabi::XSD else # assume that elements with a @type qname lacking an nsid to reference the xml schema. diff --git a/spec/fixtures/bookt.wsdl b/spec/fixtures/bookt.wsdl new file mode 100644 index 0000000..3e2d238 --- /dev/null +++ b/spec/fixtures/bookt.wsdl @@ -0,0 +1,11 @@ + + + + + + + + + + + diff --git a/spec/fixtures/bookt2.wsdl b/spec/fixtures/bookt2.wsdl new file mode 100644 index 0000000..4968382 --- /dev/null +++ b/spec/fixtures/bookt2.wsdl @@ -0,0 +1,243 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/spec/fixtures/bookt3.wsdl b/spec/fixtures/bookt3.wsdl new file mode 100644 index 0000000..caa1e6f --- /dev/null +++ b/spec/fixtures/bookt3.wsdl @@ -0,0 +1,286 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/spec/fixtures/import_port_types.wsdl b/spec/fixtures/bydexchange.wsdl similarity index 84% rename from spec/fixtures/import_port_types.wsdl rename to spec/fixtures/bydexchange.wsdl index 76f9fc0..c7f4b48 100644 --- a/spec/fixtures/import_port_types.wsdl +++ b/spec/fixtures/bydexchange.wsdl @@ -1,10 +1,28 @@ - + + + + + + + + + + + + + + + + + + + diff --git a/spec/fixtures/bydexchange2.wsdl b/spec/fixtures/bydexchange2.wsdl new file mode 100644 index 0000000..86acf7a --- /dev/null +++ b/spec/fixtures/bydexchange2.wsdl @@ -0,0 +1,119 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index d75545f..ed3626c 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -1,5 +1,7 @@ -require "bundler" -Bundler.require :default, :development +require 'bundler' +Bundler.setup + +require 'wasabi' unless RUBY_PLATFORM =~ /java/ require "simplecov" @@ -15,5 +17,6 @@ Dir[support_files].each { |file| require file } RSpec.configure do |config| - config.include SpecSupport::Methods + config.include SpecSupport + config.mock_framework = :mocha end diff --git a/spec/support/fixture.rb b/spec/support/fixture.rb index 073ddc3..7b0316b 100644 --- a/spec/support/fixture.rb +++ b/spec/support/fixture.rb @@ -1,6 +1,7 @@ module SpecSupport class Fixture + def self.[](name) fixtures[name] end @@ -31,12 +32,11 @@ def path def read Fixture[filename] ||= File.read(path) end + end - module Methods - def fixture(*args) - Fixture.new(*args) - end + def fixture(*args) + Fixture.new(*args) end end diff --git a/spec/support/mock_request.rb b/spec/support/mock_request.rb new file mode 100644 index 0000000..fb3d5c4 --- /dev/null +++ b/spec/support/mock_request.rb @@ -0,0 +1,8 @@ +module SpecSupport + + def mock_request(url, fixture_name) + response = HTTPI::Response.new 200, {}, fixture(fixture_name).read + HTTPI.expects(:get).with { |r| r.url == URI(url) }.returns(response) + end + +end diff --git a/spec/wasabi/document_spec.rb b/spec/wasabi/document_spec.rb deleted file mode 100644 index 3a3f397..0000000 --- a/spec/wasabi/document_spec.rb +++ /dev/null @@ -1,24 +0,0 @@ -require "spec_helper" - -describe Wasabi::Document do - - subject { Wasabi::Document.new fixture(:authentication).read } - - it "accepts a URL" do - HTTPI.should_receive(:get) { HTTPI::Response.new(200, {}, "wsdl") } - - document = Wasabi::Document.new("http://example.com?wsdl") - document.xml.should == "wsdl" - end - - it "accepts a path" do - document = Wasabi::Document.new fixture(:authentication).path - document.xml.should == fixture(:authentication).read - end - - it "accepts raw XML" do - document = Wasabi::Document.new fixture(:authentication).read - document.xml.should == fixture(:authentication).read - end - -end diff --git a/spec/wasabi/integration/bookt_spec.rb b/spec/wasabi/integration/bookt_spec.rb new file mode 100644 index 0000000..f2471f3 --- /dev/null +++ b/spec/wasabi/integration/bookt_spec.rb @@ -0,0 +1,24 @@ +require 'spec_helper' + +describe Wasabi do + context 'with: bookt.wsdl' do + + subject(:wsdl) { Wasabi.new(wsdl_url) } + + let(:wsdl_url) { 'http://connect.bookt.com/svc/connect.svc?wsdl' } + let(:wsdl2_url) { 'http://connect.bookt.com/svc/connect.svc?wsdl=wsdl1' } + let(:wsdl3_url) { 'http://connect.bookt.com/svc/connect.svc?wsdl=wsdl0' } + + before do + mock_request wsdl_url, :bookt + mock_request wsdl2_url, :bookt2 + mock_request wsdl3_url, :bookt3 + end + + it 'resolves WSDL imports to get the operations' do + expect(wsdl.documents.operations).to_not be_empty + end + + end +end + diff --git a/spec/wasabi/integration/bydexchange_spec.rb b/spec/wasabi/integration/bydexchange_spec.rb new file mode 100644 index 0000000..6cb3a3a --- /dev/null +++ b/spec/wasabi/integration/bydexchange_spec.rb @@ -0,0 +1,22 @@ +require 'spec_helper' + +describe Wasabi do + context 'with: bydexchange.wsdl' do + + subject(:wsdl) { Wasabi.new(wsdl_url) } + + let(:wsdl_url) { 'http://bydexchange.nbs-us.com/BYDExchangeServer.svc?wsdl' } + let(:wsdl2_url) { 'http://bydexchange.nbs-us.com/BYDExchangeServer.svc?wsdl=wsdl0' } + + before do + mock_request wsdl_url, :bydexchange + mock_request wsdl2_url, :bydexchange2 + end + + it 'resolves WSDL imports to get the operations' do + expect(wsdl.documents.operations.keys).to include(:get_customer) + end + + end +end + diff --git a/spec/wasabi/integration/economic_spec.rb b/spec/wasabi/integration/economic_spec.rb index 0e185c1..5f19d76 100644 --- a/spec/wasabi/integration/economic_spec.rb +++ b/spec/wasabi/integration/economic_spec.rb @@ -8,7 +8,7 @@ # XXX: this might be useless now that almost everything is parsed lazily. it 'has an ok parse-time for huge wsdl files' do #profiler = MethodProfiler.observe(Wasabi::Parser) - expect(wsdl.parser.operations.count).to eq(1511) + expect(wsdl.documents.operations.count).to eq(1511) #puts profiler.report end diff --git a/spec/wasabi/parser/juniper_spec.rb b/spec/wasabi/integration/juniper_spec.rb similarity index 70% rename from spec/wasabi/parser/juniper_spec.rb rename to spec/wasabi/integration/juniper_spec.rb index 4be7caa..d0708aa 100644 --- a/spec/wasabi/parser/juniper_spec.rb +++ b/spec/wasabi/integration/juniper_spec.rb @@ -1,14 +1,14 @@ require "spec_helper" -describe Wasabi::Parser do +describe Wasabi do context 'with: juniper.wsdl' do - subject(:parser) { Wasabi::Parser.new Nokogiri::XML(xml) } + subject(:wsdl) { Wasabi.new(xml) } let(:xml) { fixture(:juniper).read } it 'does not blow up when an extension base element is defined in an import' do - operation = parser.operations[:get_system_info_request] + operation = wsdl.documents.operations[:get_system_info_request] operation.input.should == 'GetSystemInfoRequest' operation.soap_action.should == 'urn:#GetSystemInfoRequest' diff --git a/spec/wasabi/parser/no_message_parts_spec.rb b/spec/wasabi/integration/no_message_parts_spec.rb similarity index 58% rename from spec/wasabi/parser/no_message_parts_spec.rb rename to spec/wasabi/integration/no_message_parts_spec.rb index 2f13ddc..54f2772 100644 --- a/spec/wasabi/parser/no_message_parts_spec.rb +++ b/spec/wasabi/integration/no_message_parts_spec.rb @@ -1,18 +1,18 @@ require "spec_helper" -describe Wasabi::Parser do +describe Wasabi do context "with: no_message_parts.wsdl" do - subject(:parser) { Wasabi::Parser.new Nokogiri::XML(xml) } + subject(:wsdl) { Wasabi.new(xml) } let(:xml) { fixture(:no_message_parts).read } it "falls back to using the message type in the port element" do - parser.operations[:save].input.should == "Save" + wsdl.documents.operations[:save].input.should == "Save" end it "falls back to using the namespace ID in the port element" do - parser.operations[:save].nsid.should == "actions" + wsdl.documents.operations[:save].nsid.should == "actions" end end end diff --git a/spec/wasabi/parser/symbolic_endpoint_spec.rb b/spec/wasabi/integration/symbolic_endpoint_spec.rb similarity index 58% rename from spec/wasabi/parser/symbolic_endpoint_spec.rb rename to spec/wasabi/integration/symbolic_endpoint_spec.rb index 0096c7a..c943cf8 100644 --- a/spec/wasabi/parser/symbolic_endpoint_spec.rb +++ b/spec/wasabi/integration/symbolic_endpoint_spec.rb @@ -1,14 +1,14 @@ require "spec_helper" -describe Wasabi::Parser do +describe Wasabi do context "with: symbolic_endpoint.wsdl" do - subject(:parser) { Wasabi::Parser.new Nokogiri::XML(xml) } + subject(:wsdl) { Wasabi.new(xml) } let(:xml) { fixture(:symbolic_endpoint).read } it "allows symbolic endpoints" do - parser.endpoint.should be_nil + wsdl.endpoint.should be_nil end end diff --git a/spec/wasabi/parser/import_port_types_spec.rb b/spec/wasabi/parser/import_port_types_spec.rb deleted file mode 100644 index 9063621..0000000 --- a/spec/wasabi/parser/import_port_types_spec.rb +++ /dev/null @@ -1,18 +0,0 @@ -require "spec_helper" - -describe Wasabi::Parser do - context "with: import_port_types.wsdl" do - - subject(:parser) { Wasabi::Parser.new Nokogiri::XML(xml) } - - let(:xml) { fixture(:import_port_types).read } - - it "does blow up when portTypes are imported" do - operation = parser.operations[:get_customer] - - operation.input.should == "GetCustomer" - operation.nsid.should be_nil - end - - end -end diff --git a/spec/wasabi/parser/no_target_namespace_spec.rb b/spec/wasabi/parser/no_target_namespace_spec.rb deleted file mode 100644 index f38083b..0000000 --- a/spec/wasabi/parser/no_target_namespace_spec.rb +++ /dev/null @@ -1,37 +0,0 @@ -require "spec_helper" - -describe Wasabi::Parser do - context "with a WSDL defining xs:schema without targetNamespace" do - - subject do - parser = Wasabi::Parser.new Nokogiri::XML(xml) - parser.parse - parser - end - - let(:xml) do - %Q{ - - - - - - - - - - } - end - - # Don't know if real WSDL files omit targetNamespace from xs:schema, - # but I suppose we should do something reasonable if they do. - - it "defaults to the target namespace from xs:definitions" do - pending "find out if this meets the specification" - subject.schemas.types["Save"].namespace.should == "http://def.example.com" - end - - end -end diff --git a/spec/wasabi/resolver_spec.rb b/spec/wasabi/resolver_spec.rb index b96e82a..1259c04 100644 --- a/spec/wasabi/resolver_spec.rb +++ b/spec/wasabi/resolver_spec.rb @@ -4,7 +4,7 @@ describe "#resolve" do it "resolves remote documents" do - HTTPI.should_receive(:get) { HTTPI::Response.new(200, {}, "wsdl") } + HTTPI.expects(:get).returns HTTPI::Response.new(200, {}, "wsdl") xml = Wasabi::Resolver.new.resolve("http://example.com?wsdl") xml.should == "wsdl" end @@ -25,14 +25,14 @@ "content-type" => "text/html" } body = "404 Not FoundOops!" + failed_response = HTTPI::Response.new(code, headers, body) - HTTPI.stub(:get => failed_response) - lambda do - Wasabi::Resolver.new.resolve("http://example.com?wsdl") - end.should raise_error { |ex| - ex.should be_a(Wasabi::Resolver::HTTPError) - ex.message.should == "Error: #{code}" - ex.response.should == failed_response + HTTPI.stubs(:get).returns(failed_response) + + expect { Wasabi::Resolver.new.resolve("http://example.com?wsdl") }.to raise_error { |error| + error.should be_a(Wasabi::Resolver::HTTPError) + error.message.should == "Error: #{code}" + error.response.should == failed_response } end end diff --git a/spec/wasabi/types_spec.rb b/spec/wasabi/types_spec.rb index 49c43c8..7a944bb 100644 --- a/spec/wasabi/types_spec.rb +++ b/spec/wasabi/types_spec.rb @@ -1,9 +1,9 @@ require 'spec_helper' -describe Wasabi::Parser do +describe Wasabi do it 'knows simple types' do - parser = parse(' + wsdl = wsdl(' @@ -17,14 +17,14 @@ ') - unit = parser.schemas.simple_type('TemperatureUnit') + unit = wsdl.schemas.simple_type('TemperatureUnit') expect(unit).to be_a(Wasabi::SimpleType) expect(unit.type).to eq('xs:string') end it 'knows xs:all types' do - parser = parse(' + wsdl = wsdl(' @@ -41,7 +41,7 @@ ') - mp_user = parser.schemas.complex_type('MpUser') + mp_user = wsdl.schemas.complex_type('MpUser') expect(mp_user).to be_a(Wasabi::Type) expect(mp_user).to have(8).children @@ -55,7 +55,7 @@ end it 'works with multiple schemas and extensions' do - parser = parse(' + wsdl = wsdl(' @@ -94,7 +94,7 @@ ') - account = parser.schemas.complex_type('Account') + account = wsdl.schemas.complex_type('Account') expect(account).to be_a(Wasabi::Type) expect(account).to have(5).children @@ -110,7 +110,7 @@ end it 'determines whether elements are simple types by their namespace' do - parser = parse(' + wsdl = wsdl(' @@ -123,7 +123,7 @@ ') - terms = parser.schemas.element('TermOfPayment') + terms = wsdl.schemas.element('TermOfPayment') expect(terms).to be_a(Wasabi::Type) expect(terms).to have(2).children @@ -146,7 +146,7 @@ ]) end - def parse(types) + def wsdl(types) wsdl = %' ' - Wasabi::Parser.new Nokogiri.XML(wsdl) + Wasabi.new(wsdl) end end diff --git a/wasabi.gemspec b/wasabi.gemspec index 274b431..1999a29 100644 --- a/wasabi.gemspec +++ b/wasabi.gemspec @@ -16,8 +16,9 @@ Gem::Specification.new do |s| s.add_dependency "httpi", "~> 2.0" s.add_dependency "nokogiri", ">= 1.4.0" - s.add_development_dependency "rake", "~> 0.9" - s.add_development_dependency "rspec", "~> 2.10" + s.add_development_dependency "rake", "~> 10.0" + s.add_development_dependency "rspec", "~> 2.13" + s.add_development_dependency "mocha", "~> 0.13" s.files = `git ls-files`.split("\n") s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")