2013-08-27 18:02:40 +00:00
|
|
|
require 'spec_helper'
|
|
|
|
|
|
|
|
describe Grid do
|
|
|
|
|
|
|
|
let(:grid) { described_class.new(data) }
|
|
|
|
|
|
|
|
let(:data) { [
|
2013-09-16 14:24:13 +00:00
|
|
|
%w[a b c ć],
|
|
|
|
%w[de ff],
|
|
|
|
%w[ghiî],
|
|
|
|
%w[j k l m]
|
2013-08-27 18:02:40 +00:00
|
|
|
] }
|
|
|
|
|
|
|
|
describe '#width' do
|
2013-09-16 14:24:13 +00:00
|
|
|
let(:data) { [ %w[a bc def] ] }
|
|
|
|
|
2013-08-27 18:02:40 +00:00
|
|
|
subject { grid.width }
|
|
|
|
|
2013-09-16 14:24:13 +00:00
|
|
|
it { should eq(6) }
|
2013-08-27 18:02:40 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
describe '#height' do
|
|
|
|
subject { grid.height }
|
|
|
|
|
|
|
|
it { should eq(4) }
|
|
|
|
end
|
|
|
|
|
|
|
|
describe '#crop' do
|
2013-09-16 14:24:13 +00:00
|
|
|
let(:expected) { described_class.new([%w[e f], %w[hi], %w[k l]]).lines }
|
2013-08-27 18:02:40 +00:00
|
|
|
|
2013-09-16 14:24:13 +00:00
|
|
|
it 'crops the lines properly' do
|
|
|
|
expect(grid.crop(1, 1, 2, 3).lines).to eq(expected)
|
|
|
|
end
|
2013-08-27 18:02:40 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
describe '#diff' do
|
|
|
|
let(:line_a) { [:a, :b, :c] }
|
|
|
|
let(:line_b) { [:d, :e, :f] }
|
|
|
|
let(:line_c) { [:g, :h, :i] }
|
|
|
|
|
|
|
|
let(:grid) { described_class.new([line_a, line_b, line_c]) }
|
|
|
|
|
2013-09-10 19:29:17 +00:00
|
|
|
let(:line_d) { [:A, :b, :c] }
|
|
|
|
let(:line_e) { [:g, :H, :i] }
|
2013-08-27 18:02:40 +00:00
|
|
|
|
2013-09-10 19:29:17 +00:00
|
|
|
let(:other) { described_class.new([line_d, line_b, line_e]) }
|
2013-08-27 18:02:40 +00:00
|
|
|
|
|
|
|
subject { grid.diff(other) }
|
|
|
|
|
2013-09-10 19:29:17 +00:00
|
|
|
it 'returns only the lines that have changed from the other grid' do
|
|
|
|
should eq({ 0 => line_a, 2 => line_c })
|
|
|
|
end
|
|
|
|
|
|
|
|
context "when other is nil" do
|
|
|
|
let(:other) { nil }
|
2013-08-27 18:02:40 +00:00
|
|
|
|
2013-09-10 19:29:17 +00:00
|
|
|
it 'returns all the lines' do
|
|
|
|
should eq({ 0 => line_a, 1 => line_b, 2 => line_c })
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
2013-08-27 18:02:40 +00:00
|
|
|
|
2013-09-10 19:29:17 +00:00
|
|
|
describe '#as_json' do
|
|
|
|
subject { grid.as_json }
|
2013-08-27 18:02:40 +00:00
|
|
|
|
2013-09-16 14:24:13 +00:00
|
|
|
it { should eq([%w[a b c ć], %w[de ff], %w[ghiî], %w[j k l m]]) }
|
2013-08-27 18:02:40 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
end
|