Skip to content

Commit

Permalink
Finish 3.0.0
Browse files Browse the repository at this point in the history
  • Loading branch information
gkellogg committed Dec 30, 2017
2 parents cb07f4d + 9aa20fb commit 59eae01
Show file tree
Hide file tree
Showing 14 changed files with 185 additions and 125 deletions.
17 changes: 10 additions & 7 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,17 +1,20 @@
language: ruby
bundler_args: --without debug
script: "bundle exec rspec spec"
before_install: "gem update --system"
env:
- CI=true
rvm:
- 2.2.6
- 2.3.3
- 2.4.0
- jruby
- rbx
- 2.2
- 2.3
- 2.4
- 2.5
- jruby-9
- rbx-3
cache: bundler
sudo: false
matrix:
allow_failures:
- rvm: rbx
- rvm: jruby
- rvm: jruby-9
- rvm: rbx-3
dist: trusty
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,8 @@ Note that in most cases, if the instance is empty and mutable, the appropriate s

## Dependencies

* [RDF.rb](http://rubygems.org/gems/rdf) (~> 2.0)
* [RSpec](http://rubygems.org/gems/rspec) (~> 3.0)
* [RDF.rb](http://rubygems.org/gems/rdf) (~> 3.0)
* [RSpec](http://rubygems.org/gems/rspec) (~> 3.7)

## Installation

Expand Down
2 changes: 1 addition & 1 deletion VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
2.2.0
3.0.0
4 changes: 2 additions & 2 deletions etc/doap.nt
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,8 @@ _:g70121455472480 <http://xmlns.com/foaf/0.1/mbox_sha1sum> "bedbbf2451e5beb38d59
<http://rubygems.org/gems/rdf> <http://usefulinc.com/ns/doap#implements> <http://www.w3.org/TR/rdf-concepts/> .
<http://rubygems.org/gems/rdf> <http://usefulinc.com/ns/doap#implements> <http://sw.deri.org/2008/07/n-quads/> .
<http://rubygems.org/gems/rdf> <http://usefulinc.com/ns/doap#implements> <http://www.w3.org/2001/sw/RDFCore/ntriples/> .
<http://rubygems.org/gems/rdf> <http://usefulinc.com/ns/doap#download-page> <http://rubyforge.org/projects/rdf/> .
<http://rubygems.org/gems/rdf> <http://usefulinc.com/ns/doap#bug-database> <http://github.com/ruby-rdf/rdf/issues> .
<http://rubygems.org/gems/rdf> <http://usefulinc.com/ns/doap#download-page> <http://rubygems.org/gems/rdf-spec/> .
<http://rubygems.org/gems/rdf> <http://usefulinc.com/ns/doap#bug-database> <http://github.com/ruby-rdf/rdf-spec/issues> .
<http://rubygems.org/gems/rdf> <http://usefulinc.com/ns/doap#blog> <http://ar.to/> .
<http://rubygems.org/gems/rdf> <http://usefulinc.com/ns/doap#blog> <http://blog.datagraph.org/> .
<http://rubygems.org/gems/rdf> <http://usefulinc.com/ns/doap#vendor> <http://datagraph.org/> .
Expand Down
2 changes: 1 addition & 1 deletion etc/quads.nq
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ _:g70121455472480 <http://xmlns.com/foaf/0.1/mbox_sha1sum> "bedbbf2451e5beb38d59
<http://rubygems.org/gems/rdf> <http://usefulinc.com/ns/doap#implements> <http://www.w3.org/TR/rdf-concepts/> .
<http://rubygems.org/gems/rdf> <http://usefulinc.com/ns/doap#implements> <http://sw.deri.org/2008/07/n-quads/> .
<http://rubygems.org/gems/rdf> <http://usefulinc.com/ns/doap#implements> <http://www.w3.org/2001/sw/RDFCore/ntriples/> .
<http://rubygems.org/gems/rdf> <http://usefulinc.com/ns/doap#download-page> <http://rubyforge.org/projects/rdf/> .
<http://rubygems.org/gems/rdf> <http://usefulinc.com/ns/doap#download-page> <http://http://github.com/ruby-rdf/rdf/> .
<http://rubygems.org/gems/rdf> <http://usefulinc.com/ns/doap#bug-database> <http://github.com/ruby-rdf/rdf/issues> .
<http://rubygems.org/gems/rdf> <http://usefulinc.com/ns/doap#blog> <http://ar.to/> .
<http://rubygems.org/gems/rdf> <http://usefulinc.com/ns/doap#blog> <http://blog.datagraph.org/> .
Expand Down
2 changes: 1 addition & 1 deletion etc/triples.nt
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ _:g70121455472480 <http://xmlns.com/foaf/0.1/mbox_sha1sum> "bedbbf2451e5beb38d59
<http://rubygems.org/gems/rdf> <http://usefulinc.com/ns/doap#implements> <http://www.w3.org/TR/rdf-concepts/> .
<http://rubygems.org/gems/rdf> <http://usefulinc.com/ns/doap#implements> <http://sw.deri.org/2008/07/n-quads/> .
<http://rubygems.org/gems/rdf> <http://usefulinc.com/ns/doap#implements> <http://www.w3.org/2001/sw/RDFCore/ntriples/> .
<http://rubygems.org/gems/rdf> <http://usefulinc.com/ns/doap#download-page> <http://rubyforge.org/projects/rdf/> .
<http://rubygems.org/gems/rdf> <http://usefulinc.com/ns/doap#download-page> <http://http://github.com/ruby-rdf/rdf/> .
<http://rubygems.org/gems/rdf> <http://usefulinc.com/ns/doap#bug-database> <http://github.com/ruby-rdf/rdf/issues> .
<http://rubygems.org/gems/rdf> <http://usefulinc.com/ns/doap#blog> <http://ar.to/> .
<http://rubygems.org/gems/rdf> <http://usefulinc.com/ns/doap#blog> <http://blog.datagraph.org/> .
Expand Down
2 changes: 2 additions & 0 deletions lib/rdf/spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
require 'rspec' # @see http://rubygems.org/gems/rspec
require 'rdf/spec/inspects'
require 'rspec/its'
require 'webmock'
WebMock.allow_net_connect!

module RDF
##
Expand Down
12 changes: 0 additions & 12 deletions lib/rdf/spec/enumerable.rb
Original file line number Diff line number Diff line change
Expand Up @@ -514,23 +514,11 @@
context "when converting" do
it {is_expected.to respond_to(:to_h)}
it {is_expected.not_to respond_to(:to_hash)}
its(:to_hash) {
expect {
is_expected.to be_instance_of(Hash)
}.to write("DEPRECATION").to(:error)
}
describe "#to_h" do
it "should have as many keys as subjects" do
expect(subject.to_h.keys.size).to eq enumerable.subjects.to_a.size
end
end
describe "#to_h" do
it "should have as many keys as subjects (with deprecation)" do
expect {
expect(subject.to_hash.keys.size).to eq enumerable.subjects.to_a.size
}.to write("DEPRECATION").to(:error)
end
end
end

context "when dumping" do
Expand Down
2 changes: 2 additions & 0 deletions lib/rdf/spec/http_adapter.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@
raise '`http_adapter` must be defined with `let(:http_adapter`' unless
defined? http_adapter
end
before(:each) {WebMock.disable_net_connect!}
after(:each) {WebMock.allow_net_connect!}

let(:uri) {"http://ruby-rdf.github.com/rdf/etc/doap.nt"}

Expand Down
50 changes: 36 additions & 14 deletions lib/rdf/spec/matchers.rb
Original file line number Diff line number Diff line change
Expand Up @@ -269,20 +269,6 @@ def io_name

RSpec::Matchers.define :be_equivalent_graph do |expected, info|
match do |actual|
def normalize(graph)
case graph
when RDF::Enumerable then graph
when IO, StringIO
RDF::Repository.new(graph, base_uri: @info.action)
else
# Figure out which parser to use
r = RDF::Repository.new
reader_class = RDF::Reader.for() {graph}
reader_class.new(graph, base_uri: @info.action).each {|s| r << s}
r
end
end

@info = if (info.id rescue false)
info
elsif info.is_a?(Logger)
Expand Down Expand Up @@ -314,6 +300,33 @@ def normalize(graph)
"Results:\n#{@actual.dump(format, standard_prefixes: true, literal_shorthand: false, validate: false) rescue @actual.inspect}" +
"\nDebug:\n#{@info.logger}"
end

failure_message_when_negated do |actual|
format = case
when RDF.const_defined?(:TriG) then :trig
when RDF.const_defined?(:Turtle) then :ttl
else :nquads
end
info = @info.respond_to?(:information) ? @info.information : @info.inspect
"Graphs identical\n" +
"\n#{info + "\n" unless info.empty?}" +
"Results:\n#{actual.dump(format, standard_prefixes: true, literal_shorthand: false, validate: false) rescue @actual.inspect}" +
"\nDebug:\n#{@info.logger}"
end

def normalize(graph)
case graph
when RDF::Enumerable then graph
when IO, StringIO
RDF::Repository.new(graph, base_uri: @info.action)
else
# Figure out which parser to use
r = RDF::Repository.new
reader_class = RDF::Reader.for() {graph}
reader_class.new(graph, base_uri: @info.action).each {|s| r << s}
r
end
end
end

require 'json'
Expand Down Expand Up @@ -347,6 +360,15 @@ def normalize(graph)
"\n#{info + "\n" unless info.empty?}" +
"\nDebug:\n#{@info.logger}"
end

failure_message_when_negated do |actual|
info = @info.respond_to?(:information) ? @info.information : @info.inspect

"Expected not to produce the following:\n" +
"Actual : #{actual.is_a?(String) ? actual : actual.to_json(JSON_STATE) rescue 'malformed json'}\n" +
"\n#{info + "\n" unless info.empty?}" +
"\nDebug:\n#{@info.logger}"
end
end

end # Matchers
Expand Down
131 changes: 91 additions & 40 deletions lib/rdf/spec/reader.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
require 'rdf/spec'
require 'webmock/rspec'

RSpec.shared_examples 'an RDF::Reader' do
include RDF::Spec::Matchers
Expand All @@ -9,8 +10,11 @@
raise 'reader_count must be defined with let(:reader_count)' unless defined? reader_count
# define reader_invalid_input for invalid input
end
before(:each) {WebMock.disable_net_connect!}
after(:each) {WebMock.allow_net_connect!}

let(:reader_class) { reader.class }
let(:format_class) { reader_class.format }

describe ".each" do
it "yields each reader" do
Expand All @@ -21,70 +25,117 @@
end

describe ".open" do
before(:each) do
allow(RDF::Util::File).to receive(:open_file).and_yield(StringIO.new(reader_input))
end

it "yields reader given file_name" do
reader_class.format.each do |f|
f.file_extensions.each_pair do |sym, content_type|
reader_mock = double("reader")
expect(reader_mock).to receive(:got_here)
expect(reader_class).to receive(:for).with(file_name: "foo.#{sym}").and_return(reader_class)
reader_class.open("foo.#{sym}") do |r|
expect(r).to be_a(RDF::Reader)
reader_mock.got_here
end
allow(RDF::Util::File).to receive(:open_file).and_yield(StringIO.new(reader_input))
format_class.file_extensions.each_pair do |sym, content_type|
reader_mock = double("reader")
expect(reader_mock).to receive(:got_here)
expect(RDF::Reader).to receive(:for).with(file_name: "foo.#{sym}").and_return(reader_class)
RDF::Reader.open("foo.#{sym}") do |r|
expect(r).to be_a(reader_class)
reader_mock.got_here
end
end
end

it "yields reader given symbol" do
reader_class.format.each do |f|
sym = f.to_sym # Like RDF::NTriples::Format => :ntriples
allow(RDF::Util::File).to receive(:open_file).and_yield(StringIO.new(reader_input))
sym = format_class.to_sym # Like RDF::NTriples::Format => :ntriples
reader_mock = double("reader")
expect(reader_mock).to receive(:got_here)
expect(RDF::Reader).to receive(:for).with(sym).and_return(reader_class)
RDF::Reader.open("foo.#{sym}", format: sym) do |r|
expect(r).to be_a(reader_class)
reader_mock.got_here
end
end

it "yields reader given {file_name: file_name}" do
allow(RDF::Util::File).to receive(:open_file).and_yield(StringIO.new(reader_input))
format_class.file_extensions.each_pair do |sym, content_type|
reader_mock = double("reader")
expect(reader_mock).to receive(:got_here)
expect(reader_class).to receive(:for).with(sym).and_return(reader_class)
reader_class.open("foo.#{sym}", format: sym) do |r|
expect(r).to be_a(RDF::Reader)
expect(RDF::Reader).to receive(:for).with(file_name: "foo.#{sym}").and_return(reader_class)
RDF::Reader.open("foo.#{sym}", file_name: "foo.#{sym}") do |r|
expect(r).to be_a(reader_class)
reader_mock.got_here
end
end
end

it "yields reader given {file_name: file_name}" do
reader_class.format.each do |f|
f.file_extensions.each_pair do |sym, content_type|
reader_mock = double("reader")
expect(reader_mock).to receive(:got_here)
expect(reader_class).to receive(:for).with(file_name: "foo.#{sym}").and_return(reader_class)
reader_class.open("foo.#{sym}", file_name: "foo.#{sym}") do |r|
expect(r).to be_a(RDF::Reader)
reader_mock.got_here
end
it "yields reader given {content_type: 'a/b'}" do
allow(RDF::Util::File).to receive(:open_file).and_yield(StringIO.new(reader_input))
format_class.content_types.each_pair do |content_type, formats|
reader_mock = double("reader")
expect(reader_mock).to receive(:got_here)
expect(RDF::Reader).to receive(:for).with(content_type: content_type, file_name: "foo").and_return(reader_class)
RDF::Reader.open("foo", content_type: content_type) do |r|
expect(r).to be_a(reader_class)
reader_mock.got_here
end
end
end

it "yields reader given {content_type: 'a/b'}" do
reader_class.format.each do |f|
f.content_types.each_pair do |content_type, formats|
reader_mock = double("reader")
expect(reader_mock).to receive(:got_here)
expect(reader_class).to receive(:for).with(content_type: content_type, file_name: "foo").and_return(reader_class)
reader_class.open("foo", content_type: content_type) do |r|
expect(r).to be_a(RDF::Reader)
reader_mock.got_here
end
it "yields reader when returned content_type matches" do
format_class.content_types.each_pair do |content_type, formats|
uri = "http://example/foo"
reader_mock = double("reader")
expect(reader_mock).to receive(:got_here)
expect(RDF::Reader).to receive(:for).and_return(reader_class)

WebMock.stub_request(:get, uri).
to_return(body: "BODY",
status: 200,
headers: { 'Content-Type' => content_type})

RDF::Reader.open(uri) do |r|
expect(r).to be_a(reader_class)
reader_mock.got_here
end
end
end

it "sets Accept header from reader" do
uri = "http://example/foo"
accept = (format_class.accept_type + %w(*/*;q=0.1)).join(", ")
reader_mock = double("reader")
expect(reader_mock).to receive(:got_here)
WebMock.stub_request(:get, uri).with do |request|
expect(request.headers['Accept']).to eql accept
end.to_return(body: "foo")

reader_class.open(uri) do |r|
expect(r).to be_a(reader_class)
reader_mock.got_here
end
end

it "sets Accept header from symbol" do
uri = "http://example/foo"
sym = format_class.to_sym # Like RDF::NTriples::Format => :ntriples
accept = (format_class.accept_type + %w(*/*;q=0.1)).join(", ")
reader_mock = double("reader")
expect(reader_mock).to receive(:got_here)
WebMock.stub_request(:get, uri).with do |request|
expect(request.headers['Accept']).to eql accept
end.to_return(body: "foo")
expect(RDF::Reader).to receive(:for).with(sym).and_return(reader_class)

RDF::Reader.open(uri, format: sym) do |r|
expect(r).to be_a(reader_class)
reader_mock.got_here
end
end
end

describe ".format" do
it "returns itself even if given explicit format" do
it "returns a format class if given no format" do
expect(reader_class.format).not_to be_nil
end

it "returns nil if given a format" do
other_format = reader_class == RDF::NTriples::Reader ? :nquads : :ntriples
expect(reader_class.for(other_format)).to eq reader_class
expect(reader_class.format(other_format)).to be_nil
end
end

Expand Down
Loading

0 comments on commit 59eae01

Please sign in to comment.