Module: XMP2Assert::Assertions

Includes:
Test::Unit::Assertions, XMP2Rexp
Defined in:
lib/xmp2assert/assertions.rb

Overview

Helper module that implements assertions.

Instance Method Summary collapse

Methods included from XMP2Rexp

xmp2rexp

Instance Method Details

#assert_capture2e(expected, script, message = nil, rubyopts: nil, **opts) ⇒ Object

Note:

As the method name implies the assertion is against both stdin and stderr at once. This is for convenience.

Run a ruby script and assert for its output.

assert_capture2e "foo\n", Quasifile.new("puts 'foo'")

Parameters:

  • expected (String)

    expected output.

  • script (Quasifile)

    a ruby script.

  • message (String) (defaults to: nil)

    extra failure message.

  • rubyopts (Array<String>) (defaults to: nil)

    extra opts to pass to ruby process.

  • opts (Hash{Symbol=>Object})

    extra opts to pass to spawn.



56
57
58
59
60
61
# File 'lib/xmp2assert/assertions.rb', line 56

def assert_capture2e expected, script, message = nil, rubyopts: nil, **opts
  qscript = XMP2Assert::Quasifile.new script
  actual, _ = ruby qscript, rubyopts: rubyopts, **opts
  actual.force_encoding expected.encoding
  return assert_xmp_raw expected, actual, message
end

#assert_xmp(xmp, expr, message = nil) ⇒ Object

Assert if the given expression is in the same form of xmp.

assert_xmp '#<Object:0x007f896c9b49c8>', Object.new

Parameters:

  • xmp (String)

    expected pattern of inspect.

  • expr (Object)

    object to check.

  • message (String) (defaults to: nil)

    extra failure message.



72
73
74
# File 'lib/xmp2assert/assertions.rb', line 72

def assert_xmp xmp, expr, message = nil
  assert_xmp_raw xmp, expr.inspect, message
end