Sha256: c23e727fc185c47d882394f3e1c43bc826a02d9794371b03107ea407052323df

Contents?: true

Size: 941 Bytes

Versions: 3

Compression:

Stored size: 941 Bytes

Contents

require 'spec_helper'
require 'mspec/guards'

describe Object, "#with_tty" do
  before :each do
    ScratchPad.clear

    @guard = TTYGuard.new
    TTYGuard.stub(:new).and_return(@guard)
  end

  it "yields if STDOUT is a TTY" do
    STDOUT.should_receive(:tty?).and_return(true)
    with_tty { ScratchPad.record :yield }
    ScratchPad.recorded.should == :yield
  end

  it "does not yield if STDOUT is not a TTY" do
    STDOUT.should_receive(:tty?).and_return(false)
    with_tty { ScratchPad.record :yield }
    ScratchPad.recorded.should_not == :yield
  end

  it "sets the name of the guard to :with_tty" do
    with_tty { }
    @guard.name.should == :with_tty
  end

  it "calls #unregister even when an exception is raised in the guard block" do
    @guard.should_receive(:match?).and_return(true)
    @guard.should_receive(:unregister)
    lambda do
      with_tty { raise Exception }
    end.should raise_error(Exception)
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
mspec-1.9.1 spec/guards/tty_spec.rb
mspec-1.9.0 spec/guards/tty_spec.rb
mspec-1.8.0 spec/guards/tty_spec.rb