Module: TestBench::Bootstrap::Fixture

Defined in:
lib/test_bench/bootstrap.rb

Instance Method Summary collapse

Instance Method Details

#_context(prose = nil, &block) ⇒ Object



150
151
152
# File 'lib/test_bench/bootstrap.rb', line 150

def _context(prose=nil, &block)
  context(prose)
end

#_test(prose = nil, &block) ⇒ Object



174
175
176
# File 'lib/test_bench/bootstrap.rb', line 174

def _test(prose=nil, &block)
  test(prose)
end

#assert(value) ⇒ Object



86
87
88
89
90
# File 'lib/test_bench/bootstrap.rb', line 86

def assert(value)
  unless value
    raise AssertionFailure.build(1)
  end
end

#assert_raises(error_class = nil, &block) ⇒ Object



92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
# File 'lib/test_bench/bootstrap.rb', line 92

def assert_raises(error_class=nil, &block)
  begin
    Output.raw_write("assert_raises\n")
    block.()

  rescue (error_class || StandardError) => error
    return if error_class.nil?

    if error.instance_of?(error_class)
      return
    else
      raise error
    end
  end

  raise AssertionFailure.build(1)
end

#comment(text) ⇒ Object



178
179
180
# File 'lib/test_bench/bootstrap.rb', line 178

def comment(text)
  Output.write(text)
end

#context(prose = nil, &block) ⇒ Object



127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
# File 'lib/test_bench/bootstrap.rb', line 127

def context(prose=nil, &block)
  if block.nil?
    Output.write(prose || 'Context', sgr_code: 0x33)
    return
  end

  unless prose.nil?
    Output.indent(prose, sgr_code: 0x32) do
      context(&block)
    end
    return
  end

  begin
    block.()

  rescue => error
    Output.error(error)

    Abort.()
  end
end

#detail(text) ⇒ Object



182
183
184
# File 'lib/test_bench/bootstrap.rb', line 182

def detail(text)
  comment(text)
end

#fixture(cls, *args, **kwargs, &block) ⇒ Object



186
187
188
189
190
191
192
# File 'lib/test_bench/bootstrap.rb', line 186

def fixture(cls, *args, **kwargs, &block)
  fixture = TestBench::Fixture.(cls, *args, **kwargs, &block)

  passed = !fixture.test_session.failed?

  assert(passed)
end

#refute(value) ⇒ Object



110
111
112
113
114
# File 'lib/test_bench/bootstrap.rb', line 110

def refute(value)
  if value
    raise AssertionFailure.build(1)
  end
end

#refute_raises(error_class = nil, &block) ⇒ Object



116
117
118
119
120
121
122
123
124
125
# File 'lib/test_bench/bootstrap.rb', line 116

def refute_raises(error_class=nil, &block)
  block.()

rescue (error_class || StandardError) => error
  unless error.instance_of?(error_class)
    raise error
  end

  raise AssertionFailure.build(1)
end

#test(prose = nil, &block) ⇒ Object



154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
# File 'lib/test_bench/bootstrap.rb', line 154

def test(prose=nil, &block)
  if block.nil?
    Output.write(prose || 'Test', sgr_code: 0x33)
    return
  end

  begin
    block.()

    Output.indent(prose, sgr_code: 0x32)

  rescue => error
    Output.indent(prose, sgr_codes: [0x1, 0x31]) do
      Output.error(error)
    end

    Abort.()
  end
end