From 8b70e86e22654dc3cd29d1eea1a2b3e7239b26be Mon Sep 17 00:00:00 2001 From: Martijn Storck Date: Fri, 16 Apr 2021 13:36:54 +0200 Subject: [PATCH] Direct users to Workbook.open --- lib/xsv/workbook.rb | 2 ++ test/workbook_test.rb | 6 ++++++ 2 files changed, 8 insertions(+) diff --git a/lib/xsv/workbook.rb b/lib/xsv/workbook.rb index d18285f..0ee7e86 100644 --- a/lib/xsv/workbook.rb +++ b/lib/xsv/workbook.rb @@ -42,6 +42,8 @@ def self.open(data, **kws) # trim_empty_rows (false) Scan sheet for end of content and don't return trailing rows # def initialize(zip, trim_empty_rows: false) + raise ArgumentError, "Passed argument is not an instance of Zip::File. Did you mean to use Workbook.open?" unless zip.is_a?(Zip::File) + @zip = zip @trim_empty_rows = trim_empty_rows diff --git a/test/workbook_test.rb b/test/workbook_test.rb index af916ba..3edd045 100644 --- a/test/workbook_test.rb +++ b/test/workbook_test.rb @@ -58,4 +58,10 @@ def test_open_without_shared_strings @workbook = Xsv::Workbook.open("test/files/no-shared-strings.xlsx") refute_empty @workbook.sheets end + + def test_new_instead_of_open + assert_raises ArgumentError do + Xsv::Workbook.new "not a Zip::File instance" + end + end end