Sha256: 4dc796d5a7c1b0669a7a778e4427605a0a08620c4dbd978116a7d985bb311184

Contents?: true

Size: 925 Bytes

Versions: 16

Compression:

Stored size: 925 Bytes

Contents

RSpec::Matchers.define_negated_matcher :exit_without_error, :exit_with_error
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

16 entries across 16 versions & 1 rubygems

Version Path
kontena-cli-1.5.4 spec/support/exit_with_error_helper.rb
kontena-cli-1.5.4.rc1 spec/support/exit_with_error_helper.rb
kontena-cli-1.5.3 spec/support/exit_with_error_helper.rb
kontena-cli-1.5.2 spec/support/exit_with_error_helper.rb
kontena-cli-1.5.1 spec/support/exit_with_error_helper.rb
kontena-cli-1.5.0 spec/support/exit_with_error_helper.rb
kontena-cli-1.5.0.rc1 spec/support/exit_with_error_helper.rb
kontena-cli-1.5.0.pre5 spec/support/exit_with_error_helper.rb
kontena-cli-1.5.0.pre4 spec/support/exit_with_error_helper.rb
kontena-cli-1.5.0.pre3 spec/support/exit_with_error_helper.rb
kontena-cli-1.5.0.pre2 spec/support/exit_with_error_helper.rb
kontena-cli-1.5.0.pre1 spec/support/exit_with_error_helper.rb
kontena-cli-1.4.3 spec/support/exit_with_error_helper.rb
kontena-cli-1.4.3.rc1 spec/support/exit_with_error_helper.rb
kontena-cli-1.4.2 spec/support/exit_with_error_helper.rb
kontena-cli-1.4.2.rc1 spec/support/exit_with_error_helper.rb