Sha256: c4ffb7558ca3489680df17b4236074b88fd88a1127bb51c656aaadcae638944b

Contents?: true

Size: 1.93 KB

Versions: 3

Compression:

Stored size: 1.93 KB

Contents

require 'test_helper'

module Vedeu
  describe Stream do
    let(:stream) {
      Stream.new({
        colour: {
          foreground: '#ff0000',
          background: '#000000'
        },
        text:  'Some text',
        style: style,
        width: width,
        align: align
      })
    }
    let(:style) { 'normal' }
    let(:align) { :left }
    let(:width) { 9 }

    describe '#text' do
      it 'has a text attribute' do
        stream.text.must_equal('Some text')
      end
    end

    describe '#width' do
      it 'has a width attribute' do
        stream.width.must_equal(9)
      end
    end

    describe '#align' do
      it 'has an align attribute' do
        stream.align.must_equal(:left)
      end
    end

    describe '#to_s' do
      describe 'when a width is set and align is default' do
        let(:width) { 20 }

        it 'returns a String' do
          stream.to_s.must_equal(
            "\e[38;2;255;0;0m\e[48;2;0;0;0m" \
            "\e[24m\e[22m\e[27m"      \
            "Some text           "
          )
        end

        describe 'and align is :centre' do
          let(:align) { :centre }

          it 'returns a String' do
            stream.to_s.must_equal(
              "\e[38;2;255;0;0m\e[48;2;0;0;0m" \
              "\e[24m\e[22m\e[27m"      \
              "     Some text      "
            )
          end
        end

        describe 'and align is :right' do
          let(:align) { :right }

          it 'returns a String' do
            stream.to_s.must_equal(
              "\e[38;2;255;0;0m\e[48;2;0;0;0m" \
              "\e[24m\e[22m\e[27m"      \
              "           Some text"
            )
          end
        end
      end

      describe 'when a width is not set' do
        it 'returns a String' do
          stream.to_s.must_equal(
            "\e[38;2;255;0;0m\e[48;2;0;0;0m" \
            "\e[24m\e[22m\e[27m"      \
            "Some text"
          )
        end
      end
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
vedeu-0.1.18 test/lib/vedeu/models/stream_test.rb
vedeu-0.1.17 test/lib/vedeu/models/stream_test.rb
vedeu-0.1.16 test/lib/vedeu/models/stream_test.rb