Module: AssertGenerator

Defined in:
lib/assert_generator.rb,
lib/assert_generator/version.rb

Defined Under Namespace

Classes: Klass

Constant Summary collapse

VERSION =
'0.1.1'

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

    Yields:

    • a block which when evaluated returns the source object



24
25
26
# File 'lib/assert_generator.rb', line 24

def self.generate_asserts(source = nil, source_expr = nil, relative_dates: nil, &block)
  AssertGenerator::Klass.new.send(:generate_asserts, source, source_expr, relative_dates, block)
end