spout 0.1.0.rc → 0.1.0.rc2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: e32f497120ec785b137d1c17e742276175bcefb1
4
- data.tar.gz: fc4b7095bc652ca44c4ad0fc57bcb9b7e393faf1
3
+ metadata.gz: 107e09d3629aadfb7fd0e06b27c115a2d0e87fbd
4
+ data.tar.gz: 62ea6faceb8218158e870aebedb42ac3047a2a66
5
5
  SHA512:
6
- metadata.gz: 348a4e793232013cfe12d1444ad6e68e802b095e3cc5b6ee0663ae3985ad010cb1d828c099827f86c991a156e6457fce97667b9ca1fc04ef270647c2bd7f4d6f
7
- data.tar.gz: 559c1d2b2c288d81bd2be68387fce94d15f1ac2cccf03bb17ac56cad7457bc2d9d353a3a33cbc1bbc6c4b6e52c374f3ad525ca8f19131762863bebda090c401b
6
+ metadata.gz: 3d5710e58b74e66277fa1dd0c6a85fbf63edbea619e5b51c5b7720b00f786d7c43586e07f99733432f61c06ac6f83f8daabcf56d12b924a67acb553bc8bfae3b
7
+ data.tar.gz: a94c8b3c1bfd03586f62079dd01d91cd4563f2fbed2fabaf34d900ea2bc1d5801c22a8ad61846948b6ca80bce0d535aea8a9d741f82b86a9e3fd2ab5d8aee8bd
data/README.md CHANGED
@@ -25,11 +25,20 @@ spout new my_data_dictionary
25
25
 
26
26
  cd my_data_dictionary
27
27
 
28
- spout import CSV=data_dictionary.csv
28
+ spout import data_dictionary.csv
29
29
  ```
30
30
 
31
31
  ### Test your repository
32
32
 
33
+ If you created your data dictionary repository using `spout new`, you can go ahead and test using:
34
+
35
+ ```
36
+ spout test
37
+ ```
38
+
39
+ If not, you can add the following to your `test` directory to include all Spout tests, or just a subset of Spout tests.
40
+
41
+ `test/dictionary_test.rb`
33
42
 
34
43
  ```
35
44
  require 'spout/tests'
@@ -49,7 +58,7 @@ class DictionaryTest < Test::Unit::TestCase
49
58
  end
50
59
  ```
51
60
 
52
- Then run either `bundle exec rake` or `spout test` to run your tests
61
+ Then run either `spout test` or `bundle exec rake` to run your tests.
53
62
 
54
63
 
55
64
  ### Create a CSV Data Dictionary from your JSON repository
@@ -54,7 +54,7 @@ namespace :dd do
54
54
  CSV.parse( File.open(ENV['CSV'].to_s, 'r:iso-8859-1:utf-8'){|f| f.read}, headers: true ) do |line|
55
55
  row = line.to_hash
56
56
  next if row['id'] == ''
57
- folder = File.join('variables', row['folder'])
57
+ folder = File.join('variables', row.delete('folder').to_s.gsub(':', '/'))
58
58
  FileUtils.mkpath folder
59
59
  hash = {}
60
60
  id = row.delete('id')
@@ -4,7 +4,7 @@ class DictionaryTest < Test::Unit::TestCase
4
4
  include Spout::Tests
5
5
 
6
6
  # You may add additional tests here
7
- # test "the truth" do
7
+ # def test_truth
8
8
  # assert true
9
9
  # end
10
10
  end
@@ -2,10 +2,24 @@ module Spout
2
2
  module Tests
3
3
  module DomainExistenceValidation
4
4
 
5
+ def assert_domain_existence(item, msg = nil)
6
+ result = begin
7
+ domain_name = JSON.parse(File.read(item))["domain"]+".json"
8
+ File.exists?(File.join("domains", domain_name))
9
+ rescue JSON::ParserError => e
10
+ error = e
11
+ false
12
+ end
13
+ full_message = build_message(msg, "The domain \"domains/#{domain_name}\" referenced by ? does not exist.", item)
14
+ assert_block(full_message) do
15
+ result
16
+ end
17
+ end
18
+
5
19
  Dir.glob("variables/**/*.json").each do |file|
6
20
  if (not [nil, ''].include?(JSON.parse(File.read(file))["domain"]) rescue false)
7
21
  define_method("test_domain_exists: "+file) do
8
- assert_equal true, (File.exists?(File.join("domains", JSON.parse(File.read(file))["domain"]+".json")) rescue false)
22
+ assert_domain_existence file
9
23
  end
10
24
  end
11
25
  end
@@ -2,15 +2,28 @@ module Spout
2
2
  module Tests
3
3
  module JsonValidation
4
4
 
5
+ def assert_valid_json(item, msg = nil)
6
+ result = begin
7
+ !!JSON.parse(File.read(item))
8
+ rescue JSON::ParserError => e
9
+ error = e
10
+ false
11
+ end
12
+ full_message = build_message(msg, "?", error)
13
+ assert_block(full_message) do
14
+ result
15
+ end
16
+ end
17
+
5
18
  Dir.glob("variables/**/*.json").each do |file|
6
19
  define_method("test_json: "+file) do
7
- assert_equal true, (!!JSON.parse(File.read(file)) rescue false)
20
+ assert_valid_json file
8
21
  end
9
22
  end
10
23
 
11
24
  Dir.glob("domains/**/*.json").each do |file|
12
25
  define_method("test_json: "+file) do
13
- assert_equal true, (!!JSON.parse(File.read(file)) rescue false)
26
+ assert_valid_json file
14
27
  end
15
28
  end
16
29
 
@@ -1,11 +1,18 @@
1
1
  module Spout
2
2
  module Tests
3
3
  module VariableTypeValidation
4
- VALID_VARIABLE_TYPES = ['identifier', 'choices', 'integer', 'numeric']
4
+ VALID_VARIABLE_TYPES = ['identifier', 'choices', 'integer', 'numeric'].sort
5
+
6
+ def assert_variable_type(item, msg = nil)
7
+ full_message = build_message(msg, "? invalid variable type. Valid types: #{VALID_VARIABLE_TYPES.join(', ')}", item)
8
+ assert_block(full_message) do
9
+ VALID_VARIABLE_TYPES.include?(item)
10
+ end
11
+ end
5
12
 
6
13
  Dir.glob("variables/**/*.json").each do |file|
7
14
  define_method("test_variable_type: "+file) do
8
- assert_equal true, (VALID_VARIABLE_TYPES.include?(JSON.parse(File.read(file))["type"]) rescue false)
15
+ assert_variable_type begin JSON.parse(File.read(file))["type"] rescue nil end
9
16
  end
10
17
  end
11
18
 
data/lib/spout/tests.rb CHANGED
@@ -12,5 +12,7 @@ module Spout
12
12
  include Spout::Tests::JsonValidation
13
13
  include Spout::Tests::VariableTypeValidation
14
14
  include Spout::Tests::DomainExistenceValidation
15
+
16
+ Turn.config.trace = 1
15
17
  end
16
18
  end
data/lib/spout/version.rb CHANGED
@@ -3,7 +3,7 @@ module Spout
3
3
  MAJOR = 0
4
4
  MINOR = 1
5
5
  TINY = 0
6
- BUILD = "rc" # nil, "pre", "rc", "rc2"
6
+ BUILD = "rc2" # nil, "pre", "rc", "rc2"
7
7
 
8
8
  STRING = [MAJOR, MINOR, TINY, BUILD].compact.join('.')
9
9
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: spout
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0.rc
4
+ version: 0.1.0.rc2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Remo Mueller
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2013-05-15 00:00:00.000000000 Z
11
+ date: 2013-05-16 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rake