Skip to content

Commit

Permalink
Finish 3.1.0
Browse files Browse the repository at this point in the history
  • Loading branch information
gkellogg committed Dec 16, 2019
2 parents 59eae01 + 84a9cbe commit 4726bb4
Show file tree
Hide file tree
Showing 16 changed files with 165 additions and 169 deletions.
13 changes: 5 additions & 8 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,20 +1,17 @@
language: ruby
bundler_args: --without debug
script: "bundle exec rspec spec"
before_install: "gem update --system"
env:
- CI=true
rvm:
- 2.2
- 2.3
- 2.4
- 2.5
- jruby-9
- rbx-3
- 2.6
- 2.7
- jruby
cache: bundler
sudo: false
matrix:
allow_failures:
- rvm: jruby-9
- rvm: rbx-3
- rvm: jruby
- rvm: 2.7
dist: trusty
4 changes: 2 additions & 2 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,6 @@ group :debug do
end

group :development, :test do
gem 'simplecov', require: false, platform: :mri
gem 'coveralls', require: false, platform: :mri
gem 'simplecov', platforms: :mri
gem 'coveralls', '~> 0.8', platforms: :mri
end
2 changes: 1 addition & 1 deletion VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
3.0.0
3.1.0
51 changes: 25 additions & 26 deletions lib/rdf/spec/enumerable.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,25 +7,24 @@
raise 'enumerable must be set with `let(:enumerable)' unless
defined? enumerable

@statements ||= RDF::Spec.quads
@rdf_enumerable_iv_statements ||= RDF::Spec.quads

if enumerable.empty?
if (enumerable.writable? rescue false)
enumerable.insert(*@statements)
enumerable.insert(*@rdf_enumerable_iv_statements)
elsif enumerable.respond_to?(:<<)
@statements.each { |statement| enumerable << statement }
@rdf_enumerable_iv_statements.each { |statement| enumerable << statement }
else
raise "@enumerable must respond to #<< or be pre-populated with the statements in #{RDF::Spec::TRIPLES_FILE} in a before(:each) block"
end
end

@supports_named_graphs = enumerable.supports?(:graph_name) rescue true
end

let(:subject_count) {@statements.map(&:subject).uniq.length}
let(:bnode_subject_count) {@statements.map(&:subject).uniq.select(&:node?).length}
let(:non_bnode_statements) {@statements.reject(&:node?)}
let(:non_bnode_terms) {@statements.map(&:to_quad).flatten.compact.reject(&:node?).uniq}
let(:supports_named_graphs) {enumerable.supports?(:graph_name) rescue true}
let(:subject_count) {@rdf_enumerable_iv_statements.map(&:subject).uniq.length}
let(:bnode_subject_count) {@rdf_enumerable_iv_statements.map(&:subject).uniq.select(&:node?).length}
let(:non_bnode_statements) {@rdf_enumerable_iv_statements.reject(&:node?)}
let(:non_bnode_terms) {@rdf_enumerable_iv_statements.map(&:to_quad).flatten.compact.reject(&:node?).uniq}

subject { enumerable }
it {is_expected.to respond_to(:supports?)}
Expand Down Expand Up @@ -57,9 +56,9 @@
it {is_expected.to respond_to(:empty?)}
it {is_expected.to_not be_empty}
it {is_expected.to respond_to(:count)}
its(:count) {is_expected.to eq @statements.size}
its(:count) {is_expected.to eq @rdf_enumerable_iv_statements.size}
it {is_expected.to respond_to(:size)}
its(:size) {is_expected.to eq @statements.size}
its(:size) {is_expected.to eq @rdf_enumerable_iv_statements.size}

context "and empty" do
subject {[].extend(RDF::Enumerable)}
Expand All @@ -74,7 +73,7 @@
its(:statements) {is_expected.to be_a(Array)}

context "#statements" do
specify {expect(subject.statements.size).to eq @statements.size}
specify {expect(subject.statements.size).to eq @rdf_enumerable_iv_statements.size}
specify {expect(subject.statements).to all(be_a_statement)}
end

Expand All @@ -89,7 +88,7 @@
end

it "does not have statement in different named graph" do
if @supports_named_graphs
if supports_named_graphs
graph_name = RDF::URI.new("urn:graph_name:1")
non_bnode_statements.each do |statement|
s = statement.dup
Expand Down Expand Up @@ -132,7 +131,7 @@

its(:triples) {is_expected.to be_a(Array)}
context "#triples" do
specify {expect(subject.triples.size).to eq @statements.size}
specify {expect(subject.triples.size).to eq @rdf_enumerable_iv_statements.size}
specify {expect(subject.triples).to all(be_a_triple)}
end

Expand Down Expand Up @@ -176,13 +175,13 @@

its(:quads) {is_expected.to be_a(Array)}
context "#quads" do
specify {expect(subject.quads.size).to eq @statements.size}
specify {expect(subject.quads.size).to eq @rdf_enumerable_iv_statements.size}
specify {expect(subject.quads).to all(be_a_quad)}
end

context "#has_quad?" do
specify do
if @supports_named_graphs
if supports_named_graphs
non_bnode_statements.each do |statement|
is_expected.to have_quad(statement.to_quad)
end
Expand Down Expand Up @@ -265,7 +264,7 @@
end

context "when enumerating predicates" do
let(:predicates) {@statements.map { |s| s.predicate }.uniq}
let(:predicates) {@rdf_enumerable_iv_statements.map { |s| s.predicate }.uniq}
it {is_expected.to respond_to(:predicates)}
it {is_expected.to respond_to(:has_predicate?)}
it {is_expected.to respond_to(:each_predicate)}
Expand All @@ -285,7 +284,7 @@
context "#has_predicate?" do
specify do
checked = []
@statements.each do |statement|
@rdf_enumerable_iv_statements.each do |statement|
expect(enumerable).to have_predicate(statement.predicate) unless checked.include?(statement.predicate)
checked << statement.predicate
end
Expand Down Expand Up @@ -434,8 +433,8 @@
end

it "should implement #has_graph?" do
if @supports_named_graphs
@statements.each do |statement|
if supports_named_graphs
@rdf_enumerable_iv_statements.each do |statement|
if statement.has_graph?
expect(enumerable).to have_graph(statement.graph_name)
end
Expand Down Expand Up @@ -480,21 +479,21 @@

context "non-existing graph" do
let(:graph_name) {RDF::URI.new('http://example.org/does/not/have/this/uri')}
specify {expect(subject.project_graph(graph_name)).to be_empty if @supports_named_graphs}
specify {expect(subject.project_graph(graph_name)).to be_empty if supports_named_graphs}
end
end

its(:each_graph) {is_expected.to be_an_enumerator}

describe "#each_graph" do
let(:graph_names) {@statements.map { |s| s.graph_name }.uniq.compact}
let(:graph_names) {@rdf_enumerable_iv_statements.map { |s| s.graph_name }.uniq.compact}
subject { enumerable.each_graph }
it {is_expected.to be_an_enumerator}
specify {is_expected.to all(be_a_graph) if @supports_named_graphs}
specify {is_expected.to all(be_a_graph) if supports_named_graphs}

it "has appropriate number of graphs" do
if @supports_named_graphs
graph_names = @statements.map { |s| s.graph_name }.uniq.compact
if supports_named_graphs
graph_names = @rdf_enumerable_iv_statements.map { |s| s.graph_name }.uniq.compact
expect(subject.to_a.size).to eq (graph_names.size + 1)
end
end
Expand All @@ -505,7 +504,7 @@
it {is_expected.to be_an_enumerator}
it {is_expected.to be_countable}
it "enumerates the same as #each_graph" do
expect(subject.to_a).to include(*enumerable.each_graph.to_a) if @supports_named_graphs # expect with match problematic
expect(subject.to_a).to include(*enumerable.each_graph.to_a) if supports_named_graphs # expect with match problematic
end
end
end
Expand Down
18 changes: 18 additions & 0 deletions lib/rdf/spec/http_adapter.rb
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,24 @@
end
end

it "adds User-Agent header using default" do
WebMock.stub_request(:get, uri).with do |request|
expect(request.headers['User-Agent']).to eq "Ruby RDF.rb/#{RDF::VERSION}"
end.to_return(body: "foo")
RDF::Util::File.open_file(uri) do |f|
opened.opened
end
end

it "used provided User-Agent header" do
WebMock.stub_request(:get, uri).with do |request|
expect(request.headers["User-Agent"]).to eq "Foo"
end.to_return(body: "foo")
RDF::Util::File.open_file(uri, headers: {"User-Agent" => "Foo"}) do |f|
opened.opened
end
end

it "sets content_type and encoding to utf-8 if absent" do
WebMock.stub_request(:get, uri).to_return(body: "foo", headers: {"Content-Type" => "text/turtle"})
RDF::Util::File.open_file(uri) do |f|
Expand Down
32 changes: 0 additions & 32 deletions lib/rdf/spec/inspects.rb
Original file line number Diff line number Diff line change
Expand Up @@ -31,38 +31,6 @@ def inspect
end
end

class Array
alias_method :inspect_without_formatting, :inspect
def inspect_with_formatting
if all? { |item| item.is_a?(Hash) }
string = "[\n"
each do |item|
string += " {\n"
item.keys.sort_by(&:to_s).each do |key|
string += " #{key.inspect}: #{item[key].inspect}\n"
end
string += " },\n"
end
string += "]"
string
elsif all? { |item| item.is_a?(RDF::Query::Solution)}
string = "[\n"
each do |item|
string += " {\n"
item.bindings.keys.sort_by(&:to_s).each do |key|
string += " #{key.inspect}: #{item.bindings[key].inspect}\n"
end
string += " },\n"
end
string += "]"
string
else
inspect_without_formatting
end
end
alias_method :inspect, :inspect_with_formatting
end

class RDF::Query::Solutions
def inspect
string = "vars: #{variable_names.join(",")}\n#{to_a.inspect}"
Expand Down
44 changes: 18 additions & 26 deletions lib/rdf/spec/matchers.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
require 'rspec/matchers' # @see http://rubygems.org/gems/rspec
require 'awesome_print'

module RDF; module Spec
##
Expand Down Expand Up @@ -187,17 +188,17 @@ module Matchers
RSpec::Matchers.define :write_each do |*messages|
supports_block_expectations { true }

match do |block|
match(notify_expectation_failures: true) do |block|
messages.each { |message| expect(&block).to write(message) }
end
end

RSpec::Matchers.define :write do |message|
chain(:to) { |io| @io = io }
chain(:to) { |io| @rdf_matcher_iv_io = io }

supports_block_expectations { true }

match do |block|
match(notify_expectation_failures: true) do |block|
@output =
case io
when :output then fake_stdout(&block)
Expand Down Expand Up @@ -256,7 +257,7 @@ def fake_stdout

# default IO is standard output
def io
@io ||= :output
@rdf_matcher_iv_io ||= :output
end

# IO name is used for description message
Expand All @@ -265,7 +266,7 @@ def io_name
end
end

Info = Struct.new(:id, :logger, :action, :result)
Info = Struct.new(:id, :logger, :action, :result, :format)

RSpec::Matchers.define :be_equivalent_graph do |expected, info|
match do |actual|
Expand All @@ -274,30 +275,30 @@ def io_name
elsif info.is_a?(Logger)
Info.new("", info)
elsif info.is_a?(Hash)
Info.new(info[:id], info[:logger], info[:action], info[:result])
Info.new(info[:id], info[:logger], info[:action], info[:result], info[:format])
else
Info.new(info)
end
@info.format ||= case
when RDF.const_defined?(:TriG) then :trig
when RDF.const_defined?(:Turtle) then :ttl
else :nquads
end
@expected = normalize(expected)
@actual = normalize(actual)
@actual.isomorphic_with?(@expected) rescue false
end

failure_message 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
if @expected.is_a?(RDF::Enumerable) && @actual.size != @expected.size
"Graph entry counts differ:\nexpected: #{@expected.size}\nactual: #{@actual.size}\n"
else
"Graphs differ\n"
end +
"\n#{info + "\n" unless info.empty?}" +
"Expected:\n#{@expected.dump(format, standard_prefixes: true, literal_shorthand: false, validate: false) rescue @expected.inspect}" +
"Results:\n#{@actual.dump(format, standard_prefixes: true, literal_shorthand: false, validate: false) rescue @actual.inspect}" +
"Expected:\n#{@expected.dump(@info.format, standard_prefixes: true, literal_shorthand: false, validate: false) rescue @expected.inspect}" +
"Results:\n#{@actual.dump(@info.format, standard_prefixes: true, literal_shorthand: false, validate: false) rescue @actual.inspect}" +
"\nDebug:\n#{@info.logger}"
end

Expand All @@ -310,7 +311,7 @@ def io_name
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}" +
"Results:\n#{actual.dump(@info.format, standard_prefixes: true, literal_shorthand: false, validate: false) rescue @actual.inspect}" +
"\nDebug:\n#{@info.logger}"
end

Expand All @@ -329,15 +330,6 @@ def normalize(graph)
end
end

require 'json'
JSON_STATE = ::JSON::State.new(
indent: " ",
space: " ",
space_before: "",
object_nl: "\n",
array_nl: "\n"
)

RSpec::Matchers.define :produce do |expected, info|
match do |actual|
@info = if (info.id rescue false)
Expand All @@ -355,8 +347,8 @@ def normalize(graph)
failure_message do |actual|
info = @info.respond_to?(:information) ? @info.information : @info.inspect

"Expected: #{expected.is_a?(String) ? expected : expected.to_json(JSON_STATE) rescue 'malformed json'}\n" +
"Actual : #{actual.is_a?(String) ? actual : actual.to_json(JSON_STATE) rescue 'malformed json'}\n" +
"Expected: #{expected.ai}\n" +
"Actual : #{actual.ai}\n" +
"\n#{info + "\n" unless info.empty?}" +
"\nDebug:\n#{@info.logger}"
end
Expand All @@ -365,7 +357,7 @@ def normalize(graph)
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" +
"Actual : #{actual.ai}\n" +
"\n#{info + "\n" unless info.empty?}" +
"\nDebug:\n#{@info.logger}"
end
Expand Down
Loading

0 comments on commit 4726bb4

Please sign in to comment.