Permalink
Browse files

add new tests(specs), make a ruby gem to provide path to schema files

  • Loading branch information...
1 parent a7a3b92 commit cbae8eb20d280ac6ae07bee018b27e2ab31172b5 @schorsch schorsch committed Jan 1, 2013
View
@@ -1 +1,2 @@
Gemfile.lock
+pkg/
View
@@ -1,4 +1,5 @@
rvm:
- - 1.9.2
-gemfile: test/Gemfile
-script: 'bundle exec ruby test/validate_schemas.rb'
+ - 1.9.2
+ - 1.9.3
+gemfile:
+ - Gemfile
View
@@ -0,0 +1,2 @@
+source :rubygems
+gemspec
@@ -35,12 +35,11 @@ and it's xml-based subsets rather fit big enterprises and are way too bloated.
A tiny test-suite in /test ensures that all schema files contain valid json.
The test are run after each commit by travis-ci(see batch above)
-To run the test locally you need ruby. First install the dependencies and then
-run it:
+To run the test locally you need ruby. First install the ruby-gem dependencies
+and then run it:
- cd test
bundle install
- ruby validate_schemas.rb
+ rake spec
## Initiative Supporters a-z
View
@@ -0,0 +1,18 @@
+#!/usr/bin/env rake
+require 'bundler/gem_tasks'
+require 'rspec'
+require 'rspec/core/rake_task'
+require 'rdoc/task'
+
+desc 'Run specs'
+RSpec::Core::RakeTask.new
+task :default => :spec
+
+desc 'Generate documentation.'
+Rake::RDocTask.new(:rdoc) do |rdoc|
+ rdoc.rdoc_dir = 'rdoc'
+ rdoc.title = 'DocTag JSON Schema'
+ rdoc.options << '--line-numbers' << '--inline-source'
+ rdoc.rdoc_files.include('README')
+ rdoc.rdoc_files.include('lib/**/*.rb')
+end
View
@@ -0,0 +1,26 @@
+# -*- encoding: utf-8 -*-
+$:.push File.expand_path('../lib', __FILE__)
+require 'doc_tag/version'
+
+Gem::Specification.new do |s|
+ s.version = DocTag::Schema::VERSION
+ s.date = %q{2012-12-23}
+ s.name = %q{doctag_json_schema}
+ s.summary = 'DocTag API - JSON Schema'
+ s.description = %q{This is the formal description of the docTag document exchange format. With docTag we(see Supporters) aim to simplify the exchange of documents e.g. invoices, between services. Ruby users can use this gem with utility methods to load and test the schema files.}
+ s.authors = ['Georg Leciejewski']
+ s.email = %q{gl@salesking.eu}
+ s.homepage = %q{https://github.com/docTag/doctag_json_schema}
+ s.extra_rdoc_files = ['README.md']
+ s.executables = nil
+ s.files = `git ls-files`.split("\n").reject{|i| i[/^docs\//] }
+ s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
+
+ s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
+ s.require_paths = ['lib']
+
+ #s.add_development_dependency 'json'
+ s.add_development_dependency 'rspec'
+ s.add_development_dependency 'json_schema_tools'
+ s.add_development_dependency 'rake', '>= 0.9.2'
+end
View
@@ -0,0 +1,10 @@
+# encoding: utf-8
+module DocTag
+ class Schema
+ # Get the path to schema files. So it can be used f.ex. with
+ # gem json_schema_tools
+ def self.path
+ File.expand_path( '../../schema', File.dirname(__FILE__))
+ end
+ end
+end
View
@@ -0,0 +1,6 @@
+module DocTag
+ class Schema
+ # gem version
+ VERSION='1.0.0'
+ end
+end
@@ -0,0 +1 @@
+require 'doc_tag/schema'
View
@@ -0,0 +1,20 @@
+require 'spec_helper'
+
+describe DocTag::Schema do
+
+ context 'path' do
+ it 'should provide path to schema files' do
+ DocTag::Schema.path.should == File.expand_path( File.join('../schema'), File.dirname(__FILE__))
+ end
+ end
+
+ context 'read schemata' do
+
+ it 'should read all json files' do
+ SchemaTools.schema_path = DocTag::Schema.path
+ SchemaTools::Reader.read_all
+ SchemaTools::Reader.registry.should_not be_empty
+ end
+
+ end
+end
View
@@ -0,0 +1,10 @@
+# encoding: utf-8
+$:.unshift(File.dirname(__FILE__))
+$:.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
+
+require 'rspec'
+require 'json_schema_tools'
+require 'doctag_json_schema'
+
+RSpec.configure do |config|
+end
View
@@ -1,4 +0,0 @@
-source :rubygems
-gem 'json'
-gem 'json-schema'
-gem 'minitest'
View
@@ -1,24 +0,0 @@
-#encoding: UTF-8
-require 'minitest/autorun'
-require 'json-schema'
-require 'json'
-
-SCHEMAS_PATH = File.join(File.dirname(File.expand_path(__FILE__)) , '/../schema')
-
-describe 'schema' do
- Dir["#{SCHEMAS_PATH}/**/*\.*"].each do |file|
- it "#{File.basename file} contains valid json" do
- begin
- json_str = File.open(file) { |f| f.read }
- # force_encoding only available in ruby 1.9.2
- obj = JSON.parse( json_str.respond_to?(:force_encoding ) ? json_str.force_encoding('UTF-8') : json_str)['question']
- rescue JSON::ParserError => parser_error
- assertion = false, parser_error.message
- else
- assertion = true
- end
-
- assert *assertion
- end
- end
-end

0 comments on commit cbae8eb

Please sign in to comment.