Sha256: 1bc7a674da2987af47885a930825822f4cda9502a36bf4c7b2f95d98b256edc4

Contents?: true

Size: 1.53 KB

Versions: 16

Compression:

Stored size: 1.53 KB

Contents

require 'spec_helper'

describe GithubCLI::Pager do

  context '#pager_command' do
    it 'permits custom commands' do
      cmd = 'more'
      GithubCLI::System.stub(:command?) { true }
      described_class.pager_command(cmd).should == cmd
    end
  end

  context '#page' do
    let(:read_io) { stub(:read_io).as_null_object }
    let(:write_io) { stub(:write_io).as_null_object }
    let(:pager) { described_class.new }

    before do
      $stdout.stub(:tty?).and_return true
      IO.stub(:pipe).and_return [read_io, write_io]
    end

    context 'child process' do
      before { Kernel.stub(:fork) { false } }

      it 'pipes to standard output' do
        Kernel.stub(:fork) { false}
        $stdout.should_receive(:reopen).with(write_io)
        $stderr.should_receive(:reopen).with(write_io)
        pager.page
      end

      it 'closes pipe' do
        $stdout.stub(:reopen)
        $stderr.stub(:reopen)
        write_io.should_receive(:close)
        read_io.should_receive(:close)
        pager.page
      end
    end

    context 'parent process' do
      before do
        Kernel.stub(:fork) { true }
        Kernel.stub(:select)
        described_class.stub(:pager_command) { 'less' }
        Kernel.stub(:exec)
      end

      it 'reads from standard output' do
        $stdin.should_receive(:reopen).with(read_io)
        pager.page
      end

      it 'closes pipe' do
        $stdin.stub(:reopen)
        write_io.should_receive(:close)
        read_io.should_receive(:close)
        pager.page
      end
    end
  end

end # GithubCLI::Pager

Version data entries

16 entries across 16 versions & 1 rubygems

Version Path
github_cli-0.6.2 spec/github_cli/pager_spec.rb
github_cli-0.6.1 spec/github_cli/pager_spec.rb
github_cli-0.6.0 spec/github_cli/pager_spec.rb
github_cli-0.5.9 spec/github_cli/pager_spec.rb
github_cli-0.5.8 spec/github_cli/pager_spec.rb
github_cli-0.5.7 spec/github_cli/pager_spec.rb
github_cli-0.5.6 spec/github_cli/pager_spec.rb
github_cli-0.5.5 spec/github_cli/pager_spec.rb
github_cli-0.5.4 spec/github_cli/pager_spec.rb
github_cli-0.5.3 spec/github_cli/pager_spec.rb
github_cli-0.5.2 spec/github_cli/pager_spec.rb
github_cli-0.5.1 spec/github_cli/pager_spec.rb
github_cli-0.5.0 spec/github_cli/pager_spec.rb
github_cli-0.4.4 spec/github_cli/pager_spec.rb
github_cli-0.4.3 spec/github_cli/pager_spec.rb
github_cli-0.4.2 spec/github_cli/pager_spec.rb