Skip to content

Commit

Permalink
Add deprecation warning
Browse files Browse the repository at this point in the history
WrapExcel::Book.new and WrapExcel::Book.open will be split.
WrapExcel::Book.new will be used create new excel file.
  • Loading branch information
tomiacannondale committed Mar 11, 2013
1 parent 34d0625 commit b26ba58
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 0 deletions.
4 changes: 4 additions & 0 deletions lib/wrap_excel/book.rb
Expand Up @@ -11,6 +11,10 @@ def open(file, options={ }, &block)
end

def initialize(file, options={ }, &block)
unless caller[1] =~ /book.rb:\d+:in\s+`open'$/
warn "DEPRECATION WARNING: WrapExcel::Book.new and WrapExcel::Book.open will be split. If you open existing file, please use WrapExcel::Book.open.(call from #{caller[1]})"
end

@options = {
:read_only => true,
:displayalerts => false,
Expand Down
16 changes: 16 additions & 0 deletions spec/book_spec.rb
Expand Up @@ -54,6 +54,22 @@
end
end

it 'should not output deprecation warning' do
capture(:stderr) {
book = WrapExcel::Book.open(@simple_file)
book.close
}.should eq ""
end

end

describe ".new" do
it 'should output deprecation warning' do
capture(:stderr) {
book = WrapExcel::Book.new(@simple_file)
book.close
}.should match /DEPRECATION WARNING: WrapExcel::Book.new and WrapExcel::Book.open will be split. If you open existing file, please use WrapExcel::Book.open.\(call from #{File.expand_path(__FILE__)}:#{__LINE__ - 2}.+\)\n/
end
end

describe 'access sheet' do
Expand Down

0 comments on commit b26ba58

Please sign in to comment.