Module: AssertGenerator

Defined in:
lib/assert_generator.rb

Defined Under Namespace

Classes: Klass

Class Method Summary collapse

Class Method Details

.generate_asserts(source, source_expr) ⇒ Object .generate_asserts({ block }) { ... } ⇒ Object

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

Overloads:

  • .generate_asserts(source, source_expr) ⇒ Object

    Generate asserts for a source object supplying an expression to access that object, e.g: ‘generate_asserts(res, ’res’ )

    Parameters:

    • source (Object)

      an object to generate asserts that the object contains the values as recorded when this got called

    • source_expr (String)

      the source expression that created the object, will be repeated into the asserts

  • .generate_asserts({ block }) { ... } ⇒ Object

    Generate asserts for a source object defined in a block - reflect the block to get the source to output

    to access the object
    

    Parameters:

    • relative_dates (String)

      adjust dates to be relative to the supplied date as a string expression

      • use with date dependent fixtures

    • numeric_precision (Integer)

      compare BigDecimal and Float using this level of precision in ‘assert_in_delta, set to nil for an `assert_equal` compare

    Yields:

    • a block which when evaluated returns the source object



27
28
29
# 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