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.



277
278
279
280
281
282
283
284
285
286
287
# File 'lib/megatest/state.rb', line 277

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:



275
276
277
# File 'lib/megatest/state.rb', line 275

def index
  @index
end

#klassObject (readonly)

Returns the value of attribute klass.



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

def klass
  @klass
end

#nameObject (readonly)

Returns the value of attribute name.



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

def name
  @name
end

#source_fileObject

Returns the value of attribute source_file.



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

def source_file
  @source_file
end

#source_lineObject

Returns the value of attribute source_line.



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

def source_line
  @source_line
end

Instance Method Details

#<=>(other) ⇒ Object



365
366
367
368
369
# File 'lib/megatest/state.rb', line 365

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

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



354
355
356
357
358
# File 'lib/megatest/state.rb', line 354

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

#around_callbacksObject



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

def around_callbacks
  @test_suite.ancestors.filter_map(&:around_callback)
end

#each_setup_callbackObject



371
372
373
374
375
# File 'lib/megatest/state.rb', line 371

def each_setup_callback
  @test_suite.ancestors.reverse_each do |test_suite|
    yield test_suite.setup_callback if test_suite.setup_callback
  end
end

#each_teardown_callbackObject



383
384
385
386
387
# File 'lib/megatest/state.rb', line 383

def each_teardown_callback
  @test_suite.ancestors.each do |test_suite|
    yield test_suite.teardown_callback if test_suite.teardown_callback
  end
end

#hashObject



361
362
363
# File 'lib/megatest/state.rb', line 361

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

#idObject

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



293
294
295
296
297
298
299
# File 'lib/megatest/state.rb', line 293

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

#included_by(test_suite, include_location) ⇒ Object



346
347
348
349
350
351
352
# File 'lib/megatest/state.rb', line 346

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)


333
334
335
# File 'lib/megatest/state.rb', line 333

def inherited?
  @inherited
end

#inherited_by(test_suite) ⇒ Object



337
338
339
340
341
342
343
344
# File 'lib/megatest/state.rb', line 337

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:



313
314
315
316
317
318
319
# File 'lib/megatest/state.rb', line 313

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

#location_idObject



325
326
327
328
329
330
331
# File 'lib/megatest/state.rb', line 325

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.



303
304
305
306
307
308
309
# File 'lib/megatest/state.rb', line 303

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

#tagsObject



321
322
323
# File 'lib/megatest/state.rb', line 321

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