Class: RSpecFixtures::Matchers::OutputFixture

Inherits:
Base
  • Object
show all
Defined in:
lib/rspec_fixtures/matchers/output_fixture.rb

Instance Attribute Summary

Attributes inherited from Base

#actual, #actual_distance, #distance, #fixture_name

Instance Method Summary collapse

Methods inherited from Base

#before, #diff, #diffable?, #except, #expected, #failure_message, #fixture_file, #fixtures_dir, #initialize, #interactive?, #sanitize?

Constructor Details

This class inherits a constructor from RSpecFixtures::Matchers::Base

Instance Method Details

#matches?(block) ⇒ Boolean

Called by RSpec

Returns:

  • (Boolean)


11
12
13
14
15
# File 'lib/rspec_fixtures/matchers/output_fixture.rb', line 11

def matches?(block)
  return false unless block.is_a? Proc
  @actual = stream_capturer.capture block
  super
end

#stream_capturerObject



37
38
39
# File 'lib/rspec_fixtures/matchers/output_fixture.rb', line 37

def stream_capturer
  @stream_capturer ||= Stream::Stdout
end

#supports_block_expectations?Boolean

Lets RSpec know that this matcher requires a block.

Returns:

  • (Boolean)


18
19
20
# File 'lib/rspec_fixtures/matchers/output_fixture.rb', line 18

def supports_block_expectations?
  true
end

#to_stderrObject

Adds chained matcher, to allow: expect{ stream }.to output_fixture(file).to_stderr



32
33
34
35
# File 'lib/rspec_fixtures/matchers/output_fixture.rb', line 32

def to_stderr
  @stream_capturer = Stream::Stderr
  self
end

#to_stdoutObject

Adds chained matcher, to allow: expect{ stream }.to output_fixture(file).to_stdout This is the default, and only provided for completeness.



25
26
27
28
# File 'lib/rspec_fixtures/matchers/output_fixture.rb', line 25

def to_stdout
  @stream_capturer = Stream::Stdout
  self
end