Sha256: c070c014a6a2ea1c7bf45af63a0bb346c9d73f677eeb41c9f5c2401927763626

Contents?: true

Size: 887 Bytes

Versions: 9

Compression:

Stored size: 887 Bytes

Contents

require 'rspec/expectations'

RSpec::Matchers.define :abort_with_error do |message|
  match do |block|
    @block = block
    with_fake_stderr do
      @got_system_exit = false
      begin
        block.call
      rescue SystemExit
        @got_system_exit = true
        @stderr = $stderr.string
        message ? message === @stderr : true
      else
        false
      end
    end
  end

  description do
    "blahhh"
  end

  failure_message_for_should do |actual|
    if @got_system_exit
      "expected STDERR to match " + \
      ((message.is_a?(Regexp) ? "/%s/" : "'%s'") % message) + \
      " but got:\n#{@stderr}"
    else
      "expected #{@block} to raise SystemExit"
    end
  end

  # Fake STDERR and return a string written to it.
  def with_fake_stderr
    original_stderr = $stderr
    $stderr = StringIO.new
    yield
  ensure
    $stderr = original_stderr
  end
end

Version data entries

9 entries across 9 versions & 2 rubygems

Version Path
rvm-capistrano-1.5.6 spec/support/abort_matcher.rb
rvm-capistrano-1.5.5 spec/support/abort_matcher.rb
rvm-capistrano-1.5.4 spec/support/abort_matcher.rb
rvm-capistrano-1.5.3 spec/support/abort_matcher.rb
rvm-capistrano-1.5.2 spec/support/abort_matcher.rb
capistrano_mailer-3.3.0 spec/support/abort_matcher.rb
rvm-capistrano-1.5.1 spec/support/abort_matcher.rb
rvm-capistrano-1.5.0 spec/support/abort_matcher.rb
rvm-capistrano-1.5.0.rc1 spec/support/abort_matcher.rb