Sha256: 42c4c30d4ec7f34c5605505dea3268d60e2787764d34ba54bb5eb04435085a96

Contents?: true

Size: 1.58 KB

Versions: 6

Compression:

Stored size: 1.58 KB

Contents

# -*- encoding: utf-8 -*-

require 'spec_helper'

describe TTY::Shell, '#say' do
  let(:input)  { StringIO.new }
  let(:output) { StringIO.new }

  subject(:shell) { TTY::Shell.new(input, output) }

  after { output.rewind }

  it 'prints an empty message' do
    shell.say ""
    expect(output.string).to eql ""
  end

  context 'with new line' do
    it 'prints a message with newline' do
      shell.say "Hell yeah!\n"
      expect(output.string).to eql "Hell yeah!\n"
    end

    it 'prints a message with implicit newline' do
      shell.say "Hell yeah!\n"
      expect(output.string).to eql "Hell yeah!\n"
    end

    it 'prints a message with newline within text' do
      shell.say "Hell\n yeah!"
      expect(output.string).to eql "Hell\n yeah!\n"
    end

    it 'prints a message with newline within text and blank space' do
      shell.say "Hell\n yeah! "
      expect(output.string).to eql "Hell\n yeah! "
    end

    it 'prints a message without newline' do
      shell.say "Hell yeah!", :newline => false
      expect(output.string).to eql "Hell yeah!"
    end
  end

  context 'with tab or space' do
    it 'prints ' do
      shell.say "Hell yeah!\t"
      expect(output.string).to eql "Hell yeah!\t"
    end
  end

  context 'with color' do
    it 'prints message with ansi color' do
      shell.say "Hell yeah!", :color => :green
      expect(output.string).to eql "\e[32mHell yeah!\e[0m\n"
    end

    it 'prints message with ansi color without newline' do
      shell.say "Hell yeah! ", :color => :green
      expect(output.string).to eql "\e[32mHell yeah! \e[0m"
    end
  end

end # say

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
tty-0.0.11 spec/tty/shell/say_spec.rb
tty-0.0.10 spec/tty/shell/say_spec.rb
tty-0.0.9 spec/tty/shell/say_spec.rb
tty-0.0.8 spec/tty/shell/say_spec.rb
tty-0.0.7 spec/tty/shell/say_spec.rb
tty-0.0.6 spec/tty/shell/say_spec.rb