Sha256: fbbc98fa7303eabd51b74735a1a055178dcd4c1c6a1f0da0d7c1f91e178b94ec

Contents?: true

Size: 832 Bytes

Versions: 2

Compression:

Stored size: 832 Bytes

Contents

module GenSpec
  module Matchers
    class OutputMatcher < GenSpec::Matchers::Base
      def output
        Thor::Base.shell.output.string
      end
      
      def initialize(text_or_regexp)
        regexp = if text_or_regexp.kind_of?(Regexp)
                   text_or_regexp
                 else
                   Regexp.compile(Regexp.escape(text_or_regexp), Regexp::MULTILINE)
                 end
        @regexp = regexp
        super()
        silence_errors!
      end
      
      def generated
        match! if output =~ @regexp
      end
      
      def failure_message
        output + "\n" \
          "expected to match #{@regexp.inspect}, but did not"
      end

      def negative_failure_message
        output + "\n" \
          "expected not to match #{@regexp.inspect}, but did"
      end
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
genspec-0.2.0.prerails3.2 lib/genspec/matchers/output_matcher.rb
genspec-0.2.0.prerails3.1 lib/genspec/matchers/output_matcher.rb