Class: Crspec::Matchers::OutputMatcher
Instance Attribute Summary
Attributes inherited from BaseMatcher
#actual, #expected
Instance Method Summary
collapse
Methods inherited from BaseMatcher
#and, #failure_message_when_negated, #or
Constructor Details
#initialize(expected = nil) ⇒ OutputMatcher
Returns a new instance of OutputMatcher.
586
587
588
589
|
# File 'lib/crspec/matchers.rb', line 586
def initialize(expected = nil)
super
@stream = :stdout
end
|
Instance Method Details
#failure_message ⇒ Object
614
615
616
|
# File 'lib/crspec/matchers.rb', line 614
def failure_message
"Expected block to output #{@expected ? @expected.inspect : "something"} to #{@stream}, got #{@captured.inspect}"
end
|
#matches?(block) ⇒ Boolean
601
602
603
604
605
606
607
608
609
610
611
612
|
# File 'lib/crspec/matchers.rb', line 601
def matches?(block)
raise ArgumentError, "output matcher requires a block" unless block.respond_to?(:call)
@captured = capture(block)
if @expected.nil?
!@captured.empty?
elsif @expected.is_a?(Regexp)
@expected.match?(@captured)
else
@captured.include?(@expected)
end
end
|
#to_stderr ⇒ Object
596
597
598
599
|
# File 'lib/crspec/matchers.rb', line 596
def to_stderr
@stream = :stderr
self
end
|
#to_stdout ⇒ Object
591
592
593
594
|
# File 'lib/crspec/matchers.rb', line 591
def to_stdout
@stream = :stdout
self
end
|