Sha256: a3dcb1690376f54ea26fa9435e3be02f7ebdf968b61b24849b0b7f04731bb6f4

Contents?: true

Size: 1.74 KB

Versions: 4

Compression:

Stored size: 1.74 KB

Contents

# Git Pivotal Tracker Integration
# Copyright (c) 2013 the original author or authors.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#      http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

require 'spec_helper'
require 'git-pivotal-tracker-integration/util/shell'

describe PivotalIntegration::Util::Shell do

  before do
    $stdout = StringIO.new
    $stderr = StringIO.new
  end

  it 'should return result when exit code is 0' do
    PivotalIntegration::Util::Shell.should_receive(:`).with('test_command').and_return('test_result')
    $?.should_receive(:exitstatus).and_return(0)

    result = PivotalIntegration::Util::Shell.exec 'test_command'

    expect(result).to eq('test_result')
  end

  it "should abort with 'FAIL' when the exit code is not 0" do
    PivotalIntegration::Util::Shell.should_receive(:`).with('test_command')
    $?.should_receive(:exitstatus).and_return(-1)

    lambda { PivotalIntegration::Util::Shell.exec 'test_command' }.should raise_error(SystemExit)

    expect($stderr.string).to match(/FAIL/)
  end

  it 'should return result when the exit code is not 0 and told not to abort on failure' do
    PivotalIntegration::Util::Shell.should_receive(:`).with('test_command')
    $?.should_receive(:exitstatus).and_return(-1)

    PivotalIntegration::Util::Shell.exec 'test_command', false
  end


end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
pivotal-integration-1.6.0.4 spec/git-pivotal-tracker-integration/util/shell_spec.rb
pivotal-integration-1.6.0.3 spec/git-pivotal-tracker-integration/util/shell_spec.rb
pivotal-integration-1.6.0.2 spec/git-pivotal-tracker-integration/util/shell_spec.rb
pivotal-integration-1.6.0.1 spec/git-pivotal-tracker-integration/util/shell_spec.rb