Skip to content

Commit 6778062

Browse files
committed
Move illegal content writer test to a separate group. Exclude for REXML as xpath results are different for attribute values.
1 parent d5d1e1d commit 6778062

2 files changed

Lines changed: 43 additions & 16 deletions

File tree

spec/spec_helper.rb

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,11 @@
1111
require 'rdf/spec/matchers'
1212
require 'rdf/isomorphic'
1313
require 'open-uri/cached'
14+
begin
15+
require 'nokogiri'
16+
rescue LoadError => e
17+
:rexml
18+
end
1419

1520
# Create and maintain a cache of downloaded URIs
1621
URI_CACHE = File.expand_path(File.join(File.dirname(__FILE__), "uri-cache"))
@@ -20,10 +25,6 @@
2025
::RSpec.configure do |c|
2126
c.filter_run :focus => true
2227
c.run_all_when_everything_filtered = true
23-
c.exclusion_filter = {
24-
:ruby => lambda { |version| !(RUBY_VERSION.to_s =~ /^#{version.to_s}/) },
25-
:no_jruby => lambda { |version| !(RUBY_PLATFORM.to_s != 'java') },
26-
}
2728
c.include(RDF::Spec::Matchers)
2829
end
2930

spec/writer_spec.rb

Lines changed: 38 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -18,27 +18,18 @@ class FOO < RDF::Vocabulary("http://foo/"); end
1818
context "typed resources" do
1919
context "resource without type" do
2020
subject do
21-
@graph << [RDF::URI.new("http://release/"), RDF::DC.title, "foo & bar"]
21+
@graph << [RDF::URI.new("http://release/"), RDF::DC.title, "foo"]
2222
serialize(attributes: :untyped)
2323
end
2424

2525
{
2626
"/rdf:RDF/rdf:Description/@rdf:about" => "http://release/",
27-
"/rdf:RDF/rdf:Description[@dc:title='foo & bar']/@rdf:about" => "http://release/",
28-
"/rdf:RDF/rdf:Description/@dc:title" => "foo & bar"
27+
"/rdf:RDF/rdf:Description/@dc:title" => "foo"
2928
}.each do |path, value|
3029
it "returns #{value.inspect} for xpath #{path}" do
3130
expect(subject).to have_xpath(path, value, {}, @debug)
3231
end
3332
end
34-
[
35-
'<dc:title>foo &amp; bar</dc:title>',
36-
'dc:title=\'foo &amp; bar\''
37-
].each do |value|
38-
it "serializes literal value with illegal XML characters to fragment #{value}" do
39-
expect(subject).to include(value)
40-
end
41-
end
4233
end
4334

4435
context "resource with type" do
@@ -119,7 +110,42 @@ class FOO < RDF::Vocabulary("http://foo/"); end
119110
end
120111
end
121112
end
122-
113+
114+
context "with illegal content" do
115+
context "in attribute", skip: !defined?(::Nokogiri) do
116+
subject do
117+
@graph << [RDF::URI.new("http://release/"), RDF::DC.title, "foo & bar"]
118+
serialize(attributes: :untyped)
119+
end
120+
121+
{
122+
"/rdf:RDF/rdf:Description/@rdf:about" => "http://release/",
123+
"/rdf:RDF/rdf:Description/@dc:title" => "foo & bar",
124+
"/rdf:RDF/rdf:Description/dc:title" => false
125+
}.each do |path, value|
126+
it "returns #{value.inspect} for xpath #{path}" do
127+
expect(subject).to have_xpath(path, value, {}, @debug)
128+
end
129+
end
130+
end
131+
context "in element" do
132+
subject do
133+
@graph << [RDF::URI.new("http://release/"), RDF::DC.title, "foo & bar"]
134+
serialize(attributes: :none)
135+
end
136+
137+
{
138+
"/rdf:RDF/rdf:Description/@rdf:about" => "http://release/",
139+
"/rdf:RDF/rdf:Description/@dc:title" => false,
140+
"/rdf:RDF/rdf:Description/dc:title/text()" => "foo &amp; bar"
141+
}.each do |path, value|
142+
it "returns #{value.inspect} for xpath #{path}" do
143+
expect(subject).to have_xpath(path, value, {}, @debug)
144+
end
145+
end
146+
end
147+
end
148+
123149
context "with children" do
124150
before(:each) {
125151
@graph << [RDF::URI.new("http://release/"), RDF.type, FOO.Release]

0 commit comments

Comments
 (0)