csvlint 0.4.0 → 1.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/.github/dependabot.yml +11 -0
- data/.github/workflows/push.yml +35 -0
- data/.gitignore +1 -0
- data/.ruby-version +1 -1
- data/.standard_todo.yml +43 -0
- data/CHANGELOG.md +38 -0
- data/Dockerfile +16 -0
- data/Gemfile +2 -2
- data/README.md +13 -10
- data/Rakefile +7 -7
- data/bin/create_schema +2 -2
- data/csvlint.gemspec +19 -22
- data/docker_notes_for_windows.txt +20 -0
- data/features/step_definitions/cli_steps.rb +11 -11
- data/features/step_definitions/information_steps.rb +4 -4
- data/features/step_definitions/parse_csv_steps.rb +11 -11
- data/features/step_definitions/schema_validation_steps.rb +10 -10
- data/features/step_definitions/sources_steps.rb +1 -1
- data/features/step_definitions/validation_errors_steps.rb +19 -19
- data/features/step_definitions/validation_info_steps.rb +9 -9
- data/features/step_definitions/validation_warnings_steps.rb +11 -11
- data/features/support/aruba.rb +10 -9
- data/features/support/earl_formatter.rb +39 -39
- data/features/support/env.rb +10 -11
- data/features/support/load_tests.rb +109 -105
- data/features/support/webmock.rb +3 -1
- data/lib/csvlint/cli.rb +136 -142
- data/lib/csvlint/csvw/column.rb +279 -280
- data/lib/csvlint/csvw/date_format.rb +90 -92
- data/lib/csvlint/csvw/metadata_error.rb +1 -3
- data/lib/csvlint/csvw/number_format.rb +40 -32
- data/lib/csvlint/csvw/property_checker.rb +714 -717
- data/lib/csvlint/csvw/table.rb +49 -52
- data/lib/csvlint/csvw/table_group.rb +24 -23
- data/lib/csvlint/error_collector.rb +2 -0
- data/lib/csvlint/error_message.rb +0 -1
- data/lib/csvlint/field.rb +153 -141
- data/lib/csvlint/schema.rb +35 -43
- data/lib/csvlint/validate.rb +173 -151
- data/lib/csvlint/version.rb +1 -1
- data/lib/csvlint.rb +22 -23
- data/spec/csvw/column_spec.rb +15 -16
- data/spec/csvw/date_format_spec.rb +5 -7
- data/spec/csvw/number_format_spec.rb +2 -4
- data/spec/csvw/table_group_spec.rb +103 -105
- data/spec/csvw/table_spec.rb +71 -73
- data/spec/field_spec.rb +116 -121
- data/spec/schema_spec.rb +131 -141
- data/spec/spec_helper.rb +6 -6
- data/spec/validator_spec.rb +167 -203
- metadata +41 -85
- data/.travis.yml +0 -37
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 7f9c598fca283466c50e65c4b436166fccb0e9e0340d3d370fb3f4e814cf1f3e
|
4
|
+
data.tar.gz: 321481d47fca1f6ef1df7963e5d705ce05685a9861e48d954397eb288f46541a
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 1e9f755b174f3c1b3052f43621e8c15cf3a3b947a5a611f370b42f309492797664a622886520a7d209d109f271a2d101aaa24017529900c82d76a71b8cb46173
|
7
|
+
data.tar.gz: 73da87ddbbc71a1e62f90ffaebca3947833921f546dcb01524bd464c7fbf1a3dbf086757443838e6ec401bac86e5cacf26a9e3b397904ba9ee32a0688c4271a0
|
@@ -0,0 +1,35 @@
|
|
1
|
+
name: CI
|
2
|
+
on:
|
3
|
+
push:
|
4
|
+
branches: [ main ]
|
5
|
+
pull_request:
|
6
|
+
branches: [ main ]
|
7
|
+
jobs:
|
8
|
+
test:
|
9
|
+
runs-on: ubuntu-latest
|
10
|
+
strategy:
|
11
|
+
matrix:
|
12
|
+
ruby-version: ['2.5', '2.6', '2.7', '3.0', '3.1', '3.2']
|
13
|
+
fail-fast: false
|
14
|
+
steps:
|
15
|
+
- uses: actions/checkout@v3
|
16
|
+
- uses: ruby/setup-ruby@v1
|
17
|
+
with:
|
18
|
+
bundler-cache: true
|
19
|
+
ruby-version: ${{ matrix.ruby-version }}
|
20
|
+
- name: Install dependencies
|
21
|
+
run: bundle install
|
22
|
+
- name: Run the tests
|
23
|
+
run: bundle exec rake
|
24
|
+
lint:
|
25
|
+
runs-on: ubuntu-latest
|
26
|
+
steps:
|
27
|
+
- uses: actions/checkout@v2
|
28
|
+
- uses: ruby/setup-ruby@v1
|
29
|
+
with:
|
30
|
+
bundler-cache: true
|
31
|
+
ruby-version: "3.2"
|
32
|
+
- name: Install dependencies
|
33
|
+
run: bundle install
|
34
|
+
- name: Run the tests
|
35
|
+
run: bundle exec standardrb
|
data/.gitignore
CHANGED
data/.ruby-version
CHANGED
@@ -1 +1 @@
|
|
1
|
-
2.
|
1
|
+
3.2.0
|
data/.standard_todo.yml
ADDED
@@ -0,0 +1,43 @@
|
|
1
|
+
# Auto generated files with errors to ignore.
|
2
|
+
# Remove from this list as you refactor files.
|
3
|
+
---
|
4
|
+
ignore:
|
5
|
+
- features/step_definitions/validation_errors_steps.rb:
|
6
|
+
- Lint/Void
|
7
|
+
- features/support/load_tests.rb:
|
8
|
+
- Style/For
|
9
|
+
- Security/Open
|
10
|
+
- Lint/UselessAssignment
|
11
|
+
- lib/csvlint/cli.rb:
|
12
|
+
- Style/NonNilCheck
|
13
|
+
- lib/csvlint/csvw/column.rb:
|
14
|
+
- Style/TernaryParentheses
|
15
|
+
- lib/csvlint/csvw/date_format.rb:
|
16
|
+
- Lint/MixedRegexpCaptureTypes
|
17
|
+
- lib/csvlint/csvw/number_format.rb:
|
18
|
+
- Style/SlicingWithRange
|
19
|
+
- Style/IdenticalConditionalBranches
|
20
|
+
- lib/csvlint/csvw/property_checker.rb:
|
21
|
+
- Performance/InefficientHashSearch
|
22
|
+
- Lint/UselessAssignment
|
23
|
+
- Naming/VariableName
|
24
|
+
- Style/SlicingWithRange
|
25
|
+
- Security/Open
|
26
|
+
- Lint/BooleanSymbol
|
27
|
+
- lib/csvlint/csvw/table_group.rb:
|
28
|
+
- Style/OptionalArguments
|
29
|
+
- lib/csvlint/field.rb:
|
30
|
+
- Naming/VariableName
|
31
|
+
- lib/csvlint/schema.rb:
|
32
|
+
- Security/Open
|
33
|
+
- Lint/UselessAssignment
|
34
|
+
- Style/SlicingWithRange
|
35
|
+
- lib/csvlint/validate.rb:
|
36
|
+
- Lint/UselessAssignment
|
37
|
+
- Performance/Count
|
38
|
+
- Lint/BooleanSymbol
|
39
|
+
- Naming/VariableName
|
40
|
+
- Security/Open
|
41
|
+
- Lint/NonLocalExitFromIterator
|
42
|
+
- spec/validator_spec.rb:
|
43
|
+
- Lint/UselessAssignment
|
data/CHANGELOG.md
CHANGED
@@ -1,5 +1,43 @@
|
|
1
1
|
# Change Log
|
2
2
|
|
3
|
+
## [v1.0.0](https://github.com/Data-Liberation-Front/csvlint.rb/tree/v1.0.0) (2022-07-13)
|
4
|
+
[Full Changelog](https://github.com/theodi/csvlint.rb/compare/0.4.0...v1.0.0)
|
5
|
+
|
6
|
+
Support Ruby 3.x, and DROPPED support for Ruby 2.4 - that's why the major version bump. That and this has been around long enough that it really shouldn't be on a zero version any more :)
|
7
|
+
|
8
|
+
## What's Changed
|
9
|
+
* Don't patch CSV#init_converters for ruby 2.5 compatibility by @rbmrclo in https://github.com/Data-Liberation-Front/csvlint.rb/pull/217
|
10
|
+
* correct typos in README by @erikj in https://github.com/Data-Liberation-Front/csvlint.rb/pull/216
|
11
|
+
* add info about your PATH by @ftrotter in https://github.com/Data-Liberation-Front/csvlint.rb/pull/222
|
12
|
+
* Remove tests on deprecated ruby versions < 2.3 by @Floppy in https://github.com/Data-Liberation-Front/csvlint.rb/pull/234
|
13
|
+
* Drop mime-types gem dependency by @ohbarye in https://github.com/Data-Liberation-Front/csvlint.rb/pull/221
|
14
|
+
* remove specific version of net-http-persistent in gemspec by @kotaro0522 in https://github.com/Data-Liberation-Front/csvlint.rb/pull/219
|
15
|
+
* Replace colorize with rainbow to make licensing consistent. by @cobbr2 in https://github.com/Data-Liberation-Front/csvlint.rb/pull/215
|
16
|
+
* Update rdf requirement from < 2.0 to < 4.0 by @dependabot-preview in https://github.com/Data-Liberation-Front/csvlint.rb/pull/231
|
17
|
+
* Test on Ruby 2.5 and 2.6 by @Domon in https://github.com/Data-Liberation-Front/csvlint.rb/pull/223
|
18
|
+
* Fix load_from_json deprecation warnings. by @jezhiggins in https://github.com/Data-Liberation-Front/csvlint.rb/pull/237
|
19
|
+
* Fix csvw tests by @Floppy in https://github.com/Data-Liberation-Front/csvlint.rb/pull/239
|
20
|
+
* Test on Ruby 2.6 and 2.7 by @Floppy in https://github.com/Data-Liberation-Front/csvlint.rb/pull/240
|
21
|
+
* Create Dependabot config file by @dependabot-preview in https://github.com/Data-Liberation-Front/csvlint.rb/pull/245
|
22
|
+
* Include active_support/object to ensure this works in ruby 2.6 by @mseverini in https://github.com/Data-Liberation-Front/csvlint.rb/pull/246
|
23
|
+
* add CI workflow for github actions by @Floppy in https://github.com/Data-Liberation-Front/csvlint.rb/pull/255
|
24
|
+
* Enable and fix tests for Ruby 2.5 by @Floppy in https://github.com/Data-Liberation-Front/csvlint.rb/pull/259
|
25
|
+
* Support Ruby 2.6 by @Floppy in https://github.com/Data-Liberation-Front/csvlint.rb/pull/262
|
26
|
+
* Ruby 2.7 support by @Floppy in https://github.com/Data-Liberation-Front/csvlint.rb/pull/263
|
27
|
+
* Drop support for Ruby 2.4 by @Floppy in https://github.com/Data-Liberation-Front/csvlint.rb/pull/265
|
28
|
+
* Ruby 3.0 by @Floppy in https://github.com/Data-Liberation-Front/csvlint.rb/pull/264
|
29
|
+
|
30
|
+
## New Contributors
|
31
|
+
* @rbmrclo made their first contribution in https://github.com/Data-Liberation-Front/csvlint.rb/pull/217
|
32
|
+
* @erikj made their first contribution in https://github.com/Data-Liberation-Front/csvlint.rb/pull/216
|
33
|
+
* @ftrotter made their first contribution in https://github.com/Data-Liberation-Front/csvlint.rb/pull/222
|
34
|
+
* @ohbarye made their first contribution in https://github.com/Data-Liberation-Front/csvlint.rb/pull/221
|
35
|
+
* @kotaro0522 made their first contribution in https://github.com/Data-Liberation-Front/csvlint.rb/pull/219
|
36
|
+
* @cobbr2 made their first contribution in https://github.com/Data-Liberation-Front/csvlint.rb/pull/215
|
37
|
+
* @dependabot-preview made their first contribution in https://github.com/Data-Liberation-Front/csvlint.rb/pull/231
|
38
|
+
* @Domon made their first contribution in https://github.com/Data-Liberation-Front/csvlint.rb/pull/223
|
39
|
+
* @mseverini made their first contribution in https://github.com/Data-Liberation-Front/csvlint.rb/pull/246
|
40
|
+
|
3
41
|
## [0.4.0](https://github.com/theodi/csvlint.rb/tree/0.4.0) (2017-xx-xx)
|
4
42
|
[Full Changelog](https://github.com/theodi/csvlint.rb/compare/0.3.3...0.4.0)
|
5
43
|
|
data/Dockerfile
ADDED
@@ -0,0 +1,16 @@
|
|
1
|
+
FROM ruby:2.5.8-buster
|
2
|
+
|
3
|
+
# throw errors if Gemfile has been modified since Gemfile.lock
|
4
|
+
RUN bundle config --global frozen 1
|
5
|
+
|
6
|
+
WORKDIR /usr/src/app
|
7
|
+
|
8
|
+
ENV LANG C.UTF-8
|
9
|
+
|
10
|
+
COPY ./lib/csvlint/version.rb ./lib/csvlint/
|
11
|
+
COPY csvlint.gemspec Gemfile Gemfile.lock ./
|
12
|
+
RUN bundle install
|
13
|
+
|
14
|
+
COPY ./ ./
|
15
|
+
|
16
|
+
CMD ["./bin/csvlint"]
|
data/Gemfile
CHANGED
data/README.md
CHANGED
@@ -1,23 +1,23 @@
|
|
1
|
-
[![Build Status](
|
2
|
-
[![Dependency Status](
|
3
|
-
[![Coverage Status](http://img.shields.io/coveralls/
|
1
|
+
[![Build Status](https://img.shields.io/github/workflow/status/Data-Liberation-Front/csvlint.rb/CI/main)](https://travis-ci.org/theodi/csvlint.rb)
|
2
|
+
[![Dependency Status](https://img.shields.io/librariesio/github/Data-Liberation-Front/csvlint.rb)](https://libraries.io/github/Data-Liberation-Front/csvlint.rb)
|
3
|
+
[![Coverage Status](http://img.shields.io/coveralls/Data-Liberation-Front/csvlint.rb.svg)](https://coveralls.io/r/Data-Liberation-Front/csvlint.rb)
|
4
4
|
[![License](http://img.shields.io/:license-mit-blue.svg)](http://theodi.mit-license.org)
|
5
5
|
[![Badges](http://img.shields.io/:badges-5/5-ff6799.svg)](https://github.com/pikesley/badger)
|
6
6
|
|
7
7
|
# CSV Lint
|
8
8
|
|
9
|
-
A ruby gem to support validating CSV files to check their syntax and contents. You can either use this gem within your own Ruby code, or as a
|
9
|
+
A ruby gem to support validating CSV files to check their syntax and contents. You can either use this gem within your own Ruby code, or as a standalone command line application
|
10
10
|
|
11
11
|
## Summary of features
|
12
12
|
|
13
|
-
* Validation that checks the structural formatting of a CSV file
|
13
|
+
* Validation that checks the structural formatting of a CSV file
|
14
14
|
* Validation of a delimiter-separated values (dsv) file accesible via URL, File, or an IO-style object (e.g. StringIO)
|
15
|
-
* Validation against [CSV dialects](http://dataprotocols.org/csv-dialect/)
|
16
|
-
* Validation against multiple schema standards; [JSON Table Schema](https://github.com/theodi/csvlint.rb/blob/master/README.md#json-table-schema-support) and [CSV on the Web](https://github.com/theodi/csvlint.rb/blob/master/README.md#csv-on-the-web-validation-support)
|
15
|
+
* Validation against [CSV dialects](http://dataprotocols.org/csv-dialect/)
|
16
|
+
* Validation against multiple schema standards; [JSON Table Schema](https://github.com/theodi/csvlint.rb/blob/master/README.md#json-table-schema-support) and [CSV on the Web](https://github.com/theodi/csvlint.rb/blob/master/README.md#csv-on-the-web-validation-support)
|
17
17
|
|
18
18
|
## Development
|
19
19
|
|
20
|
-
`ruby version 2
|
20
|
+
`ruby version 3.2`
|
21
21
|
|
22
22
|
### Tests
|
23
23
|
|
@@ -63,7 +63,7 @@ Or install it yourself as:
|
|
63
63
|
|
64
64
|
## Usage
|
65
65
|
|
66
|
-
You can either use this gem within your own Ruby code, or as a
|
66
|
+
You can either use this gem within your own Ruby code, or as a standalone command line application
|
67
67
|
|
68
68
|
## On the command line
|
69
69
|
|
@@ -71,6 +71,9 @@ After installing the gem, you can validate a CSV on the command line like so:
|
|
71
71
|
|
72
72
|
csvlint myfile.csv
|
73
73
|
|
74
|
+
You may need to add the gem exectuable directory to your path, by adding '/usr/local/lib/ruby/gems/2.6.0/bin'
|
75
|
+
or whatever your version is, to your .bash_profile PATH entry. [like so](https://stackoverflow.com/questions/2392293/ruby-gems-returns-command-not-found)
|
76
|
+
|
74
77
|
You will then see the validation result, together with any warnings or errors e.g.
|
75
78
|
|
76
79
|
```
|
@@ -210,7 +213,7 @@ An example JSON Table Schema schema file is:
|
|
210
213
|
"name": "price",
|
211
214
|
"constraints": {
|
212
215
|
"required": true,
|
213
|
-
"minLength": 1
|
216
|
+
"minLength": 1
|
214
217
|
}
|
215
218
|
},
|
216
219
|
{
|
data/Rakefile
CHANGED
@@ -1,12 +1,12 @@
|
|
1
1
|
require "bundler/gem_tasks"
|
2
2
|
|
3
|
-
$:.unshift File.join(
|
3
|
+
$:.unshift File.join(File.dirname(__FILE__), "lib")
|
4
4
|
|
5
|
-
require
|
6
|
-
require
|
7
|
-
require
|
8
|
-
require
|
9
|
-
require
|
5
|
+
require "rubygems"
|
6
|
+
require "cucumber"
|
7
|
+
require "cucumber/rake/task"
|
8
|
+
require "coveralls/rake/task"
|
9
|
+
require "rspec/core/rake_task"
|
10
10
|
|
11
11
|
RSpec::Core::RakeTask.new(:spec)
|
12
12
|
Coveralls::RakeTask.new
|
@@ -14,4 +14,4 @@ Cucumber::Rake::Task.new(:features) do |t|
|
|
14
14
|
t.cucumber_opts = "features --format pretty"
|
15
15
|
end
|
16
16
|
|
17
|
-
task :
|
17
|
+
task default: [:spec, :features, "coveralls:push"]
|
data/bin/create_schema
CHANGED
@@ -5,7 +5,7 @@ require 'csvlint'
|
|
5
5
|
|
6
6
|
begin
|
7
7
|
puts ARGV[0]
|
8
|
-
|
8
|
+
csv = CSV.new( URI.open(ARGV[0]) )
|
9
9
|
headers = csv.shift
|
10
10
|
|
11
11
|
name = File.basename( ARGV[0] )
|
@@ -29,4 +29,4 @@ rescue => e
|
|
29
29
|
puts e
|
30
30
|
puts e.backtrace
|
31
31
|
puts "Unable to parse CSV file"
|
32
|
-
end
|
32
|
+
end
|
data/csvlint.gemspec
CHANGED
@@ -1,27 +1,24 @@
|
|
1
|
-
|
2
|
-
lib = File.expand_path('../lib', __FILE__)
|
1
|
+
lib = File.expand_path("../lib", __FILE__)
|
3
2
|
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
-
require
|
3
|
+
require "csvlint/version"
|
5
4
|
|
6
5
|
Gem::Specification.new do |spec|
|
7
|
-
spec.name
|
8
|
-
spec.version
|
9
|
-
spec.authors
|
10
|
-
spec.email
|
11
|
-
spec.description
|
12
|
-
spec.summary
|
13
|
-
spec.homepage
|
14
|
-
spec.license
|
6
|
+
spec.name = "csvlint"
|
7
|
+
spec.version = Csvlint::VERSION
|
8
|
+
spec.authors = ["pezholio"]
|
9
|
+
spec.email = ["pezholio@gmail.com"]
|
10
|
+
spec.description = "CSV Validator"
|
11
|
+
spec.summary = "CSV Validator"
|
12
|
+
spec.homepage = "https://github.com/theodi/csvlint.rb"
|
13
|
+
spec.license = "MIT"
|
15
14
|
|
16
|
-
spec.files
|
17
|
-
spec.executables
|
18
|
-
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
15
|
+
spec.files = `git ls-files`.split($/)
|
16
|
+
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
19
17
|
spec.require_paths = ["lib"]
|
20
18
|
|
21
|
-
spec.required_ruby_version = [
|
19
|
+
spec.required_ruby_version = [">= 2.5", "< 3.3"]
|
22
20
|
|
23
|
-
spec.add_dependency "
|
24
|
-
spec.add_dependency "colorize"
|
21
|
+
spec.add_dependency "rainbow"
|
25
22
|
spec.add_dependency "open_uri_redirections"
|
26
23
|
spec.add_dependency "activesupport"
|
27
24
|
spec.add_dependency "addressable"
|
@@ -30,9 +27,9 @@ Gem::Specification.new do |spec|
|
|
30
27
|
spec.add_dependency "uri_template"
|
31
28
|
spec.add_dependency "thor"
|
32
29
|
spec.add_dependency "rack"
|
33
|
-
spec.add_dependency "net-http-persistent"
|
30
|
+
spec.add_dependency "net-http-persistent"
|
34
31
|
|
35
|
-
spec.add_development_dependency "bundler", "
|
32
|
+
spec.add_development_dependency "bundler", ">= 1.3"
|
36
33
|
spec.add_development_dependency "rake"
|
37
34
|
spec.add_development_dependency "cucumber"
|
38
35
|
spec.add_development_dependency "simplecov"
|
@@ -43,11 +40,11 @@ Gem::Specification.new do |spec|
|
|
43
40
|
spec.add_development_dependency "rspec-pride"
|
44
41
|
spec.add_development_dependency "rspec-expectations"
|
45
42
|
spec.add_development_dependency "coveralls"
|
46
|
-
spec.add_development_dependency "
|
43
|
+
spec.add_development_dependency "byebug"
|
47
44
|
spec.add_development_dependency "github_changelog_generator"
|
48
45
|
spec.add_development_dependency "aruba"
|
49
|
-
spec.add_development_dependency "rdf", "<
|
46
|
+
spec.add_development_dependency "rdf", "< 4.0"
|
50
47
|
spec.add_development_dependency "rdf-turtle"
|
51
48
|
spec.add_development_dependency "henry"
|
52
|
-
|
49
|
+
spec.add_development_dependency "standardrb"
|
53
50
|
end
|
@@ -0,0 +1,20 @@
|
|
1
|
+
# Note that these commands are specific for a docker environment on MS Windows.
|
2
|
+
|
3
|
+
# to generate Gemfile.lock file
|
4
|
+
docker run --rm -v %CD%:/usr/src/app -w /usr/src/app ruby:2.5 bundle install
|
5
|
+
|
6
|
+
# to build docker image from source (the ending dot is significant)
|
7
|
+
docker build -t csvlint .
|
8
|
+
|
9
|
+
# to run tests
|
10
|
+
docker run -it --rm csvlint rake
|
11
|
+
|
12
|
+
# to run csvlint command line with a CSV file.
|
13
|
+
# cd to the directory with the CSV file then
|
14
|
+
docker run -it --rm -v %CD%:/tmp csvlint ./bin/csvlint --dump-errors /tmp/file-to-lint.csv
|
15
|
+
|
16
|
+
# to enter the linux container
|
17
|
+
docker run -it --rm -v %CD%:/tmp csvlint bash
|
18
|
+
|
19
|
+
# to enter the ruby REPL
|
20
|
+
docker run -it --rm -v %CD%:/tmp csvlint irb
|
@@ -1,37 +1,37 @@
|
|
1
|
-
Given(/^I have stubbed stdin to contain "(.*?)"$/) do |file|
|
2
|
-
expect(
|
1
|
+
Given(/^I have stubbed $stdin to contain "(.*?)"$/) do |file|
|
2
|
+
expect($stdin).to receive(:read).and_return(File.read(file))
|
3
3
|
end
|
4
4
|
|
5
|
-
Given(/^I have stubbed stdin to contain nothing$/) do
|
6
|
-
expect(
|
5
|
+
Given(/^I have stubbed $stdin to contain nothing$/) do
|
6
|
+
expect($stdin).to receive(:read).and_return(nil)
|
7
7
|
end
|
8
8
|
|
9
9
|
Then(/^nothing should be outputted to STDERR$/) do
|
10
|
-
expect(
|
10
|
+
expect($stderr).to_not receive(:puts)
|
11
11
|
end
|
12
12
|
|
13
13
|
Then(/^the output should contain JSON$/) do
|
14
14
|
@json = JSON.parse(all_stdout)
|
15
|
-
expect(@json[
|
15
|
+
expect(@json["validation"]).to be_present
|
16
16
|
end
|
17
17
|
|
18
18
|
Then(/^the JSON should have a state of "(.*?)"$/) do |state|
|
19
|
-
expect(@json[
|
19
|
+
expect(@json["validation"]["state"]).to eq(state)
|
20
20
|
end
|
21
21
|
|
22
22
|
Then(/^the JSON should have (\d+) errors?$/) do |count|
|
23
23
|
@index = count.to_i - 1
|
24
|
-
expect(@json[
|
24
|
+
expect(@json["validation"]["errors"].count).to eq(count.to_i)
|
25
25
|
end
|
26
26
|
|
27
27
|
Then(/^that error should have the "(.*?)" "(.*?)"$/) do |k, v|
|
28
|
-
expect(@json[
|
28
|
+
expect(@json["validation"]["errors"][@index][k].to_s).to eq(v)
|
29
29
|
end
|
30
30
|
|
31
31
|
Then(/^error (\d+) should have the "(.*?)" "(.*?)"$/) do |index, k, v|
|
32
|
-
expect(@json[
|
32
|
+
expect(@json["validation"]["errors"][index.to_i - 1][k].to_s).to eq(v)
|
33
33
|
end
|
34
34
|
|
35
35
|
Then(/^error (\d+) should have the constraint "(.*?)" "(.*?)"$/) do |index, k, v|
|
36
|
-
expect(@json[
|
36
|
+
expect(@json["validation"]["errors"][index.to_i - 1]["constraints"][k].to_s).to eq(v)
|
37
37
|
end
|
@@ -3,11 +3,11 @@ Given(/^the content type is "(.*?)"$/) do |arg1|
|
|
3
3
|
end
|
4
4
|
|
5
5
|
Then(/^the "(.*?)" should be "(.*?)"$/) do |type, encoding|
|
6
|
-
validator = Csvlint::Validator.new(
|
7
|
-
expect(
|
6
|
+
validator = Csvlint::Validator.new(@url, default_csv_options)
|
7
|
+
expect(validator.send(type.to_sym)).to eq(encoding)
|
8
8
|
end
|
9
9
|
|
10
10
|
Then(/^the metadata content type should be "(.*?)"$/) do |content_type|
|
11
|
-
validator = Csvlint::Validator.new(
|
12
|
-
expect(
|
11
|
+
validator = Csvlint::Validator.new(@url, default_csv_options)
|
12
|
+
expect(validator.headers["content-type"]).to eq(content_type)
|
13
13
|
end
|
@@ -12,31 +12,31 @@ Given(/^it is stored at the url "(.*?)"$/) do |url|
|
|
12
12
|
charset = @encoding || "UTF-8"
|
13
13
|
headers = {"Content-Type" => "#{content_type}; charset=#{charset}"}
|
14
14
|
headers["Link"] = @link if @link
|
15
|
-
stub_request(:get, url).to_return(:
|
16
|
-
stub_request(:get, URI.join(url,
|
17
|
-
stub_request(:get, url +
|
18
|
-
stub_request(:get, URI.join(url,
|
15
|
+
stub_request(:get, url).to_return(status: 200, body: @csv, headers: headers)
|
16
|
+
stub_request(:get, URI.join(url, "/.well-known/csvm")).to_return(status: 404)
|
17
|
+
stub_request(:get, url + "-metadata.json").to_return(status: 404)
|
18
|
+
stub_request(:get, URI.join(url, "csv-metadata.json")).to_return(status: 404)
|
19
19
|
end
|
20
20
|
|
21
21
|
Given(/^it is stored at the url "(.*?)" with no character set$/) do |url|
|
22
22
|
@url = url
|
23
23
|
content_type = @content_type || "text/csv"
|
24
|
-
stub_request(:get, url).to_return(:
|
25
|
-
stub_request(:get, URI.join(url,
|
26
|
-
stub_request(:get, url +
|
27
|
-
stub_request(:get, URI.join(url,
|
24
|
+
stub_request(:get, url).to_return(status: 200, body: @csv, headers: {"Content-Type" => content_type.to_s})
|
25
|
+
stub_request(:get, URI.join(url, "/.well-known/csvm")).to_return(status: 404)
|
26
|
+
stub_request(:get, url + "-metadata.json").to_return(status: 404)
|
27
|
+
stub_request(:get, URI.join(url, "csv-metadata.json")).to_return(status: 404)
|
28
28
|
end
|
29
29
|
|
30
30
|
When(/^I ask if the CSV is valid$/) do
|
31
31
|
@csv_options ||= default_csv_options
|
32
|
-
@validator = Csvlint::Validator.new(
|
32
|
+
@validator = Csvlint::Validator.new(@url, @csv_options)
|
33
33
|
@valid = @validator.valid?
|
34
34
|
end
|
35
35
|
|
36
36
|
Then(/^I should get the value of true$/) do
|
37
|
-
expect(
|
37
|
+
expect(@valid).to be(true)
|
38
38
|
end
|
39
39
|
|
40
40
|
Then(/^I should get the value of false$/) do
|
41
|
-
expect(
|
41
|
+
expect(@valid).to be(false)
|
42
42
|
end
|
@@ -10,24 +10,24 @@ end
|
|
10
10
|
|
11
11
|
Given(/^I have a metadata file called "([^"]*)"$/) do |filename|
|
12
12
|
@schema_type = :csvw_metadata
|
13
|
-
@schema_json = File.read(
|
13
|
+
@schema_json = File.read(File.join(File.dirname(__FILE__), "..", "fixtures", filename))
|
14
14
|
end
|
15
15
|
|
16
|
-
Given(/^the (schema|metadata) is stored at the url "(.*?)"$/) do |schema_type,schema_url|
|
16
|
+
Given(/^the (schema|metadata) is stored at the url "(.*?)"$/) do |schema_type, schema_url|
|
17
17
|
@schema_url = schema_url
|
18
|
-
stub_request(:get, @schema_url).to_return(:
|
18
|
+
stub_request(:get, @schema_url).to_return(status: 200, body: @schema_json.to_str)
|
19
19
|
end
|
20
20
|
|
21
21
|
Given(/^there is a file at "(.*?)" with the content:$/) do |url, content|
|
22
|
-
stub_request(:get, url).to_return(:
|
22
|
+
stub_request(:get, url).to_return(status: 200, body: content.to_str)
|
23
23
|
end
|
24
24
|
|
25
|
-
Given(/^I have a file called "(.*?)" at the url "(.*?)"$/) do |filename,url|
|
26
|
-
content = File.read(
|
27
|
-
content_type =
|
28
|
-
stub_request(:get, url).to_return(:
|
25
|
+
Given(/^I have a file called "(.*?)" at the url "(.*?)"$/) do |filename, url|
|
26
|
+
content = File.read(File.join(File.dirname(__FILE__), "..", "fixtures", filename))
|
27
|
+
content_type = /.csv$/.match?(filename) ? "text/csv" : "application/csvm+json"
|
28
|
+
stub_request(:get, url).to_return(status: 200, body: content, headers: {"Content-Type" => "#{content_type}; charset=UTF-8"})
|
29
29
|
end
|
30
30
|
|
31
31
|
Given(/^there is no file at the url "(.*?)"$/) do |url|
|
32
|
-
stub_request(:get, url).to_return(:
|
33
|
-
end
|
32
|
+
stub_request(:get, url).to_return(status: 404)
|
33
|
+
end
|
@@ -3,5 +3,5 @@ Given(/^it is parsed as a StringIO$/) do
|
|
3
3
|
end
|
4
4
|
|
5
5
|
Given(/^I parse a file called "(.*?)"$/) do |filename|
|
6
|
-
@url = File.new(
|
6
|
+
@url = File.new(File.join(File.dirname(__FILE__), "..", "fixtures", filename))
|
7
7
|
end
|
@@ -2,14 +2,14 @@ When(/^I ask if there are errors$/) do
|
|
2
2
|
@csv_options ||= default_csv_options
|
3
3
|
|
4
4
|
if @schema_json
|
5
|
-
if @schema_type == :json_table
|
6
|
-
|
5
|
+
@schema = if @schema_type == :json_table
|
6
|
+
Csvlint::Schema.from_json_table(@schema_url || "http://example.org ", JSON.parse(@schema_json))
|
7
7
|
else
|
8
|
-
|
8
|
+
Csvlint::Schema.from_csvw_metadata(@schema_url || "http://example.org ", JSON.parse(@schema_json))
|
9
9
|
end
|
10
10
|
end
|
11
11
|
|
12
|
-
@validator = Csvlint::Validator.new(
|
12
|
+
@validator = Csvlint::Validator.new(@url, @csv_options, @schema)
|
13
13
|
@errors = @validator.errors
|
14
14
|
end
|
15
15
|
|
@@ -19,10 +19,10 @@ When(/^I carry out CSVW validation$/) do
|
|
19
19
|
begin
|
20
20
|
if @schema_json
|
21
21
|
json = JSON.parse(@schema_json)
|
22
|
-
if @schema_type == :json_table
|
23
|
-
|
22
|
+
@schema = if @schema_type == :json_table
|
23
|
+
Csvlint::Schema.from_json_table(@schema_url || "http://example.org ", json)
|
24
24
|
else
|
25
|
-
|
25
|
+
Csvlint::Schema.from_csvw_metadata(@schema_url || "http://example.org ", json)
|
26
26
|
end
|
27
27
|
end
|
28
28
|
|
@@ -30,12 +30,12 @@ When(/^I carry out CSVW validation$/) do
|
|
30
30
|
@errors = []
|
31
31
|
@warnings = []
|
32
32
|
@schema.tables.keys.each do |table_url|
|
33
|
-
validator = Csvlint::Validator.new(
|
33
|
+
validator = Csvlint::Validator.new(table_url, @csv_options, @schema)
|
34
34
|
@errors += validator.errors
|
35
35
|
@warnings += validator.warnings
|
36
36
|
end
|
37
37
|
else
|
38
|
-
validator = Csvlint::Validator.new(
|
38
|
+
validator = Csvlint::Validator.new(@url, @csv_options, @schema)
|
39
39
|
@errors = validator.errors
|
40
40
|
@warnings = validator.warnings
|
41
41
|
end
|
@@ -49,42 +49,42 @@ end
|
|
49
49
|
Then(/^there should be errors$/) do
|
50
50
|
# this test is only used for CSVW testing; :invalid_encoding & :line_breaks mask lack of real errors
|
51
51
|
@errors.delete_if { |e| e.instance_of?(Csvlint::ErrorMessage) && [:invalid_encoding, :line_breaks].include?(e.type) }
|
52
|
-
expect(
|
52
|
+
expect(@errors.count).to be > 0
|
53
53
|
end
|
54
54
|
|
55
55
|
Then(/^there should not be errors$/) do
|
56
|
-
expect(
|
56
|
+
expect(@errors.count).to eq(0)
|
57
57
|
end
|
58
58
|
|
59
59
|
Then(/^there should be (\d+) error$/) do |count|
|
60
|
-
expect(
|
60
|
+
expect(@errors.count).to eq(count.to_i)
|
61
61
|
end
|
62
62
|
|
63
63
|
Then(/^that error should have the type "(.*?)"$/) do |type|
|
64
|
-
expect(
|
64
|
+
expect(@errors.first.type).to eq(type.to_sym)
|
65
65
|
end
|
66
66
|
|
67
67
|
Then(/^that error should have the row "(.*?)"$/) do |row|
|
68
|
-
expect(
|
68
|
+
expect(@errors.first.row).to eq(row.to_i)
|
69
69
|
end
|
70
70
|
|
71
71
|
Then(/^that error should have the column "(.*?)"$/) do |column|
|
72
|
-
expect(
|
72
|
+
expect(@errors.first.column).to eq(column.to_i)
|
73
73
|
end
|
74
74
|
|
75
75
|
Then(/^that error should have the content "(.*)"$/) do |content|
|
76
|
-
expect(
|
76
|
+
expect(@errors.first.content.chomp).to eq(content.chomp)
|
77
77
|
end
|
78
78
|
|
79
79
|
Then(/^that error should have no content$/) do
|
80
|
-
expect(
|
80
|
+
expect(@errors.first.content).to eq(nil)
|
81
81
|
end
|
82
82
|
|
83
83
|
Given(/^I have a CSV that doesn't exist$/) do
|
84
84
|
@url = "http//www.example.com/fake-csv.csv"
|
85
|
-
stub_request(:get, @url).to_return(:
|
85
|
+
stub_request(:get, @url).to_return(status: 404)
|
86
86
|
end
|
87
87
|
|
88
88
|
Then(/^there should be no "(.*?)" errors$/) do |type|
|
89
|
-
@errors.each
|
89
|
+
@errors.each { |error| error.type.should_not == type.to_sym }
|
90
90
|
end
|