csvlint 1.0.0 → 1.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (49) hide show
  1. checksums.yaml +4 -4
  2. data/.github/dependabot.yml +4 -0
  3. data/.github/workflows/push.yml +14 -2
  4. data/.ruby-version +1 -1
  5. data/.standard_todo.yml +43 -0
  6. data/Dockerfile +16 -0
  7. data/Gemfile +2 -2
  8. data/README.md +9 -9
  9. data/Rakefile +7 -7
  10. data/csvlint.gemspec +14 -16
  11. data/docker_notes_for_windows.txt +20 -0
  12. data/features/step_definitions/cli_steps.rb +11 -11
  13. data/features/step_definitions/information_steps.rb +4 -4
  14. data/features/step_definitions/parse_csv_steps.rb +11 -11
  15. data/features/step_definitions/schema_validation_steps.rb +10 -10
  16. data/features/step_definitions/sources_steps.rb +1 -1
  17. data/features/step_definitions/validation_errors_steps.rb +19 -19
  18. data/features/step_definitions/validation_info_steps.rb +9 -9
  19. data/features/step_definitions/validation_warnings_steps.rb +11 -11
  20. data/features/support/aruba.rb +6 -6
  21. data/features/support/earl_formatter.rb +39 -39
  22. data/features/support/env.rb +10 -11
  23. data/features/support/load_tests.rb +107 -103
  24. data/features/support/webmock.rb +2 -2
  25. data/lib/csvlint/cli.rb +133 -130
  26. data/lib/csvlint/csvw/column.rb +279 -280
  27. data/lib/csvlint/csvw/date_format.rb +90 -92
  28. data/lib/csvlint/csvw/metadata_error.rb +1 -3
  29. data/lib/csvlint/csvw/number_format.rb +40 -32
  30. data/lib/csvlint/csvw/property_checker.rb +714 -717
  31. data/lib/csvlint/csvw/table.rb +49 -52
  32. data/lib/csvlint/csvw/table_group.rb +24 -23
  33. data/lib/csvlint/error_collector.rb +2 -0
  34. data/lib/csvlint/error_message.rb +0 -1
  35. data/lib/csvlint/field.rb +153 -141
  36. data/lib/csvlint/schema.rb +34 -42
  37. data/lib/csvlint/validate.rb +161 -143
  38. data/lib/csvlint/version.rb +1 -1
  39. data/lib/csvlint.rb +22 -23
  40. data/spec/csvw/column_spec.rb +15 -16
  41. data/spec/csvw/date_format_spec.rb +5 -7
  42. data/spec/csvw/number_format_spec.rb +2 -4
  43. data/spec/csvw/table_group_spec.rb +103 -105
  44. data/spec/csvw/table_spec.rb +71 -73
  45. data/spec/field_spec.rb +116 -121
  46. data/spec/schema_spec.rb +129 -139
  47. data/spec/spec_helper.rb +6 -6
  48. data/spec/validator_spec.rb +167 -190
  49. metadata +22 -55
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 651e0cab26de36c97d333823f6ac72ad1377397e5e5dbf02397725fd8b42d663
4
- data.tar.gz: cf81fa72bc040e242e947c8abb7009f7dd8ec6d5c9f08c21c9177eb62ab9c648
3
+ metadata.gz: 7f9c598fca283466c50e65c4b436166fccb0e9e0340d3d370fb3f4e814cf1f3e
4
+ data.tar.gz: 321481d47fca1f6ef1df7963e5d705ce05685a9861e48d954397eb288f46541a
5
5
  SHA512:
6
- metadata.gz: dbe214a6737375e2e5f4b6c08c63345ce850eaaea30373fab732a8352b84e58f862af5490d39dc18415f0256b92d0625c51c8e61ade9d2ef562050239340d985
7
- data.tar.gz: 79296f466687b53a26a3e1c402a2ac7a6f2c2f999092a11567c897d71e3b78eca592cba97da211af5226e09ffd7086ed2cf0433cdeb14ad8c0635e5f6b55a7b8
6
+ metadata.gz: 1e9f755b174f3c1b3052f43621e8c15cf3a3b947a5a611f370b42f309492797664a622886520a7d209d109f271a2d101aaa24017529900c82d76a71b8cb46173
7
+ data.tar.gz: 73da87ddbbc71a1e62f90ffaebca3947833921f546dcb01524bd464c7fbf1a3dbf086757443838e6ec401bac86e5cacf26a9e3b397904ba9ee32a0688c4271a0
@@ -5,3 +5,7 @@ updates:
5
5
  schedule:
6
6
  interval: daily
7
7
  open-pull-requests-limit: 10
8
+ - package-ecosystem: github-actions
9
+ directory: "/"
10
+ schedule:
11
+ interval: weekly
@@ -9,10 +9,10 @@ jobs:
9
9
  runs-on: ubuntu-latest
10
10
  strategy:
11
11
  matrix:
12
- ruby-version: ['2.5', '2.6', '2.7', '3.0', '3.1']
12
+ ruby-version: ['2.5', '2.6', '2.7', '3.0', '3.1', '3.2']
13
13
  fail-fast: false
14
14
  steps:
15
- - uses: actions/checkout@v2
15
+ - uses: actions/checkout@v3
16
16
  - uses: ruby/setup-ruby@v1
17
17
  with:
18
18
  bundler-cache: true
@@ -21,3 +21,15 @@ jobs:
21
21
  run: bundle install
22
22
  - name: Run the tests
23
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/.ruby-version CHANGED
@@ -1 +1 @@
1
- 3.1.2
1
+ 3.2.0
@@ -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/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
@@ -1,4 +1,4 @@
1
- source 'https://rubygems.org'
1
+ source "https://rubygems.org"
2
2
 
3
3
  # Specify your gem's dependencies in csvlint.rb.gemspec
4
- gemspec
4
+ gemspec
data/README.md CHANGED
@@ -1,6 +1,6 @@
1
- [![Build Status](http://img.shields.io/travis/theodi/csvlint.rb.svg)](https://travis-ci.org/theodi/csvlint.rb)
2
- [![Dependency Status](http://img.shields.io/gemnasium/theodi/csvlint.rb.svg)](https://gemnasium.com/theodi/csvlint.rb)
3
- [![Coverage Status](http://img.shields.io/coveralls/theodi/csvlint.rb.svg)](https://coveralls.io/r/theodi/csvlint.rb)
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
 
@@ -10,14 +10,14 @@ A ruby gem to support validating CSV files to check their syntax and contents. Y
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.1.4`
20
+ `ruby version 3.2`
21
21
 
22
22
  ### Tests
23
23
 
@@ -71,7 +71,7 @@ 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'
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
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
76
 
77
77
  You will then see the validation result, together with any warnings or errors e.g.
@@ -213,7 +213,7 @@ An example JSON Table Schema schema file is:
213
213
  "name": "price",
214
214
  "constraints": {
215
215
  "required": true,
216
- "minLength": 1
216
+ "minLength": 1
217
217
  }
218
218
  },
219
219
  {
data/Rakefile CHANGED
@@ -1,12 +1,12 @@
1
1
  require "bundler/gem_tasks"
2
2
 
3
- $:.unshift File.join( File.dirname(__FILE__), "lib")
3
+ $:.unshift File.join(File.dirname(__FILE__), "lib")
4
4
 
5
- require 'rubygems'
6
- require 'cucumber'
7
- require 'cucumber/rake/task'
8
- require 'coveralls/rake/task'
9
- require 'rspec/core/rake_task'
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 :default => [:spec, :features, 'coveralls:push']
17
+ task default: [:spec, :features, "coveralls:push"]
data/csvlint.gemspec CHANGED
@@ -1,24 +1,22 @@
1
- # coding: utf-8
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 'csvlint/version'
3
+ require "csvlint/version"
5
4
 
6
5
  Gem::Specification.new do |spec|
7
- spec.name = "csvlint"
8
- spec.version = Csvlint::VERSION
9
- spec.authors = ["pezholio"]
10
- spec.email = ["pezholio@gmail.com"]
11
- spec.description = %q{CSV Validator}
12
- spec.summary = %q{CSV Validator}
13
- spec.homepage = "https://github.com/theodi/csvlint.rb"
14
- spec.license = "MIT"
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 = `git ls-files`.split($/)
17
- spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
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 = ['>= 2.5', '< 3.2']
19
+ spec.required_ruby_version = [">= 2.5", "< 3.3"]
22
20
 
23
21
  spec.add_dependency "rainbow"
24
22
  spec.add_dependency "open_uri_redirections"
@@ -48,5 +46,5 @@ Gem::Specification.new do |spec|
48
46
  spec.add_development_dependency "rdf", "< 4.0"
49
47
  spec.add_development_dependency "rdf-turtle"
50
48
  spec.add_development_dependency "henry"
51
-
49
+ spec.add_development_dependency "standardrb"
52
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(STDIN).to receive(:read).and_return(File.read(file))
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(STDIN).to receive(:read).and_return(nil)
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(STDERR).to_not receive(:puts)
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['validation']).to be_present
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['validation']['state']).to eq(state)
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['validation']['errors'].count).to eq(count.to_i)
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['validation']['errors'][@index][k].to_s).to eq(v)
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['validation']['errors'][index.to_i - 1][k].to_s).to eq(v)
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['validation']['errors'][index.to_i - 1]['constraints'][k].to_s).to eq(v)
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( @url, default_csv_options )
7
- expect( validator.send(type.to_sym) ).to eq( encoding )
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( @url, default_csv_options )
12
- expect( validator.headers['content-type'] ).to eq( content_type )
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(: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)
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(:status => 200, :body => @csv, :headers => {"Content-Type" => "#{content_type}"})
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)
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( @url, @csv_options )
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( @valid ).to be(true)
37
+ expect(@valid).to be(true)
38
38
  end
39
39
 
40
40
  Then(/^I should get the value of false$/) do
41
- expect( @valid ).to be(false)
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( File.join( File.dirname(__FILE__), "..", "fixtures", filename ) )
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(:status => 200, :body => @schema_json.to_str)
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(:status => 200, :body => content.to_str)
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( File.join( File.dirname(__FILE__), "..", "fixtures", filename ) )
27
- content_type = filename =~ /.csv$/ ? "text/csv" : "application/csvm+json"
28
- stub_request(:get, url).to_return(:status => 200, :body => content, :headers => {"Content-Type" => "#{content_type}; charset=UTF-8"})
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(:status => 404)
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( File.join( File.dirname(__FILE__), "..", "fixtures", filename ) )
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
- @schema = Csvlint::Schema.from_json_table( @schema_url || "http://example.org ", JSON.parse(@schema_json) )
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
- @schema = Csvlint::Schema.from_csvw_metadata( @schema_url || "http://example.org ", JSON.parse(@schema_json) )
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( @url, @csv_options, @schema )
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
- @schema = Csvlint::Schema.from_json_table( @schema_url || "http://example.org ", json )
22
+ @schema = if @schema_type == :json_table
23
+ Csvlint::Schema.from_json_table(@schema_url || "http://example.org ", json)
24
24
  else
25
- @schema = Csvlint::Schema.from_csvw_metadata( @schema_url || "http://example.org ", json )
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( table_url, @csv_options, @schema )
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( @url, @csv_options, @schema )
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( @errors.count ).to be > 0
52
+ expect(@errors.count).to be > 0
53
53
  end
54
54
 
55
55
  Then(/^there should not be errors$/) do
56
- expect( @errors.count ).to eq(0)
56
+ expect(@errors.count).to eq(0)
57
57
  end
58
58
 
59
59
  Then(/^there should be (\d+) error$/) do |count|
60
- expect( @errors.count ).to eq( count.to_i )
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( @errors.first.type ).to eq( type.to_sym )
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( @errors.first.row ).to eq( row.to_i )
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( @errors.first.column ).to eq( column.to_i )
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( @errors.first.content.chomp ).to eq( content.chomp )
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( @errors.first.content ).to eq( nil )
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(:status => 404)
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 do |error| error.type.should_not == type.to_sym end
89
+ @errors.each { |error| error.type.should_not == type.to_sym }
90
90
  end
@@ -1,22 +1,22 @@
1
1
  Given(/^I ask if there are info messages$/) do
2
2
  @csv_options ||= default_csv_options
3
-
3
+
4
4
  if @schema_json
5
- if @schema_type == :json_table
6
- @schema = Csvlint::Schema.from_json_table( @schema_url || "http://example.org ", JSON.parse(@schema_json) )
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
- @schema = Csvlint::Schema.from_csvw_metadata( @schema_url || "http://example.org ", JSON.parse(@schema_json) )
8
+ Csvlint::Schema.from_csvw_metadata(@schema_url || "http://example.org ", JSON.parse(@schema_json))
9
9
  end
10
10
  end
11
-
12
- @validator = Csvlint::Validator.new( @url, @csv_options, @schema )
11
+
12
+ @validator = Csvlint::Validator.new(@url, @csv_options, @schema)
13
13
  @info_messages = @validator.info_messages
14
14
  end
15
15
 
16
16
  Then(/^there should be (\d+) info messages?$/) do |num|
17
- expect( @info_messages.count ).to eq( num.to_i )
17
+ expect(@info_messages.count).to eq(num.to_i)
18
18
  end
19
19
 
20
20
  Then(/^one of the messages should have the type "(.*?)"$/) do |msg_type|
21
- expect( @info_messages.find{|x| x.type == msg_type.to_sym} ).to be_present
22
- end
21
+ expect(@info_messages.find { |x| x.type == msg_type.to_sym }).to be_present
22
+ end
@@ -12,35 +12,35 @@ Given(/^I do not set an encoding header$/) do
12
12
  end
13
13
 
14
14
  Given(/^I have a CSV file called "(.*?)"$/) do |filename|
15
- @csv = File.read( File.join( File.dirname(__FILE__), "..", "fixtures", filename ) )
15
+ @csv = File.read(File.join(File.dirname(__FILE__), "..", "fixtures", filename))
16
16
  end
17
17
 
18
18
  When(/^I ask if there are warnings$/) do
19
19
  @csv_options ||= default_csv_options
20
20
  if @schema_json
21
- if @schema_type == :json_table
22
- @schema = Csvlint::Schema.from_json_table( @schema_url || "http://example.org ", JSON.parse(@schema_json) )
21
+ @schema = if @schema_type == :json_table
22
+ Csvlint::Schema.from_json_table(@schema_url || "http://example.org ", JSON.parse(@schema_json))
23
23
  else
24
- @schema = Csvlint::Schema.from_csvw_metadata( @schema_url || "http://example.org ", JSON.parse(@schema_json) )
24
+ Csvlint::Schema.from_csvw_metadata(@schema_url || "http://example.org ", JSON.parse(@schema_json))
25
25
  end
26
26
  end
27
27
 
28
- @validator = Csvlint::Validator.new( @url, @csv_options, @schema )
28
+ @validator = Csvlint::Validator.new(@url, @csv_options, @schema)
29
29
  @warnings = @validator.warnings
30
30
  end
31
31
 
32
32
  Then(/^there should be warnings$/) do
33
- expect( @warnings.count ).to be > 0
33
+ expect(@warnings.count).to be > 0
34
34
  end
35
35
 
36
36
  Then(/^there should not be warnings$/) do
37
37
  # this test is only used for CSVW testing, and :inconsistent_values warnings don't count in CSVW
38
38
  @warnings.delete_if { |w| [:inconsistent_values, :check_options].include?(w.type) }
39
- expect( @warnings.count ).to eq(0)
39
+ expect(@warnings.count).to eq(0)
40
40
  end
41
41
 
42
42
  Then(/^there should be (\d+) warnings$/) do |count|
43
- expect( @warnings.count ).to eq( count.to_i )
43
+ expect(@warnings.count).to eq(count.to_i)
44
44
  end
45
45
 
46
46
  Given(/^the content type is set to "(.*?)"$/) do |type|
@@ -48,13 +48,13 @@ Given(/^the content type is set to "(.*?)"$/) do |type|
48
48
  end
49
49
 
50
50
  Then(/^that warning should have the row "(.*?)"$/) do |row|
51
- expect( @warnings.first.row ).to eq( row.to_i )
51
+ expect(@warnings.first.row).to eq(row.to_i)
52
52
  end
53
53
 
54
54
  Then(/^that warning should have the column "(.*?)"$/) do |column|
55
- expect( @warnings.first.column ).to eq( column.to_i )
55
+ expect(@warnings.first.column).to eq(column.to_i)
56
56
  end
57
57
 
58
58
  Then(/^that warning should have the type "(.*?)"$/) do |type|
59
- expect( @warnings.first.type ).to eq( type.to_sym )
59
+ expect(@warnings.first.type).to eq(type.to_sym)
60
60
  end