Permalink
Browse files

start using remote XSD file when verifying XML in tests

  • Loading branch information...
shime committed Apr 25, 2013
1 parent e93132c commit df1c1e00c8157e549626acf0b0baa168382d9923
Showing with 5 additions and 91 deletions.
  1. +0 −89 resources/airbrake_2_4.xsd
  2. +5 −2 test/notice_test.rb
View
@@ -1,89 +0,0 @@
-<?xml version="1.0"?>
-<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">
-
- <xs:element name="notice">
- <xs:complexType>
- <xs:all>
- <xs:element name="api-key" type="xs:string"/>
- <xs:element name="notifier" type="notifier"/>
- <xs:element name="error" type="error"/>
- <xs:element name="request" type="request" minOccurs="0"/>
- <xs:element name="server-environment" type="serverEnvironment"/>
- <xs:element name="current-user" type="current-user" minOccurs="0"/>
- <xs:element name="framework" type="xs:string" minOccurs="0"/>
- </xs:all>
- <xs:attribute name="version" type="xs:string" use="required"/>
- </xs:complexType>
- </xs:element>
-
- <xs:complexType name="notifier">
- <xs:all>
- <xs:element name="name" type="xs:string"/>
- <xs:element name="version" type="xs:string"/>
- <xs:element name="url" type="xs:string"/>
- </xs:all>
- </xs:complexType>
-
- <xs:complexType name="error">
- <xs:all>
- <xs:element name="class" type="xs:string"/>
- <xs:element name="message" type="xs:string" minOccurs="0"/>
- <xs:element name="backtrace" type="backtrace"/>
- </xs:all>
- </xs:complexType>
-
- <xs:complexType name="backtrace">
- <xs:sequence>
- <xs:element name="line" maxOccurs="unbounded" minOccurs="0">
- <xs:complexType>
- <xs:attribute name="file" type="xs:string" use="required"/>
- <xs:attribute name="number" type="xs:string" use="required"/>
- <xs:attribute name="method" type="xs:string" use="optional"/>
- </xs:complexType>
- </xs:element>
- </xs:sequence>
- </xs:complexType>
-
- <xs:complexType name="request">
- <xs:all>
- <xs:element name="url" type="xs:string"/>
- <xs:element name="component" type="xs:string"/>
- <xs:element name="action" type="xs:string" minOccurs="0"/>
- <xs:element name="params" type="varList" minOccurs="0"/>
- <xs:element name="session" type="varList" minOccurs="0"/>
- <xs:element name="cgi-data" type="varList" minOccurs="0"/>
- </xs:all>
- </xs:complexType>
-
- <xs:complexType name="varList">
- <xs:sequence>
- <xs:element name="var" type="var" maxOccurs="unbounded"/>
- </xs:sequence>
- </xs:complexType>
-
- <xs:complexType name="var" mixed="true">
- <xs:sequence>
- <xs:element name="var" type="var" minOccurs="0" maxOccurs="unbounded"/>
- </xs:sequence>
- <xs:attribute name="key" type="xs:string" use="required"/>
- </xs:complexType>
-
- <xs:complexType name="serverEnvironment">
- <xs:sequence>
- <xs:element name="project-root" type="xs:string" minOccurs="0"/>
- <xs:element name="environment-name" type="xs:string"/>
- <xs:element name="app-version" type="xs:string" minOccurs="0"/>
- <xs:element name="hostname" type="xs:string" minOccurs="0"/>
- </xs:sequence>
- </xs:complexType>
-
- <xs:complexType name="current-user">
- <xs:all>
- <xs:element name="id" type="xs:string"/>
- <xs:element name="name" type="xs:string" minOccurs="0"/>
- <xs:element name="email" type="xs:string" minOccurs="0"/>
- <xs:element name="username" type="xs:string" minOccurs="0"/>
- </xs:all>
- </xs:complexType>
-
-</xs:schema>
View
@@ -1,5 +1,8 @@
require File.expand_path '../helper', __FILE__
+XSD_SCHEMA_PATH = "http://airbrake.io/airbrake_#{Airbrake::API_VERSION.tr(".","_")}.xsd"
+FakeWeb.allow_net_connect = %r{#{XSD_SCHEMA_PATH}}
+
class NoticeTest < Test::Unit::TestCase
include DefinesConstants
@@ -61,8 +64,8 @@ def assert_serializes_hash(attribute)
end
def assert_valid_notice_document(document)
- xsd_path = File.expand_path(File.join(File.dirname(__FILE__),"..", "resources", "airbrake_2_4.xsd"))
- schema = Nokogiri::XML::Schema.new(IO.read(xsd_path))
+ xsd_path = URI(XSD_SCHEMA_PATH)
+ schema = Nokogiri::XML::Schema.new(Net::HTTP.get(xsd_path))
errors = schema.validate(document)
assert errors.empty?, errors.collect{|e| e.message }.join
end

0 comments on commit df1c1e0

Please sign in to comment.