Method: OutputToFDMatcher#matches?

Defined in:
lib/mspec/matchers/output_to_fd.rb

#matches?(block) ⇒ Boolean

Returns:

  • (Boolean)


25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
# File 'lib/mspec/matchers/output_to_fd.rb', line 25

def matches?(block)
  old_to = @to.dup
  out = File.open(tmp("mspec_output_to_#{$$}_#{Time.now.to_i}"), 'w+')

  # Replacing with a file handle so that Readline etc. work
  @to.reopen out

  block.call

ensure
  begin
    @to.reopen old_to

    out.rewind
    @actual = out.read

    case @expected
      when Regexp
        return !(@actual =~ @expected).nil?
      else
        return @actual == @expected
    end

  # Clean up
  ensure
    out.close unless out.closed?
    FileUtils.rm out.path
  end

  return true
end