<commit_before># -*- encoding: utf-8 -*-

require 'spec_helper'

describe TTY::Table::Columns, '#enforce' do
  let(:header) { ['h1', 'h2', 'h3', 'h4'] }
  let(:rows)   { [['a1', 'a2', 'a3', 'a4'], ['b1', 'b2', 'b3', 'b4']] }
  let(:table)  { TTY::Table.new(header, rows) }
  let(:object) { described_class.new(renderer) }

  subject { object.enforce }

  context 'with width contraint' do
    let(:renderer) { TTY::Table::Renderer::Basic.new(table, options) }
    let(:options) { { width: 5 }}

    it 'raises error when table width is too small' do
      expect { subject }.to raise_error(ArgumentError)
    end
  end

  context 'with table larger than allowed width' do
    let(:renderer) { TTY::Table::Renderer::Basic.new(table, options) }
    let(:options) { { width: 8 }}

    it 'changes table orientation to vertical' do
      TTY.shell.should_receive(:warn)
      expect(renderer.column_widths).to eql([2,2,2,2])
      expect(renderer.table.orientation.name).to eql(:horizontal)
      subject
      expect(renderer.column_widths).to eq([2,2,2])
      expect(renderer.table.orientation.name).to eql(:vertical)
    end
  end

  context 'with table less than allowed width' do
    let(:renderer) { TTY::Table::Renderer::Basic.new(table, options) }
    let(:options) { { width: 15 }}

    before { TTY.shell.stub(:warn) }

    it "doesnt change original widths" do
      expect(renderer.column_widths).to eq([2,2,2,2])
    end
  end
end
<commit_msg>Fix spec for columns width enforcement.<commit_after># -*- encoding: utf-8 -*-

require 'spec_helper'

describe TTY::Table::Columns, '#enforce' do
  let(:header) { ['h1', 'h2', 'h3', 'h4'] }
  let(:rows)   { [['a1', 'a2', 'a3', 'a4'], ['b1', 'b2', 'b3', 'b4']] }
  let(:table)  { TTY::Table.new(header, rows) }
  let(:object) { described_class.new(renderer) }

  subject { object.enforce }

  context 'with width contraint' do
    let(:renderer) { TTY::Table::Renderer::Basic.new(table, options) }
    let(:options) { { width: 5 }}

    it 'raises error when table width is too small' do
      expect { subject }.to raise_error(ArgumentError)
    end
  end

  context 'with table larger than allowed width' do
    let(:renderer) { TTY::Table::Renderer::Basic.new(table, options) }
    let(:options) { { width: 8 }}

    it 'changes table orientation to vertical' do
      TTY.shell.should_receive(:warn)
      expect(renderer.column_widths).to eql([2,2,2,2])
      expect(renderer.table.orientation.name).to eql(:horizontal)
      subject
      expect(renderer.column_widths).to eq([2,2])
      expect(renderer.table.orientation.name).to eql(:vertical)
    end
  end

  context 'with table less than allowed width' do
    let(:renderer) { TTY::Table::Renderer::Basic.new(table, options) }
    let(:options) { { width: 15 }}

    before { TTY.shell.stub(:warn) }

    it "doesnt change original widths" do
      expect(renderer.column_widths).to eq([2,2,2,2])
    end
  end
end

{'fraction_non_alphanumeric': 0.16655290102389078, 'fraction_numerical': 0.01877133105802048, 'mean_word_length': 3.6450079239302693, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5201959', 'n_tokens_mistral': 1026, 'n_tokens_neox': 1011, 'n_words': 239}