Sha256: 74b1033850fe63daabace6e19587fabd8b45e94e90cb64f0c6e4bfa6b78ad758

Contents?: true

Size: 1.42 KB

Versions: 188

Compression:

Stored size: 1.42 KB

Contents

require 'mspec/helpers/io'

class OutputMatcher
  def initialize(stdout, stderr)
    @out = stdout
    @err = stderr
  end

  def matches?(proc)
    @saved_out = $stdout
    @saved_err = $stderr
    @stdout = $stdout = IOStub.new
    @stderr = $stderr = IOStub.new

    proc.call

    unless @out.nil?
      case @out
      when Regexp
        return false unless $stdout =~ @out
      else
        return false unless $stdout == @out
      end
    end

    unless @err.nil?
      case @err
      when Regexp
        return false unless $stderr =~ @err
      else
        return false unless $stderr == @err
      end
    end

    return true
  ensure
    $stdout = @saved_out
    $stderr = @saved_err
  end

  def failure_message
    expected_out = "\n"
    actual_out = "\n"
    unless @out.nil?
      expected_out << "  $stdout: #{@out.inspect}\n"
      actual_out << "  $stdout: #{@stdout.chomp.inspect}\n"
    end
    unless @err.nil?
      expected_out << "  $stderr: #{@err.inspect}\n"
      actual_out << "  $stderr: #{@stderr.chomp.inspect}\n"
    end
    ["Expected:#{expected_out}", "     got:#{actual_out}"]
  end

  def negative_failure_message
    out = ""
    out << "  $stdout: #{@stdout.chomp.dump}\n" unless @out.nil?
    out << "  $stderr: #{@stderr.chomp.dump}\n" unless @err.nil?
    ["Expected output not to be:\n", out]
  end
end

class Object
  def output(stdout=nil, stderr=nil)
    OutputMatcher.new(stdout, stderr)
  end
end

Version data entries

188 entries across 164 versions & 4 rubygems

Version Path
rhodes-2.4.0.beta.2 lib/extensions/mspec/mspec/matchers/output.rb
rhodes-2.4.0.beta.1 lib/extensions/mspec/mspec/matchers/output.rb
rhodes-2.3.2 lib/extensions/mspec/mspec/matchers/output.rb
rhodes-2.3.2.beta.2 lib/extensions/mspec/mspec/matchers/output.rb
rhodes-2.3.2.beta.1 lib/extensions/mspec/mspec/matchers/output.rb
rhodes-2.3.1 lib/extensions/mspec/mspec/matchers/output.rb
rhodes-2.3.1.beta.1 lib/extensions/mspec/mspec/matchers/output.rb
rhodes-2.3.0 lib/extensions/mspec/mspec/matchers/output.rb
rhodes-2.3.0.beta.3 lib/extensions/mspec/mspec/matchers/output.rb
rhodes-2.3.0.beta.2 lib/extensions/mspec/mspec/matchers/output.rb
rhodes-2.3.0.beta.1 lib/extensions/mspec/mspec/matchers/output.rb
rhodes-2.2.6 lib/extensions/mspec/mspec/matchers/output.rb
rhodes-2.2.6.beta.1 lib/extensions/mspec/mspec/matchers/output.rb
rhodes-2.2.5 lib/extensions/mspec/mspec/matchers/output.rb
rhodes-2.2.5.beta.3 lib/extensions/mspec/mspec/matchers/output.rb
rhodes-2.2.5.beta.2 lib/extensions/mspec/mspec/matchers/output.rb
rhodes-2.2.5.beta.1 lib/extensions/mspec/mspec/matchers/output.rb
rhodes-2.2.4.beta.1 lib/extensions/mspec/mspec/matchers/output.rb
rhodes-2.2.3 lib/extensions/mspec/mspec/matchers/output.rb
rhodes-2.2.3.beta.1 lib/extensions/mspec/mspec/matchers/output.rb