csvlint 0.3.1 → 0.3.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,15 +1,15 @@
1
1
  ---
2
2
  !binary "U0hBMQ==":
3
3
  metadata.gz: !binary |-
4
- MDdiMTU5MDRkOWMzODllZGVjZTE1NWU0NzgyMjNkODgzYjlkNDE3NQ==
4
+ YWY4NmZlNTBlYjBlZWU2MjY5NmEzNGUzNWI1ZTkzN2Y1MDcyZjQ0ZA==
5
5
  data.tar.gz: !binary |-
6
- MmY0YjQyZTM1ODBkOTA2OWQxOGRkOWYxYmI2ZDA2NWEyZjRjM2U2YQ==
6
+ YTI3ODc0NWFlMzAxMzJkZTJiZjZkNjBkNmI3YjkxMDFiMTlhM2JjMQ==
7
7
  SHA512:
8
8
  metadata.gz: !binary |-
9
- NWM1OGNjNDk0MzgzY2MwZmY5NjJhOTBiNDFjYTA3YjBkYTAzN2IzNzUyYjg3
10
- NDdlZjVlYzEzZTFkMmI2ODQzZjIwY2IwZDU1Mjk5Y2QwNzdjNTg3YjYxM2Zj
11
- MzFkNWM5ZWUzOTY1NGUzZTgyMWZhYzRhNDI2ZWI0NmQyNWNjYzQ=
9
+ NTQwOGE2ZjdhMzg0OGJjYzFjNGQ2ZjFkMDQ0YTU1YjEzYmEyNzA4MzgyMjEw
10
+ ZmM4NGZjOWZkNWQ3YzVlNGI5ODlmMWY0Y2YwZWI4OTIwMDBiZWIxZDVlYzZh
11
+ Y2JhN2Q4MzY2ODQyYTBiMjBlZTU3OTEzZDU4NTZmOGU2ZWM3OGI=
12
12
  data.tar.gz: !binary |-
13
- ODc3MjNlZDRmOGFmNmJiYWM4OWJmN2IzZGYzNTI5YWY1Zjg5YzZmMmYyYjhi
14
- NWZhMjQ3ZTc4NGRhYTQ5ZjBlZjQ5ZjcwOThhYzQ5NjNhZDViZDVjYTFjYjlk
15
- YzgwNGM3NjMxMWNkOTI4ODU1ZDM4YmIwODc4MTExOWUyZWJkYjA=
13
+ YzhiOGUzYjEwYTc1YWJhMDQ2MGY2MTk5Zjk2NjI0ZjQzNzEwYTE4ZTk1NTZh
14
+ Mjc2MzcyZmJmZmNjN2ZmMDcwYWU1OTgzYTU0NDJiNGNjM2E3NDcwNWU1YTMy
15
+ YjNiNzNjYzA0ZDgxODQ2ZjMyMDgyM2IzYmQxODY5ZGIzYjE2NDA=
@@ -27,8 +27,7 @@ after_success:
27
27
  - '[ "$TRAVIS_BRANCH" == "master" ] && [ "$TRAVIS_PULL_REQUEST" == "false" ] && curl
28
28
  -v -X POST -d ''{"ref":"refs/tags/''$GEM_VERSION''","sha":"''$TRAVIS_COMMIT''"}'' --header
29
29
  "Content-Type:application/json" -u $GITHUB_USER:$GITHUB_PASSWORD "https://api.github.com/repos/$TRAVIS_REPO_SLUG/git/refs"'
30
- - gem install henry
31
- - henry deploy
30
+ - bundle exec henry deploy
32
31
  env:
33
32
  global:
34
33
  - secure: hM8Pv/EAZoB4fGGEUwKQQ/2+mgKbUac+PH2cwud25l2MJ64eoKEMZzfy4TF6+XMIzXhlWpsg4s51y6K3+W8pUyRAuwo2MsN5Iee7HnLz+LlYTiT0//iQdAmxQ0JlOyh8vd2SEFBcVfwpp/iZFIHAfbBO73ZDXhtGMEieMk025I0=
@@ -44,5 +44,6 @@ Gem::Specification.new do |spec|
44
44
  spec.add_development_dependency "aruba"
45
45
  spec.add_development_dependency "rdf"
46
46
  spec.add_development_dependency "rdf-turtle"
47
+ spec.add_development_dependency "henry"
47
48
 
48
49
  end
@@ -123,6 +123,32 @@ Feature: CSVlint CLI
123
123
  And the output should contain "1. Id: min_length. Row: 2,2. 5"
124
124
  And the output should contain "1. malformed_header. Row: 1. Bob,1234,bob@example.org"
125
125
 
126
+ Scenario: Schema errors with JSON
127
+ Given I have a CSV with the following content:
128
+ """
129
+ "Bob","1234","bob@example.org"
130
+ "Alice","5","alice@example.com"
131
+ """
132
+ And it is stored at the url "http://example.com/example1.csv"
133
+ And I have a schema with the following content:
134
+ """
135
+ {
136
+ "fields": [
137
+ { "name": "Name", "constraints": { "required": true } },
138
+ { "name": "Id", "constraints": { "required": true, "minLength": 3 } },
139
+ { "name": "Email", "constraints": { "required": true } }
140
+ ]
141
+ }
142
+ """
143
+ And the schema is stored at the url "http://example.com/schema.json"
144
+ When I run `csvlint http://example.com/example1.csv --schema http://example.com/schema.json --json`
145
+ Then the output should contain JSON
146
+ And the JSON should have a state of "invalid"
147
+ And the JSON should have 1 error
148
+ And error 1 should have the "type" "min_length"
149
+ And error 1 should have the "header" "Id"
150
+ And error 1 should have the constraint "min_length" "3"
151
+
126
152
  Scenario: Invalid schema
127
153
  Given I have a CSV with the following content:
128
154
  """
@@ -19,7 +19,7 @@ Then(/^the JSON should have a state of "(.*?)"$/) do |state|
19
19
  expect(@json['validation']['state']).to eq(state)
20
20
  end
21
21
 
22
- Then(/^the JSON should have (\d+) error$/) do |count|
22
+ Then(/^the JSON should have (\d+) errors?$/) do |count|
23
23
  @index = count.to_i - 1
24
24
  expect(@json['validation']['errors'].count).to eq(count.to_i)
25
25
  end
@@ -27,3 +27,11 @@ end
27
27
  Then(/^that error should have the "(.*?)" "(.*?)"$/) do |k, v|
28
28
  expect(@json['validation']['errors'][@index][k].to_s).to eq(v)
29
29
  end
30
+
31
+ Then(/^error (\d+) should have the "(.*?)" "(.*?)"$/) do |index, k, v|
32
+ expect(@json['validation']['errors'][index.to_i - 1][k].to_s).to eq(v)
33
+ end
34
+
35
+ Then(/^error (\d+) should have the constraint "(.*?)" "(.*?)"$/) do |index, k, v|
36
+ expect(@json['validation']['errors'][index.to_i - 1]['constraints'][k].to_s).to eq(v)
37
+ end
@@ -4,6 +4,8 @@ require 'json'
4
4
  require 'pp'
5
5
  require 'thor'
6
6
 
7
+ require 'active_support/inflector'
8
+
7
9
  module Csvlint
8
10
  class Cli < Thor
9
11
 
@@ -93,7 +95,9 @@ module Csvlint
93
95
  end
94
96
  output_string = "#{index+1}. "
95
97
  if error.column && @schema && @schema.class == Csvlint::Schema
96
- output_string += "#{@schema.fields[error.column - 1].name}: "
98
+ if @schema.fields[error.column - 1] != nil
99
+ output_string += "#{@schema.fields[error.column - 1].name}: "
100
+ end
97
101
  end
98
102
  output_string += "#{error.type}"
99
103
  output_string += ". #{location}" unless location.empty?
@@ -167,12 +171,20 @@ module Csvlint
167
171
  end
168
172
 
169
173
  def hashify(error)
170
- {
174
+ h = {
171
175
  type: error.type,
172
176
  category: error.category,
173
177
  row: error.row,
174
- col: error.column,
178
+ col: error.column
175
179
  }
180
+
181
+ if error.column && @schema && @schema.class == Csvlint::Schema && @schema.fields[error.column - 1] != nil
182
+ field = @schema.fields[error.column - 1]
183
+ h[:header] = field.name
184
+ h[:constraints] = Hash[field.constraints.map {|k,v| [k.underscore, v] }]
185
+ end
186
+
187
+ h
176
188
  end
177
189
 
178
190
  def report_lines
@@ -1,3 +1,3 @@
1
1
  module Csvlint
2
- VERSION = "0.3.1"
2
+ VERSION = "0.3.2"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: csvlint
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.1
4
+ version: 0.3.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - pezholio
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-05-23 00:00:00.000000000 Z
11
+ date: 2016-05-24 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: mime-types
@@ -360,6 +360,20 @@ dependencies:
360
360
  - - ! '>='
361
361
  - !ruby/object:Gem::Version
362
362
  version: '0'
363
+ - !ruby/object:Gem::Dependency
364
+ name: henry
365
+ requirement: !ruby/object:Gem::Requirement
366
+ requirements:
367
+ - - ! '>='
368
+ - !ruby/object:Gem::Version
369
+ version: '0'
370
+ type: :development
371
+ prerelease: false
372
+ version_requirements: !ruby/object:Gem::Requirement
373
+ requirements:
374
+ - - ! '>='
375
+ - !ruby/object:Gem::Version
376
+ version: '0'
363
377
  description: CSV Validator
364
378
  email:
365
379
  - pezholio@gmail.com