Class: Easytest::Case

Inherits:
Object
  • Object
show all
Defined in:
lib/easytest/case.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name:, skipped: false, only: false, block: nil) ⇒ Case

Returns a new instance of Case.



12
13
14
15
16
17
18
# File 'lib/easytest/case.rb', line 12

def initialize(name:, skipped: false, only: false, block: nil)
  @name = name
  @file = (caller_locations(3, 1)&.first&.absolute_path or raise)
  @block = block
  @skipped = skipped
  @only = only
end

Instance Attribute Details

#blockObject (readonly)

Returns the value of attribute block.



5
6
7
# File 'lib/easytest/case.rb', line 5

def block
  @block
end

#fileObject (readonly)

Returns the value of attribute file.



4
5
6
# File 'lib/easytest/case.rb', line 4

def file
  @file
end

#nameObject (readonly)

Returns the value of attribute name.



3
4
5
# File 'lib/easytest/case.rb', line 3

def name
  @name
end

#onlyObject (readonly) Also known as: only?

Returns the value of attribute only.



7
8
9
# File 'lib/easytest/case.rb', line 7

def only
  @only
end

#skippedObject (readonly) Also known as: skipped?

Returns the value of attribute skipped.



6
7
8
# File 'lib/easytest/case.rb', line 6

def skipped
  @skipped
end

Instance Method Details

#runObject



24
25
26
27
28
29
30
31
32
33
# File 'lib/easytest/case.rb', line 24

def run
  return [:todo, Reporter.new(name).report_todo] unless block
  return [:skipped, Reporter.new(name).report_skip] if skipped?

  block.call
  [:passed, nil]
rescue MatchError, FatalError => error
  report = Reporter.new(name).report_error(error) or raise error
  [:failed, report]
end

#skip!Object



20
21
22
# File 'lib/easytest/case.rb', line 20

def skip!
  @skipped = true
end