Sha256: b8f39193fe649d2734a0049809aec2d77f8ed5330a64c645f17db4ee9d148b74

Contents?: true

Size: 726 Bytes

Versions: 333

Compression:

Stored size: 726 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 && 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

333 entries across 333 versions & 2 rubygems

Version Path
chef-17.10.163-universal-mingw32 spec/support/shared/matchers/exit_with_code.rb
chef-17.10.163 spec/support/shared/matchers/exit_with_code.rb
knife-18.5.0 spec/support/shared/matchers/exit_with_code.rb
chef-18.5.0-x64-mingw-ucrt spec/support/shared/matchers/exit_with_code.rb
chef-18.5.0 spec/support/shared/matchers/exit_with_code.rb
chef-18.4.12-x64-mingw-ucrt spec/support/shared/matchers/exit_with_code.rb
chef-18.4.12 spec/support/shared/matchers/exit_with_code.rb
chef-17.10.122-universal-mingw32 spec/support/shared/matchers/exit_with_code.rb
chef-17.10.122 spec/support/shared/matchers/exit_with_code.rb
chef-17.10.114-universal-mingw32 spec/support/shared/matchers/exit_with_code.rb
chef-17.10.114 spec/support/shared/matchers/exit_with_code.rb
knife-18.4.2 spec/support/shared/matchers/exit_with_code.rb
chef-18.4.2-x64-mingw-ucrt spec/support/shared/matchers/exit_with_code.rb
chef-18.4.2 spec/support/shared/matchers/exit_with_code.rb
knife-17.10.95 spec/support/shared/matchers/exit_with_code.rb
chef-17.10.95-universal-mingw32 spec/support/shared/matchers/exit_with_code.rb
chef-17.10.95 spec/support/shared/matchers/exit_with_code.rb
knife-18.3.0 spec/support/shared/matchers/exit_with_code.rb
chef-18.3.0-x64-mingw-ucrt spec/support/shared/matchers/exit_with_code.rb
chef-18.3.0 spec/support/shared/matchers/exit_with_code.rb