Class: Example

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(example, report_folder) ⇒ Example

Returns a new instance of Example.



10
11
12
13
14
15
16
17
18
19
# File 'lib/example.rb', line 10

def initialize(example, report_folder)
  @description = example.description
  @full_description = example.full_description
  @execution_result = example.execution_result
  @metadata = example.
  @file_path = @metadata[:file_path]
  @exception = Oopsy.new(example.exception, @file_path)
  @spec = nil
  @report_folder = report_folder
end

Instance Attribute Details

#descriptionObject (readonly)

Returns the value of attribute description.



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

def description
  @description
end

#durationObject (readonly)

Returns the value of attribute duration.



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

def duration
  @duration
end

#exceptionObject (readonly)

Returns the value of attribute exception.



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

def exception
  @exception
end

#file_pathObject (readonly)

Returns the value of attribute file_path.



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

def file_path
  @file_path
end

#full_descriptionObject (readonly)

Returns the value of attribute full_description.



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

def full_description
  @full_description
end

#metadataObject (readonly)

Returns the value of attribute metadata.



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

def 
  @metadata
end

#run_timeObject (readonly)

Returns the value of attribute run_time.



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

def run_time
  @run_time
end

#specObject (readonly)

Returns the value of attribute spec.



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

def spec
  @spec
end

#statusObject (readonly)

Returns the value of attribute status.



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

def status
  @status
end

Instance Method Details

#has_exception?Boolean

Returns:

  • (Boolean)


21
22
23
# File 'lib/example.rb', line 21

def has_exception?
  !@exception.klass.nil?
end

#has_spec?Boolean

Returns:

  • (Boolean)


25
26
27
# File 'lib/example.rb', line 25

def has_spec?
  !@spec.nil?
end

#klass(prefix = 'label-') ⇒ Object



33
34
35
36
# File 'lib/example.rb', line 33

def klass(prefix = 'label-')
  class_map = { passed: "#{prefix}success", failed: "#{prefix}danger", pending: "#{prefix}warning" }
  class_map[status.to_sym]
end

#screenshotObject



38
39
40
41
42
43
44
45
46
47
48
# File 'lib/example.rb', line 38

def screenshot
  return nil unless @metadata[:screenshot]

  unless File.exist?(@metadata[:screenshot])
    puts "The screenshot '#{@metadata[:screenshot]}' does not exist"
  end

  report_dir = Pathname.new(File.expand_path(File.dirname(@report_folder)))
  screenshot = Pathname.new(File.expand_path(@metadata[:screenshot]))
  screenshot.relative_path_from(report_dir).to_s
end

#set_spec(spec) ⇒ Object



29
30
31
# File 'lib/example.rb', line 29

def set_spec(spec)
  @spec = spec
end