Class: Megatest::State::Test

Inherits:
Object
  • Object
show all
Defined in:
lib/megatest/state.rb

Overview

:startdoc:

Direct Known Subclasses

BlockTest, MethodTest

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(test_suite, klass, name, callable, tags, location) ⇒ Test

Returns a new instance of Test.



274
275
276
277
278
279
280
281
282
283
284
# File 'lib/megatest/state.rb', line 274

def initialize(test_suite, klass, name, callable, tags, location)
  @test_suite = test_suite
  @klass = klass
  @name = name
  @callable = callable
  @source_file, @source_line = location
  @id = nil
  @index = nil
  @inherited = false
  @tags = tags
end

Instance Attribute Details

#indexObject

:stopdoc:



272
273
274
# File 'lib/megatest/state.rb', line 272

def index
  @index
end

#klassObject (readonly)

Returns the value of attribute klass.



269
270
271
# File 'lib/megatest/state.rb', line 269

def klass
  @klass
end

#nameObject (readonly)

Returns the value of attribute name.



269
270
271
# File 'lib/megatest/state.rb', line 269

def name
  @name
end

#source_fileObject

Returns the value of attribute source_file.



269
270
271
# File 'lib/megatest/state.rb', line 269

def source_file
  @source_file
end

#source_lineObject

Returns the value of attribute source_line.



269
270
271
# File 'lib/megatest/state.rb', line 269

def source_line
  @source_line
end

Instance Method Details

#<=>(other) ⇒ Object



362
363
364
365
366
# File 'lib/megatest/state.rb', line 362

def <=>(other)
  cmp = @klass.name <=> other.klass.name
  cmp = @name <=> other.name if cmp&.zero?
  cmp || 0
end

#==(other) ⇒ Object Also known as: eql?



351
352
353
354
355
# File 'lib/megatest/state.rb', line 351

def ==(other)
  other.is_a?(Test) &&
    @klass == other.klass &&
    @name == other.name
end

#around_callbacksObject



374
375
376
# File 'lib/megatest/state.rb', line 374

def around_callbacks
  @test_suite.ancestors.flat_map(&:around_callbacks)
end

#each_setup_callback(&block) ⇒ Object



368
369
370
371
372
# File 'lib/megatest/state.rb', line 368

def each_setup_callback(&block)
  @test_suite.ancestors.reverse_each do |test_suite|
    test_suite.setup_callbacks.each(&block)
  end
end

#each_teardown_callback(&block) ⇒ Object



378
379
380
381
382
# File 'lib/megatest/state.rb', line 378

def each_teardown_callback(&block)
  @test_suite.ancestors.each do |test_suite|
    test_suite.teardown_callbacks.reverse_each(&block)
  end
end

#hashObject



358
359
360
# File 'lib/megatest/state.rb', line 358

def hash
  [Test, @klass, @name].hash
end

#idObject

Returns a unique identifier string for that test, in the form of ‘klass#name`



290
291
292
293
294
295
296
# File 'lib/megatest/state.rb', line 290

def id
  if klass.name
    @id ||= "#{klass.name}##{name}"
  else
    "#{klass}##{name}"
  end
end

#included_by(test_suite, include_location) ⇒ Object



343
344
345
346
347
348
349
# File 'lib/megatest/state.rb', line 343

def included_by(test_suite, include_location)
  copy = dup
  copy.test_suite = test_suite
  copy.source_file, copy.source_line = include_location
  copy.inherited = true
  copy
end

#inherited?Boolean

Returns:

  • (Boolean)


330
331
332
# File 'lib/megatest/state.rb', line 330

def inherited?
  @inherited
end

#inherited_by(test_suite) ⇒ Object



334
335
336
337
338
339
340
341
# File 'lib/megatest/state.rb', line 334

def inherited_by(test_suite)
  copy = dup
  copy.test_suite = test_suite
  copy.source_file = test_suite.source_file
  copy.source_line = test_suite.source_line
  copy.inherited = true
  copy
end

#inspectObject

:stopdoc:



310
311
312
313
314
315
316
# File 'lib/megatest/state.rb', line 310

def inspect
  if klass.name
    "#<#{self.class}: #{id} @ #{location_id}>"
  else
    "#<#{self.class}: #{klass.inspect}##{name} @ #{location_id}>"
  end
end

#location_idObject



322
323
324
325
326
327
328
# File 'lib/megatest/state.rb', line 322

def location_id
  if @index
    "#{@source_file}:#{@source_line}~#{@index}"
  else
    "#{@source_file}:#{@source_line}"
  end
end

#tag(name) ⇒ Object

Lookup a tag for that test. Returns nil if the tag isn’t set.



300
301
302
303
304
305
306
# File 'lib/megatest/state.rb', line 300

def tag(name)
  if @tags&.key?(name)
    @tags[name]
  else
    @test_suite.tag(name)
  end
end

#tagsObject



318
319
320
# File 'lib/megatest/state.rb', line 318

def tags
  @test_suite.tags.merge(@tags || {})
end