Skip to content

Commit

Permalink
Add a test helper to replace standard streams in a block
Browse files Browse the repository at this point in the history
  • Loading branch information
piotrmurach committed Nov 26, 2023
1 parent 5f25cfa commit 9de8f83
Showing 1 changed file with 25 additions and 0 deletions.
25 changes: 25 additions & 0 deletions spec/spec_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,34 @@
end
end

module Helpers
# Replace standard streams
#
# @example
# replace_standard_streams(StringIO.new) do
# ...
# end
#
# @param [StringIO] output
# the output to replace standard streams with
#
# @return [void]
#
# @api public
def replace_standard_streams(output)
original_streams = [$stdin, $stdout, $stderr]
$stdin, $stdout, $stderr = output, output, output
yield
ensure
$stdin, $stdout, $stderr = *original_streams
end
end

require "tty-screen"

RSpec.configure do |config|
config.include(Helpers)

config.expect_with :rspec do |expectations|
expectations.include_chain_clauses_in_custom_matcher_descriptions = true
end
Expand Down

0 comments on commit 9de8f83

Please sign in to comment.