Class: Megatest::State::Test
- Inherits:
-
Object
- Object
- Megatest::State::Test
- Defined in:
- lib/megatest/state.rb
Overview
:startdoc:
Direct Known Subclasses
Instance Attribute Summary collapse
-
#index ⇒ Object
:stopdoc:.
-
#klass ⇒ Object
readonly
Returns the value of attribute klass.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#source_file ⇒ Object
readonly
Returns the value of attribute source_file.
-
#source_line ⇒ Object
readonly
Returns the value of attribute source_line.
Instance Method Summary collapse
- #<=>(other) ⇒ Object
- #==(other) ⇒ Object (also: #eql?)
- #around_callbacks ⇒ Object
- #each_setup_callback ⇒ Object
- #each_teardown_callback ⇒ Object
- #hash ⇒ Object
-
#id ⇒ Object
Returns a unique identifier string for that test, in the form of ‘klass#name`.
- #included_by(test_suite, include_location) ⇒ Object
- #inherited? ⇒ Boolean
- #inherited_by(test_suite) ⇒ Object
-
#initialize(test_suite, klass, name, callable, tags, location) ⇒ Test
constructor
A new instance of Test.
-
#inspect ⇒ Object
:stopdoc:.
- #location_id ⇒ Object
-
#tag(name) ⇒ Object
Lookup a tag for that test.
- #tags ⇒ Object
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, , location) @test_suite = test_suite @klass = klass @name = name @callable = callable @source_file, @source_line = location @id = nil @index = nil @inherited = false @tags = end |
Instance Attribute Details
#index ⇒ Object
:stopdoc:
275 276 277 |
# File 'lib/megatest/state.rb', line 275 def index @index end |
#klass ⇒ Object (readonly)
Returns the value of attribute klass.
272 273 274 |
# File 'lib/megatest/state.rb', line 272 def klass @klass end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
272 273 274 |
# File 'lib/megatest/state.rb', line 272 def name @name end |
#source_file ⇒ Object
Returns the value of attribute source_file.
272 273 274 |
# File 'lib/megatest/state.rb', line 272 def source_file @source_file end |
#source_line ⇒ Object
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_callbacks ⇒ Object
379 380 381 |
# File 'lib/megatest/state.rb', line 379 def around_callbacks @test_suite.ancestors.filter_map(&:around_callback) end |
#each_setup_callback ⇒ Object
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_callback ⇒ Object
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 |
#hash ⇒ Object
361 362 363 |
# File 'lib/megatest/state.rb', line 361 def hash [Test, @klass, @name].hash end |
#id ⇒ Object
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
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 |
#inspect ⇒ Object
: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_id ⇒ Object
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 |
#tags ⇒ Object
321 322 323 |
# File 'lib/megatest/state.rb', line 321 def @test_suite..merge(@tags || {}) end |