Skip to content

Commit

Permalink
Updates for Statement and Query::Pattern positional argument deprecat…
Browse files Browse the repository at this point in the history
…ion.
  • Loading branch information
gkellogg committed Dec 21, 2015
1 parent 9088383 commit 7bd1ffe
Show file tree
Hide file tree
Showing 7 changed files with 23 additions and 55 deletions.
2 changes: 1 addition & 1 deletion .travis.yml
Expand Up @@ -7,7 +7,7 @@ rvm:
- 2.0
- 2.1
- 2.2
- jruby
- jruby-9
- rbx-2
cache: bundler
sudo: false
2 changes: 1 addition & 1 deletion Gemfile
Expand Up @@ -2,7 +2,7 @@ source "http://rubygems.org"

gemspec

gem "rdf", git: "git://github.com/ruby-rdf/rdf.git", branch: "develop"
gem "rdf", git: "git://github.com/ruby-rdf/rdf.git", branch: "feature/keyword-arguments"

group :development do
gem "wirble"
Expand Down
2 changes: 1 addition & 1 deletion lib/rdf/spec/enumerable.rb
Expand Up @@ -80,7 +80,7 @@

it {is_expected.to respond_to(:has_statement?)}
context "#has_statement?" do
let(:unknown_statement) {RDF::Statement.new(RDF::Node.new, RDF::URI.new("http://example.org/unknown"), RDF::Node.new)}
let(:unknown_statement) {RDF::Statement.new(subject: RDF::Node.new, predicate: RDF::URI.new("http://example.org/unknown"), object: RDF::Node.new)}
it "should have all statements" do
# Don't check for BNodes, as equivalence depends on their being exactly the same, not just the same identifier. If subject is loaded separately, these won't match.
non_bnode_statements.each do |statement|
Expand Down
2 changes: 1 addition & 1 deletion lib/rdf/spec/indexable.rb
Expand Up @@ -18,7 +18,7 @@
end

it "returns self on #index!" do
expect(subject.index!).to be eql(subject)
expect(subject.index!).to eql(subject)
end
end

Expand Down
9 changes: 5 additions & 4 deletions lib/rdf/spec/mutable.rb
Expand Up @@ -126,7 +126,7 @@
if subject.mutable?
# Setup three statements identical except for graph_name
count = subject.count + (@supports_named_graphs ? 3 : 1)
s1 = RDF::Statement.new(resource, RDF::URI.new("urn:predicate:1"), RDF::URI.new("urn:object:1"))
s1 = RDF::Statement.new(subject: resource, predicate: RDF::URI.new("urn:predicate:1"), object: RDF::URI.new("urn:object:1"))
s2 = s1.dup
s2.graph_name = RDF::URI.new("urn:graph_name:1")
s3 = s1.dup
Expand All @@ -148,9 +148,10 @@

describe '#delete_insert' do
let(:statement) do
RDF::Statement.new(resource,
RDF::URI.new("urn:predicate:1"),
RDF::URI.new("urn:object:1"))
RDF::Statement.new(
subject: resource,
predicate: RDF::URI.new("urn:predicate:1"),
object: RDF::URI.new("urn:object:1"))
end

it 'deletes and inserts' do
Expand Down
59 changes: 13 additions & 46 deletions lib/rdf/spec/queryable.rb
Expand Up @@ -77,52 +77,16 @@
end
end

context "with context", unless: RDF::VERSION.to_s >= "1.99" do
it "returns statements from all contexts with no context" do
pattern = RDF::Query::Pattern.new(nil, nil, nil, context: nil)
solutions = []
subject.send(method, pattern) {|s| solutions << s}
expect(solutions.size).to eq @statements.size
end

it "returns statements from unnamed contexts with false context" do
pattern = RDF::Query::Pattern.new(nil, nil, nil, context: false)
solutions = []
subject.send(method, pattern) {|s| solutions << s}
context_statements = subject.statements.reject {|st| st.has_context?}.length
expect(solutions.size).to eq context_statements
end

it "returns statements from named contexts with variable context" do
unless subject.contexts.to_a.empty?
pattern = RDF::Query::Pattern.new(nil, nil, nil, context: :c)
solutions = []
subject.send(method, pattern) {|s| solutions << s}
context_statements = subject.statements.select {|st| st.has_context?}.length
expect(solutions.size).to eq context_statements
end
end

it "returns statements from specific context with URI context" do
unless subject.contexts.to_a.empty?
pattern = RDF::Query::Pattern.new(nil, nil, nil, context: RDF::URI("http://ar.to/#self"))
solutions = []
subject.send(method, pattern) {|s| solutions << s}
expect(solutions.size).to eq File.readlines(@doap).grep(/^<http:\/\/ar.to\/\#self>/).size
end
end
end

context "with graph_name", if: RDF::VERSION.to_s >= "1.99" do
context "with graph_name" do
it "returns statements from all graphs with no graph_name" do
pattern = RDF::Query::Pattern.new(nil, nil, nil, graph_name: nil)
pattern = RDF::Query::Pattern.new(subject: nil, predicate: nil, object: nil, graph_name: nil)
solutions = []
subject.send(method, pattern) {|s| solutions << s}
expect(solutions.size).to eq @statements.size
end

it "returns statements from unnamed graphss with false graph_name" do
pattern = RDF::Query::Pattern.new(nil, nil, nil, graph_name: false)
pattern = RDF::Query::Pattern.new(subject: nil, predicate: nil, object: nil, graph_name: false)
solutions = []
subject.send(method, pattern) {|s| solutions << s}
named_statements = subject.statements.reject {|st| st.has_name?}.length
Expand All @@ -131,7 +95,7 @@

it "returns statements from named graphss with variable graph_name" do
unless subject.graph_names.to_a.empty?
pattern = RDF::Query::Pattern.new(nil, nil, nil, graph_name: :c)
pattern = RDF::Query::Pattern.new(subject: nil, predicate: nil, object: nil, graph_name: :c)
solutions = []
subject.send(method, pattern) {|s| solutions << s}
named_statements = subject.statements.select {|st| st.has_name?}.length
Expand All @@ -141,7 +105,7 @@

it "returns statements from specific graph with URI graph_name" do
unless subject.graph_names.to_a.empty?
pattern = RDF::Query::Pattern.new(nil, nil, nil, graph_name: RDF::URI("http://ar.to/#self"))
pattern = RDF::Query::Pattern.new(subject: nil, predicate: nil, object: nil, graph_name: RDF::URI("http://ar.to/#self"))
solutions = []
subject.send(method, pattern) {|s| solutions << s}
expect(solutions.size).to eq File.readlines(@doap).grep(/^<http:\/\/ar.to\/\#self>/).size
Expand All @@ -164,12 +128,12 @@
end

it "accepts a pattern argument" do
expect { subject.query(RDF::Query::Pattern.new(nil, nil, nil)) }.not_to raise_error
expect { subject.query(RDF::Query::Pattern.new(:s, :p, :o)) }.not_to raise_error
expect { subject.query(RDF::Query::Pattern.new(subject: nil, predicate: nil, object: nil)) }.not_to raise_error
expect { subject.query(RDF::Query::Pattern.new(subject: :s, predicate: :p, object: :o)) }.not_to raise_error
end

it "accepts a statement argument" do
expect { subject.query(RDF::Statement.new(nil, nil, nil)) }.not_to raise_error
expect { subject.query(RDF::Statement.new(subject: nil, predicate: nil, object: nil)) }.not_to raise_error
end

it "accepts a triple argument" do
Expand Down Expand Up @@ -287,13 +251,16 @@
context "triple pattern combinations" do
it "?s p o" do
expect(subject.query(predicate: RDF::URI("http://example.org/p"), object: RDF::Literal.new(1)).to_a).to(
include *[RDF::Statement.new(RDF::URI("http://example.org/xi1"), RDF::URI("http://example.org/p"), 1), RDF::Statement.new(RDF::URI("http://example.org/xi2"), RDF::URI("http://example.org/p"), 1)]
include *[
RDF::Statement.from([RDF::URI("http://example.org/xi1"), RDF::URI("http://example.org/p"), 1]),
RDF::Statement.from([RDF::URI("http://example.org/xi2"), RDF::URI("http://example.org/p"), 1])
]
)
end

it "s ?p o" do
expect(subject.query(subject: RDF::URI("http://example.org/xi2"), object: RDF::Literal.new(1)).to_a).to(
include *[RDF::Statement.new(RDF::URI("http://example.org/xi2"), RDF::URI("http://example.org/p"), 1)]
include *[RDF::Statement.from([RDF::URI("http://example.org/xi2"), RDF::URI("http://example.org/p"), 1])]
)
end
end
Expand Down
2 changes: 1 addition & 1 deletion lib/rdf/spec/writer.rb
Expand Up @@ -138,7 +138,7 @@
file = StringIO.new
expect do
writer_class.new(file, logger: false) do |w|
w << RDF::Statement.new(
w << RDF::Statement(
RDF::URI("http://rubygems.org/gems/rdf"),
RDF::URI("http://purl.org/dc/terms/creator"),
nil)
Expand Down

0 comments on commit 7bd1ffe

Please sign in to comment.