Sha256: 8e0cbd8e8ea8d44124989f7e6eb587cef729378bf16e42386ebdf60e7832c21e

Contents?: true

Size: 1.9 KB

Versions: 3

Compression:

Stored size: 1.9 KB

Contents

require 'spec_helper'

SimpleCov.command_name('Table') unless RUBY_VERSION.to_s < '1.9.0'

describe 'Table, Unit' do

  clazz = CucumberAnalytics::Table

  it_should_behave_like 'a nested element', clazz
  it_should_behave_like 'a bare bones element', clazz
  it_should_behave_like 'a prepopulated element', clazz
  it_should_behave_like 'a raw element', clazz

  it 'can be parsed from stand alone text' do
    source = '| a table |'

    expect { @element = clazz.new(source) }.to_not raise_error

    # Sanity check in case instantiation failed in a non-explosive manner
    @element.contents.should == [['a table']]
  end

  before(:each) do
    @table = clazz.new
  end

  it 'has contents - #contents' do
    @table.should respond_to(:contents)
  end

  it 'can get and set its contents - #contents, #contents=' do
    @table.contents = :some_contents
    @table.contents.should == :some_contents
    @table.contents = :some_other_contents
    @table.contents.should == :some_other_contents
  end

  it 'starts with no contents' do
    @table.contents.should == []
  end

  it 'has row elements' do
    @table.should respond_to(:row_elements)
  end

  it 'can get and set its row elements' do
    @table.row_elements = :some_row_elements
    @table.row_elements.should == :some_row_elements
    @table.row_elements = :some_other_row_elements
    @table.row_elements.should == :some_other_row_elements
  end

  it 'starts with no row elements' do
    @table.row_elements.should == []
  end

  it 'stores its contents as a nested array of strings' do
    source = "| cell 1 | cell 2 |\n| cell 3 | cell 4 |"
    table = CucumberAnalytics::Table.new(source)

    contents = table.contents

    contents.is_a?(Array).should be_true

    contents.each do |row|
      row.is_a?(Array).should be_true
      row.each { |cell| cell.is_a?(String).should be_true }
    end
  end

end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
cucumber_analytics-1.4.2 spec/unit/table_unit_spec.rb
cucumber_analytics-1.4.1 spec/unit/table_unit_spec.rb
cucumber_analytics-1.4.0 spec/unit/table_unit_spec.rb