require 'spec_helper' module Diagnostics describe DataGroup do describe '#attributes' do context 'with no attributes set' do it 'returns an empty array' do subject.attributes.should eq([]) end end context 'given :plain format' do let(:data_group) { create_data_group } specify do data_group.attributes(:plain).should eq(['a: 1', 'b: 2']) end end context 'given :html format' do let(:data_group) { create_data_group } specify do data_group.attributes(:html).should eq( ['a: 1', 'b: 2'] ) end end def create_data_group data_group = subject data_group['a'] = 1 data_group['b'] = 2 data_group end end describe '#lists' do context 'with no lists added' do it 'returns an empty array' do subject.lists.should eq([]) end end context 'given :plain format' do let(:data_group) { create_data_group } specify do data_group.lists(:plain).should eq( ["a\nb\nc", "1\n2\n3"] ) end end context 'given :html format' do let(:data_group) { create_data_group } specify do data_group.lists(:html).should eq( ['a
b
c', '1
2
3'] ) end end def create_data_group data_group = subject data_group << ['a', 'b', 'c'] data_group << [1, 2, 3] data_group end end describe '#texts' do context 'with no texts added' do it 'returns an empty array' do subject.texts.should eq([]) end end context 'given :plain format' do let(:data_group) { create_data_group } specify do data_group.texts(:plain).should eq(['a', 'b']) end end context 'given :html format' do let(:data_group) { create_data_group } specify do data_group.texts(:html).should eq( ['

a

', '

b

'] ) end end def create_data_group data_group = subject data_group << 'a' data_group << 'b' data_group end end describe '#tables' do context 'with no texts added' do it 'returns an empty array' do subject.tables.should eq([]) end end context 'given :html format' do let(:data_group) { create_data_group } specify do data_group.tables(:html).should eq( [ '' \ '' \ '' \ '' \ '' \ '' \ '' \ '' \ '' \ '' \ '' \ '' \ '' \ '
heading 1heading 2
13
2
' \ ] ) end end def create_data_group data_group = subject data_group << { 'heading 1' => [1,2], 'heading 2' => [3, nil] } data_group end end describe '#[]=' do it 'adds an instance of Data::Attribute' do data_group = subject data_group['key'] = 'value' data_group.should have(1).attributes data_group.attributes[0].should be_an_instance_of(Data::Attribute) end end describe '#<<' do context 'given an array' do it 'adds an instance of Data::List' do data_group = subject data_group << [1,2,3] data_group.should have(1).lists data_group.lists[0].should be_an_instance_of(Data::List) end end context 'given a string' do it 'adds an instance of Data::Text' do data_group = subject data_group << "a string" data_group.should have(1).texts data_group.texts[0].should be_an_instance_of(Data::Text) end end end end end