Sha256: 5a396773c4d3fbf3ffdab64396222083a76507a3074fbf7967165580338115cb

Contents?: true

Size: 848 Bytes

Versions: 53

Compression:

Stored size: 848 Bytes

Contents

RSpec::Matchers.define :exit_with_error do

  def supports_block_expectations?
    true
  end

  match do |block|
    begin
      block.call
    rescue SystemExit => e
      @exit_status = e.status
    end
    !@exit_status.nil? && @exit_status == expected_status
  end

  chain :status do |status|
    @expected_status = status
  end

  failure_message do |block|
    "expected block to exit with status #{expected_status} but exit " +
      (@exit_status.nil? ? "was not called" : "status was #{@exit_status}")
  end

  failure_message_when_negated do |block|
    "expected block not to raise SystemExit, got exit with status #{@exit_status}"
  end

  description do
    "expect block to exit #{expected_status.zero? ? "without error" : "with error (status #{expected_status})"}"
  end

  def expected_status
    @expected_status ||= 1
  end
end

Version data entries

53 entries across 53 versions & 1 rubygems

Version Path
kontena-cli-1.4.2.pre1 spec/support/exit_with_error_helper.rb
kontena-cli-1.4.1 spec/support/exit_with_error_helper.rb
kontena-cli-1.4.1.rc1 spec/support/exit_with_error_helper.rb
kontena-cli-1.4.1.pre1 spec/support/exit_with_error_helper.rb
kontena-cli-1.3.5 spec/support/exit_with_error_helper.rb
kontena-cli-1.3.5.rc1 spec/support/exit_with_error_helper.rb
kontena-cli-1.4.0 spec/support/exit_with_error_helper.rb
kontena-cli-1.4.0.rc2 spec/support/exit_with_error_helper.rb
kontena-cli-1.4.0.rc1 spec/support/exit_with_error_helper.rb
kontena-cli-1.4.0.pre14 spec/support/exit_with_error_helper.rb
kontena-cli-1.4.0.pre13 spec/support/exit_with_error_helper.rb
kontena-cli-1.4.0.pre12 spec/support/exit_with_error_helper.rb
kontena-cli-1.4.0.pre11 spec/support/exit_with_error_helper.rb
kontena-cli-1.4.0.pre10 spec/support/exit_with_error_helper.rb
kontena-cli-1.4.0.pre9 spec/support/exit_with_error_helper.rb
kontena-cli-1.4.0.pre8 spec/support/exit_with_error_helper.rb
kontena-cli-1.4.0.pre7 spec/support/exit_with_error_helper.rb
kontena-cli-1.4.0.pre6 spec/support/exit_with_error_helper.rb
kontena-cli-1.4.0.pre5 spec/support/exit_with_error_helper.rb
kontena-cli-1.4.0.pre4 spec/support/exit_with_error_helper.rb