module AssertGenerator

Public Class Methods

generate_asserts(source = nil, source_expr = nil, relative_dates: nil, numeric_precision: 2, &block) click to toggle source

Generate asserts based on some actual output from an object under test Outputs executable code to stdout with the assert statements, which can be pasted into the test The user needs to ensure that values are deterministic and do not change between test invocations

@overload generate_asserts(source, source_expr)

Generate asserts for a source object supplying an expression to access that object,
e.g: `generate_asserts(res, 'res' )
@param source [Object] an object to generate asserts that the object contains the values as recorded
  when this got called
@param source_expr [String] the source expression that created the object, will be repeated into the asserts

@overload generate_asserts { block }

Generate asserts for a source object defined in a block - reflect the block to get the source to output
  to access the object
@param relative_dates [String] adjust dates to be relative to the supplied date as a string expression
  - use with date dependent fixtures
@param numeric_precision [Integer] compare BigDecimal and Float using this level of precision
  in `assert_in_delta, set to nil for an `assert_equal` compare
@yield a block which when evaluated returns the source object
# File lib/assert_generator.rb, line 27
def self.generate_asserts(source = nil, source_expr = nil, relative_dates: nil, numeric_precision: 2, &block)
  AssertGenerator::Klass.new.send(:generate_asserts, source, source_expr, relative_dates, numeric_precision, block)
end