Skip to content

Commit

Permalink
Merge pull request #7 from theodi/feature-detect-blank-rows
Browse files Browse the repository at this point in the history
Looks good, merged
  • Loading branch information
ldodds committed Jan 8, 2014
2 parents ba034f4 + a61a047 commit 5289b3a
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 2 deletions.
15 changes: 14 additions & 1 deletion features/validation_errors.feature
Original file line number Diff line number Diff line change
Expand Up @@ -32,4 +32,17 @@ Feature: Get validation errors
When I ask if there are errors
Then there should be 1 error
And that error should have the type "whitespace"
And that error should have the position "1"
And that error should have the position "1"

Scenario: Successfully report a CSV with blank rows
Given I have a CSV with the following content:
"""
"Foo","Bar","Baz"
"","",
"Baz","Bar","Foo"
"""
And it is stored at the url "http://example.com/example1.csv"
When I ask if there are errors
Then there should be 1 error
And that error should have the type "blank_rows"
And that error should have the position "2"
4 changes: 3 additions & 1 deletion lib/csvlint.rb
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ def validate
row = CSV.parse( line )[0]
expected_columns = row.count unless expected_columns != 0
build_errors(:ragged_rows, current_line) if row.count != expected_columns
build_errors(:blank_rows, current_line) if row.reject{ |c| c.nil? || c.empty? }.count == 0
rescue CSV::MalformedCSVError => e
type = fetch_error(e)
build_errors(type, current_line)
Expand Down Expand Up @@ -68,4 +69,5 @@ def fetch_error(error)
end

end
end

end

0 comments on commit 5289b3a

Please sign in to comment.