Skip to content

Commit

Permalink
Fail expressively when #row_with fails to find the headers. #129
Browse files Browse the repository at this point in the history
  • Loading branch information
Empact committed Nov 17, 2014
1 parent 8d49197 commit 4e7d7d1
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 8 deletions.
5 changes: 4 additions & 1 deletion CHANGELOG
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,10 @@
* Extend Roo::Spreadsheet.open to accept Tempfiles and other arguments responding to #path. Note they require an :extension option to be declared, as the tempfile mangles the extension. #84.

* bugfixes
* Fix that paths with spaces in them would fail with URI::InvalidURIError. #121.
* Fix that paths with spaces in them would fail with
URI::InvalidURIError. #121.
# Fix that #parse-ing with a hash of columns not in the document
would fail mysteriously. #129

== 1.13.2 2013-12-23

Expand Down
1 change: 1 addition & 0 deletions lib/roo/base.rb
Original file line number Diff line number Diff line change
Expand Up @@ -490,6 +490,7 @@ def row_with(query,return_headers=false)
raise "Couldn't find header row."
end
end
raise "Couldn't find header row."
end

protected
Expand Down
34 changes: 27 additions & 7 deletions spec/lib/roo/excelx_spec.rb
Original file line number Diff line number Diff line change
@@ -1,19 +1,20 @@
require 'spec_helper'

describe Roo::Excelx do
subject(:xlsx) {
Roo::Excelx.new(path)
}


describe '.new' do
subject {
Roo::Excelx.new('test/files/numbers1.xlsx')
}
let(:path) { 'test/files/numeric-link.xlsx' }

it 'creates an instance' do
expect(subject).to be_a(Roo::Excelx)
end

context 'given a file with missing rels' do
subject {
Roo::Excelx.new('test/files/file_item_error.xlsx')
}
let(:path) { 'test/files/file_item_error.xlsx' }

it 'creates an instance' do
expect(subject).to be_a(Roo::Excelx)
Expand All @@ -24,8 +25,10 @@
describe '#cell' do
context 'for a link cell' do
context 'with numeric contents' do
let(:path) { 'test/files/numeric-link.xlsx' }

subject {
Roo::Excelx.new('test/files/numeric-link.xlsx').cell('A', 1)
xlsx.cell('A', 1)
}

it 'returns a link with the number as a string value' do
Expand All @@ -35,4 +38,21 @@
end
end
end

describe '#parse' do
let(:path) { 'test/files/numeric-link.xlsx' }

context 'with a columns hash' do
context 'when not present in the sheet' do
it 'does not raise' do
expect {
xlsx.sheet(0).parse(
this: "This",
that: "That"
)
}.to raise_error("Couldn't find header row.")
end
end
end
end
end

0 comments on commit 4e7d7d1

Please sign in to comment.