Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

#ruby3_each_with_pagename fixed and test added #588

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 2 additions & 5 deletions lib/roo/base.rb
Original file line number Diff line number Diff line change
Expand Up @@ -250,11 +250,8 @@ def sheet(index, name = false)

# iterate through all worksheets of a document
def each_with_pagename
Enumerator.new do |yielder|
sheets.each do |s|
yielder << sheet(s, true)
end
end
return to_enum(:each_with_pagename) { sheets.size } unless block_given?
sheets.each { |x| yield(sheet(x, true)) }
end

# by passing in headers as options, this method returns
Expand Down
20 changes: 16 additions & 4 deletions spec/lib/roo/base_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -183,10 +183,22 @@ def sheets
end

describe '#each_with_pagename' do
it 'should return an enumerator with all the rows' do
each_with_pagename = spreadsheet.each_with_pagename
expect(each_with_pagename).to be_a(Enumerator)
expect(each_with_pagename.to_a.last).to eq([spreadsheet.default_sheet, spreadsheet])
context 'when block given' do
it 'iterate with sheet and sheet_name' do
sheet_names = []
spreadsheet.each_with_pagename do |sheet_name, sheet|
sheet_names.push(sheet_name)
end
expect(sheet_names).to eq ['my_sheet', 'blank sheet']
end
end

context 'when called without block' do
it 'should return an enumerator with all the rows' do
each_with_pagename = spreadsheet.each_with_pagename
expect(each_with_pagename).to be_a(Enumerator)
expect(each_with_pagename.to_a.last).to eq([spreadsheet.default_sheet, spreadsheet])
end
end
end

Expand Down