Sha256: 8c4d9dbd061595be25d2bac64ae1775f886e2626a13e55aac905b93d906f0120

Contents?: true

Size: 1.14 KB

Versions: 1

Compression:

Stored size: 1.14 KB

Contents

##
# @api private
require 'pp'

module PropCheck::Property::OutputFormatter
  extend self

  def pre_output(output, n_successful, generated_root, problem)
    output.puts ""
    output.puts "(after #{n_successful} successful property test runs)"
    output.puts "Failed on: "
    output.puts "`#{print_roots(generated_root)}`"
    output.puts ""
    output.puts "Exception message:\n---\n#{problem}"
    output.puts "---"
    output.puts ""

    output
  end

  def post_output(output, n_shrink_steps, shrunken_result, shrunken_exception)
    if n_shrink_steps == 0
      output.puts '(shrinking impossible)'
    else
      output.puts ''
      output.puts "Shrunken input (after #{n_shrink_steps} shrink steps):"
      output.puts "`#{print_roots(shrunken_result)}`"
      output.puts ""
      output.puts "Shrunken exception:\n---\n#{shrunken_exception}"
      output.puts "---"
      output.puts ""
    end
    output
  end

  def print_roots(lazy_tree_val)
    data =
      if lazy_tree_val.is_a?(Array) && lazy_tree_val.length == 1 && lazy_tree_val[0].is_a?(Hash)
        lazy_tree_val[0]
      else
        lazy_tree_val
      end

    PP.pp(data, '')
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
prop_check-1.0.0 lib/prop_check/property/output_formatter.rb