Sha256: 14f09f480f1b4bca1a9ada407f69f02002f34da3fd69ada8b57ec4d4663d6da6

Contents?: true

Size: 729 Bytes

Versions: 35

Compression:

Stored size: 729 Bytes

Contents

require 'rspec/expectations'

# Lifted from http://stackoverflow.com/questions/1480537/how-can-i-validate-exits-and-aborts-in-rspec
RSpec::Matchers.define :exit_with_code do |exp_code|
  actual = nil
  match do |block|
    begin
      block.call
    rescue SystemExit => e
      actual = e.status
    end
    actual and actual == exp_code
  end

  failure_message do |block|
    "expected block to call exit(#{exp_code}) but exit" +
        (actual.nil? ? " not called" : "(#{actual}) was called")
  end

  failure_message_when_negated do |block|
    "expected block not to call exit(#{exp_code})"
  end

  description do
    "expect block to call exit(#{exp_code})"
  end

  def supports_block_expectations?
    true
  end

end

Version data entries

35 entries across 35 versions & 1 rubygems

Version Path
chef-12.6.0 spec/support/shared/matchers/exit_with_code.rb
chef-12.6.0-universal-mingw32 spec/support/shared/matchers/exit_with_code.rb
chef-12.5.1-universal-mingw32 spec/support/shared/matchers/exit_with_code.rb
chef-12.5.1 spec/support/shared/matchers/exit_with_code.rb
chef-12.4.3-universal-mingw32 spec/support/shared/matchers/exit_with_code.rb
chef-12.4.3 spec/support/shared/matchers/exit_with_code.rb
chef-12.4.2-universal-mingw32 spec/support/shared/matchers/exit_with_code.rb
chef-12.4.2 spec/support/shared/matchers/exit_with_code.rb
chef-12.5.0.alpha.1 spec/support/shared/matchers/exit_with_code.rb
chef-12.4.1-universal-mingw32 spec/support/shared/matchers/exit_with_code.rb
chef-12.4.1 spec/support/shared/matchers/exit_with_code.rb
chef-12.4.0 spec/support/shared/matchers/exit_with_code.rb
chef-12.4.0-universal-mingw32 spec/support/shared/matchers/exit_with_code.rb
chef-12.4.0.rc.2 spec/support/shared/matchers/exit_with_code.rb
chef-12.4.0.rc.2-universal-mingw32 spec/support/shared/matchers/exit_with_code.rb
chef-12.4.0.rc.0 spec/support/shared/matchers/exit_with_code.rb
chef-12.4.0.rc.0-universal-mingw32 spec/support/shared/matchers/exit_with_code.rb
chef-12.3.0-x86-mingw32 spec/support/shared/matchers/exit_with_code.rb
chef-12.3.0 spec/support/shared/matchers/exit_with_code.rb
chef-12.3.0.rc.0-x86-mingw32 spec/support/shared/matchers/exit_with_code.rb