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(&block) ⇒ Object
- #each_teardown_callback(&block) ⇒ 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.
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, , 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:
272 273 274 |
# File 'lib/megatest/state.rb', line 272 def index @index end |
#klass ⇒ Object (readonly)
Returns the value of attribute klass.
269 270 271 |
# File 'lib/megatest/state.rb', line 269 def klass @klass end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
269 270 271 |
# File 'lib/megatest/state.rb', line 269 def name @name end |
#source_file ⇒ Object
Returns the value of attribute source_file.
269 270 271 |
# File 'lib/megatest/state.rb', line 269 def source_file @source_file end |
#source_line ⇒ Object
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_callbacks ⇒ Object
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 |
#hash ⇒ Object
358 359 360 |
# File 'lib/megatest/state.rb', line 358 def hash [Test, @klass, @name].hash end |
#id ⇒ Object
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
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 |
#inspect ⇒ Object
: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_id ⇒ Object
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 |
#tags ⇒ Object
318 319 320 |
# File 'lib/megatest/state.rb', line 318 def @test_suite..merge(@tags || {}) end |