Sha256: 7b2e82960660781396ec2127b4791250023f796cbc9e9e5d5f90d28f7a75c7fe

Contents?: true

Size: 691 Bytes

Versions: 8

Compression:

Stored size: 691 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_for_should do |block|
    "expected block to call exit(#{exp_code}) but exit" +
        (actual.nil? ? " not called" : "(#{actual}) was called")
  end

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

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

end

Version data entries

8 entries across 8 versions & 1 rubygems

Version Path
chef-12.0.3-x86-mingw32 spec/support/shared/matchers/exit_with_code.rb
chef-12.0.3 spec/support/shared/matchers/exit_with_code.rb
chef-12.0.1-x86-mingw32 spec/support/shared/matchers/exit_with_code.rb
chef-12.0.1 spec/support/shared/matchers/exit_with_code.rb
chef-12.0.0-x86-mingw32 spec/support/shared/matchers/exit_with_code.rb
chef-12.0.0 spec/support/shared/matchers/exit_with_code.rb
chef-12.0.0.rc.0-x86-mingw32 spec/support/shared/matchers/exit_with_code.rb
chef-12.0.0.rc.0 spec/support/shared/matchers/exit_with_code.rb