Sha256: 713262560400546e1a5390ebf25492d005b8b9d71082f4b1705eb4c40a7be4c4
Contents?: true
Size: 1.47 KB
Versions: 28
Compression:
Stored size: 1.47 KB
Contents
module OutputHelpers extend RSpec::Matchers::DSL matcher :return_and_output do |expected, *lines| supports_block_expectations match do |block| stdout = lines.flatten.join("\n") + "\n" begin expect{@return = block.call}.to output(stdout).to_stdout rescue Exception => error @error = error return false else return values_match? expected, @return end end failure_message do |block| if @error return @error else return "expected #{block} to return #{expected}, but returned #{@return}" end end end matcher :output_table do |lines| supports_block_expectations match do |block| stdout = Regexp.new('^' + lines.map{|fields| fields.join('\s+')}.join('\n') + '\n$', Regexp::MULTILINE) begin expect{@return = block.call}.to output(stdout).to_stdout rescue Exception => error @error = error return false else return true end end failure_message do |block| return @error end end matcher :output_lines do |lines| supports_block_expectations match do |block| stdout = lines.flatten.join("\n") + "\n" begin expect{@return = block.call}.to output(stdout).to_stdout rescue Exception => error @error = error return false else return true end end failure_message do |block| return @error end end end
Version data entries
28 entries across 28 versions & 1 rubygems