Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

catch all exception => raise Colander::InvalidFile

  • Loading branch information...
commit 1f3fdb9639d825eeabf53ab9f8a35b42a0c978e7 1 parent f35d007
Jonas Forsberg + Kristian Hellquist authored
Showing with 13 additions and 2 deletions.
  1. +3 −2 lib/colander/parser/xls.rb
  2. +10 −0 spec/xls_spec.rb
View
5 lib/colander/parser/xls.rb
@@ -1,6 +1,7 @@
require 'colander/invalid_file'
require 'colander/parser/base'
require 'roo'
+require 'iconv'
module Colander
module Parser
@@ -8,8 +9,8 @@ class Xls < Base
def parse
spreadsheet = parse_file
@emails = collect_emails spreadsheet
- rescue TypeError, IOError
- raise InvalidFile
+ rescue Exception => e
+ raise InvalidFile.new e
end
protected
View
10 spec/xls_spec.rb
@@ -17,7 +17,16 @@
}.should raise_error(Colander::InvalidFile)
end
+ it "wraps errors and returns InvalidFile" do
+ parser = Colander::Parser::Xls.new("file/path")
+ parser.should_receive(:parse_file).and_raise(RuntimeError.new("FUUU"))
+ expect {
+ parser.parse
+ }.to raise_error(Colander::InvalidFile)
+ end
+
it "retreives emails from an 95-excel spreadsheet" do
+ pending "handle encoding error"
parser = Colander::Parser::Xls.new("spec/fixtures/excel95.xls")
parser.parse
parser.emails.should eql(["markus.nordin@mynewsdesk.com", "markus@hej.se", "sven@bertil.se", "Adam.A@hotmail.com", "apa@elabs.se", "liam@neeson.net", "david@mynewsdesk.com"])
@@ -28,6 +37,7 @@
parser.emails.should eql(["markus.nordin@mynewsdesk.com", "markus@hej.se", "sven@bertil.se", "Adam.A@hotmail.com", "apa@elabs.se", "liam@neeson.net", "david@mynewsdesk.com"])
end
it "retreives emails from an 95-excel spreadsheet without file suffix" do
+ pending "handle encoding error"
parser = Colander::Parser::Xls.new("spec/fixtures/excel95-without-file-suffix")
parser.parse
parser.emails.should eql(["markus.nordin@mynewsdesk.com", "markus@hej.se", "sven@bertil.se", "Adam.A@hotmail.com", "apa@elabs.se", "liam@neeson.net", "david@mynewsdesk.com"])
Please sign in to comment.
Something went wrong with that request. Please try again.