Make Snapshot#crop return the snapshot of exact requested height

openid
Marcin Kulik 11 years ago
parent 7c9a9842af
commit 4767442875

@ -18,8 +18,13 @@ class Snapshot
end end
def crop(width, height) def crop(width, height)
height = [height, lines.size].min min_height = [height, lines.size].min
new_lines = lines.drop(lines.size - height).map { |line| line.crop(width) } new_lines = lines.drop(lines.size - min_height).map { |line| line.crop(width) }
while new_lines.size < height
new_lines << []
end
self.class.new(new_lines) self.class.new(new_lines)
end end

@ -98,9 +98,9 @@ describe Snapshot do
context "when height is greater than lines count" do context "when height is greater than lines count" do
let(:height) { 4 } let(:height) { 4 }
it 'returns a new Snapshot with all lines cropped' do it 'returns a new Snapshot with all lines cropped and missing lines added' do
expect(subject).to eq(Snapshot.new([cropped_line_1, cropped_line_2, expect(subject).to eq(Snapshot.new([cropped_line_1, cropped_line_2,
cropped_line_3])) cropped_line_3, []]))
end end
end end
end end

Loading…
Cancel
Save