diff --git a/lib/squib/input_helpers.rb b/lib/squib/input_helpers.rb index fa9dc88..7b0d461 100644 --- a/lib/squib/input_helpers.rb +++ b/lib/squib/input_helpers.rb @@ -221,7 +221,11 @@ module Squib def rowify(opts) unless opts[:rows].respond_to? :to_i raise "Columns must be an integer" unless opts[:columns].respond_to? :to_i - opts[:rows] = (@cards.size / opts[:columns].to_i).ceil + if @cards.size < opts[:columns].to_i + opts[:rows] = 1 + else + opts[:rows] = (@cards.size / opts[:columns].to_i).ceil + end end opts end diff --git a/spec/input_helpers_spec.rb b/spec/input_helpers_spec.rb index be70d37..b682404 100644 --- a/spec/input_helpers_spec.rb +++ b/spec/input_helpers_spec.rb @@ -182,19 +182,30 @@ describe Squib::InputHelpers do end context '#rowify' do + before(:each) do + @default_opts = { rows: :infinite, columns: 5 } + end + it 'does nothing on an integer' do - opts = @deck.send(:rowify, {columns: 2, rows: 2}) + opts = @deck.send(:rowify, @default_opts.merge({columns: 2, rows: 2})) expect(opts).to eq({ columns: 2, rows: 2 }) end it 'computes properly on non-integer' do - opts = @deck.send(:rowify, {columns: 1, rows: :infinite}) + opts = @deck.send(:rowify, @default_opts.merge({columns: 1, rows: :infinite})) expect(opts).to eq({ columns: 1, rows: 2 }) end + + it 'computes properly on unspecified rows' do + opts = @deck.send(:rowify, @default_opts.merge({columns: 3})) + expect(opts).to eq({ columns: 3, + rows: 1 + }) + end end context '#faceify' do