Class: GenSpec::Matchers::OutputMatcher

Inherits:
Base
  • Object
show all
Defined in:
lib/genspec/matchers/output_matcher.rb

Instance Attribute Summary

Attributes inherited from Base

#args, #block, #destination_root, #error, #generator, #init_blocks

Instance Method Summary collapse

Methods inherited from Base

#match!, #matched?, #matches?, #source_root

Constructor Details

#initialize(text_or_regexp) ⇒ OutputMatcher

Returns a new instance of OutputMatcher.



8
9
10
11
12
13
14
15
16
17
# File 'lib/genspec/matchers/output_matcher.rb', line 8

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

Instance Method Details

#failure_messageObject



23
24
25
26
# File 'lib/genspec/matchers/output_matcher.rb', line 23

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

#generatedObject



19
20
21
# File 'lib/genspec/matchers/output_matcher.rb', line 19

def generated
  match! if output =~ @regexp
end

#negative_failure_messageObject



28
29
30
31
# File 'lib/genspec/matchers/output_matcher.rb', line 28

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

#outputObject



4
5
6
# File 'lib/genspec/matchers/output_matcher.rb', line 4

def output
  shell.output.string
end