Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Loading…

Specs fail with latest Rspec [Patch] #1

Open
pboling opened this Issue · 0 comments

1 participant

@pboling

Current rspec matcher code (doesn't work with latest rspec 2):

module Spec
  module Matchers
    def have_stdout(regex)
      regex = /^#{Regexp.escape(regex)}$/ if regex.is_a?(String)

      simple_matcher("have_stdout") do |given, matcher|
        $stdout = StringIO.new
        given.call
        $stdout.rewind
        captured = $stdout.read

        matcher.failure_message = "Expected #{regex} but got #{captured}"

        $stdout = STDOUT
        captured =~ regex
      end
    end
  end
end

Changing the rspec matcher to this will get your spec suite working with rspec 2:

RSpec::Matchers.define :have_stdout do |regex|
  define_method :has_stdout? do |actual|
    regex = /^#{Regexp.escape(regex)}$/ if regex.is_a?(String)

    $stdout = StringIO.new
    actual.call
    $stdout.rewind
    captured = $stdout.read

    $stdout = STDOUT
    captured =~ regex
  end
  match { |actual| has_stdout?(actual) }
end

Cool library! I would fork and create a pull req if I "could".

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.