Module: GrumpyOldMan

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

Overview

A mixin for RSpec tests that provides old school assert methods.

Constant Summary collapse

VERSION =
"0.1.6"

Instance Method Summary collapse

Instance Method Details

#assert(arg = nil) ⇒ Object

A simple assert for RSpec.

Examples:

assert true
assert { true.to_s == "true" }

Parameters:

  • arg (Object) (defaults to: nil)

    An optional arg to assert as equal to true.



16
17
18
19
# File 'lib/grumpy_old_man.rb', line 16

def assert(arg = nil)
  arg = yield if block_given?
  assert_equal !!arg, true
end

#assert_equal(actual, expected) ⇒ Object

A basic assert helper that tests for Object equality. Tests for object equivalence rather than object identity since this is sufficient for most tests.

Parameters:

  • actual (Object)

    The Object to compare.

  • expected (Object)

    The expected value.



40
41
42
# File 'lib/grumpy_old_man.rb', line 40

def assert_equal(actual, expected)
  expect(actual).to eql(expected)
end

#assert_raise(ex, &block) ⇒ Object

A basic assert helper that ensures an Error was raised.

Parameters:

  • ex (Class)

    The expected Exception class.



46
47
48
# File 'lib/grumpy_old_man.rb', line 46

def assert_raise(ex, &block)
  expect(Proc.new(&block)).to raise_error(ex)
end

#refute(arg = nil) ⇒ Object

A simple refute for RSpec.

Examples:

refute false
refute { false.to_s == "true" }

Parameters:

  • arg (Object) (defaults to: nil)

    An optional arg to assert as equal to true.



30
31
32
33
# File 'lib/grumpy_old_man.rb', line 30

def refute(arg = nil)
  arg = yield if block_given?
  assert_equal !!arg, false
end