From a556d3345aacec5aca1f75e53dbdf6e66a28d279 Mon Sep 17 00:00:00 2001 From: Gregg Kellogg Date: Sat, 7 Nov 2015 13:22:40 -0800 Subject: [PATCH 1/3] Add specs from RDF.rb which invoke rdf-spec behaviors. --- spec/countable_spec.rb | 11 ++++++ spec/durable_spec.rb | 12 +++++++ spec/enumerable_spec.rb | 11 ++++++ spec/format_spec.rb | 12 +++++++ spec/http_adapter_spec.rb | 12 +++++++ spec/indexable.rb | 15 ++++++++ spec/inferable_spec.rb | 7 ++++ spec/literal_spec.rb | 75 +++++++++++++++++++++++++++++++++++++++ spec/mutable_spec.rb | 11 ++++++ spec/queryable_spec.rb | 13 +++++++ spec/readable.rb | 11 ++++++ spec/reader_spec.rb | 17 +++++++++ spec/transaction_spec.rb | 7 ++++ spec/writable_spec.rb | 13 +++++++ spec/writer_spec.rb | 11 ++++++ 15 files changed, 238 insertions(+) create mode 100644 spec/countable_spec.rb create mode 100644 spec/durable_spec.rb create mode 100644 spec/enumerable_spec.rb create mode 100644 spec/format_spec.rb create mode 100644 spec/http_adapter_spec.rb create mode 100644 spec/indexable.rb create mode 100644 spec/inferable_spec.rb create mode 100644 spec/literal_spec.rb create mode 100644 spec/mutable_spec.rb create mode 100644 spec/queryable_spec.rb create mode 100644 spec/readable.rb create mode 100644 spec/reader_spec.rb create mode 100644 spec/transaction_spec.rb create mode 100644 spec/writable_spec.rb create mode 100644 spec/writer_spec.rb diff --git a/spec/countable_spec.rb b/spec/countable_spec.rb new file mode 100644 index 0000000..c5ddc8b --- /dev/null +++ b/spec/countable_spec.rb @@ -0,0 +1,11 @@ +require File.join(File.dirname(__FILE__), 'spec_helper') +require 'rdf/spec/countable' + +describe RDF::Countable do + # @see lib/rdf/spec/countable.rb in rdf-spec + it_behaves_like 'an RDF::Countable' do + # The available reference implementations are `RDF::Repository` and + # `RDF::Graph`, but a plain Ruby array will do fine as well: + let(:countable) { RDF::Spec.quads.extend(described_class) } + end +end diff --git a/spec/durable_spec.rb b/spec/durable_spec.rb new file mode 100644 index 0000000..e3fddcc --- /dev/null +++ b/spec/durable_spec.rb @@ -0,0 +1,12 @@ +require File.join(File.dirname(__FILE__), 'spec_helper') +require 'rdf/spec/durable' + +describe RDF::Durable do + # The available reference implementations are `RDF::Repository` and + # `RDF::Graph`, but a plain Ruby array will do fine as well + # FIXME + before { @load_durable = lambda { RDF::Repository.new } } + + # @see lib/rdf/spec/countable.rb in rdf-spec + it_behaves_like 'an RDF::Durable' +end diff --git a/spec/enumerable_spec.rb b/spec/enumerable_spec.rb new file mode 100644 index 0000000..6ae5bd9 --- /dev/null +++ b/spec/enumerable_spec.rb @@ -0,0 +1,11 @@ +require File.join(File.dirname(__FILE__), 'spec_helper') +require 'rdf/spec/enumerable' + +describe RDF::Enumerable do + # @see lib/rdf/spec/enumerable.rb in rdf-spec + it_behaves_like 'an RDF::Enumerable' do + # The available reference implementations are `RDF::Repository` and + # `RDF::Graph`, but a plain Ruby array will do fine as well: + let(:enumerable) { RDF::Spec.quads.extend(described_class) } + end +end diff --git a/spec/format_spec.rb b/spec/format_spec.rb new file mode 100644 index 0000000..1809906 --- /dev/null +++ b/spec/format_spec.rb @@ -0,0 +1,12 @@ +require File.join(File.dirname(__FILE__), 'spec_helper') +require 'rdf/spec/format' +require 'rdf/ntriples' +require 'rdf/nquads' + +describe RDF::Format do + + # @see lib/rdf/spec/format.rb in rdf-spec + it_behaves_like 'an RDF::Format' do + let(:format_class) { described_class } + end +end diff --git a/spec/http_adapter_spec.rb b/spec/http_adapter_spec.rb new file mode 100644 index 0000000..445a3d6 --- /dev/null +++ b/spec/http_adapter_spec.rb @@ -0,0 +1,12 @@ +require File.join(File.dirname(__FILE__), 'spec_helper') +require 'webmock/rspec' +require 'rdf/ntriples' +require 'rdf/spec/http_adapter' + +context "HTTP Adapters" do + context "using Net::HTTP" do + it_behaves_like 'an RDF::HttpAdapter' do + let(:http_adapter) { RDF::Util::File::NetHttpAdapter } + end + end +end diff --git a/spec/indexable.rb b/spec/indexable.rb new file mode 100644 index 0000000..9f62aa6 --- /dev/null +++ b/spec/indexable.rb @@ -0,0 +1,15 @@ +require File.join(File.dirname(__FILE__), 'spec_helper') +require 'rdf/spec/indexable' + +describe RDF::Indexable do + # @see lib/rdf/spec/indexable.rb in rdf-spec + it_behaves_like 'an RDF::Indexable' do + # The available reference implementations are `RDF::Repository` and + # `RDF::Graph`, but a double will do fine as well: + let(:indexable) do + d = double("Indexable").extend(RDF::Indexable) + allow(d).to receive(:index!) {d} + d + end + end +end diff --git a/spec/inferable_spec.rb b/spec/inferable_spec.rb new file mode 100644 index 0000000..59fd777 --- /dev/null +++ b/spec/inferable_spec.rb @@ -0,0 +1,7 @@ +require File.join(File.dirname(__FILE__), 'spec_helper') +require 'rdf/spec/inferable' + +describe RDF::Inferable do + # @see lib/rdf/spec/enumerable.rb in rdf-spec + it_behaves_like 'an RDF::Inferable' +end diff --git a/spec/literal_spec.rb b/spec/literal_spec.rb new file mode 100644 index 0000000..ae68552 --- /dev/null +++ b/spec/literal_spec.rb @@ -0,0 +1,75 @@ +require File.join(File.dirname(__FILE__), 'spec_helper') +require 'rdf/spec/literal' + +describe RDF::Literal do + describe RDF::Literal::Boolean do + it_behaves_like 'RDF::Literal with datatype and grammar', "true", RDF::XSD.boolean + it_behaves_like 'RDF::Literal equality', "true", true + it_behaves_like 'RDF::Literal lexical values', "true" + it_behaves_like 'RDF::Literal canonicalization', RDF::XSD.boolean, [ + %w(true true), + %w(false false), + %w(tRuE true), + %w(FaLsE false), + %w(1 true), + %w(0 false) + ] + it_behaves_like 'RDF::Literal validation', RDF::XSD.boolean, + %w(true false tRuE FaLsE 1 0), + %w(foo 10) + end + + describe RDF::Literal::Integer do + it_behaves_like 'RDF::Literal with datatype and grammar', "1", RDF::XSD.integer + it_behaves_like 'RDF::Literal equality', "1", 1 + it_behaves_like 'RDF::Literal lexical values', "1" + it_behaves_like 'RDF::Literal canonicalization', RDF::XSD.integer, [ + %w(01 1), + %w(1 1), + %w(-1 -1), + %w(+1 1) + ] + it_behaves_like 'RDF::Literal validation', RDF::XSD.integer, + %w(1 10 100 01 +1 -1), + %w(foo 10.1 12xyz) + end + + describe RDF::Literal::DateTime do + it_behaves_like 'RDF::Literal with datatype and grammar', "2010-01-01T00:00:00Z", RDF::XSD.dateTime + it_behaves_like 'RDF::Literal equality', "2010-01-01T00:00:00Z", DateTime.parse("2010-01-01T00:00:00Z") + it_behaves_like 'RDF::Literal lexical values', "2010-01-01T00:00:00Z" + it_behaves_like 'RDF::Literal canonicalization', RDF::XSD.dateTime, [ + ["2010-01-01T00:00:00Z", "2010-01-01T00:00:00Z", "12:00:00 AM UTC on Friday, 01 January 2010"], + ["2010-01-01T00:00:00.0000Z", "2010-01-01T00:00:00Z", "12:00:00 AM UTC on Friday, 01 January 2010"], + ["2010-01-01T00:00:00", "2010-01-01T00:00:00", "12:00:00 AM on Friday, 01 January 2010"], + ["2010-01-01T00:00:00+00:00", "2010-01-01T00:00:00Z", "12:00:00 AM UTC on Friday, 01 January 2010"], + ["2010-01-01T01:00:00+01:00", "2010-01-01T00:00:00Z", "01:00:00 AM +01:00 on Friday, 01 January 2010"], + ["2009-12-31T23:00:00-01:00", "2010-01-01T00:00:00Z", "11:00:00 PM -01:00 on Thursday, 31 December 2009"], + ["-2010-01-01T00:00:00Z", "-2010-01-01T00:00:00Z","12:00:00 AM UTC on Friday, 01 January -2010"], + #["2014-09-01T12:13:14.567", "2014-09-01T12:13:14", "12:13:14 PM on Monday, 01 September 2014"], + #["2014-09-01T12:13:14.567Z", "2014-09-01T12:13:14Z", "12:13:14 PM UTC on Monday, 01 September 2014"], + #["2014-09-01T12:13:14.567-08:00","2014-09-01T20:13:14Z","12:13:14 PM -08:00 on Monday, 01 September 2014"], + ] + it_behaves_like 'RDF::Literal validation', RDF::XSD.dateTime, + %w( + 2010-01-01T00:00:00Z + 2010-01-01T00:00:00.0000Z + 2010-01-01T00:00:00 + 2010-01-01T00:00:00+00:00 + 2010-01-01T01:00:00+01:00 + 2009-12-31T23:00:00-01:00 + -2010-01-01T00:00:00Z + ), + %w( + foo + +2010-01-01T00:00:00Z + 2010-01-01T00:00:00FOO + 02010-01-01T00:00:00 + 2010-01-01 + 2010-1-1T00:00:00 + 0000-01-01T00:00:00 + 2010-07 + 2010 + ) + end +end diff --git a/spec/mutable_spec.rb b/spec/mutable_spec.rb new file mode 100644 index 0000000..b03bff5 --- /dev/null +++ b/spec/mutable_spec.rb @@ -0,0 +1,11 @@ +require File.join(File.dirname(__FILE__), 'spec_helper') +require 'rdf/spec/mutable' + +describe RDF::Mutable do + # @see lib/rdf/spec/mutable.rb in rdf-spec + it_behaves_like 'an RDF::Mutable' do + # The available reference implementations are `RDF::Repository` and + # `RDF::Graph` + let(:mutable) { RDF::Repository.new } + end +end diff --git a/spec/queryable_spec.rb b/spec/queryable_spec.rb new file mode 100644 index 0000000..ec1dd05 --- /dev/null +++ b/spec/queryable_spec.rb @@ -0,0 +1,13 @@ +require File.join(File.dirname(__FILE__), 'spec_helper') +require 'rdf/spec/queryable' + +describe RDF::Queryable do + # @see lib/rdf/spec/queryable.rb in rdf-spec + it_behaves_like 'an RDF::Queryable' do + # The available reference implementations are `RDF::Repository` and + # `RDF::Graph`, but a subclass of Ruby Array implementing + # `query_pattern` and `query_execute` should do as well + # FIXME + let(:queryable) { RDF::Repository.new } + end +end diff --git a/spec/readable.rb b/spec/readable.rb new file mode 100644 index 0000000..eb63521 --- /dev/null +++ b/spec/readable.rb @@ -0,0 +1,11 @@ +require File.join(File.dirname(__FILE__), 'spec_helper') +require 'rdf/spec/readable' + +describe RDF::Readable do + # @see lib/rdf/spec/readable.rb in rdf-spec + it_behaves_like 'an RDF::Readable' do + # The available reference implementations are `RDF::Repository` and + # `RDF::Graph`, but a plain Ruby array will do fine as well: + let(:readable) { double("Readable").extend(RDF::Readable) } + end +end diff --git a/spec/reader_spec.rb b/spec/reader_spec.rb new file mode 100644 index 0000000..417b6ae --- /dev/null +++ b/spec/reader_spec.rb @@ -0,0 +1,17 @@ +# -*- encoding: utf-8 -*- +require File.join(File.dirname(__FILE__), 'spec_helper') +require 'rdf/ntriples' +require 'rdf/spec/reader' + +describe RDF::NTriples::Reader do + let!(:doap) {File.expand_path("../../etc/doap.nt", __FILE__)} + let!(:doap_count) {File.open(doap).each_line.to_a.length} + subject { RDF::NTriples::Reader.new } + + # @see lib/rdf/spec/reader.rb in rdf-spec + it_behaves_like 'an RDF::Reader' do + let(:reader) { RDF::NTriples::Reader.new } + let(:reader_input) { File.read(doap) } + let(:reader_count) { doap_count } + end +end diff --git a/spec/transaction_spec.rb b/spec/transaction_spec.rb new file mode 100644 index 0000000..770cff8 --- /dev/null +++ b/spec/transaction_spec.rb @@ -0,0 +1,7 @@ +require File.join(File.dirname(__FILE__), 'spec_helper') +require 'rdf/spec/transaction' + +describe RDF::Transaction, skip: "pending fixes to immutability errors" do + # @see lib/rdf/spec/transaction.rb in rdf-spec + it_behaves_like "an RDF::Transaction", RDF::Transaction +end diff --git a/spec/writable_spec.rb b/spec/writable_spec.rb new file mode 100644 index 0000000..3dd099d --- /dev/null +++ b/spec/writable_spec.rb @@ -0,0 +1,13 @@ +require File.join(File.dirname(__FILE__), 'spec_helper') +require 'rdf/spec/writable' + +describe RDF::Writable do + subject {RDF::Repository.new} + + # @see lib/rdf/spec/writable.rb in rdf-spec + it_behaves_like 'an RDF::Writable' do + # The available reference implementations are `RDF::Repository` and + # `RDF::Graph`, but a plain Ruby array will do fine as well: + let(:writable) { RDF::Repository.new } + end +end diff --git a/spec/writer_spec.rb b/spec/writer_spec.rb new file mode 100644 index 0000000..93f4c0d --- /dev/null +++ b/spec/writer_spec.rb @@ -0,0 +1,11 @@ +# -*- encoding: utf-8 -*- +require File.join(File.dirname(__FILE__), 'spec_helper') +require 'rdf/ntriples' +require 'rdf/spec/writer' + +describe RDF::NTriples::Writer do + # @see lib/rdf/spec/writer.rb in rdf-spec + it_behaves_like 'an RDF::Writer' do + let(:writer) { RDF::NTriples::Writer.new } + end +end From 6a4100671003a5c16f1e6f46562e05e14e4cdaa3 Mon Sep 17 00:00:00 2001 From: Gregg Kellogg Date: Sat, 7 Nov 2015 13:26:05 -0800 Subject: [PATCH 2/3] Add Tavis configuration. --- .travis.yml | 13 +++++++++++++ 1 file changed, 13 insertions(+) create mode 100644 .travis.yml diff --git a/.travis.yml b/.travis.yml new file mode 100644 index 0000000..128476d --- /dev/null +++ b/.travis.yml @@ -0,0 +1,13 @@ +language: ruby +bundler_args: --without debug +script: "bundle exec rspec spec" +env: + - CI=true +rvm: + - 2.0 + - 2.1 + - 2.2 + - jruby + - rbx-2 +cache: bundler +sudo: false From cca6356ea4a21a1ab8e8f74066d30d9392ca81bf Mon Sep 17 00:00:00 2001 From: Gregg Kellogg Date: Sat, 7 Nov 2015 13:32:49 -0800 Subject: [PATCH 3/3] Add coveralls code coverage. --- .gitignore | 1 + Gemfile | 5 +++++ README.md | 2 ++ spec/spec_helper.rb | 9 +++++++++ 4 files changed, 17 insertions(+) diff --git a/.gitignore b/.gitignore index e9245a9..ce0296e 100644 --- a/.gitignore +++ b/.gitignore @@ -6,3 +6,4 @@ tmp /*.gem /*.lock /doc/ +/coverage/ diff --git a/Gemfile b/Gemfile index bb0cd9f..f3118b0 100644 --- a/Gemfile +++ b/Gemfile @@ -7,3 +7,8 @@ gem "rdf", git: "git://github.com/ruby-rdf/rdf.git", branch: "develop" group :development do gem "wirble" end + +group :development, :test do + gem 'simplecov', require: false + gem 'coveralls', require: false +end \ No newline at end of file diff --git a/README.md b/README.md index f77fee9..b7587fc 100644 --- a/README.md +++ b/README.md @@ -6,6 +6,8 @@ and shared examples for Ruby projects that use RDF.rb and RSpec. * [![Gem Version](https://badge.fury.io/rb/rdf-spec.png)](http://badge.fury.io/rb/rdf-spec) +[![Build Status](https://travis-ci.org/ruby-rdf/rdf-spec.png?branch=master)](http://travis-ci.org/ruby-rdf/rdf-spec) +[![Coverage Status](https://coveralls.io/repos/ruby-rdf/rdf-spec/badge.svg)](https://coveralls.io/r/ruby-rdf/rdf-spec) ## Documentation diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index 78bd74e..92b535e 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -1,5 +1,14 @@ require "bundler/setup" require 'rdf' +require 'simplecov' +require 'coveralls' +SimpleCov.formatter = SimpleCov::Formatter::MultiFormatter[ + SimpleCov::Formatter::HTMLFormatter, + Coveralls::SimpleCov::Formatter +] +SimpleCov.start do + add_filter "/spec/" +end require 'rdf/spec' require 'rdf/spec/matchers'