Skip to content

Commit

Permalink
code to run ironruby xml validation vs nokogiri xml validation
Browse files Browse the repository at this point in the history
  • Loading branch information
Derick Bailey committed Feb 25, 2011
1 parent d530539 commit 91ec137
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 4 deletions.
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ spec/support/expandtemplates/output
spec/support/expandtemplates/working
spec/support/TestSolution/NDependOut
spec/support/zip/*.zip.*
spec/support/nuspec
spec/support/nuspec/output
github-test.rb
Albacore-*.gem
albacore-*.gem
Expand Down
17 changes: 14 additions & 3 deletions spec/nuspec_spec.rb
Original file line number Diff line number Diff line change
@@ -1,11 +1,22 @@
require 'fileutils'
require 'spec_helper.rb'
require 'albacore/nuspec.rb'
require 'support\nokogiri_validator'

if IS_IRONRUBY
require 'support\ironruby_validator'
else
require 'support\nokogiri_validator'
end

describe Nuspec, 'when creating a file with minimum requirements' do
let(:working_dir) { File.expand_path(File.join(File.dirname(__FILE__), 'support/nuspec/')) }
let(:working_dir) do
wd = File.expand_path(File.join(File.dirname(__FILE__), 'support/nuspec/output'))
FileUtils.mkdir(wd) unless File.exist?(wd)
wd
end

let(:nuspec_output) { File.join(working_dir, 'nuspec_test.nuspec') }
let(:schema_file) { File.join(working_dir, 'nuspec.xsd') }
let(:schema_file) { File.expand_path(File.join(working_dir, '../', 'nuspec.xsd')) }

let(:nuspec) do
nuspec = Nuspec.new
Expand Down
1 change: 1 addition & 0 deletions spec/spec_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -21,3 +21,4 @@
config.mock_with NotAMock::RspecMockFrameworkAdapter
end

IS_IRONRUBY = (defined?(RUBY_ENGINE) && RUBY_ENGINE == "ironruby")
25 changes: 25 additions & 0 deletions spec/support/ironruby_validator.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
class XmlValidator
require 'System, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089'
require 'System.Xml, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089'

include System::Xml
include System::Xml::Schema
include System::IO

def self.validate(xml, xsd_file)
settings = XmlReaderSettings.new
settings.validation_type = ValidationType.Schema;
settings.schemas.add(nil, xsd_file)

is_valid = true
settings.validation_event_handler { |s, e|
is_valid = false if e.severity == XmlSeverityType.error
}

reader = XmlReader.create(StringReader.new(xml), settings)
while reader.read
end

return is_valid
end
end

0 comments on commit 91ec137

Please sign in to comment.