Module: Tet

Defined in:
lib/tet.rb

Overview

A namespace for all of the helper methods and classes.

Defined Under Namespace

Modules: Messages, Stats, StringFormatting Classes: TestError

Class Method Summary collapse

Class Method Details

.erred(caught, expected = nil) ⇒ Object

Call when an assertion has erred



103
104
105
106
# File 'lib/tet.rb', line 103

def erred caught, expected = nil
  Stats.erred
  Messages.erred(caught, expected)
end

.failedObject

Call when an assertion has failed



97
98
99
100
# File 'lib/tet.rb', line 97

def failed
  Stats.failed
  Messages.failed
end

.passedObject

Call when an assertion has passed



92
93
94
# File 'lib/tet.rb', line 92

def passed
  Stats.passed
end

.run(label:, truthy: -> { }, falsy: -> { }, error: ->(caught) { erred(caught) }, no_nest: false, test:) ⇒ Object

Run a block as a test



109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
# File 'lib/tet.rb', line 109

def run label:,
        truthy:  -> { },
        falsy:   -> { },
        error:   ->(caught) { erred(caught) },
        no_nest: false,
        test:

  Messages.with_label(label) do
    nesting_guard(no_nest) do
      begin
        test.call ? truthy.call : falsy.call
      rescue TestError => caught
        erred(caught)
      rescue StandardError => caught
        error.call(caught)
      end
    end
  end

  nil
end